18 #include "Kokkos_DynRankView.hpp"
25 #include "Teuchos_FancyOStream.hpp"
27 namespace panzer_stk {
34 class LocalIdCompare {
36 LocalIdCompare(
const RCP<const STK_Interface> & mesh) : mesh_(mesh) {}
39 bool operator() (stk::mesh::Entity a,stk::mesh::Entity b)
40 {
return mesh_->elementLocalId(a) < mesh_->elementLocalId(b);}
43 RCP<const STK_Interface> mesh_;
47 : stkMeshDB_(stkMeshDB), ownedElementCount_(0)
76 std::vector<std::string> blockIds;
79 std::size_t blockIndex=0;
80 for(std::vector<std::string>::const_iterator idItr=blockIds.begin();
81 idItr!=blockIds.end();++idItr,++blockIndex) {
82 std::string blockId = *idItr;
85 std::vector<stk::mesh::Entity> blockElmts;
93 for(std::size_t i=0;i<blockElmts.size();i++)
100 for(std::vector<std::string>::const_iterator idItr=blockIds.begin();
101 idItr!=blockIds.end();++idItr,++blockIndex) {
102 std::string blockId = *idItr;
105 std::vector<stk::mesh::Entity> blockElmts;
106 stkMeshDB_->getNeighborElements(blockId,blockElmts);
113 for(std::size_t i=0;i<blockElmts.size();i++)
161 edgeOffset = nodeOffset+(maxNodeId+1)*nodeIdCnt;
162 faceOffset = edgeOffset+(maxEdgeId+1)*edgeIdCnt;
163 cellOffset = faceOffset+(maxFaceId+1)*faceIdCnt;
167 && edgeOffset <= faceOffset
168 && faceOffset <= cellOffset);
173 unsigned subcellRank,
176 const unsigned maxIds)
183 stk::mesh::BulkData& bulkData = *
stkMeshDB_->getBulkData();
184 const stk::mesh::EntityRank rank =
static_cast<stk::mesh::EntityRank
>(subcellRank);
189 "ERROR: The maxIds (num vertices from basis cell topology) is greater than the num vertices in the stk mesh topology!");
192 const size_t num_rels = (maxIds > 0) ? maxIds : bulkData.num_connectivity(element, rank);
193 stk::mesh::Entity
const* relations = bulkData.begin(element, rank);
194 for(std::size_t sc=0; sc<num_rels; ++sc) {
195 stk::mesh::Entity subcell = relations[sc];
199 connectivity_.push_back(offset+idCnt*(bulkData.identifier(subcell)-1)+i);
214 const std::vector<int> & subCellIndices = fp.
getSubcellIndices(subcellRank,subcellId);
217 for(std::size_t i=0;i<subCellIndices.size();i++) {
218 conn[subCellIndices[i]] = offset+subCellIndices.size()*(newId-1)+i;
224 #ifdef HAVE_EXTRA_TIMERS
226 RCP<Teuchos::TimeMonitor> tM =
rcp(
new TimeMonitor(*TimeMonitor::getNewTimer(std::string(
"panzer_stk::STKConnManager::buildConnectivity"))));
229 stk::mesh::BulkData& bulkData = *
stkMeshDB_->getBulkData();
239 LocalOrdinal nodeIdCnt=0, edgeIdCnt=0, faceIdCnt=0, cellIdCnt=0;
240 GlobalOrdinal nodeOffset=0, edgeOffset=0, faceOffset=0, cellOffset=0;
242 nodeOffset, edgeOffset, faceOffset, cellOffset);
255 for(std::size_t elmtLid=0;elmtLid!=
elements_->size();++elmtLid) {
257 stk::mesh::Entity element = (*elements_)[elmtLid];
274 connectivity_.push_back(cellOffset+cellIdCnt*(bulkData.identifier(element)-1));
294 stk::mesh::Entity element = (*elements_)[localElmtId];
296 return stkMeshDB_->containingBlockId(element);
305 #ifdef HAVE_EXTRA_TIMERS
307 RCP<Teuchos::TimeMonitor> tM =
rcp(
new TimeMonitor(*TimeMonitor::getNewTimer(std::string(
"panzer_stk::STKConnManager::applyPeriodicBCs"))));
314 = matchedValues.first;
316 = matchedValues.second;
319 if(matchedNodes==Teuchos::null)
return;
321 for(std::size_t m=0;m<matchedNodes->size();m++) {
322 stk::mesh::EntityId oldNodeId = (*matchedNodes)[m].first;
323 std::size_t newNodeId = (*matchedNodes)[m].second;
325 std::vector<stk::mesh::Entity> elements;
326 std::vector<int> localIds;
330 if((*matchTypes)[m] == 0)
331 offset1 = nodeOffset-offset0;
332 else if((*matchTypes)[m] == 1){
334 offset1 = edgeOffset-offset0;
335 }
else if((*matchTypes)[m] == 2){
337 offset1 = faceOffset-offset0;
342 stkMeshDB_->getOwnedElementsSharingNode(stk::mesh::EntityId(oldNodeId-offset0),elements,localIds,(*matchTypes)[m]);
345 for(std::size_t e=0;e<elements.size();e++){
356 std::vector<std::size_t> & localCellIds,
357 Kokkos::DynRankView<double,PHX::Device> & points)
const
363 Kokkos::DynRankView<double,PHX::Device> nodes;
367 points = Kokkos::DynRankView<double,PHX::Device>(
"points",localCellIds.size(),numIds,dim);
384 stk::mesh::Entity
const e)
386 return static_cast<std::size_t
>(
387 std::distance(elements.begin(), std::find(elements.begin(), elements.end(), e)));
392 stk::mesh::BulkData& bulkData = *
stkMeshDB_->getBulkData();
395 std::vector<stk::mesh::Entity> sides;
398 for (std::vector<stk::mesh::Entity>::const_iterator si = sides.begin();
399 si != sides.end(); ++si) {
400 stk::mesh::Entity side = *si;
401 const size_t num_elements = bulkData.num_elements(side);
402 stk::mesh::Entity
const* elements = bulkData.begin_elements(side);
403 if (num_elements != 2) {
421 std::vector<std::string> sidesets;
431 const std::vector<STKConnManager::LocalOrdinal>&
void clearLocalElementMapping()
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::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
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
void getInterpolatoryCoordinates(Kokkos::DynRankView< double, PHX::Device > &coords) const
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_