Panzer  Version of the Day
Panzer_STK_CubeHexMeshFactory.cpp
Go to the documentation of this file.
1 // @HEADER
2 // ***********************************************************************
3 //
4 // Panzer: A partial differential equation assembly
5 // engine for strongly coupled complex multiphysics systems
6 // Copyright (2011) Sandia Corporation
7 //
8 // Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
9 // the U.S. Government retains certain rights in this software.
10 //
11 // Redistribution and use in source and binary forms, with or without
12 // modification, are permitted provided that the following conditions are
13 // met:
14 //
15 // 1. Redistributions of source code must retain the above copyright
16 // notice, this list of conditions and the following disclaimer.
17 //
18 // 2. Redistributions in binary form must reproduce the above copyright
19 // notice, this list of conditions and the following disclaimer in the
20 // documentation and/or other materials provided with the distribution.
21 //
22 // 3. Neither the name of the Corporation nor the names of the
23 // contributors may be used to endorse or promote products derived from
24 // this software without specific prior written permission.
25 //
26 // THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
27 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
28 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
30 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
31 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
32 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
33 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
34 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
35 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
36 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
37 //
38 // Questions? Contact Roger P. Pawlowski (rppawlo@sandia.gov) and
39 // Eric C. Cyr (eccyr@sandia.gov)
40 // ***********************************************************************
41 // @HEADER
42 
44 #include <Teuchos_TimeMonitor.hpp>
45 #include <PanzerAdaptersSTK_config.hpp>
46 
47 using Teuchos::RCP;
48 using Teuchos::rcp;
49 
50 namespace panzer_stk {
51 
53 {
55 }
56 
59 {
60 }
61 
63 Teuchos::RCP<STK_Interface> CubeHexMeshFactory::buildMesh(stk::ParallelMachine parallelMach) const
64 {
65  PANZER_FUNC_TIME_MONITOR("panzer::CubeHexMeshFactory::buildMesh()");
66 
67  // build all meta data
68  RCP<STK_Interface> mesh = buildUncommitedMesh(parallelMach);
69 
70  // commit meta data
71  mesh->initialize(parallelMach);
72 
73  // build bulk data
74  completeMeshConstruction(*mesh,parallelMach);
75 
76  return mesh;
77 }
78 
79 Teuchos::RCP<STK_Interface> CubeHexMeshFactory::buildUncommitedMesh(stk::ParallelMachine parallelMach) const
80 {
81  PANZER_FUNC_TIME_MONITOR("panzer::CubeHexMeshFactory::buildUncomittedMesh()");
82 
83  RCP<STK_Interface> mesh = rcp(new STK_Interface(3));
84 
85  machRank_ = stk::parallel_machine_rank(parallelMach);
86  machSize_ = stk::parallel_machine_size(parallelMach);
87 
88  if(xProcs_==-1) {
89  // default x only decomposition
90  xProcs_ = machSize_;
91  yProcs_ = 1;
92  zProcs_ = 1;
93  }
94  TEUCHOS_TEST_FOR_EXCEPTION(int(machSize_)!=xProcs_*yProcs_*zProcs_,std::logic_error,
95  "Cannot build CubeHexMeshFactory, the product of \"X Procs\", \"Y Procs\", and \"Z Procs\""
96  " must equal the number of processors.");
98 
99  // build meta information: blocks and side set setups
100  buildMetaData(parallelMach,*mesh);
101 
102  mesh->addPeriodicBCs(periodicBCVec_);
103 
104  return mesh;
105 }
106 
107 void CubeHexMeshFactory::completeMeshConstruction(STK_Interface & mesh,stk::ParallelMachine parallelMach) const
108 {
109  PANZER_FUNC_TIME_MONITOR("panzer::CubeHexMeshFactory::completeMeshConstruction()");
110 
111  if(not mesh.isInitialized())
112  mesh.initialize(parallelMach);
113 
114  // add node and element information
115  buildElements(parallelMach,mesh);
116 
117  Teuchos::FancyOStream out(Teuchos::rcpFromRef(std::cout));
118  out.setOutputToRootOnly(0);
119  out.setShowProcRank(true);
120 
121  // finish up the edges and faces
122  if(buildSubcells_) {
123  mesh.buildSubcells();
124 
125  out << "CubeHexMesh: Building sub cells" << std::endl;
126  }
127  else {
128  addSides(mesh);
129 
130  out << "CubeHexMesh: NOT building sub cells" << std::endl;
131  }
132 
133  mesh.buildLocalElementIDs();
134 
135  // now that edges are built, side and node sets can be added
136  addSideSets(mesh);
137  addNodeSets(mesh);
138 
139  // calls Stk_MeshFactory::rebalance
140  this->rebalance(mesh);
141 }
142 
144 void CubeHexMeshFactory::setParameterList(const Teuchos::RCP<Teuchos::ParameterList> & paramList)
145 {
146  paramList->validateParametersAndSetDefaults(*getValidParameters(),0);
147 
148  setMyParamList(paramList);
149 
150  x0_ = paramList->get<double>("X0");
151  y0_ = paramList->get<double>("Y0");
152  z0_ = paramList->get<double>("Z0");
153 
154  xf_ = paramList->get<double>("Xf");
155  yf_ = paramList->get<double>("Yf");
156  zf_ = paramList->get<double>("Zf");
157 
158  xBlocks_ = paramList->get<int>("X Blocks");
159  yBlocks_ = paramList->get<int>("Y Blocks");
160  zBlocks_ = paramList->get<int>("Z Blocks");
161 
162  xProcs_ = paramList->get<int>("X Procs");
163  yProcs_ = paramList->get<int>("Y Procs");
164  zProcs_ = paramList->get<int>("Z Procs");
165 
166  nXElems_ = paramList->get<int>("X Elements");
167  nYElems_ = paramList->get<int>("Y Elements");
168  nZElems_ = paramList->get<int>("Z Elements");
169 
170  buildInterfaceSidesets_ = paramList->get<bool>("Build Interface Sidesets");
171 
172  buildSubcells_ = paramList->get<bool>("Build Subcells");
173 
174  // read in periodic boundary conditions
175  parsePeriodicBCList(Teuchos::rcpFromRef(paramList->sublist("Periodic BCs")),periodicBCVec_);
176 }
177 
179 Teuchos::RCP<const Teuchos::ParameterList> CubeHexMeshFactory::getValidParameters() const
180 {
181  static RCP<Teuchos::ParameterList> defaultParams;
182 
183  // fill with default values
184  if(defaultParams == Teuchos::null) {
185  defaultParams = rcp(new Teuchos::ParameterList);
186 
187  defaultParams->set<double>("X0",0.0);
188  defaultParams->set<double>("Y0",0.0);
189  defaultParams->set<double>("Z0",0.0);
190 
191  defaultParams->set<double>("Xf",1.0);
192  defaultParams->set<double>("Yf",1.0);
193  defaultParams->set<double>("Zf",1.0);
194 
195  defaultParams->set<int>("X Blocks",1);
196  defaultParams->set<int>("Y Blocks",1);
197  defaultParams->set<int>("Z Blocks",1);
198 
199  defaultParams->set<int>("X Procs",-1);
200  defaultParams->set<int>("Y Procs",1);
201  defaultParams->set<int>("Z Procs",1);
202 
203  defaultParams->set<int>("X Elements",5);
204  defaultParams->set<int>("Y Elements",5);
205  defaultParams->set<int>("Z Elements",5);
206 
207  defaultParams->set<bool>("Build Interface Sidesets",false);
208 
209  defaultParams->set<bool>("Build Subcells",true);
210 
211  Teuchos::ParameterList & bcs = defaultParams->sublist("Periodic BCs");
212  bcs.set<int>("Count",0); // no default periodic boundary conditions
213  }
214 
215  return defaultParams;
216 }
217 
219 {
220  // get valid parameters
221  RCP<Teuchos::ParameterList> validParams = rcp(new Teuchos::ParameterList(*getValidParameters()));
222 
223  // set that parameter list
224  setParameterList(validParams);
225 }
226 
227 void CubeHexMeshFactory::buildMetaData(stk::ParallelMachine parallelMach, STK_Interface & mesh) const
228 {
229  typedef shards::Hexahedron<8> HexTopo;
230  const CellTopologyData * ctd = shards::getCellTopologyData<HexTopo>();
231  const CellTopologyData * side_ctd = shards::CellTopology(ctd).getBaseCellTopologyData(2,0);
232 
233  // build meta data
234  //mesh.setDimension(2);
235  for(int bx=0;bx<xBlocks_;bx++) {
236  for(int by=0;by<yBlocks_;by++) {
237  for(int bz=0;bz<zBlocks_;bz++) {
238 
239  std::stringstream ebPostfix;
240  ebPostfix << "-" << bx << "_" << by << "_" << bz;
241 
242  // add element blocks
243  mesh.addElementBlock("eblock"+ebPostfix.str(),ctd);
244  }
245  }
246  }
247 
248  // add sidesets
249  mesh.addSideset("left",side_ctd);
250  mesh.addSideset("right",side_ctd);
251  mesh.addSideset("top",side_ctd);
252  mesh.addSideset("bottom",side_ctd);
253  mesh.addSideset("front",side_ctd);
254  mesh.addSideset("back",side_ctd);
255 
257  for(int bx=1;bx<xBlocks_;bx++) {
258  std::stringstream ss;
259  ss << "vertical_" << bx-1;
260  mesh.addSideset(ss.str(),side_ctd);
261  }
262  for(int by=1;by<yBlocks_;by++) {
263  std::stringstream ss;
264  ss << "horizontal_" << by-1;
265  mesh.addSideset(ss.str(),side_ctd);
266  }
267  for(int bz=1;bz<zBlocks_;bz++) {
268  std::stringstream ss;
269  ss << "transverse_" << bz-1;
270  mesh.addSideset(ss.str(),side_ctd);
271  }
272  }
273 
274  // add nodesets
275  mesh.addNodeset("origin");
276 }
277 
278 void CubeHexMeshFactory::buildElements(stk::ParallelMachine parallelMach,STK_Interface & mesh) const
279 {
280  mesh.beginModification();
281  // build each block
282  for(int xBlock=0;xBlock<xBlocks_;xBlock++) {
283  for(int yBlock=0;yBlock<yBlocks_;yBlock++) {
284  for(int zBlock=0;zBlock<zBlocks_;zBlock++) {
285  buildBlock(parallelMach,xBlock,yBlock,zBlock,mesh);
286  }
287  }
288  }
289  mesh.endModification();
290 }
291 
292 void CubeHexMeshFactory::buildBlock(stk::ParallelMachine parallelMach,int xBlock,int yBlock,int zBlock,STK_Interface & mesh) const
293 {
294  // grab this processors rank and machine size
295  std::pair<panzer::Ordinal64,panzer::Ordinal64> sizeAndStartX = determineXElemSizeAndStart(xBlock,xProcs_,machRank_);
296  std::pair<panzer::Ordinal64,panzer::Ordinal64> sizeAndStartY = determineYElemSizeAndStart(yBlock,yProcs_,machRank_);
297  std::pair<panzer::Ordinal64,panzer::Ordinal64> sizeAndStartZ = determineZElemSizeAndStart(zBlock,zProcs_,machRank_);
298 
299  panzer::Ordinal64 myXElems_start = sizeAndStartX.first;
300  panzer::Ordinal64 myXElems_end = myXElems_start+sizeAndStartX.second;
301  panzer::Ordinal64 myYElems_start = sizeAndStartY.first;
302  panzer::Ordinal64 myYElems_end = myYElems_start+sizeAndStartY.second;
303  panzer::Ordinal64 myZElems_start = sizeAndStartZ.first;
304  panzer::Ordinal64 myZElems_end = myZElems_start+sizeAndStartZ.second;
305 
306  panzer::Ordinal64 totalXElems = nXElems_*xBlocks_;
307  panzer::Ordinal64 totalYElems = nYElems_*yBlocks_;
308  panzer::Ordinal64 totalZElems = nZElems_*zBlocks_;
309 
310  double deltaX = (xf_-x0_)/double(totalXElems);
311  double deltaY = (yf_-y0_)/double(totalYElems);
312  double deltaZ = (zf_-z0_)/double(totalZElems);
313 
314  std::vector<double> coord(3,0.0);
315 
316  // build the nodes
317  for(panzer::Ordinal64 nx=myXElems_start;nx<myXElems_end+1;++nx) {
318  coord[0] = double(nx)*deltaX+x0_;
319  for(panzer::Ordinal64 ny=myYElems_start;ny<myYElems_end+1;++ny) {
320  coord[1] = double(ny)*deltaY+y0_;
321  for(panzer::Ordinal64 nz=myZElems_start;nz<myZElems_end+1;++nz) {
322  coord[2] = double(nz)*deltaZ+z0_;
323 
324  mesh.addNode(nz*(totalYElems+1)*(totalXElems+1)+ny*(totalXElems+1)+nx+1,coord);
325  }
326  }
327  }
328 
329  std::stringstream blockName;
330  blockName << "eblock-" << xBlock << "_" << yBlock << "_" << zBlock;
331  stk::mesh::Part * block = mesh.getElementBlockPart(blockName.str());
332 
333  // build the elements
334  for(panzer::Ordinal64 nx=myXElems_start;nx<myXElems_end;++nx) {
335  for(panzer::Ordinal64 ny=myYElems_start;ny<myYElems_end;++ny) {
336  for(panzer::Ordinal64 nz=myZElems_start;nz<myZElems_end;++nz) {
337  stk::mesh::EntityId gid = totalXElems*totalYElems*nz+totalXElems*ny+nx+1;
338  std::vector<stk::mesh::EntityId> nodes(8);
339  nodes[0] = nx+1+ny*(totalXElems+1) +nz*(totalYElems+1)*(totalXElems+1);
340  nodes[1] = nodes[0]+1;
341  nodes[2] = nodes[1]+(totalXElems+1);
342  nodes[3] = nodes[2]-1;
343  nodes[4] = nodes[0]+(totalYElems+1)*(totalXElems+1);
344  nodes[5] = nodes[1]+(totalYElems+1)*(totalXElems+1);
345  nodes[6] = nodes[2]+(totalYElems+1)*(totalXElems+1);
346  nodes[7] = nodes[3]+(totalYElems+1)*(totalXElems+1);
347 
348  RCP<ElementDescriptor> ed = rcp(new ElementDescriptor(gid,nodes));
349  mesh.addElement(ed,block);
350  }
351  }
352  }
353 }
354 
355 std::pair<panzer::Ordinal64,panzer::Ordinal64> CubeHexMeshFactory::determineXElemSizeAndStart(int xBlock,unsigned int size,unsigned int rank) const
356 {
357  std::size_t xProcLoc = procTuple_[0];
358  panzer::Ordinal64 minElements = nXElems_/size;
359  panzer::Ordinal64 extra = nXElems_ - minElements*size;
360 
361  TEUCHOS_ASSERT(minElements>0);
362 
363  // first "extra" elements get an extra column of elements
364  // this determines the starting X index and number of elements
365  panzer::Ordinal64 nume=0, start=0;
366  if(panzer::Ordinal64(xProcLoc)<extra) {
367  nume = minElements+1;
368  start = xProcLoc*(minElements+1);
369  }
370  else {
371  nume = minElements;
372  start = extra*(minElements+1)+(xProcLoc-extra)*minElements;
373  }
374 
375  return std::make_pair(start+nXElems_*xBlock,nume);
376 }
377 
378 std::pair<panzer::Ordinal64,panzer::Ordinal64> CubeHexMeshFactory::determineYElemSizeAndStart(int yBlock,unsigned int size,unsigned int rank) const
379 {
380  // int start = yBlock*nYElems_;
381  // return std::make_pair(start,nYElems_);
382 
383  std::size_t yProcLoc = procTuple_[1];
384  panzer::Ordinal64 minElements = nYElems_/size;
385  panzer::Ordinal64 extra = nYElems_ - minElements*size;
386 
387  TEUCHOS_ASSERT(minElements>0);
388 
389  // first "extra" elements get an extra column of elements
390  // this determines the starting X index and number of elements
391  panzer::Ordinal64 nume=0, start=0;
392  if(panzer::Ordinal64(yProcLoc)<extra) {
393  nume = minElements+1;
394  start = yProcLoc*(minElements+1);
395  }
396  else {
397  nume = minElements;
398  start = extra*(minElements+1)+(yProcLoc-extra)*minElements;
399  }
400 
401  return std::make_pair(start+nYElems_*yBlock,nume);
402 }
403 
404 std::pair<panzer::Ordinal64,panzer::Ordinal64> CubeHexMeshFactory::determineZElemSizeAndStart(int zBlock,unsigned int size,unsigned int rank) const
405 {
406  // int start = zBlock*nZElems_;
407  // return std::make_pair(start,nZElems_);
408  std::size_t zProcLoc = procTuple_[2];
409  panzer::Ordinal64 minElements = nZElems_/size;
410  panzer::Ordinal64 extra = nZElems_ - minElements*size;
411 
412  TEUCHOS_ASSERT(minElements>0);
413 
414  // first "extra" elements get an extra column of elements
415  // this determines the starting X index and number of elements
416  panzer::Ordinal64 nume=0, start=0;
417  if(zProcLoc<Teuchos::as<std::size_t>(extra)) {
418  nume = minElements+1;
419  start = zProcLoc*(minElements+1);
420  }
421  else {
422  nume = minElements;
423  start = extra*(minElements+1)+(zProcLoc-extra)*minElements;
424  }
425 
426  return std::make_pair(start+nZElems_*zBlock,nume);
427 }
428 
429 // this adds side entities only (does not inject them into side sets)
431 {
432  mesh.beginModification();
433 
434  std::size_t totalXElems = nXElems_*xBlocks_;
435  std::size_t totalYElems = nYElems_*yBlocks_;
436  std::size_t totalZElems = nZElems_*zBlocks_;
437 
438  std::vector<stk::mesh::Entity> localElmts;
439  mesh.getMyElements(localElmts);
440 
441  stk::mesh::EntityId offset[6];
442  offset[0] = 0;
443  offset[1] = offset[0] + totalXElems*totalZElems;
444  offset[2] = offset[1] + totalYElems*totalZElems;
445  offset[3] = offset[2] + totalXElems*totalZElems;
446  offset[4] = offset[3] + totalYElems*totalZElems;
447  offset[5] = offset[4] + totalXElems*totalYElems;
448 
449  // gid = totalXElems*totalYElems*nz+totalXElems*ny+nx+1
450 
451  // loop over elements adding sides to sidesets
452  std::vector<stk::mesh::Entity>::const_iterator itr;
453  for(itr=localElmts.begin();itr!=localElmts.end();++itr) {
454  stk::mesh::Entity element = (*itr);
455  stk::mesh::EntityId gid = mesh.elementGlobalId(element);
456 
457  std::size_t nx,ny,nz;
458  nz = (gid-1) / (totalXElems*totalYElems);
459  gid = (gid-1)-nz*(totalXElems*totalYElems);
460  ny = gid / totalXElems;
461  nx = gid-ny*totalXElems;
462 
463  std::vector<stk::mesh::Part*> parts;
464 
465  if(nz==0) {
466  // on the back
467  stk::mesh::EntityId eid = (1+nx+ny*totalXElems)+offset[4];
468  stk::mesh::Entity side = mesh.getBulkData()->declare_entity(mesh.getSideRank(),eid,parts);
469  mesh.getBulkData()->declare_relation(element,side,4);
470  }
471  if(nz+1==totalZElems) {
472  // on the front
473  stk::mesh::EntityId eid = (1+nx+ny*totalXElems)+offset[5];
474  stk::mesh::Entity side = mesh.getBulkData()->declare_entity(mesh.getSideRank(),eid,parts);
475  mesh.getBulkData()->declare_relation(element,side,5);
476  }
477 
478  if(ny==0) {
479  // on the bottom
480  stk::mesh::EntityId eid = (1+nx+nz*totalXElems)+offset[0];
481  stk::mesh::Entity side = mesh.getBulkData()->declare_entity(mesh.getSideRank(),eid,parts);
482  mesh.getBulkData()->declare_relation(element,side,0);
483  }
484  if(ny+1==totalYElems) {
485  // on the top
486  stk::mesh::EntityId eid = (1+nx+nz*totalXElems)+offset[2];
487  stk::mesh::Entity side = mesh.getBulkData()->declare_entity(mesh.getSideRank(),eid,parts);
488  mesh.getBulkData()->declare_relation(element,side,2);
489  }
490 
491  if(nx==0) {
492  // on the left
493  stk::mesh::EntityId eid = (1+ny+nz*totalYElems)+offset[3];
494  stk::mesh::Entity side = mesh.getBulkData()->declare_entity(mesh.getSideRank(),eid,parts);
495  mesh.getBulkData()->declare_relation(element,side,3);
496  }
497  if(nx+1==totalXElems) {
498  // on the right
499  stk::mesh::EntityId eid = (1+ny+nz*totalYElems)+offset[1];
500  stk::mesh::Entity side = mesh.getBulkData()->declare_entity(mesh.getSideRank(),eid,parts);
501  mesh.getBulkData()->declare_relation(element,side,1);
502  }
503  }
504 
505  mesh.endModification();
506 }
507 
509 {
510  mesh.beginModification();
511  const stk::mesh::EntityRank side_rank = mesh.getSideRank();
512 
513  std::size_t totalXElems = nXElems_*xBlocks_;
514  std::size_t totalYElems = nYElems_*yBlocks_;
515  std::size_t totalZElems = nZElems_*zBlocks_;
516 
517  // get all part vectors
518  stk::mesh::Part * left = mesh.getSideset("left");
519  stk::mesh::Part * right = mesh.getSideset("right");
520  stk::mesh::Part * top = mesh.getSideset("top");
521  stk::mesh::Part * bottom = mesh.getSideset("bottom");
522  stk::mesh::Part * front = mesh.getSideset("front");
523  stk::mesh::Part * back = mesh.getSideset("back");
524 
525  std::vector<stk::mesh::Part*> vertical;
526  std::vector<stk::mesh::Part*> horizontal;
527  std::vector<stk::mesh::Part*> transverse;
528 
530  for(int bx=1;bx<xBlocks_;bx++) {
531  std::stringstream ss;
532  ss << "vertical_" << bx-1;
533  vertical.push_back(mesh.getSideset(ss.str()));
534  }
535  for(int by=1;by<yBlocks_;by++) {
536  std::stringstream ss;
537  ss << "horizontal_" << by-1;
538  horizontal.push_back(mesh.getSideset(ss.str()));
539  }
540  for(int bz=1;bz<zBlocks_;bz++) {
541  std::stringstream ss;
542  ss << "transverse_" << bz-1;
543  transverse.push_back(mesh.getSideset(ss.str()));
544  }
545  }
546 
547  std::vector<stk::mesh::Entity> localElmts;
548  mesh.getMyElements(localElmts);
549 
550  // gid = totalXElems*totalYElems*nz+totalXElems*ny+nx+1
551 
552  // loop over elements adding sides to sidesets
553  std::vector<stk::mesh::Entity>::const_iterator itr;
554  for(itr=localElmts.begin();itr!=localElmts.end();++itr) {
555  stk::mesh::Entity element = (*itr);
556  stk::mesh::EntityId gid = mesh.elementGlobalId(element);
557 
558  std::size_t nx,ny,nz;
559  nz = (gid-1) / (totalXElems*totalYElems);
560  gid = (gid-1)-nz*(totalXElems*totalYElems);
561  ny = gid / totalXElems;
562  nx = gid-ny*totalXElems;
563 
564  if(nz % nZElems_==0) {
565  stk::mesh::Entity side = mesh.findConnectivityById(element, side_rank, 4);
566 
567  // on the back
568  if(mesh.entityOwnerRank(side)==machRank_) {
569  if(nz==0) {
570  mesh.addEntityToSideset(side,back);
571  } else {
573  int index = nz/nZElems_-1;
574  mesh.addEntityToSideset(side,transverse[index]);
575  }
576  }
577  }
578  }
579  if((nz+1) % nZElems_==0) {
580  stk::mesh::Entity side = mesh.findConnectivityById(element, side_rank, 5);
581 
582  // on the front
583  if(mesh.entityOwnerRank(side)==machRank_) {
584  if(nz+1==totalZElems) {
585  mesh.addEntityToSideset(side,front);
586  } else {
588  int index = (nz+1)/nZElems_-1;
589  mesh.addEntityToSideset(side,transverse[index]);
590  }
591  }
592  }
593  }
594 
595  if(ny % nYElems_==0) {
596  stk::mesh::Entity side = mesh.findConnectivityById(element, side_rank, 0);
597 
598  // on the bottom
599  if(mesh.entityOwnerRank(side)==machRank_) {
600  if(ny==0) {
601  mesh.addEntityToSideset(side,bottom);
602  } else {
604  int index = ny/nYElems_-1;
605  mesh.addEntityToSideset(side,horizontal[index]);
606  }
607  }
608  }
609  }
610  if((ny+1) % nYElems_==0) {
611  stk::mesh::Entity side = mesh.findConnectivityById(element, side_rank, 2);
612 
613  // on the top
614  if(mesh.entityOwnerRank(side)==machRank_) {
615  if(ny+1==totalYElems) {
616  mesh.addEntityToSideset(side,top);
617  } else {
619  int index = (ny+1)/nYElems_-1;
620  mesh.addEntityToSideset(side,horizontal[index]);
621  }
622  }
623  }
624  }
625 
626  if(nx % nXElems_==0) {
627  stk::mesh::Entity side = mesh.findConnectivityById(element, side_rank, 3);
628 
629  // on the left
630  if(mesh.entityOwnerRank(side)==machRank_) {
631  if(nx==0) {
632  mesh.addEntityToSideset(side,left);
633  } else {
635  int index = nx/nXElems_-1;
636  mesh.addEntityToSideset(side,vertical[index]);
637  }
638  }
639  }
640  }
641  if((nx+1) % nXElems_==0) {
642  stk::mesh::Entity side = mesh.findConnectivityById(element, side_rank, 1);
643 
644  // on the right
645  if(mesh.entityOwnerRank(side)==machRank_) {
646  if(nx+1==totalXElems) {
647  mesh.addEntityToSideset(side,right);
648  } else {
650  int index = (nx+1)/nXElems_-1;
651  mesh.addEntityToSideset(side,vertical[index]);
652  }
653  }
654  }
655  }
656  }
657 
658  mesh.endModification();
659 }
660 
662 {
663  mesh.beginModification();
664 
665  // get all part vectors
666  stk::mesh::Part * origin = mesh.getNodeset("origin");
667 
668  Teuchos::RCP<stk::mesh::BulkData> bulkData = mesh.getBulkData();
669  if(machRank_==0)
670  {
671  // add zero node to origin node set
672  stk::mesh::Entity node = bulkData->get_entity(mesh.getNodeRank(),1);
673  mesh.addEntityToNodeset(node,origin);
674  }
675 
676  mesh.endModification();
677 }
678 
680 Teuchos::Tuple<std::size_t,3> CubeHexMeshFactory::procRankToProcTuple(std::size_t procRank) const
681 {
682  std::size_t i=0,j=0,k=0;
683 
684  k = procRank/(xProcs_*yProcs_); procRank = procRank % (xProcs_*yProcs_);
685  j = procRank/xProcs_; procRank = procRank % xProcs_;
686  i = procRank;
687 
688  return Teuchos::tuple(i,j,k);
689 }
690 
691 } // end panzer_stk
stk::mesh::Part * getElementBlockPart(const std::string &name) const
get the block count
std::pair< panzer::Ordinal64, panzer::Ordinal64 > determineYElemSizeAndStart(int yBlock, unsigned int size, unsigned int rank) const
void addNodeset(const std::string &name)
void addSides(STK_Interface &mesh) const
void addEntityToNodeset(stk::mesh::Entity entity, stk::mesh::Part *nodeset)
virtual Teuchos::RCP< STK_Interface > buildUncommitedMesh(stk::ParallelMachine parallelMach) const
std::pair< panzer::Ordinal64, panzer::Ordinal64 > determineXElemSizeAndStart(int xBlock, unsigned int size, unsigned int rank) const
void getMyElements(std::vector< stk::mesh::Entity > &elements) const
void addEntityToSideset(stk::mesh::Entity entity, stk::mesh::Part *sideset)
stk::mesh::EntityRank getNodeRank() const
Teuchos::RCP< stk::mesh::BulkData > getBulkData() const
void addSideSets(STK_Interface &mesh) const
virtual void completeMeshConstruction(STK_Interface &mesh, stk::ParallelMachine parallelMach) 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
stk::mesh::Part * getSideset(const std::string &name) const
void addElement(const Teuchos::RCP< ElementDescriptor > &ed, stk::mesh::Part *block)
stk::mesh::EntityId elementGlobalId(std::size_t lid) const
void buildMetaData(stk::ParallelMachine parallelMach, STK_Interface &mesh) const
Teuchos::RCP< STK_Interface > buildMesh(stk::ParallelMachine parallelMach) const
Build the mesh object.
bool isInitialized() const
Has initialize been called on this mesh object?
void setParameterList(const Teuchos::RCP< Teuchos::ParameterList > &paramList)
From ParameterListAcceptor.
Teuchos::Tuple< std::size_t, 3 > procRankToProcTuple(std::size_t procRank) const
what is the 3D tuple describe this processor distribution
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_
void buildElements(stk::ParallelMachine parallelMach, STK_Interface &mesh) const
void addNodeSets(STK_Interface &mesh) const
void addSideset(const std::string &name, const CellTopologyData *ctData)
std::vector< Teuchos::RCP< const PeriodicBC_MatcherBase > > periodicBCVec_
unsigned entityOwnerRank(stk::mesh::Entity entity) const
std::pair< panzer::Ordinal64, panzer::Ordinal64 > determineZElemSizeAndStart(int zBlock, unsigned int size, unsigned int rank) const
void rebalance(STK_Interface &mesh) const
Teuchos::RCP< const Teuchos::ParameterList > getValidParameters() const
From ParameterListAcceptor.
void addElementBlock(const std::string &name, const CellTopologyData *ctData)
stk::mesh::Part * getNodeset(const std::string &name) const
void buildBlock(stk::ParallelMachine machRank, int xBlock, int yBlock, int zBlock, STK_Interface &mesh) const
static void parsePeriodicBCList(const Teuchos::RCP< Teuchos::ParameterList > &pl, std::vector< Teuchos::RCP< const PeriodicBC_MatcherBase > > &periodicBC)