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 
00137     bool isInLocalElement(int nodeNumber);
00138 
00140     int getNumSubdomains(int nodeNumber)
00141     {
00142       std::vector<int>* subdomains = NULL;
00143       std::map<int,std::vector<int>* >::iterator
00144         nns_iter = nodenumSubdomainDB_.find(nodeNumber);
00145       if (nns_iter != nodenumSubdomainDB_.end()) subdomains = (*nns_iter).second;
00146       return( subdomains==0 ? 0 : subdomains->size() );
00147     }
00148 
00150     int* getSubdomainList(int nodeNumber)
00151     {
00152       std::vector<int>* subdomains = NULL;
00153       std::map<int,std::vector<int>* >::iterator
00154         nns_iter = nodenumSubdomainDB_.find(nodeNumber);
00155       if (nns_iter != nodenumSubdomainDB_.end()) subdomains = (*nns_iter).second;
00156 
00157       return( subdomains==0 ? NULL : &(*subdomains)[0] );
00158     }
00159 
00161     int getNumSharedNodes()
00162     {
00163       int numShared;
00164       int err = vspace_->getNumSharedIDs(nodeIDType_, numShared);
00165       return(err==0 ? numShared : -1);
00166     }
00167 
00169     const int* getSharedNodeNumbers()
00170     {
00171       fei::SharedIDs<int>& sharedIDs = vspace_->getSharedIDs_private(nodeIDType_);
00172 
00173       int numShared = sharedIDs.getSharedIDs().size();
00174       workspace_.resize(numShared*2);
00175       int* wkPtr = &workspace_[0];
00176       fei::copyKeysToArray(sharedIDs.getSharedIDs(), numShared, wkPtr);
00177 
00178       snl_fei::RecordCollection* collection = NULL;
00179       vspace_->getRecordCollection(nodeIDType_, collection);
00180 
00181       for(int i=0; i<numShared; ++i) {
00182         fei::Record<int>* node = collection->getRecordWithID(wkPtr[i]);
00183         if (node == NULL) return NULL;
00184 
00185         wkPtr[numShared+i] = node->getNumber();
00186       }
00187       return(wkPtr+numShared);
00188     }
00189 
00191     const int* getSharedNodeProcs(int nodeNumber)
00192     {
00193       std::map<int,fei::Record<int>*>::iterator
00194         nnp_iter = nodenumPairs_.find(nodeNumber);
00195 
00196       if (nnp_iter == nodenumPairs_.end()) return(0);
00197 
00198       fei::Record<int>* node = (*nnp_iter).second;
00199 
00200       const fei::SharedIDs<int>& sharedIDs = vspace_->getSharedIDs_private(nodeIDType_);
00201 
00202       int shID = node->getID();
00203 
00204       fei::SharedIDs<int>::map_type::const_iterator
00205         iter = sharedIDs.getSharedIDs().find(shID);
00206       if (iter == sharedIDs.getSharedIDs().end()) return(NULL);
00207 
00208       const std::set<int>& shprocs = iter->second;
00209 
00210       fei::copySetToVector(shprocs, workspace_);
00211       return(&workspace_[0]);
00212     }
00213 
00215     int getNumSharingProcs(int nodeNumber)
00216     {
00217       std::map<int,fei::Record<int>*>::iterator
00218         nnp_iter = nodenumPairs_.find(nodeNumber);
00219 
00220       if (nnp_iter == nodenumPairs_.end()) return(0);
00221 
00222       fei::Record<int>* node = (*nnp_iter).second;
00223 
00224       const fei::SharedIDs<int>& sharedIDs = vspace_->getSharedIDs_private(nodeIDType_);
00225 
00226       int shID = node->getID();
00227 
00228       fei::SharedIDs<int>::map_type::const_iterator
00229         iter = sharedIDs.getSharedIDs().find(shID);
00230       if (iter == sharedIDs.getSharedIDs().end()) return(0);
00231 
00232       const std::set<int>& shprocs = iter->second;
00233       return(shprocs.size());
00234     }
00235 
00237     bool isExactlyBlkEqn(int ptEqn)
00238       { return( ptBlkMap_->isExactlyBlkEqn(ptEqn) ); }
00239 
00241     int ptEqnToBlkEqn(int ptEqn)
00242       { return( ptBlkMap_->eqnToBlkEqn(ptEqn) ); }
00243 
00245     int getOffsetIntoBlkEqn(int blkEqn, int ptEqn);
00246 
00248     int getBlkEqnSize(int blkEqn)
00249     {
00250       return( ptBlkMap_->getBlkEqnSize(blkEqn) );
00251     }
00252 
00253   private:
00254     int buildDatabases();
00255 
00256     fei::SharedPtr<fei::MatrixGraph> matGraph_;
00257     snl_fei::PointBlockMap* ptBlkMap_;
00258     fei::SharedPtr<fei::VectorSpace> vspace_;
00259     int nodeIDType_;
00260 
00261     std::map<int, fei::Record<int>*> nodenumPairs_;
00262     std::map<int,fei::Record<int>*> eqnnumPairs_;
00263 
00264     std::map<int,std::vector<int>*> nodenumSubdomainDB_;
00265 
00266     bool databasesBuilt_;
00267 
00268     std::vector<int> fieldIDs_;
00269     std::vector<int> fieldSizes_;
00270     std::vector<GlobalID> elemBlockIDs_;
00271     std::vector<const int*> fieldIDs_2D_;
00272     std::vector<int> workspace_;
00273   };//class Lookup_Impl
00274 }//namespace fei
00275 
00276 #endif // _fei_Lookup_Impl_hpp_
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Friends
Generated on Wed Apr 13 10:08:24 2011 for FEI by  doxygen 1.6.3