Panzer Version of the Day
Loading...
Searching...
No Matches
Panzer_STK_CubeTetMeshFactory.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
15using Teuchos::RCP;
16using Teuchos::rcp;
17
18namespace panzer_stk {
19
24
29
31Teuchos::RCP<STK_Interface> CubeTetMeshFactory::buildMesh(stk::ParallelMachine parallelMach) const
32{
33 PANZER_FUNC_TIME_MONITOR("panzer::CubeTetMeshFactory::buildMesh()");
34
35 // build all meta data
36 RCP<STK_Interface> mesh = buildUncommitedMesh(parallelMach);
37
38 // commit meta data
39 mesh->initialize(parallelMach);
40
41 // build bulk data
42 completeMeshConstruction(*mesh,parallelMach);
43
44 return mesh;
45}
46
47Teuchos::RCP<STK_Interface> CubeTetMeshFactory::buildUncommitedMesh(stk::ParallelMachine parallelMach) const
48{
49 PANZER_FUNC_TIME_MONITOR("panzer::CubeTetMeshFactory::buildUncomittedMesh()");
50
51 RCP<STK_Interface> mesh = rcp(new STK_Interface(3));
52
53 machRank_ = stk::parallel_machine_rank(parallelMach);
54 machSize_ = stk::parallel_machine_size(parallelMach);
55
56 if (xProcs_ == -1 && yProcs_ == -1 && zProcs_ == -1) {
57 // copied from galeri
58 xProcs_ = yProcs_ = zProcs_ = Teuchos::as<int>(pow(Teuchos::as<double>(machSize_), 0.333334));
59
60 if (xProcs_ * yProcs_ * zProcs_ != Teuchos::as<int>(machSize_)) {
61 // Simple method to find a set of processor assignments
62 xProcs_ = yProcs_ = zProcs_ = 1;
63
64 // This means that this works correctly up to about maxFactor^3
65 // processors.
66 const int maxFactor = 50;
67
68 int ProcTemp = machSize_;
69 int factors[maxFactor];
70 for (int jj = 0; jj < maxFactor; jj++) factors[jj] = 0;
71 for (int jj = 2; jj < maxFactor; jj++) {
72 bool flag = true;
73 while (flag) {
74 int temp = ProcTemp/jj;
75 if (temp*jj == ProcTemp) {
76 factors[jj]++;
77 ProcTemp = temp;
78
79 } else {
80 flag = false;
81 }
82 }
83 }
84 xProcs_ = ProcTemp;
85 for (int jj = maxFactor-1; jj > 0; jj--) {
86 while (factors[jj] != 0) {
87 if ((xProcs_ <= yProcs_) && (xProcs_ <= zProcs_)) xProcs_ = xProcs_*jj;
88 else if ((yProcs_ <= xProcs_) && (yProcs_ <= zProcs_)) yProcs_ = yProcs_*jj;
89 else zProcs_ = zProcs_*jj;
90 factors[jj]--;
91 }
92 }
93 }
94
95 } else if(xProcs_==-1) {
96 // default x only decomposition
98 yProcs_ = 1;
99 zProcs_ = 1;
100 }
101 TEUCHOS_TEST_FOR_EXCEPTION(int(machSize_)!=xProcs_*yProcs_*zProcs_,std::logic_error,
102 "Cannot build CubeTetMeshFactory, the product of \"X Procs\", \"Y Procs\", and \"Z Procs\""
103 " must equal the number of processors.");
105
106 // build meta information: blocks and side set setups
107 buildMetaData(parallelMach,*mesh);
108
109 mesh->addPeriodicBCs(periodicBCVec_);
110 mesh->setBoundingBoxSearchFlag(useBBoxSearch_);
111
112 return mesh;
113}
114
115void CubeTetMeshFactory::completeMeshConstruction(STK_Interface & mesh,stk::ParallelMachine parallelMach) const
116{
117 PANZER_FUNC_TIME_MONITOR("panzer::CubeTetMeshFactory::completeMeshConstruction()");
118
119 if(not mesh.isInitialized())
120 mesh.initialize(parallelMach);
121
122 // add node and element information
123 buildElements(parallelMach,mesh);
124
125 // finish up the edges and faces
126 mesh.buildSubcells();
129 mesh.buildLocalEdgeIDs();
130 }
132 mesh.buildLocalFaceIDs();
133 }
134
135 // now that edges are built, sidets can be added
136 addSideSets(mesh);
137 addNodeSets(mesh);
138
139 mesh.beginModification();
141 addEdgeBlocks(mesh);
142 }
144 addFaceBlocks(mesh);
145 }
146 mesh.endModification();
147
148 // calls Stk_MeshFactory::rebalance
149 this->rebalance(mesh);
150}
151
153void CubeTetMeshFactory::setParameterList(const Teuchos::RCP<Teuchos::ParameterList> & paramList)
154{
155 paramList->validateParametersAndSetDefaults(*getValidParameters(),0);
156
157 setMyParamList(paramList);
158
159 x0_ = paramList->get<double>("X0");
160 y0_ = paramList->get<double>("Y0");
161 z0_ = paramList->get<double>("Z0");
162
163 xf_ = paramList->get<double>("Xf");
164 yf_ = paramList->get<double>("Yf");
165 zf_ = paramList->get<double>("Zf");
166
167 xBlocks_ = paramList->get<int>("X Blocks");
168 yBlocks_ = paramList->get<int>("Y Blocks");
169 zBlocks_ = paramList->get<int>("Z Blocks");
170
171 xProcs_ = paramList->get<int>("X Procs");
172 yProcs_ = paramList->get<int>("Y Procs");
173 zProcs_ = paramList->get<int>("Z Procs");
174
175 nXElems_ = paramList->get<int>("X Elements");
176 nYElems_ = paramList->get<int>("Y Elements");
177 nZElems_ = paramList->get<int>("Z Elements");
178
179 createEdgeBlocks_ = paramList->get<bool>("Create Edge Blocks");
180 createFaceBlocks_ = paramList->get<bool>("Create Face Blocks");
181
182 splitHexIntoTwelveTets_ = paramList->get<bool>("Split hex into 12 tets");
183
184 // read in periodic boundary conditions
185 parsePeriodicBCList(Teuchos::rcpFromRef(paramList->sublist("Periodic BCs")),periodicBCVec_,useBBoxSearch_);
186}
187
189Teuchos::RCP<const Teuchos::ParameterList> CubeTetMeshFactory::getValidParameters() const
190{
191 static RCP<Teuchos::ParameterList> defaultParams;
192
193 // fill with default values
194 if(defaultParams == Teuchos::null) {
195 defaultParams = rcp(new Teuchos::ParameterList);
196
197 defaultParams->set<double>("X0",0.0);
198 defaultParams->set<double>("Y0",0.0);
199 defaultParams->set<double>("Z0",0.0);
200
201 defaultParams->set<double>("Xf",1.0);
202 defaultParams->set<double>("Yf",1.0);
203 defaultParams->set<double>("Zf",1.0);
204
205 defaultParams->set<int>("X Blocks",1);
206 defaultParams->set<int>("Y Blocks",1);
207 defaultParams->set<int>("Z Blocks",1);
208
209 defaultParams->set<int>("X Procs",-1);
210 defaultParams->set<int>("Y Procs",1);
211 defaultParams->set<int>("Z Procs",1);
212
213 defaultParams->set<int>("X Elements",5);
214 defaultParams->set<int>("Y Elements",5);
215 defaultParams->set<int>("Z Elements",5);
216
217 // default to false for backward compatibility
218 defaultParams->set<bool>("Create Edge Blocks",false,"Create edge blocks in the mesh");
219 defaultParams->set<bool>("Create Face Blocks",false,"Create face blocks in the mesh");
220
221 defaultParams->set<bool>("Split hex into 12 tets",true,"Create a tet mesh by splitting hexes into 12 tets. If false, split into 6 tets.");
222
223 Teuchos::ParameterList & bcs = defaultParams->sublist("Periodic BCs");
224 bcs.set<int>("Count",0); // no default periodic boundary conditions
225 }
226
227 return defaultParams;
228}
229
231{
232 // get valid parameters
233 RCP<Teuchos::ParameterList> validParams = rcp(new Teuchos::ParameterList(*getValidParameters()));
234
235 // set that parameter list
236 setParameterList(validParams);
237
238 /* This is a tet mesh factory so all elements in all element blocks
239 * will be tet4. This means that all the edges will be line2 and
240 * all the faces will be tri3. The edge and face block names are
241 * hard coded to reflect this.
242 */
245}
246
247void CubeTetMeshFactory::buildMetaData(stk::ParallelMachine /* parallelMach */, STK_Interface & mesh) const
248{
249 typedef shards::Tetrahedron<4> TetTopo;
250 const CellTopologyData * ctd = shards::getCellTopologyData<TetTopo>();
251 const CellTopologyData * side_ctd = shards::CellTopology(ctd).getBaseCellTopologyData(2,0);
252 const CellTopologyData * edge_ctd = shards::CellTopology(ctd).getBaseCellTopologyData(1,0);
253 const CellTopologyData * face_ctd = shards::CellTopology(ctd).getBaseCellTopologyData(2,0);
254
255 // build meta data
256 //mesh.setDimension(2);
257 for(int bx=0;bx<xBlocks_;bx++) {
258 for(int by=0;by<yBlocks_;by++) {
259 for(int bz=0;bz<zBlocks_;bz++) {
260
261 std::stringstream ebPostfix;
262 ebPostfix << "-" << bx << "_" << by << "_" << bz;
263
264 // add element blocks
265 mesh.addElementBlock("eblock"+ebPostfix.str(),ctd);
267 mesh.addEdgeBlock("eblock"+ebPostfix.str(),
269 edge_ctd);
270 }
272 mesh.addFaceBlock("eblock"+ebPostfix.str(),
274 face_ctd);
275 }
276 }
277 }
278 }
279
280 // add sidesets
281 mesh.addSideset("left",side_ctd);
282 mesh.addSideset("right",side_ctd);
283 mesh.addSideset("top",side_ctd);
284 mesh.addSideset("bottom",side_ctd);
285 mesh.addSideset("front",side_ctd);
286 mesh.addSideset("back",side_ctd);
287
288 mesh.addNodeset("origin");
289}
290
291void CubeTetMeshFactory::buildElements(stk::ParallelMachine parallelMach,STK_Interface & mesh) const
292{
293 mesh.beginModification();
294 // build each block
295 for(int xBlock=0;xBlock<xBlocks_;xBlock++) {
296 for(int yBlock=0;yBlock<yBlocks_;yBlock++) {
297 for(int zBlock=0;zBlock<zBlocks_;zBlock++) {
298 buildBlock(parallelMach,xBlock,yBlock,zBlock,mesh);
299 }
300 }
301 }
302 mesh.endModification();
303}
304
305void CubeTetMeshFactory::buildBlock(stk::ParallelMachine /* parallelMach */,int xBlock,int yBlock,int zBlock,STK_Interface & mesh) const
306{
307 // grab this processors rank and machine size
308 std::pair<int,int> sizeAndStartX = determineXElemSizeAndStart(xBlock,xProcs_,machRank_);
309 std::pair<int,int> sizeAndStartY = determineYElemSizeAndStart(yBlock,yProcs_,machRank_);
310 std::pair<int,int> sizeAndStartZ = determineZElemSizeAndStart(zBlock,zProcs_,machRank_);
311
312 int myXElems_start = sizeAndStartX.first;
313 int myXElems_end = myXElems_start+sizeAndStartX.second;
314 int myYElems_start = sizeAndStartY.first;
315 int myYElems_end = myYElems_start+sizeAndStartY.second;
316 int myZElems_start = sizeAndStartZ.first;
317 int myZElems_end = myZElems_start+sizeAndStartZ.second;
318
319 int totalXElems = nXElems_*xBlocks_;
320 int totalYElems = nYElems_*yBlocks_;
321 int totalZElems = nZElems_*zBlocks_;
322
323 double deltaX = (xf_-x0_)/double(totalXElems);
324 double deltaY = (yf_-y0_)/double(totalYElems);
325 double deltaZ = (zf_-z0_)/double(totalZElems);
326
327 std::vector<double> coord(3,0.0);
328
329 // build the nodes
330 for(int nx=myXElems_start;nx<myXElems_end+1;++nx) {
331 coord[0] = this->getMeshCoord(nx, deltaX, x0_);
332 for(int ny=myYElems_start;ny<myYElems_end+1;++ny) {
333 coord[1] = this->getMeshCoord(ny, deltaY, y0_);
334 for(int nz=myZElems_start;nz<myZElems_end+1;++nz) {
335 coord[2] = this->getMeshCoord(nz, deltaZ, z0_);
336
337 mesh.addNode(nz*(totalYElems+1)*(totalXElems+1)+ny*(totalXElems+1)+nx+1,coord);
338 }
339 }
340 }
341
342 std::stringstream blockName;
343 blockName << "eblock-" << xBlock << "_" << yBlock << "_" << zBlock;
344 stk::mesh::Part * block = mesh.getElementBlockPart(blockName.str());
345
346 // build the elements
347 for(int nx=myXElems_start;nx<myXElems_end;++nx) {
348 for(int ny=myYElems_start;ny<myYElems_end;++ny) {
349 for(int nz=myZElems_start;nz<myZElems_end;++nz) {
350
351 std::vector<stk::mesh::EntityId> nodes(8);
352 nodes[0] = nx+1+ny*(totalXElems+1) +nz*(totalYElems+1)*(totalXElems+1);
353 nodes[1] = nodes[0]+1;
354 nodes[2] = nodes[1]+(totalXElems+1);
355 nodes[3] = nodes[2]-1;
356 nodes[4] = nodes[0]+(totalYElems+1)*(totalXElems+1);
357 nodes[5] = nodes[1]+(totalYElems+1)*(totalXElems+1);
358 nodes[6] = nodes[2]+(totalYElems+1)*(totalXElems+1);
359 nodes[7] = nodes[3]+(totalYElems+1)*(totalXElems+1);
360
362 buildTwelveTetsOnHex(Teuchos::tuple(totalXElems,totalYElems,totalZElems),
363 Teuchos::tuple(nx,ny,nz),
364 block,nodes,mesh);
365 else
366 buildSixTetsOnHex(Teuchos::tuple(totalXElems,totalYElems,totalZElems),
367 Teuchos::tuple(nx,ny,nz),
368 block,nodes,mesh);
369 }
370 }
371 }
372}
373
374 void CubeTetMeshFactory::buildTwelveTetsOnHex(const Teuchos::Tuple<int,3> & meshDesc,
375 const Teuchos::Tuple<int,3> & element,
376 stk::mesh::Part * block,
377 const std::vector<stk::mesh::EntityId> & h_nodes,
378 STK_Interface & mesh) const
379{
380 Teuchos::FancyOStream out(Teuchos::rcpFromRef(std::cout));
381 out.setShowProcRank(true);
382 out.setOutputToRootOnly(-1);
383
384 int totalXElems = meshDesc[0]; int totalYElems = meshDesc[1]; int totalZElems = meshDesc[2];
385 int nx = element[0]; int ny = element[1]; int nz = element[2];
386
387 stk::mesh::EntityId hex_id = totalXElems*totalYElems*nz+totalXElems*ny+nx+1;
388 stk::mesh::EntityId gid_0 = 12*(hex_id-1)+1;
389 std::vector<stk::mesh::EntityId> nodes(4);
390
391 // add centroid node
392 stk::mesh::EntityId centroid = 0;
393 {
394 stk::mesh::EntityId largestNode = (totalXElems+1)*(totalYElems+1)*(totalZElems+1);
395 centroid = hex_id+largestNode;
396
397 // compute average of coordinates
398 std::vector<double> coord(3,0.0);
399 for(std::size_t i=0;i<h_nodes.size();i++) {
400 const double * node_coord = mesh.getNodeCoordinates(h_nodes[i]);
401 coord[0] += node_coord[0];
402 coord[1] += node_coord[1];
403 coord[2] += node_coord[2];
404 }
405 coord[0] /= 8.0;
406 coord[1] /= 8.0;
407 coord[2] /= 8.0;
408
409 mesh.addNode(centroid,coord);
410 }
411
412 //
413 int idSet[][3] = { { 0, 1, 2}, // back
414 { 0, 2, 3},
415 { 0, 5, 1}, // bottom
416 { 0, 4, 5},
417 { 0, 7, 4}, // left
418 { 0, 3, 7},
419 { 6, 1, 5}, // right
420 { 6, 2, 1},
421 { 6, 3, 2}, // top
422 { 6, 7, 3},
423 { 6, 4, 7}, // front
424 { 6, 5, 4} };
425
426 for(int i=0;i<12;i++) {
427 nodes[0] = h_nodes[idSet[i][0]];
428 nodes[1] = h_nodes[idSet[i][1]];
429 nodes[2] = h_nodes[idSet[i][2]];
430 nodes[3] = centroid;
431
432 // add element to mesh
433 mesh.addElement(rcp(new ElementDescriptor(gid_0+i,nodes)),block);
434 }
435}
436
437void CubeTetMeshFactory::buildSixTetsOnHex(const Teuchos::Tuple<int,3> & meshDesc,
438 const Teuchos::Tuple<int,3> & element,
439 stk::mesh::Part * block,
440 const std::vector<stk::mesh::EntityId> & h_nodes,
441 STK_Interface & mesh) const
442{
443 Teuchos::FancyOStream out(Teuchos::rcpFromRef(std::cout));
444 out.setShowProcRank(true);
445 out.setOutputToRootOnly(-1);
446
447 int totalXElems = meshDesc[0]; int totalYElems = meshDesc[1]; int totalZElems = meshDesc[2];
448 int nx = element[0]; int ny = element[1]; int nz = element[2];
449
450 stk::mesh::EntityId hex_id = totalXElems*totalYElems*nz+totalXElems*ny+nx+1;
451 stk::mesh::EntityId gid_0 = 6*(hex_id-1)+1;
452 std::vector<stk::mesh::EntityId> nodes(4);
453
454 // add centroid node
455 stk::mesh::EntityId centroid = 0;
456 {
457 stk::mesh::EntityId largestNode = (totalXElems+1)*(totalYElems+1)*(totalZElems+1);
458 centroid = hex_id+largestNode;
459
460 // compute average of coordinates
461 std::vector<double> coord(3,0.0);
462 for(std::size_t i=0;i<h_nodes.size();i++) {
463 const double * node_coord = mesh.getNodeCoordinates(h_nodes[i]);
464 coord[0] += node_coord[0];
465 coord[1] += node_coord[1];
466 coord[2] += node_coord[2];
467 }
468 coord[0] /= 8.0;
469 coord[1] /= 8.0;
470 coord[2] /= 8.0;
471
472 mesh.addNode(centroid,coord);
473 }
474
475 //
476 // int idSet[][3] = { { 0, 1, 2}, // back
477 // { 0, 2, 3},
478 // { 0, 5, 1}, // bottom
479 // { 0, 4, 5},
480 // { 0, 7, 4}, // left
481 // { 0, 3, 7},
482 // { 6, 1, 5}, // right
483 // { 6, 2, 1},
484 // { 6, 3, 2}, // top
485 // { 6, 7, 3},
486 // { 6, 4, 7}, // front
487 // { 6, 5, 4} };
488
489 int idSet[][4] = {
490 {0, 3, 7, 6},
491 {0, 7, 4, 6},
492 {0, 5, 4, 6},
493 {0, 1, 5, 6},
494 {0, 1, 2, 6},
495 {0, 2, 3, 6}
496 };
497
498 for(int i=0;i<6;i++) {
499 nodes[0] = h_nodes[idSet[i][0]];
500 nodes[1] = h_nodes[idSet[i][1]];
501 nodes[2] = h_nodes[idSet[i][2]];
502 nodes[3] = h_nodes[idSet[i][3]];
503
504 // add element to mesh
505 mesh.addElement(rcp(new ElementDescriptor(gid_0+i,nodes)),block);
506 }
507}
508
509std::pair<int,int> CubeTetMeshFactory::determineXElemSizeAndStart(int xBlock,unsigned int size,unsigned int /* rank */) const
510{
511 std::size_t xProcLoc = procTuple_[0];
512 unsigned int minElements = nXElems_/size;
513 unsigned int extra = nXElems_ - minElements*size;
514
515 TEUCHOS_ASSERT(minElements>0);
516
517 // first "extra" elements get an extra column of elements
518 // this determines the starting X index and number of elements
519 int nume=0, start=0;
520 if(xProcLoc<extra) {
521 nume = minElements+1;
522 start = xProcLoc*(minElements+1);
523 }
524 else {
525 nume = minElements;
526 start = extra*(minElements+1)+(xProcLoc-extra)*minElements;
527 }
528
529 return std::make_pair(start+nXElems_*xBlock,nume);
530}
531
532std::pair<int,int> CubeTetMeshFactory::determineYElemSizeAndStart(int yBlock,unsigned int size,unsigned int /* rank */) const
533{
534 // int start = yBlock*nYElems_;
535 // return std::make_pair(start,nYElems_);
536
537 std::size_t yProcLoc = procTuple_[1];
538 unsigned int minElements = nYElems_/size;
539 unsigned int extra = nYElems_ - minElements*size;
540
541 TEUCHOS_ASSERT(minElements>0);
542
543 // first "extra" elements get an extra column of elements
544 // this determines the starting X index and number of elements
545 int nume=0, start=0;
546 if(yProcLoc<extra) {
547 nume = minElements+1;
548 start = yProcLoc*(minElements+1);
549 }
550 else {
551 nume = minElements;
552 start = extra*(minElements+1)+(yProcLoc-extra)*minElements;
553 }
554
555 return std::make_pair(start+nYElems_*yBlock,nume);
556}
557
558std::pair<int,int> CubeTetMeshFactory::determineZElemSizeAndStart(int zBlock,unsigned int size,unsigned int /* rank */) const
559{
560 // int start = zBlock*nZElems_;
561 // return std::make_pair(start,nZElems_);
562 std::size_t zProcLoc = procTuple_[2];
563 unsigned int minElements = nZElems_/size;
564 unsigned int extra = nZElems_ - minElements*size;
565
566 TEUCHOS_ASSERT(minElements>0);
567
568 // first "extra" elements get an extra column of elements
569 // this determines the starting X index and number of elements
570 int nume=0, start=0;
571 if(zProcLoc<extra) {
572 nume = minElements+1;
573 start = zProcLoc*(minElements+1);
574 }
575 else {
576 nume = minElements;
577 start = extra*(minElements+1)+(zProcLoc-extra)*minElements;
578 }
579
580 return std::make_pair(start+nZElems_*zBlock,nume);
581}
582
584{
585 mesh.beginModification();
586 const stk::mesh::EntityRank side_rank = mesh.getSideRank();
587
588 std::size_t totalXElems = nXElems_*xBlocks_;
589 std::size_t totalYElems = nYElems_*yBlocks_;
590 std::size_t totalZElems = nZElems_*zBlocks_;
591
592 // get all part vectors
593 stk::mesh::Part * left = mesh.getSideset("left");
594 stk::mesh::Part * right = mesh.getSideset("right");
595 stk::mesh::Part * top = mesh.getSideset("top");
596 stk::mesh::Part * bottom = mesh.getSideset("bottom");
597 stk::mesh::Part * front = mesh.getSideset("front");
598 stk::mesh::Part * back = mesh.getSideset("back");
599
600 std::vector<stk::mesh::Entity> localElmts;
601 mesh.getMyElements(localElmts);
602
603 // gid = totalXElems*totalYElems*nz+totalXElems*ny+nx+1
604
605 // loop over elements adding sides to sidesets
606 std::vector<stk::mesh::Entity>::const_iterator itr;
607 for(itr=localElmts.begin();itr!=localElmts.end();++itr) {
608 stk::mesh::Entity element = (*itr);
609 stk::mesh::EntityId gid = mesh.elementGlobalId(element);
610
611 // get hex global id
612 stk::mesh::EntityId h_gid = (gid-1)/12+1;
613 stk::mesh::EntityId t_offset = gid - (12*(h_gid-1)+1);
614
615 std::size_t nx,ny,nz;
616 nz = (h_gid-1) / (totalXElems*totalYElems);
617 h_gid = (h_gid-1)-nz*(totalXElems*totalYElems);
618 ny = h_gid / totalXElems;
619 nx = h_gid-ny*totalXElems;
620
621 if(nz==0 && (t_offset==0 || t_offset==1)) {
622 stk::mesh::Entity side = mesh.findConnectivityById(element, side_rank, 3);
623
624 // on the back
625 if(mesh.entityOwnerRank(side)==machRank_)
626 mesh.addEntityToSideset(side,back);
627 }
628 if(nz+1==totalZElems && (t_offset==10 || t_offset==11)) {
629 stk::mesh::Entity side = mesh.findConnectivityById(element, side_rank, 3);
630
631 // on the front
632 if(mesh.entityOwnerRank(side)==machRank_)
633 mesh.addEntityToSideset(side,front);
634 }
635
636 if(ny==0 && (t_offset==2 || t_offset==3)) {
637 stk::mesh::Entity side = mesh.findConnectivityById(element, side_rank, 3);
638
639 // on the bottom
640 if(mesh.entityOwnerRank(side)==machRank_)
641 mesh.addEntityToSideset(side,bottom);
642 }
643 if(ny+1==totalYElems && (t_offset==8 || t_offset==9)) {
644 stk::mesh::Entity side = mesh.findConnectivityById(element, side_rank, 3);
645
646 // on the top
647 if(mesh.entityOwnerRank(side)==machRank_)
648 mesh.addEntityToSideset(side,top);
649 }
650
651 if(nx==0 && (t_offset==4 || t_offset==5)) {
652 stk::mesh::Entity side = mesh.findConnectivityById(element, side_rank, 3);
653
654 // on the left
655 if(mesh.entityOwnerRank(side)==machRank_)
656 mesh.addEntityToSideset(side,left);
657 }
658 if(nx+1==totalXElems && (t_offset==6 || t_offset==7)) {
659 stk::mesh::Entity side = mesh.findConnectivityById(element, side_rank, 3);
660
661 // on the right
662 if(mesh.entityOwnerRank(side)==machRank_)
663 mesh.addEntityToSideset(side,right);
664 }
665 }
666
667 mesh.endModification();
668}
669
671{
672 mesh.beginModification();
673
674 // get all part vectors
675 stk::mesh::Part * origin = mesh.getNodeset("origin");
676
677 Teuchos::RCP<stk::mesh::BulkData> bulkData = mesh.getBulkData();
678 if(machRank_==0)
679 {
680 // add zero node to origin node set
681 stk::mesh::Entity node = bulkData->get_entity(mesh.getNodeRank(),1);
682 mesh.addEntityToNodeset(node,origin);
683 }
684
685 mesh.endModification();
686}
687
688// Pre-Condition: call beginModification() before entry
689// Post-Condition: call endModification() after exit
691{
692 Teuchos::RCP<stk::mesh::BulkData> bulkData = mesh.getBulkData();
693 Teuchos::RCP<stk::mesh::MetaData> metaData = mesh.getMetaData();
694
695 stk::mesh::Part * edge_block = mesh.getEdgeBlock(edgeBlockName_);
696
697 stk::mesh::Selector owned_block = metaData->locally_owned_part();
698
699 std::vector<stk::mesh::Entity> edges;
700 bulkData->get_entities(mesh.getEdgeRank(), owned_block, edges);
701 mesh.addEntitiesToEdgeBlock(edges, edge_block);
702}
703
704// Pre-Condition: call beginModification() before entry
705// Post-Condition: call endModification() after exit
707{
708 Teuchos::RCP<stk::mesh::BulkData> bulkData = mesh.getBulkData();
709 Teuchos::RCP<stk::mesh::MetaData> metaData = mesh.getMetaData();
710
711 stk::mesh::Part * face_block = mesh.getFaceBlock(faceBlockName_);
712
713 stk::mesh::Selector owned_block = metaData->locally_owned_part();
714
715 std::vector<stk::mesh::Entity> faces;
716 bulkData->get_entities(mesh.getFaceRank(), owned_block, faces);
717 mesh.addEntitiesToFaceBlock(faces, face_block);
718}
719
721Teuchos::Tuple<std::size_t,3> CubeTetMeshFactory::procRankToProcTuple(std::size_t procRank) const
722{
723 std::size_t i=0,j=0,k=0;
724
725 k = procRank/(xProcs_*yProcs_); procRank = procRank % (xProcs_*yProcs_);
726 j = procRank/xProcs_; procRank = procRank % xProcs_;
727 i = procRank;
728
729 return Teuchos::tuple(i,j,k);
730}
731
732} // end panzer_stk
Teuchos::RCP< const Teuchos::ParameterList > getValidParameters() const
From ParameterListAcceptor.
void addFaceBlocks(STK_Interface &mesh) const
void addEdgeBlocks(STK_Interface &mesh) const
virtual Teuchos::RCP< STK_Interface > buildUncommitedMesh(stk::ParallelMachine parallelMach) const
void buildBlock(stk::ParallelMachine machRank, int xBlock, int yBlock, int zBlock, STK_Interface &mesh) const
void buildTwelveTetsOnHex(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
Teuchos::RCP< STK_Interface > buildMesh(stk::ParallelMachine parallelMach) const
Build the mesh object.
Teuchos::Tuple< std::size_t, 3 > procTuple_
void buildMetaData(stk::ParallelMachine parallelMach, STK_Interface &mesh) const
void buildSixTetsOnHex(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
void addSideSets(STK_Interface &mesh) const
void setParameterList(const Teuchos::RCP< Teuchos::ParameterList > &paramList)
From ParameterListAcceptor.
void buildElements(stk::ParallelMachine parallelMach, STK_Interface &mesh) const
std::pair< int, int > determineZElemSizeAndStart(int zBlock, unsigned int size, unsigned int rank) const
std::pair< int, int > determineXElemSizeAndStart(int xBlock, unsigned int size, unsigned int rank) const
virtual void completeMeshConstruction(STK_Interface &mesh, stk::ParallelMachine parallelMach) const
void addNodeSets(STK_Interface &mesh) const
std::pair< int, int > determineYElemSizeAndStart(int yBlock, 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
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
const double * getNodeCoordinates(stk::mesh::EntityId nodeId) const
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_