45 #include <PanzerAdaptersSTK_config.hpp>
46 #include <FEMHelpers.hpp>
51 namespace panzer_stk {
66 PANZER_FUNC_TIME_MONITOR(
"panzer::CubeHexMeshFactory::buildMesh()");
72 mesh->initialize(parallelMach);
82 PANZER_FUNC_TIME_MONITOR(
"panzer::CubeHexMeshFactory::buildUncomittedMesh()");
86 machRank_ = stk::parallel_machine_rank(parallelMach);
87 machSize_ = stk::parallel_machine_size(parallelMach);
99 const int maxFactor = 50;
102 int factors[maxFactor];
103 for (
int jj = 0; jj < maxFactor; jj++) factors[jj] = 0;
104 for (
int jj = 2; jj < maxFactor; jj++) {
107 int temp = ProcTemp/jj;
108 if (temp*jj == ProcTemp) {
118 for (
int jj = maxFactor-1; jj > 0; jj--) {
119 while (factors[jj] != 0) {
135 "Cannot build CubeHexMeshFactory, the product of \"X Procs\", \"Y Procs\", and \"Z Procs\""
136 " must equal the number of processors.");
149 PANZER_FUNC_TIME_MONITOR(
"panzer::CubeHexMeshFactory::completeMeshConstruction()");
165 out <<
"CubeHexMesh: Building sub cells" << std::endl;
170 out <<
"CubeHexMesh: NOT building sub cells" << std::endl;
190 x0_ = paramList->
get<
double>(
"X0");
191 y0_ = paramList->
get<
double>(
"Y0");
192 z0_ = paramList->
get<
double>(
"Z0");
194 xf_ = paramList->
get<
double>(
"Xf");
195 yf_ = paramList->
get<
double>(
"Yf");
196 zf_ = paramList->
get<
double>(
"Zf");
224 if(defaultParams == Teuchos::null) {
227 defaultParams->
set<
double>(
"X0",0.0);
228 defaultParams->
set<
double>(
"Y0",0.0);
229 defaultParams->
set<
double>(
"Z0",0.0);
231 defaultParams->
set<
double>(
"Xf",1.0);
232 defaultParams->
set<
double>(
"Yf",1.0);
233 defaultParams->
set<
double>(
"Zf",1.0);
235 defaultParams->
set<
int>(
"X Blocks",1);
236 defaultParams->
set<
int>(
"Y Blocks",1);
237 defaultParams->
set<
int>(
"Z Blocks",1);
239 defaultParams->
set<
int>(
"X Procs",-1);
240 defaultParams->
set<
int>(
"Y Procs",1);
241 defaultParams->
set<
int>(
"Z Procs",1);
243 defaultParams->
set<
int>(
"X Elements",5);
244 defaultParams->
set<
int>(
"Y Elements",5);
245 defaultParams->
set<
int>(
"Z Elements",5);
247 defaultParams->
set<
bool>(
"Build Interface Sidesets",
false);
249 defaultParams->
set<
bool>(
"Build Subcells",
true);
252 bcs.
set<
int>(
"Count",0);
255 return defaultParams;
269 typedef shards::Hexahedron<8> HexTopo;
270 const CellTopologyData * ctd = shards::getCellTopologyData<HexTopo>();
271 const CellTopologyData * side_ctd = shards::CellTopology(ctd).getBaseCellTopologyData(2,0);
279 std::stringstream ebPostfix;
280 ebPostfix <<
"-" << bx <<
"_" << by <<
"_" << bz;
298 std::stringstream ss;
299 ss <<
"vertical_" << bx-1;
303 std::stringstream ss;
304 ss <<
"horizontal_" << by-1;
308 std::stringstream ss;
309 ss <<
"transverse_" << bz-1;
322 for(
int xBlock=0;xBlock<
xBlocks_;xBlock++) {
323 for(
int yBlock=0;yBlock<
yBlocks_;yBlock++) {
324 for(
int zBlock=0;zBlock<
zBlocks_;zBlock++) {
325 buildBlock(parallelMach,xBlock,yBlock,zBlock,mesh);
339 panzer::Ordinal64 myXElems_start = sizeAndStartX.first;
340 panzer::Ordinal64 myXElems_end = myXElems_start+sizeAndStartX.second;
341 panzer::Ordinal64 myYElems_start = sizeAndStartY.first;
342 panzer::Ordinal64 myYElems_end = myYElems_start+sizeAndStartY.second;
343 panzer::Ordinal64 myZElems_start = sizeAndStartZ.first;
344 panzer::Ordinal64 myZElems_end = myZElems_start+sizeAndStartZ.second;
350 double deltaX = (
xf_-
x0_)/
double(totalXElems);
351 double deltaY = (
yf_-
y0_)/
double(totalYElems);
352 double deltaZ = (
zf_-
z0_)/
double(totalZElems);
354 std::vector<double> coord(3,0.0);
357 for(panzer::Ordinal64 nx=myXElems_start;nx<myXElems_end+1;++nx) {
358 coord[0] = double(nx)*deltaX+
x0_;
359 for(panzer::Ordinal64 ny=myYElems_start;ny<myYElems_end+1;++ny) {
360 coord[1] = double(ny)*deltaY+
y0_;
361 for(panzer::Ordinal64 nz=myZElems_start;nz<myZElems_end+1;++nz) {
362 coord[2] = double(nz)*deltaZ+
z0_;
364 mesh.
addNode(nz*(totalYElems+1)*(totalXElems+1)+ny*(totalXElems+1)+nx+1,coord);
369 std::stringstream blockName;
370 blockName <<
"eblock-" << xBlock <<
"_" << yBlock <<
"_" << zBlock;
374 for(panzer::Ordinal64 nx=myXElems_start;nx<myXElems_end;++nx) {
375 for(panzer::Ordinal64 ny=myYElems_start;ny<myYElems_end;++ny) {
376 for(panzer::Ordinal64 nz=myZElems_start;nz<myZElems_end;++nz) {
377 stk::mesh::EntityId gid = totalXElems*totalYElems*nz+totalXElems*ny+nx+1;
378 std::vector<stk::mesh::EntityId> nodes(8);
379 nodes[0] = nx+1+ny*(totalXElems+1) +nz*(totalYElems+1)*(totalXElems+1);
380 nodes[1] = nodes[0]+1;
381 nodes[2] = nodes[1]+(totalXElems+1);
382 nodes[3] = nodes[2]-1;
383 nodes[4] = nodes[0]+(totalYElems+1)*(totalXElems+1);
384 nodes[5] = nodes[1]+(totalYElems+1)*(totalXElems+1);
385 nodes[6] = nodes[2]+(totalYElems+1)*(totalXElems+1);
386 nodes[7] = nodes[3]+(totalYElems+1)*(totalXElems+1);
398 panzer::Ordinal64 minElements =
nXElems_/size;
399 panzer::Ordinal64 extra =
nXElems_ - minElements*size;
405 panzer::Ordinal64 nume=0, start=0;
406 if(panzer::Ordinal64(xProcLoc)<extra) {
407 nume = minElements+1;
408 start = xProcLoc*(minElements+1);
412 start = extra*(minElements+1)+(xProcLoc-extra)*minElements;
415 return std::make_pair(start+
nXElems_*xBlock,nume);
424 panzer::Ordinal64 minElements =
nYElems_/size;
425 panzer::Ordinal64 extra =
nYElems_ - minElements*size;
431 panzer::Ordinal64 nume=0, start=0;
432 if(panzer::Ordinal64(yProcLoc)<extra) {
433 nume = minElements+1;
434 start = yProcLoc*(minElements+1);
438 start = extra*(minElements+1)+(yProcLoc-extra)*minElements;
441 return std::make_pair(start+
nYElems_*yBlock,nume);
449 panzer::Ordinal64 minElements =
nZElems_/size;
450 panzer::Ordinal64 extra =
nZElems_ - minElements*size;
456 panzer::Ordinal64 nume=0, start=0;
457 if(zProcLoc<Teuchos::as<std::size_t>(extra)) {
458 nume = minElements+1;
459 start = zProcLoc*(minElements+1);
463 start = extra*(minElements+1)+(zProcLoc-extra)*minElements;
466 return std::make_pair(start+
nZElems_*zBlock,nume);
478 std::vector<stk::mesh::Entity> localElmts;
481 stk::mesh::EntityId offset[6];
483 offset[1] = offset[0] + totalXElems*totalZElems;
484 offset[2] = offset[1] + totalYElems*totalZElems;
485 offset[3] = offset[2] + totalXElems*totalZElems;
486 offset[4] = offset[3] + totalYElems*totalZElems;
487 offset[5] = offset[4] + totalXElems*totalYElems;
492 std::vector<stk::mesh::Entity>::const_iterator itr;
493 for(itr=localElmts.begin();itr!=localElmts.end();++itr) {
494 stk::mesh::Entity element = (*itr);
497 std::size_t nx,ny,nz;
498 nz = (gid-1) / (totalXElems*totalYElems);
499 gid = (gid-1)-nz*(totalXElems*totalYElems);
500 ny = gid / totalXElems;
501 nx = gid-ny*totalXElems;
503 std::vector<stk::mesh::Part*> parts;
507 mesh.
getBulkData()->declare_element_side(element, 4, parts);
509 if(nz+1==totalZElems) {
511 mesh.
getBulkData()->declare_element_side(element, 5, parts);
516 mesh.
getBulkData()->declare_element_side(element, 0, parts);
518 if(ny+1==totalYElems) {
520 mesh.
getBulkData()->declare_element_side(element, 2, parts);
525 mesh.
getBulkData()->declare_element_side(element, 3, parts);
527 if(nx+1==totalXElems) {
529 mesh.
getBulkData()->declare_element_side(element, 1, parts);
539 const stk::mesh::EntityRank side_rank = mesh.
getSideRank();
546 stk::mesh::Part * left = mesh.
getSideset(
"left");
547 stk::mesh::Part * right = mesh.
getSideset(
"right");
548 stk::mesh::Part * top = mesh.
getSideset(
"top");
549 stk::mesh::Part * bottom = mesh.
getSideset(
"bottom");
550 stk::mesh::Part * front = mesh.
getSideset(
"front");
551 stk::mesh::Part * back = mesh.
getSideset(
"back");
553 std::vector<stk::mesh::Part*> vertical;
554 std::vector<stk::mesh::Part*> horizontal;
555 std::vector<stk::mesh::Part*> transverse;
559 std::stringstream ss;
560 ss <<
"vertical_" << bx-1;
561 vertical.push_back(mesh.
getSideset(ss.str()));
564 std::stringstream ss;
565 ss <<
"horizontal_" << by-1;
566 horizontal.push_back(mesh.
getSideset(ss.str()));
569 std::stringstream ss;
570 ss <<
"transverse_" << bz-1;
571 transverse.push_back(mesh.
getSideset(ss.str()));
575 std::vector<stk::mesh::Entity> localElmts;
581 std::vector<stk::mesh::Entity>::const_iterator itr;
582 for(itr=localElmts.begin();itr!=localElmts.end();++itr) {
583 stk::mesh::Entity element = (*itr);
586 std::size_t nx,ny,nz;
587 nz = (gid-1) / (totalXElems*totalYElems);
588 gid = (gid-1)-nz*(totalXElems*totalYElems);
589 ny = gid / totalXElems;
590 nx = gid-ny*totalXElems;
612 if(nz+1==totalZElems) {
643 if(ny+1==totalYElems) {
674 if(nx+1==totalXElems) {
694 stk::mesh::Part * origin = mesh.
getNodeset(
"origin");
700 stk::mesh::Entity node = bulkData->get_entity(mesh.
getNodeRank(),1);
710 std::size_t i=0,j=0,k=0;
716 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 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 count
void buildElements(stk::ParallelMachine parallelMach, STK_Interface &mesh) const
ParameterList & set(std::string const &name, T const &value, std::string const &docString="", RCP< const ParameterEntryValidator > const &validator=null)
panzer::Ordinal64 nZElems_
#define TEUCHOS_TEST_FOR_EXCEPTION(throw_exception_test, Exception, msg)
void addEntityToSideset(stk::mesh::Entity entity, stk::mesh::Part *sideset)
void addSideSets(STK_Interface &mesh) const
stk::mesh::Part * getNodeset(const std::string &name) const
void initialize(stk::ParallelMachine parallelMach, bool setupIO=true)
panzer::Ordinal64 nXElems_
panzer::Ordinal64 nYElems_
stk::mesh::Part * getSideset(const std::string &name) const
std::pair< panzer::Ordinal64, panzer::Ordinal64 > determineXElemSizeAndStart(int xBlock, unsigned int size, unsigned int rank) 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
std::pair< panzer::Ordinal64, panzer::Ordinal64 > determineYElemSizeAndStart(int yBlock, unsigned int size, unsigned int rank) const
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)
basic_FancyOStream & setOutputToRootOnly(const int rootRank)
void setParameterList(const Teuchos::RCP< Teuchos::ParameterList > ¶mList)
From ParameterListAcceptor.
void addNode(stk::mesh::EntityId gid, const std::vector< double > &coord)
void buildSubcells()
force the mesh to build subcells: edges and faces
Teuchos::Tuple< std::size_t, 3 > procTuple_
std::pair< panzer::Ordinal64, panzer::Ordinal64 > determineZElemSizeAndStart(int zBlock, unsigned int size, unsigned int rank) const
Teuchos::RCP< STK_Interface > buildMesh(stk::ParallelMachine parallelMach) const
Build the mesh object.
Teuchos::RCP< const Teuchos::ParameterList > getValidParameters() const
From ParameterListAcceptor.
CubeHexMeshFactory()
Constructor.
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)
std::vector< Teuchos::RCP< const PeriodicBC_MatcherBase > > periodicBCVec_
bool buildInterfaceSidesets_
void buildLocalElementIDs()
ParameterList & sublist(const std::string &name, bool mustAlreadyExist=false, const std::string &docString="")
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
void addElementBlock(const std::string &name, const CellTopologyData *ctData)
static void parsePeriodicBCList(const Teuchos::RCP< Teuchos::ParameterList > &pl, std::vector< Teuchos::RCP< const PeriodicBC_MatcherBase > > &periodicBC)
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