18 #include "Kokkos_DynRankView.hpp"
25 #include "Teuchos_FancyOStream.hpp"
27 namespace panzer_stk {
39 class LocalIdCompare {
41 LocalIdCompare(
const RCP<const STK_Interface> & mesh) : mesh_(mesh) {}
44 bool operator() (stk::mesh::Entity a,stk::mesh::Entity b)
45 {
return mesh_->elementLocalId(a) < mesh_->elementLocalId(b);}
48 RCP<const STK_Interface> mesh_;
52 : stkMeshDB_(stkMeshDB), ownedElementCount_(0)
57 : stkMeshDB_(cm.stkMeshDB_),
58 elements_(cm.elements_),
59 elementBlocks_(cm.elementBlocks_),
60 neighborElementBlocks_(cm.neighborElementBlocks_),
61 blockIdToIndex_(cm.blockIdToIndex_),
62 elmtLidToConn_(cm.elmtLidToConn_),
63 connSize_(cm.connSize_),
64 connectivity_(cm.connectivity_),
65 ownedElementCount_(cm.ownedElementCount_),
66 sidesetsToAssociate_(cm.sidesetsToAssociate_),
67 sidesetYieldedAssociations_(cm.sidesetYieldedAssociations_)
99 std::vector<std::string> blockIds;
102 std::size_t blockIndex=0;
103 for(std::vector<std::string>::const_iterator idItr=blockIds.begin();
104 idItr!=blockIds.end();++idItr,++blockIndex) {
105 std::string blockId = *idItr;
108 std::vector<stk::mesh::Entity> blockElmts;
109 stkMeshDB_->getMyElements(blockId,blockElmts);
116 for(std::size_t i=0;i<blockElmts.size();i++)
123 for(std::vector<std::string>::const_iterator idItr=blockIds.begin();
124 idItr!=blockIds.end();++idItr,++blockIndex) {
125 std::string blockId = *idItr;
128 std::vector<stk::mesh::Entity> blockElmts;
129 stkMeshDB_->getNeighborElements(blockId,blockElmts);
136 for(std::size_t i=0;i<blockElmts.size();i++)
184 edgeOffset = nodeOffset+(maxNodeId+1)*nodeIdCnt;
185 faceOffset = edgeOffset+(maxEdgeId+1)*edgeIdCnt;
186 cellOffset = faceOffset+(maxFaceId+1)*faceIdCnt;
190 && edgeOffset <= faceOffset
191 && faceOffset <= cellOffset);
196 unsigned subcellRank,
199 const unsigned maxIds)
206 stk::mesh::BulkData& bulkData = *
stkMeshDB_->getBulkData();
207 const stk::mesh::EntityRank rank =
static_cast<stk::mesh::EntityRank
>(subcellRank);
212 "ERROR: The maxIds (num vertices from basis cell topology) is greater than the num vertices in the stk mesh topology!");
215 const size_t num_rels = (maxIds > 0) ? maxIds : bulkData.num_connectivity(element, rank);
216 stk::mesh::Entity
const* relations = bulkData.begin(element, rank);
217 for(std::size_t sc=0; sc<num_rels; ++sc) {
218 stk::mesh::Entity subcell = relations[sc];
222 connectivity_.push_back(offset+idCnt*(bulkData.identifier(subcell)-1)+i);
237 const std::vector<int> & subCellIndices = fp.
getSubcellIndices(subcellRank,subcellId);
240 for(std::size_t i=0;i<subCellIndices.size();i++) {
241 conn[subCellIndices[i]] = offset+subCellIndices.size()*(newId-1)+i;
247 PANZER_FUNC_TIME_MONITOR_DIFF(
"panzer_stk::STKConnManager::buildConnectivity", build_connectivity);
250 auto fp_rcp = fp.
clone();
255 PANZER_FUNC_TIME_MONITOR_DIFF(
"panzer_stk::STKConnManager::copyingCachedConnectivity", copy_cached_connectivity);
279 stk::mesh::BulkData& bulkData = *
stkMeshDB_->getBulkData();
289 LocalOrdinal nodeIdCnt=0, edgeIdCnt=0, faceIdCnt=0, cellIdCnt=0;
290 GlobalOrdinal nodeOffset=0, edgeOffset=0, faceOffset=0, cellOffset=0;
292 nodeOffset, edgeOffset, faceOffset, cellOffset);
305 for(std::size_t elmtLid=0;elmtLid!=
elements_->size();++elmtLid) {
307 stk::mesh::Entity element = (*elements_)[elmtLid];
324 connectivity_.push_back(cellOffset+cellIdCnt*(bulkData.identifier(element)-1));
341 auto fp_rcp = fp.
clone();
349 stk::mesh::Entity element = (*elements_)[localElmtId];
351 return stkMeshDB_->containingBlockId(element);
360 PANZER_FUNC_TIME_MONITOR_DIFF(
"panzer_stk::STKConnManager::applyPeriodicBCs", apply_periodic_bcs);
366 = matchedValues.first;
368 = matchedValues.second;
371 if(matchedNodes==Teuchos::null)
return;
373 for(std::size_t m=0;m<matchedNodes->size();m++) {
374 stk::mesh::EntityId oldNodeId = (*matchedNodes)[m].first;
375 std::size_t newNodeId = (*matchedNodes)[m].second;
377 std::vector<stk::mesh::Entity> elements;
378 std::vector<int> localIds;
382 if((*matchTypes)[m] == 0)
383 offset1 = nodeOffset-offset0;
384 else if((*matchTypes)[m] == 1){
386 offset1 = edgeOffset-offset0;
387 }
else if((*matchTypes)[m] == 2){
389 offset1 = faceOffset-offset0;
394 stkMeshDB_->getOwnedElementsSharingNode(stk::mesh::EntityId(oldNodeId-offset0),elements,localIds,(*matchTypes)[m]);
397 for(std::size_t e=0;e<elements.size();e++){
408 std::vector<std::size_t> & localCellIds,
409 Kokkos::DynRankView<double,PHX::Device> & points)
const
415 Kokkos::DynRankView<double,PHX::Device> nodes;
419 points = Kokkos::DynRankView<double,PHX::Device>(
"points",localCellIds.size(),numIds,dim);
436 stk::mesh::Entity
const e)
438 return static_cast<std::size_t
>(
439 std::distance(elements.begin(), std::find(elements.begin(), elements.end(), e)));
444 stk::mesh::BulkData& bulkData = *
stkMeshDB_->getBulkData();
447 std::vector<stk::mesh::Entity> sides;
450 for (std::vector<stk::mesh::Entity>::const_iterator si = sides.begin();
451 si != sides.end(); ++si) {
452 stk::mesh::Entity side = *si;
453 const size_t num_elements = bulkData.num_elements(side);
454 stk::mesh::Entity
const* elements = bulkData.begin_elements(side);
455 if (num_elements != 2) {
473 std::vector<std::string> sidesets;
483 const std::vector<STKConnManager::LocalOrdinal>&
void clearLocalElementMapping()
virtual Teuchos::RCP< panzer::FieldPattern > clone() const =0
virtual int getDimension() const =0
std::map< std::string, Teuchos::RCP< std::vector< LocalOrdinal > > > elementBlocks_
virtual const std::vector< LocalOrdinal > & getAssociatedNeighbors(const LocalOrdinal &el) const
virtual int getDimension() const
virtual std::string getBlockId(LocalOrdinal localElmtId) const
panzer::ConnManager::GlobalOrdinal GlobalOrdinal
#define TEUCHOS_TEST_FOR_EXCEPTION(throw_exception_test, Exception, msg)
std::vector< bool > sidesetYieldedAssociations_
std::map< std::string, Teuchos::RCP< std::vector< LocalOrdinal > > > neighborElementBlocks_
Teuchos::RCP< const STK_Interface > stkMeshDB_
std::map< std::string, GlobalOrdinal > blockIdToIndex_
std::vector< GlobalOrdinal > connectivity_
std::size_t ownedElementCount_
void getIdsAndNodes(const panzer_stk::STK_Interface &mesh, std::string blockId, std::vector< std::size_t > &localIds, ArrayT &nodes)
virtual bool hasAssociatedNeighbors() const
std::vector< std::string > checkAssociateElementsInSidesets(const Teuchos::Comm< int > &comm) const
std::vector< std::vector< LocalOrdinal > > elmtToAssociatedElmts_
virtual int numberIds() const
virtual const panzer::GlobalOrdinal * getConnectivity(LocalOrdinal localElmtId) const
void buildOffsetsAndIdCounts(const panzer::FieldPattern &fp, LocalOrdinal &nodeIdCnt, LocalOrdinal &edgeIdCnt, LocalOrdinal &faceIdCnt, LocalOrdinal &cellIdCnt, GlobalOrdinal &nodeOffset, GlobalOrdinal &edgeOffset, GlobalOrdinal &faceOffset, GlobalOrdinal &cellOffset) const
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
virtual Teuchos::RCP< panzer::ConnManager > noConnectivityClone() const
static std::vector< CachedEntry > cached_conn_managers_
void modifySubcellConnectivities(const panzer::FieldPattern &fp, stk::mesh::Entity element, unsigned subcellRank, unsigned subcellId, GlobalOrdinal newId, GlobalOrdinal offset)
void applyPeriodicBCs(const panzer::FieldPattern &fp, GlobalOrdinal nodeOffset, GlobalOrdinal edgeOffset, GlobalOrdinal faceOffset, GlobalOrdinal cellOffset)
panzer::ConnManager::LocalOrdinal LocalOrdinal
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...
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 buildLocalElementMapping()
std::vector< LocalOrdinal > elmtLidToConn_
std::vector< std::string > sidesetsToAssociate_
virtual shards::CellTopology getCellTopology() const =0
static int cached_reuse_count_
void getInterpolatoryCoordinates(Kokkos::DynRankView< double, PHX::Device > &coords) const
static bool cache_connectivity_
virtual const std::vector< int > & getSubcellIndices(int dim, int cellIndex) const =0
void applyInterfaceConditions()
#define TEUCHOS_ASSERT(assertion_test)
Teuchos::RCP< std::vector< stk::mesh::Entity > > elements_
std::size_t getElementIdx(const std::vector< stk::mesh::Entity > &elements, stk::mesh::Entity const e)
virtual void buildConnectivity(const panzer::FieldPattern &fp)
STKConnManager(const Teuchos::RCP< const STK_Interface > &stkMeshDB)
void associateElementsInSideset(const std::string sideset_id)
std::vector< LocalOrdinal > connSize_