45 #include <PanzerAdaptersSTK_config.hpp> 65 PANZER_FUNC_TIME_MONITOR(
"panzer::CubeTetMeshFactory::buildMesh()");
71 mesh->initialize(parallelMach);
81 PANZER_FUNC_TIME_MONITOR(
"panzer::CubeTetMeshFactory::buildUncomittedMesh()");
85 machRank_ = stk::parallel_machine_rank(parallelMach);
86 machSize_ = stk::parallel_machine_size(parallelMach);
95 "Cannot build CubeTetMeshFactory, the product of \"X Procs\", \"Y Procs\", and \"Z Procs\"" 96 " must equal the number of processors.");
109 PANZER_FUNC_TIME_MONITOR(
"panzer::CubeTetMeshFactory::completeMeshConstruction()");
135 x0_ = paramList->
get<
double>(
"X0");
136 y0_ = paramList->
get<
double>(
"Y0");
137 z0_ = paramList->
get<
double>(
"Z0");
139 xf_ = paramList->
get<
double>(
"Xf");
140 yf_ = paramList->
get<
double>(
"Yf");
141 zf_ = paramList->
get<
double>(
"Zf");
165 if(defaultParams == Teuchos::null) {
168 defaultParams->
set<
double>(
"X0",0.0);
169 defaultParams->
set<
double>(
"Y0",0.0);
170 defaultParams->
set<
double>(
"Z0",0.0);
172 defaultParams->
set<
double>(
"Xf",1.0);
173 defaultParams->
set<
double>(
"Yf",1.0);
174 defaultParams->
set<
double>(
"Zf",1.0);
176 defaultParams->
set<
int>(
"X Blocks",1);
177 defaultParams->
set<
int>(
"Y Blocks",1);
178 defaultParams->
set<
int>(
"Z Blocks",1);
180 defaultParams->
set<
int>(
"X Procs",-1);
181 defaultParams->
set<
int>(
"Y Procs",1);
182 defaultParams->
set<
int>(
"Z Procs",1);
184 defaultParams->
set<
int>(
"X Elements",5);
185 defaultParams->
set<
int>(
"Y Elements",5);
186 defaultParams->
set<
int>(
"Z Elements",5);
189 bcs.
set<
int>(
"Count",0);
192 return defaultParams;
206 typedef shards::Tetrahedron<4> TetTopo;
207 const CellTopologyData * ctd = shards::getCellTopologyData<TetTopo>();
208 const CellTopologyData * side_ctd = shards::CellTopology(ctd).getBaseCellTopologyData(2,0);
216 std::stringstream ebPostfix;
217 ebPostfix <<
"-" << bx <<
"_" << by <<
"_" << bz;
238 for(
int xBlock=0;xBlock<
xBlocks_;xBlock++) {
239 for(
int yBlock=0;yBlock<
yBlocks_;yBlock++) {
240 for(
int zBlock=0;zBlock<
zBlocks_;zBlock++) {
241 buildBlock(parallelMach,xBlock,yBlock,zBlock,mesh);
255 int myXElems_start = sizeAndStartX.first;
256 int myXElems_end = myXElems_start+sizeAndStartX.second;
257 int myYElems_start = sizeAndStartY.first;
258 int myYElems_end = myYElems_start+sizeAndStartY.second;
259 int myZElems_start = sizeAndStartZ.first;
260 int myZElems_end = myZElems_start+sizeAndStartZ.second;
266 double deltaX = (
xf_-
x0_)/
double(totalXElems);
267 double deltaY = (
yf_-
y0_)/
double(totalYElems);
268 double deltaZ = (
zf_-
z0_)/
double(totalZElems);
270 std::vector<double> coord(3,0.0);
273 for(
int nx=myXElems_start;nx<myXElems_end+1;++nx) {
274 coord[0] = double(nx)*deltaX+
x0_;
275 for(
int ny=myYElems_start;ny<myYElems_end+1;++ny) {
276 coord[1] = double(ny)*deltaY+
y0_;
277 for(
int nz=myZElems_start;nz<myZElems_end+1;++nz) {
278 coord[2] = double(nz)*deltaZ+
z0_;
280 mesh.
addNode(nz*(totalYElems+1)*(totalXElems+1)+ny*(totalXElems+1)+nx+1,coord);
285 std::stringstream blockName;
286 blockName <<
"eblock-" << xBlock <<
"_" << yBlock <<
"_" << zBlock;
290 for(
int nx=myXElems_start;nx<myXElems_end;++nx) {
291 for(
int ny=myYElems_start;ny<myYElems_end;++ny) {
292 for(
int nz=myZElems_start;nz<myZElems_end;++nz) {
294 std::vector<stk::mesh::EntityId> nodes(8);
295 nodes[0] = nx+1+ny*(totalXElems+1) +nz*(totalYElems+1)*(totalXElems+1);
296 nodes[1] = nodes[0]+1;
297 nodes[2] = nodes[1]+(totalXElems+1);
298 nodes[3] = nodes[2]-1;
299 nodes[4] = nodes[0]+(totalYElems+1)*(totalXElems+1);
300 nodes[5] = nodes[1]+(totalYElems+1)*(totalXElems+1);
301 nodes[6] = nodes[2]+(totalYElems+1)*(totalXElems+1);
302 nodes[7] = nodes[3]+(totalYElems+1)*(totalXElems+1);
304 buildTetsOnHex(Teuchos::tuple(totalXElems,totalYElems,totalZElems),
305 Teuchos::tuple(nx,ny,nz),
314 stk::mesh::Part * block,
315 const std::vector<stk::mesh::EntityId> & h_nodes,
322 int totalXElems = meshDesc[0];
int totalYElems = meshDesc[1];
int totalZElems = meshDesc[2];
323 int nx = element[0];
int ny = element[1];
int nz = element[2];
325 stk::mesh::EntityId hex_id = totalXElems*totalYElems*nz+totalXElems*ny+nx+1;
326 stk::mesh::EntityId gid_0 = 12*(hex_id-1)+1;
327 std::vector<stk::mesh::EntityId> nodes(4);
330 stk::mesh::EntityId centroid = 0;
332 stk::mesh::EntityId largestNode = (totalXElems+1)*(totalYElems+1)*(totalZElems+1);
333 centroid = hex_id+largestNode;
336 std::vector<double> coord(3,0.0);
337 for(std::size_t i=0;i<h_nodes.size();i++) {
339 coord[0] += node_coord[0];
340 coord[1] += node_coord[1];
341 coord[2] += node_coord[2];
351 int idSet[][3] = { { 0, 1, 2},
364 for(
int i=0;i<12;i++) {
365 nodes[0] = h_nodes[idSet[i][0]];
366 nodes[1] = h_nodes[idSet[i][1]];
367 nodes[2] = h_nodes[idSet[i][2]];
378 unsigned int minElements =
nXElems_/size;
379 unsigned int extra =
nXElems_ - minElements*size;
387 nume = minElements+1;
388 start = xProcLoc*(minElements+1);
392 start = extra*(minElements+1)+(xProcLoc-extra)*minElements;
395 return std::make_pair(start+
nXElems_*xBlock,nume);
404 unsigned int minElements =
nYElems_/size;
405 unsigned int extra =
nYElems_ - minElements*size;
413 nume = minElements+1;
414 start = yProcLoc*(minElements+1);
418 start = extra*(minElements+1)+(yProcLoc-extra)*minElements;
421 return std::make_pair(start+
nYElems_*yBlock,nume);
429 unsigned int minElements =
nZElems_/size;
430 unsigned int extra =
nZElems_ - minElements*size;
438 nume = minElements+1;
439 start = zProcLoc*(minElements+1);
443 start = extra*(minElements+1)+(zProcLoc-extra)*minElements;
446 return std::make_pair(start+
nZElems_*zBlock,nume);
452 const stk::mesh::EntityRank side_rank = mesh.
getSideRank();
459 stk::mesh::Part * left = mesh.
getSideset(
"left");
460 stk::mesh::Part * right = mesh.
getSideset(
"right");
461 stk::mesh::Part * top = mesh.
getSideset(
"top");
462 stk::mesh::Part * bottom = mesh.
getSideset(
"bottom");
463 stk::mesh::Part * front = mesh.
getSideset(
"front");
464 stk::mesh::Part * back = mesh.
getSideset(
"back");
466 std::vector<stk::mesh::Entity> localElmts;
472 std::vector<stk::mesh::Entity>::const_iterator itr;
473 for(itr=localElmts.begin();itr!=localElmts.end();++itr) {
474 stk::mesh::Entity element = (*itr);
478 stk::mesh::EntityId h_gid = (gid-1)/12+1;
479 stk::mesh::EntityId t_offset = gid - (12*(h_gid-1)+1);
481 std::size_t nx,ny,nz;
482 nz = (h_gid-1) / (totalXElems*totalYElems);
483 h_gid = (h_gid-1)-nz*(totalXElems*totalYElems);
484 ny = h_gid / totalXElems;
485 nx = h_gid-ny*totalXElems;
487 if(nz==0 && (t_offset==0 || t_offset==1)) {
494 if(nz+1==totalZElems && (t_offset==10 || t_offset==11)) {
502 if(ny==0 && (t_offset==2 || t_offset==3)) {
509 if(ny+1==totalYElems && (t_offset==8 || t_offset==9)) {
517 if(nx==0 && (t_offset==4 || t_offset==5)) {
524 if(nx+1==totalXElems && (t_offset==6 || t_offset==7)) {
539 std::size_t i=0,j=0,k=0;
545 return Teuchos::tuple(i,j,k);
stk::mesh::Part * getElementBlockPart(const std::string &name) const
get the block count
void buildTetsOnHex(const Teuchos::Tuple< int, 3 > &meshDesc, const Teuchos::Tuple< int, 3 > &element, stk::mesh::Part *block, const std::vector< stk::mesh::EntityId > &h_nodes, STK_Interface &mesh) const
basic_FancyOStream & setShowProcRank(const bool showProcRank)
T & get(const std::string &name, T def_value)
ParameterList & set(std::string const &name, T const &value, std::string const &docString="", RCP< const ParameterEntryValidator > const &validator=null)
#define TEUCHOS_TEST_FOR_EXCEPTION(throw_exception_test, Exception, msg)
Teuchos::RCP< const Teuchos::ParameterList > getValidParameters() const
From ParameterListAcceptor.
void getMyElements(std::vector< stk::mesh::Entity > &elements) const
void addEntityToSideset(stk::mesh::Entity entity, stk::mesh::Part *sideset)
Teuchos::RCP< STK_Interface > buildMesh(stk::ParallelMachine parallelMach) const
Build the mesh object.
void addSideSets(STK_Interface &mesh) const
stk::mesh::EntityRank getSideRank() const
void initialize(stk::ParallelMachine parallelMach, bool setupIO=true)
stk::mesh::Entity findConnectivityById(stk::mesh::Entity src, stk::mesh::EntityRank tgt_rank, unsigned rel_id) const
const double * getNodeCoordinates(stk::mesh::EntityId nodeId) const
std::pair< int, int > determineYElemSizeAndStart(int yBlock, unsigned int size, unsigned int rank) const
void buildElements(stk::ParallelMachine parallelMach, STK_Interface &mesh) const
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::EntityId elementGlobalId(std::size_t lid) const
std::pair< int, int > determineZElemSizeAndStart(int zBlock, unsigned int size, unsigned int rank) const
void setMyParamList(const RCP< ParameterList > ¶mList)
bool isInitialized() const
Has initialize been called on this mesh object?
virtual void completeMeshConstruction(STK_Interface &mesh, stk::ParallelMachine parallelMach) const
void validateParametersAndSetDefaults(ParameterList const &validParamList, int const depth=1000)
virtual ~CubeTetMeshFactory()
Destructor.
basic_FancyOStream & setOutputToRootOnly(const int rootRank)
void setParameterList(const Teuchos::RCP< Teuchos::ParameterList > ¶mList)
From ParameterListAcceptor.
virtual Teuchos::RCP< STK_Interface > buildUncommitedMesh(stk::ParallelMachine parallelMach) const
void addNode(stk::mesh::EntityId gid, const std::vector< double > &coord)
void buildSubcells()
force the mesh to build subcells: edges and faces
void initializeWithDefaults()
void addSideset(const std::string &name, const CellTopologyData *ctData)
std::vector< Teuchos::RCP< const PeriodicBC_MatcherBase > > periodicBCVec_
std::pair< int, int > determineXElemSizeAndStart(int xBlock, unsigned int size, unsigned int rank) const
Teuchos::Tuple< std::size_t, 3 > procRankToProcTuple(std::size_t procRank) const
what is the 3D tuple describe this processor distribution
void buildLocalElementIDs()
void buildBlock(stk::ParallelMachine machRank, int xBlock, int yBlock, int zBlock, STK_Interface &mesh) const
ParameterList & sublist(const std::string &name, bool mustAlreadyExist=false, const std::string &docString="")
unsigned entityOwnerRank(stk::mesh::Entity entity) const
void rebalance(STK_Interface &mesh) const
#define TEUCHOS_ASSERT(assertion_test)
void buildMetaData(stk::ParallelMachine parallelMach, STK_Interface &mesh) const
CubeTetMeshFactory()
Constructor.
Teuchos::Tuple< std::size_t, 3 > procTuple_
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)