FEI  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
fei_Lookup_Impl.hpp
1 /*--------------------------------------------------------------------*/
2 /* Copyright 2005 Sandia Corporation. */
3 /* Under the terms of Contract DE-AC04-94AL85000, there is a */
4 /* non-exclusive license for use of this work by or on behalf */
5 /* of the U.S. Government. Export of this program may require */
6 /* a license from the United States Government. */
7 /*--------------------------------------------------------------------*/
8 
9 #ifndef _fei_Lookup_Impl_hpp_
10 #define _fei_Lookup_Impl_hpp_
11 
12 #include <fei_macros.hpp>
13 #include <fei_MatrixGraph.hpp>
14 #include <fei_Pattern.hpp>
15 #include <fei_ConnectivityBlock.hpp>
16 #include <fei_SharedIDs.hpp>
17 #include <snl_fei_RecordCollection.hpp>
18 #include <snl_fei_PointBlockMap.hpp>
19 #include <fei_TemplateUtils.hpp>
20 #include <fei_Lookup.hpp>
21 
22 #include <vector>
23 
24 namespace fei {
27  class Lookup_Impl : public virtual Lookup {
28  public:
31  int nodeIDType);
32 
34  virtual ~Lookup_Impl();
35 
37  int getNumFields()
38  {
39  return( vspace_->getNumFields() );
40  }
41 
43  int getFieldSize(int fieldID)
44  {
45  return(vspace_->getFieldSize(fieldID));
46  }
47 
49  const int* getFieldIDsPtr()
50  {
51  int len = getNumFields();
52  if (len < 1) return(NULL);
53 
54  vspace_->getFields(fieldIDs_);
55  return(&fieldIDs_[0]);
56  }
57 
59  const int* getFieldSizesPtr()
60  {
61  const int* fieldIDs = getFieldIDsPtr();
62  if (fieldIDs == NULL) return(NULL);
63 
64  unsigned numFields = fieldIDs_.size();
65  fieldSizes_.resize(numFields);
66  int* fsPtr = &fieldSizes_[0];
67  for(unsigned i=0; i<numFields; ++i) {
68  fsPtr[i] = vspace_->getFieldSize(fieldIDs[i]);
69  }
70  return(fsPtr);
71  }
72 
74  int getNumElemBlocks()
75  { return(matGraph_->getConnectivityBlocks().size()); }
76 
78  const GlobalID* getElemBlockIDs()
79  {
80  int err = matGraph_->getConnectivityBlockIDs(elemBlockIDs_);
81  return(err==0 ? &elemBlockIDs_[0] : NULL);
82  }
83 
85  void getElemBlockInfo(GlobalID blockID,
86  int& interleaveStrategy, int& lumpingStrategy,
87  int& numElemDOF, int& numElements,
88  int& numNodesPerElem, int& numEqnsPerElem)
89  {
90  interleaveStrategy = 0; lumpingStrategy = 0;
91  numElemDOF = 0;
92  const fei::ConnectivityBlock* cblock =
93  matGraph_->getConnectivityBlock(blockID);
94  numElements = cblock->getConnectivityIDs().size();
95  numNodesPerElem = cblock->getRowPattern()->getNumIDs();
96  numEqnsPerElem = cblock->getRowPattern()->getNumIndices();
97  }
98 
100  const int* getNumFieldsPerNode(GlobalID blockID)
101  {
102  const fei::ConnectivityBlock* cblock = matGraph_->getConnectivityBlock(blockID);
103  if (cblock==NULL) return(NULL);
104  return(cblock->getRowPattern()->getNumFieldsPerID());
105  }
106 
108  const int* const* getFieldIDsTable(GlobalID blockID)
109  {
110  const fei::ConnectivityBlock* cblock = matGraph_->getConnectivityBlock(blockID);
111  if (cblock==NULL) return(NULL);
112  int numNodes = cblock->getRowPattern()->getNumIDs();
113  const int* numFieldsPerNode = cblock->getRowPattern()->getNumFieldsPerID();
114  const int* fieldIDs = cblock->getRowPattern()->getFieldIDs();
115  fieldIDs_2D_.resize(numNodes);
116  const int** f2dPtr = &fieldIDs_2D_[0];
117  int offset = 0;
118  for(int i=0; i<numNodes; ++i) {
119  f2dPtr[i] = fieldIDs + offset;
120  offset += numFieldsPerNode[i];
121  }
122  return(f2dPtr);
123  }
124 
126  int getEqnNumber(int nodeNumber, int fieldID);
127 
129  int getAssociatedNodeNumber(int eqnNumber);
130 
131  int getAssociatedNodeID(int eqnNumber);
132 
134  int getAssociatedFieldID(int eqnNumber);
135 
137  bool isInLocalElement(int nodeNumber);
138 
140  int getNumSubdomains(int nodeNumber)
141  {
142  std::vector<int>* subdomains = NULL;
143  std::map<int,std::vector<int>* >::iterator
144  nns_iter = nodenumSubdomainDB_.find(nodeNumber);
145  if (nns_iter != nodenumSubdomainDB_.end()) subdomains = (*nns_iter).second;
146  return( subdomains==0 ? 0 : subdomains->size() );
147  }
148 
150  int* getSubdomainList(int nodeNumber)
151  {
152  std::vector<int>* subdomains = NULL;
153  std::map<int,std::vector<int>* >::iterator
154  nns_iter = nodenumSubdomainDB_.find(nodeNumber);
155  if (nns_iter != nodenumSubdomainDB_.end()) subdomains = (*nns_iter).second;
156 
157  return( subdomains==0 ? NULL : &(*subdomains)[0] );
158  }
159 
161  int getNumSharedNodes()
162  {
163  int numShared;
164  int err = vspace_->getNumSharedIDs(nodeIDType_, numShared);
165  return(err==0 ? numShared : -1);
166  }
167 
169  const int* getSharedNodeNumbers()
170  {
171  fei::SharedIDs<int>& sharedIDs = vspace_->getSharedIDs(nodeIDType_);
172 
173  int numShared = sharedIDs.getSharedIDs().size();
174  workspace_.resize(numShared*2);
175  int* wkPtr = &workspace_[0];
176  fei::copyKeysToArray(sharedIDs.getSharedIDs(), numShared, wkPtr);
177 
178  snl_fei::RecordCollection* collection = NULL;
179  vspace_->getRecordCollection(nodeIDType_, collection);
180 
181  for(int i=0; i<numShared; ++i) {
182  fei::Record<int>* node = collection->getRecordWithID(wkPtr[i]);
183  if (node == NULL) return NULL;
184 
185  wkPtr[numShared+i] = node->getNumber();
186  }
187  return(wkPtr+numShared);
188  }
189 
191  const int* getSharedNodeProcs(int nodeNumber)
192  {
193  std::map<int,fei::Record<int>*>::iterator
194  nnp_iter = nodenumPairs_.find(nodeNumber);
195 
196  if (nnp_iter == nodenumPairs_.end()) return(0);
197 
198  fei::Record<int>* node = (*nnp_iter).second;
199 
200  const fei::SharedIDs<int>& sharedIDs = vspace_->getSharedIDs(nodeIDType_);
201 
202  int shID = node->getID();
203 
205  iter = sharedIDs.getSharedIDs().find(shID);
206  if (iter == sharedIDs.getSharedIDs().end()) return(NULL);
207 
208  const std::set<int>& shprocs = iter->second;
209 
210  fei::copySetToVector(shprocs, workspace_);
211  return(&workspace_[0]);
212  }
213 
215  int getNumSharingProcs(int nodeNumber)
216  {
217  std::map<int,fei::Record<int>*>::iterator
218  nnp_iter = nodenumPairs_.find(nodeNumber);
219 
220  if (nnp_iter == nodenumPairs_.end()) return(0);
221 
222  fei::Record<int>* node = (*nnp_iter).second;
223 
224  const fei::SharedIDs<int>& sharedIDs = vspace_->getSharedIDs(nodeIDType_);
225 
226  int shID = node->getID();
227 
229  iter = sharedIDs.getSharedIDs().find(shID);
230  if (iter == sharedIDs.getSharedIDs().end()) return(0);
231 
232  const std::set<int>& shprocs = iter->second;
233  return(shprocs.size());
234  }
235 
237  bool isExactlyBlkEqn(int ptEqn)
238  { return( ptBlkMap_->isExactlyBlkEqn(ptEqn) ); }
239 
241  int ptEqnToBlkEqn(int ptEqn)
242  { return( ptBlkMap_->eqnToBlkEqn(ptEqn) ); }
243 
245  int getOffsetIntoBlkEqn(int blkEqn, int ptEqn);
246 
248  int getBlkEqnSize(int blkEqn)
249  {
250  return( ptBlkMap_->getBlkEqnSize(blkEqn) );
251  }
252 
253  private:
254  int buildDatabases();
255 
257  snl_fei::PointBlockMap* ptBlkMap_;
259  int nodeIDType_;
260 
261  std::map<int, fei::Record<int>*> nodenumPairs_;
262  std::map<int,fei::Record<int>*> eqnnumPairs_;
263 
264  std::map<int,std::vector<int>*> nodenumSubdomainDB_;
265 
266  bool databasesBuilt_;
267 
268  std::vector<int> fieldIDs_;
269  std::vector<int> fieldSizes_;
270  std::vector<GlobalID> elemBlockIDs_;
271  std::vector<const int*> fieldIDs_2D_;
272  std::vector<int> workspace_;
273  };//class Lookup_Impl
274 }//namespace fei
275 
276 #endif // _fei_Lookup_Impl_hpp_
GlobalIDType getNumber() const
int getBlkEqnSize(int blkEqn)
const std::map< int, int > & getConnectivityIDs() const
const int * getSharedNodeProcs(int nodeNumber)
int getNumIndices() const
map_type & getSharedIDs()
const int * getNumFieldsPerID() const
void copySetToVector(const std::set< T > &set_obj, std::vector< T > &vec)
Lookup_Impl(fei::SharedPtr< fei::MatrixGraph > matGraph, int nodeIDType)
int getAssociatedFieldID(int eqnNumber)
int * getSubdomainList(int nodeNumber)
int getNumSubdomains(int nodeNumber)
virtual const fei::ConnectivityBlock * getConnectivityBlock(int blockID) const =0
const int * getFieldIDs() const
bool isExactlyBlkEqn(int ptEqn)
int getAssociatedNodeNumber(int eqnNumber)
const int *const * getFieldIDsTable(GlobalID blockID)
virtual std::map< int, fei::ConnectivityBlock * > & getConnectivityBlocks()=0
void copyKeysToArray(const MAP_TYPE &map_obj, unsigned lenList, int *list)
const GlobalID * getElemBlockIDs()
int ptEqnToBlkEqn(int ptEqn)
int getNumSharingProcs(int nodeNumber)
int eqnToBlkEqn(int eqn) const
int getNumSharedIDs(int idType, int &numShared)
void getFields(std::vector< int > &fieldIDs)
const int * getNumFieldsPerNode(GlobalID blockID)
int getFieldSize(int fieldID)
int getNumIDs() const
const int * getFieldSizesPtr()
const int * getSharedNodeNumbers()
void getElemBlockInfo(GlobalID blockID, int &interleaveStrategy, int &lumpingStrategy, int &numElemDOF, int &numElements, int &numNodesPerElem, int &numEqnsPerElem)
int getEqnNumber(int nodeNumber, int fieldID)
const int * getFieldIDsPtr()
GlobalIDType getID() const
unsigned getFieldSize(int fieldID)
bool isInLocalElement(int nodeNumber)
virtual int getConnectivityBlockIDs(std::vector< int > &blockIDs) const =0
int getRecordCollection(int idType, snl_fei::RecordCollection *&records)
int getOffsetIntoBlkEqn(int blkEqn, int ptEqn)
const fei::Pattern * getRowPattern() const