1 #ifndef _SNL_FEI_Structure_hpp_
2 #define _SNL_FEI_Structure_hpp_
12 #include <fei_fwd.hpp>
14 #include <fei_constants.hpp>
15 #include "fei_TemplateUtils.hpp"
16 #include <snl_fei_PointBlockMap.hpp>
17 #include <fei_EqnBuffer.hpp>
18 #include <fei_FieldDofMap.hpp>
19 #include <fei_CSRMat.hpp>
20 #include <fei_CSVec.hpp>
22 #include <fei_NodeCommMgr.hpp>
23 #include <fei_NodeDatabase.hpp>
24 #include <fei_NodeDescriptor.hpp>
26 #include <fei_Lookup.hpp>
73 int parameters(
int numParams,
const char*
const* paramStrings);
75 int initFields(
int numFields,
const int* fieldSizes,
const int* fieldIDs,
76 const int* fieldTypes = NULL);
78 int initElemBlock(GlobalID elemBlockID,
80 int numNodesPerElement,
81 const int* numFieldsPerNode,
82 const int*
const* nodalFieldIDs,
83 int numElemDofFieldsPerElement,
84 const int* elemDofFieldIDs,
85 int interleaveStrategy);
87 int initElem(GlobalID elemBlockID,
89 const GlobalID* elemConn);
91 int initSlaveVariable(GlobalID slaveNodeID,
93 int offsetIntoSlaveField,
95 const GlobalID* masterNodeIDs,
96 const int* masterFieldIDs,
97 const double* weights,
102 int initSharedNodes(
int numSharedNodes,
103 const GlobalID *sharedNodeIDs,
104 const int* numProcsPerNode,
105 const int *
const *sharingProcIDs);
109 int initCRMult(
int numCRNodes,
110 const GlobalID* CRNodes,
115 int initCRPen(
int numCRNodes,
116 const GlobalID* CRNodes,
120 int initComplete(
bool generateGraph =
true);
122 const std::vector<int>& getFieldIDs()
const
123 {
return fieldIDs_; }
128 int len = fieldDatabase_->size();
129 workarray_.resize(len*2);
130 fei::copyToArrays<std::map<int,int> >(*fieldDatabase_, len,
133 return( &workarray_[0] );
139 int len = fieldDatabase_->size();
140 workarray_.resize(len*2);
141 fei::copyToArrays<std::map<int,int> >(*fieldDatabase_, len,
144 return( &workarray_[0]+len );
153 std::map<int,int>::const_iterator
154 f_iter = fieldDatabase_->find(fieldID);
156 return(f_iter != fieldDatabase_->end() ? (*f_iter).second : -1);
160 {
return fieldDofMap_; }
191 int& interleaveStrategy,
int& lumpingStrategy,
192 int& numElemDOF,
int& numElements,
193 int& numNodesPerElem,
int& numEqnsPerElem);
195 int addBlock(GlobalID blockID);
209 if (index < blockIDs_.size())
return blockIDs_[index];
213 int allocateBlockConnectivity(GlobalID blockID);
214 void destroyConnectivityTables();
218 void getScatterIndices_ID(GlobalID blockID, GlobalID elemID,
219 int interleaveStrategy,
220 int* scatterIndices);
222 void getScatterIndices_index(
int blockIndex,
int elemIndex,
223 int interleaveStrategy,
224 int* scatterIndices);
226 int getBlkScatterIndices_index(
int blockIndex,
228 int* scatterIndices);
230 void getScatterIndices_ID(GlobalID blockID, GlobalID elemID,
231 int interleaveStrategy,
233 int* blkScatterIndices,
236 void getScatterIndices_index(
int blockIndex,
int elemIndex,
237 int interleaveStrategy,
239 int* blkScatterIndices,
249 return(&(nodeCommMgr_->getSharedNodeNumbers())[0]);
253 int index = nodeCommMgr_->getSharedNodeIndex_num(nodeNumber);
254 if (index < 0)
return(NULL);
255 return(&(nodeCommMgr_->getSharedNodeProcs(index))[0]);
259 int index = nodeCommMgr_->getSharedNodeIndex_num(nodeNumber);
260 if (index < 0)
return(-1);
261 return(nodeCommMgr_->getSharedNodeProcs(index).size());
267 if (err != 0)
return(-1);
268 GlobalID nodeID = node->getGlobalNodeID();
269 return(nodeCommMgr_->getSharedNodeNumSubdomains(nodeID));
275 if (err != 0)
return(NULL);
276 GlobalID nodeID = node->getGlobalNodeID();
277 return(&(*(nodeCommMgr_->getSharedNodeSubdomainList(nodeID)))[0]);
281 int translateToReducedNodeNumber(
int nodeNumber,
int proc);
290 int reducedNodeNumber = -1;
291 if (nodeNumber >= 0) {
292 reducedNodeNumber = translateToReducedNodeNumber(nodeNumber, localProc_);
294 return( reducedNodeNumber );
326 int getNumActiveNodes() {
return(nodeDatabase_->
getNodeIDs().size());}
328 NodeDatabase& getNodeDatabase() {
return( *nodeDatabase_ ); }
330 std::map<GlobalID,int>& getActiveNodeIDList()
333 std::vector<int>& getGlobalNodeOffsets() {
return(globalNodeOffsets_);}
334 std::vector<int>& getGlobalEqnOffsets() {
return(globalEqnOffsets_);}
335 std::vector<int>& getGlobalBlkEqnOffsets() {
return(globalBlkEqnOffsets_);}
337 NodeCommMgr& getNodeCommMgr() {
return(*nodeCommMgr_);}
338 EqnCommMgr& getEqnCommMgr() {
return(*eqnCommMgr_ );}
340 void initializeEqnCommMgr();
342 void getEqnInfo(
int& numGlobalEqns,
int& numLocalEqns,
343 int& localStartRow,
int& localEndRow);
345 int getEqnNumbers(GlobalID ID,
int idType,
int fieldID,
346 int& numEqns,
int* eqnNumbers);
348 int getEqnNumbers(
int numIDs,
const GlobalID* IDs,
349 int idType,
int fieldID,
350 int& numEqns,
int* eqnNumbers);
352 void getEqnBlkInfo(
int& numGlobalEqnBlks,
int& numLocalEqnBlks,
353 int& localBlkOffset);
357 void destroyMatIndices();
359 int getNumMultConstRecords() {
return(multCRs_.size());};
361 std::map<GlobalID,snl_fei::Constraint<GlobalID>*>&
362 getMultConstRecords()
367 std::map<int,snl_fei::Constraint<GlobalID>*>::iterator
368 cr_iter = multCRs_.find(CRID);
370 if (cr_iter != multCRs_.end()) {
371 multCR = (*cr_iter).second;
375 return( returncode );
378 int getNumPenConstRecords() {
return(penCRs_.size());}
379 std::map<GlobalID,snl_fei::Constraint<GlobalID>*>&
385 std::map<int,snl_fei::Constraint<GlobalID>*>::iterator
386 cr_iter = penCRs_.find(CRID);
388 if (cr_iter != penCRs_.end()) {
389 penCR = (*cr_iter).second;
393 return( returncode );
396 void addSlaveVariable(
SlaveVariable* svar) {slaveVars_->push_back(svar);}
398 int calculateSlaveEqns(MPI_Comm comm);
400 fei::FillableMat* getSlaveDependencies() {
return(slaveMatrix_);}
402 EqnBuffer* getSlaveEqns() {
return(slaveEqns_); }
404 int numSlaveEquations() {
return(numSlvs_); }
476 int getNumGlobalEqns() {
return( numGlobalEqns_ ); }
477 int getNumLocalEqns() {
return( numLocalEqns_ ); }
478 int getFirstLocalEqn() {
return( localStartRow_ ); }
479 int getLastLocalEqn() {
return( localEndRow_ ); }
481 int getFirstReducedEqn() {
return( reducedStartRow_ ); }
482 int getLastReducedEqn() {
return( reducedEndRow_ ); }
484 int getNumGlobalEqnBlks() {
return( numGlobalEqnBlks_ ); }
485 int getNumLocalEqnBlks() {
return( numLocalEqnBlks_ ); }
486 int getNumLocalReducedEqnBlks() {
return( numLocalReducedEqnBlks_ ); }
487 int getGlobalMaxBlkSize() {
return(globalMaxBlkSize_); }
489 int getNumLocalReducedEqns() {
return( numLocalReducedRows_ ); }
491 int getMatrixRowLengths(std::vector<int>& rowLengths);
492 int getMatrixStructure(
int** colIndices, std::vector<int>& rowLengths);
494 int getMatrixStructure(
int** ptColIndices, std::vector<int>& ptRowLengths,
495 int** blkColIndices,
int* blkIndices_1D,
496 std::vector<int>& blkRowLengths,
497 std::vector<int>& numPtRowsPerBlkRow);
499 static int gatherSlaveEqns(MPI_Comm comm,
503 static int removeCouplings(
EqnBuffer& eqnbuf,
int& levelsOfCoupling);
505 int calcTotalNumElemDOF();
506 int calcNumMultCREqns();
508 MPI_Comm getCommunicator()
const {
return( comm_ ); }
510 #ifdef FEI_HAVE_IOSFWD
511 int setDbgOut(std::ostream& ostr,
const char* path,
const char* feiName);
513 int setDbgOut(ostream& ostr,
const char* path,
const char* feiName);
527 int writeEqn2NodeMap();
529 int getElemNodeDescriptors(
int blockIndex,
int elemIndex,
534 int* scatterIndices,
int& offset);
538 int* scatterIndices,
int& offset,
539 int* blkScatterIndices,
540 int* blkSizes,
int& blkOffset);
543 int** fieldIDs,
int* fieldsPerNode,
544 int* scatterIndices,
int& offset);
547 int* scatterIndices,
int& offset);
550 int** fieldIDs,
int* fieldsPerNode,
551 int* scatterIndices,
int& offset,
552 int* blkScatterIndices,
553 int* blkSizes,
int& blkOffset);
556 std::vector<int>* fieldIDs,
557 std::vector<int>& fieldsPerNode,
558 std::vector<int>& scatterIndices);
561 int** fieldIDs,
int* fieldsPerNode,
562 int* scatterIndices,
int& offset);
565 std::vector<int>* fieldIDs,
566 std::vector<int>& fieldsPerNode,
567 std::vector<int>& scatterIndices);
569 void calcGlobalEqnInfo(
int numLocallyOwnedNodes,
571 int numLocalEqnBlks);
573 int finalizeActiveNodes();
574 int finalizeNodeCommMgr();
575 bool activeNodesInitialized();
577 int formMatrixStructure();
579 int initElemBlockStructure();
580 int initMultCRStructure();
581 int initPenCRStructure();
582 int createMatrixPosition(
int row,
int col,
const char* callingFunction);
583 int createMatrixPositions(
int row,
int numCols,
int* cols,
584 const char* callingFunction);
587 int createSymmEqnStructure(std::vector<int>& scatterIndices);
588 int createBlkSymmEqnStructure(std::vector<int>& scatterIndices);
590 int storeElementScatterIndices(std::vector<int>& scatterIndices);
591 int storeElementScatterIndices_noSlaves(std::vector<int>& scatterIndices);
592 int storeElementScatterBlkIndices_noSlaves(std::vector<int>& scatterIndices);
598 void storeNodalRowIndices(
NodeDescriptor& node,
int fieldID,
int eqn);
599 void storeNodalSendIndex(
NodeDescriptor& node,
int fieldID,
int col);
603 int assembleReducedStructure();
605 bool nodalEqnsAllSlaves(
const NodeDescriptor* node, std::vector<int>& slaveEqns);
607 int initializeBlkEqnMapper();
609 int setNumNodesAndEqnsPerBlock();
611 void destroyBlockRoster();
613 #ifdef FEI_HAVE_IOSFWD
614 std::ostream& dbgOut() {
return( *dbgOStreamPtr_ ); }
616 ostream& dbgOut() {
return( *dbgOStreamPtr_ ); }
623 int setNodalEqnInfo();
624 void setElemDOFEqnInfo();
625 int setMultCREqnInfo();
632 int localProc_, masterProc_, numProcs_;
634 std::vector<int> fieldIDs_;
635 std::vector<int> fieldSizes_;
636 std::map<int,int>* fieldDatabase_;
638 std::vector<int> workarray_;
640 std::vector<GlobalID> blockIDs_;
641 std::vector<BlockDescriptor*> blocks_;
642 std::vector<ConnectivityTable*> connTables_;
646 bool activeNodesInitialized_;
648 std::vector<int> globalNodeOffsets_;
649 std::vector<int> globalEqnOffsets_;
650 std::vector<int> globalBlkEqnOffsets_;
652 std::vector<SlaveVariable*>* slaveVars_;
654 std::vector<int>* slvEqnNumbers_;
655 int numSlvs_, lowestSlv_, highestSlv_;
656 fei::FillableMat* slaveMatrix_;
657 std::vector<int> globalNumNodesVanished_;
658 std::vector<int> localVanishedNodeNumbers_;
669 int numLocalNodalEqns_;
670 int numLocalElemDOF_;
671 int numLocalMultCRs_;
673 int reducedStartRow_, reducedEndRow_, numLocalReducedRows_;
674 fei::FillableMat *Kid_, *Kdi_, *Kdd_;
675 fei::CSRMat csrD, csrKid, csrKdi, csrKdd, tmpMat1_, tmpMat2_;
676 int reducedEqnCounter_, reducedRHSCounter_;
677 std::vector<int> rSlave_, cSlave_;
678 std::vector<NodeDescriptor*> work_nodePtrs_;
680 bool structureFinalized_;
686 int numGlobalEqnBlks_;
687 int numLocalEqnBlks_;
688 int numLocalReducedEqnBlks_;
690 int localReducedBlkOffset_;
691 int globalMaxBlkSize_;
693 int firstLocalNodeNumber_;
697 bool matIndicesDestroyed_;
699 std::vector<int> workSpace_;
703 std::map<GlobalID, snl_fei::Constraint<GlobalID>* > multCRs_;
705 std::map<GlobalID, snl_fei::Constraint<GlobalID>* > penCRs_;
707 bool checkSharedNodes_;
713 std::string dbgPath_;
714 #ifdef FEI_HAVE_IOSFWD
715 std::ostream* dbgOStreamPtr_;
717 ostream* dbgOStreamPtr_;
719 bool setDbgOutCalled_;
int translateMatToReducedEqns(fei::CSRMat &mat)
int getFieldSize(int fieldID)
const int * getFieldIDsPtr()
int getNumSharingProcs(int nodeNumber)
int getBlockDescriptor_index(int index, BlockDescriptor *&block)
std::map< GlobalID, int > & getNodeIDs()
int getNodeWithNumber(int nodeNumber, const NodeDescriptor *&node) const
SNL_FEI_Structure(MPI_Comm comm)
int getMasterEqnRHS(int slaveEqn, double &rhsValue)
int getBlockID(unsigned index) const
int ptEqnToBlkEqn(int ptEqn)
const int * getSharedNodeNumbers()
int getMasterEqnCoefs(int slaveEqn, std::vector< double > *&masterCoefs)
int getNumSubdomains(int nodeNumber)
bool isExactlyBlkEqn(int ptEqn)
const int * getFieldSizesPtr()
int getBlkEqnSize(int blkEqn)
int getMasterEqnNumbers(int slaveEqn, std::vector< int > *&masterEqns)
int getOffsetIntoBlkEqn(int blkEqn, int ptEqn)
bool isExactlyBlkEqn(int ptEqn)
virtual ~SNL_FEI_Structure()
const int * getSharedNodeProcs(int nodeNumber)
int getBlkEqnOffset(int blkEqn, int ptEqn)
int translateToReducedEqns(EqnCommMgr &eqnCommMgr)
bool isInLocalElement(int nodeNumber)
int getAssociatedFieldID(int eqnNumber)
const int * getNumFieldsPerNode(GlobalID blockID)
int eqnToBlkEqn(int eqn) const
int getAssociatedFieldID(int eqnNumber)
bool translateToReducedEqn(int eqn, int &reducedEqn)
int getOwnerProcForEqn(int eqn)
int * getSubdomainList(int nodeNumber)
int getAssociatedNodeNumber(int eqnNumber)
int getAssociatedNodeNumber(int eqnNumber)
int getBlkEqnSize(int blkEqn)
int translateFromReducedEqn(int reducedEqn)
const GlobalID * getElemBlockIDs()
int parameters(int numParams, const char *const *paramStrings)
void getElemBlockInfo(GlobalID blockID, int &interleaveStrategy, int &lumpingStrategy, int &numElemDOF, int &numElements, int &numNodesPerElem, int &numEqnsPerElem)
int getIndexOfBlock(GlobalID blockID) const
const int *const * getFieldIDsTable(GlobalID blockID)
int getEqnNumber(int nodeNumber, int fieldID)