13 #include <PanzerAdaptersSTK_config.hpp>
14 #include <stk_mesh/base/FEMHelpers.hpp>
19 namespace panzer_stk {
34 PANZER_FUNC_TIME_MONITOR(
"panzer::CubeHexMeshFactory::buildMesh()");
40 mesh->initialize(parallelMach);
50 PANZER_FUNC_TIME_MONITOR(
"panzer::CubeHexMeshFactory::buildUncomittedMesh()");
54 machRank_ = stk::parallel_machine_rank(parallelMach);
55 machSize_ = stk::parallel_machine_size(parallelMach);
67 const int maxFactor = 50;
70 int factors[maxFactor];
71 for (
int jj = 0; jj < maxFactor; jj++) factors[jj] = 0;
72 for (
int jj = 2; jj < maxFactor; jj++) {
75 int temp = ProcTemp/jj;
76 if (temp*jj == ProcTemp) {
86 for (
int jj = maxFactor-1; jj > 0; jj--) {
87 while (factors[jj] != 0) {
103 "Cannot build CubeHexMeshFactory, the product of \"X Procs\", \"Y Procs\", and \"Z Procs\""
104 " must equal the number of processors.");
118 PANZER_FUNC_TIME_MONITOR(
"panzer::CubeHexMeshFactory::completeMeshConstruction()");
134 out <<
"CubeHexMesh: Building sub cells" << std::endl;
139 out <<
"CubeHexMesh: NOT building sub cells" << std::endl;
175 x0_ = paramList->
get<
double>(
"X0");
176 y0_ = paramList->
get<
double>(
"Y0");
177 z0_ = paramList->
get<
double>(
"Z0");
179 xf_ = paramList->
get<
double>(
"Xf");
180 yf_ = paramList->
get<
double>(
"Yf");
181 zf_ = paramList->
get<
double>(
"Zf");
201 if (not buildSubcells_ && createEdgeBlocks_) {
206 out <<
"CubeHexMesh: NOT creating edge blocks because building sub cells disabled" << std::endl;
207 createEdgeBlocks_ =
false;
209 if (not buildSubcells_ && createFaceBlocks_) {
214 out <<
"CubeHexMesh: NOT creating face blocks because building sub cells disabled" << std::endl;
215 createFaceBlocks_ =
false;
228 if(defaultParams == Teuchos::null) {
231 defaultParams->
set<
double>(
"X0",0.0);
232 defaultParams->
set<
double>(
"Y0",0.0);
233 defaultParams->
set<
double>(
"Z0",0.0);
235 defaultParams->
set<
double>(
"Xf",1.0);
236 defaultParams->
set<
double>(
"Yf",1.0);
237 defaultParams->
set<
double>(
"Zf",1.0);
239 defaultParams->
set<
int>(
"X Blocks",1);
240 defaultParams->
set<
int>(
"Y Blocks",1);
241 defaultParams->
set<
int>(
"Z Blocks",1);
243 defaultParams->
set<
int>(
"X Procs",-1);
244 defaultParams->
set<
int>(
"Y Procs",1);
245 defaultParams->
set<
int>(
"Z Procs",1);
247 defaultParams->
set<
int>(
"X Elements",5);
248 defaultParams->
set<
int>(
"Y Elements",5);
249 defaultParams->
set<
int>(
"Z Elements",5);
251 defaultParams->
set<
bool>(
"Build Interface Sidesets",
false);
253 defaultParams->
set<
bool>(
"Build Subcells",
true);
256 defaultParams->
set<
bool>(
"Create Edge Blocks",
false,
"Create edge blocks in the mesh");
257 defaultParams->
set<
bool>(
"Create Face Blocks",
false,
"Create face blocks in the mesh");
260 bcs.
set<
int>(
"Count",0);
263 return defaultParams;
285 typedef shards::Hexahedron<8> HexTopo;
286 const CellTopologyData * ctd = shards::getCellTopologyData<HexTopo>();
287 const CellTopologyData * side_ctd = shards::CellTopology(ctd).getBaseCellTopologyData(2,0);
288 const CellTopologyData * edge_ctd = shards::CellTopology(ctd).getBaseCellTopologyData(1,0);
289 const CellTopologyData * face_ctd = shards::CellTopology(ctd).getBaseCellTopologyData(2,0);
297 std::stringstream ebPostfix;
298 ebPostfix <<
"-" << bx <<
"_" << by <<
"_" << bz;
327 std::stringstream ss;
328 ss <<
"vertical_" << bx-1;
332 std::stringstream ss;
333 ss <<
"horizontal_" << by-1;
337 std::stringstream ss;
338 ss <<
"transverse_" << bz-1;
351 for(
int xBlock=0;xBlock<
xBlocks_;xBlock++) {
352 for(
int yBlock=0;yBlock<
yBlocks_;yBlock++) {
353 for(
int zBlock=0;zBlock<
zBlocks_;zBlock++) {
354 buildBlock(parallelMach,xBlock,yBlock,zBlock,mesh);
368 panzer::GlobalOrdinal myXElems_start = sizeAndStartX.first;
369 panzer::GlobalOrdinal myXElems_end = myXElems_start+sizeAndStartX.second;
370 panzer::GlobalOrdinal myYElems_start = sizeAndStartY.first;
371 panzer::GlobalOrdinal myYElems_end = myYElems_start+sizeAndStartY.second;
372 panzer::GlobalOrdinal myZElems_start = sizeAndStartZ.first;
373 panzer::GlobalOrdinal myZElems_end = myZElems_start+sizeAndStartZ.second;
379 double deltaX = (
xf_-
x0_)/
double(totalXElems);
380 double deltaY = (
yf_-
y0_)/
double(totalYElems);
381 double deltaZ = (
zf_-
z0_)/
double(totalZElems);
383 std::vector<double> coord(3,0.0);
386 for(panzer::GlobalOrdinal nx=myXElems_start;nx<myXElems_end+1;++nx) {
388 for(panzer::GlobalOrdinal ny=myYElems_start;ny<myYElems_end+1;++ny) {
390 for(panzer::GlobalOrdinal nz=myZElems_start;nz<myZElems_end+1;++nz) {
393 mesh.
addNode(nz*(totalYElems+1)*(totalXElems+1)+ny*(totalXElems+1)+nx+1,coord);
398 std::stringstream blockName;
399 blockName <<
"eblock-" << xBlock <<
"_" << yBlock <<
"_" << zBlock;
403 for(panzer::GlobalOrdinal nx=myXElems_start;nx<myXElems_end;++nx) {
404 for(panzer::GlobalOrdinal ny=myYElems_start;ny<myYElems_end;++ny) {
405 for(panzer::GlobalOrdinal nz=myZElems_start;nz<myZElems_end;++nz) {
406 stk::mesh::EntityId gid = totalXElems*totalYElems*nz+totalXElems*ny+nx+1;
407 std::vector<stk::mesh::EntityId> nodes(8);
408 nodes[0] = nx+1+ny*(totalXElems+1) +nz*(totalYElems+1)*(totalXElems+1);
409 nodes[1] = nodes[0]+1;
410 nodes[2] = nodes[1]+(totalXElems+1);
411 nodes[3] = nodes[2]-1;
412 nodes[4] = nodes[0]+(totalYElems+1)*(totalXElems+1);
413 nodes[5] = nodes[1]+(totalYElems+1)*(totalXElems+1);
414 nodes[6] = nodes[2]+(totalYElems+1)*(totalXElems+1);
415 nodes[7] = nodes[3]+(totalYElems+1)*(totalXElems+1);
427 panzer::GlobalOrdinal minElements =
nXElems_/size;
428 panzer::GlobalOrdinal extra =
nXElems_ - minElements*size;
434 panzer::GlobalOrdinal nume=0, start=0;
435 if(panzer::GlobalOrdinal(xProcLoc)<extra) {
436 nume = minElements+1;
437 start = xProcLoc*(minElements+1);
441 start = extra*(minElements+1)+(xProcLoc-extra)*minElements;
444 return std::make_pair(start+
nXElems_*xBlock,nume);
453 panzer::GlobalOrdinal minElements =
nYElems_/size;
454 panzer::GlobalOrdinal extra =
nYElems_ - minElements*size;
460 panzer::GlobalOrdinal nume=0, start=0;
461 if(panzer::GlobalOrdinal(yProcLoc)<extra) {
462 nume = minElements+1;
463 start = yProcLoc*(minElements+1);
467 start = extra*(minElements+1)+(yProcLoc-extra)*minElements;
470 return std::make_pair(start+
nYElems_*yBlock,nume);
478 panzer::GlobalOrdinal minElements =
nZElems_/size;
479 panzer::GlobalOrdinal extra =
nZElems_ - minElements*size;
485 panzer::GlobalOrdinal nume=0, start=0;
486 if(zProcLoc<Teuchos::as<std::size_t>(extra)) {
487 nume = minElements+1;
488 start = zProcLoc*(minElements+1);
492 start = extra*(minElements+1)+(zProcLoc-extra)*minElements;
495 return std::make_pair(start+
nZElems_*zBlock,nume);
507 std::vector<stk::mesh::Entity> localElmts;
510 stk::mesh::EntityId offset[6];
512 offset[1] = offset[0] + totalXElems*totalZElems;
513 offset[2] = offset[1] + totalYElems*totalZElems;
514 offset[3] = offset[2] + totalXElems*totalZElems;
515 offset[4] = offset[3] + totalYElems*totalZElems;
516 offset[5] = offset[4] + totalXElems*totalYElems;
521 std::vector<stk::mesh::Entity>::const_iterator itr;
522 for(itr=localElmts.begin();itr!=localElmts.end();++itr) {
523 stk::mesh::Entity element = (*itr);
526 std::size_t nx,ny,nz;
527 nz = (gid-1) / (totalXElems*totalYElems);
528 gid = (gid-1)-nz*(totalXElems*totalYElems);
529 ny = gid / totalXElems;
530 nx = gid-ny*totalXElems;
532 std::vector<stk::mesh::Part*> parts;
536 mesh.
getBulkData()->declare_element_side(element, 4, parts);
538 if(nz+1==totalZElems) {
540 mesh.
getBulkData()->declare_element_side(element, 5, parts);
545 mesh.
getBulkData()->declare_element_side(element, 0, parts);
547 if(ny+1==totalYElems) {
549 mesh.
getBulkData()->declare_element_side(element, 2, parts);
554 mesh.
getBulkData()->declare_element_side(element, 3, parts);
556 if(nx+1==totalXElems) {
558 mesh.
getBulkData()->declare_element_side(element, 1, parts);
569 const stk::mesh::EntityRank side_rank = mesh.
getSideRank();
576 stk::mesh::Part * left = mesh.
getSideset(
"left");
577 stk::mesh::Part * right = mesh.
getSideset(
"right");
578 stk::mesh::Part * top = mesh.
getSideset(
"top");
579 stk::mesh::Part * bottom = mesh.
getSideset(
"bottom");
580 stk::mesh::Part * front = mesh.
getSideset(
"front");
581 stk::mesh::Part * back = mesh.
getSideset(
"back");
583 std::vector<stk::mesh::Part*> vertical;
584 std::vector<stk::mesh::Part*> horizontal;
585 std::vector<stk::mesh::Part*> transverse;
589 std::stringstream ss;
590 ss <<
"vertical_" << bx-1;
591 vertical.push_back(mesh.
getSideset(ss.str()));
594 std::stringstream ss;
595 ss <<
"horizontal_" << by-1;
596 horizontal.push_back(mesh.
getSideset(ss.str()));
599 std::stringstream ss;
600 ss <<
"transverse_" << bz-1;
601 transverse.push_back(mesh.
getSideset(ss.str()));
605 std::vector<stk::mesh::Entity> localElmts;
611 std::vector<stk::mesh::Entity>::const_iterator itr;
612 for(itr=localElmts.begin();itr!=localElmts.end();++itr) {
613 stk::mesh::Entity element = (*itr);
616 std::size_t nx,ny,nz;
617 nz = (gid-1) / (totalXElems*totalYElems);
618 gid = (gid-1)-nz*(totalXElems*totalYElems);
619 ny = gid / totalXElems;
620 nx = gid-ny*totalXElems;
642 if(nz+1==totalZElems) {
673 if(ny+1==totalYElems) {
704 if(nx+1==totalXElems) {
722 stk::mesh::Part * origin = mesh.
getNodeset(
"origin");
728 stk::mesh::Entity node = bulkData->get_entity(mesh.
getNodeRank(),1);
742 stk::mesh::Selector owned_block = metaData->locally_owned_part();
744 std::vector<stk::mesh::Entity> edges;
745 bulkData->get_entities(mesh.
getEdgeRank(), owned_block, edges);
758 stk::mesh::Selector owned_block = metaData->locally_owned_part();
760 std::vector<stk::mesh::Entity> faces;
761 bulkData->get_entities(mesh.
getFaceRank(), owned_block, faces);
768 std::size_t i=0,j=0,k=0;
774 return Teuchos::tuple(i,j,k);
void addSides(STK_Interface &mesh) const
void initializeWithDefaults()
virtual ~CubeHexMeshFactory()
Destructor.
void addNodeset(const std::string &name)
unsigned entityOwnerRank(stk::mesh::Entity entity) const
void addEntityToNodeset(stk::mesh::Entity entity, stk::mesh::Part *nodeset)
void addEdgeBlocks(STK_Interface &mesh) const
static void parsePeriodicBCList(const Teuchos::RCP< Teuchos::ParameterList > &pl, std::vector< Teuchos::RCP< const PeriodicBC_MatcherBase > > &periodicBC, bool &useBBoxSearch)
void addFaceBlocks(STK_Interface &mesh) const
void buildMetaData(stk::ParallelMachine parallelMach, STK_Interface &mesh) const
basic_FancyOStream & setShowProcRank(const bool showProcRank)
T & get(const std::string &name, T def_value)
stk::mesh::Part * getElementBlockPart(const std::string &name) const
get the block part
void buildElements(stk::ParallelMachine parallelMach, STK_Interface &mesh) const
panzer::GlobalOrdinal nXElems_
#define TEUCHOS_TEST_FOR_EXCEPTION(throw_exception_test, Exception, msg)
void addEntityToSideset(stk::mesh::Entity entity, stk::mesh::Part *sideset)
ParameterList & set(std::string const &name, T &&value, std::string const &docString="", RCP< const ParameterEntryValidator > const &validator=null)
void addSideSets(STK_Interface &mesh) const
stk::mesh::Part * getNodeset(const std::string &name) const
stk::mesh::Part * getFaceBlock(const std::string &name) const
get the block part
void addEdgeBlock(const std::string &elemBlockName, const std::string &edgeBlockName, const stk::topology &topology)
stk::mesh::Part * getSideset(const std::string &name) const
void addElement(const Teuchos::RCP< ElementDescriptor > &ed, stk::mesh::Part *block)
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
stk::mesh::EntityRank getSideRank() const
void initialize(stk::ParallelMachine parallelMach, bool setupIO=true, const bool buildRefinementSupport=false)
void rebalance(STK_Interface &mesh) const
Teuchos::RCP< stk::mesh::BulkData > getBulkData() const
void buildBlock(stk::ParallelMachine machRank, int xBlock, int yBlock, int zBlock, STK_Interface &mesh) const
void addNodeSets(STK_Interface &mesh) const
stk::mesh::EntityId elementGlobalId(std::size_t lid) const
void setMyParamList(const RCP< ParameterList > ¶mList)
void validateParametersAndSetDefaults(ParameterList const &validParamList, int const depth=1000)
static const std::string edgeBlockString
basic_FancyOStream & setOutputToRootOnly(const int rootRank)
void setParameterList(const Teuchos::RCP< Teuchos::ParameterList > ¶mList)
From ParameterListAcceptor.
std::pair< panzer::GlobalOrdinal, panzer::GlobalOrdinal > determineZElemSizeAndStart(int zBlock, unsigned int size, unsigned int rank) const
stk::mesh::EntityRank getFaceRank() const
void addNode(stk::mesh::EntityId gid, const std::vector< double > &coord)
void addEntitiesToEdgeBlock(std::vector< stk::mesh::Entity > entities, stk::mesh::Part *edgeblock)
void buildSubcells()
force the mesh to build subcells: edges and faces
Teuchos::Tuple< std::size_t, 3 > procTuple_
Teuchos::RCP< STK_Interface > buildMesh(stk::ParallelMachine parallelMach) const
Build the mesh object.
Teuchos::RCP< const Teuchos::ParameterList > getValidParameters() const
From ParameterListAcceptor.
CubeHexMeshFactory()
Constructor.
Teuchos::RCP< stk::mesh::MetaData > getMetaData() const
bool isInitialized() const
Has initialize been called on this mesh object?
stk::mesh::Entity findConnectivityById(stk::mesh::Entity src, stk::mesh::EntityRank tgt_rank, unsigned rel_id) const
void addSideset(const std::string &name, const CellTopologyData *ctData)
static const std::string faceBlockString
double getMeshCoord(const int nx, const double deltaX, const double x0) const
std::pair< panzer::GlobalOrdinal, panzer::GlobalOrdinal > determineXElemSizeAndStart(int xBlock, unsigned int size, unsigned int rank) const
stk::mesh::Part * getEdgeBlock(const std::string &name) const
get the block part
std::vector< Teuchos::RCP< const PeriodicBC_MatcherBase > > periodicBCVec_
stk::mesh::EntityRank getEdgeRank() const
void addEntitiesToFaceBlock(std::vector< stk::mesh::Entity > entities, stk::mesh::Part *faceblock)
bool buildInterfaceSidesets_
void buildLocalElementIDs()
void addFaceBlock(const std::string &elemBlockName, const std::string &faceBlockName, const stk::topology &topology)
ParameterList & sublist(const std::string &name, bool mustAlreadyExist=false, const std::string &docString="")
std::pair< panzer::GlobalOrdinal, panzer::GlobalOrdinal > determineYElemSizeAndStart(int yBlock, unsigned int size, unsigned int rank) const
panzer::GlobalOrdinal nYElems_
void getMyElements(std::vector< stk::mesh::Entity > &elements) const
#define TEUCHOS_ASSERT(assertion_test)
stk::mesh::EntityRank getNodeRank() const
virtual Teuchos::RCP< STK_Interface > buildUncommitedMesh(stk::ParallelMachine parallelMach) const
panzer::GlobalOrdinal nZElems_
void addElementBlock(const std::string &name, const CellTopologyData *ctData)
std::string edgeBlockName_
std::string faceBlockName_
virtual void completeMeshConstruction(STK_Interface &mesh, stk::ParallelMachine parallelMach) const
Teuchos::Tuple< std::size_t, 3 > procRankToProcTuple(std::size_t procRank) const
what is the 3D tuple describe this processor distribution