11 #ifndef PANZER_BLOCKED_DOF_MANAGER_IMPL_HPP
12 #define PANZER_BLOCKED_DOF_MANAGER_IMPL_HPP
31 : fieldsRegistered_(false), maxSubFieldNum_(-1), requireOrientations_(false), useDOFManagerFEI_(true), useTieBreak_(false)
35 : fieldsRegistered_(false), maxSubFieldNum_(-1), requireOrientations_(false), useDOFManagerFEI_(true), useTieBreak_(false)
45 std::map<std::string,int>::const_iterator itr =
fieldStrToNum_.find(str);
51 "BlockedDOFManager::getFieldNum No field with the name \"" + str +
"\" has been added");
60 std::map<int,std::string>::const_iterator itr =
fieldNumToStr_.find(number);
64 std::stringstream ss; ss << number;
67 "BlockedDOFManager::getFieldString No field with number \"" + ss.str() +
"\" has been added");
77 std::map<std::string,std::set<std::string> >::const_iterator fieldsItr =
blockIdToFieldStrings_.find(block);
79 "BlockedDOFManager::fieldInBlock could not find the element block \""+block+
"\"");
82 const std::set<std::string> & fields = fieldsItr->second;
83 std::set<std::string>::const_iterator itr = fields.find(field);
84 return itr!=fields.end();
94 return fieldsItr->second;
97 static std::vector<int> empty;
115 std::vector<panzer::GlobalOrdinal> fieldBlockOwned;
139 std::vector<panzer::GlobalOrdinal> fieldBlockOwned;
143 for(std::size_t i=0;i<fieldBlockOwned.size();i++)
144 gids.push_back(std::make_pair(fbm,fieldBlockOwned[i]));
158 gidsOrientation.resize(0);
162 std::vector<double> blkOrientation;
166 for(std::size_t i=0;i<blkOrientation.size();i++)
167 gidsOrientation.push_back(blkOrientation[i]);
173 typedef std::map<std::string,std::map<int,std::vector<int> > > FieldOffsetsMap;
177 std::map<int,std::vector<int> > & fieldToVectorMap = blockItr->second;
178 std::map<int,std::vector<int> >::const_iterator itr = fieldToVectorMap.find(fieldNum);
181 if(itr!=fieldToVectorMap.end())
185 std::vector<std::string> elementBlocks;
187 TEUCHOS_TEST_FOR_EXCEPTION(std::find(elementBlocks.begin(),elementBlocks.end(),blockId)==elementBlocks.end(),std::logic_error,
188 "BlockedDOFManager::getGIDFieldOffsets: Block ID \""+blockId+
"\" does not exist");
191 blockItr = gidFieldOffsets_.find(blockId);
195 std::map<int,std::vector<int> > & fieldToVectorMap = blockItr->second;
205 const std::vector<int> & subGIDOffsets
206 = dofManager->getGIDFieldOffsets(blockId,dofManager->getFieldNum(
getFieldString(fieldNum)));
210 std::vector<int> & finalFieldOffsets = fieldToVectorMap[fieldNum];
211 finalFieldOffsets.resize(subGIDOffsets.size());
212 for(std::size_t i=0;i<finalFieldOffsets.size();i++)
213 finalFieldOffsets[i] = gidOffset+subGIDOffsets[i];
215 return finalFieldOffsets;
221 if(a[0] < b[0])
return true;
222 if(a[0] > b[0])
return false;
225 if(a[1] < b[1])
return true;
226 if(a[1] > b[1])
return false;
229 if(a[2] < b[2])
return true;
230 if(a[2] > b[2])
return false;
236 const std::pair<std::vector<int>,std::vector<int> > &
242 typename TupleToVectorPairMap::const_iterator itr =
243 fieldToTupleMap.find(Teuchos::tuple(fieldNum,subcellDim,subcellId));
246 if(itr!=fieldToTupleMap.end())
250 std::vector<std::string> elementBlocks;
252 TEUCHOS_TEST_FOR_EXCEPTION(std::find(elementBlocks.begin(),elementBlocks.end(),blockId)==elementBlocks.end(),std::logic_error,
253 "BlockedDOFManager::getGIDFieldOffsets: Block ID \""+blockId+
"\" does not exist");
256 blockItr = gidFieldOffsets_closure_.find(blockId);
270 const std::pair<std::vector<int>,std::vector<int> > & subGIDOffsets_closure
271 = dofManager->getGIDFieldOffsets_closure(blockId,dofManager->getFieldNum(
getFieldString(fieldNum)),subcellDim,subcellId);
275 std::pair<std::vector<int>,std::vector<int> > & finalFieldOffsets = fieldToTupleMap[Teuchos::tuple(fieldNum,subcellDim,subcellId)];
276 finalFieldOffsets.first.resize(subGIDOffsets_closure.first.size());
277 finalFieldOffsets.second = subGIDOffsets_closure.second;
278 for(std::size_t i=0;i<finalFieldOffsets.first.size();i++)
279 finalFieldOffsets.first[i] = gidOffset+subGIDOffsets_closure.first[i];
281 return finalFieldOffsets;
291 using std::make_pair;
296 vector<panzer::GlobalOrdinal> fieldBlockOwned;
311 using std::make_pair;
316 vector<panzer::GlobalOrdinal> fieldBlockGhosted;
331 using std::make_pair;
336 vector<panzer::GlobalOrdinal> fieldBlockOwnedAndGhosted;
338 fieldBlockOwnedAndGhosted);
360 std::vector<int> fieldBlockOwned;
373 using std::make_pair;
378 vector<int> fieldBlockOwned;
389 using std::make_pair;
394 vector<int> fieldBlockGhosted;
405 using std::make_pair;
410 vector<int> fieldBlockOwnedAndGhosted;
412 fieldBlockOwnedAndGhosted);
472 std::vector<std::vector<bool>::const_iterator> blockItrs;
477 blockItrs.push_back(blockIsOwned[fbm].begin());
554 std::vector<std::string> elementBlockIds;
555 connMngr_->getElementBlockIds(elementBlockIds);
558 for(std::size_t i=0;i<elementBlockIds.size();i++)
559 addField(elementBlockIds[i],str,pattern);
566 "BlockedDOFManager::addField: addField cannot be called after registerFields or"
567 "buildGlobalUnknowns has been called");
587 std::set<std::string> fields;
590 std::string fieldName = fieldItr->first.second;
591 fields.insert(fieldName);
596 std::set<std::string>::const_iterator itr;
597 for(itr=fields.begin();itr!=fields.end();itr++) {
598 std::vector<std::string> block;
599 block.push_back(*itr);
608 std::stringstream ss;
610 ss <<
"BlockedDOFManager::registerFields - Field order is invalid!\n";
612 ss <<
" fields = [ ";
613 for(std::set<std::string>::const_iterator itr=fields.begin();
614 itr!=fields.end();++itr)
615 ss <<
"\"" << *itr <<
"\" ";
618 ss <<
" fieldOrder = [ ";
619 for(std::vector<std::vector<std::string> >::const_iterator bitr=
fieldOrder_.begin();
622 for(std::vector<std::string>::const_iterator itr=bitr->begin();
623 itr!=bitr->end();++itr) {
624 ss <<
"\"" << *itr <<
"\" ";
636 for(std::size_t fldBlk=0;fldBlk<
fieldOrder_.size();fldBlk++) {
655 std::map<std::string,int> tempStrToNum;
659 const std::vector<std::string> & activeFields =
fieldOrder_[fldBlk];
662 for(std::size_t f=0;f<activeFields.size();f++) {
663 fieldNum = dofManager->
getFieldNum(activeFields[f]);
664 tempStrToNum[activeFields[f]] = fieldNum;
674 const std::vector<std::string> & activeFields =
fieldOrder_[fldBlk];
676 for(std::size_t f=0;f<activeFields.size();f++) {
678 int fieldNum = tempStrToNum[activeFields[f]]+numOffset;
697 const std::set<std::string> & fields = itr->second;
700 for(std::set<std::string>::const_iterator fldItr=fields.begin();
701 fldItr!=fields.end();++fldItr) {
722 using Teuchos::rcp_dynamic_cast;
728 if(dofManager!=Teuchos::null) {
729 dofManager->setOrientationsRequired(required);
742 using Teuchos::rcp_dynamic_cast;
748 if(dofManager!=Teuchos::null) {
749 dofManager->buildGlobalUnknowns(geomPattern);
759 std::ostream & os)
const
762 using Teuchos::rcp_dynamic_cast;
768 if(dofManager!=Teuchos::null) {
769 dofManager->printFieldInformation(os);
779 const std::string & elementBlock)
const
782 using Teuchos::rcp_dynamic_cast;
786 return indexer->getElementBlockGIDCount(elementBlock);
790 const std::size_t & elementBlock)
const
793 using Teuchos::rcp_dynamic_cast;
797 return indexer->getElementBlockGIDCount(elementBlock);
822 using Teuchos::ptrFromRef;
823 using Teuchos::ptr_dynamic_cast;
825 Ptr<GlobalIndexer> ugi_ptr = ptrFromRef(fieldBlockManager);
829 Ptr<DOFManager> dofManager_ptr = ptr_dynamic_cast<
DOFManager>(ugi_ptr);
831 if(dofManager_ptr!=Teuchos::null) {
845 std::vector<std::size_t> correctnessCheck(activeFields.size(),0);
846 std::vector<std::string> elementBlocks;
850 for(std::size_t eb=0;eb<elementBlocks.size();eb++) {
851 std::string elementBlock = elementBlocks[eb];
854 for(std::size_t f=0;f<activeFields.size();f++) {
855 std::string fieldName = activeFields[f];
858 if(fp!=Teuchos::null) {
859 fieldBlockManager.
addField(elementBlock,fieldName,fp);
860 correctnessCheck[f] = 1;
866 std::size_t correctFlag = std::accumulate(correctnessCheck.begin(),correctnessCheck.end(),0);
868 "BlockedDOFManager::addFieldsToFieldBlockManager detected inconsistincies in the active fields.");
893 std::set<std::string> fields;
896 fields.insert(itr->first.second);
898 return fields.size();
909 using Teuchos::rcp_dynamic_cast;
926 "panzer::BlockedDOFManager::buildGlobalUnknowns: UGI at index " << 0 <<
927 " is not of DOFManager type!");
930 TEUCHOS_TEST_FOR_EXCEPTION(refConnManager!=connManager,std::runtime_error,
931 "panzer::BlockedDOFManager::buildGlobalUnknowns: connection manager for UGI " << 0 <<
932 " does not match the reference connection manager");
934 refGeomPattern = refDofManager->getGeometricFieldPattern();
936 for(std::size_t i=1;i<fieldBlockManagers.size();i++) {
939 TEUCHOS_TEST_FOR_EXCEPTION(refDofManager==Teuchos::null,std::runtime_error,
940 "panzer::BlockedDOFManager::buildGlobalUnknowns: UGI at index " << i <<
941 " is not of DOFManager type!");
946 TEUCHOS_TEST_FOR_EXCEPTION(!refGeomPattern->equals(*geomPattern),std::runtime_error,
947 "panzer::BlockedDOFManager::buildGlobalUnknowns: geometric pattern for UGI " << i <<
948 " does not match the reference pattern (from UGI 0)");
949 TEUCHOS_TEST_FOR_EXCEPTION(refConnManager!=testConnManager,std::runtime_error,
950 "panzer::BlockedDOFManager::buildGlobalUnknowns: connection manager for UGI " << i <<
951 " does not match the reference connection manager (from UGI 0)");
958 std::vector<std::string> eblocks;
961 for(std::size_t i=0;i<fieldBlockManagers.size();i++) {
963 = rcp_dynamic_cast<
const DOFManager>(fieldBlockManagers[i]);
965 for(std::size_t e=0;e<eblocks.size();e++) {
966 const std::vector<int> & fieldIds = dofManager->getBlockFieldNumbers(eblocks[e]);
969 for(std::size_t f=0;f<fieldIds.size();f++) {
971 std::string fieldName = dofManager->getFieldString(fieldIds[f]);
973 = dofManager->getFieldPattern(eblocks[e],fieldName);
976 this->
addField(eblocks[e],fieldName,fieldPattern);
993 std::vector<std::string> elementBlocks;
995 for(std::size_t eb=0;eb<elementBlocks.size();eb++) {
1027 std::vector<std::string> elementBlocks;
1029 for(std::size_t eb=0;eb<elementBlocks.size();eb++) {
1051 std::vector<std::pair<FieldType,RCP<const FieldPattern>>> patVector;
1054 patVector.push_back(std::make_pair(
FieldType::CG,f2p_itr->second));
1061 aggFieldPattern->buildPattern(patVector);
1064 connMngr_->buildConnectivity(*aggFieldPattern);
1072 os <<
"BlockedDOFManager Field Information: " << std::endl;
1077 os <<
"*************************************************\n";
1078 os <<
"Field Block Index = " << fbm << std::endl;
1082 os <<
" Field String to Field Id (blocked/sub):\n";
1083 for(std::size_t i=0;i<
fieldOrder_[fbm].size();i++) {
1086 os <<
" \"" << fieldString <<
"\" is field ID " << fieldNum
1094 os <<
"Fields not yet registered! Unknowns not built (call registerFields or buildGlobalUnknowns)" << std::endl;
1105 return Teuchos::null;
1119 const std::set<std::string> & fields)
const
1121 std::set<std::string> orderedFields;
1122 std::size_t numberInOrder = 0;
1124 for(std::size_t b=0;b<fieldOrder_ut.size();b++) {
1125 numberInOrder += fieldOrder_ut[b].size();
1126 orderedFields.insert(fieldOrder_ut[b].begin(),
1127 fieldOrder_ut[b].
end());
1130 bool correctCount = (numberInOrder==fields.size());
1131 bool sameFields = (orderedFields==fields);
1133 return correctCount && sameFields;
virtual const std::vector< int > & getGIDFieldOffsets(const std::string &blockId, int fieldNum) const
Use the field pattern so that you can find a particular field in the GIDs array.
virtual void getGhostedIndices(std::vector< GlobalOrdinal > &indices) const
Get the set of indices ghosted for this processor.
bool requireOrientations_
void setFieldOrder(const std::vector< std::string > &fieldOrder)
std::map< std::string, TupleToVectorPairMap > gidFieldOffsets_closure_
bool operator()(const Teuchos::Tuple< int, 3 > &a, const Teuchos::Tuple< int, 3 > &b) const
Teuchos::RCP< GlobalIndexer > buildNewIndexer(const Teuchos::RCP< ConnManager > &connManager, MPI_Comm mpiComm) const
void getFieldOrder(std::vector< std::vector< std::string > > &fieldOrder) const
#define TEUCHOS_TEST_FOR_EXCEPTION(throw_exception_test, Exception, msg)
Teuchos::RCP< const FieldPattern > getFieldPattern(const std::string &blockId, const std::string &fieldName) const
Find a field pattern stored for a particular block and field number. This will retrive the pattern ad...
int getFieldNum(const std::string &str) const
Get the number used for access to this field.
virtual void getOwnedIndices(std::vector< GlobalOrdinal > &indices) const
Get the set of indices owned by this processor.
virtual void getElementOrientation(panzer::LocalOrdinal localElmtId, std::vector< double > &gidsOrientation) const
Get a vector containg the orientation of the GIDs relative to the neighbors.
std::vector< Teuchos::RCP< GlobalIndexer > > fieldBlockManagers_
void enableTieBreak(bool enable)
virtual int getNumGhosted() const
Get the number of indices ghosted for this processor.
int getNumFields() const
How many fields are handled by this manager.
virtual bool fieldInBlock(const std::string &field, const std::string &block) const
virtual void ownedIndices(const std::vector< GlobalOrdinal > &indices, std::vector< bool > &isOwned) const
virtual const std::vector< int > & getBlockFieldNumbers(const std::string &block) const
std::map< std::string, std::set< std::string > > blockIdToFieldStrings_
block ID ==> field strings
std::map< int, int > fieldNumToFieldBlk_
field number ==> field block
void setConnManager(const Teuchos::RCP< ConnManager > &connMngr, MPI_Comm mpiComm)
Set the connection manager and MPI_Comm objects.
bool fieldsRegistered() const
virtual void getOwnedAndGhostedIndices(std::vector< GlobalOrdinal > &indices) const
Get the set of owned and ghosted indices for this processor.
PHX::MDField< ScalarT, panzer::Cell, panzer::IP > result
A field that will be used to build up the result of the integral we're performing.
const std::string & getFieldString(int num) const
Get the string name associated with a field number.
void setConnManager(const Teuchos::RCP< ConnManager > &connMngr, MPI_Comm mpiComm)
Adds a Connection Manager that will be associated with this DOFManager.
virtual void getElementBlockIds(std::vector< std::string > &elementBlockIds) const
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
bool validFieldOrder(const std::vector< std::vector< std::string > > &fieldOrder_ut, const std::set< std::string > &fields) const
int getBlockGIDOffset(const std::string &elementBlock, int fieldBlock) const
void getElementGIDs(panzer::LocalOrdinal localElmtId, std::vector< GlobalOrdinal > &gids, const std::string &blockIdHint="") const
Get the global IDs for a particular element. This function overwrites the gids variable.
virtual void getOwnedIndicesAsInt(std::vector< int > &indices) const
Get the set of indices owned by this processor.
std::map< std::string, std::map< int, std::vector< int > > > gidFieldOffsets_
Teuchos::RCP< const ConnManager > getConnManager() const
Teuchos::RCP< ConnManager > resetIndices()
Reset the indicies for this DOF manager.
void getElementGIDsPair(panzer::LocalOrdinal localElmtId, std::vector< std::pair< int, GlobalOrdinal >> &gids, const std::string &blockIdHint="") const
Get the global IDs for a particular element. This function overwrites the gids variable.
std::map< std::string, int > fieldStrToNum_
field string ==> field number
Teuchos::RCP< Teuchos::MpiComm< int > > communicator_
virtual int getNumOwned() const
Get the number of indices owned by this processor.
std::vector< std::vector< std::string > > fieldOrder_
void printFieldInformation(std::ostream &os) const
virtual int getFieldNum(const std::string &str) const =0
Get the number used for access to this field.
void getElementGIDsAsInt(panzer::LocalOrdinal localElmtId, std::vector< int > &gids, const std::string &blockIdHint="") const
Get the global IDs for a particular element. This function overwrites the gids variable.
virtual int getElementBlockGIDCount(const std::string &blockId) const
How any GIDs are associate with a particular element block.
virtual void getGhostedIndicesAsInt(std::vector< int > &indices) const
Get the set of indices ghosted for this processor.
virtual void buildGlobalUnknowns()
Teuchos::RCP< const FieldPattern > geomPattern_
std::map< std::pair< std::string, int >, int > blockGIDOffset_
(element block,field block) ==> gid offset
virtual const std::pair< std::vector< int >, std::vector< int > > & getGIDFieldOffsets_closure(const std::string &blockId, int fieldNum, int subcellDim, int subcellId) const
Use the field pattern so that you can find a particular field in the GIDs array. This version lets yo...
void addField(const std::string &str, const Teuchos::RCP< const FieldPattern > &pattern)
Add a field to the DOF manager.
void registerFields(bool buildSubUGIs)
std::map< std::string, std::vector< int > > blockIdToFieldNumbers_
block ID ==> field numbers
std::map< Teuchos::Tuple< int, 3 >, std::pair< std::vector< int >, std::vector< int > >, LessThan > TupleToVectorPairMap
PHX::MDField< ScalarT, panzer::Cell, panzer::BASIS > field
A field to which we'll contribute, or in which we'll store, the result of computing this integral...
int getNumFieldBlocks() const
int getFieldBlock(int fieldNum) const
Teuchos::RCP< ConnManager > connMngr_
void setFieldOrder(const std::vector< std::vector< std::string > > &fieldOrder)
void addFieldsToFieldBlockManager(const std::vector< std::string > &activeFields, GlobalIndexer &fieldBlockManager) const
virtual int getNumOwnedAndGhosted() const
Get the number of owned and ghosted indices for this processor.
std::map< std::pair< std::string, std::string >, Teuchos::RCP< const FieldPattern > > fieldStringToPattern_
(block ID x field string) ==> pattern
std::map< int, std::string > fieldNumToStr_
field number ==> field string
#define TEUCHOS_ASSERT(assertion_test)
int addField(const std::string &str, const Teuchos::RCP< const FieldPattern > &pattern, const panzer::FieldType &type=panzer::FieldType::CG)
Add a field to the DOF manager.
bool getOrientationsRequired() const
virtual void getOwnedAndGhostedIndicesAsInt(std::vector< int > &indices) const
Get the set of owned and ghosted indices for this processor.
void setOrientationsRequired(bool ro)