Panzer  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Panzer_STK_CubeHexMeshFactory.cpp
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 
12 #include <Teuchos_TimeMonitor.hpp>
13 #include <PanzerAdaptersSTK_config.hpp>
14 #include <stk_mesh/base/FEMHelpers.hpp>
15 
16 using Teuchos::RCP;
17 using Teuchos::rcp;
18 
19 namespace panzer_stk {
20 
22 {
24 }
25 
28 {
29 }
30 
32 Teuchos::RCP<STK_Interface> CubeHexMeshFactory::buildMesh(stk::ParallelMachine parallelMach) const
33 {
34  PANZER_FUNC_TIME_MONITOR("panzer::CubeHexMeshFactory::buildMesh()");
35 
36  // build all meta data
37  RCP<STK_Interface> mesh = buildUncommitedMesh(parallelMach);
38 
39  // commit meta data
40  mesh->initialize(parallelMach);
41 
42  // build bulk data
43  completeMeshConstruction(*mesh,parallelMach);
44 
45  return mesh;
46 }
47 
49 {
50  PANZER_FUNC_TIME_MONITOR("panzer::CubeHexMeshFactory::buildUncomittedMesh()");
51 
52  RCP<STK_Interface> mesh = rcp(new STK_Interface(3));
53 
54  machRank_ = stk::parallel_machine_rank(parallelMach);
55  machSize_ = stk::parallel_machine_size(parallelMach);
56 
57  if (xProcs_ == -1 && yProcs_ == -1 && zProcs_ == -1) {
58  // copied from galeri
59  xProcs_ = yProcs_ = zProcs_ = Teuchos::as<int>(pow(Teuchos::as<double>(machSize_), 0.333334));
60 
61  if (xProcs_ * yProcs_ * zProcs_ != Teuchos::as<int>(machSize_)) {
62  // Simple method to find a set of processor assignments
63  xProcs_ = yProcs_ = zProcs_ = 1;
64 
65  // This means that this works correctly up to about maxFactor^3
66  // processors.
67  const int maxFactor = 50;
68 
69  int ProcTemp = machSize_;
70  int factors[maxFactor];
71  for (int jj = 0; jj < maxFactor; jj++) factors[jj] = 0;
72  for (int jj = 2; jj < maxFactor; jj++) {
73  bool flag = true;
74  while (flag) {
75  int temp = ProcTemp/jj;
76  if (temp*jj == ProcTemp) {
77  factors[jj]++;
78  ProcTemp = temp;
79 
80  } else {
81  flag = false;
82  }
83  }
84  }
85  xProcs_ = ProcTemp;
86  for (int jj = maxFactor-1; jj > 0; jj--) {
87  while (factors[jj] != 0) {
88  if ((xProcs_ <= yProcs_) && (xProcs_ <= zProcs_)) xProcs_ = xProcs_*jj;
89  else if ((yProcs_ <= xProcs_) && (yProcs_ <= zProcs_)) yProcs_ = yProcs_*jj;
90  else zProcs_ = zProcs_*jj;
91  factors[jj]--;
92  }
93  }
94  }
95 
96  } else if(xProcs_==-1) {
97  // default x only decomposition
99  yProcs_ = 1;
100  zProcs_ = 1;
101  }
103  "Cannot build CubeHexMeshFactory, the product of \"X Procs\", \"Y Procs\", and \"Z Procs\""
104  " must equal the number of processors.");
106 
107  // build meta information: blocks and side set setups
108  buildMetaData(parallelMach,*mesh);
109 
110  mesh->addPeriodicBCs(periodicBCVec_);
111  mesh->setBoundingBoxSearchFlag(useBBoxSearch_);
112 
113  return mesh;
114 }
115 
116 void CubeHexMeshFactory::completeMeshConstruction(STK_Interface & mesh,stk::ParallelMachine parallelMach) const
117 {
118  PANZER_FUNC_TIME_MONITOR("panzer::CubeHexMeshFactory::completeMeshConstruction()");
119 
120  if(not mesh.isInitialized())
121  mesh.initialize(parallelMach);
122 
123  // add node and element information
124  buildElements(parallelMach,mesh);
125 
126  Teuchos::FancyOStream out(Teuchos::rcpFromRef(std::cout));
127  out.setOutputToRootOnly(0);
128  out.setShowProcRank(true);
129 
130  // finish up the edges and faces
131  if(buildSubcells_) {
132  mesh.buildSubcells();
133 
134  out << "CubeHexMesh: Building sub cells" << std::endl;
135  }
136  else {
137  addSides(mesh);
138 
139  out << "CubeHexMesh: NOT building sub cells" << std::endl;
140  }
141 
142  mesh.buildLocalElementIDs();
143  if(createEdgeBlocks_) {
144  mesh.buildLocalEdgeIDs();
145  }
146  if(createFaceBlocks_) {
147  mesh.buildLocalFaceIDs();
148  }
149 
150  mesh.beginModification();
151 
152  // now that edges are built, side and node sets can be added
153  addSideSets(mesh);
154  addNodeSets(mesh);
155  if(createEdgeBlocks_) {
156  addEdgeBlocks(mesh);
157  }
158  if(createFaceBlocks_) {
159  addFaceBlocks(mesh);
160  }
161 
162  mesh.endModification();
163 
164  // calls Stk_MeshFactory::rebalance
165  this->rebalance(mesh);
166 }
167 
170 {
172 
173  setMyParamList(paramList);
174 
175  x0_ = paramList->get<double>("X0");
176  y0_ = paramList->get<double>("Y0");
177  z0_ = paramList->get<double>("Z0");
178 
179  xf_ = paramList->get<double>("Xf");
180  yf_ = paramList->get<double>("Yf");
181  zf_ = paramList->get<double>("Zf");
182 
183  xBlocks_ = paramList->get<int>("X Blocks");
184  yBlocks_ = paramList->get<int>("Y Blocks");
185  zBlocks_ = paramList->get<int>("Z Blocks");
186 
187  xProcs_ = paramList->get<int>("X Procs");
188  yProcs_ = paramList->get<int>("Y Procs");
189  zProcs_ = paramList->get<int>("Z Procs");
190 
191  nXElems_ = paramList->get<int>("X Elements");
192  nYElems_ = paramList->get<int>("Y Elements");
193  nZElems_ = paramList->get<int>("Z Elements");
194 
195  buildInterfaceSidesets_ = paramList->get<bool>("Build Interface Sidesets");
196 
197  buildSubcells_ = paramList->get<bool>("Build Subcells");
198 
199  createEdgeBlocks_ = paramList->get<bool>("Create Edge Blocks");
200  createFaceBlocks_ = paramList->get<bool>("Create Face Blocks");
201  if (not buildSubcells_ && createEdgeBlocks_) {
202  Teuchos::FancyOStream out(Teuchos::rcpFromRef(std::cout));
203  out.setOutputToRootOnly(0);
204  out.setShowProcRank(true);
205 
206  out << "CubeHexMesh: NOT creating edge blocks because building sub cells disabled" << std::endl;
207  createEdgeBlocks_ = false;
208  }
209  if (not buildSubcells_ && createFaceBlocks_) {
210  Teuchos::FancyOStream out(Teuchos::rcpFromRef(std::cout));
211  out.setOutputToRootOnly(0);
212  out.setShowProcRank(true);
213 
214  out << "CubeHexMesh: NOT creating face blocks because building sub cells disabled" << std::endl;
215  createFaceBlocks_ = false;
216  }
217 
218  // read in periodic boundary conditions
219  parsePeriodicBCList(Teuchos::rcpFromRef(paramList->sublist("Periodic BCs")),periodicBCVec_,useBBoxSearch_);
220 }
221 
224 {
225  static RCP<Teuchos::ParameterList> defaultParams;
226 
227  // fill with default values
228  if(defaultParams == Teuchos::null) {
229  defaultParams = rcp(new Teuchos::ParameterList);
230 
231  defaultParams->set<double>("X0",0.0);
232  defaultParams->set<double>("Y0",0.0);
233  defaultParams->set<double>("Z0",0.0);
234 
235  defaultParams->set<double>("Xf",1.0);
236  defaultParams->set<double>("Yf",1.0);
237  defaultParams->set<double>("Zf",1.0);
238 
239  defaultParams->set<int>("X Blocks",1);
240  defaultParams->set<int>("Y Blocks",1);
241  defaultParams->set<int>("Z Blocks",1);
242 
243  defaultParams->set<int>("X Procs",-1);
244  defaultParams->set<int>("Y Procs",1);
245  defaultParams->set<int>("Z Procs",1);
246 
247  defaultParams->set<int>("X Elements",5);
248  defaultParams->set<int>("Y Elements",5);
249  defaultParams->set<int>("Z Elements",5);
250 
251  defaultParams->set<bool>("Build Interface Sidesets",false);
252 
253  defaultParams->set<bool>("Build Subcells",true);
254 
255  // default to false for backward compatibility
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");
258 
259  Teuchos::ParameterList & bcs = defaultParams->sublist("Periodic BCs");
260  bcs.set<int>("Count",0); // no default periodic boundary conditions
261  }
262 
263  return defaultParams;
264 }
265 
267 {
268  // get valid parameters
270 
271  // set that parameter list
272  setParameterList(validParams);
273 
274  /* This is a hex mesh factory so all elements in all element blocks
275  * will be hex8. This means that all the edges will be line2 and
276  * all the faces will be quad4. The edge and face block names are
277  * hard coded to reflect this.
278  */
281 }
282 
283 void CubeHexMeshFactory::buildMetaData(stk::ParallelMachine /* parallelMach */, STK_Interface & mesh) const
284 {
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);
290 
291  // build meta data
292  //mesh.setDimension(2);
293  for(int bx=0;bx<xBlocks_;bx++) {
294  for(int by=0;by<yBlocks_;by++) {
295  for(int bz=0;bz<zBlocks_;bz++) {
296 
297  std::stringstream ebPostfix;
298  ebPostfix << "-" << bx << "_" << by << "_" << bz;
299 
300  // add element blocks
301  mesh.addElementBlock("eblock"+ebPostfix.str(),ctd);
302 
303  if(createEdgeBlocks_) {
304  mesh.addEdgeBlock("eblock"+ebPostfix.str(),
306  edge_ctd);
307  }
308  if(createFaceBlocks_) {
309  mesh.addFaceBlock("eblock"+ebPostfix.str(),
311  face_ctd);
312  }
313  }
314  }
315  }
316 
317  // add sidesets
318  mesh.addSideset("left",side_ctd);
319  mesh.addSideset("right",side_ctd);
320  mesh.addSideset("top",side_ctd);
321  mesh.addSideset("bottom",side_ctd);
322  mesh.addSideset("front",side_ctd);
323  mesh.addSideset("back",side_ctd);
324 
326  for(int bx=1;bx<xBlocks_;bx++) {
327  std::stringstream ss;
328  ss << "vertical_" << bx-1;
329  mesh.addSideset(ss.str(),side_ctd);
330  }
331  for(int by=1;by<yBlocks_;by++) {
332  std::stringstream ss;
333  ss << "horizontal_" << by-1;
334  mesh.addSideset(ss.str(),side_ctd);
335  }
336  for(int bz=1;bz<zBlocks_;bz++) {
337  std::stringstream ss;
338  ss << "transverse_" << bz-1;
339  mesh.addSideset(ss.str(),side_ctd);
340  }
341  }
342 
343  // add nodesets
344  mesh.addNodeset("origin");
345 }
346 
347 void CubeHexMeshFactory::buildElements(stk::ParallelMachine parallelMach,STK_Interface & mesh) const
348 {
349  mesh.beginModification();
350  // build each block
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);
355  }
356  }
357  }
358  mesh.endModification();
359 }
360 
361 void CubeHexMeshFactory::buildBlock(stk::ParallelMachine /* parallelMach */,int xBlock,int yBlock,int zBlock,STK_Interface & mesh) const
362 {
363  // grab this processors rank and machine size
364  std::pair<panzer::GlobalOrdinal,panzer::GlobalOrdinal> sizeAndStartX = determineXElemSizeAndStart(xBlock,xProcs_,machRank_);
365  std::pair<panzer::GlobalOrdinal,panzer::GlobalOrdinal> sizeAndStartY = determineYElemSizeAndStart(yBlock,yProcs_,machRank_);
366  std::pair<panzer::GlobalOrdinal,panzer::GlobalOrdinal> sizeAndStartZ = determineZElemSizeAndStart(zBlock,zProcs_,machRank_);
367 
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;
374 
375  panzer::GlobalOrdinal totalXElems = nXElems_*xBlocks_;
376  panzer::GlobalOrdinal totalYElems = nYElems_*yBlocks_;
377  panzer::GlobalOrdinal totalZElems = nZElems_*zBlocks_;
378 
379  double deltaX = (xf_-x0_)/double(totalXElems);
380  double deltaY = (yf_-y0_)/double(totalYElems);
381  double deltaZ = (zf_-z0_)/double(totalZElems);
382 
383  std::vector<double> coord(3,0.0);
384 
385  // build the nodes
386  for(panzer::GlobalOrdinal nx=myXElems_start;nx<myXElems_end+1;++nx) {
387  coord[0] = this->getMeshCoord(nx, deltaX, x0_);
388  for(panzer::GlobalOrdinal ny=myYElems_start;ny<myYElems_end+1;++ny) {
389  coord[1] = this->getMeshCoord(ny, deltaY, y0_);
390  for(panzer::GlobalOrdinal nz=myZElems_start;nz<myZElems_end+1;++nz) {
391  coord[2] = this->getMeshCoord(nz, deltaZ, z0_);
392 
393  mesh.addNode(nz*(totalYElems+1)*(totalXElems+1)+ny*(totalXElems+1)+nx+1,coord);
394  }
395  }
396  }
397 
398  std::stringstream blockName;
399  blockName << "eblock-" << xBlock << "_" << yBlock << "_" << zBlock;
400  stk::mesh::Part * block = mesh.getElementBlockPart(blockName.str());
401 
402  // build the elements
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);
416 
417  RCP<ElementDescriptor> ed = rcp(new ElementDescriptor(gid,nodes));
418  mesh.addElement(ed,block);
419  }
420  }
421  }
422 }
423 
424 std::pair<panzer::GlobalOrdinal,panzer::GlobalOrdinal> CubeHexMeshFactory::determineXElemSizeAndStart(int xBlock,unsigned int size,unsigned int /* rank */) const
425 {
426  std::size_t xProcLoc = procTuple_[0];
427  panzer::GlobalOrdinal minElements = nXElems_/size;
428  panzer::GlobalOrdinal extra = nXElems_ - minElements*size;
429 
430  TEUCHOS_ASSERT(minElements>0);
431 
432  // first "extra" elements get an extra column of elements
433  // this determines the starting X index and number of elements
434  panzer::GlobalOrdinal nume=0, start=0;
435  if(panzer::GlobalOrdinal(xProcLoc)<extra) {
436  nume = minElements+1;
437  start = xProcLoc*(minElements+1);
438  }
439  else {
440  nume = minElements;
441  start = extra*(minElements+1)+(xProcLoc-extra)*minElements;
442  }
443 
444  return std::make_pair(start+nXElems_*xBlock,nume);
445 }
446 
447 std::pair<panzer::GlobalOrdinal,panzer::GlobalOrdinal> CubeHexMeshFactory::determineYElemSizeAndStart(int yBlock,unsigned int size,unsigned int /* rank */) const
448 {
449  // int start = yBlock*nYElems_;
450  // return std::make_pair(start,nYElems_);
451 
452  std::size_t yProcLoc = procTuple_[1];
453  panzer::GlobalOrdinal minElements = nYElems_/size;
454  panzer::GlobalOrdinal extra = nYElems_ - minElements*size;
455 
456  TEUCHOS_ASSERT(minElements>0);
457 
458  // first "extra" elements get an extra column of elements
459  // this determines the starting X index and number of elements
460  panzer::GlobalOrdinal nume=0, start=0;
461  if(panzer::GlobalOrdinal(yProcLoc)<extra) {
462  nume = minElements+1;
463  start = yProcLoc*(minElements+1);
464  }
465  else {
466  nume = minElements;
467  start = extra*(minElements+1)+(yProcLoc-extra)*minElements;
468  }
469 
470  return std::make_pair(start+nYElems_*yBlock,nume);
471 }
472 
473 std::pair<panzer::GlobalOrdinal,panzer::GlobalOrdinal> CubeHexMeshFactory::determineZElemSizeAndStart(int zBlock,unsigned int size,unsigned int /* rank */) const
474 {
475  // int start = zBlock*nZElems_;
476  // return std::make_pair(start,nZElems_);
477  std::size_t zProcLoc = procTuple_[2];
478  panzer::GlobalOrdinal minElements = nZElems_/size;
479  panzer::GlobalOrdinal extra = nZElems_ - minElements*size;
480 
481  TEUCHOS_ASSERT(minElements>0);
482 
483  // first "extra" elements get an extra column of elements
484  // this determines the starting X index and number of elements
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);
489  }
490  else {
491  nume = minElements;
492  start = extra*(minElements+1)+(zProcLoc-extra)*minElements;
493  }
494 
495  return std::make_pair(start+nZElems_*zBlock,nume);
496 }
497 
498 // this adds side entities only (does not inject them into side sets)
500 {
501  mesh.beginModification();
502 
503  std::size_t totalXElems = nXElems_*xBlocks_;
504  std::size_t totalYElems = nYElems_*yBlocks_;
505  std::size_t totalZElems = nZElems_*zBlocks_;
506 
507  std::vector<stk::mesh::Entity> localElmts;
508  mesh.getMyElements(localElmts);
509 
510  stk::mesh::EntityId offset[6];
511  offset[0] = 0;
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;
517 
518  // gid = totalXElems*totalYElems*nz+totalXElems*ny+nx+1
519 
520  // loop over elements adding sides to sidesets
521  std::vector<stk::mesh::Entity>::const_iterator itr;
522  for(itr=localElmts.begin();itr!=localElmts.end();++itr) {
523  stk::mesh::Entity element = (*itr);
524  stk::mesh::EntityId gid = mesh.elementGlobalId(element);
525 
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;
531 
532  std::vector<stk::mesh::Part*> parts;
533 
534  if(nz==0) {
535  // on the back
536  mesh.getBulkData()->declare_element_side(element, 4, parts);
537  }
538  if(nz+1==totalZElems) {
539  // on the front
540  mesh.getBulkData()->declare_element_side(element, 5, parts);
541  }
542 
543  if(ny==0) {
544  // on the bottom
545  mesh.getBulkData()->declare_element_side(element, 0, parts);
546  }
547  if(ny+1==totalYElems) {
548  // on the top
549  mesh.getBulkData()->declare_element_side(element, 2, parts);
550  }
551 
552  if(nx==0) {
553  // on the left
554  mesh.getBulkData()->declare_element_side(element, 3, parts);
555  }
556  if(nx+1==totalXElems) {
557  // on the right
558  mesh.getBulkData()->declare_element_side(element, 1, parts);
559  }
560  }
561 
562  mesh.endModification();
563 }
564 
565 // Pre-Condition: call beginModification() before entry
566 // Post-Condition: call endModification() after exit
568 {
569  const stk::mesh::EntityRank side_rank = mesh.getSideRank();
570 
571  std::size_t totalXElems = nXElems_*xBlocks_;
572  std::size_t totalYElems = nYElems_*yBlocks_;
573  std::size_t totalZElems = nZElems_*zBlocks_;
574 
575  // get all part vectors
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");
582 
583  std::vector<stk::mesh::Part*> vertical;
584  std::vector<stk::mesh::Part*> horizontal;
585  std::vector<stk::mesh::Part*> transverse;
586 
588  for(int bx=1;bx<xBlocks_;bx++) {
589  std::stringstream ss;
590  ss << "vertical_" << bx-1;
591  vertical.push_back(mesh.getSideset(ss.str()));
592  }
593  for(int by=1;by<yBlocks_;by++) {
594  std::stringstream ss;
595  ss << "horizontal_" << by-1;
596  horizontal.push_back(mesh.getSideset(ss.str()));
597  }
598  for(int bz=1;bz<zBlocks_;bz++) {
599  std::stringstream ss;
600  ss << "transverse_" << bz-1;
601  transverse.push_back(mesh.getSideset(ss.str()));
602  }
603  }
604 
605  std::vector<stk::mesh::Entity> localElmts;
606  mesh.getMyElements(localElmts);
607 
608  // gid = totalXElems*totalYElems*nz+totalXElems*ny+nx+1
609 
610  // loop over elements adding sides to sidesets
611  std::vector<stk::mesh::Entity>::const_iterator itr;
612  for(itr=localElmts.begin();itr!=localElmts.end();++itr) {
613  stk::mesh::Entity element = (*itr);
614  stk::mesh::EntityId gid = mesh.elementGlobalId(element);
615 
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;
621 
622  if(nz % nZElems_==0) {
623  stk::mesh::Entity side = mesh.findConnectivityById(element, side_rank, 4);
624 
625  // on the back
626  if(mesh.entityOwnerRank(side)==machRank_) {
627  if(nz==0) {
628  mesh.addEntityToSideset(side,back);
629  } else {
631  int index = nz/nZElems_-1;
632  mesh.addEntityToSideset(side,transverse[index]);
633  }
634  }
635  }
636  }
637  if((nz+1) % nZElems_==0) {
638  stk::mesh::Entity side = mesh.findConnectivityById(element, side_rank, 5);
639 
640  // on the front
641  if(mesh.entityOwnerRank(side)==machRank_) {
642  if(nz+1==totalZElems) {
643  mesh.addEntityToSideset(side,front);
644  } else {
646  int index = (nz+1)/nZElems_-1;
647  mesh.addEntityToSideset(side,transverse[index]);
648  }
649  }
650  }
651  }
652 
653  if(ny % nYElems_==0) {
654  stk::mesh::Entity side = mesh.findConnectivityById(element, side_rank, 0);
655 
656  // on the bottom
657  if(mesh.entityOwnerRank(side)==machRank_) {
658  if(ny==0) {
659  mesh.addEntityToSideset(side,bottom);
660  } else {
662  int index = ny/nYElems_-1;
663  mesh.addEntityToSideset(side,horizontal[index]);
664  }
665  }
666  }
667  }
668  if((ny+1) % nYElems_==0) {
669  stk::mesh::Entity side = mesh.findConnectivityById(element, side_rank, 2);
670 
671  // on the top
672  if(mesh.entityOwnerRank(side)==machRank_) {
673  if(ny+1==totalYElems) {
674  mesh.addEntityToSideset(side,top);
675  } else {
677  int index = (ny+1)/nYElems_-1;
678  mesh.addEntityToSideset(side,horizontal[index]);
679  }
680  }
681  }
682  }
683 
684  if(nx % nXElems_==0) {
685  stk::mesh::Entity side = mesh.findConnectivityById(element, side_rank, 3);
686 
687  // on the left
688  if(mesh.entityOwnerRank(side)==machRank_) {
689  if(nx==0) {
690  mesh.addEntityToSideset(side,left);
691  } else {
693  int index = nx/nXElems_-1;
694  mesh.addEntityToSideset(side,vertical[index]);
695  }
696  }
697  }
698  }
699  if((nx+1) % nXElems_==0) {
700  stk::mesh::Entity side = mesh.findConnectivityById(element, side_rank, 1);
701 
702  // on the right
703  if(mesh.entityOwnerRank(side)==machRank_) {
704  if(nx+1==totalXElems) {
705  mesh.addEntityToSideset(side,right);
706  } else {
708  int index = (nx+1)/nXElems_-1;
709  mesh.addEntityToSideset(side,vertical[index]);
710  }
711  }
712  }
713  }
714  }
715 }
716 
717 // Pre-Condition: call beginModification() before entry
718 // Post-Condition: call endModification() after exit
720 {
721  // get all part vectors
722  stk::mesh::Part * origin = mesh.getNodeset("origin");
723 
725  if(machRank_==0)
726  {
727  // add zero node to origin node set
728  stk::mesh::Entity node = bulkData->get_entity(mesh.getNodeRank(),1);
729  mesh.addEntityToNodeset(node,origin);
730  }
731 }
732 
733 // Pre-Condition: call beginModification() before entry
734 // Post-Condition: call endModification() after exit
736 {
739 
740  stk::mesh::Part * edge_block = mesh.getEdgeBlock(edgeBlockName_);
741 
742  stk::mesh::Selector owned_block = metaData->locally_owned_part();
743 
744  std::vector<stk::mesh::Entity> edges;
745  bulkData->get_entities(mesh.getEdgeRank(), owned_block, edges);
746  mesh.addEntitiesToEdgeBlock(edges, edge_block);
747 }
748 
749 // Pre-Condition: call beginModification() before entry
750 // Post-Condition: call endModification() after exit
752 {
755 
756  stk::mesh::Part * face_block = mesh.getFaceBlock(faceBlockName_);
757 
758  stk::mesh::Selector owned_block = metaData->locally_owned_part();
759 
760  std::vector<stk::mesh::Entity> faces;
761  bulkData->get_entities(mesh.getFaceRank(), owned_block, faces);
762  mesh.addEntitiesToFaceBlock(faces, face_block);
763 }
764 
767 {
768  std::size_t i=0,j=0,k=0;
769 
770  k = procRank/(xProcs_*yProcs_); procRank = procRank % (xProcs_*yProcs_);
771  j = procRank/xProcs_; procRank = procRank % xProcs_;
772  i = procRank;
773 
774  return Teuchos::tuple(i,j,k);
775 }
776 
777 } // end panzer_stk
void addSides(STK_Interface &mesh) const
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
#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 > &paramList)
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 > &paramList)
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.
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)
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
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)
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