43 #include <PanzerAdaptersSTK_config.hpp> 46 #include <Teuchos_as.hpp> 50 #include <stk_mesh/base/FieldBase.hpp> 51 #include <stk_mesh/base/Comm.hpp> 52 #include <stk_mesh/base/Selector.hpp> 53 #include <stk_mesh/base/GetEntities.hpp> 54 #include <stk_mesh/base/GetBuckets.hpp> 55 #include <stk_mesh/base/CreateAdjacentEntities.hpp> 62 #include <stk_util/parallel/ParallelReduce.hpp> 63 #include <stk_util/parallel/CommSparse.hpp> 65 #ifdef PANZER_HAVE_IOSS 66 #include <Ionit_Initializer.h> 67 #include <stk_io/IossBridge.hpp> 81 : gid_(gid), nodes_(nodes) {}
86 Teuchos::RCP<ElementDescriptor>
98 : dimension_(0), initialized_(false), currentLocalId_(0), initialStateTime_(0.0), currentStateTime_(0.0), useFieldCoordinates_(false)
100 metaData_ = rcp(
new stk::mesh::MetaData());
104 : dimension_(0), initialized_(false), currentLocalId_(0), initialStateTime_(0.0), currentStateTime_(0.0), useFieldCoordinates_(false)
110 : dimension_(dim), initialized_(false), currentLocalId_(0), useFieldCoordinates_(false)
112 std::vector<std::string> entity_rank_names = stk::mesh::entity_rank_names();
113 entity_rank_names.push_back(
"FAMILY_TREE");
125 stk::mesh::Part * sideset =
metaData_->get_part(name);
127 sideset = &
metaData_->declare_part_with_topology(name,
128 stk::mesh::get_topology(shards::CellTopology(ctData),
dimension_));
129 sidesets_.insert(std::make_pair(name,sideset));
137 stk::mesh::Part * nodeset =
metaData_->get_part(name);
139 const CellTopologyData * ctData = shards::getCellTopologyData<shards::Node>();
140 nodeset = &
metaData_->declare_part_with_topology(name,
141 stk::mesh::get_topology(shards::CellTopology(ctData),
dimension_));
143 nodesets_.insert(std::make_pair(name,nodeset));
150 "Unknown element block \"" << blockId <<
"\"");
151 std::pair<std::string,std::string> key = std::make_pair(fieldName,blockId);
166 "Unknown element block \"" << blockId <<
"\"");
167 std::pair<std::string,std::string> key = std::make_pair(fieldName,blockId);
179 const std::vector<std::string> & coordNames,
180 const std::string & dispPrefix)
183 TEUCHOS_ASSERT(
dimension_==coordNames.size());
186 "Unknown element block \"" << blockId <<
"\"");
190 "STK_Interface::addMeshCoordFields: Can't set more than one set of coordinate " 191 "fields for element block \""+blockId+
"\".");
204 std::pair<std::string,std::string> key = std::make_pair(coordNames[i],blockId);
205 std::string dispName = dispPrefix+coordNames[i];
207 dispFields[i] = dispName;
243 #ifdef PANZER_HAVE_IOSS 250 std::map<std::string, stk::mesh::Part*>::iterator itr;
252 if(!stk::io::is_part_io_part(*itr->second))
253 stk::io::put_io_part_attribute(*itr->second);
258 std::map<std::string, stk::mesh::Part*>::iterator itr;
260 if(!stk::io::is_part_io_part(*itr->second))
261 stk::io::put_io_part_attribute(*itr->second);
266 std::map<std::string, stk::mesh::Part*>::iterator itr;
268 if(!stk::io::is_part_io_part(*itr->second))
269 stk::io::put_io_part_attribute(*itr->second);
277 stk::io::set_field_role(*
edgesField_, Ioss::Field::MESH);
279 stk::io::set_field_role(*
facesField_, Ioss::Field::MESH);
295 std::set<SolutionFieldType*> uniqueFields;
296 std::map<std::pair<std::string,std::string>,
SolutionFieldType*>::const_iterator fieldIter;
297 for(fieldIter=nameToField.begin();fieldIter!=nameToField.end();++fieldIter)
298 uniqueFields.insert(fieldIter->second);
301 std::set<SolutionFieldType*>::const_iterator uniqueFieldIter;
302 for(uniqueFieldIter=uniqueFields.begin();uniqueFieldIter!=uniqueFields.end();++uniqueFieldIter)
303 stk::mesh::put_field(*(*uniqueFieldIter),
metaData_->universal_part());
306 #ifdef PANZER_HAVE_IOSS 309 std::set<SolutionFieldType*>::const_iterator uniqueFieldIter;
310 for(uniqueFieldIter=uniqueFields.begin();uniqueFieldIter!=uniqueFields.end();++uniqueFieldIter)
311 stk::io::set_field_role(*(*uniqueFieldIter), Ioss::Field::TRANSIENT);
318 TEUCHOS_ASSERT(
bulkData_==Teuchos::null);
327 TEUCHOS_TEST_FOR_EXCEPTION(
bulkData_==Teuchos::null,std::logic_error,
328 "STK_Interface: Must call \"initialized\" or \"instantiateBulkData\" before \"beginModification\"");
335 TEUCHOS_TEST_FOR_EXCEPTION(
bulkData_==Teuchos::null,std::logic_error,
336 "STK_Interface: Must call \"initialized\" or \"instantiateBulkData\" before \"endModification\"");
343 stk::CommSparse comm(
bulkData_->parallel());
345 for (
int phase=0;phase<2;++phase) {
346 for (
int i=0;i<
bulkData_->parallel_size();++i) {
348 const stk::mesh::BucketVector& buckets =
bulkData_->buckets(stk::topology::NODE_RANK);
349 for (
size_t j=0;j<buckets.size();++j) {
350 const stk::mesh::Bucket& bucket = *buckets[j];
351 if ( bucket.owned() ) {
352 for (
size_t k=0;k<bucket.size();++k) {
353 stk::mesh::EntityKey key =
bulkData_->entity_key(bucket[k]);
354 comm.send_buffer(i).pack<stk::mesh::EntityKey>(key);
362 comm.allocate_buffers();
369 for (
int i=0;i<
bulkData_->parallel_size();++i) {
371 while(comm.recv_buffer(i).remaining()) {
372 stk::mesh::EntityKey key;
373 comm.recv_buffer(i).unpack<stk::mesh::EntityKey>(key);
374 stk::mesh::Entity node =
bulkData_->get_entity(key);
391 TEUCHOS_TEST_FOR_EXCEPTION(not
isModifiable(),std::logic_error,
392 "STK_Interface::addNode: STK_Interface must be modifiable to add a node");
393 TEUCHOS_TEST_FOR_EXCEPTION(coord.size()!=
getDimension(),std::logic_error,
394 "STK_Interface::addNode: number of coordinates in vector must mation dimension");
395 TEUCHOS_TEST_FOR_EXCEPTION(gid==0,std::logic_error,
396 "STK_Interface::addNode: STK has STUPID restriction of no zero GIDs, pick something else");
403 for(std::size_t i=0;i<coord.size();++i)
404 fieldCoords[i] = coord[i];
409 std::vector<stk::mesh::Part*> sidesetV;
410 sidesetV.push_back(sideset);
412 bulkData_->change_entity_parts(entity,sidesetV);
417 std::vector<stk::mesh::Part*> nodesetV;
418 nodesetV.push_back(nodeset);
420 bulkData_->change_entity_parts(entity,nodesetV);
425 std::vector<stk::mesh::Part*> blockVec;
426 blockVec.push_back(block);
430 stk::mesh::Entity element =
bulkData_->declare_entity(elementRank,ed->getGID(),blockVec);
433 const std::vector<stk::mesh::EntityId> & nodes = ed->getNodes();
434 for(std::size_t i=0;i<nodes.size();++i) {
436 stk::mesh::Entity node =
bulkData_->get_entity(nodeRank,nodes[i]);
437 TEUCHOS_ASSERT(
bulkData_->is_valid(node));
438 bulkData_->declare_relation(element,node,i);
442 procId[0] = Teuchos::as<ProcIdData>(
procRank_);
450 std::vector<stk::mesh::Entity> localElmts;
452 std::vector<stk::mesh::Entity>::const_iterator itr;
453 for(itr=localElmts.begin();itr!=localElmts.end();++itr) {
454 stk::mesh::Entity element = (*itr);
455 stk::mesh::EntityId gid =
bulkData_->identifier(element);
456 std::vector<stk::mesh::EntityId> subcellIds;
459 for(std::size_t i=0;i<subcellIds.size();++i) {
460 stk::mesh::Entity edge =
bulkData_->get_entity(edgeRank,subcellIds[i]);
461 stk::mesh::Entity
const* relations =
bulkData_->begin_nodes(edge);
467 double * edgeCoords = stk::mesh::field_data(*
edgesField_,edge);
469 edgeCoords[i] = (node_coord_1[i]+node_coord_2[i])/2.0;
478 std::vector<stk::mesh::Entity> localElmts;
480 std::vector<stk::mesh::Entity>::const_iterator itr;
481 for(itr=localElmts.begin();itr!=localElmts.end();++itr) {
482 stk::mesh::Entity element = (*itr);
484 std::vector<stk::mesh::EntityId> subcellIds;
487 for(std::size_t i=0;i<subcellIds.size();++i) {
488 stk::mesh::Entity face =
bulkData_->get_entity(faceRank,subcellIds[i]);
489 stk::mesh::Entity
const* relations =
bulkData_->begin_nodes(face);
490 const size_t num_relations =
bulkData_->num_nodes(face);
493 double * faceCoords = stk::mesh::field_data(*
facesField_,face);
496 for(std::size_t j=0;j<num_relations;++j)
498 faceCoords[i] /= double(num_relations);
506 const size_t num_rels =
bulkData_->num_connectivity(src, tgt_rank);
507 stk::mesh::Entity
const* relations =
bulkData_->begin(src, tgt_rank);
508 stk::mesh::ConnectivityOrdinal
const* ordinals =
bulkData_->begin_ordinals(src, tgt_rank);
509 for (
size_t i = 0; i < num_rels; ++i) {
510 if (ordinals[i] == static_cast<stk::mesh::ConnectivityOrdinal>(rel_id)) {
515 return stk::mesh::Entity();
526 const std::string& filename)
540 const std::string& filename)
542 using std::runtime_error;
543 using stk::io::StkMeshIoBroker;
544 using stk::mesh::FieldVector;
545 using stk::ParallelMachine;
547 PANZER_FUNC_TIME_MONITOR(
"STK_Interface::setupExodusFile(filename)");
548 #ifdef PANZER_HAVE_IOSS 549 TEUCHOS_ASSERT(not
mpiComm_.is_null())
550 ParallelMachine comm = *
mpiComm_->getRawMpiComm();
551 meshData_ = rcp(
new StkMeshIoBroker(comm));
553 meshIndex_ = meshData_->create_output_mesh(filename, stk::io::WRITE_RESULTS);
554 const FieldVector& fields =
metaData_->get_fields();
555 for (
size_t i(0); i < fields.size(); ++i) {
561 auto role = stk::io::get_field_role(*fields[i]);
562 if (role !=
nullptr) {
563 if (*role != Ioss::Field::MESH)
564 meshData_->add_field(meshIndex_, *fields[i]);
566 meshData_->add_field(meshIndex_, *fields[i]);
570 TEUCHOS_ASSERT(
false)
586 using Teuchos::FancyOStream;
587 using Teuchos::rcpFromRef;
588 PANZER_FUNC_TIME_MONITOR(
"STK_Interface::writeToExodus(timestep)");
589 #ifdef PANZER_HAVE_IOSS 590 if (not meshData_.is_null())
593 globalToExodus(GlobalVariable::ADD);
595 meshData_->write_defined_output_fields(meshIndex_);
596 globalToExodus(GlobalVariable::WRITE);
597 meshData_->end_output_step(meshIndex_);
601 FancyOStream out(rcpFromRef(cout));
602 out.setOutputToRootOnly(0);
603 out <<
"WARNING: Exodus I/O has been disabled or not setup properly; " 604 <<
"not writing to Exodus." << endl;
607 TEUCHOS_ASSERT(
false);
619 const GlobalVariable& flag)
621 using std::invalid_argument;
623 using Teuchos::Array;
628 for (
auto i = globalData_.begin(); i != globalData_.end(); ++i)
630 const string& name = globalData_.name(i);
633 if (globalData_.isType<
int>(name))
635 const auto& value = globalData_.get<
int>(name);
636 if (flag == GlobalVariable::ADD)
640 meshData_->add_global(meshIndex_, name, value,
641 stk::util::ParameterType::INTEGER);
649 meshData_->write_global(meshIndex_, name, value,
650 stk::util::ParameterType::INTEGER);
654 else if (globalData_.isType<
double>(name))
656 const auto& value = globalData_.get<
double>(name);
657 if (flag == GlobalVariable::ADD)
661 meshData_->add_global(meshIndex_, name, value,
662 stk::util::ParameterType::DOUBLE);
670 meshData_->write_global(meshIndex_, name, value,
671 stk::util::ParameterType::DOUBLE);
675 else if (globalData_.isType<Array<int>>(name))
677 const auto& value = globalData_.get<Array<int>>(name).toVector();
678 if (flag == GlobalVariable::ADD)
682 meshData_->add_global(meshIndex_, name, value,
683 stk::util::ParameterType::INTEGERVECTOR);
691 meshData_->write_global(meshIndex_, name, value,
692 stk::util::ParameterType::INTEGERVECTOR);
696 else if (globalData_.isType<Array<double>>(name))
698 const auto& value = globalData_.get<Array<double>>(name).toVector();
699 if (flag == GlobalVariable::ADD)
703 meshData_->add_global(meshIndex_, name, value,
704 stk::util::ParameterType::DOUBLEVECTOR);
712 meshData_->write_global(meshIndex_, name, value,
713 stk::util::ParameterType::DOUBLEVECTOR);
718 TEUCHOS_TEST_FOR_EXCEPTION(
true, invalid_argument,
719 "STK_Interface::globalToExodus(): The global variable to be added " \
720 "to the Exodus output file is of an invalid type. Valid types are " \
721 "int and double, along with std::vectors of those types.")
733 const std::string& key,
736 globalData_.set(key, value);
747 const std::string& key,
750 globalData_.set(key, value);
761 const std::string& key,
762 const std::vector<int>& value)
764 using Teuchos::Array;
765 globalData_.set(key, Array<int>(value));
776 const std::string& key,
777 const std::vector<double>& value)
779 using Teuchos::Array;
780 globalData_.set(key, Array<double>(value));
785 #ifdef PANZER_HAVE_IOSS 797 stk::mesh::Entity node =
bulkData_->get_entity(nodeRank,nodeId);
798 const size_t numElements =
bulkData_->num_elements(node);
799 stk::mesh::Entity
const* relations =
bulkData_->begin_elements(node);
802 elements.insert(elements.end(), relations, relations + numElements);
806 std::vector<int> & relIds)
const 809 const size_t numElements =
bulkData_->num_elements(node);
810 stk::mesh::Entity
const* relations =
bulkData_->begin_elements(node);
811 stk::mesh::ConnectivityOrdinal
const* rel_ids =
bulkData_->begin_element_ordinals(node);
814 for (
size_t i = 0; i < numElements; ++i) {
815 stk::mesh::Entity element = relations[i];
819 elements.push_back(element);
820 relIds.push_back(rel_ids[i]);
826 std::vector<int> & relIds,
unsigned int matchType)
const 828 stk::mesh::EntityRank rank;
831 else if(matchType == 1)
833 else if(matchType == 2)
836 TEUCHOS_ASSERT(
false);
838 stk::mesh::Entity node =
bulkData_->get_entity(rank,nodeId);
845 std::vector<stk::mesh::Entity> current;
848 std::sort(current.begin(),current.end());
851 for(std::size_t n=1;n<nodeIds.size();++n) {
853 std::vector<stk::mesh::Entity> nextNode;
855 std::sort(nextNode.begin(),nextNode.end());
858 std::vector<stk::mesh::Entity> intersection(std::min(nextNode.size(),current.size()));
859 std::vector<stk::mesh::Entity>::const_iterator endItr
860 = std::set_intersection(current.begin(),current.end(),
861 nextNode.begin(),nextNode.end(),
862 intersection.begin());
863 std::size_t newLength = endItr-intersection.begin();
864 intersection.resize(newLength);
868 current = intersection;
877 stk::mesh::Entity
const* nodeRel =
getBulkData()->begin_nodes(element);
878 const size_t numNodes =
getBulkData()->num_nodes(element);
880 nodeIds.reserve(numNodes);
881 for(
size_t i = 0; i < numNodes; ++i) {
896 const unsigned entityRankCount =
metaData_->entity_rank_count();
897 const size_t commCount = 10;
899 TEUCHOS_ASSERT(entityRankCount<10);
902 stk::ParallelMachine mach = *
mpiComm_->getRawMpiComm();
904 std::vector<stk::mesh::EntityId> local(commCount,0);
907 stk::mesh::Selector ownedPart =
metaData_->locally_owned_part();
908 for(stk::mesh::EntityRank i=stk::topology::NODE_RANK; i<entityRankCount; ++i) {
909 std::vector<stk::mesh::Entity> entities;
911 stk::mesh::get_selected_entities(ownedPart,
bulkData_->buckets(i),entities);
914 std::vector<stk::mesh::Entity>::const_iterator itr;
915 for(itr=entities.begin();itr!=entities.end();++itr) {
916 stk::mesh::EntityId
id =
bulkData_->identifier(*itr);
923 stk::all_reduce(mach,stk::ReduceMax<10>(&local[0]));
924 maxEntityId_.assign(local.begin(),local.begin()+entityRankCount+1);
929 TEUCHOS_TEST_FOR_EXCEPTION(entityRank>=
entityCounts_.size(),std::logic_error,
930 "STK_Interface::getEntityCounts: Entity counts do not include rank: " << entityRank);
937 TEUCHOS_TEST_FOR_EXCEPTION(entityRank>=
maxEntityId_.size(),std::logic_error,
938 "STK_Interface::getMaxEntityId: Max entity ids do not include rank: " << entityRank);
945 stk::mesh::PartVector emptyPartVector;
946 stk::mesh::create_adjacent_entities(*
bulkData_,emptyPartVector);
968 std::vector<stk::mesh::EntityId> & subcellIds)
const 971 stk::mesh::Entity cell =
bulkData_->get_entity(elementRank,elementId);
973 TEUCHOS_TEST_FOR_EXCEPTION(!
bulkData_->is_valid(cell),std::logic_error,
974 "STK_Interface::getSubcellIndices: could not find element requested (GID = " << elementId <<
")");
976 const size_t numSubcells =
bulkData_->num_connectivity(cell, static_cast<stk::mesh::EntityRank>(entityRank));
977 stk::mesh::Entity
const* subcells =
bulkData_->begin(cell, static_cast<stk::mesh::EntityRank>(entityRank));
979 subcellIds.resize(numSubcells,0);
982 for(
size_t i = 0; i < numSubcells; ++i) {
983 stk::mesh::Entity subcell = subcells[i];
984 subcellIds[i] =
bulkData_->identifier(subcell);
991 stk::mesh::Selector ownedPart =
metaData_->locally_owned_part();
995 stk::mesh::get_selected_entities(ownedPart,
bulkData_->buckets(elementRank),elements);
1002 TEUCHOS_TEST_FOR_EXCEPTION(elementBlock==0,std::logic_error,
"Could not find element block \"" << blockID <<
"\"");
1006 stk::mesh::Selector ownedBlock =
metaData_->locally_owned_part() & (*elementBlock);
1010 stk::mesh::get_selected_entities(ownedBlock,
bulkData_->buckets(elementRank),elements);
1016 stk::mesh::Selector neighborBlock = (!
metaData_->locally_owned_part());
1020 stk::mesh::get_selected_entities(neighborBlock,
bulkData_->buckets(elementRank),elements);
1027 TEUCHOS_TEST_FOR_EXCEPTION(elementBlock==0,std::logic_error,
"Could not find element block \"" << blockID <<
"\"");
1030 stk::mesh::Selector neighborBlock = (!
metaData_->locally_owned_part()) & (*elementBlock);
1034 stk::mesh::get_selected_entities(neighborBlock,
bulkData_->buckets(elementRank),elements);
1039 stk::mesh::Part * sidePart =
getSideset(sideName);
1040 TEUCHOS_TEST_FOR_EXCEPTION(sidePart==0,std::logic_error,
1041 "Unknown side set \"" << sideName <<
"\"");
1043 stk::mesh::Selector side = *sidePart;
1044 stk::mesh::Selector ownedBlock =
metaData_->locally_owned_part() & side;
1052 stk::mesh::Part * sidePart =
getSideset(sideName);
1055 "Unknown side set \"" << sideName <<
"\"");
1057 "Unknown element block \"" << blockName <<
"\"");
1059 stk::mesh::Selector side = *sidePart;
1060 stk::mesh::Selector block = *elmtPart;
1061 stk::mesh::Selector ownedBlock =
metaData_->locally_owned_part() & block & side;
1069 stk::mesh::Part * sidePart =
getSideset(sideName);
1070 TEUCHOS_TEST_FOR_EXCEPTION(sidePart==0,std::logic_error,
1071 "Unknown side set \"" << sideName <<
"\"");
1073 stk::mesh::Selector side = *sidePart;
1081 stk::mesh::Part * sidePart =
getSideset(sideName);
1084 "Unknown side set \"" << sideName <<
"\"");
1086 "Unknown element block \"" << blockName <<
"\"");
1088 stk::mesh::Selector side = *sidePart;
1089 stk::mesh::Selector block = *elmtPart;
1090 stk::mesh::Selector sideBlock = block & side;
1098 stk::mesh::Part * nodePart =
getNodeset(nodesetName);
1101 "Unknown node set \"" << nodesetName <<
"\"");
1103 "Unknown element block \"" << blockName <<
"\"");
1105 stk::mesh::Selector nodeset = *nodePart;
1106 stk::mesh::Selector block = *elmtPart;
1107 stk::mesh::Selector ownedBlock =
metaData_->locally_owned_part() & block & nodeset;
1120 std::map<std::string, stk::mesh::Part*>::const_iterator blkItr;
1122 names.push_back(blkItr->first);
1132 std::map<std::string, stk::mesh::Part*>::const_iterator sideItr;
1134 names.push_back(sideItr->first);
1142 std::map<std::string, stk::mesh::Part*>::const_iterator nodeItr;
1144 names.push_back(nodeItr->first);
1160 std::unordered_map<stk::mesh::EntityId,std::size_t>::const_iterator itr =
localIDHash_.find(gid);
1169 if(
bulkData_->bucket(elmt).member(*(eb_pair.second)))
1170 return eb_pair.first;
1175 const std::string & blockId)
const 1178 std::map<std::pair<std::string,std::string>,
SolutionFieldType*>::const_iterator
1183 "Solution field name \"" << fieldName <<
"\" in block ID \"" << blockId <<
"\" was not found");
1185 return iter->second;
1189 const std::string & blockId)
const 1192 std::map<std::pair<std::string,std::string>,
SolutionFieldType*>::const_iterator
1197 "Cell field named \"" << fieldName <<
"\" in block ID \"" << blockId <<
"\" was not found");
1199 return iter->second;
1219 stk::mesh::Part * block =
metaData_->get_part(name);
1221 block = &
metaData_->declare_part_with_topology(name, stk::mesh::get_topology(shards::CellTopology(ctData)));
1225 Teuchos::RCP<shards::CellTopology> ct
1226 = Teuchos::rcp(
new shards::CellTopology(ctData));
1264 std::vector<stk::mesh::Entity> elements;
1267 for(std::size_t index=0;index<elements.size();++index) {
1268 stk::mesh::Entity element = elements[index];
1272 procId[0] = Teuchos::as<ProcIdData>(
procRank_);
1285 for(std::size_t index=0;index<elements.size();++index) {
1286 stk::mesh::Entity element = elements[index];
1290 procId[0] = Teuchos::as<ProcIdData>(
procRank_);
1302 std::vector<std::string> names;
1305 for(std::size_t b=0;b<names.size();b++) {
1307 std::map<std::string,double>::const_iterator bw_itr =
blockWeights_.find(names[b]);
1308 double blockWeight = (bw_itr!=
blockWeights_.end()) ? bw_itr->second : 1.0;
1310 std::vector<stk::mesh::Entity> elements;
1313 for(std::size_t index=0;index<elements.size();++index) {
1315 double * loadBal = stk::mesh::field_data(*
loadBalField_,elements[index]);
1316 loadBal[0] = blockWeight;
1323 const std::string & fieldName,
1326 std::map<std::string,std::vector<std::string> >::const_iterator blkItr =
meshCoordFields_.find(eBlock);
1332 for(axis=0;axis<Teuchos::as<int>(blkItr->second.size());axis++) {
1333 if(blkItr->second[axis]==fieldName)
1337 if(axis>=Teuchos::as<int>(blkItr->second.size()))
1343 std::pair<Teuchos::RCP<std::vector<std::pair<std::size_t,std::size_t> > >, Teuchos::RCP<std::vector<unsigned int> > >
1346 Teuchos::RCP<std::vector<std::pair<std::size_t,std::size_t> > > vec;
1347 Teuchos::RCP<std::vector<unsigned int > > type_vec = rcp(
new std::vector<unsigned int>);
1348 const std::vector<Teuchos::RCP<const PeriodicBC_MatcherBase> > & matchers =
getPeriodicBCVector();
1351 for(std::size_t m=0;m<matchers.size();m++){
1352 vec = matchers[m]->getMatchedPair(*
this,vec);
1354 if(matchers[m]->getType() ==
"coord")
1356 else if(matchers[m]->getType() ==
"edge")
1358 else if(matchers[m]->getType() ==
"face")
1361 TEUCHOS_ASSERT(
false);
1362 type_vec->insert(type_vec->begin(),vec->size()-type_vec->size(),type);
1365 return std::make_pair(vec,type_vec);
1370 std::map<std::string, stk::mesh::Part*>::const_iterator blkItr =
elementBlocks_.find(blockId);
1377 std::vector<std::string> blockNames, sidesetNames, nodesetNames;
1383 os <<
"STK Mesh data:\n";
1386 os <<
" Entity counts (Nodes, Edges, Cells) = ( " 1391 os <<
" Entity counts (Nodes, Edges, Faces, Cells) = ( " 1397 os <<
" Entity counts (Nodes, Cells) = ( " 1401 os <<
" Element blocks = ";
1402 for(std::size_t i=0;i<blockNames.size();i++)
1403 os <<
"\"" << blockNames[i] <<
"\" ";
1405 os <<
" Sidesets = ";
1406 for(std::size_t i=0;i<sidesetNames.size();i++)
1407 os <<
"\"" << sidesetNames[i] <<
"\" ";
1409 os <<
" Nodesets = ";
1410 for(std::size_t i=0;i<nodesetNames.size();i++)
1411 os <<
"\"" << nodesetNames[i] <<
"\" ";
1415 const std::vector<Teuchos::RCP<const PeriodicBC_MatcherBase> > & bcVector
1417 if(bcVector.size()!=0) {
1418 os <<
" Periodic BCs:\n";
1419 for(std::size_t i=0;i<bcVector.size();i++)
1420 os <<
" " << bcVector[i]->getString() <<
"\n";
1427 std::vector<std::string> blockNames, sidesetNames, nodesetNames;
1433 os <<
"STK Meta data:\n";
1434 os <<
" Element blocks = ";
1435 for(std::size_t i=0;i<blockNames.size();i++)
1436 os <<
"\"" << blockNames[i] <<
"\" ";
1438 os <<
" Sidesets = ";
1439 for(std::size_t i=0;i<sidesetNames.size();i++)
1440 os <<
"\"" << sidesetNames[i] <<
"\" ";
1442 os <<
" Nodesets = ";
1443 for(std::size_t i=0;i<nodesetNames.size();i++)
1444 os <<
"\"" << nodesetNames[i] <<
"\" ";
1448 const std::vector<Teuchos::RCP<const PeriodicBC_MatcherBase> > & bcVector
1450 if(bcVector.size()!=0) {
1451 os <<
" Periodic BCs:\n";
1452 for(std::size_t i=0;i<bcVector.size();i++)
1453 os <<
" " << bcVector[i]->getString() <<
"\n";
1459 const stk::mesh::FieldVector & fv =
metaData_->get_fields();
1460 for(std::size_t i=0;i<fv.size();i++)
1461 os <<
"\"" << fv[i]->name() <<
"\" ";
1467 std::map<std::string, Teuchos::RCP<shards::CellTopology> >::const_iterator itr;
1471 std::stringstream ss;
1473 TEUCHOS_TEST_FOR_EXCEPTION(itr==
elementBlockCT_.end(),std::logic_error,
1474 "STK_Interface::getCellTopology: No such element block \"" +eBlock +
"\" available.\n\n" 1475 <<
"STK Meta Data follows: \n" << ss.str());
1484 const int err = MPI_Comm_dup (parallelMach, &newComm);
1485 TEUCHOS_TEST_FOR_EXCEPTION(err != MPI_SUCCESS, std::runtime_error,
1486 "panzer::STK_Interface: MPI_Comm_dup failed with error \"" 1487 << Teuchos::mpiErrorCodeToString (err) <<
"\".");
1494 TEUCHOS_TEST_FOR_EXCEPTION(
true, std::runtime_error,
"Rebalance not currently supported");
1499 stk::mesh::Selector selector(
getMetaData()->universal_part());
1500 stk::mesh::Selector owned_selector(
getMetaData()->locally_owned_part());
1502 Teuchos::FancyOStream out(Teuchos::rcpFromRef(std::cout));
1503 out.setOutputToRootOnly(0);
1507 Teuchos::ParameterList graph;
1508 if(params.begin()!=params.end())
1509 graph.sublist(stk::rebalance::Zoltan::default_parameters_name()) = params;
1520 Teuchos::RCP<const Teuchos::Comm<int> >
void initializeFromMetaData()
Teuchos::RCP< ElementDescriptor > buildElementDescriptor(stk::mesh::EntityId elmtId, std::vector< stk::mesh::EntityId > &nodes)
Teuchos::RCP< stk::mesh::MetaData > getMetaData() const
stk::mesh::Part * getElementBlockPart(const std::string &name) const
get the block count
bool isMeshCoordField(const std::string &eBlock, const std::string &fieldName, int &axis) const
void addNodeset(const std::string &name)
Teuchos::RCP< stk::mesh::BulkData > bulkData_
void getMySides(const std::string &sideName, std::vector< stk::mesh::Entity > &sides) const
std::vector< stk::mesh::Part * > facesPartVec_
std::map< std::pair< std::string, std::string >, SolutionFieldType * > fieldNameToSolution_
std::string containingBlockId(stk::mesh::Entity elmt) const
void addEntityToNodeset(stk::mesh::Entity entity, stk::mesh::Part *nodeset)
stk::mesh::EntityRank getFaceRank() const
void addGlobalToExodus(const std::string &key, const int &value)
Add an int global variable to the information to be written to the Exodus output file.
std::size_t elementLocalId(stk::mesh::Entity elmt) const
stk::mesh::Field< double > SolutionFieldType
std::vector< stk::mesh::Part * > edgesPartVec_
std::map< std::string, double > blockWeights_
VectorFieldType * coordinatesField_
bool isModifiable() const
void getMyElements(std::vector< stk::mesh::Entity > &elements) const
void addEntityToSideset(stk::mesh::Entity entity, stk::mesh::Part *sideset)
stk::mesh::Part * nodesPart_
stk::mesh::EntityRank getNodeRank() const
void addSolutionField(const std::string &fieldName, const std::string &blockId)
std::map< std::string, Teuchos::RCP< shards::CellTopology > > elementBlockCT_
Teuchos::RCP< stk::mesh::BulkData > getBulkData() const
std::size_t currentLocalId_
std::map< std::string, stk::mesh::Part * > sidesets_
std::vector< std::size_t > entityCounts_
void getElementsSharingNode(stk::mesh::EntityId nodeId, std::vector< stk::mesh::Entity > &elements) const
get a set of elements sharing a single node
void getSubcellIndices(unsigned entityRank, stk::mesh::EntityId elementId, std::vector< stk::mesh::EntityId > &subcellIds) const
stk::mesh::EntityRank getSideRank() const
void initialize(stk::ParallelMachine parallelMach, bool setupIO=true)
SolutionFieldType * loadBalField_
stk::mesh::Entity findConnectivityById(stk::mesh::Entity src, stk::mesh::EntityRank tgt_rank, unsigned rel_id) const
static const std::string nodesString
const double * getNodeCoordinates(stk::mesh::EntityId nodeId) const
void instantiateBulkData(stk::ParallelMachine parallelMach)
void getElementBlockNames(std::vector< std::string > &names) const
stk::mesh::EntityRank getEdgeRank() const
stk::mesh::Part * getSideset(const std::string &name) const
unsigned getDimension() const
get the dimension
void addElement(const Teuchos::RCP< ElementDescriptor > &ed, stk::mesh::Part *block)
std::map< std::string, std::vector< std::string > > meshDispFields_
VectorFieldType * edgesField_
stk::mesh::EntityId elementGlobalId(std::size_t lid) const
void getNodeIdsForElement(stk::mesh::Entity element, std::vector< stk::mesh::EntityId > &nodeIds) const
get a list of node ids for nodes connected to an element
static const std::string coordsString
stk::mesh::Field< double, stk::mesh::Cartesian > VectorFieldType
stk::mesh::Field< double > * getCellField(const std::string &fieldName, const std::string &blockId) const
std::size_t getEntityCounts(unsigned entityRank) const
get the global counts for the entity of specified rank
void writeToExodus(const std::string &filename)
Write this mesh and associated fields to the given output file.
std::map< std::string, stk::mesh::Part * > elementBlocks_
bool isInitialized() const
Has initialize been called on this mesh object?
std::vector< stk::mesh::Part * > nodesPartVec_
static const std::string edgesString
void printMetaData(std::ostream &os) const
void initializeFieldsInSTK(const std::map< std::pair< std::string, std::string >, SolutionFieldType *> &nameToField, bool setupIO)
Teuchos::RCP< const std::vector< stk::mesh::Entity > > getElementsOrderedByLID() const
void addNode(stk::mesh::EntityId gid, const std::vector< double > &coord)
const std::vector< Teuchos::RCP< const PeriodicBC_MatcherBase > > & getPeriodicBCVector() const
void buildSubcells()
force the mesh to build subcells: edges and faces
Teuchos::RCP< Teuchos::MpiComm< int > > mpiComm_
Teuchos::RCP< stk::mesh::MetaData > metaData_
virtual ~ElementDescriptor()
Teuchos::RCP< std::vector< stk::mesh::Entity > > orderedElementVector_
Teuchos::RCP< const Teuchos::Comm< int > > getComm() const
get the comm associated with this mesh
void addMeshCoordFields(const std::string &blockId, const std::vector< std::string > &coordField, const std::string &dispPrefix)
void applyElementLoadBalanceWeights()
bool validBlockId(const std::string &blockId) const
void addSideset(const std::string &name, const CellTopologyData *ctData)
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...
void rebalance(const Teuchos::ParameterList ¶ms)
Teuchos::RCP< const shards::CellTopology > getCellTopology(const std::string &eBlock) const
void getAllSides(const std::string &sideName, std::vector< stk::mesh::Entity > &sides) const
void getSidesetNames(std::vector< std::string > &name) const
std::map< std::string, std::vector< std::string > > meshCoordFields_
static const std::string facesString
Teuchos::RCP< Teuchos::MpiComm< int > > getSafeCommunicator(stk::ParallelMachine parallelMach) const
std::pair< Teuchos::RCP< std::vector< std::pair< std::size_t, std::size_t > > >, Teuchos::RCP< std::vector< unsigned int > > > getPeriodicNodePairing() const
void getNodesetNames(std::vector< std::string > &name) const
void buildLocalElementIDs()
void setupExodusFile(const std::string &filename)
Set up an output Exodus file for writing results.
std::unordered_map< stk::mesh::EntityId, std::size_t > localIDHash_
std::vector< stk::mesh::EntityId > maxEntityId_
const VectorFieldType & getCoordinatesField() const
void print(std::ostream &os) const
stk::mesh::EntityRank getElementRank() const
stk::mesh::Field< ProcIdData > ProcIdFieldType
stk::mesh::EntityId getMaxEntityId(unsigned entityRank) const
get max entity ID of type entityRank
void addCellField(const std::string &fieldName, const std::string &blockId)
stk::mesh::Part * edgesPart_
void getMyNodes(const std::string &sideName, const std::string &blockName, std::vector< stk::mesh::Entity > &nodes) const
void getElementsSharingNodes(const std::vector< stk::mesh::EntityId > nodeId, std::vector< stk::mesh::Entity > &elements) const
get a set of elements sharing multiple nodes
stk::mesh::Part * facesPart_
ProcIdFieldType * processorIdField_
void addElementBlock(const std::string &name, const CellTopologyData *ctData)
void getOwnedElementsSharingNode(stk::mesh::Entity node, std::vector< stk::mesh::Entity > &elements, std::vector< int > &relIds) const
stk::mesh::Part * getNodeset(const std::string &name) const
stk::mesh::Field< double > * getSolutionField(const std::string &fieldName, const std::string &blockId) const
std::map< std::pair< std::string, std::string >, SolutionFieldType * > fieldNameToCellField_
std::map< std::string, stk::mesh::Part * > nodesets_
VectorFieldType * facesField_
void getNeighborElements(std::vector< stk::mesh::Entity > &elements) const