9 #include <stk_util/unit_test_support/GeneratedMesh.hpp> 10 #include <stk_util/util/tokenize.hpp> 25 GeneratedMesh::GeneratedMesh(
int num_x,
int num_y,
int num_z,
26 int proc_count,
int my_proc) :
27 numX(num_x), numY(num_y), numZ(num_z), myNumZ(num_z), myStartZ(0),
28 processorCount(proc_count), myProcessor(my_proc),
29 offX(0), offY(0), offZ(0),
30 sclX(1), sclY(1), sclZ(1),
36 GeneratedMesh::GeneratedMesh(
const std::string ¶meters,
37 int proc_count,
int my_proc) :
38 numX(0), numY(0), numZ(0), myNumZ(0), myStartZ(0),
39 processorCount(proc_count), myProcessor(my_proc),
40 offX(0), offY(0), offZ(0),
41 sclX(1), sclY(1), sclZ(1),
44 std::vector<std::string> groups;
45 stk_classic::util::tokenize(parameters,
"|+", groups);
48 std::vector<std::string> tokens;
49 stk_classic::util::tokenize(groups[0],
"x", tokens);
50 assert(tokens.size() == 3);
51 numX = std::strtol(tokens[0].c_str(), NULL, 10);
52 numY = std::strtol(tokens[1].c_str(), NULL, 10);
53 numZ = std::strtol(tokens[2].c_str(), NULL, 10);
56 parse_options(groups);
60 GeneratedMesh::~GeneratedMesh() {}
62 void GeneratedMesh::initialize()
64 assert(numZ >= processorCount);
65 if (processorCount > 1) {
66 myNumZ = numZ / processorCount;
67 if (myProcessor < (numZ % processorCount)) myNumZ++;
70 size_t extra = numZ % processorCount;
71 if (extra > myProcessor)
73 size_t per_proc = numZ / processorCount;
74 myStartZ = myProcessor * per_proc + extra;
79 for (
int i=0; i < 3; i++) {
80 for (
int j=0; j < 3; j++) {
87 size_t GeneratedMesh::add_shell_block(ShellLocation loc)
89 shellBlocks.push_back(loc);
90 return shellBlocks.size();
93 size_t GeneratedMesh::add_nodeset(ShellLocation loc)
95 nodesets.push_back(loc);
96 return nodesets.size();
99 size_t GeneratedMesh::add_sideset(ShellLocation loc)
101 sidesets.push_back(loc);
102 return sidesets.size();
105 void GeneratedMesh::set_bbox(
double xmin,
double ymin,
double zmin,
106 double xmax,
double ymax,
double zmax)
112 double x_range = xmax - xmin;
113 double y_range = ymax - ymin;
114 double z_range = zmax - zmin;
116 sclX = x_range /
static_cast<double>(numX);
117 sclY = y_range /
static_cast<double>(numY);
118 sclZ = z_range /
static_cast<double>(numZ);
125 void GeneratedMesh::set_scale(
double scl_x,
double scl_y,
double scl_z)
132 void GeneratedMesh::set_offset(
double off_x,
double off_y,
double off_z)
139 void GeneratedMesh::parse_options(
const std::vector<std::string> &groups)
141 for (
size_t i=1; i < groups.size(); i++) {
142 std::vector<std::string> option;
143 stk_classic::util::tokenize(groups[i],
":", option);
146 if (option[0] ==
"shell") {
150 size_t length = option[1].size();
151 for (
size_t j=0; j < length; j++) {
152 switch (option[1][j]) {
172 std::cerr <<
"ERROR: Unrecognized shell location option '" 178 else if (option[0] ==
"nodeset") {
182 size_t length = option[1].size();
183 for (
size_t j=0; j < length; j++) {
184 switch (option[1][j]) {
204 std::cerr <<
"ERROR: Unrecognized nodeset location option '" 210 else if (option[0] ==
"sideset") {
214 size_t length = option[1].size();
215 for (
size_t j=0; j < length; j++) {
216 switch (option[1][j]) {
236 std::cerr <<
"ERROR: Unrecognized sideset location option '" 242 else if (option[0] ==
"scale") {
244 std::vector<std::string> tokens;
245 stk_classic::util::tokenize(option[1],
",", tokens);
246 assert(tokens.size() == 3);
247 sclX = std::strtod(tokens[0].c_str(), NULL);
248 sclY = std::strtod(tokens[1].c_str(), NULL);
249 sclZ = std::strtod(tokens[2].c_str(), NULL);
252 else if (option[0] ==
"offset") {
254 std::vector<std::string> tokens;
255 stk_classic::util::tokenize(option[1],
",", tokens);
256 assert(tokens.size() == 3);
257 offX = std::strtod(tokens[0].c_str(), NULL);
258 offY = std::strtod(tokens[1].c_str(), NULL);
259 offZ = std::strtod(tokens[2].c_str(), NULL);
262 else if (option[0] ==
"zdecomp") {
268 std::vector<std::string> tokens;
269 stk_classic::util::tokenize(option[1],
",", tokens);
270 assert(tokens.size() == processorCount);
271 std::vector<size_t> Zs;
273 for (
size_t j = 0; j < processorCount; j++) {
274 Zs.push_back(std::strtol(tokens[j].c_str(), NULL, 10));
277 myNumZ = Zs[myProcessor];
279 for (
size_t j=0; j < myProcessor; j++) {
284 else if (option[0] ==
"bbox") {
286 std::vector<std::string> tokens;
287 stk_classic::util::tokenize(option[1],
",", tokens);
288 assert(tokens.size() == 6);
289 double xmin = std::strtod(tokens[0].c_str(), NULL);
290 double ymin = std::strtod(tokens[1].c_str(), NULL);
291 double zmin = std::strtod(tokens[2].c_str(), NULL);
292 double xmax = std::strtod(tokens[3].c_str(), NULL);
293 double ymax = std::strtod(tokens[4].c_str(), NULL);
294 double zmax = std::strtod(tokens[5].c_str(), NULL);
296 set_bbox(xmin, ymin, zmin, xmax, ymax, zmax);
299 else if (option[0] ==
"rotate") {
301 std::vector<std::string> tokens;
302 stk_classic::util::tokenize(option[1],
",", tokens);
303 assert(tokens.size() %2 == 0);
304 for (
size_t ir=0; ir < tokens.size();) {
305 std::string axis = tokens[ir++];
306 double angle_degree = std::strtod(tokens[ir++].c_str(), NULL);
307 set_rotation(axis, angle_degree);
311 else if (option[0] ==
"help") {
312 std::cerr <<
"\nValid Options for GeneratedMesh parameter string:\n" 313 <<
"\tIxJxK -- specifies intervals; must be first option. Ex: 4x10x12\n" 314 <<
"\toffset:xoff, yoff, zoff\n" 315 <<
"\tscale: xscl, yscl, zscl\n" 316 <<
"\tzdecomp:n1,n2,n3,...,n#proc\n" 317 <<
"\tbbox: xmin, ymin, zmin, xmax, ymax, zmax\n" 318 <<
"\trotate: axis,angle,axis,angle,...\n" 319 <<
"\tshell:xXyYzZ (specifies which plane to apply shell)\n" 320 <<
"\tnodeset:xXyXzZ (specifies which plane to apply nodeset)\n" 321 <<
"\tsideset:xXyXzZ (specifies which plane to apply sideset)\n" 322 <<
"\tshow -- show mesh parameters\n" 323 <<
"\thelp -- show this list\n\n";
326 else if (option[0] ==
"show") {
331 std::cerr <<
"ERROR: Unrecognized option '" << option[0]
332 <<
"'. It will be ignored.\n";
337 void GeneratedMesh::show_parameters()
const 339 if (myProcessor == 0) {
340 std::cerr <<
"\nMesh Parameters:\n" 341 <<
"\tIntervals: " << numX <<
" by " << numY <<
" by " << numZ <<
"\n" 342 <<
"\tX = " << sclX <<
" * (0.." << numX <<
") + " << offX
343 <<
"\tRange: " << offX <<
" <= X <= " << offX + numX * sclX <<
"\n" 344 <<
"\tY = " << sclY <<
" * (0.." << numY <<
") + " << offY
345 <<
"\tRange: " << offY <<
" <= Y <= " << offY + numY * sclY <<
"\n" 346 <<
"\tZ = " << sclZ <<
" * (0.." << numZ <<
") + " << offZ
347 <<
"\tRange: " << offZ <<
" <= Z <= " << offZ + numZ * sclZ <<
"\n\n" 348 <<
"\tNode Count (total) = " <<
std::setw(9) << node_count() <<
"\n" 349 <<
"\tElement Count (total) = " <<
std::setw(9) << element_count() <<
"\n" 350 <<
"\tBlock Count = " <<
std::setw(9) << block_count() <<
"\n" 351 <<
"\tNodeset Count = " <<
std::setw(9) << nodeset_count() <<
"\n" 352 <<
"\tSideset Count = " <<
std::setw(9) << sideset_count() <<
"\n\n";
354 std::cerr <<
"\tRotation Matrix: \n\t" << std::scientific ;
355 for (
int ii=0; ii < 3; ii++) {
356 for (
int jj=0; jj < 3; jj++) {
357 std::cerr <<
std::setw(14) << rotmat[ii][jj] <<
"\t";
361 std::cerr << std::fixed <<
"\n";
366 size_t GeneratedMesh::node_count()
const 368 return (numX+1) * (numY+1) * (numZ+1);
371 size_t GeneratedMesh::node_count_proc()
const 373 return (numX+1) * (numY+1) * (myNumZ+1);
376 size_t GeneratedMesh::block_count()
const 378 return shellBlocks.size() + 1;
381 size_t GeneratedMesh::nodeset_count()
const 383 return nodesets.size();
386 size_t GeneratedMesh::sideset_count()
const 388 return sidesets.size();
391 size_t GeneratedMesh::element_count()
const 393 size_t count = element_count(1);
394 for (
size_t i=0; i < shellBlocks.size(); i++) {
395 count += element_count(i+2);
400 size_t GeneratedMesh::element_count_proc()
const 403 for (
size_t i=0; i < block_count(); i++) {
404 count += element_count_proc(i+1);
409 size_t GeneratedMesh::element_count(
size_t block_number)
const 411 assert(block_number <= block_count());
413 if (block_number == 1) {
414 return numX * numY * numZ;
416 ShellLocation loc = shellBlocks[block_number-2];
417 return shell_element_count(loc);
421 size_t GeneratedMesh::shell_element_count(ShellLocation loc)
const 437 size_t GeneratedMesh::element_count_proc(
size_t block_number)
const 439 assert(block_number <= block_count());
441 if (block_number == 1) {
442 return numX * numY * myNumZ;
444 ShellLocation loc = shellBlocks[block_number-2];
445 return shell_element_count_proc(loc);
449 size_t GeneratedMesh::shell_element_count_proc(ShellLocation loc)
const 454 return numY * myNumZ;
457 return numX * myNumZ;
459 if (myProcessor == 0)
464 if (myProcessor == processorCount -1)
472 size_t GeneratedMesh::nodeset_node_count(
size_t id)
const 475 assert(
id > 0 &&
id <= nodesets.size());
476 ShellLocation loc = nodesets[
id-1];
480 return (numY+1) * (numZ+1);
483 return (numX+1) * (numZ+1);
486 return (numX+1) * (numY+1);
491 size_t GeneratedMesh::nodeset_node_count_proc(
size_t id)
const 494 assert(
id > 0 &&
id <= nodesets.size());
495 ShellLocation loc = nodesets[
id-1];
499 return (numY+1) * (myNumZ+1);
502 return (numX+1) * (myNumZ+1);
504 if (myProcessor == 0)
505 return (numX+1) * (numY+1);
509 if (myProcessor == processorCount -1)
510 return (numX+1) * (numY+1);
517 size_t GeneratedMesh::sideset_side_count(
size_t id)
const 520 assert(
id > 0 &&
id <= sidesets.size());
521 ShellLocation loc = sidesets[
id-1];
536 size_t GeneratedMesh::sideset_side_count_proc(
size_t id)
const 539 assert(
id > 0 &&
id <= sidesets.size());
540 ShellLocation loc = sidesets[
id-1];
544 return numY * myNumZ;
547 return numX * myNumZ;
549 if (myProcessor == 0)
554 if (myProcessor == processorCount -1)
562 std::pair<std::string,int> GeneratedMesh::topology_type(
size_t block_number)
const 564 assert(block_number <= block_count() && block_number > 0);
566 if (block_number == 1) {
567 return std::make_pair(std::string(
"hex8"), 8);
569 return std::make_pair(std::string(
"shell4"), 4);
573 void GeneratedMesh::node_map(std::vector<int> &map)
575 size_t count = node_count_proc();
577 size_t offset = myStartZ * (numX+1) * (numY+1);
578 for (
size_t i=0; i <
count; i++) {
579 map[i] =
static_cast<int>(offset + i + 1);
583 size_t GeneratedMesh::communication_node_count_proc()
const 585 size_t count = (numX+1) * (numY+1);
586 if (myProcessor != 0 && myProcessor != processorCount-1)
592 void GeneratedMesh::node_communication_map(std::vector<int> &map, std::vector<int> &proc)
594 size_t count = (numX+1) * (numY+1);
596 if (myProcessor != 0 && myProcessor != processorCount-1)
602 if (myProcessor != 0) {
603 size_t offset = myStartZ * (numX+1) * (numY+1);
604 for (
size_t i=0; i < slab; i++) {
605 map[j] =
static_cast<int>(offset + i + 1);
606 proc[j++] =
static_cast<int>(myProcessor-1);
609 if (myProcessor != processorCount-1) {
610 size_t offset = (myStartZ + myNumZ) * (numX+1) * (numY+1);
611 for (
size_t i=0; i < slab; i++) {
612 map[j] =
static_cast<int>(offset + i + 1);
613 proc[j++] =
static_cast<int>(myProcessor+1);
618 void GeneratedMesh::element_map(
size_t block_number, std::vector<int> &map)
const 620 assert(block_number <= block_count() && block_number > 0);
622 size_t count = element_count_proc(block_number);
625 if (block_number == 1) {
627 count = element_count_proc(1);
628 size_t offset = myStartZ * numX * numY;
629 for (
size_t i=0; i <
count; i++) {
630 map[i] =
static_cast<int>(offset + i + 1);
633 size_t start = element_count(1);
636 for (
size_t ib=0; ib < shellBlocks.size(); ib++) {
637 count = element_count_proc(ib+2);
638 if (static_cast<size_t>(block_number) == ib + 2) {
640 ShellLocation loc = shellBlocks[ib];
645 offset = myStartZ * numY;
650 offset = myStartZ * numX;
658 for (
size_t i=0; i <
count; i++) {
659 map[i] =
static_cast<int>(start + offset + i + 1);
662 start += element_count(ib+2);
668 void GeneratedMesh::element_map(std::vector<int> &map)
const 670 size_t count = element_count_proc();
675 count = element_count_proc(1);
676 size_t offset = myStartZ * numX * numY;
677 for (
size_t i=0; i <
count; i++) {
678 map[k++] =
static_cast<int>(offset + i + 1);
681 size_t start = element_count(1);
684 for (
size_t ib=0; ib < shellBlocks.size(); ib++) {
685 count = element_count_proc(ib+2);
687 ShellLocation loc = shellBlocks[ib];
692 offset = myStartZ * numY;
697 offset = myStartZ * numX;
705 for (
size_t i=0; i <
count; i++) {
706 map[k++] =
static_cast<int>(start + offset + i + 1);
708 start += element_count(ib+2);
712 void GeneratedMesh::element_surface_map(ShellLocation loc, std::vector<int> &map)
const 714 size_t count = shell_element_count_proc(loc);
722 offset = myStartZ * numX * numY + 1;
723 for (
size_t k = 0; k < myNumZ; ++k) {
724 for (
size_t j = 0; j < numY; ++j) {
725 map[index++] = offset;
733 offset = myStartZ * numX * numY + numX;
734 for (
size_t k = 0; k < myNumZ; ++k) {
735 for (
size_t j = 0; j < numY; ++j) {
736 map[index++] = offset;
744 offset = myStartZ * numX * numY + 1;
745 for (
size_t k = 0; k < myNumZ; ++k) {
746 for (
size_t i = 0; i < numX; ++i) {
747 map[index++] = offset++;
750 offset+= numX * (numY-1);
755 offset = myStartZ * numX * numY + numX * (numY-1) +1;
756 for (
size_t k = 0; k < myNumZ; ++k) {
757 for (
size_t i = 0; i < numX; ++i) {
758 map[index++] = offset++;
761 offset+= numX * (numY-1);
766 if (myProcessor == 0) {
768 for (
size_t i=0; i < numY; i++) {
769 for (
size_t j=0; j < numX; j++) {
770 map[index++] = offset++;
778 if (myProcessor == processorCount-1) {
779 offset = (numZ-1)*numX*numY + 1;
780 for (
size_t i=0, k=0; i < numY; i++) {
781 for (
size_t j=0; j < numX; j++, k++) {
782 map[index++] = offset++;
791 void GeneratedMesh::coordinates(std::vector<double> &coord)
const 794 size_t count = node_count_proc();
795 coord.resize(count * 3);
798 for (
size_t m=myStartZ; m < myStartZ+myNumZ+1; m++) {
799 for (
size_t i=0; i < numY+1; i++) {
800 for (
size_t j=0; j < numX+1; j++) {
801 coord[k++] = sclX *
static_cast<double>(j) + offX;
802 coord[k++] = sclY *
static_cast<double>(i) + offY;
803 coord[k++] = sclZ *
static_cast<double>(m) + offZ;
809 for (
size_t i=0; i <
count*3; i+=3) {
810 double xn = coord[i+0];
811 double yn = coord[i+1];
812 double zn = coord[i+2];
813 coord[i+0] = xn * rotmat[0][0] + yn * rotmat[1][0] + zn * rotmat[2][0];
814 coord[i+1] = xn * rotmat[0][1] + yn * rotmat[1][1] + zn * rotmat[2][1];
815 coord[i+2] = xn * rotmat[0][2] + yn * rotmat[1][2] + zn * rotmat[2][2];
820 void GeneratedMesh::coordinates(std::vector<double> &x,
821 std::vector<double> &y,
822 std::vector<double> &z)
const 825 size_t count = node_count_proc();
831 for (
size_t m=myStartZ; m < myStartZ+myNumZ+1; m++) {
832 for (
size_t i=0; i < numY+1; i++) {
833 for (
size_t j=0; j < numX+1; j++) {
834 x[k] = sclX *
static_cast<double>(j) + offX;
835 y[k] = sclY *
static_cast<double>(i) + offY;
836 z[k] = sclZ *
static_cast<double>(m) + offZ;
842 for (
size_t i=0; i <
count; i++) {
846 x[i] = xn * rotmat[0][0] + yn * rotmat[1][0] + zn * rotmat[2][0];
847 y[i] = xn * rotmat[0][1] + yn * rotmat[1][1] + zn * rotmat[2][1];
848 z[i] = xn * rotmat[0][2] + yn * rotmat[1][2] + zn * rotmat[2][2];
853 void GeneratedMesh::connectivity(
size_t block_number, std::vector<int> &connect)
const 855 assert(block_number <= block_count());
857 size_t xp1yp1 = (numX+1) * (numY+1);
860 if (block_number == 1) {
861 connect.resize(element_count_proc(block_number)*8);
864 for (
size_t m=myStartZ; m < myNumZ+myStartZ; m++) {
865 for (
size_t i=0, k=0; i < numY; i++) {
866 for (
size_t j=0; j < numX; j++, k++) {
867 size_t base = (m*xp1yp1) + k + i + 1;
869 connect[cnt++] =
static_cast<int>(base);
870 connect[cnt++] =
static_cast<int>(base+1);
871 connect[cnt++] =
static_cast<int>(base+numX+2);
872 connect[cnt++] =
static_cast<int>(base+numX+1);
874 connect[cnt++] =
static_cast<int>(xp1yp1 + base);
875 connect[cnt++] =
static_cast<int>(xp1yp1 + base+1);
876 connect[cnt++] =
static_cast<int>(xp1yp1 + base+numX+2);
877 connect[cnt++] =
static_cast<int>(xp1yp1 + base+numX+1);
882 ShellLocation loc = shellBlocks[block_number-2];
883 connect.resize(element_count_proc(block_number)*4);
888 for (
size_t i=0; i < myNumZ; i++) {
889 size_t layer_off = i * xp1yp1;
890 for (
size_t j=0; j < numY; j++) {
891 size_t base = layer_off + j * (numX+1) + 1 + myStartZ * xp1yp1;
892 connect[cnt++] =
static_cast<int>(base);
893 connect[cnt++] =
static_cast<int>(base + xp1yp1);
894 connect[cnt++] =
static_cast<int>(base + xp1yp1 + (numX+1));
895 connect[cnt++] =
static_cast<int>(base + (numX+1));
900 for (
size_t i=0; i < myNumZ; i++) {
901 size_t layer_off = i * xp1yp1;
902 for (
size_t j=0; j < numY; j++) {
903 size_t base = layer_off + j * (numX+1) + numX + 1 + myStartZ * xp1yp1;
904 connect[cnt++] =
static_cast<int>(base);
905 connect[cnt++] =
static_cast<int>(base + (numX+1));
906 connect[cnt++] =
static_cast<int>(base + xp1yp1 + (numX+1));
907 connect[cnt++] =
static_cast<int>(base + xp1yp1);
912 for (
size_t i=0; i < myNumZ; i++) {
913 size_t layer_off = i * xp1yp1;
914 for (
size_t j=0; j < numX; j++) {
915 size_t base = layer_off + j + 1 + myStartZ * xp1yp1;
916 connect[cnt++] =
static_cast<int>(base);
917 connect[cnt++] =
static_cast<int>(base + 1);
918 connect[cnt++] =
static_cast<int>(base + xp1yp1 + 1);
919 connect[cnt++] =
static_cast<int>(base + xp1yp1);
924 for (
size_t i=0; i < myNumZ; i++) {
925 size_t layer_off = i * xp1yp1;
926 for (
size_t j=0; j < numX; j++) {
927 size_t base = layer_off + (numX+1)*(numY) + j + 1 + myStartZ * xp1yp1;
928 connect[cnt++] =
static_cast<int>(base);
929 connect[cnt++] =
static_cast<int>(base + xp1yp1);
930 connect[cnt++] =
static_cast<int>(base + xp1yp1 + 1);
931 connect[cnt++] =
static_cast<int>(base + 1);
936 if (myProcessor == 0) {
937 for (
size_t i=0, k=0; i < numY; i++) {
938 for (
size_t j=0; j < numX; j++, k++) {
939 size_t base = i + k + 1 + myStartZ * xp1yp1;
940 connect[cnt++] =
static_cast<int>(base);
941 connect[cnt++] =
static_cast<int>(base+numX+1);
942 connect[cnt++] =
static_cast<int>(base+numX+2);
943 connect[cnt++] =
static_cast<int>(base+1);
949 if (myProcessor == processorCount-1) {
950 for (
size_t i=0, k=0; i < numY; i++) {
951 for (
size_t j=0; j < numX; j++, k++) {
952 size_t base = xp1yp1 * (numZ - myStartZ) + k + i + 1 + myStartZ * xp1yp1;
953 connect[cnt++] =
static_cast<int>(base);
954 connect[cnt++] =
static_cast<int>(base+1);
955 connect[cnt++] =
static_cast<int>(base+numX+2);
956 connect[cnt++] =
static_cast<int>(base+numX+1);
962 assert(cnt == 4 * element_count_proc(block_number));
967 void GeneratedMesh::nodeset_nodes(
size_t id, std::vector<int> &nodes)
const 970 assert(
id > 0 &&
id <= nodesets.size());
971 ShellLocation loc = nodesets[
id-1];
972 nodes.resize(nodeset_node_count_proc(
id));
974 size_t xp1yp1 = (numX+1) * (numY+1);
979 for (
size_t i=0; i < myNumZ+1; i++) {
980 size_t layer_off = myStartZ * xp1yp1 + i * xp1yp1;
981 for (
size_t j=0; j < numY+1; j++) {
982 nodes[k++] = layer_off + j * (numX+1) + 1;
987 for (
size_t i=0; i < myNumZ+1; i++) {
988 size_t layer_off = myStartZ * xp1yp1 + i * xp1yp1;
989 for (
size_t j=0; j < numY+1; j++) {
990 nodes[k++] = layer_off + j * (numX+1) + numX + 1;
995 for (
size_t i=0; i < myNumZ+1; i++) {
996 size_t layer_off = myStartZ * xp1yp1 + i * xp1yp1;
997 for (
size_t j=0; j < numX+1; j++) {
998 nodes[k++] = layer_off + j + 1;
1003 for (
size_t i=0; i < myNumZ+1; i++) {
1004 size_t layer_off = myStartZ * xp1yp1 + i * xp1yp1;
1005 for (
size_t j=0; j < numX+1; j++) {
1006 nodes[k++] = layer_off + (numX+1)*(numY) + j + 1;
1011 if (myProcessor == 0) {
1012 for (
size_t i=0; i < (numY+1) * (numX+1); i++) {
1018 if (myProcessor == processorCount-1) {
1019 size_t offset = (numY+1) * (numX+1) * numZ;
1020 for (
size_t i=0; i < (numY+1) * (numX+1); i++) {
1021 nodes[i] = offset + i+1;
1028 void GeneratedMesh::sideset_elem_sides(
size_t id, std::vector<int> &elem_sides)
const 1031 assert(
id > 0 &&
id <= sidesets.size());
1032 ShellLocation loc = sidesets[
id-1];
1037 bool underlying_shell =
false;
1038 size_t shell_block = 0;
1039 for (
size_t i = 0; i < shellBlocks.size(); i++) {
1040 if (shellBlocks[i] == loc) {
1041 underlying_shell =
true;
1047 if (underlying_shell) {
1049 element_map(shell_block, elem_sides);
1053 elem_sides.resize(2*sideset_side_count_proc(
id));
1054 int face_ordinal = 0;
1055 int i = 2* (int)sideset_side_count_proc(
id) - 1;
1056 int j = (int)sideset_side_count_proc(
id) - 1;
1058 elem_sides[i--] = face_ordinal;
1059 elem_sides[i--] = elem_sides[j--];
1062 element_surface_map(loc, elem_sides);
1066 void GeneratedMesh::set_rotation(
const std::string &axis,
double angle_degrees)
1069 static double degang = std::atan2(0.0, -1.0) / 180.0;
1077 if (axis ==
"x" || axis ==
"X") {
1078 n1 = 1; n2 = 2; n3 = 0;
1079 }
else if (axis ==
"y" || axis ==
"Y") {
1080 n1 = 2; n2 = 0; n3 = 1;
1081 }
else if (axis ==
"z" || axis ==
"Z") {
1082 n1 = 0; n2 = 1; n3 = 2;
1084 std::cerr <<
"\nInvalid axis specification '" << axis <<
"'. Valid options are 'x', 'y', or 'z'\n";
1088 double ang = angle_degrees * degang;
1089 double cosang = std::cos(ang);
1090 double sinang = std::sin(ang);
1092 assert(n1 >= 0 && n2 >= 0 && n3 >= 0);
1094 by[n1][n1] = cosang;
1095 by[n2][n1] = -sinang;
1097 by[n1][n2] = sinang;
1098 by[n2][n2] = cosang;
1105 for (
size_t i=0; i < 3; i++) {
1106 res[i][0] = rotmat[i][0]*by[0][0] + rotmat[i][1]*by[1][0] + rotmat[i][2]*by[2][0];
1107 res[i][1] = rotmat[i][0]*by[0][1] + rotmat[i][1]*by[1][1] + rotmat[i][2]*by[2][1];
1108 res[i][2] = rotmat[i][0]*by[0][2] + rotmat[i][1]*by[1][2] + rotmat[i][2]*by[2][2];
1112 std::memcpy(rotmat, res, 9*
sizeof(
double));
1114 for (
int i=0; i < 3; i++) {
1115 for (
int j=0; j < 3; j++) {
1116 rotmat[i][j] = res[i][j];
1127 std::string ToString(
size_t t) {
1128 std::ostringstream os;
1133 #include <exodusII.h> 1136 int num_processors = 8;
1137 for (
int proc = 0; proc < num_processors; proc++) {
1139 stk_classic::GeneratedMesh mesh(100, 125, 10*num_processors, num_processors, proc);
1141 std::cerr <<
"Node Count (total) = " << mesh.node_count() <<
"\n";
1142 std::cerr <<
"Node Count (proc) = " << mesh.node_count_proc() <<
"\n";
1143 std::cerr <<
"Element Count (total) = " << mesh.element_count() <<
"\n";
1144 std::cerr <<
"Element Count (proc) = " << mesh.element_count_proc() <<
"\n";
1145 std::cerr <<
"Block Count = " << mesh.block_count() <<
"\n";
1147 int CPU_word_size = 8;
1148 int IO_word_size = 8;
1149 std::string name =
"test-scale.e";
1150 if (num_processors > 1) {
1151 name +=
"." + ToString(num_processors) +
"." + ToString(proc);
1153 int exoid = ex_create (name.c_str(), EX_CLOBBER, &CPU_word_size, &IO_word_size);
1155 int num_nodes = mesh.node_count_proc();
1156 int num_elems = mesh.element_count_proc();
1157 int num_elem_blk = mesh.block_count();
1158 int error = ex_put_init (exoid,
"title", 3, num_nodes, num_elems,
1159 num_elem_blk, 0, 0);
1161 if (num_processors > 1) {
1162 std::vector<int> nodes;
1163 std::vector<int> procs;
1164 mesh.node_communication_map(nodes, procs);
1166 int node_map_ids[1] = {1};
1167 int node_map_node_cnts[1] = {procs.size()};
1168 ex_put_init_info(exoid, num_processors, 1,
"p");
1169 ex_put_loadbal_param(exoid, 0, 0, 0, 0, 0, 1, 0, proc);
1170 ex_put_cmap_params(exoid, node_map_ids, node_map_node_cnts, 0, 0, proc);
1171 ex_put_node_cmap(exoid, 1, &nodes[0], &procs[0], proc);
1174 for (
int i=1; i < mesh.block_count(); i++) {
1175 std::cerr <<
"Block " << i+1 <<
" has " << mesh.element_count_proc(i+1) <<
" " 1176 << mesh.topology_type(i+1).first <<
" elements\n";
1178 std::string btype = mesh.topology_type(i+1).first;
1179 error = ex_put_elem_block(exoid, i+1, btype.c_str(),
1180 mesh.element_count_proc(i+1),
1181 mesh.topology_type(i+1).second, 0);
1184 std::cerr <<
"Block " << 1 <<
" has " << mesh.element_count_proc(1) <<
" " 1185 << mesh.topology_type(1).first <<
" elements\n";
1187 std::string btype = mesh.topology_type(1).first;
1188 error = ex_put_elem_block(exoid, 1, btype.c_str(),
1189 mesh.element_count_proc(1),
1190 mesh.topology_type(1).second, 0);
1193 if (num_processors > 1) {
1194 std::vector<int> map;
1196 ex_put_id_map(exoid, EX_NODE_MAP, &map[0]);
1198 mesh.element_map(map);
1199 ex_put_id_map(exoid, EX_ELEM_MAP, &map[0]);
1202 std::cerr <<
"Outputting connectivity...\n";
1203 for (
int i=1; i < mesh.block_count(); i++) {
1204 if (mesh.element_count_proc(i+1) > 0) {
1205 std::vector<int> connectivity;
1206 mesh.connectivity(i+1, connectivity);
1207 ex_put_elem_conn(exoid, i+1, &connectivity[0]);
1211 std::vector<int> connectivity;
1212 mesh.connectivity(1, connectivity);
1213 ex_put_elem_conn(exoid, 1, &connectivity[0]);
1217 std::vector<double> x;
1218 std::vector<double> y;
1219 std::vector<double> z;
1220 mesh.coordinates(x, y, z);
1221 error = ex_put_coord (exoid, &x[0], &y[0], &z[0]);
_setw setw(int width)
Function setw sets the width for the next field as a manipulator.
eastl::iterator_traits< InputIterator >::difference_type count(InputIterator first, InputIterator last, const T &value)