fei_Lookup_Impl.hpp

00001 /*--------------------------------------------------------------------*/
00002 /*    Copyright 2005 Sandia Corporation.                              */
00003 /*    Under the terms of Contract DE-AC04-94AL85000, there is a       */
00004 /*    non-exclusive license for use of this work by or on behalf      */
00005 /*    of the U.S. Government.  Export of this program may require     */
00006 /*    a license from the United States Government.                    */
00007 /*--------------------------------------------------------------------*/
00008 
00009 #ifndef _fei_Lookup_Impl_hpp_
00010 #define _fei_Lookup_Impl_hpp_
00011 
00012 #include <fei_macros.hpp>
00013 #include <fei_MatrixGraph.hpp>
00014 #include <fei_Pattern.hpp>
00015 #include <fei_ConnectivityBlock.hpp>
00016 #include <fei_SharedIDs.hpp>
00017 #include <snl_fei_RecordCollection.hpp>
00018 #include <snl_fei_PointBlockMap.hpp>
00019 #include <fei_TemplateUtils.hpp>
00020 #include <fei_Lookup.hpp>
00021 
00022 #include <vector>
00023 
00024 namespace fei {
00027   class Lookup_Impl : public virtual Lookup {
00028   public:
00030     Lookup_Impl(fei::SharedPtr<fei::MatrixGraph> matGraph,
00031     int nodeIDType);
00032 
00034     virtual ~Lookup_Impl();
00035 
00037     int getNumFields()
00038       {
00039   return( vspace_->getNumFields() );
00040       }
00041 
00043     int getFieldSize(int fieldID)
00044       {
00045   return(vspace_->getFieldSize(fieldID));
00046       }
00047 
00049     const int* getFieldIDsPtr()
00050       {
00051   int len = getNumFields();
00052   if (len < 1) return(NULL);
00053 
00054   vspace_->getFields(fieldIDs_);
00055   return(&fieldIDs_[0]);
00056       }
00057 
00059     const int* getFieldSizesPtr()
00060       {
00061   const int* fieldIDs = getFieldIDsPtr();
00062   if (fieldIDs == NULL) return(NULL);
00063 
00064   unsigned numFields = fieldIDs_.size();
00065   fieldSizes_.resize(numFields);
00066   int* fsPtr = &fieldSizes_[0];
00067   for(unsigned i=0; i<numFields; ++i) {
00068     fsPtr[i] = vspace_->getFieldSize(fieldIDs[i]);
00069   }
00070   return(fsPtr);
00071       }
00072 
00074     int getNumElemBlocks()
00075       { return(matGraph_->getConnectivityBlocks().size()); }
00076 
00078     const GlobalID* getElemBlockIDs()
00079       {
00080   int err = matGraph_->getConnectivityBlockIDs(elemBlockIDs_);
00081   return(err==0 ? &elemBlockIDs_[0] : NULL);
00082       }
00083 
00085     void getElemBlockInfo(GlobalID blockID,
00086                          int& interleaveStrategy, int& lumpingStrategy,
00087                          int& numElemDOF, int& numElements,
00088                          int& numNodesPerElem, int& numEqnsPerElem)
00089       {
00090   interleaveStrategy = 0; lumpingStrategy = 0;
00091   numElemDOF = 0;
00092   const fei::ConnectivityBlock* cblock =
00093     matGraph_->getConnectivityBlock(blockID);
00094   numElements = cblock->getConnectivityIDs().size();
00095   numNodesPerElem = cblock->getRowPattern()->getNumIDs();
00096   numEqnsPerElem = cblock->getRowPattern()->getNumIndices();
00097       }
00098 
00100     const int* getNumFieldsPerNode(GlobalID blockID)
00101       {
00102   const fei::ConnectivityBlock* cblock = matGraph_->getConnectivityBlock(blockID);
00103   if (cblock==NULL) return(NULL);
00104   return(cblock->getRowPattern()->getNumFieldsPerID());
00105       }
00106 
00108     const int* const* getFieldIDsTable(GlobalID blockID)
00109       {
00110   const fei::ConnectivityBlock* cblock = matGraph_->getConnectivityBlock(blockID);
00111   if (cblock==NULL) return(NULL);
00112   int numNodes = cblock->getRowPattern()->getNumIDs();
00113   const int* numFieldsPerNode = cblock->getRowPattern()->getNumFieldsPerID();
00114   const int* fieldIDs = cblock->getRowPattern()->getFieldIDs();
00115   fieldIDs_2D_.resize(numNodes);
00116   const int** f2dPtr = &fieldIDs_2D_[0];
00117   int offset = 0;
00118   for(int i=0; i<numNodes; ++i) {
00119     f2dPtr[i] = fieldIDs + offset;
00120     offset += numFieldsPerNode[i];
00121   }
00122   return(f2dPtr);
00123       }
00124 
00126     int getEqnNumber(int nodeNumber, int fieldID);
00127 
00129     int getAssociatedNodeNumber(int eqnNumber);
00130 
00131     int getAssociatedNodeID(int eqnNumber);
00132 
00134     int getAssociatedFieldID(int eqnNumber)
00135       { return(-1); }
00136 
00138     bool isInLocalElement(int nodeNumber);
00139 
00141     int getNumSubdomains(int nodeNumber)
00142       {
00143   std::vector<int>* subdomains = NULL;
00144   std::map<int,std::vector<int>* >::iterator
00145     nns_iter = nodenumSubdomainDB_.find(nodeNumber);
00146   if (nns_iter != nodenumSubdomainDB_.end()) subdomains = (*nns_iter).second;
00147   return( subdomains==0 ? 0 : subdomains->size() );
00148       }
00149 
00151     int* getSubdomainList(int nodeNumber)
00152       {
00153   std::vector<int>* subdomains = NULL;
00154   std::map<int,std::vector<int>* >::iterator
00155     nns_iter = nodenumSubdomainDB_.find(nodeNumber);
00156   if (nns_iter != nodenumSubdomainDB_.end()) subdomains = (*nns_iter).second;
00157 
00158   return( subdomains==0 ? NULL : &(*subdomains)[0] );
00159       }
00160 
00162     int getNumSharedNodes()
00163       {
00164   int numShared;
00165   int err = vspace_->getNumSharedIDs(nodeIDType_, numShared);
00166   return(err==0 ? numShared : -1);
00167       }
00168 
00170     const int* getSharedNodeNumbers()
00171       {
00172   fei::SharedIDs* sharedIDs = NULL;
00173   vspace_->getSharedIDs_private(nodeIDType_, sharedIDs);
00174 
00175   int numShared = sharedIDs->getSharedIDs().getMap().size();
00176   workspace_.resize(numShared*2);
00177   int* wkPtr = &workspace_[0];
00178   fei::copyKeysToArray(sharedIDs->getSharedIDs().getMap(), numShared, wkPtr);
00179 
00180   snl_fei::RecordCollection* collection = NULL;
00181   vspace_->getRecordCollection(nodeIDType_, collection);
00182 
00183   for(int i=0; i<numShared; ++i) {
00184     fei::Record* node = collection->getRecordWithID(wkPtr[i]);
00185           if (node == NULL) return NULL;
00186 
00187     wkPtr[numShared+i] = node->getNumber();
00188   }
00189   return(wkPtr+numShared);
00190       }
00191 
00193     const int* getSharedNodeProcs(int nodeNumber)
00194       {
00195   std::map<int,fei::Record*>::iterator
00196     nnp_iter = nodenumPairs_.find(nodeNumber);
00197 
00198   if (nnp_iter == nodenumPairs_.end()) return(0);
00199 
00200   fei::Record* node = (*nnp_iter).second;
00201 
00202   fei::SharedIDs* sharedIDs = NULL;
00203   vspace_->getSharedIDs_private(nodeIDType_, sharedIDs);
00204 
00205   int shID = node->getID();
00206 
00207   fei::SharedIDs::table_type::row_type* list = sharedIDs->getSharedIDs().getRow(shID);
00208   if (list == NULL) return(NULL);
00209 
00210         workspace_.resize(list->size());
00211   list->copy_to_array(workspace_.size(), &workspace_[0]);
00212   return(&workspace_[0]);
00213       }
00214 
00216     int getNumSharingProcs(int nodeNumber)
00217       {
00218   std::map<int,fei::Record*>::iterator
00219     nnp_iter = nodenumPairs_.find(nodeNumber);
00220 
00221   if (nnp_iter == nodenumPairs_.end()) return(0);
00222 
00223   fei::Record* node = (*nnp_iter).second;
00224 
00225   fei::SharedIDs* sharedIDs = NULL;
00226   vspace_->getSharedIDs_private(nodeIDType_, sharedIDs);
00227 
00228   int shID = node->getID();
00229 
00230   fei::SharedIDs::table_type::row_type* list = sharedIDs->getSharedIDs().getRow(shID);
00231   return(list!=NULL ? list->size() : -1);
00232       }
00233 
00235     bool isExactlyBlkEqn(int ptEqn)
00236       { return( ptBlkMap_->isExactlyBlkEqn(ptEqn) ); }
00237 
00239     int ptEqnToBlkEqn(int ptEqn)
00240       { return( ptBlkMap_->eqnToBlkEqn(ptEqn) ); }
00241 
00243     int getOffsetIntoBlkEqn(int blkEqn, int ptEqn);
00244 
00246     int getBlkEqnSize(int blkEqn)
00247       {
00248   return( ptBlkMap_->getBlkEqnSize(blkEqn) );
00249       }
00250 
00251   private:
00252     int buildDatabases();
00253 
00254     fei::SharedPtr<fei::MatrixGraph> matGraph_;
00255     snl_fei::PointBlockMap* ptBlkMap_;
00256     fei::SharedPtr<fei::VectorSpace> vspace_;
00257     int nodeIDType_;
00258 
00259     std::map<int, fei::Record*> nodenumPairs_;
00260     std::map<int,fei::Record*> eqnnumPairs_;
00261 
00262     std::map<int,std::vector<int>*> nodenumSubdomainDB_;
00263 
00264     bool databasesBuilt_;
00265 
00266     std::vector<int> fieldIDs_;
00267     std::vector<int> fieldSizes_;
00268     std::vector<GlobalID> elemBlockIDs_;
00269     std::vector<const int*> fieldIDs_2D_;
00270     std::vector<int> workspace_;
00271   };//class Lookup_Impl
00272 }//namespace fei
00273 
00274 #endif // _fei_Lookup_Impl_hpp_

Generated on Wed May 12 21:30:41 2010 for FEI by  doxygen 1.4.7