306 START_LOG(
"build_cube()",
"MeshTools::Generation");
315 using namespace MeshTools::Generation::Private;
320 BoundaryInfo & boundary_info =
mesh.get_boundary_info();
324 mesh.set_mesh_dimension(3);
325 mesh.set_spatial_dimension(3);
329 mesh.set_mesh_dimension(2);
330 mesh.set_spatial_dimension(2);
334 mesh.set_mesh_dimension(1);
335 mesh.set_spatial_dimension(1);
340 mesh.set_mesh_dimension(0);
341 mesh.set_spatial_dimension(0);
344 switch (
mesh.mesh_dimension())
350 libmesh_assert_equal_to (nx, 0);
351 libmesh_assert_equal_to (ny, 0);
352 libmesh_assert_equal_to (nz, 0);
357 mesh.add_point (Point(0, 0, 0), 0);
358 Elem * elem =
mesh.add_elem (
new NodeElem);
359 elem->set_node(0) =
mesh.node_ptr(0);
370 libmesh_assert_not_equal_to (nx, 0);
371 libmesh_assert_equal_to (ny, 0);
372 libmesh_assert_equal_to (nz, 0);
373 libmesh_assert_less (xmin, xmax);
383 mesh.reserve_elem (nx);
388 libmesh_error_msg(
"ERROR: Unrecognized 1D element type.");
397 mesh.reserve_nodes(nx+1);
403 mesh.reserve_nodes(2*nx+1);
409 mesh.reserve_nodes(3*nx+1);
414 libmesh_error_msg(
"ERROR: Unrecognized 1D element type.");
420 unsigned int node_id = 0;
426 for (
unsigned int i=0; i<=nx; i++)
427 mesh.add_point (Point(static_cast<Real>(i)/nx, 0, 0), node_id++);
434 for (
unsigned int i=0; i<=2*nx; i++)
435 mesh.add_point (Point(static_cast<Real>(i)/(2*nx), 0, 0), node_id++);
441 for (
unsigned int i=0; i<=3*nx; i++)
442 mesh.add_point (Point(static_cast<Real>(i)/(3*nx), 0, 0), node_id++);
448 libmesh_error_msg(
"ERROR: Unrecognized 1D element type.");
458 for (
unsigned int i=0; i<nx; i++)
460 Elem * elem =
new Edge2;
462 elem =
mesh.add_elem (elem);
463 elem->set_node(0) =
mesh.node_ptr(i);
464 elem->set_node(1) =
mesh.node_ptr(i+1);
467 boundary_info.add_side(elem, 0, 0);
470 boundary_info.add_side(elem, 1, 1);
477 for (
unsigned int i=0; i<nx; i++)
479 Elem * elem =
new Edge3;
481 elem =
mesh.add_elem (elem);
482 elem->set_node(0) =
mesh.node_ptr(2*i);
483 elem->set_node(2) =
mesh.node_ptr(2*i+1);
484 elem->set_node(1) =
mesh.node_ptr(2*i+2);
487 boundary_info.add_side(elem, 0, 0);
490 boundary_info.add_side(elem, 1, 1);
497 for (
unsigned int i=0; i<nx; i++)
499 Elem * elem =
new Edge4;
501 elem =
mesh.add_elem (elem);
502 elem->set_node(0) =
mesh.node_ptr(3*i);
503 elem->set_node(2) =
mesh.node_ptr(3*i+1);
504 elem->set_node(3) =
mesh.node_ptr(3*i+2);
505 elem->set_node(1) =
mesh.node_ptr(3*i+3);
508 boundary_info.add_side(elem, 0, 0);
511 boundary_info.add_side(elem, 1, 1);
517 libmesh_error_msg(
"ERROR: Unrecognized 1D element type.");
521 if (gauss_lobatto_grid)
523 GaussLobattoRedistributionFunction func(nx, xmin, xmax);
528 for (
unsigned int p=0; p<
mesh.n_nodes(); p++)
529 mesh.node_ref(p)(0) = (
mesh.node_ref(p)(0))*(xmax-xmin) + xmin;
533 boundary_info.sideset_name(0) =
"left";
534 boundary_info.sideset_name(1) =
"right";
537 boundary_info.nodeset_name(0) =
"left";
538 boundary_info.nodeset_name(1) =
"right";
556 libmesh_assert_not_equal_to (nx, 0);
557 libmesh_assert_not_equal_to (ny, 0);
558 libmesh_assert_equal_to (nz, 0);
559 libmesh_assert_less (xmin, xmax);
560 libmesh_assert_less (ymin, ymax);
571 mesh.reserve_elem (nx*ny);
578 mesh.reserve_elem (2*nx*ny);
583 libmesh_error_msg(
"ERROR: Unrecognized 2D element type.");
596 mesh.reserve_nodes( (nx+1)*(ny+1) );
604 mesh.reserve_nodes( (2*nx+1)*(2*ny+1) );
610 libmesh_error_msg(
"ERROR: Unrecognized 2D element type.");
618 unsigned int node_id = 0;
625 for (
unsigned int j=0; j<=ny; j++)
626 for (
unsigned int i=0; i<=nx; i++)
627 mesh.add_point (Point(static_cast<Real>(i)/static_cast<Real>(nx),
628 static_cast<Real>(j)/static_cast<Real>(ny),
638 for (
unsigned int j=0; j<=(2*ny); j++)
639 for (
unsigned int i=0; i<=(2*nx); i++)
640 mesh.add_point (Point(static_cast<Real>(i)/static_cast<Real>(2*nx),
641 static_cast<Real>(j)/static_cast<Real>(2*ny),
649 libmesh_error_msg(
"ERROR: Unrecognized 2D element type.");
658 unsigned int elem_id = 0;
665 for (
unsigned int j=0; j<ny; j++)
666 for (
unsigned int i=0; i<nx; i++)
668 Elem * elem =
new Quad4;
669 elem->set_id(elem_id++);
670 elem =
mesh.add_elem (elem);
672 elem->set_node(0) =
mesh.node_ptr(
idx(type,nx,i,j) );
673 elem->set_node(1) =
mesh.node_ptr(
idx(type,nx,i+1,j) );
674 elem->set_node(2) =
mesh.node_ptr(
idx(type,nx,i+1,j+1));
675 elem->set_node(3) =
mesh.node_ptr(
idx(type,nx,i,j+1) );
678 boundary_info.add_side(elem, 0, 0);
681 boundary_info.add_side(elem, 2, 2);
684 boundary_info.add_side(elem, 3, 3);
687 boundary_info.add_side(elem, 1, 1);
695 for (
unsigned int j=0; j<ny; j++)
696 for (
unsigned int i=0; i<nx; i++)
699 Elem * elem =
new Tri3;
700 elem->set_id(elem_id++);
701 elem =
mesh.add_elem (elem);
703 elem->set_node(0) =
mesh.node_ptr(
idx(type,nx,i,j) );
704 elem->set_node(1) =
mesh.node_ptr(
idx(type,nx,i+1,j) );
705 elem->set_node(2) =
mesh.node_ptr(
idx(type,nx,i+1,j+1));
708 boundary_info.add_side(elem, 0, 0);
711 boundary_info.add_side(elem, 1, 1);
715 elem->set_id(elem_id++);
716 elem =
mesh.add_elem (elem);
718 elem->set_node(0) =
mesh.node_ptr(
idx(type,nx,i,j) );
719 elem->set_node(1) =
mesh.node_ptr(
idx(type,nx,i+1,j+1));
720 elem->set_node(2) =
mesh.node_ptr(
idx(type,nx,i,j+1) );
723 boundary_info.add_side(elem, 1, 2);
726 boundary_info.add_side(elem, 2, 3);
736 for (
unsigned int j=0; j<(2*ny); j += 2)
737 for (
unsigned int i=0; i<(2*nx); i += 2)
739 Elem * elem = (type ==
QUAD8) ?
740 static_cast<Elem *>(
new Quad8) :
741 static_cast<Elem *
>(
new Quad9);
742 elem->set_id(elem_id++);
743 elem =
mesh.add_elem (elem);
745 elem->set_node(0) =
mesh.node_ptr(
idx(type,nx,i,j) );
746 elem->set_node(1) =
mesh.node_ptr(
idx(type,nx,i+2,j) );
747 elem->set_node(2) =
mesh.node_ptr(
idx(type,nx,i+2,j+2));
748 elem->set_node(3) =
mesh.node_ptr(
idx(type,nx,i,j+2) );
749 elem->set_node(4) =
mesh.node_ptr(
idx(type,nx,i+1,j) );
750 elem->set_node(5) =
mesh.node_ptr(
idx(type,nx,i+2,j+1));
751 elem->set_node(6) =
mesh.node_ptr(
idx(type,nx,i+1,j+2));
752 elem->set_node(7) =
mesh.node_ptr(
idx(type,nx,i,j+1) );
754 elem->set_node(8) =
mesh.node_ptr(
idx(type,nx,i+1,j+1));
758 boundary_info.add_side(elem, 0, 0);
761 boundary_info.add_side(elem, 2, 2);
764 boundary_info.add_side(elem, 3, 3);
767 boundary_info.add_side(elem, 1, 1);
775 for (
unsigned int j=0; j<(2*ny); j += 2)
776 for (
unsigned int i=0; i<(2*nx); i += 2)
779 Elem * elem =
new Tri6;
780 elem->set_id(elem_id++);
781 elem =
mesh.add_elem (elem);
783 elem->set_node(0) =
mesh.node_ptr(
idx(type,nx,i,j) );
784 elem->set_node(1) =
mesh.node_ptr(
idx(type,nx,i+2,j) );
785 elem->set_node(2) =
mesh.node_ptr(
idx(type,nx,i+2,j+2));
786 elem->set_node(3) =
mesh.node_ptr(
idx(type,nx,i+1,j) );
787 elem->set_node(4) =
mesh.node_ptr(
idx(type,nx,i+2,j+1));
788 elem->set_node(5) =
mesh.node_ptr(
idx(type,nx,i+1,j+1));
791 boundary_info.add_side(elem, 0, 0);
794 boundary_info.add_side(elem, 1, 1);
798 elem->set_id(elem_id++);
799 elem =
mesh.add_elem (elem);
801 elem->set_node(0) =
mesh.node_ptr(
idx(type,nx,i,j) );
802 elem->set_node(1) =
mesh.node_ptr(
idx(type,nx,i+2,j+2));
803 elem->set_node(2) =
mesh.node_ptr(
idx(type,nx,i,j+2) );
804 elem->set_node(3) =
mesh.node_ptr(
idx(type,nx,i+1,j+1));
805 elem->set_node(4) =
mesh.node_ptr(
idx(type,nx,i+1,j+2));
806 elem->set_node(5) =
mesh.node_ptr(
idx(type,nx,i,j+1) );
809 boundary_info.add_side(elem, 1, 2);
812 boundary_info.add_side(elem, 2, 3);
820 libmesh_error_msg(
"ERROR: Unrecognized 2D element type.");
827 if (gauss_lobatto_grid)
829 GaussLobattoRedistributionFunction func(nx, xmin, xmax,
835 for (
unsigned int p=0; p<
mesh.n_nodes(); p++)
837 mesh.node_ref(p)(0) = (
mesh.node_ref(p)(0))*(xmax-xmin) + xmin;
838 mesh.node_ref(p)(1) = (
mesh.node_ref(p)(1))*(ymax-ymin) + ymin;
843 boundary_info.sideset_name(0) =
"bottom";
844 boundary_info.sideset_name(1) =
"right";
845 boundary_info.sideset_name(2) =
"top";
846 boundary_info.sideset_name(3) =
"left";
849 boundary_info.nodeset_name(0) =
"bottom";
850 boundary_info.nodeset_name(1) =
"right";
851 boundary_info.nodeset_name(2) =
"top";
852 boundary_info.nodeset_name(3) =
"left";
871 libmesh_assert_not_equal_to (nx, 0);
872 libmesh_assert_not_equal_to (ny, 0);
873 libmesh_assert_not_equal_to (nz, 0);
874 libmesh_assert_less (xmin, xmax);
875 libmesh_assert_less (ymin, ymax);
876 libmesh_assert_less (zmin, zmax);
893 mesh.reserve_elem(nx*ny*nz);
901 mesh.reserve_elem(2*nx*ny*nz);
906 libmesh_error_msg(
"ERROR: Unrecognized 3D element type.");
920 mesh.reserve_nodes( (nx+1)*(ny+1)*(nz+1) );
938 mesh.reserve_nodes( (2*nx+1)*(2*ny+1)*(2*nz+1) );
943 libmesh_error_msg(
"ERROR: Unrecognized 3D element type.");
950 unsigned int node_id = 0;
957 for (
unsigned int k=0; k<=nz; k++)
958 for (
unsigned int j=0; j<=ny; j++)
959 for (
unsigned int i=0; i<=nx; i++)
960 mesh.add_point(Point(static_cast<Real>(i)/static_cast<Real>(nx),
961 static_cast<Real>(j)/static_cast<Real>(ny),
962 static_cast<Real>(k)/static_cast<Real>(nz)), node_id++);
977 for (
unsigned int k=0; k<=(2*nz); k++)
978 for (
unsigned int j=0; j<=(2*ny); j++)
979 for (
unsigned int i=0; i<=(2*nx); i++)
980 mesh.add_point(Point(static_cast<Real>(i)/static_cast<Real>(2*nx),
981 static_cast<Real>(j)/static_cast<Real>(2*ny),
982 static_cast<Real>(k)/static_cast<Real>(2*nz)), node_id++);
989 libmesh_error_msg(
"ERROR: Unrecognized 3D element type.");
996 unsigned int elem_id = 0;
1002 for (
unsigned int k=0; k<nz; k++)
1003 for (
unsigned int j=0; j<ny; j++)
1004 for (
unsigned int i=0; i<nx; i++)
1006 Elem * elem =
new Hex8;
1007 elem->set_id(elem_id++);
1008 elem =
mesh.add_elem (elem);
1010 elem->set_node(0) =
mesh.node_ptr(
idx(type,nx,ny,i,j,k) );
1011 elem->set_node(1) =
mesh.node_ptr(
idx(type,nx,ny,i+1,j,k) );
1012 elem->set_node(2) =
mesh.node_ptr(
idx(type,nx,ny,i+1,j+1,k) );
1013 elem->set_node(3) =
mesh.node_ptr(
idx(type,nx,ny,i,j+1,k) );
1014 elem->set_node(4) =
mesh.node_ptr(
idx(type,nx,ny,i,j,k+1) );
1015 elem->set_node(5) =
mesh.node_ptr(
idx(type,nx,ny,i+1,j,k+1) );
1016 elem->set_node(6) =
mesh.node_ptr(
idx(type,nx,ny,i+1,j+1,k+1));
1017 elem->set_node(7) =
mesh.node_ptr(
idx(type,nx,ny,i,j+1,k+1) );
1020 boundary_info.add_side(elem, 0, 0);
1023 boundary_info.add_side(elem, 5, 5);
1026 boundary_info.add_side(elem, 1, 1);
1029 boundary_info.add_side(elem, 3, 3);
1032 boundary_info.add_side(elem, 4, 4);
1035 boundary_info.add_side(elem, 2, 2);
1045 for (
unsigned int k=0; k<nz; k++)
1046 for (
unsigned int j=0; j<ny; j++)
1047 for (
unsigned int i=0; i<nx; i++)
1050 Elem * elem =
new Prism6;
1051 elem->set_id(elem_id++);
1052 elem =
mesh.add_elem (elem);
1054 elem->set_node(0) =
mesh.node_ptr(
idx(type,nx,ny,i,j,k) );
1055 elem->set_node(1) =
mesh.node_ptr(
idx(type,nx,ny,i+1,j,k) );
1056 elem->set_node(2) =
mesh.node_ptr(
idx(type,nx,ny,i,j+1,k) );
1057 elem->set_node(3) =
mesh.node_ptr(
idx(type,nx,ny,i,j,k+1) );
1058 elem->set_node(4) =
mesh.node_ptr(
idx(type,nx,ny,i+1,j,k+1) );
1059 elem->set_node(5) =
mesh.node_ptr(
idx(type,nx,ny,i,j+1,k+1) );
1063 boundary_info.add_side(elem, 3, 4);
1066 boundary_info.add_side(elem, 1, 1);
1069 boundary_info.add_side(elem, 0, 0);
1072 boundary_info.add_side(elem, 4, 5);
1076 elem->set_id(elem_id++);
1077 elem =
mesh.add_elem (elem);
1079 elem->set_node(0) =
mesh.node_ptr(
idx(type,nx,ny,i+1,j,k) );
1080 elem->set_node(1) =
mesh.node_ptr(
idx(type,nx,ny,i+1,j+1,k) );
1081 elem->set_node(2) =
mesh.node_ptr(
idx(type,nx,ny,i,j+1,k) );
1082 elem->set_node(3) =
mesh.node_ptr(
idx(type,nx,ny,i+1,j,k+1) );
1083 elem->set_node(4) =
mesh.node_ptr(
idx(type,nx,ny,i+1,j+1,k+1));
1084 elem->set_node(5) =
mesh.node_ptr(
idx(type,nx,ny,i,j+1,k+1) );
1088 boundary_info.add_side(elem, 1, 2);
1091 boundary_info.add_side(elem, 2, 3);
1094 boundary_info.add_side(elem, 0, 0);
1097 boundary_info.add_side(elem, 4, 5);
1115 for (
unsigned int k=0; k<(2*nz); k += 2)
1116 for (
unsigned int j=0; j<(2*ny); j += 2)
1117 for (
unsigned int i=0; i<(2*nx); i += 2)
1119 Elem * elem = (type ==
HEX20) ?
1120 static_cast<Elem *>(
new Hex20) :
1121 static_cast<Elem *
>(
new Hex27);
1122 elem->set_id(elem_id++);
1123 elem =
mesh.add_elem (elem);
1125 elem->set_node(0) =
mesh.node_ptr(
idx(type,nx,ny,i, j, k) );
1126 elem->set_node(1) =
mesh.node_ptr(
idx(type,nx,ny,i+2,j, k) );
1127 elem->set_node(2) =
mesh.node_ptr(
idx(type,nx,ny,i+2,j+2,k) );
1128 elem->set_node(3) =
mesh.node_ptr(
idx(type,nx,ny,i, j+2,k) );
1129 elem->set_node(4) =
mesh.node_ptr(
idx(type,nx,ny,i, j, k+2));
1130 elem->set_node(5) =
mesh.node_ptr(
idx(type,nx,ny,i+2,j, k+2));
1131 elem->set_node(6) =
mesh.node_ptr(
idx(type,nx,ny,i+2,j+2,k+2));
1132 elem->set_node(7) =
mesh.node_ptr(
idx(type,nx,ny,i, j+2,k+2));
1133 elem->set_node(8) =
mesh.node_ptr(
idx(type,nx,ny,i+1,j, k) );
1134 elem->set_node(9) =
mesh.node_ptr(
idx(type,nx,ny,i+2,j+1,k) );
1135 elem->set_node(10) =
mesh.node_ptr(
idx(type,nx,ny,i+1,j+2,k) );
1136 elem->set_node(11) =
mesh.node_ptr(
idx(type,nx,ny,i, j+1,k) );
1137 elem->set_node(12) =
mesh.node_ptr(
idx(type,nx,ny,i, j, k+1));
1138 elem->set_node(13) =
mesh.node_ptr(
idx(type,nx,ny,i+2,j, k+1));
1139 elem->set_node(14) =
mesh.node_ptr(
idx(type,nx,ny,i+2,j+2,k+1));
1140 elem->set_node(15) =
mesh.node_ptr(
idx(type,nx,ny,i, j+2,k+1));
1141 elem->set_node(16) =
mesh.node_ptr(
idx(type,nx,ny,i+1,j, k+2));
1142 elem->set_node(17) =
mesh.node_ptr(
idx(type,nx,ny,i+2,j+1,k+2));
1143 elem->set_node(18) =
mesh.node_ptr(
idx(type,nx,ny,i+1,j+2,k+2));
1144 elem->set_node(19) =
mesh.node_ptr(
idx(type,nx,ny,i, j+1,k+2));
1148 elem->set_node(20) =
mesh.node_ptr(
idx(type,nx,ny,i+1,j+1,k) );
1149 elem->set_node(21) =
mesh.node_ptr(
idx(type,nx,ny,i+1,j, k+1));
1150 elem->set_node(22) =
mesh.node_ptr(
idx(type,nx,ny,i+2,j+1,k+1));
1151 elem->set_node(23) =
mesh.node_ptr(
idx(type,nx,ny,i+1,j+2,k+1));
1152 elem->set_node(24) =
mesh.node_ptr(
idx(type,nx,ny,i, j+1,k+1));
1153 elem->set_node(25) =
mesh.node_ptr(
idx(type,nx,ny,i+1,j+1,k+2));
1154 elem->set_node(26) =
mesh.node_ptr(
idx(type,nx,ny,i+1,j+1,k+1));
1159 boundary_info.add_side(elem, 0, 0);
1162 boundary_info.add_side(elem, 5, 5);
1165 boundary_info.add_side(elem, 1, 1);
1168 boundary_info.add_side(elem, 3, 3);
1171 boundary_info.add_side(elem, 4, 4);
1174 boundary_info.add_side(elem, 2, 2);
1185 for (
unsigned int k=0; k<(2*nz); k += 2)
1186 for (
unsigned int j=0; j<(2*ny); j += 2)
1187 for (
unsigned int i=0; i<(2*nx); i += 2)
1190 Elem * elem = (type ==
PRISM15) ?
1191 static_cast<Elem *>(
new Prism15) :
1192 static_cast<Elem *
>(
new Prism18);
1193 elem->set_id(elem_id++);
1194 elem =
mesh.add_elem (elem);
1196 elem->set_node(0) =
mesh.node_ptr(
idx(type,nx,ny,i, j, k) );
1197 elem->set_node(1) =
mesh.node_ptr(
idx(type,nx,ny,i+2,j, k) );
1198 elem->set_node(2) =
mesh.node_ptr(
idx(type,nx,ny,i, j+2,k) );
1199 elem->set_node(3) =
mesh.node_ptr(
idx(type,nx,ny,i, j, k+2));
1200 elem->set_node(4) =
mesh.node_ptr(
idx(type,nx,ny,i+2,j, k+2));
1201 elem->set_node(5) =
mesh.node_ptr(
idx(type,nx,ny,i, j+2,k+2));
1202 elem->set_node(6) =
mesh.node_ptr(
idx(type,nx,ny,i+1,j, k) );
1203 elem->set_node(7) =
mesh.node_ptr(
idx(type,nx,ny,i+1,j+1,k) );
1204 elem->set_node(8) =
mesh.node_ptr(
idx(type,nx,ny,i, j+1,k) );
1205 elem->set_node(9) =
mesh.node_ptr(
idx(type,nx,ny,i, j, k+1));
1206 elem->set_node(10) =
mesh.node_ptr(
idx(type,nx,ny,i+2,j, k+1));
1207 elem->set_node(11) =
mesh.node_ptr(
idx(type,nx,ny,i, j+2,k+1));
1208 elem->set_node(12) =
mesh.node_ptr(
idx(type,nx,ny,i+1,j, k+2));
1209 elem->set_node(13) =
mesh.node_ptr(
idx(type,nx,ny,i+1,j+1,k+2));
1210 elem->set_node(14) =
mesh.node_ptr(
idx(type,nx,ny,i, j+1,k+2));
1213 elem->set_node(15) =
mesh.node_ptr(
idx(type,nx,ny,i+1,j, k+1));
1214 elem->set_node(16) =
mesh.node_ptr(
idx(type,nx,ny,i+1,j+1,k+1));
1215 elem->set_node(17) =
mesh.node_ptr(
idx(type,nx,ny,i, j+1,k+1));
1220 boundary_info.add_side(elem, 3, 4);
1223 boundary_info.add_side(elem, 1, 1);
1226 boundary_info.add_side(elem, 0, 0);
1229 boundary_info.add_side(elem, 4, 5);
1234 static_cast<Elem *>(
new Prism15) :
1235 static_cast<Elem *
>(
new Prism18);
1236 elem->set_id(elem_id++);
1237 elem =
mesh.add_elem (elem);
1239 elem->set_node(0) =
mesh.node_ptr(
idx(type,nx,ny,i+2,j,k) );
1240 elem->set_node(1) =
mesh.node_ptr(
idx(type,nx,ny,i+2,j+2,k) );
1241 elem->set_node(2) =
mesh.node_ptr(
idx(type,nx,ny,i,j+2,k) );
1242 elem->set_node(3) =
mesh.node_ptr(
idx(type,nx,ny,i+2,j,k+2) );
1243 elem->set_node(4) =
mesh.node_ptr(
idx(type,nx,ny,i+2,j+2,k+2) );
1244 elem->set_node(5) =
mesh.node_ptr(
idx(type,nx,ny,i,j+2,k+2) );
1245 elem->set_node(6) =
mesh.node_ptr(
idx(type,nx,ny,i+2,j+1,k) );
1246 elem->set_node(7) =
mesh.node_ptr(
idx(type,nx,ny,i+1,j+2,k) );
1247 elem->set_node(8) =
mesh.node_ptr(
idx(type,nx,ny,i+1,j+1,k) );
1248 elem->set_node(9) =
mesh.node_ptr(
idx(type,nx,ny,i+2,j,k+1) );
1249 elem->set_node(10) =
mesh.node_ptr(
idx(type,nx,ny,i+2,j+2,k+1));
1250 elem->set_node(11) =
mesh.node_ptr(
idx(type,nx,ny,i,j+2,k+1) );
1251 elem->set_node(12) =
mesh.node_ptr(
idx(type,nx,ny,i+2,j+1,k+2));
1252 elem->set_node(13) =
mesh.node_ptr(
idx(type,nx,ny,i+1,j+2,k+2));
1253 elem->set_node(14) =
mesh.node_ptr(
idx(type,nx,ny,i+1,j+1,k+2));
1256 elem->set_node(15) =
mesh.node_ptr(
idx(type,nx,ny,i+2,j+1,k+1));
1257 elem->set_node(16) =
mesh.node_ptr(
idx(type,nx,ny,i+1,j+2,k+1));
1258 elem->set_node(17) =
mesh.node_ptr(
idx(type,nx,ny,i+1,j+1,k+1));
1263 boundary_info.add_side(elem, 1, 2);
1266 boundary_info.add_side(elem, 2, 3);
1269 boundary_info.add_side(elem, 0, 0);
1272 boundary_info.add_side(elem, 4, 5);
1283 libmesh_error_msg(
"ERROR: Unrecognized 3D element type.");
1291 if (gauss_lobatto_grid)
1293 GaussLobattoRedistributionFunction func(nx, xmin, xmax,
1300 for (
unsigned int p=0; p<
mesh.n_nodes(); p++)
1302 mesh.node_ref(p)(0) = (
mesh.node_ref(p)(0))*(xmax-xmin) + xmin;
1303 mesh.node_ref(p)(1) = (
mesh.node_ref(p)(1))*(ymax-ymin) + ymin;
1304 mesh.node_ref(p)(2) = (
mesh.node_ref(p)(2))*(zmax-zmin) + zmin;
1317 if ((type ==
TET4) ||
1324 std::vector<Elem *> new_elements;
1327 new_elements.reserve(24*
mesh.n_elem());
1329 new_elements.reserve(6*
mesh.n_elem());
1332 for (
auto & base_hex :
mesh.element_ptr_range())
1335 Node * apex_node = base_hex->node_ptr(26);
1338 std::vector<boundary_id_type> ids;
1340 for (
auto s : base_hex->side_index_range())
1343 boundary_info.boundary_ids(base_hex, s, ids);
1346 libmesh_assert(ids.size() <= 1);
1352 std::unique_ptr<Elem>
side = base_hex->build_side_ptr(s);
1357 for (
unsigned int sub_tet=0; sub_tet<4; ++sub_tet)
1359 new_elements.push_back(
new Tet4 );
1360 Elem * sub_elem = new_elements.back();
1361 sub_elem->set_node(0) =
side->node_ptr(sub_tet);
1362 sub_elem->set_node(1) =
side->node_ptr(8);
1363 sub_elem->set_node(2) =
side->node_ptr(sub_tet==3 ? 0 : sub_tet+1 );
1364 sub_elem->set_node(3) = apex_node;
1369 if (b_id != BoundaryInfo::invalid_id)
1370 boundary_info.add_side(sub_elem, 0, b_id);
1377 new_elements.push_back(
new Pyramid5);
1378 Elem * sub_elem = new_elements.back();
1383 sub_elem->set_node(0) =
side->node_ptr(0);
1384 sub_elem->set_node(1) =
side->node_ptr(3);
1385 sub_elem->set_node(2) =
side->node_ptr(2);
1386 sub_elem->set_node(3) =
side->node_ptr(1);
1389 sub_elem->set_node(4) = apex_node;
1393 if (b_id != BoundaryInfo::invalid_id)
1394 boundary_info.add_side(sub_elem, 4, b_id);
1401 for (
auto & elem :
mesh.element_ptr_range())
1403 boundary_info.remove(elem);
1404 mesh.delete_elem(elem);
1409 n_new = cast_int<dof_id_type>(new_elements.size());
1412 new_elements[i]->set_id(i);
1413 mesh.add_elem(new_elements[i]);
1421 mesh.all_second_order();
1424 mesh.all_second_order(
false);
1428 boundary_info.sideset_name(0) =
"back";
1429 boundary_info.sideset_name(1) =
"bottom";
1430 boundary_info.sideset_name(2) =
"right";
1431 boundary_info.sideset_name(3) =
"top";
1432 boundary_info.sideset_name(4) =
"left";
1433 boundary_info.sideset_name(5) =
"front";
1436 boundary_info.nodeset_name(0) =
"back";
1437 boundary_info.nodeset_name(1) =
"bottom";
1438 boundary_info.nodeset_name(2) =
"right";
1439 boundary_info.nodeset_name(3) =
"top";
1440 boundary_info.nodeset_name(4) =
"left";
1441 boundary_info.nodeset_name(5) =
"front";
1447 libmesh_error_msg(
"Unknown dimension " <<
mesh.mesh_dimension());
1450 STOP_LOG(
"build_cube()",
"MeshTools::Generation");
1455 mesh.prepare_for_use (
false);