Panzer Version of the Day
Loading...
Searching...
No Matches
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
16using Teuchos::RCP;
17using Teuchos::rcp;
18
19namespace panzer_stk {
20
25
30
32Teuchos::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
48Teuchos::RCP<STK_Interface> CubeHexMeshFactory::buildUncommitedMesh(stk::ParallelMachine parallelMach) const
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 }
102 TEUCHOS_TEST_FOR_EXCEPTION(int(machSize_)!=xProcs_*yProcs_*zProcs_,std::logic_error,
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
116void 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 else {
135 addSides(mesh);
136 }
137
140 mesh.buildLocalEdgeIDs();
141 }
143 mesh.buildLocalFaceIDs();
144 }
145
146 mesh.beginModification();
147
148 // now that edges are built, side and node sets can be added
149 addSideSets(mesh);
150 addNodeSets(mesh);
152 addEdgeBlocks(mesh);
153 }
155 addFaceBlocks(mesh);
156 }
157
158 mesh.endModification();
159
160 // calls Stk_MeshFactory::rebalance
161 this->rebalance(mesh);
162}
163
165void CubeHexMeshFactory::setParameterList(const Teuchos::RCP<Teuchos::ParameterList> & paramList)
166{
167 paramList->validateParametersAndSetDefaults(*getValidParameters(),0);
168
169 setMyParamList(paramList);
170
171 x0_ = paramList->get<double>("X0");
172 y0_ = paramList->get<double>("Y0");
173 z0_ = paramList->get<double>("Z0");
174
175 xf_ = paramList->get<double>("Xf");
176 yf_ = paramList->get<double>("Yf");
177 zf_ = paramList->get<double>("Zf");
178
179 xBlocks_ = paramList->get<int>("X Blocks");
180 yBlocks_ = paramList->get<int>("Y Blocks");
181 zBlocks_ = paramList->get<int>("Z Blocks");
182
183 xProcs_ = paramList->get<int>("X Procs");
184 yProcs_ = paramList->get<int>("Y Procs");
185 zProcs_ = paramList->get<int>("Z Procs");
186
187 nXElems_ = paramList->get<int>("X Elements");
188 nYElems_ = paramList->get<int>("Y Elements");
189 nZElems_ = paramList->get<int>("Z Elements");
190
191 buildInterfaceSidesets_ = paramList->get<bool>("Build Interface Sidesets");
192
193 buildSubcells_ = paramList->get<bool>("Build Subcells");
194
195 createEdgeBlocks_ = paramList->get<bool>("Create Edge Blocks");
196 createFaceBlocks_ = paramList->get<bool>("Create Face Blocks");
198 Teuchos::FancyOStream out(Teuchos::rcpFromRef(std::cout));
199 out.setOutputToRootOnly(0);
200 out.setShowProcRank(true);
201
202 out << "CubeHexMesh: NOT creating edge blocks because building sub cells disabled" << std::endl;
203 createEdgeBlocks_ = false;
204 }
206 Teuchos::FancyOStream out(Teuchos::rcpFromRef(std::cout));
207 out.setOutputToRootOnly(0);
208 out.setShowProcRank(true);
209
210 out << "CubeHexMesh: NOT creating face blocks because building sub cells disabled" << std::endl;
211 createFaceBlocks_ = false;
212 }
213
214 // read in periodic boundary conditions
215 parsePeriodicBCList(Teuchos::rcpFromRef(paramList->sublist("Periodic BCs")),periodicBCVec_,useBBoxSearch_);
216}
217
219Teuchos::RCP<const Teuchos::ParameterList> CubeHexMeshFactory::getValidParameters() const
220{
221 static RCP<Teuchos::ParameterList> defaultParams;
222
223 // fill with default values
224 if(defaultParams == Teuchos::null) {
225 defaultParams = rcp(new Teuchos::ParameterList);
226
227 defaultParams->set<double>("X0",0.0);
228 defaultParams->set<double>("Y0",0.0);
229 defaultParams->set<double>("Z0",0.0);
230
231 defaultParams->set<double>("Xf",1.0);
232 defaultParams->set<double>("Yf",1.0);
233 defaultParams->set<double>("Zf",1.0);
234
235 defaultParams->set<int>("X Blocks",1);
236 defaultParams->set<int>("Y Blocks",1);
237 defaultParams->set<int>("Z Blocks",1);
238
239 defaultParams->set<int>("X Procs",-1);
240 defaultParams->set<int>("Y Procs",1);
241 defaultParams->set<int>("Z Procs",1);
242
243 defaultParams->set<int>("X Elements",5);
244 defaultParams->set<int>("Y Elements",5);
245 defaultParams->set<int>("Z Elements",5);
246
247 defaultParams->set<bool>("Build Interface Sidesets",false);
248
249 defaultParams->set<bool>("Build Subcells",true);
250
251 // default to false for backward compatibility
252 defaultParams->set<bool>("Create Edge Blocks",false,"Create edge blocks in the mesh");
253 defaultParams->set<bool>("Create Face Blocks",false,"Create face blocks in the mesh");
254
255 Teuchos::ParameterList & bcs = defaultParams->sublist("Periodic BCs");
256 bcs.set<int>("Count",0); // no default periodic boundary conditions
257 }
258
259 return defaultParams;
260}
261
263{
264 // get valid parameters
265 RCP<Teuchos::ParameterList> validParams = rcp(new Teuchos::ParameterList(*getValidParameters()));
266
267 // set that parameter list
268 setParameterList(validParams);
269
270 /* This is a hex mesh factory so all elements in all element blocks
271 * will be hex8. This means that all the edges will be line2 and
272 * all the faces will be quad4. The edge and face block names are
273 * hard coded to reflect this.
274 */
277}
278
279void CubeHexMeshFactory::buildMetaData(stk::ParallelMachine /* parallelMach */, STK_Interface & mesh) const
280{
281 typedef shards::Hexahedron<8> HexTopo;
282 const CellTopologyData * ctd = shards::getCellTopologyData<HexTopo>();
283 const CellTopologyData * side_ctd = shards::CellTopology(ctd).getBaseCellTopologyData(2,0);
284 const CellTopologyData * edge_ctd = shards::CellTopology(ctd).getBaseCellTopologyData(1,0);
285 const CellTopologyData * face_ctd = shards::CellTopology(ctd).getBaseCellTopologyData(2,0);
286
287 // build meta data
288 //mesh.setDimension(2);
289 for(int bx=0;bx<xBlocks_;bx++) {
290 for(int by=0;by<yBlocks_;by++) {
291 for(int bz=0;bz<zBlocks_;bz++) {
292
293 std::stringstream ebPostfix;
294 ebPostfix << "-" << bx << "_" << by << "_" << bz;
295
296 // add element blocks
297 mesh.addElementBlock("eblock"+ebPostfix.str(),ctd);
298
300 mesh.addEdgeBlock("eblock"+ebPostfix.str(),
302 edge_ctd);
303 }
305 mesh.addFaceBlock("eblock"+ebPostfix.str(),
307 face_ctd);
308 }
309 }
310 }
311 }
312
313 // add sidesets
314 mesh.addSideset("left",side_ctd);
315 mesh.addSideset("right",side_ctd);
316 mesh.addSideset("top",side_ctd);
317 mesh.addSideset("bottom",side_ctd);
318 mesh.addSideset("front",side_ctd);
319 mesh.addSideset("back",side_ctd);
320
322 for(int bx=1;bx<xBlocks_;bx++) {
323 std::stringstream ss;
324 ss << "vertical_" << bx-1;
325 mesh.addSideset(ss.str(),side_ctd);
326 }
327 for(int by=1;by<yBlocks_;by++) {
328 std::stringstream ss;
329 ss << "horizontal_" << by-1;
330 mesh.addSideset(ss.str(),side_ctd);
331 }
332 for(int bz=1;bz<zBlocks_;bz++) {
333 std::stringstream ss;
334 ss << "transverse_" << bz-1;
335 mesh.addSideset(ss.str(),side_ctd);
336 }
337 }
338
339 // add nodesets
340 mesh.addNodeset("origin");
341}
342
343void CubeHexMeshFactory::buildElements(stk::ParallelMachine parallelMach,STK_Interface & mesh) const
344{
345 mesh.beginModification();
346 // build each block
347 for(int xBlock=0;xBlock<xBlocks_;xBlock++) {
348 for(int yBlock=0;yBlock<yBlocks_;yBlock++) {
349 for(int zBlock=0;zBlock<zBlocks_;zBlock++) {
350 buildBlock(parallelMach,xBlock,yBlock,zBlock,mesh);
351 }
352 }
353 }
354 mesh.endModification();
355}
356
357void CubeHexMeshFactory::buildBlock(stk::ParallelMachine /* parallelMach */,int xBlock,int yBlock,int zBlock,STK_Interface & mesh) const
358{
359 // grab this processors rank and machine size
360 std::pair<panzer::GlobalOrdinal,panzer::GlobalOrdinal> sizeAndStartX = determineXElemSizeAndStart(xBlock,xProcs_,machRank_);
361 std::pair<panzer::GlobalOrdinal,panzer::GlobalOrdinal> sizeAndStartY = determineYElemSizeAndStart(yBlock,yProcs_,machRank_);
362 std::pair<panzer::GlobalOrdinal,panzer::GlobalOrdinal> sizeAndStartZ = determineZElemSizeAndStart(zBlock,zProcs_,machRank_);
363
364 panzer::GlobalOrdinal myXElems_start = sizeAndStartX.first;
365 panzer::GlobalOrdinal myXElems_end = myXElems_start+sizeAndStartX.second;
366 panzer::GlobalOrdinal myYElems_start = sizeAndStartY.first;
367 panzer::GlobalOrdinal myYElems_end = myYElems_start+sizeAndStartY.second;
368 panzer::GlobalOrdinal myZElems_start = sizeAndStartZ.first;
369 panzer::GlobalOrdinal myZElems_end = myZElems_start+sizeAndStartZ.second;
370
371 panzer::GlobalOrdinal totalXElems = nXElems_*xBlocks_;
372 panzer::GlobalOrdinal totalYElems = nYElems_*yBlocks_;
373 panzer::GlobalOrdinal totalZElems = nZElems_*zBlocks_;
374
375 double deltaX = (xf_-x0_)/double(totalXElems);
376 double deltaY = (yf_-y0_)/double(totalYElems);
377 double deltaZ = (zf_-z0_)/double(totalZElems);
378
379 std::vector<double> coord(3,0.0);
380
381 // build the nodes
382 for(panzer::GlobalOrdinal nx=myXElems_start;nx<myXElems_end+1;++nx) {
383 coord[0] = this->getMeshCoord(nx, deltaX, x0_);
384 for(panzer::GlobalOrdinal ny=myYElems_start;ny<myYElems_end+1;++ny) {
385 coord[1] = this->getMeshCoord(ny, deltaY, y0_);
386 for(panzer::GlobalOrdinal nz=myZElems_start;nz<myZElems_end+1;++nz) {
387 coord[2] = this->getMeshCoord(nz, deltaZ, z0_);
388
389 mesh.addNode(nz*(totalYElems+1)*(totalXElems+1)+ny*(totalXElems+1)+nx+1,coord);
390 }
391 }
392 }
393
394 std::stringstream blockName;
395 blockName << "eblock-" << xBlock << "_" << yBlock << "_" << zBlock;
396 stk::mesh::Part * block = mesh.getElementBlockPart(blockName.str());
397
398 // build the elements
399 for(panzer::GlobalOrdinal nx=myXElems_start;nx<myXElems_end;++nx) {
400 for(panzer::GlobalOrdinal ny=myYElems_start;ny<myYElems_end;++ny) {
401 for(panzer::GlobalOrdinal nz=myZElems_start;nz<myZElems_end;++nz) {
402 stk::mesh::EntityId gid = totalXElems*totalYElems*nz+totalXElems*ny+nx+1;
403 std::vector<stk::mesh::EntityId> nodes(8);
404 nodes[0] = nx+1+ny*(totalXElems+1) +nz*(totalYElems+1)*(totalXElems+1);
405 nodes[1] = nodes[0]+1;
406 nodes[2] = nodes[1]+(totalXElems+1);
407 nodes[3] = nodes[2]-1;
408 nodes[4] = nodes[0]+(totalYElems+1)*(totalXElems+1);
409 nodes[5] = nodes[1]+(totalYElems+1)*(totalXElems+1);
410 nodes[6] = nodes[2]+(totalYElems+1)*(totalXElems+1);
411 nodes[7] = nodes[3]+(totalYElems+1)*(totalXElems+1);
412
413 RCP<ElementDescriptor> ed = rcp(new ElementDescriptor(gid,nodes));
414 mesh.addElement(ed,block);
415 }
416 }
417 }
418}
419
420std::pair<panzer::GlobalOrdinal,panzer::GlobalOrdinal> CubeHexMeshFactory::determineXElemSizeAndStart(int xBlock,unsigned int size,unsigned int /* rank */) const
421{
422 std::size_t xProcLoc = procTuple_[0];
423 panzer::GlobalOrdinal minElements = nXElems_/size;
424 panzer::GlobalOrdinal extra = nXElems_ - minElements*size;
425
426 TEUCHOS_ASSERT(minElements>0);
427
428 // first "extra" elements get an extra column of elements
429 // this determines the starting X index and number of elements
430 panzer::GlobalOrdinal nume=0, start=0;
431 if(panzer::GlobalOrdinal(xProcLoc)<extra) {
432 nume = minElements+1;
433 start = xProcLoc*(minElements+1);
434 }
435 else {
436 nume = minElements;
437 start = extra*(minElements+1)+(xProcLoc-extra)*minElements;
438 }
439
440 return std::make_pair(start+nXElems_*xBlock,nume);
441}
442
443std::pair<panzer::GlobalOrdinal,panzer::GlobalOrdinal> CubeHexMeshFactory::determineYElemSizeAndStart(int yBlock,unsigned int size,unsigned int /* rank */) const
444{
445 // int start = yBlock*nYElems_;
446 // return std::make_pair(start,nYElems_);
447
448 std::size_t yProcLoc = procTuple_[1];
449 panzer::GlobalOrdinal minElements = nYElems_/size;
450 panzer::GlobalOrdinal extra = nYElems_ - minElements*size;
451
452 TEUCHOS_ASSERT(minElements>0);
453
454 // first "extra" elements get an extra column of elements
455 // this determines the starting X index and number of elements
456 panzer::GlobalOrdinal nume=0, start=0;
457 if(panzer::GlobalOrdinal(yProcLoc)<extra) {
458 nume = minElements+1;
459 start = yProcLoc*(minElements+1);
460 }
461 else {
462 nume = minElements;
463 start = extra*(minElements+1)+(yProcLoc-extra)*minElements;
464 }
465
466 return std::make_pair(start+nYElems_*yBlock,nume);
467}
468
469std::pair<panzer::GlobalOrdinal,panzer::GlobalOrdinal> CubeHexMeshFactory::determineZElemSizeAndStart(int zBlock,unsigned int size,unsigned int /* rank */) const
470{
471 // int start = zBlock*nZElems_;
472 // return std::make_pair(start,nZElems_);
473 std::size_t zProcLoc = procTuple_[2];
474 panzer::GlobalOrdinal minElements = nZElems_/size;
475 panzer::GlobalOrdinal extra = nZElems_ - minElements*size;
476
477 TEUCHOS_ASSERT(minElements>0);
478
479 // first "extra" elements get an extra column of elements
480 // this determines the starting X index and number of elements
481 panzer::GlobalOrdinal nume=0, start=0;
482 if(zProcLoc<Teuchos::as<std::size_t>(extra)) {
483 nume = minElements+1;
484 start = zProcLoc*(minElements+1);
485 }
486 else {
487 nume = minElements;
488 start = extra*(minElements+1)+(zProcLoc-extra)*minElements;
489 }
490
491 return std::make_pair(start+nZElems_*zBlock,nume);
492}
493
494// this adds side entities only (does not inject them into side sets)
496{
497 mesh.beginModification();
498
499 std::size_t totalXElems = nXElems_*xBlocks_;
500 std::size_t totalYElems = nYElems_*yBlocks_;
501 std::size_t totalZElems = nZElems_*zBlocks_;
502
503 std::vector<stk::mesh::Entity> localElmts;
504 mesh.getMyElements(localElmts);
505
506 stk::mesh::EntityId offset[6];
507 offset[0] = 0;
508 offset[1] = offset[0] + totalXElems*totalZElems;
509 offset[2] = offset[1] + totalYElems*totalZElems;
510 offset[3] = offset[2] + totalXElems*totalZElems;
511 offset[4] = offset[3] + totalYElems*totalZElems;
512 offset[5] = offset[4] + totalXElems*totalYElems;
513
514 // gid = totalXElems*totalYElems*nz+totalXElems*ny+nx+1
515
516 // loop over elements adding sides to sidesets
517 std::vector<stk::mesh::Entity>::const_iterator itr;
518 for(itr=localElmts.begin();itr!=localElmts.end();++itr) {
519 stk::mesh::Entity element = (*itr);
520 stk::mesh::EntityId gid = mesh.elementGlobalId(element);
521
522 std::size_t nx,ny,nz;
523 nz = (gid-1) / (totalXElems*totalYElems);
524 gid = (gid-1)-nz*(totalXElems*totalYElems);
525 ny = gid / totalXElems;
526 nx = gid-ny*totalXElems;
527
528 std::vector<stk::mesh::Part*> parts;
529
530 if(nz==0) {
531 // on the back
532 mesh.getBulkData()->declare_element_side(element, 4, parts);
533 }
534 if(nz+1==totalZElems) {
535 // on the front
536 mesh.getBulkData()->declare_element_side(element, 5, parts);
537 }
538
539 if(ny==0) {
540 // on the bottom
541 mesh.getBulkData()->declare_element_side(element, 0, parts);
542 }
543 if(ny+1==totalYElems) {
544 // on the top
545 mesh.getBulkData()->declare_element_side(element, 2, parts);
546 }
547
548 if(nx==0) {
549 // on the left
550 mesh.getBulkData()->declare_element_side(element, 3, parts);
551 }
552 if(nx+1==totalXElems) {
553 // on the right
554 mesh.getBulkData()->declare_element_side(element, 1, parts);
555 }
556 }
557
558 mesh.endModification();
559}
560
561// Pre-Condition: call beginModification() before entry
562// Post-Condition: call endModification() after exit
564{
565 const stk::mesh::EntityRank side_rank = mesh.getSideRank();
566
567 std::size_t totalXElems = nXElems_*xBlocks_;
568 std::size_t totalYElems = nYElems_*yBlocks_;
569 std::size_t totalZElems = nZElems_*zBlocks_;
570
571 // get all part vectors
572 stk::mesh::Part * left = mesh.getSideset("left");
573 stk::mesh::Part * right = mesh.getSideset("right");
574 stk::mesh::Part * top = mesh.getSideset("top");
575 stk::mesh::Part * bottom = mesh.getSideset("bottom");
576 stk::mesh::Part * front = mesh.getSideset("front");
577 stk::mesh::Part * back = mesh.getSideset("back");
578
579 std::vector<stk::mesh::Part*> vertical;
580 std::vector<stk::mesh::Part*> horizontal;
581 std::vector<stk::mesh::Part*> transverse;
582
584 for(int bx=1;bx<xBlocks_;bx++) {
585 std::stringstream ss;
586 ss << "vertical_" << bx-1;
587 vertical.push_back(mesh.getSideset(ss.str()));
588 }
589 for(int by=1;by<yBlocks_;by++) {
590 std::stringstream ss;
591 ss << "horizontal_" << by-1;
592 horizontal.push_back(mesh.getSideset(ss.str()));
593 }
594 for(int bz=1;bz<zBlocks_;bz++) {
595 std::stringstream ss;
596 ss << "transverse_" << bz-1;
597 transverse.push_back(mesh.getSideset(ss.str()));
598 }
599 }
600
601 std::vector<stk::mesh::Entity> localElmts;
602 mesh.getMyElements(localElmts);
603
604 // gid = totalXElems*totalYElems*nz+totalXElems*ny+nx+1
605
606 // loop over elements adding sides to sidesets
607 std::vector<stk::mesh::Entity>::const_iterator itr;
608 for(itr=localElmts.begin();itr!=localElmts.end();++itr) {
609 stk::mesh::Entity element = (*itr);
610 stk::mesh::EntityId gid = mesh.elementGlobalId(element);
611
612 std::size_t nx,ny,nz;
613 nz = (gid-1) / (totalXElems*totalYElems);
614 gid = (gid-1)-nz*(totalXElems*totalYElems);
615 ny = gid / totalXElems;
616 nx = gid-ny*totalXElems;
617
618 if(nz % nZElems_==0) {
619 stk::mesh::Entity side = mesh.findConnectivityById(element, side_rank, 4);
620
621 // on the back
622 if(mesh.entityOwnerRank(side)==machRank_) {
623 if(nz==0) {
624 mesh.addEntityToSideset(side,back);
625 } else {
627 int index = nz/nZElems_-1;
628 mesh.addEntityToSideset(side,transverse[index]);
629 }
630 }
631 }
632 }
633 if((nz+1) % nZElems_==0) {
634 stk::mesh::Entity side = mesh.findConnectivityById(element, side_rank, 5);
635
636 // on the front
637 if(mesh.entityOwnerRank(side)==machRank_) {
638 if(nz+1==totalZElems) {
639 mesh.addEntityToSideset(side,front);
640 } else {
642 int index = (nz+1)/nZElems_-1;
643 mesh.addEntityToSideset(side,transverse[index]);
644 }
645 }
646 }
647 }
648
649 if(ny % nYElems_==0) {
650 stk::mesh::Entity side = mesh.findConnectivityById(element, side_rank, 0);
651
652 // on the bottom
653 if(mesh.entityOwnerRank(side)==machRank_) {
654 if(ny==0) {
655 mesh.addEntityToSideset(side,bottom);
656 } else {
658 int index = ny/nYElems_-1;
659 mesh.addEntityToSideset(side,horizontal[index]);
660 }
661 }
662 }
663 }
664 if((ny+1) % nYElems_==0) {
665 stk::mesh::Entity side = mesh.findConnectivityById(element, side_rank, 2);
666
667 // on the top
668 if(mesh.entityOwnerRank(side)==machRank_) {
669 if(ny+1==totalYElems) {
670 mesh.addEntityToSideset(side,top);
671 } else {
673 int index = (ny+1)/nYElems_-1;
674 mesh.addEntityToSideset(side,horizontal[index]);
675 }
676 }
677 }
678 }
679
680 if(nx % nXElems_==0) {
681 stk::mesh::Entity side = mesh.findConnectivityById(element, side_rank, 3);
682
683 // on the left
684 if(mesh.entityOwnerRank(side)==machRank_) {
685 if(nx==0) {
686 mesh.addEntityToSideset(side,left);
687 } else {
689 int index = nx/nXElems_-1;
690 mesh.addEntityToSideset(side,vertical[index]);
691 }
692 }
693 }
694 }
695 if((nx+1) % nXElems_==0) {
696 stk::mesh::Entity side = mesh.findConnectivityById(element, side_rank, 1);
697
698 // on the right
699 if(mesh.entityOwnerRank(side)==machRank_) {
700 if(nx+1==totalXElems) {
701 mesh.addEntityToSideset(side,right);
702 } else {
704 int index = (nx+1)/nXElems_-1;
705 mesh.addEntityToSideset(side,vertical[index]);
706 }
707 }
708 }
709 }
710 }
711}
712
713// Pre-Condition: call beginModification() before entry
714// Post-Condition: call endModification() after exit
716{
717 // get all part vectors
718 stk::mesh::Part * origin = mesh.getNodeset("origin");
719
720 Teuchos::RCP<stk::mesh::BulkData> bulkData = mesh.getBulkData();
721 if(machRank_==0)
722 {
723 // add zero node to origin node set
724 stk::mesh::Entity node = bulkData->get_entity(mesh.getNodeRank(),1);
725 mesh.addEntityToNodeset(node,origin);
726 }
727}
728
729// Pre-Condition: call beginModification() before entry
730// Post-Condition: call endModification() after exit
732{
733 Teuchos::RCP<stk::mesh::BulkData> bulkData = mesh.getBulkData();
734 Teuchos::RCP<stk::mesh::MetaData> metaData = mesh.getMetaData();
735
736 stk::mesh::Part * edge_block = mesh.getEdgeBlock(edgeBlockName_);
737
738 stk::mesh::Selector owned_block = metaData->locally_owned_part();
739
740 std::vector<stk::mesh::Entity> edges;
741 bulkData->get_entities(mesh.getEdgeRank(), owned_block, edges);
742 mesh.addEntitiesToEdgeBlock(edges, edge_block);
743}
744
745// Pre-Condition: call beginModification() before entry
746// Post-Condition: call endModification() after exit
748{
749 Teuchos::RCP<stk::mesh::BulkData> bulkData = mesh.getBulkData();
750 Teuchos::RCP<stk::mesh::MetaData> metaData = mesh.getMetaData();
751
752 stk::mesh::Part * face_block = mesh.getFaceBlock(faceBlockName_);
753
754 stk::mesh::Selector owned_block = metaData->locally_owned_part();
755
756 std::vector<stk::mesh::Entity> faces;
757 bulkData->get_entities(mesh.getFaceRank(), owned_block, faces);
758 mesh.addEntitiesToFaceBlock(faces, face_block);
759}
760
762Teuchos::Tuple<std::size_t,3> CubeHexMeshFactory::procRankToProcTuple(std::size_t procRank) const
763{
764 std::size_t i=0,j=0,k=0;
765
766 k = procRank/(xProcs_*yProcs_); procRank = procRank % (xProcs_*yProcs_);
767 j = procRank/xProcs_; procRank = procRank % xProcs_;
768 i = procRank;
769
770 return Teuchos::tuple(i,j,k);
771}
772
773} // end panzer_stk
void buildElements(stk::ParallelMachine parallelMach, STK_Interface &mesh) const
virtual Teuchos::RCP< STK_Interface > buildUncommitedMesh(stk::ParallelMachine parallelMach) const
std::pair< panzer::GlobalOrdinal, panzer::GlobalOrdinal > determineZElemSizeAndStart(int zBlock, unsigned int size, unsigned int rank) const
void buildMetaData(stk::ParallelMachine parallelMach, STK_Interface &mesh) const
Teuchos::Tuple< std::size_t, 3 > procRankToProcTuple(std::size_t procRank) const
what is the 3D tuple describe this processor distribution
std::pair< panzer::GlobalOrdinal, panzer::GlobalOrdinal > determineYElemSizeAndStart(int yBlock, unsigned int size, unsigned int rank) const
std::pair< panzer::GlobalOrdinal, panzer::GlobalOrdinal > determineXElemSizeAndStart(int xBlock, unsigned int size, unsigned int rank) const
void addNodeSets(STK_Interface &mesh) const
Teuchos::Tuple< std::size_t, 3 > procTuple_
void addEdgeBlocks(STK_Interface &mesh) const
void buildBlock(stk::ParallelMachine machRank, int xBlock, int yBlock, int zBlock, STK_Interface &mesh) const
Teuchos::RCP< STK_Interface > buildMesh(stk::ParallelMachine parallelMach) const
Build the mesh object.
void addFaceBlocks(STK_Interface &mesh) const
Teuchos::RCP< const Teuchos::ParameterList > getValidParameters() const
From ParameterListAcceptor.
void addSideSets(STK_Interface &mesh) const
virtual void completeMeshConstruction(STK_Interface &mesh, stk::ParallelMachine parallelMach) const
void setParameterList(const Teuchos::RCP< Teuchos::ParameterList > &paramList)
From ParameterListAcceptor.
stk::mesh::Entity findConnectivityById(stk::mesh::Entity src, stk::mesh::EntityRank tgt_rank, unsigned rel_id) const
void initialize(stk::ParallelMachine parallelMach, bool setupIO=true, const bool buildRefinementSupport=false)
stk::mesh::Part * getElementBlockPart(const std::string &name) const
get the block part
static const std::string edgeBlockString
stk::mesh::EntityId elementGlobalId(std::size_t lid) const
stk::mesh::Part * getEdgeBlock(const std::string &name) const
get the block part
bool isInitialized() const
Has initialize been called on this mesh object?
void addEntitiesToFaceBlock(std::vector< stk::mesh::Entity > entities, stk::mesh::Part *faceblock)
stk::mesh::EntityRank getNodeRank() const
void addEdgeBlock(const std::string &elemBlockName, const std::string &edgeBlockName, const stk::topology &topology)
void buildSubcells()
force the mesh to build subcells: edges and faces
void addEntityToNodeset(stk::mesh::Entity entity, stk::mesh::Part *nodeset)
void addElement(const Teuchos::RCP< ElementDescriptor > &ed, stk::mesh::Part *block)
void addNode(stk::mesh::EntityId gid, const std::vector< double > &coord)
void addNodeset(const std::string &name)
void addSideset(const std::string &name, const CellTopologyData *ctData)
stk::mesh::EntityRank getFaceRank() const
Teuchos::RCP< stk::mesh::MetaData > getMetaData() const
stk::mesh::Part * getNodeset(const std::string &name) const
void endModification(const bool find_and_set_shared_nodes_in_stk=true)
unsigned entityOwnerRank(stk::mesh::Entity entity) const
void addEntitiesToEdgeBlock(std::vector< stk::mesh::Entity > entities, stk::mesh::Part *edgeblock)
void addEntityToSideset(stk::mesh::Entity entity, stk::mesh::Part *sideset)
stk::mesh::EntityRank getSideRank() const
void getMyElements(std::vector< stk::mesh::Entity > &elements) const
void addElementBlock(const std::string &name, const CellTopologyData *ctData)
void addFaceBlock(const std::string &elemBlockName, const std::string &faceBlockName, const stk::topology &topology)
Teuchos::RCP< stk::mesh::BulkData > getBulkData() const
static const std::string faceBlockString
stk::mesh::Part * getFaceBlock(const std::string &name) const
get the block part
stk::mesh::EntityRank getEdgeRank() const
stk::mesh::Part * getSideset(const std::string &name) const
void rebalance(STK_Interface &mesh) const
static void parsePeriodicBCList(const Teuchos::RCP< Teuchos::ParameterList > &pl, std::vector< Teuchos::RCP< const PeriodicBC_MatcherBase > > &periodicBC, bool &useBBoxSearch)
double getMeshCoord(const int nx, const double deltaX, const double x0) const
std::vector< Teuchos::RCP< const PeriodicBC_MatcherBase > > periodicBCVec_