Panzer Version of the Day
Loading...
Searching...
No Matches
Panzer_STKConnManager.hpp
Go to the documentation of this file.
1// @HEADER
2// *****************************************************************************
3// Panzer: A partial differential equation assembly
4// engine for strongly coupled complex multiphysics systems
5//
6// Copyright 2011 NTESS and the Panzer contributors.
7// SPDX-License-Identifier: BSD-3-Clause
8// *****************************************************************************
9// @HEADER
10
11#ifndef __Panzer_STKConnManager_hpp__
12#define __Panzer_STKConnManager_hpp__
13
14#include <vector>
15
16// Teuchos includes
17#include "Teuchos_RCP.hpp"
18
19// Kokkos includes
20#include "Kokkos_DynRankView.hpp"
21
22// Panzer includes
24
27
28namespace panzer_stk {
29
56public:
59 typedef typename Kokkos::DynRankView<GlobalOrdinal,PHX::Device>::host_mirror_type::const_type GlobalOrdinalView;
60 typedef typename Kokkos::DynRankView<LocalOrdinal, PHX::Device>::host_mirror_type::const_type LocalOrdinalView;
61
63 STKConnManager(const Teuchos::RCP<const STK_Interface> & stkMeshDB);
64
67
68 virtual ~STKConnManager() {}
69
75 virtual void buildConnectivity(const panzer::FieldPattern & fp);
76
81 virtual Teuchos::RCP<panzer::ConnManager> noConnectivityClone() const;
82
90 virtual const panzer::GlobalOrdinal * getConnectivity(LocalOrdinal localElmtId) const
91 { return &(*connectivityPtr_)[(*elmtLidToConnPtr_)[localElmtId]]; }
92
100 { return (*connSizePtr_)[localElmtId]; }
101
105
109
113
118 virtual std::string getBlockId(LocalOrdinal localElmtId) const;
119
122 virtual std::size_t numElementBlocks() const
123 { return stkMeshDB_->getNumElementBlocks(); }
124
127 virtual void getElementBlockIds(std::vector<std::string> & elementBlockIds) const
128 { return stkMeshDB_->getElementBlockNames(elementBlockIds); }
129
132 virtual void getElementBlockTopologies(std::vector<shards::CellTopology> & elementBlockTopologies) const{
133 std::vector<std::string> elementBlockIds;
134 getElementBlockIds(elementBlockIds);
135 elementBlockTopologies.reserve(elementBlockIds.size());
136
137 for (unsigned i=0; i<elementBlockIds.size(); ++i) {
138 elementBlockTopologies.push_back(*(stkMeshDB_->getCellTopology(elementBlockIds[i])));
139 }
140 }
141
148 virtual const std::vector<LocalOrdinal> & getElementBlock(const std::string & blockId) const
149 { return *(elementBlocks_.find(blockId)->second); }
150
159 virtual const std::vector<LocalOrdinal> & getNeighborElementBlock(const std::string & blockId) const
160 { return *(neighborElementBlocks_.find(blockId)->second); }
161
170 virtual void getDofCoords(const std::string & blockId,
171 const panzer::Intrepid2FieldPattern & coordProvider,
172 std::vector<std::size_t> & localCellIds,
173 Kokkos::DynRankView<double,PHX::Device> & points) const;
174
177 Teuchos::RCP<const STK_Interface> getSTKInterface() const
178 { return stkMeshDB_; }
179
187 std::size_t getOwnedElementCount() const
188 { return ownedElementCount_; }
189
193 void associateElementsInSideset(const std::string sideset_id);
194
200 std::vector<std::string> checkAssociateElementsInSidesets(const Teuchos::Comm<int>& comm) const;
201
205 virtual const std::vector<LocalOrdinal>& getAssociatedNeighbors(const LocalOrdinal& el) const;
206
210 virtual bool hasAssociatedNeighbors() const;
211
218 static void cacheConnectivity()
219 { cache_connectivity_ = true; }
220
223 {
224 PANZER_FUNC_TIME_MONITOR("panzer::ConnectivityManager::clearCachedConnectivityData()");
225 cached_conn_managers_.clear();
226 }
227
233 static void clearCachedConnectivityData(const Teuchos::RCP<const STK_Interface>& mesh);
234
237 { return cached_reuse_count_; }
238
239protected:
245 void applyPeriodicBCs( const panzer::FieldPattern & fp, GlobalOrdinal nodeOffset, GlobalOrdinal edgeOffset,
246 GlobalOrdinal faceOffset, GlobalOrdinal cellOffset);
248
252 LocalOrdinal & nodeIdCnt, LocalOrdinal & edgeIdCnt,
253 LocalOrdinal & faceIdCnt, LocalOrdinal & cellIdCnt,
254 GlobalOrdinal & nodeOffset, GlobalOrdinal & edgeOffset,
255 GlobalOrdinal & faceOffset, GlobalOrdinal & cellOffset) const;
256
270 LocalOrdinal addSubcellConnectivities(stk::mesh::Entity element,unsigned subcellRank,
271 LocalOrdinal idCnt,GlobalOrdinal offset,const unsigned maxIds=0);
272
273 void modifySubcellConnectivities(const panzer::FieldPattern & fp, stk::mesh::Entity element,
274 unsigned subcellRank,unsigned subcellId,GlobalOrdinal newId,GlobalOrdinal offset);
275
276 Teuchos::RCP<const STK_Interface> stkMeshDB_;
277
278 Teuchos::RCP<std::vector<stk::mesh::Entity> > elements_;
279
280 // element block information
281 std::map<std::string,Teuchos::RCP<std::vector<LocalOrdinal> > > elementBlocks_;
282 std::map<std::string,Teuchos::RCP<std::vector<LocalOrdinal> > > neighborElementBlocks_;
283
284 // Large arrays are held by RCP so cached connectivity can be shared
285 // instead of copied. A rebuild must allocate new arrays rather than
286 // modify these in place, since they may be shared with the cache.
287 Teuchos::RCP<std::vector<LocalOrdinal> > elmtLidToConnPtr_; // element LID to Connectivity map
288 Teuchos::RCP<std::vector<LocalOrdinal> > connSizePtr_; // element LID to Connectivity size
289 Teuchos::RCP<std::vector<GlobalOrdinal> > connectivityPtr_; // Connectivity
290
292
293 std::vector<std::string> sidesetsToAssociate_;
295 Teuchos::RCP<std::vector<std::vector<LocalOrdinal> > > elmtToAssociatedElmtsPtr_;
296
297 using CachedEntry = std::pair<Teuchos::RCP<const panzer::FieldPattern>,Teuchos::RCP<panzer_stk::STKConnManager>>;
302 const std::vector<std::string>& sidesets_;
304 const STK_Interface* mesh,
305 const std::vector<std::string>& sidesets)
306 : fp_(fp), mesh_(mesh), sidesets_(sidesets) {}
307 bool inline operator()(const CachedEntry& entry_to_compare) const
308 {
309 const STKConnManager& cm = *entry_to_compare.second;
310 return (cm.stkMeshDB_.get() == mesh_) &&
312 fp_.equals(*entry_to_compare.first);
313 }
314 };
315
317 static std::vector<CachedEntry> cached_conn_managers_;
319};
320
321}
322
323#endif
Pure virtual base class for supplying mesh connectivity information to the DOF Manager.
panzer::GlobalOrdinal GlobalOrdinal
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_
const LocalOrdinalView getElementLidToConnView() const
Returns a read-only view of the per-element offset into the flat connectivity array returned by getCo...
virtual Teuchos::RCP< panzer::ConnManager > noConnectivityClone() const
Teuchos::RCP< std::vector< GlobalOrdinal > > connectivityPtr_
virtual const panzer::GlobalOrdinal * getConnectivity(LocalOrdinal localElmtId) const
std::map< std::string, Teuchos::RCP< std::vector< LocalOrdinal > > > neighborElementBlocks_
panzer::ConnManager::LocalOrdinal LocalOrdinal
Teuchos::RCP< std::vector< LocalOrdinal > > connSizePtr_
Kokkos::DynRankView< LocalOrdinal, PHX::Device >::host_mirror_type::const_type LocalOrdinalView
virtual void getDofCoords(const std::string &blockId, const panzer::Intrepid2FieldPattern &coordProvider, std::vector< std::size_t > &localCellIds, Kokkos::DynRankView< double, PHX::Device > &points) const
static int getCachedReuseCount()
This is purely for unit testing. Returns the number of times that buildConnectivity() was called,...
static void cacheConnectivity()
Enables the caching of connectivity data.
void buildOffsetsAndIdCounts(const panzer::FieldPattern &fp, LocalOrdinal &nodeIdCnt, LocalOrdinal &edgeIdCnt, LocalOrdinal &faceIdCnt, LocalOrdinal &cellIdCnt, GlobalOrdinal &nodeOffset, GlobalOrdinal &edgeOffset, GlobalOrdinal &faceOffset, GlobalOrdinal &cellOffset) const
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)
std::vector< bool > sidesetYieldedAssociations_
static std::vector< CachedEntry > cached_conn_managers_
virtual bool hasAssociatedNeighbors() const
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 getElementBlockIds(std::vector< std::string > &elementBlockIds) const
virtual LocalOrdinal getConnectivitySize(LocalOrdinal localElmtId) const
std::vector< std::string > sidesetsToAssociate_
virtual void getElementBlockTopologies(std::vector< shards::CellTopology > &elementBlockTopologies) const
virtual const std::vector< LocalOrdinal > & getAssociatedNeighbors(const LocalOrdinal &el) const
std::map< std::string, Teuchos::RCP< std::vector< LocalOrdinal > > > elementBlocks_
virtual const std::vector< LocalOrdinal > & getNeighborElementBlock(const std::string &blockId) const
Teuchos::RCP< const STK_Interface > getSTKInterface() const
const LocalOrdinalView getConnectivitySizeView() const
Returns a read-only view of the per-element connectivity size array.
const GlobalOrdinalView getConnectivityView() const
Returns a read-only view of the flat connectivity array (all elements' global IDs,...
virtual const std::vector< LocalOrdinal > & getElementBlock(const std::string &blockId) const
Teuchos::RCP< const STK_Interface > stkMeshDB_
std::pair< Teuchos::RCP< const panzer::FieldPattern >, Teuchos::RCP< panzer_stk::STKConnManager > > CachedEntry
Kokkos::DynRankView< GlobalOrdinal, PHX::Device >::host_mirror_type::const_type GlobalOrdinalView
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)
virtual std::size_t numElementBlocks() const
bool operator()(const CachedEntry &entry_to_compare) const
CacheKeyCompare(const panzer::FieldPattern &fp, const STK_Interface *mesh, const std::vector< std::string > &sidesets)