17#include "Teuchos_RCP.hpp"
19#include "Kokkos_DynRankView.hpp"
26#include "Teuchos_FancyOStream.hpp"
40 PANZER_FUNC_TIME_MONITOR(
"panzer::ConnectivityManager::clearCachedConnectivityData()");
45 { return entry.second->stkMeshDB_.get() == mesh_ptr; }),
53 LocalIdCompare(
const RCP<const STK_Interface> & mesh) : mesh_(mesh) {}
56 bool operator() (stk::mesh::Entity a,stk::mesh::Entity b)
57 {
return mesh_->elementLocalId(a) < mesh_->elementLocalId(b);}
60 RCP<const STK_Interface> mesh_;
88Teuchos::RCP<panzer::ConnManager>
103 connSizePtr_ = Teuchos::rcp(
new std::vector<LocalOrdinal>);
114 elements_ = Teuchos::rcp(
new std::vector<stk::mesh::Entity>);
117 std::vector<std::string> blockIds;
120 std::size_t blockIndex=0;
121 for(std::vector<std::string>::const_iterator idItr=blockIds.begin();
122 idItr!=blockIds.end();++idItr,++blockIndex) {
123 std::string blockId = *idItr;
126 std::vector<stk::mesh::Entity> blockElmts;
127 stkMeshDB_->getMyElements(blockId,blockElmts);
133 elementBlocks_[blockId] = Teuchos::rcp(
new std::vector<LocalOrdinal>);
134 for(std::size_t i=0;i<blockElmts.size();i++)
141 for(std::vector<std::string>::const_iterator idItr=blockIds.begin();
142 idItr!=blockIds.end();++idItr,++blockIndex) {
143 std::string blockId = *idItr;
146 std::vector<stk::mesh::Entity> blockElmts;
147 stkMeshDB_->getNeighborElements(blockId,blockElmts);
154 for(std::size_t i=0;i<blockElmts.size();i++)
194 TEUCHOS_ASSERT(
false);
199 edgeOffset = nodeOffset+(maxNodeId+1)*nodeIdCnt;
200 faceOffset = edgeOffset+(maxEdgeId+1)*edgeIdCnt;
201 cellOffset = faceOffset+(maxFaceId+1)*faceIdCnt;
204 TEUCHOS_ASSERT(nodeOffset <= edgeOffset
205 && edgeOffset <= faceOffset
206 && faceOffset <= cellOffset);
211 unsigned subcellRank,
214 const unsigned maxIds)
222 stk::mesh::BulkData& bulkData = *
stkMeshDB_->getBulkData();
223 const stk::mesh::EntityRank rank =
static_cast<stk::mesh::EntityRank
>(subcellRank);
226 TEUCHOS_TEST_FOR_EXCEPTION(maxIds > bulkData.num_connectivity(element, rank),
228 "ERROR: The maxIds (num vertices from basis cell topology) is greater than the num vertices in the stk mesh topology!");
231 const size_t num_rels = (maxIds > 0) ? maxIds : bulkData.num_connectivity(element, rank);
232 stk::mesh::Entity
const* relations = bulkData.begin(element, rank);
233 for(std::size_t sc=0; sc<num_rels; ++sc) {
234 stk::mesh::Entity subcell = relations[sc];
238 connectivity.push_back(offset+idCnt*(bulkData.identifier(subcell)-1)+i);
252 GlobalOrdinal * conn = &(*connectivityPtr_)[(*elmtLidToConnPtr_)[elmtLID]];
253 const std::vector<int> & subCellIndices = fp.
getSubcellIndices(subcellRank,subcellId);
256 for(std::size_t i=0;i<subCellIndices.size();i++) {
257 conn[subCellIndices[i]] = offset+subCellIndices.size()*(newId-1)+i;
263 PANZER_FUNC_TIME_MONITOR_DIFF(
"panzer_stk::STKConnManager::buildConnectivity", build_connectivity);
270 PANZER_FUNC_TIME_MONITOR_DIFF(
"panzer_stk::STKConnManager::copyingCachedConnectivity", copy_cached_connectivity);
290 stk::mesh::BulkData& bulkData = *
stkMeshDB_->getBulkData();
305 LocalOrdinal nodeIdCnt=0, edgeIdCnt=0, faceIdCnt=0, cellIdCnt=0;
306 GlobalOrdinal nodeOffset=0, edgeOffset=0, faceOffset=0, cellOffset=0;
308 nodeOffset, edgeOffset, faceOffset, cellOffset);
321 for(std::size_t elmtLid=0;elmtLid!=
elements_->size();++elmtLid) {
323 stk::mesh::Entity element = (*elements_)[elmtLid];
326 elmtLidToConn[elmtLid] = connectivity.size();
340 connectivity.push_back(cellOffset+cellIdCnt*(bulkData.identifier(element)-1));
345 connSize[elmtLid] = numIds;
357 auto fp_rcp = fp.
clone();
365 stk::mesh::Entity element = (*elements_)[localElmtId];
367 return stkMeshDB_->containingBlockId(element);
376 PANZER_FUNC_TIME_MONITOR_DIFF(
"panzer_stk::STKConnManager::applyPeriodicBCs", apply_periodic_bcs);
378 std::pair<Teuchos::RCP<std::vector<std::pair<std::size_t,std::size_t> > >, Teuchos::RCP<std::vector<unsigned int> > > matchedValues
381 Teuchos::RCP<std::vector<std::pair<std::size_t,std::size_t> > > matchedNodes
382 = matchedValues.first;
383 Teuchos::RCP<std::vector<unsigned int> > matchTypes
384 = matchedValues.second;
387 if(matchedNodes==Teuchos::null)
return;
389 for(std::size_t m=0;m<matchedNodes->size();m++) {
390 stk::mesh::EntityId oldNodeId = (*matchedNodes)[m].first;
391 std::size_t newNodeId = (*matchedNodes)[m].second;
393 std::vector<stk::mesh::Entity> elements;
394 std::vector<int> localIds;
398 if((*matchTypes)[m] == 0)
399 offset1 = nodeOffset-offset0;
400 else if((*matchTypes)[m] == 1){
402 offset1 = edgeOffset-offset0;
403 }
else if((*matchTypes)[m] == 2){
405 offset1 = faceOffset-offset0;
407 TEUCHOS_ASSERT(
false);
410 stkMeshDB_->getOwnedElementsSharingNode(stk::mesh::EntityId(oldNodeId-offset0),elements,localIds,(*matchTypes)[m]);
413 for(std::size_t e=0;e<elements.size();e++){
424 std::vector<std::size_t> & localCellIds,
425 Kokkos::DynRankView<double,PHX::Device> & points)
const
431 Kokkos::DynRankView<double,PHX::Device> nodes;
435 points = Kokkos::DynRankView<double,PHX::Device>(
"points",localCellIds.size(),numIds,dim);
452 stk::mesh::Entity
const e)
454 return static_cast<std::size_t
>(
455 std::distance(elements.begin(), std::find(elements.begin(), elements.end(), e)));
460 stk::mesh::BulkData& bulkData = *
stkMeshDB_->getBulkData();
462 elmtToAssociatedElmts.resize(
elements_->size());
464 std::vector<stk::mesh::Entity> sides;
467 for (std::vector<stk::mesh::Entity>::const_iterator si = sides.begin();
468 si != sides.end(); ++si) {
469 stk::mesh::Entity side = *si;
470 const size_t num_elements = bulkData.num_elements(side);
471 stk::mesh::Entity
const* elements = bulkData.begin_elements(side);
472 if (num_elements != 2) {
475 TEUCHOS_ASSERT(si == sides.begin());
481 elmtToAssociatedElmts[ea_id].push_back(eb_id);
482 elmtToAssociatedElmts[eb_id].push_back(ea_id);
490 std::vector<std::string> sidesets;
493 Teuchos::reduceAll(comm, Teuchos::REDUCE_MAX, 1, &my_sya, &sya);
500const std::vector<STKConnManager::LocalOrdinal>&
virtual int getDimension() const =0
virtual shards::CellTopology getCellTopology() const =0
virtual int numberIds() const
virtual const std::vector< int > & getSubcellIndices(int dim, int cellIndex) const =0
virtual Teuchos::RCP< panzer::FieldPattern > clone() const =0
virtual int getDimension() const
void getInterpolatoryCoordinates(Kokkos::DynRankView< double, PHX::Device > &coords) const
A panzer::ConnManager implementation backed by an STK mesh, mapping local element IDs to global mesh-...
Teuchos::RCP< std::vector< LocalOrdinal > > elmtLidToConnPtr_
std::vector< std::string > checkAssociateElementsInSidesets(const Teuchos::Comm< int > &comm) const
void applyPeriodicBCs(const panzer::FieldPattern &fp, GlobalOrdinal nodeOffset, GlobalOrdinal edgeOffset, GlobalOrdinal faceOffset, GlobalOrdinal cellOffset)
Teuchos::RCP< std::vector< stk::mesh::Entity > > elements_
void applyInterfaceConditions()
static int cached_reuse_count_
virtual Teuchos::RCP< panzer::ConnManager > noConnectivityClone() const
Teuchos::RCP< std::vector< GlobalOrdinal > > connectivityPtr_
std::map< std::string, Teuchos::RCP< std::vector< LocalOrdinal > > > neighborElementBlocks_
panzer::ConnManager::LocalOrdinal LocalOrdinal
Teuchos::RCP< std::vector< LocalOrdinal > > connSizePtr_
virtual void getDofCoords(const std::string &blockId, const panzer::Intrepid2FieldPattern &coordProvider, std::vector< std::size_t > &localCellIds, Kokkos::DynRankView< double, PHX::Device > &points) const
void buildOffsetsAndIdCounts(const panzer::FieldPattern &fp, LocalOrdinal &nodeIdCnt, LocalOrdinal &edgeIdCnt, LocalOrdinal &faceIdCnt, LocalOrdinal &cellIdCnt, GlobalOrdinal &nodeOffset, GlobalOrdinal &edgeOffset, GlobalOrdinal &faceOffset, GlobalOrdinal &cellOffset) const
std::size_t ownedElementCount_
STKConnManager(const Teuchos::RCP< const STK_Interface > &stkMeshDB)
Construct from the STK mesh to build connectivity from. buildConnectivity() must be called before con...
panzer::ConnManager::GlobalOrdinal GlobalOrdinal
virtual void buildConnectivity(const panzer::FieldPattern &fp)
void buildLocalElementMapping()
std::vector< bool > sidesetYieldedAssociations_
static std::vector< CachedEntry > cached_conn_managers_
virtual bool hasAssociatedNeighbors() const
static bool cache_connectivity_
LocalOrdinal addSubcellConnectivities(stk::mesh::Entity element, unsigned subcellRank, LocalOrdinal idCnt, GlobalOrdinal offset, const unsigned maxIds=0)
Loops over relations of a given rank for a specified element and adds a unique ID to the connectivity...
std::vector< std::string > sidesetsToAssociate_
virtual const std::vector< LocalOrdinal > & getAssociatedNeighbors(const LocalOrdinal &el) const
std::map< std::string, Teuchos::RCP< std::vector< LocalOrdinal > > > elementBlocks_
void clearLocalElementMapping()
Teuchos::RCP< const STK_Interface > stkMeshDB_
std::pair< Teuchos::RCP< const panzer::FieldPattern >, Teuchos::RCP< panzer_stk::STKConnManager > > CachedEntry
virtual std::string getBlockId(LocalOrdinal localElmtId) const
Teuchos::RCP< std::vector< std::vector< LocalOrdinal > > > elmtToAssociatedElmtsPtr_
void associateElementsInSideset(const std::string sideset_id)
static void clearCachedConnectivityData()
If you enable caching with cacheConnectivity(), this must be called prior to exiting the code.
void modifySubcellConnectivities(const panzer::FieldPattern &fp, stk::mesh::Entity element, unsigned subcellRank, unsigned subcellId, GlobalOrdinal newId, GlobalOrdinal offset)
void getIdsAndNodes(const panzer_stk::STK_Interface &mesh, std::string blockId, std::vector< std::size_t > &localIds, ArrayT &nodes)
std::size_t getElementIdx(const std::vector< stk::mesh::Entity > &elements, stk::mesh::Entity const e)
Matches a cache entry on mesh, field pattern and sideset association list.