12 #include "Panzer_Workset_Builder.hpp"
13 #include "Teuchos_Assert.hpp"
15 #include <stk_mesh/base/Selector.hpp>
16 #include <stk_mesh/base/GetEntities.hpp>
18 namespace panzer_stk {
22 const std::string & eBlock,
25 using namespace workset_utils;
27 std::vector<std::string> element_blocks;
29 std::vector<std::size_t> local_cell_ids;
30 Kokkos::DynRankView<double,PHX::Device> cell_node_coordinates;
32 getIdsAndNodes(mesh, eBlock, local_cell_ids, cell_node_coordinates);
44 const std::string & sideset,
45 const std::string & eBlock,
48 using namespace workset_utils;
51 std::vector<stk::mesh::Entity> sideEntities;
63 std::vector<std::string> sideSets;
67 ss << e.what() <<
"\nChoose one of:\n";
68 for(std::size_t i=0;i<sideSets.size();i++)
69 ss <<
"\"" << sideSets[i] <<
"\"\n";
75 std::vector<std::string> elementBlocks;
79 ss << e.what() <<
"\nChoose one of:\n";
80 for(std::size_t i=0;i<elementBlocks.size();i++)
81 ss <<
"\"" << elementBlocks[i] <<
"\"\n";
85 catch(std::logic_error & e) {
87 ss << e.what() <<
"\nUnrecognized logic error.\n";
92 std::vector<stk::mesh::Entity> elements;
93 std::map<std::pair<unsigned,unsigned>,std::vector<std::size_t> > local_cell_ids;
96 std::vector<std::size_t> local_side_ids;
98 sideEntities,local_side_ids,elements);
101 for(std::size_t elm=0;elm<elements.size();++elm) {
102 stk::mesh::Entity element = elements[elm];
104 local_cell_ids[std::make_pair(subcell_dim,local_side_ids[elm])].push_back(mesh.
elementLocalId(element));
108 std::vector<std::size_t> local_subcell_ids, subcell_dim;
110 sideEntities,subcell_dim,local_subcell_ids,elements);
113 for(std::size_t elm=0;elm<elements.size();++elm) {
114 stk::mesh::Entity element = elements[elm];
116 local_cell_ids[std::make_pair(subcell_dim[elm],local_subcell_ids[elm])].push_back(mesh.
elementLocalId(element));
124 if(elements.size()!=0) {
131 for(std::map<std::pair<unsigned,unsigned>,std::vector<std::size_t> >::const_iterator itr=local_cell_ids.begin();
132 itr!=local_cell_ids.end();++itr) {
134 if(itr->second.size()==0)
137 Kokkos::DynRankView<double,PHX::Device> nodes;
144 for(std::size_t w=0;w<current->size();w++) {
145 (*current)[w].subcell_dim = itr->first.first;
146 (*current)[w].subcell_index = itr->first.second;
150 worksets->insert(worksets->end(),current->begin(),current->end());
157 return Teuchos::rcp(
new std::vector<panzer::Workset>());
163 const std::string & blockid_a,
165 const std::string & blockid_b,
166 const std::string & sideset)
168 using namespace workset_utils;
171 std::vector<stk::mesh::Entity> sideEntities;
181 stk::mesh::Part * sidePart = mesh.
getSideset(sideset);
183 "Unknown side set \"" << sideset <<
"\"");
185 stk::mesh::Selector side = *sidePart;
192 std::stringstream ss;
193 std::vector<std::string> elementBlocks;
197 ss << e.what() <<
"\nChoose one of:\n";
198 for(std::size_t i=0;i<elementBlocks.size();i++)
199 ss <<
"\"" << elementBlocks[i] <<
"\"\n";
203 catch(std::logic_error & e) {
204 std::stringstream ss;
205 ss << e.what() <<
"\nUnrecognized logic error.\n";
210 std::vector<stk::mesh::Entity> elements_a, elements_b;
211 std::vector<std::size_t> local_cell_ids_a, local_cell_ids_b;
212 std::vector<std::size_t> local_side_ids_a, local_side_ids_b;
216 local_side_ids_a,elements_a,
217 local_side_ids_b,elements_b);
220 "For a DG type boundary, the number of elements on the \"left\" and \"right\" is not the same.");
226 if(elements_a.size()==0)
227 return Teuchos::rcp(
new std::map<unsigned,panzer::Workset>);
232 for(std::size_t elm=0;elm<elements_a.size();++elm) {
233 stk::mesh::Entity element_a = elements_a[elm];
234 stk::mesh::Entity element_b = elements_b[elm];
240 Kokkos::DynRankView<double,PHX::Device> node_coordinates_a, node_coordinates_b;
245 return buildBCWorkset(needs_a,blockid_a, local_cell_ids_a, local_side_ids_a, node_coordinates_a,
246 needs_b,blockid_b, local_cell_ids_b, local_side_ids_b, node_coordinates_b);
252 const std::string & eblockID,
253 const std::string & sidesetID)
255 using namespace workset_utils;
258 std::vector<stk::mesh::Entity> sideEntities;
263 mesh.
getMySides(sidesetID,eblockID,sideEntities);
266 std::stringstream ss;
267 std::vector<std::string> sideSets;
271 ss << e.what() <<
"\nChoose one of:\n";
272 for(std::size_t i=0;i<sideSets.size();i++)
273 ss <<
"\"" << sideSets[i] <<
"\"\n";
278 std::stringstream ss;
279 std::vector<std::string> elementBlocks;
283 ss << e.what() <<
"\nChoose one of:\n";
284 for(std::size_t i=0;i<elementBlocks.size();i++)
285 ss <<
"\"" << elementBlocks[i] <<
"\"\n";
289 catch(std::logic_error & e) {
290 std::stringstream ss;
291 ss << e.what() <<
"\nUnrecognized logic error.\n";
296 std::vector<stk::mesh::Entity> elements;
297 std::vector<std::size_t> local_cell_ids;
298 std::vector<std::size_t> local_side_ids;
300 sideEntities,local_side_ids,elements);
303 for(std::size_t elm=0;elm<elements.size();++elm) {
304 stk::mesh::Entity element = elements[elm];
313 if(elements.size()!=0) {
317 Kokkos::DynRankView<double,PHX::Device> nodes;
323 return Teuchos::null;
326 namespace workset_utils {
329 const std::string & blockId,
330 const std::vector<stk::mesh::Entity> & entities,
331 std::vector<std::size_t> & localEntityIds,
332 std::vector<stk::mesh::Entity> & elements)
337 stk::mesh::BulkData& bulkData = *mesh.
getBulkData();
341 std::vector<stk::mesh::Entity>::const_iterator entityItr;
342 for(entityItr=entities.begin();entityItr!=entities.end();++entityItr) {
343 stk::mesh::Entity entity = *entityItr;
345 const size_t num_rels = bulkData.num_elements(entity);
346 stk::mesh::Entity
const* relations = bulkData.begin_elements(entity);
347 stk::mesh::ConnectivityOrdinal
const* ordinals = bulkData.begin_element_ordinals(entity);
348 for(std::size_t e=0; e<num_rels; ++e) {
349 stk::mesh::Entity element = relations[e];
350 std::size_t entityId = ordinals[e];
353 stk::mesh::Bucket
const& bucket = bulkData.bucket(element);
354 bool inBlock = bucket.member(*blockPart);
355 bool onProc = bucket.member(*ownedPart);
356 if(inBlock && onProc) {
358 elements.push_back(element);
359 localEntityIds.push_back(entityId);
366 const std::string & blockId,
367 const std::vector<stk::mesh::Entity> & entities,
368 std::vector<std::size_t> & localEntityIds,
369 std::vector<stk::mesh::Entity> & elements,
370 std::vector<std::size_t> & missingElementIndices)
374 stk::mesh::Part * universalPart = &mesh.
getMetaData()->universal_part();
375 stk::mesh::BulkData& bulkData = *mesh.
getBulkData();
379 std::size_t entityIndex =-1;
380 std::vector<stk::mesh::Entity>::const_iterator entityItr;
381 for(entityItr=entities.begin();entityItr!=entities.end();++entityItr) {
382 stk::mesh::Entity entity = *entityItr;
385 const size_t num_rels = bulkData.num_elements(entity);
386 stk::mesh::Entity
const* element_rels = bulkData.begin_elements(entity);
387 stk::mesh::ConnectivityOrdinal
const* ordinals = bulkData.begin_element_ordinals(entity);
388 for(std::size_t e=0; e<num_rels; ++e) {
389 stk::mesh::Entity element = element_rels[e];
390 std::size_t entityId = ordinals[e];
393 stk::mesh::Bucket
const& bucket = bulkData.bucket(element);
394 bool inBlock = bucket.member(*blockPart);
395 bool onProc = bucket.member(*universalPart);
396 if(inBlock && onProc) {
398 elements.push_back(element);
399 localEntityIds.push_back(entityId);
400 }
else if(!inBlock && (num_rels == 1)) {
403 missingElementIndices.push_back(entityIndex);
410 const std::string & blockId,
411 const std::vector<stk::mesh::Entity> & sides,
412 std::vector<std::size_t> & localSubcellDim,
413 std::vector<std::size_t> & localSubcellIds,
414 std::vector<stk::mesh::Entity> & elements)
421 std::vector<std::vector<stk::mesh::Entity> > subcells;
423 subcells.push_back(sides);
428 for(std::size_t d=0;d<subcells.size();d++) {
429 std::vector<std::size_t> subcellIds;
430 std::vector<stk::mesh::Entity> subcellElements;
439 localSubcellDim.insert(localSubcellDim.end(),subcellElements.size(),d);
440 localSubcellIds.insert(localSubcellIds.end(),subcellIds.begin(),subcellIds.end());
441 elements.insert(elements.end(),subcellElements.begin(),subcellElements.end());
446 const std::string & blockId,
447 const std::vector<stk::mesh::Entity> & sides,
448 std::vector<std::size_t> & localSideIds,
449 std::vector<stk::mesh::Entity> & elements)
455 const std::string & blockId_a,
456 const std::string & blockId_b,
457 const std::vector<stk::mesh::Entity> & sides,
458 std::vector<std::size_t> & localSideIds_a,
459 std::vector<stk::mesh::Entity> & elements_a,
460 std::vector<std::size_t> & localSideIds_b,
461 std::vector<stk::mesh::Entity> & elements_b)
467 stk::mesh::Part * universalPart = &mesh.
getMetaData()->universal_part();
468 stk::mesh::BulkData& bulkData = *mesh.
getBulkData();
472 std::vector<stk::mesh::Entity>::const_iterator sidesItr;
473 for(sidesItr=sides.begin();sidesItr!=sides.end();++sidesItr) {
474 stk::mesh::Entity side = *sidesItr;
477 stk::mesh::Entity element_a = stk::mesh::Entity(), element_b = stk::mesh::Entity();
478 std::size_t entityId_a=0, entityId_b=0;
480 const size_t num_rels = bulkData.num_elements(side);
481 stk::mesh::Entity
const* element_rels = bulkData.begin_elements(side);
482 stk::mesh::ConnectivityOrdinal
const* ordinals = bulkData.begin_element_ordinals(side);
483 for(std::size_t e=0; e<num_rels; ++e) {
484 stk::mesh::Entity element = element_rels[e];
485 std::size_t entityId = ordinals[e];
488 stk::mesh::Bucket
const& bucket = bulkData.bucket(element);
489 bool inBlock_a = bucket.member(*blockPart_a);
490 bool inBlock_b = bucket.member(*blockPart_b);
491 bool onProc = bucket.member(*ownedPart);
492 bool unProc = bucket.member(*universalPart);
494 if(inBlock_a && onProc) {
497 entityId_a = entityId;
499 if(inBlock_b && unProc) {
502 entityId_b = entityId;
506 if(element_a!=stk::mesh::Entity() && element_b!=stk::mesh::Entity()) {
507 elements_a.push_back(element_a);
508 localSideIds_a.push_back(entityId_a);
511 elements_b.push_back(element_b);
512 localSideIds_b.push_back(entityId_b);
518 const std::string & blockId,
519 const std::vector<stk::mesh::Entity> & nodes,
520 std::vector<std::size_t> & localNodeIds,
521 std::vector<stk::mesh::Entity> & elements)
527 const std::vector<stk::mesh::Entity> & entities,
528 std::vector<std::vector<stk::mesh::Entity> > & subcells)
531 if(entities.size()==0) {
536 stk::mesh::BulkData& bulkData = *mesh.
getBulkData();
537 stk::mesh::EntityRank master_rank = bulkData.entity_rank(entities[0]);
539 std::vector<std::set<stk::mesh::Entity> > subcells_set(master_rank);
543 std::vector<stk::mesh::Entity>::const_iterator entityItr;
544 for(entityItr=entities.begin();entityItr!=entities.end();++entityItr) {
545 stk::mesh::Entity entity = *entityItr;
550 for(
int i=0; i<static_cast<int>(master_rank); i++) {
551 stk::mesh::EntityRank
const to_rank =
static_cast<stk::mesh::EntityRank
>(i);
552 const size_t num_rels = bulkData.num_connectivity(entity, to_rank);
553 stk::mesh::Entity
const* relations = bulkData.begin(entity, to_rank);
557 for(std::size_t e=0; e<num_rels; ++e) {
558 stk::mesh::Entity subcell = relations[e];
560 subcells_set[i].insert(subcell);
567 subcells.resize(subcells_set.size());
568 for(std::size_t i=0;i<subcells_set.size();i++)
569 subcells[i].assign(subcells_set[i].begin(),subcells_set[i].end());
void getSidesetNames(std::vector< std::string > &name) const
int baseCellDimension() const
Dimension of the base cell. NOT the dimension of the local side, even if the side() method returns tr...
void getElementBlockNames(std::vector< std::string > &names) const
stk::mesh::Part * getElementBlockPart(const std::string &name) const
get the block part
void getSubcellEntities(const panzer_stk::STK_Interface &mesh, const std::vector< stk::mesh::Entity > &entities, std::vector< std::vector< stk::mesh::Entity > > &subcells)
#define TEUCHOS_TEST_FOR_EXCEPTION(throw_exception_test, Exception, msg)
void getElementNodes(const std::vector< std::size_t > &localIds, ArrayT &nodes) const
Teuchos::RCP< std::vector< Workset > > buildWorksets(const WorksetNeeds &needs, const std::string &elementBlock, const std::vector< std::size_t > &local_cell_ids, const ArrayT &node_coordinates)
Teuchos::RCP< std::vector< panzer::Workset > > buildWorksets(const panzer_stk::STK_Interface &mesh, const std::string &eBlock, const panzer::WorksetNeeds &needs)
void getIdsAndNodes(const panzer_stk::STK_Interface &mesh, std::string blockId, std::vector< std::size_t > &localIds, ArrayT &nodes)
void getSubcellElements(const panzer_stk::STK_Interface &mesh, const std::string &blockId, const std::vector< stk::mesh::Entity > &entities, std::vector< std::size_t > &localEntityIds, std::vector< stk::mesh::Entity > &elements)
Teuchos::RCP< std::map< unsigned, panzer::Workset > > buildBCWorksets(const panzer_stk::STK_Interface &mesh, const panzer::WorksetNeeds &needs_a, const std::string &blockid_a, const panzer::WorksetNeeds &needs_b, const std::string &blockid_b, const std::string &sideset)
stk::mesh::Part * getSideset(const std::string &name) const
void getMySides(const std::string &sideName, std::vector< stk::mesh::Entity > &sides) const
std::size_t elementLocalId(stk::mesh::Entity elmt) const
void getSideElements(const panzer_stk::STK_Interface &mesh, const std::string &blockId, const std::vector< stk::mesh::Entity > &sides, std::vector< std::size_t > &localSideIds, std::vector< stk::mesh::Entity > &elements)
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
stk::mesh::EntityRank getSideRank() const
void getUniversalSubcellElements(const panzer_stk::STK_Interface &mesh, const std::string &blockId, const std::vector< stk::mesh::Entity > &entities, std::vector< std::size_t > &localEntityIds, std::vector< stk::mesh::Entity > &elements, std::vector< std::size_t > &missingElementIndices)
Teuchos::RCP< stk::mesh::BulkData > getBulkData() const
Teuchos::RCP< std::map< unsigned, Workset > > buildBCWorkset(const WorksetNeeds &needs, const std::string &elementBlock, const std::vector< std::size_t > &local_cell_ids, const std::vector< std::size_t > &local_side_ids, const ArrayT &node_coordinates, const bool populate_value_arrays=true)
Teuchos::RCP< stk::mesh::MetaData > getMetaData() const
void getAllSides(const std::string &sideName, std::vector< stk::mesh::Entity > &sides) const
#define TEUCHOS_ASSERT(assertion_test)
void getSideElementCascade(const panzer_stk::STK_Interface &mesh, const std::string &blockId, const std::vector< stk::mesh::Entity > &sides, std::vector< std::size_t > &localSubcellDim, std::vector< std::size_t > &localSubcellIds, std::vector< stk::mesh::Entity > &elements)
void getNodeElements(const panzer_stk::STK_Interface &mesh, const std::string &blockId, const std::vector< stk::mesh::Entity > &nodes, std::vector< std::size_t > &localNodeIds, std::vector< stk::mesh::Entity > &elements)
stk::mesh::Part * getOwnedPart() const
Get a pointer to the locally owned part.
Teuchos::RCP< const shards::CellTopology > getCellTopology(const std::string &eBlock) const
#define TEUCHOS_TEST_FOR_EXCEPTION_PURE_MSG(throw_exception_test, Exception, msg)