Debian Codegraph @

packages/seacas/libraries/ioss/src/generated/Iogn_GeneratedMesh.C

raw
1 // Copyright(C) 1999-2025 National Technology & Engineering Solutions
2 // of Sandia, LLC (NTESS). Under the terms of Contract DE-NA0003525 with
3 // NTESS, the U.S. Government retains certain rights in this software.
4 //
5 // See packages/seacas/LICENSE for details
6
7 #include "Ioss_Hex8.h"
8 #include "Ioss_Pyramid5.h"
9 #include "Ioss_Shell4.h"
10 #include "Ioss_Tet4.h"
11 #include "Ioss_TriShell3.h"
12 #include "Ioss_Utils.h"
13 #include "generated/Iogn_GeneratedMesh.h"
14 #include <cassert> // for assert
15 #include <cmath> // for atan2, cos, sin
16 #include <fmt/format.h>
17 #include <fmt/ostream.h>
18 #include <iostream>
19 #include <numeric>
20 #include <string>
21 #include <tokenize.h> // for tokenize
22 #include <vector> // for vector
23
24 #include "Ioss_CodeTypes.h"
25 #include "Ioss_EntityType.h"
26
27 namespace {
28 void output_help(std::ostream &output)
29 {
30 fmt::print(output, "\nValid Options for GeneratedMesh parameter string:\n"
31 "\tIxJxK -- specifies intervals; must be first option. Ex: 4x10x12\n"
32 "\toffset:xoff, yoff, zoff\n"
33 "\tscale: xscl, yscl, zscl\n"
34 "\tzdecomp:n1,n2,n3,...,n#proc\n"
35 "\tbbox: xmin, ymin, zmin, xmax, ymax, zmax\n"
36 "\trotate: axis,angle,axis,angle,...\n"
37 "\tshell:xXyYzZ (specifies which plane to apply shell)\n"
38 "\tnodeset:xXyYzZ (specifies which plane to apply nodeset)\n"
39 "\tsideset:xXyYzZ (specifies which plane to apply sideset)\n"
40 "\ttets (split each hex into 6 tets)\n"
41 "\tpyramids (split each hex into 6 pyramids)\n"
42 "\tvariables:type,count,... "
43 "type=global|element|node|nodal|nodeset|nset|sideset|sset|surface\n"
44 "\ttimes:count (number of timesteps to generate)\n"
45 "\ttinit:t0 (start time, default 0.0)\n"
46 "\ttdelta:delta (delta between timesteps, default 1.0)\n"
47 "\tshow -- show mesh parameters\n"
48 "\thelp -- show this list\n\n");
49 }
50 } // namespace
51
52 namespace Iogn {
53 GeneratedMesh::GeneratedMesh(int64_t num_x, int64_t num_y, int64_t num_z, int proc_count,
54 int my_proc)
55 : numX(num_x), numY(num_y), numZ(num_z), myNumZ(num_z), processorCount(proc_count),
56 myProcessor(my_proc)
57 {
58 initialize();
59 }
60
61 GeneratedMesh::GeneratedMesh(const std::string &parameters, int proc_count, int my_proc)
62 : processorCount(proc_count), myProcessor(my_proc)
63 {
64 // Possible that the 'parameters' has the working directory path
65 // prepended to the parameter list. Strip off everything in front
66 // of the last '/' (if any)...
67 auto params = Ioss::tokenize(parameters, "/");
68
69 auto groups = Ioss::tokenize(params.back(), "|+");
70
71 if (groups[0] == "help") {
72 output_help(Ioss::OUTPUT());
73 groups[0] = "1x1x1";
74 }
75
76 // First 'group' is the interval specification -- IxJxK
77 auto tokens = Ioss::tokenize(groups[0], "x");
78 assert(tokens.size() == 3);
79 numX = std::stoull(tokens[0]);
80 numY = std::stoull(tokens[1]);
81 numZ = std::stoull(tokens[2]);
82
83 if (numX <= 0 || numY <= 0 || numZ <= 0) {
84 IOSS_ERROR(fmt::format("ERROR: (Iogn::GeneratedMesh::GeneratedMesh)\n"
85 " All interval counts must be greater than 0.\n"
86 " numX = {}, numY = {}, numZ = {}\n",
87 numX, numY, numZ));
88 }
89 initialize();
90 parse_options(groups);
91 }
92
93 GeneratedMesh::GeneratedMesh() { initialize(); }
94
95 void GeneratedMesh::initialize()
96 {
97 if (processorCount > numZ) {
98 IOSS_ERROR(
99 fmt::format("ERROR: (Iogn::GeneratedMesh::initialize)\n"
100 " The number of mesh intervals in the Z direction ({})\n"
101 " must be at least as large as the number of processors ({}).\n"
102 " The current parameters do not meet that requirement. Execution will "
103 "terminate.\n",
104 numZ, processorCount));
105 }
106
107 if (processorCount > 1) {
108 myNumZ = numZ / processorCount;
109 if (myProcessor < (numZ % processorCount)) {
110 myNumZ++;
111 }
112
113 // Determine myStartZ for this processor...
114 auto extra = numZ % processorCount;
115 if (extra > myProcessor) {
116 extra = myProcessor;
117 }
118 auto per_proc = numZ / processorCount;
119 myStartZ = myProcessor * per_proc + extra;
120 }
121 else {
122 myNumZ = numZ;
123 }
124
125 for (int i = 0; i < 3; i++) {
126 for (int j = 0; j < 3; j++) {
127 rotmat[i][j] = 0.0;
128 }
129 rotmat[i][i] = 1.0;
130 }
131
132 variableCount[Ioss::COMMSET] = 0;
133 variableCount[Ioss::EDGEBLOCK] = 0;
134 variableCount[Ioss::EDGESET] = 0;
135 variableCount[Ioss::ELEMENTBLOCK] = 0;
136 variableCount[Ioss::ELEMENTSET] = 0;
137 variableCount[Ioss::FACEBLOCK] = 0;
138 variableCount[Ioss::FACESET] = 0;
139 variableCount[Ioss::INVALID_TYPE] = 0;
140 variableCount[Ioss::NODEBLOCK] = 0;
141 variableCount[Ioss::NODESET] = 0;
142 variableCount[Ioss::REGION] = 0;
143 variableCount[Ioss::SIDEBLOCK] = 0;
144 variableCount[Ioss::SIDESET] = 0;
145 variableCount[Ioss::SUPERELEMENT] = 0;
146 }
147
148 void GeneratedMesh::create_tets(bool yesno) { createTets = yesno; }
149 void GeneratedMesh::create_pyramids(bool yesno) { createPyramids = yesno; }
150
151 int64_t GeneratedMesh::add_shell_block(ShellLocation loc)
152 {
153 shellBlocks.push_back(loc);
154 return shellBlocks.size();
155 }
156
157 int64_t GeneratedMesh::add_nodeset(ShellLocation loc)
158 {
159 nodesets.push_back(loc);
160 return nodesets.size();
161 }
162
163 int64_t GeneratedMesh::add_sideset(ShellLocation loc)
164 {
165 sidesets.push_back(loc);
166 return sidesets.size();
167 }
168
169 void GeneratedMesh::set_bbox(double xmin, double ymin, double zmin, double xmax, double ymax,
170 double zmax)
171 {
172 // NOTE: All calculations are based on the currently
173 // active interval settings. If scale or offset or zdecomp
174 // specified later in the option list, you may not get the
175 // desired bounding box.
176 if (numX == 0 || numY == 0 || numZ == 0) {
177 IOSS_ERROR(fmt::format("ERROR: (Iogn::GeneratedMesh::set_bbox)\n"
178 " All interval counts must be greater than 0.\n"
179 " numX = {}, numY = {}, numZ = {}\n",
180 numX, numY, numZ));
181 }
182
183 double x_range = xmax - xmin;
184 double y_range = ymax - ymin;
185 double z_range = zmax - zmin;
186
187 sclX = x_range / static_cast<double>(numX);
188 sclY = y_range / static_cast<double>(numY);
189 sclZ = z_range / static_cast<double>(numZ);
190
191 offX = xmin;
192 offY = ymin;
193 offZ = zmin;
194 }
195
196 void GeneratedMesh::set_scale(double scl_x, double scl_y, double scl_z)
197 {
198 sclX = scl_x;
199 sclY = scl_y;
200 sclZ = scl_z;
201 }
202
203 void GeneratedMesh::set_offset(double off_x, double off_y, double off_z)
204 {
205 offX = off_x;
206 offY = off_y;
207 offZ = off_z;
208 }
209
210 void GeneratedMesh::parse_options(const Ioss::NameList &groups)
211 {
212 for (size_t i = 1; i < groups.size(); i++) {
213 auto option = Ioss::tokenize(groups[i], ":");
214 // option[0] is the type of the option and option[1] is the argument to the option.
215
216 if (option[0] == "shell") {
217 // Option of the form "shell:xXyYzZ"
218 // The argument specifies whether there is a shell block
219 // at the location. 'x' is minX, 'X' is maxX, etc.
220 for (auto opt : option[1]) {
221 switch (opt) {
222 case 'x': add_shell_block(MX); break;
223 case 'X': add_shell_block(PX); break;
224 case 'y': add_shell_block(MY); break;
225 case 'Y': add_shell_block(PY); break;
226 case 'z': add_shell_block(MZ); break;
227 case 'Z': add_shell_block(PZ); break;
228 default: IOSS_ERROR(fmt::format("ERROR: Unrecognized shell location option '{}'.", opt));
229 }
230 }
231 }
232 else if (option[0] == "nodeset" || option[0] == "nset") {
233 // Option of the form "nodeset:xXyYzZ"
234 // The argument specifies whether there is a nodeset
235 // at the location. 'x' is minX, 'X' is maxX, etc.
236 for (auto opt : option[1]) {
237 switch (opt) {
238 case 'x': add_nodeset(MX); break;
239 case 'X': add_nodeset(PX); break;
240 case 'y': add_nodeset(MY); break;
241 case 'Y': add_nodeset(PY); break;
242 case 'z': add_nodeset(MZ); break;
243 case 'Z': add_nodeset(PZ); break;
244 default:
245 IOSS_ERROR(fmt::format("ERROR: Unrecognized nodeset location option '{}'.", opt));
246 }
247 }
248 }
249 else if (option[0] == "sideset" || option[0] == "sset") {
250 // Option of the form "sideset:xXyYzZ"
251 // The argument specifies whether there is a sideset
252 // at the location. 'x' is minX, 'X' is maxX, etc.
253 for (auto opt : option[1]) {
254 switch (opt) {
255 case 'x': add_sideset(MX); break;
256 case 'X': add_sideset(PX); break;
257 case 'y': add_sideset(MY); break;
258 case 'Y': add_sideset(PY); break;
259 case 'z': add_sideset(MZ); break;
260 case 'Z': add_sideset(PZ); break;
261 default:
262 IOSS_ERROR(fmt::format("ERROR: Unrecognized sideset location option '{}'.", opt));
263 }
264 }
265 }
266 else if (option[0] == "scale") {
267 // Option of the form "scale:xs,ys,zs
268 auto tokens = Ioss::tokenize(option[1], ",");
269 assert(tokens.size() == 3);
270 sclX = std::stod(tokens[0]);
271 sclY = std::stod(tokens[1]);
272 sclZ = std::stod(tokens[2]);
273 }
274
275 else if (option[0] == "offset") {
276 // Option of the form "offset:xo,yo,zo
277 auto tokens = Ioss::tokenize(option[1], ",");
278 assert(tokens.size() == 3);
279 offX = std::stod(tokens[0]);
280 offY = std::stod(tokens[1]);
281 offZ = std::stod(tokens[2]);
282 }
283
284 else if (option[0] == "zdecomp") {
285 // Option of the form "zdecomp:1,1,2,2,1,2,...
286 // Specifies the number of intervals in the z direction
287 // for each processor. The number of tokens must match
288 // the number of processors. Note that the new numZ will
289 // be the sum of the intervals specified in this command.
290 auto tokens = Ioss::tokenize(option[1], ",");
291 assert(tokens.size() == static_cast<size_t>(processorCount));
292 Ioss::Int64Vector Zs;
293 numZ = 0;
294 for (int j = 0; j < processorCount; j++) {
295 Zs.push_back(std::stoull(tokens[j]));
296 numZ += Zs[j];
297 }
298 myNumZ = Zs[myProcessor];
299 myStartZ = 0;
300 for (int j = 0; j < myProcessor; j++) {
301 myStartZ += Zs[j];
302 }
303 }
304
305 else if (option[0] == "bbox") {
306 // Bounding-Box Option of the form "bbox:xmin,ymin,zmin,xmax,ymax,zmaxo
307 auto tokens = Ioss::tokenize(option[1], ",");
308 assert(tokens.size() == 6);
309 double xmin = std::stod(tokens[0]);
310 double ymin = std::stod(tokens[1]);
311 double zmin = std::stod(tokens[2]);
312 double xmax = std::stod(tokens[3]);
313 double ymax = std::stod(tokens[4]);
314 double zmax = std::stod(tokens[5]);
315
316 set_bbox(xmin, ymin, zmin, xmax, ymax, zmax);
317 }
318
319 else if (option[0] == "rotate") {
320 // Rotate Option of the form "rotate:axis,angle,axis,angle,...
321 auto tokens = Ioss::tokenize(option[1], ",");
322 assert(tokens.size() % 2 == 0);
323 for (size_t ir = 0; ir < tokens.size();) {
324 std::string axis = tokens[ir++];
325 double angle_degree = std::stod(tokens[ir++]);
326 set_rotation(axis, angle_degree);
327 }
328 }
329
330 else if (option[0] == "times" || option[0] == "steps") {
331 timestepCount = std::stoull(option[1]);
332 }
333
334 else if (option[0] == "tinit") {
335 timestepInitial = std::stod(option[1]);
336 }
337
338 else if (option[0] == "tdelta") {
339 timestepInterval = std::stod(option[1]);
340 }
341
342 else if (option[0] == "tets") {
343 createTets = true;
344 }
345
346 else if (option[0] == "pyramids") {
347 createPyramids = true;
348 if (processorCount > 1) {
349 IOSS_ERROR("ERROR: Pyramid option can currently only be used in a serial run. "
350 "Parallel not supported yet.\n");
351 }
352 }
353
354 else if (option[0] == "variables") {
355 // Variables Option of the form "variables:global,10,element,100,..."
356 auto tokens = Ioss::tokenize(option[1], ",");
357 assert(tokens.size() % 2 == 0);
358 for (size_t ir = 0; ir < tokens.size();) {
359 std::string type = tokens[ir++];
360 int count = std::stoull(tokens[ir++]);
361 set_variable_count(type, count);
362 }
363 if (timestepCount == 0) {
364 timestepCount = 1;
365 }
366 }
367
368 else if (option[0] == "help") {
369 output_help(Ioss::OUTPUT());
370 }
371
372 else if (option[0] == "show") {
373 show_parameters();
374 }
375
376 else {
377 IOSS_ERROR(
378 fmt::format("ERROR: Unrecognized option '{}'. It will be ignored.\n", option[0]));
379 }
380 }
381 }
382
383 void GeneratedMesh::show_parameters() const
384 {
385 if (myProcessor == 0) {
386 fmt::print(Ioss::OUTPUT(),
387 "\nMesh Parameters:\n"
388 "\tIntervals: {} by {} by {}\n"
389 "\tX = {} * (0..{}) + {}\tRange: {} <= X <= {}\n"
390 "\tY = {} * (0..{}) + {}\tRange: {} <= Y <= {}\n"
391 "\tZ = {} * (0..{}) + {}\tRange: {} <= Z <= {}\n\n"
392 "\tNode Count (total) = {:12}\n"
393 "\tElement Count (total) = {:12}\n"
394 "\tBlock Count = {:12}\n"
395 "\tNodeSet Count = {:12}\n"
396 "\tSideSet Count = {:12}\n"
397 "\tTimestep Count = {:12}\n\n",
398 numX, numY, numZ, sclX, numX, offX, offX, offX + numX * sclX, sclY, numY, offY,
399 offY, offY + numY * sclY, sclZ, numZ, offZ, offZ, offZ + numZ * sclZ,
400 fmt::group_digits(node_count()), fmt::group_digits(element_count()),
401 fmt::group_digits(block_count()), fmt::group_digits(nodeset_count()),
402 fmt::group_digits(sideset_count()), fmt::group_digits(timestep_count()));
403
404 if (doRotation) {
405 fmt::print(Ioss::OUTPUT(), "\tRotation Matrix: \n\t");
406 for (const auto &elem : rotmat) {
407 for (double jj : elem) {
408 fmt::print(Ioss::OUTPUT(), fmt::runtime("{:14.e}\t"), jj);
409 }
410 fmt::print(Ioss::OUTPUT(), "\n\t");
411 }
412 fmt::print(Ioss::OUTPUT(), "\n");
413 }
414 }
415 }
416
417 int64_t GeneratedMesh::node_count() const
418 {
419 auto count = (numX + 1) * (numY + 1) * (numZ + 1);
420 if (createPyramids) {
421 // Handle node at center of hex which is used as vertex of each pyramid
422 count += numX * numY * numZ;
423 }
424 return count;
425 }
426
427 int64_t GeneratedMesh::node_count_proc() const
428 {
429 auto count = (numX + 1) * (numY + 1) * (myNumZ + 1);
430 if (createPyramids) {
431 // Handle node at center of hex which is used as vertex of each pyramid
432 count += numX * numY * myNumZ;
433 }
434 return count;
435 }
436
437 int GeneratedMesh::block_count() const { return static_cast<int>(shellBlocks.size()) + 1; }
438
439 int GeneratedMesh::nodeset_count() const { return static_cast<int>(nodesets.size()); }
440
441 int GeneratedMesh::sideset_count() const { return static_cast<int>(sidesets.size()); }
442
443 int64_t GeneratedMesh::element_count() const
444 {
445 int64_t count = element_count(1);
446 for (size_t i = 0; i < shellBlocks.size(); i++) {
447 count += element_count(i + 2);
448 }
449 return count;
450 }
451
452 int64_t GeneratedMesh::element_count_proc() const
453 {
454 int64_t count = 0;
455 for (int64_t i = 0; i < block_count(); i++) {
456 count += element_count_proc(i + 1);
457 }
458 return count;
459 }
460
461 int64_t GeneratedMesh::element_count(int64_t block_number) const
462 {
463 assert(block_number <= block_count());
464
465 if (block_number == 1) {
466 int64_t mult = (createTets || createPyramids) ? 6 : 1;
467 return mult * numX * numY * numZ;
468 }
469 ShellLocation loc = shellBlocks[block_number - 2];
470 return shell_element_count(loc);
471 }
472
473 int64_t GeneratedMesh::shell_element_count(ShellLocation loc) const
474 {
475 int64_t mult = createTets ? 2 : 1;
476 switch (loc) {
477 case MX:
478 case PX: return mult * numY * numZ;
479 case MY:
480 case PY: return mult * numX * numZ;
481 case MZ:
482 case PZ: return mult * numX * numY;
483 }
484 return 0;
485 }
486
487 int64_t GeneratedMesh::element_count_proc(int64_t block_number) const
488 {
489 assert(block_number <= block_count());
490
491 if (block_number == 1) {
492 int64_t mult = (createTets || createPyramids) ? 6 : 1;
493 return mult * numX * numY * myNumZ;
494 }
495 ShellLocation loc = shellBlocks[block_number - 2];
496 return shell_element_count_proc(loc);
497 }
498
499 int64_t GeneratedMesh::shell_element_count_proc(ShellLocation loc) const
500 {
501 int64_t mult = createTets ? 2 : 1;
502 switch (loc) {
503 case MX:
504 case PX: return mult * numY * myNumZ;
505 case MY:
506 case PY: return mult * numX * myNumZ;
507 case MZ:
508 if (myProcessor == 0) {
509 return mult * numX * numY;
510 }
511 else {
512 return 0;
513 }
514 case PZ:
515 if (myProcessor == processorCount - 1) {
516 return mult * numX * numY;
517 }
518 else {
519 return 0;
520 }
521 }
522 return 0;
523 }
524
525 int64_t GeneratedMesh::nodeset_node_count(int64_t id) const
526 {
527 // id is position in nodeset list + 1
528 assert(id > 0 && (size_t)id <= nodesets.size());
529 ShellLocation loc = nodesets[id - 1];
530 switch (loc) {
531 case MX:
532 case PX: return (numY + 1) * (numZ + 1);
533 case MY:
534 case PY: return (numX + 1) * (numZ + 1);
535 case MZ:
536 case PZ: return (numX + 1) * (numY + 1);
537 }
538 return 0;
539 }
540
541 int64_t GeneratedMesh::nodeset_node_count_proc(int64_t id) const
542 {
543 // id is position in nodeset list + 1
544 assert(id > 0 && (size_t)id <= nodesets.size());
545 ShellLocation loc = nodesets[id - 1];
546 switch (loc) {
547 case MX:
548 case PX: return (numY + 1) * (myNumZ + 1);
549 case MY:
550 case PY: return (numX + 1) * (myNumZ + 1);
551 case MZ:
552 if (myProcessor == 0) {
553 return (numX + 1) * (numY + 1);
554 }
555 else {
556 return 0;
557 }
558 case PZ:
559 if (myProcessor == processorCount - 1) {
560 return (numX + 1) * (numY + 1);
561 }
562 else {
563 return 0;
564 }
565 }
566 return 0;
567 }
568
569 int64_t GeneratedMesh::sideset_side_count(int64_t id) const
570 {
571 // id is position in sideset list + 1
572 int64_t mult = createTets ? 2 : 1;
573 assert(id > 0 && (size_t)id <= sidesets.size());
574 ShellLocation loc = sidesets[id - 1];
575 switch (loc) {
576 case MX:
577 case PX: return mult * numY * numZ;
578 case MY:
579 case PY: return mult * numX * numZ;
580 case MZ:
581 case PZ: return mult * numX * numY;
582 }
583 return 0;
584 }
585
586 int64_t GeneratedMesh::sideset_side_count_proc(int64_t id) const
587 {
588 // id is position in sideset list + 1
589 assert(id > 0 && (size_t)id <= sidesets.size());
590 int64_t mult = createTets ? 2 : 1;
591 ShellLocation loc = sidesets[id - 1];
592 switch (loc) {
593 case MX:
594 case PX: return mult * numY * myNumZ;
595 case MY:
596 case PY: return mult * numX * myNumZ;
597 case MZ:
598 if (myProcessor == 0) {
599 return mult * numX * numY;
600 }
601 else {
602 return 0;
603 }
604 case PZ:
605 if (myProcessor == processorCount - 1) {
606 return mult * numX * numY;
607 }
608 else {
609 return 0;
610 }
611 }
612 return 0;
613 }
614
615 std::pair<std::string, int> GeneratedMesh::topology_type(int64_t block_number) const
616 {
617 assert(block_number <= block_count() && block_number > 0);
618
619 if (createTets) {
620 if (block_number == 1) {
621 return std::make_pair(std::string(Ioss::Tet4::name), 4);
622 }
623 return std::make_pair(std::string(Ioss::TriShell3::name), 3);
624 }
625
626 if (createPyramids) {
627 if (block_number == 1) {
628 return std::make_pair(std::string(Ioss::Pyramid5::name), 5);
629 }
630 return std::make_pair(std::string(Ioss::Shell4::name), 4);
631 }
632
633 if (block_number == 1) {
634 return std::make_pair(std::string(Ioss::Hex8::name), 8);
635 }
636 return std::make_pair(std::string(Ioss::Shell4::name), 4);
637 }
638
639 void GeneratedMesh::node_map(Ioss::Int64Vector &map) const
640 {
641 map.resize(node_count_proc());
642 int64_t offset = myStartZ * (numX + 1) * (numY + 1);
643 std::iota(map.begin(), map.end(), offset + 1);
644 }
645
646 void GeneratedMesh::node_map(Ioss::IntVector &map) const
647 {
648 map.resize(node_count_proc());
649 int offset = myStartZ * (numX + 1) * (numY + 1);
650 std::iota(map.begin(), map.end(), offset + 1);
651 }
652
653 int64_t GeneratedMesh::communication_node_count_proc() const
654 {
655 int64_t count = (numX + 1) * (numY + 1);
656 if (myProcessor != 0 && myProcessor != processorCount - 1) {
657 count *= 2;
658 }
659
660 return count;
661 }
662
663 void GeneratedMesh::owning_processor(int *owner, int64_t num_node)
664 {
665 for (int64_t i = 0; i < num_node; i++) {
666 owner[i] = myProcessor;
667 }
668
669 if (myProcessor != 0) {
670 int64_t count = (numX + 1) * (numY + 1);
671 for (int64_t i = 0; i < count; i++) {
672 owner[i] = myProcessor - 1;
673 }
674 }
675 }
676
677 void GeneratedMesh::build_node_map(Ioss::Int64Vector &map, std::vector<int> &proc, int64_t slab,
678 size_t slabOffset, size_t adjacentProc, size_t index)
679 {
680 int64_t offset = (myStartZ + slabOffset) * (numX + 1) * (numY + 1);
681 for (int64_t i = 0; i < slab; i++) {
682 map[index] = offset + i + 1;
683 proc[index++] = static_cast<int>(adjacentProc);
684 }
685 }
686
687 void GeneratedMesh::node_communication_map(Ioss::Int64Vector &map, std::vector<int> &proc)
688 {
689 bool isFirstProc = myProcessor == 0;
690 bool isLastProc = myProcessor == processorCount - 1;
691
692 int64_t count = (numX + 1) * (numY + 1);
693 int64_t slab = count;
694 if (!isFirstProc && !isLastProc) {
695 count *= 2;
696 }
697 map.resize(count);
698 proc.resize(count);
699
700 size_t offset = 0;
701 if (!isFirstProc) {
702 build_node_map(map, proc, slab, 0, myProcessor - 1, offset);
703 offset += slab;
704 }
705 if (!isLastProc) {
706 build_node_map(map, proc, slab, myNumZ, myProcessor + 1, offset);
707 }
708 }
709
710 void GeneratedMesh::element_map(int64_t block_number, Ioss::Int64Vector &map) const
711 {
712 raw_element_map(block_number, map);
713 }
714
715 void GeneratedMesh::element_map(int64_t block_number, Ioss::IntVector &map) const
716 {
717 raw_element_map(block_number, map);
718 }
719
720 template <typename INT>
721 void GeneratedMesh::raw_element_map(int64_t block_number, std::vector<INT> &map) const
722 {
723 assert(block_number <= block_count() && block_number > 0);
724
725 INT count = element_count_proc(block_number);
726 map.reserve(count);
727
728 if (block_number == 1) {
729 // Hex/Tet/Pyramid block...
730 INT mult = (createTets || createPyramids) ? 6 : 1;
731 count = element_count_proc(1);
732 INT offset = mult * myStartZ * numX * numY;
733 for (INT i = 0; i < count; i++) {
734 map.push_back(offset + i + 1);
735 }
736 }
737 else {
738 INT start = element_count(1);
739
740 // Shell blocks...
741 for (INT ib = 0; (size_t)ib < shellBlocks.size(); ib++) {
742 INT mult = createTets ? 2 : 1;
743 count = element_count_proc(ib + 2);
744 if (block_number == ib + 2) {
745 INT offset = 0;
746 ShellLocation loc = shellBlocks[ib];
747
748 switch (loc) {
749 case MX:
750 case PX: offset = mult * myStartZ * numY; break;
751
752 case MY:
753 case PY: offset = mult * myStartZ * numX; break;
754
755 case MZ:
756 case PZ: offset = 0; break;
757 }
758 for (INT i = 0; i < count; i++) {
759 map.push_back(start + offset + i + 1);
760 }
761 }
762 else {
763 start += element_count(ib + 2);
764 }
765 }
766 }
767 }
768
769 void GeneratedMesh::element_map(Ioss::Int64Vector &map) const { raw_element_map(map); }
770
771 void GeneratedMesh::element_map(Ioss::IntVector &map) const { raw_element_map(map); }
772
773 template <typename INT> void GeneratedMesh::raw_element_map(std::vector<INT> &map) const
774 {
775 INT mult = (createTets || createPyramids) ? 6 : 1;
776 INT count = element_count_proc();
777 map.reserve(count);
778
779 // Hex block...
780 count = element_count_proc(1);
781 INT offset = mult * myStartZ * numX * numY;
782 for (INT i = 0; i < count; i++) {
783 map.push_back(offset + i + 1);
784 }
785
786 INT start = element_count(1);
787
788 // Shell blocks...
789 INT smult = createTets ? 2 : 1;
790 for (INT ib = 0; (size_t)ib < shellBlocks.size(); ib++) {
791 count = element_count_proc(ib + 2);
792 offset = 0;
793 ShellLocation loc = shellBlocks[ib];
794
795 switch (loc) {
796 case MX:
797 case PX: offset = smult * myStartZ * numY; break;
798
799 case MY:
800 case PY: offset = smult * myStartZ * numX; break;
801
802 case MZ:
803 case PZ: offset = 0; break;
804 }
805 for (INT i = 0; i < count; i++) {
806 map.push_back(start + offset + i + 1);
807 }
808 start += element_count(ib + 2);
809 }
810 }
811
812 void GeneratedMesh::element_surface_map(ShellLocation loc, Ioss::Int64Vector &map) const
813 {
814 int64_t count = shell_element_count_proc(loc);
815 map.resize(2 * count);
816 int64_t index = 0;
817 int64_t offset = 0;
818
819 if (createTets) {
820 // For tet elements
821 switch (loc) {
822 case MX:
823 offset = myStartZ * numX * numY + 1;
824 for (int64_t k = 0; k < myNumZ; ++k) {
825 for (int64_t j = 0; j < numY; ++j) {
826 map[index++] = 6 * offset - 4; // 1-based elem id
827 map[index++] = 3; // 0-based local face id
828 map[index++] = 6 * offset - 3;
829 map[index++] = 3; // 0-based local face id
830 offset += numX;
831 }
832 }
833 break;
834
835 case PX:
836 offset = myStartZ * numX * numY + numX;
837 for (int64_t k = 0; k < myNumZ; ++k) {
838 for (int64_t j = 0; j < numY; ++j) {
839 map[index++] = 6 * offset - 1; // 1-based elem id
840 map[index++] = 3; // 0-based local face id
841 map[index++] = 6 * offset; // 1-based elem id
842 map[index++] = 3; // 0-based local face id
843 offset += numX;
844 }
845 }
846 break;
847
848 case MY:
849 offset = myStartZ * numX * numY + 1;
850 for (int64_t k = 0; k < myNumZ; ++k) {
851 for (int64_t i = 0; i < numX; ++i) {
852 map[index++] = 6 * offset - 2; // 1-based elem id
853 map[index++] = 0; // 0-based local face id
854 map[index++] = 6 * offset++ - 1; // 1-based elem id
855 map[index++] = 0; // 0-based local face id
856 }
857 offset += numX * (numY - 1);
858 }
859 break;
860
861 case PY:
862 offset = myStartZ * numX * numY + numX * (numY - 1) + 1;
863 for (int64_t k = 0; k < myNumZ; ++k) {
864 for (int64_t i = 0; i < numX; ++i) {
865 map[index++] = 6 * offset - 5;
866 map[index++] = 1; // 0-based local face id
867 map[index++] = 6 * offset++ - 4;
868 map[index++] = 1; // 0-based local face id
869 }
870 offset += numX * (numY - 1);
871 }
872 break;
873
874 case MZ:
875 if (myProcessor == 0) {
876 offset = 1;
877 for (int64_t i = 0; i < numY; i++) {
878 for (int64_t j = 0; j < numX; j++) {
879 map[index++] = 6 * offset - 5;
880 map[index++] = 3;
881 map[index++] = 6 * offset++;
882 map[index++] = 2;
883 }
884 }
885 }
886 break;
887
888 case PZ:
889 if (myProcessor == processorCount - 1) {
890 offset = (numZ - 1) * numX * numY + 1;
891 for (int64_t i = 0, k = 0; i < numY; i++) {
892 for (int64_t j = 0; j < numX; j++, k++) {
893 map[index++] = 6 * offset - 3;
894 map[index++] = 1;
895 map[index++] = 6 * offset++ - 2;
896 map[index++] = 1;
897 }
898 }
899 }
900 break;
901 }
902 }
903 else if (createPyramids) {
904 // For pyramid elements
905 // NOT IMPLEMENTED AT ALL YET
906 assert(1 == 0);
907 switch (loc) {
908 case MX:
909 offset = myStartZ * numX * numY + 1;
910 for (int64_t k = 0; k < myNumZ; ++k) {
911 for (int64_t j = 0; j < numY; ++j) {
912 map[index++] = 6 * offset - 4; // 1-based elem id
913 map[index++] = 3; // 0-based local face id
914 map[index++] = 6 * offset - 3;
915 map[index++] = 3; // 0-based local face id
916 offset += numX;
917 }
918 }
919 break;
920
921 case PX:
922 offset = myStartZ * numX * numY + numX;
923 for (int64_t k = 0; k < myNumZ; ++k) {
924 for (int64_t j = 0; j < numY; ++j) {
925 map[index++] = 6 * offset - 1; // 1-based elem id
926 map[index++] = 3; // 0-based local face id
927 map[index++] = 6 * offset; // 1-based elem id
928 map[index++] = 3; // 0-based local face id
929 offset += numX;
930 }
931 }
932 break;
933
934 case MY:
935 offset = myStartZ * numX * numY + 1;
936 for (int64_t k = 0; k < myNumZ; ++k) {
937 for (int64_t i = 0; i < numX; ++i) {
938 map[index++] = 6 * offset - 2; // 1-based elem id
939 map[index++] = 0; // 0-based local face id
940 map[index++] = 6 * offset++ - 1; // 1-based elem id
941 map[index++] = 0; // 0-based local face id
942 }
943 offset += numX * (numY - 1);
944 }
945 break;
946
947 case PY:
948 offset = myStartZ * numX * numY + numX * (numY - 1) + 1;
949 for (int64_t k = 0; k < myNumZ; ++k) {
950 for (int64_t i = 0; i < numX; ++i) {
951 map[index++] = 6 * offset - 5;
952 map[index++] = 1; // 0-based local face id
953 map[index++] = 6 * offset++ - 4;
954 map[index++] = 1; // 0-based local face id
955 }
956 offset += numX * (numY - 1);
957 }
958 break;
959
960 case MZ:
961 if (myProcessor == 0) {
962 offset = 1;
963 for (int64_t i = 0; i < numY; i++) {
964 for (int64_t j = 0; j < numX; j++) {
965 map[index++] = 6 * offset - 5;
966 map[index++] = 3;
967 map[index++] = 6 * offset++;
968 map[index++] = 2;
969 }
970 }
971 }
972 break;
973
974 case PZ:
975 if (myProcessor == processorCount - 1) {
976 offset = (numZ - 1) * numX * numY + 1;
977 for (int64_t i = 0, k = 0; i < numY; i++) {
978 for (int64_t j = 0; j < numX; j++, k++) {
979 map[index++] = 6 * offset - 3;
980 map[index++] = 1;
981 map[index++] = 6 * offset++ - 2;
982 map[index++] = 1;
983 }
984 }
985 }
986 break;
987 }
988 }
989 else {
990 // For hex elements
991 switch (loc) {
992 case MX:
993 offset = myStartZ * numX * numY + 1; // 1-based elem id
994 for (int64_t k = 0; k < myNumZ; ++k) {
995 for (int64_t j = 0; j < numY; ++j) {
996 map[index++] = offset;
997 map[index++] = 3; // 0-based local face id
998 offset += numX;
999 }
1000 }
1001 break;
1002
1003 case PX:
1004 offset = myStartZ * numX * numY + numX;
1005 for (int64_t k = 0; k < myNumZ; ++k) {
1006 for (int64_t j = 0; j < numY; ++j) {
1007 map[index++] = offset; // 1-based elem id
1008 map[index++] = 1; // 0-based local face id
1009 offset += numX;
1010 }
1011 }
1012 break;
1013
1014 case MY:
1015 offset = myStartZ * numX * numY + 1;
1016 for (int64_t k = 0; k < myNumZ; ++k) {
1017 for (int64_t i = 0; i < numX; ++i) {
1018 map[index++] = offset++;
1019 map[index++] = 0; // 0-based local face id
1020 }
1021 offset += numX * (numY - 1);
1022 }
1023 break;
1024
1025 case PY:
1026 offset = myStartZ * numX * numY + numX * (numY - 1) + 1;
1027 for (int64_t k = 0; k < myNumZ; ++k) {
1028 for (int64_t i = 0; i < numX; ++i) {
1029 map[index++] = offset++;
1030 map[index++] = 2; // 0-based local face id
1031 }
1032 offset += numX * (numY - 1);
1033 }
1034 break;
1035
1036 case MZ:
1037 if (myProcessor == 0) {
1038 offset = 1;
1039 for (int64_t i = 0; i < numY; i++) {
1040 for (int64_t j = 0; j < numX; j++) {
1041 map[index++] = offset++;
1042 map[index++] = 4;
1043 }
1044 }
1045 }
1046 break;
1047
1048 case PZ:
1049 if (myProcessor == processorCount - 1) {
1050 offset = (numZ - 1) * numX * numY + 1;
1051 for (int64_t i = 0, k = 0; i < numY; i++) {
1052 for (int64_t j = 0; j < numX; j++, k++) {
1053 map[index++] = offset++;
1054 map[index++] = 5;
1055 }
1056 }
1057 }
1058 break;
1059 }
1060 }
1061 }
1062
1063 void GeneratedMesh::coordinates(std::vector<double> &coord) const
1064 {
1065 /* create global coordinates */
1066 int64_t count = node_count_proc();
1067 coord.resize(count * 3);
1068 coordinates(Data(coord));
1069 }
1070
1071 void GeneratedMesh::coordinates(double *coord) const
1072 {
1073 /* create global coordinates */
1074 int64_t count = node_count_proc();
1075
1076 int64_t k = 0;
1077 for (int64_t m = myStartZ; m < myStartZ + myNumZ + 1; m++) {
1078 for (int64_t i = 0; i < numY + 1; i++) {
1079 for (int64_t j = 0; j < numX + 1; j++) {
1080 coord[k++] = sclX * static_cast<double>(j) + offX;
1081 coord[k++] = sclY * static_cast<double>(i) + offY;
1082 coord[k++] = sclZ * static_cast<double>(m) + offZ;
1083 }
1084 }
1085 }
1086
1087 if (createPyramids) {
1088 for (int64_t m = myStartZ; m < myStartZ + myNumZ; m++) {
1089 for (int64_t i = 0; i < numY; i++) {
1090 for (int64_t j = 0; j < numX; j++) {
1091 coord[k++] = sclX * static_cast<double>(j) + 0.5 + offX;
1092 coord[k++] = sclY * static_cast<double>(i) + 0.5 + offY;
1093 coord[k++] = sclZ * static_cast<double>(m) + 0.5 + offZ;
1094 }
1095 }
1096 }
1097 }
1098
1099 assert(k == 3 * node_count_proc());
1100
1101 if (doRotation) {
1102 for (int64_t i = 0; i < count * 3; i += 3) {
1103 double xn = coord[i + 0];
1104 double yn = coord[i + 1];
1105 double zn = coord[i + 2];
1106 coord[i + 0] = xn * rotmat[0][0] + yn * rotmat[1][0] + zn * rotmat[2][0];
1107 coord[i + 1] = xn * rotmat[0][1] + yn * rotmat[1][1] + zn * rotmat[2][1];
1108 coord[i + 2] = xn * rotmat[0][2] + yn * rotmat[1][2] + zn * rotmat[2][2];
1109 }
1110 }
1111 }
1112
1113 void GeneratedMesh::coordinates(std::vector<double> &x, std::vector<double> &y,
1114 std::vector<double> &z) const
1115 {
1116 /* create global coordinates */
1117 int64_t count = node_count_proc();
1118 x.reserve(count);
1119 y.reserve(count);
1120 z.reserve(count);
1121
1122 for (int64_t m = myStartZ; m < myStartZ + myNumZ + 1; m++) {
1123 for (int64_t i = 0; i < numY + 1; i++) {
1124 for (int64_t j = 0; j < numX + 1; j++) {
1125 x.push_back(sclX * static_cast<double>(j) + offX);
1126 y.push_back(sclY * static_cast<double>(i) + offY);
1127 z.push_back(sclZ * static_cast<double>(m) + offZ);
1128 }
1129 }
1130 }
1131 if (doRotation) {
1132 for (int64_t i = 0; i < count; i++) {
1133 double xn = x[i];
1134 double yn = y[i];
1135 double zn = z[i];
1136 x.push_back(xn * rotmat[0][0] + yn * rotmat[1][0] + zn * rotmat[2][0]);
1137 y.push_back(xn * rotmat[0][1] + yn * rotmat[1][1] + zn * rotmat[2][1]);
1138 z.push_back(xn * rotmat[0][2] + yn * rotmat[1][2] + zn * rotmat[2][2]);
1139 }
1140 }
1141 }
1142
1143 void GeneratedMesh::coordinates(int component, std::vector<double> &xyz) const
1144 {
1145 assert(!doRotation);
1146 /* create global coordinates */
1147 size_t count = node_count_proc();
1148 xyz.reserve(count);
1149
1150 if (component == 1) {
1151 for (int64_t m = myStartZ; m < myStartZ + myNumZ + 1; m++) {
1152 for (int64_t i = 0; i < numY + 1; i++) {
1153 for (int64_t j = 0; j < numX + 1; j++) {
1154 xyz.push_back(sclX * static_cast<double>(j) + offX);
1155 }
1156 }
1157 }
1158 }
1159 else if (component == 2) {
1160 for (int64_t m = myStartZ; m < myStartZ + myNumZ + 1; m++) {
1161 for (int64_t i = 0; i < numY + 1; i++) {
1162 for (int64_t j = 0; j < numX + 1; j++) {
1163 xyz.push_back(sclY * static_cast<double>(i) + offY);
1164 }
1165 }
1166 }
1167 }
1168 else if (component == 3) {
1169 for (int64_t m = myStartZ; m < myStartZ + myNumZ + 1; m++) {
1170 for (int64_t i = 0; i < numY + 1; i++) {
1171 for (int64_t j = 0; j < numX + 1; j++) {
1172 xyz.push_back(sclZ * static_cast<double>(m) + offZ);
1173 }
1174 }
1175 }
1176 }
1177 }
1178
1179 void GeneratedMesh::coordinates(int component, double *xyz) const
1180 {
1181 assert(!doRotation);
1182 /* create global coordinates */
1183 int64_t idx = 0;
1184 if (component == 1) {
1185 for (int64_t m = myStartZ; m < myStartZ + myNumZ + 1; m++) {
1186 for (int64_t i = 0; i < numY + 1; i++) {
1187 for (int64_t j = 0; j < numX + 1; j++) {
1188 xyz[idx++] = sclX * static_cast<double>(j) + offX;
1189 }
1190 }
1191 }
1192 }
1193 else if (component == 2) {
1194 for (int64_t m = myStartZ; m < myStartZ + myNumZ + 1; m++) {
1195 for (int64_t i = 0; i < numY + 1; i++) {
1196 for (int64_t j = 0; j < numX + 1; j++) {
1197 xyz[idx++] = sclY * static_cast<double>(i) + offY;
1198 }
1199 }
1200 }
1201 }
1202 else if (component == 3) {
1203 for (int64_t m = myStartZ; m < myStartZ + myNumZ + 1; m++) {
1204 for (int64_t i = 0; i < numY + 1; i++) {
1205 for (int64_t j = 0; j < numX + 1; j++) {
1206 xyz[idx++] = sclZ * static_cast<double>(m) + offZ;
1207 }
1208 }
1209 }
1210 }
1211 }
1212
1213 void GeneratedMesh::connectivity(int64_t block_number, Ioss::Int64Vector &connect) const
1214 {
1215 if (block_number == 1) { // HEX/TET/PYR Element Block
1216 int64_t npe = createTets ? 4 : createPyramids ? 5 : 8;
1217 connect.resize(element_count_proc(block_number) * npe);
1218 }
1219 else {
1220 int64_t npe = createTets ? 3 : 4;
1221 connect.resize(element_count_proc(block_number) * npe);
1222 }
1223 raw_connectivity(block_number, Data(connect));
1224 }
1225
1226 void GeneratedMesh::connectivity(int64_t block_number, Ioss::IntVector &connect) const
1227 {
1228 if (block_number == 1) { // HEX Element Block
1229 int64_t npe = createTets ? 4 : createPyramids ? 5 : 8;
1230 connect.resize(element_count_proc(block_number) * npe);
1231 }
1232 else {
1233 int64_t npe = createTets ? 3 : 4;
1234 connect.resize(element_count_proc(block_number) * npe);
1235 }
1236 raw_connectivity(block_number, Data(connect));
1237 }
1238
1239 void GeneratedMesh::connectivity(int64_t block_number, int64_t *connect) const
1240 {
1241 raw_connectivity(block_number, connect);
1242 }
1243
1244 void GeneratedMesh::connectivity(int64_t block_number, int *connect) const
1245 {
1246 raw_connectivity(block_number, connect);
1247 }
1248
1249 template <typename INT>
1250 void GeneratedMesh::raw_connectivity(int64_t block_number, INT *connect) const
1251 {
1252 assert(block_number <= block_count());
1253
1254 INT xp1yp1 = (numX + 1) * (numY + 1);
1255
1256 /* build connectivity array (node list) for mesh */
1257 if (block_number == 1) { // main block elements
1258
1259 if (createTets) {
1260 // Tet elements
1261 INT tet_vert[][4] = {{0, 2, 3, 6}, {0, 3, 7, 6}, {0, 7, 4, 6},
1262 {0, 5, 6, 4}, {1, 5, 6, 0}, {1, 6, 2, 0}};
1263
1264 INT hex_vert[8];
1265 int64_t cnt = 0;
1266 for (int64_t m = myStartZ; m < myNumZ + myStartZ; m++) {
1267 for (int64_t i = 0, k = 0; i < numY; i++) {
1268 for (int64_t j = 0; j < numX; j++, k++) {
1269 int64_t base = (m * xp1yp1) + k + i + 1;
1270
1271 hex_vert[0] = base;
1272 hex_vert[1] = base + 1;
1273 hex_vert[2] = base + numX + 2;
1274 hex_vert[3] = base + numX + 1;
1275
1276 hex_vert[4] = xp1yp1 + base;
1277 hex_vert[5] = xp1yp1 + base + 1;
1278 hex_vert[6] = xp1yp1 + base + numX + 2;
1279 hex_vert[7] = xp1yp1 + base + numX + 1;
1280
1281 for (auto &elem : tet_vert) {
1282 connect[cnt++] = hex_vert[elem[0]];
1283 connect[cnt++] = hex_vert[elem[1]];
1284 connect[cnt++] = hex_vert[elem[2]];
1285 connect[cnt++] = hex_vert[elem[3]];
1286 }
1287 }
1288 }
1289 }
1290 }
1291 else if (createPyramids) {
1292 INT pyr_vert[][5] = {{0, 1, 5, 4}, {1, 2, 6, 5}, {2, 3, 7, 6},
1293 {0, 4, 7, 3}, {0, 3, 2, 1}, {4, 5, 6, 7}};
1294 INT hex_vert[8];
1295 int64_t cnt = 0;
1296 INT offset = (numX + 1) * (numY + 1) * (myNumZ + 1);
1297
1298 for (int64_t m = myStartZ; m < myNumZ + myStartZ; m++) {
1299 for (int64_t i = 0, k = 0; i < numY; i++) {
1300 for (int64_t j = 0; j < numX; j++, k++) {
1301 int64_t base = (m * xp1yp1) + k + i + 1;
1302 ++offset;
1303
1304 hex_vert[0] = base;
1305 hex_vert[1] = base + 1;
1306 hex_vert[2] = base + numX + 2;
1307 hex_vert[3] = base + numX + 1;
1308
1309 hex_vert[4] = xp1yp1 + base;
1310 hex_vert[5] = xp1yp1 + base + 1;
1311 hex_vert[6] = xp1yp1 + base + numX + 2;
1312 hex_vert[7] = xp1yp1 + base + numX + 1;
1313
1314 for (auto &elem : pyr_vert) {
1315 connect[cnt++] = hex_vert[elem[0]];
1316 connect[cnt++] = hex_vert[elem[1]];
1317 connect[cnt++] = hex_vert[elem[2]];
1318 connect[cnt++] = hex_vert[elem[3]];
1319
1320 connect[cnt++] = offset;
1321 }
1322 }
1323 }
1324 }
1325 }
1326 else {
1327 // Hex elements
1328 int64_t cnt = 0;
1329 for (int64_t m = myStartZ; m < myNumZ + myStartZ; m++) {
1330 for (int64_t i = 0, k = 0; i < numY; i++) {
1331 for (int64_t j = 0; j < numX; j++, k++) {
1332 int64_t base = (m * xp1yp1) + k + i + 1;
1333
1334 connect[cnt++] = base;
1335 connect[cnt++] = base + 1;
1336 connect[cnt++] = base + numX + 2;
1337 connect[cnt++] = base + numX + 1;
1338
1339 connect[cnt++] = xp1yp1 + base;
1340 connect[cnt++] = xp1yp1 + base + 1;
1341 connect[cnt++] = xp1yp1 + base + numX + 2;
1342 connect[cnt++] = xp1yp1 + base + numX + 1;
1343 }
1344 }
1345 }
1346 }
1347 }
1348 else { // Shell blocks....
1349 ShellLocation loc = shellBlocks[block_number - 2];
1350
1351 if (createTets) {
1352 // Tet shells
1353 int64_t cnt = 0;
1354 INT tet_vert[][3] = {{0, 3, 2}, {0, 2, 1}};
1355 INT hex_vert[4];
1356 switch (loc) {
1357 case MX: // Minimum X Face
1358 for (int64_t i = 0; i < myNumZ; i++) {
1359 int64_t layer_off = i * xp1yp1;
1360 for (int64_t j = 0; j < numY; j++) {
1361 int64_t base = layer_off + j * (numX + 1) + 1 + myStartZ * xp1yp1;
1362 hex_vert[0] = base;
1363 hex_vert[1] = base + xp1yp1;
1364 hex_vert[2] = base + xp1yp1 + (numX + 1);
1365 hex_vert[3] = base + (numX + 1);
1366
1367 for (auto &elem : tet_vert) {
1368 connect[cnt++] = hex_vert[elem[0]];
1369 connect[cnt++] = hex_vert[elem[1]];
1370 connect[cnt++] = hex_vert[elem[2]];
1371 }
1372 }
1373 }
1374 break;
1375 case PX: // Maximum X Face
1376 for (int64_t i = 0; i < myNumZ; i++) {
1377 int64_t layer_off = i * xp1yp1;
1378 for (int64_t j = 0; j < numY; j++) {
1379 int64_t base = layer_off + j * (numX + 1) + numX + 1 + myStartZ * xp1yp1;
1380 hex_vert[0] = base;
1381 hex_vert[1] = base + (numX + 1);
1382 hex_vert[2] = base + xp1yp1 + (numX + 1);
1383 hex_vert[3] = base + xp1yp1;
1384
1385 for (auto &elem : tet_vert) {
1386 connect[cnt++] = hex_vert[elem[0]];
1387 connect[cnt++] = hex_vert[elem[1]];
1388 connect[cnt++] = hex_vert[elem[2]];
1389 }
1390 }
1391 }
1392 break;
1393 case MY: // Minimum Y Face
1394 for (int64_t i = 0; i < myNumZ; i++) {
1395 int64_t layer_off = i * xp1yp1;
1396 for (int64_t j = 0; j < numX; j++) {
1397 int64_t base = layer_off + j + 1 + myStartZ * xp1yp1;
1398 hex_vert[0] = base;
1399 hex_vert[1] = base + 1;
1400 hex_vert[2] = base + xp1yp1 + 1;
1401 hex_vert[3] = base + xp1yp1;
1402
1403 for (auto &elem : tet_vert) {
1404 connect[cnt++] = hex_vert[elem[0]];
1405 connect[cnt++] = hex_vert[elem[1]];
1406 connect[cnt++] = hex_vert[elem[2]];
1407 }
1408 }
1409 }
1410 break;
1411 case PY: // Maximum Y Face
1412 for (int64_t i = 0; i < myNumZ; i++) {
1413 int64_t layer_off = i * xp1yp1;
1414 for (int64_t j = 0; j < numX; j++) {
1415 int64_t base = layer_off + (numX + 1) * (numY) + j + 1 + myStartZ * xp1yp1;
1416 hex_vert[0] = base;
1417 hex_vert[1] = base + xp1yp1;
1418 hex_vert[2] = base + xp1yp1 + 1;
1419 hex_vert[3] = base + 1;
1420
1421 for (auto &elem : tet_vert) {
1422 connect[cnt++] = hex_vert[elem[0]];
1423 connect[cnt++] = hex_vert[elem[1]];
1424 connect[cnt++] = hex_vert[elem[2]];
1425 }
1426 }
1427 }
1428 break;
1429 case MZ: // Minimum Z Face
1430 if (myProcessor == 0) {
1431 for (int64_t i = 0, k = 0; i < numY; i++) {
1432 for (int64_t j = 0; j < numX; j++, k++) {
1433 int64_t base = i + k + 1 + myStartZ * xp1yp1;
1434 hex_vert[0] = base;
1435 hex_vert[1] = base + numX + 1;
1436 hex_vert[2] = base + numX + 2;
1437 hex_vert[3] = base + 1;
1438
1439 for (auto &elem : tet_vert) {
1440 connect[cnt++] = hex_vert[elem[0]];
1441 connect[cnt++] = hex_vert[elem[1]];
1442 connect[cnt++] = hex_vert[elem[2]];
1443 }
1444 }
1445 }
1446 }
1447 break;
1448 case PZ: // Maximum Z Face
1449 if (myProcessor == processorCount - 1) {
1450 for (int64_t i = 0, k = 0; i < numY; i++) {
1451 for (int64_t j = 0; j < numX; j++, k++) {
1452 int64_t base = xp1yp1 * (numZ - myStartZ) + k + i + 1 + myStartZ * xp1yp1;
1453 hex_vert[0] = base;
1454 hex_vert[1] = base + 1;
1455 hex_vert[2] = base + numX + 2;
1456 hex_vert[3] = base + numX + 1;
1457
1458 for (auto &elem : tet_vert) {
1459 connect[cnt++] = hex_vert[elem[0]];
1460 connect[cnt++] = hex_vert[elem[1]];
1461 connect[cnt++] = hex_vert[elem[2]];
1462 }
1463 }
1464 }
1465 }
1466 break;
1467 }
1468 }
1469 else {
1470 // Hex shells
1471 int64_t cnt = 0;
1472 switch (loc) {
1473 case MX: // Minimum X Face
1474 for (int64_t i = 0; i < myNumZ; i++) {
1475 int64_t layer_off = i * xp1yp1;
1476 for (int64_t j = 0; j < numY; j++) {
1477 int64_t base = layer_off + j * (numX + 1) + 1 + myStartZ * xp1yp1;
1478 connect[cnt++] = base;
1479 connect[cnt++] = base + xp1yp1;
1480 connect[cnt++] = base + xp1yp1 + (numX + 1);
1481 connect[cnt++] = base + (numX + 1);
1482 }
1483 }
1484 break;
1485 case PX: // Maximum X Face
1486 for (int64_t i = 0; i < myNumZ; i++) {
1487 int64_t layer_off = i * xp1yp1;
1488 for (int64_t j = 0; j < numY; j++) {
1489 int64_t base = layer_off + j * (numX + 1) + numX + 1 + myStartZ * xp1yp1;
1490 connect[cnt++] = base;
1491 connect[cnt++] = base + (numX + 1);
1492 connect[cnt++] = base + xp1yp1 + (numX + 1);
1493 connect[cnt++] = base + xp1yp1;
1494 }
1495 }
1496 break;
1497 case MY: // Minimum Y Face
1498 for (int64_t i = 0; i < myNumZ; i++) {
1499 int64_t layer_off = i * xp1yp1;
1500 for (int64_t j = 0; j < numX; j++) {
1501 int64_t base = layer_off + j + 1 + myStartZ * xp1yp1;
1502 connect[cnt++] = base;
1503 connect[cnt++] = base + 1;
1504 connect[cnt++] = base + xp1yp1 + 1;
1505 connect[cnt++] = base + xp1yp1;
1506 }
1507 }
1508 break;
1509 case PY: // Maximum Y Face
1510 for (int64_t i = 0; i < myNumZ; i++) {
1511 int64_t layer_off = i * xp1yp1;
1512 for (int64_t j = 0; j < numX; j++) {
1513 int64_t base = layer_off + (numX + 1) * (numY) + j + 1 + myStartZ * xp1yp1;
1514 connect[cnt++] = base;
1515 connect[cnt++] = base + xp1yp1;
1516 connect[cnt++] = base + xp1yp1 + 1;
1517 connect[cnt++] = base + 1;
1518 }
1519 }
1520 break;
1521 case MZ: // Minimum Z Face
1522 if (myProcessor == 0) {
1523 for (int64_t i = 0, k = 0; i < numY; i++) {
1524 for (int64_t j = 0; j < numX; j++, k++) {
1525 int64_t base = i + k + 1 + myStartZ * xp1yp1;
1526 connect[cnt++] = base;
1527 connect[cnt++] = base + numX + 1;
1528 connect[cnt++] = base + numX + 2;
1529 connect[cnt++] = base + 1;
1530 }
1531 }
1532 }
1533 break;
1534 case PZ: // Maximum Z Face
1535 if (myProcessor == processorCount - 1) {
1536 for (int64_t i = 0, k = 0; i < numY; i++) {
1537 for (int64_t j = 0; j < numX; j++, k++) {
1538 int64_t base = xp1yp1 * (numZ - myStartZ) + k + i + 1 + myStartZ * xp1yp1;
1539 connect[cnt++] = base;
1540 connect[cnt++] = base + 1;
1541 connect[cnt++] = base + numX + 2;
1542 connect[cnt++] = base + numX + 1;
1543 }
1544 }
1545 }
1546 break;
1547 }
1548 assert((cnt == int64_t(4 * element_count_proc(block_number)) && !createTets) ||
1549 (cnt == int64_t(3 * element_count_proc(block_number)) && createTets));
1550 }
1551 }
1552 }
1553
1554 void GeneratedMesh::nodeset_nodes(int64_t id, Ioss::Int64Vector &nodes) const
1555 {
1556 // id is position in nodeset list + 1
1557 assert(id > 0 && (size_t)id <= nodesets.size());
1558 ShellLocation loc = nodesets[id - 1];
1559 nodes.resize(nodeset_node_count_proc(id));
1560
1561 int64_t xp1yp1 = (numX + 1) * (numY + 1);
1562 int64_t k = 0;
1563
1564 switch (loc) {
1565 case MX: // Minimum X Face
1566 for (int64_t i = 0; i < myNumZ + 1; i++) {
1567 int64_t layer_off = myStartZ * xp1yp1 + i * xp1yp1;
1568 for (int64_t j = 0; j < numY + 1; j++) {
1569 nodes[k++] = layer_off + j * (numX + 1) + 1;
1570 }
1571 }
1572 break;
1573 case PX: // Maximum X Face
1574 for (int64_t i = 0; i < myNumZ + 1; i++) {
1575 int64_t layer_off = myStartZ * xp1yp1 + i * xp1yp1;
1576 for (int64_t j = 0; j < numY + 1; j++) {
1577 nodes[k++] = layer_off + j * (numX + 1) + numX + 1;
1578 }
1579 }
1580 break;
1581 case MY: // Minimum Y Face
1582 for (int64_t i = 0; i < myNumZ + 1; i++) {
1583 int64_t layer_off = myStartZ * xp1yp1 + i * xp1yp1;
1584 for (int64_t j = 0; j < numX + 1; j++) {
1585 nodes[k++] = layer_off + j + 1;
1586 }
1587 }
1588 break;
1589 case PY: // Maximum Y Face
1590 for (int64_t i = 0; i < myNumZ + 1; i++) {
1591 int64_t layer_off = myStartZ * xp1yp1 + i * xp1yp1;
1592 for (int64_t j = 0; j < numX + 1; j++) {
1593 nodes[k++] = layer_off + (numX + 1) * (numY) + j + 1;
1594 }
1595 }
1596 break;
1597 case MZ: // Minimum Z Face
1598 if (myProcessor == 0) {
1599 for (int64_t i = 0; i < (numY + 1) * (numX + 1); i++) {
1600 nodes[i] = i + 1;
1601 }
1602 }
1603 break;
1604 case PZ: // Maximum Z Face
1605 if (myProcessor == processorCount - 1) {
1606 int64_t offset = (numY + 1) * (numX + 1) * numZ;
1607 for (int64_t i = 0; i < (numY + 1) * (numX + 1); i++) {
1608 nodes[i] = offset + i + 1;
1609 }
1610 }
1611 break;
1612 }
1613 }
1614
1615 std::string GeneratedMesh::get_sideset_topology() const { return createTets ? "tri3" : "quad4"; }
1616
1617 void GeneratedMesh::sideset_elem_sides(int64_t id, Ioss::Int64Vector &elem_sides) const
1618 {
1619 // id is position in sideset list + 1
1620 assert(id > 0 && (size_t)id <= sidesets.size());
1621 ShellLocation loc = sidesets[id - 1];
1622
1623 // If there is a shell block on this face, then the sideset is
1624 // applied to the shell block; if not, it is applied to the
1625 // underlying hex elements.
1626 bool underlying_shell = false;
1627 int64_t shell_block = 0;
1628 for (size_t i = 0; i < shellBlocks.size(); i++) {
1629 if (shellBlocks[i] == loc) {
1630 underlying_shell = true;
1631 shell_block = i + 2;
1632 break;
1633 }
1634 }
1635
1636 if (underlying_shell) {
1637 // Get ids of shell elements at this location...
1638 element_map(shell_block, elem_sides);
1639
1640 // Insert face_ordinal in between each entry in elem_sides...
1641 // Face will be 0 for all shells...
1642 elem_sides.resize(2 * sideset_side_count_proc(id));
1643 int64_t face_ordinal = 0;
1644 int64_t i = 2 * sideset_side_count_proc(id) - 1;
1645 int64_t j = sideset_side_count_proc(id) - 1;
1646 while (i >= 0) {
1647 elem_sides[i--] = face_ordinal;
1648 elem_sides[i--] = elem_sides[j--];
1649 }
1650 }
1651 else {
1652 element_surface_map(loc, elem_sides);
1653 }
1654 }
1655
1656 Ioss::NameList GeneratedMesh::sideset_touching_blocks(int64_t /*set_id*/) const
1657 {
1658 Ioss::NameList result(1, "block_1");
1659 return result;
1660 }
1661
1662 void GeneratedMesh::set_variable_count(const std::string &type, size_t count)
1663 {
1664 if (type == "global") {
1665 variableCount[Ioss::REGION] = count;
1666 }
1667 else if (type == "element") {
1668 variableCount[Ioss::ELEMENTBLOCK] = count;
1669 }
1670 else if (type == "nodal" || type == "node") {
1671 variableCount[Ioss::NODEBLOCK] = count;
1672 }
1673 else if (type == "nodeset" || type == "nset") {
1674 variableCount[Ioss::NODESET] = count;
1675 }
1676 else if (type == "surface" || type == "sideset" || type == "sset") {
1677 variableCount[Ioss::SIDEBLOCK] = count;
1678 }
1679 else {
1680 IOSS_ERROR(fmt::format(
1681 "ERROR: (Iogn::GeneratedMesh::set_variable_count)\n"
1682 " Unrecognized variable type '{}'. Valid types are:\n"
1683 " global, element, node, nodal, nodeset, nset, surface, sideset, sset.\n",
1684 type));
1685 }
1686 }
1687
1688 void GeneratedMesh::set_rotation(const std::string &axis, double angle_degrees)
1689 {
1690 // PI / 180. Used in converting angle in degrees to radians
1691 static double degang = std::atan2(0.0, -1.0) / 180.0;
1692
1693 doRotation = true;
1694
1695 int n1 = -1;
1696 int n2 = -1;
1697 int n3 = -1;
1698
1699 if (axis == "x" || axis == "X") {
1700 n1 = 1;
1701 n2 = 2;
1702 n3 = 0;
1703 }
1704 else if (axis == "y" || axis == "Y") {
1705 n1 = 2;
1706 n2 = 0;
1707 n3 = 1;
1708 }
1709 else if (axis == "z" || axis == "Z") {
1710 n1 = 0;
1711 n2 = 1;
1712 n3 = 2;
1713 }
1714 else {
1715 fmt::print(Ioss::WarnOut(),
1716 "\nInvalid axis specification '{}'. Valid options are 'x', 'y', or 'z'\n", axis);
1717 return;
1718 }
1719
1720 double ang = angle_degrees * degang; // Convert angle in degrees to radians
1721 double cosang = std::cos(ang);
1722 double sinang = std::sin(ang);
1723
1724 assert(n1 >= 0 && n2 >= 0 && n3 >= 0);
1725 std::array<std::array<double, 3>, 3> by;
1726 by[n1][n1] = cosang;
1727 by[n2][n1] = -sinang;
1728 by[n1][n3] = 0.0;
1729 by[n1][n2] = sinang;
1730 by[n2][n2] = cosang;
1731 by[n2][n3] = 0.0;
1732 by[n3][n1] = 0.0;
1733 by[n3][n2] = 0.0;
1734 by[n3][n3] = 1.0;
1735
1736 std::array<std::array<double, 3>, 3> res;
1737 for (int i = 0; i < 3; i++) {
1738 res[i][0] = rotmat[i][0] * by[0][0] + rotmat[i][1] * by[1][0] + rotmat[i][2] * by[2][0];
1739 res[i][1] = rotmat[i][0] * by[0][1] + rotmat[i][1] * by[1][1] + rotmat[i][2] * by[2][1];
1740 res[i][2] = rotmat[i][0] * by[0][2] + rotmat[i][1] * by[1][2] + rotmat[i][2] * by[2][2];
1741 }
1742 rotmat = res;
1743 }
1744 } // namespace Iogn