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<int>& sharedIDs = vspace_->getSharedIDs_private(nodeIDType_);
00173 
00174       int numShared = sharedIDs.getSharedIDs().size();
00175       workspace_.resize(numShared*2);
00176       int* wkPtr = &workspace_[0];
00177       fei::copyKeysToArray(sharedIDs.getSharedIDs(), numShared, wkPtr);
00178 
00179       snl_fei::RecordCollection* collection = NULL;
00180       vspace_->getRecordCollection(nodeIDType_, collection);
00181 
00182       for(int i=0; i<numShared; ++i) {
00183         fei::Record<int>* node = collection->getRecordWithID(wkPtr[i]);
00184         if (node == NULL) return NULL;
00185 
00186         wkPtr[numShared+i] = node->getNumber();
00187       }
00188       return(wkPtr+numShared);
00189     }
00190 
00192     const int* getSharedNodeProcs(int nodeNumber)
00193     {
00194       std::map<int,fei::Record<int>*>::iterator
00195         nnp_iter = nodenumPairs_.find(nodeNumber);
00196 
00197       if (nnp_iter == nodenumPairs_.end()) return(0);
00198 
00199       fei::Record<int>* node = (*nnp_iter).second;
00200 
00201       const fei::SharedIDs<int>& sharedIDs = vspace_->getSharedIDs_private(nodeIDType_);
00202 
00203       int shID = node->getID();
00204 
00205       fei::SharedIDs<int>::map_type::const_iterator
00206         iter = sharedIDs.getSharedIDs().find(shID);
00207       if (iter == sharedIDs.getSharedIDs().end()) return(NULL);
00208 
00209       const std::set<int>& shprocs = iter->second;
00210 
00211       fei::copySetToVector(shprocs, workspace_);
00212       return(&workspace_[0]);
00213     }
00214 
00216     int getNumSharingProcs(int nodeNumber)
00217     {
00218       std::map<int,fei::Record<int>*>::iterator
00219         nnp_iter = nodenumPairs_.find(nodeNumber);
00220 
00221       if (nnp_iter == nodenumPairs_.end()) return(0);
00222 
00223       fei::Record<int>* node = (*nnp_iter).second;
00224 
00225       const fei::SharedIDs<int>& sharedIDs = vspace_->getSharedIDs_private(nodeIDType_);
00226 
00227       int shID = node->getID();
00228 
00229       fei::SharedIDs<int>::map_type::const_iterator
00230         iter = sharedIDs.getSharedIDs().find(shID);
00231       if (iter == sharedIDs.getSharedIDs().end()) return(0);
00232 
00233       const std::set<int>& shprocs = iter->second;
00234       return(shprocs.size());
00235     }
00236 
00238     bool isExactlyBlkEqn(int ptEqn)
00239       { return( ptBlkMap_->isExactlyBlkEqn(ptEqn) ); }
00240 
00242     int ptEqnToBlkEqn(int ptEqn)
00243       { return( ptBlkMap_->eqnToBlkEqn(ptEqn) ); }
00244 
00246     int getOffsetIntoBlkEqn(int blkEqn, int ptEqn);
00247 
00249     int getBlkEqnSize(int blkEqn)
00250     {
00251       return( ptBlkMap_->getBlkEqnSize(blkEqn) );
00252     }
00253 
00254   private:
00255     int buildDatabases();
00256 
00257     fei::SharedPtr<fei::MatrixGraph> matGraph_;
00258     snl_fei::PointBlockMap* ptBlkMap_;
00259     fei::SharedPtr<fei::VectorSpace> vspace_;
00260     int nodeIDType_;
00261 
00262     std::map<int, fei::Record<int>*> nodenumPairs_;
00263     std::map<int,fei::Record<int>*> eqnnumPairs_;
00264 
00265     std::map<int,std::vector<int>*> nodenumSubdomainDB_;
00266 
00267     bool databasesBuilt_;
00268 
00269     std::vector<int> fieldIDs_;
00270     std::vector<int> fieldSizes_;
00271     std::vector<GlobalID> elemBlockIDs_;
00272     std::vector<const int*> fieldIDs_2D_;
00273     std::vector<int> workspace_;
00274   };//class Lookup_Impl
00275 }//namespace fei
00276 
00277 #endif // _fei_Lookup_Impl_hpp_

Generated on Tue Jul 13 09:27:45 2010 for FEI by  doxygen 1.4.7