9 #include <fei_NodeDatabase.hpp>
11 #include <fei_CommUtils.hpp>
12 #include <fei_NodeDescriptor.hpp>
13 #include <fei_NodeCommMgr.hpp>
15 #include <fei_macros.hpp>
16 #include <fei_TemplateUtils.hpp>
18 #define fei_file "fei_NodeDatabase.cpp"
20 #include <fei_ErrMacros.hpp>
26 eqnNumbers_(0), eqnNodeIndices_(),
30 need_to_alloc_and_sync_(true),
31 fieldDB_(fieldDatabase),
32 nodeCommMgr_(nodeCommMgr),
34 firstLocalNodeNumber_(-1), lastLocalNodeNumber_(-1),
46 void NodeDatabase::deleteMemory()
48 for(
size_t i=0; i<nodePtrs_.size(); ++i) {
49 nodePool_.destroy(nodePtrs_[i]);
50 nodePool_.deallocate(nodePtrs_[i], 1);
63 node = nodePtrs_[index];
76 node = nodePtrs_[index];
83 if (!synchronized_) ERReturn(-1);
85 std::map<int,int>::const_iterator iter = nodeNumbers_.find(nodeNumber);
86 if (iter == nodeNumbers_.end()) {
93 int index = iter->second;
94 node = nodePtrs_[index];
102 int insertPoint = -1;
106 node = nodePtrs_[eqnNodeIndices_[index]];
108 else if (insertPoint > 0) {
109 node = nodePtrs_[eqnNodeIndices_[insertPoint-1]];
121 int numNodeFields = node->getNumFields();
122 if (numNodeFields <= 0)
return(-1);
124 int lastFieldOnNode = node->getFieldIDList()[numNodeFields-1];
126 int lastFieldSize = (*fieldDB_)[lastFieldOnNode];
128 int lastEqnOnNode = node->getFieldEqnNumbers()[numNodeFields-1] +
131 if (eqnNumber <= lastEqnOnNode)
return(0);
139 int nnodes = nodePtrs_.size();
140 if (i>=0 && i < nnodes) {
151 int nnodes = nodePtrs_.size();
152 if (i>=0 && i < nnodes) {
165 for(
size_t i=0; i<nodePtrs_.size(); i++) {
168 if (node->getOwnerProc() == localRank) {
169 int numFields = node->getNumFields();
170 const int* fieldIDList = node->getFieldIDList();
172 for(
int j=0; j<numFields; j++) {
173 int numParams = (*fieldDB_)[fieldIDList[j]];
175 numEqns += numParams;
187 for(
size_t i=0; i<nodePtrs_.size(); i++) {
188 if (nodePtrs_[i]->getOwnerProc() == localRank) numLocal++;
197 std::map<GlobalID,int>::const_iterator
198 iter = nodeIDs_.find(nodeID);
200 if (iter == nodeIDs_.end())
return(-1);
202 return( iter->second );
210 int index = nodeIDs_.size();
211 std::map<GlobalID,int>::iterator
212 iter = nodeIDs_.lower_bound(nodeID);
214 if (iter == nodeIDs_.end() || iter->first != nodeID) {
215 nodeIDs_.insert(iter, std::make_pair(nodeID,index));
218 nodePool_.construct(nodePtr, dummyNode);
220 nodePtr->setGlobalNodeID(nodeID);
222 nodePtrs_.push_back(nodePtr);
224 need_to_alloc_and_sync_ =
true;
235 for(
int i=0; i<numNodes; i++) {
248 eqnNumbers_.reserve(nodePtrs_.size());
249 eqnNodeIndices_.reserve(nodePtrs_.size());
251 eqnNumbers_.resize(0);
252 eqnNodeIndices_.resize(0);
254 firstLocalNodeNumber_ = firstLocalNodeNumber;
255 int nodeNumber = firstLocalNodeNumber;
258 nodeNumbers_.clear();
261 std::map<GlobalID,int>::iterator
262 iter = nodeIDs_.begin(), iter_end = nodeIDs_.end();
264 for(; iter!=iter_end; ++iter) {
265 int i = iter->second;
268 if (node==NULL)
continue;
270 int numFields = node->getNumFields();
271 const int* fieldIDList = node->getFieldIDList();
274 int firstEqnNumber, eqnNumber;
276 for(
int j=0; j<numFields; j++) {
277 int numFieldParams = (*fieldDB_)[fieldIDList[j]];
278 numNodalDOF += numFieldParams;
280 if (node->getOwnerProc() == localRank) {
281 eqnNumber = firstLocalEqn + numEqns;
282 if (j==0) firstEqnNumber = eqnNumber;
284 numEqns += numFieldParams;
286 node->setFieldEqnNumber(fieldIDList[j], eqnNumber);
290 if (node->getOwnerProc() == localRank) {
291 node->setNodeNumber(nodeNumber++);
295 if (insertPoint == -2) ERReturn(-2);
296 if (insertPoint >= 0) eqnNodeIndices_.insert(eqnNodeIndices_.begin()+insertPoint, i);
299 node->setNumNodalDOF(numNodalDOF);
301 int thisNodeNumber = node->getNodeNumber();
302 nodeNumbers_.insert(std::make_pair(thisNodeNumber, i));
305 lastLocalNodeNumber_ = nodeNumber - 1;
312 CHK_ERR( nodeCommMgr_->exchangeEqnInfo() );
317 int numSharedNodes = nodeCommMgr_->getNumSharedNodes();
318 for(
int i=0; i<numSharedNodes; i++) {
320 GlobalID nodeID = node.getGlobalNodeID();
322 int nDOF = node.getNumNodalDOF();
328 int firstEqn = node.getFieldEqnNumbers()[0];
330 if (insertPoint == -2) ERReturn(-2);
331 if (insertPoint >= 0) eqnNodeIndices_.insert(eqnNodeIndices_.begin()+insertPoint, index);
333 int thisNodeNumber = node.getNodeNumber();
334 nodeNumbers_.insert(std::make_pair(thisNodeNumber, index));
337 synchronized_ =
true;
338 need_to_alloc_and_sync_ =
false;
346 int insertPoint = -1;
350 return( nodePtrs_[eqnNodeIndices_[index]]->getNodeNumber() );
353 if (insertPoint > 0) {
354 NodeDescriptor& node = *(nodePtrs_[eqnNodeIndices_[insertPoint-1]]);
355 const int* fieldEqnNumbers = node.getFieldEqnNumbers();
356 const int* fieldIDList = node.getFieldIDList();
357 int numFields = node.getNumFields();
359 int lastEqn = fieldEqnNumbers[numFields-1];
362 std::map<int,int>::const_iterator f_iter
363 = fieldDB_->find(fieldIDList[numFields-1]);
364 if (f_iter == fieldDB_->end()) ERReturn(-1);
365 fieldSize = (*f_iter).second;
369 if (eqnNumber >= fieldEqnNumbers[0] && (lastEqn+fieldSize - 1) >= eqnNumber) {
370 return( node.getNodeNumber() );
382 int insertPoint = -1;
386 if (index2 < 0) index2 = insertPoint-1;
388 if (index2 < 0) ERReturn(-1);
392 const int* fieldEqnNumbers = node.getFieldEqnNumbers();
393 const int* fieldIDList = node.getFieldIDList();
394 int numFields = node.getNumFields();
396 int lastEqn = fieldEqnNumbers[numFields-1];
399 std::map<int,int>::const_iterator f_iter
400 = fieldDB_->find(fieldIDList[numFields-1]);
401 if (f_iter == fieldDB_->end()) ERReturn(-1);
402 fieldSize = (*f_iter).second;
406 if (eqnNumber < fieldEqnNumbers[0] || eqnNumber > lastEqn+fieldSize) {
411 for(
int i=0; i<numFields-1; i++) {
412 if (eqnNumber >= fieldEqnNumbers[i] && eqnNumber < fieldEqnNumbers[i+1]) {
413 return(fieldIDList[i]);
419 return(fieldIDList[numFields-1]);
int sortedListInsert(const T &item, std::vector< T > &list)
int countLocalNodeDescriptors(int localRank)
int getNodeWithNumber(int nodeNumber, const NodeDescriptor *&node) const
int initNodeID(GlobalID nodeID)
int binarySearch(const T &item, const T *list, int len)
int getNodeWithEqn(int eqnNumber, const NodeDescriptor *&node) const
int synchronize(int firstLocalNodeNumber, int firstLocalEqn, int localRank, MPI_Comm comm)
NodeDatabase(std::map< int, int > *fieldDatabase, NodeCommMgr *nodeCommMgr)
int getIndexOfID(GlobalID nodeID) const
void getNodeAtIndex(int i, const NodeDescriptor *&node) const
int countLocalNodalEqns(int localRank)
int getAssociatedFieldID(int eqnNumber)
int getAssociatedNodeNumber(int eqnNumber)
int getNodeWithID(GlobalID nodeID, const NodeDescriptor *&node) const
int initNodeIDs(GlobalID *nodeIDs, int numNodes)