14 : hoNodes(PETSC_TRUE), defMaxLevel(0), countEle(0), countVertEle(0),
20 std::string opt1 = prefix.size() ?
"-" + prefix +
"_max_post_proc_ref_level"
21 :
"-max_post_proc_ref_level";
24 std::string opt2 = prefix.size() ?
"-" + prefix +
"_max_post_ho_nodes"
25 :
"-max_post_ho_nodes";
30 "Wrong parameter -max_post_proc_ref_level "
31 "should be positive number");
39 const int max_level = defMaxLevel;
44 auto create_reference_element = [&moab_ref]() {
46 constexpr
double base_coords[] = {0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1};
48 for (
int nn = 0; nn < 4; nn++) {
50 moab_ref.create_vertex(&base_coords[3 * nn], nodes[nn]);
53 CHKERR moab_ref.create_element(MBTET, nodes, 4, tet);
60 auto refine_ref_tetrahedron = [
this, &m_field_ref, max_level]() {
67 for (
int ll = 0; ll != max_level; ++ll) {
72 ->getEntitiesByTypeAndRefLevel(
BitRefLevel().set(ll),
76 ->getEntitiesByTypeAndRefLevel(
BitRefLevel().set(ll),
81 CHKERR m_ref->addVerticesInTheMiddleOfEdges(edges,
88 auto get_ref_gauss_pts_and_shape_functions = [
this, max_level, &moab_ref,
91 for (
int ll = 0; ll != max_level + 1; ++ll) {
98 CHKERR moab_ref.create_meshset(MESHSET_SET, meshset);
99 CHKERR moab_ref.add_entities(meshset, tets);
100 CHKERR moab_ref.convert_entities(meshset,
true,
false,
false);
101 CHKERR moab_ref.delete_entities(&meshset, 1);
104 CHKERR moab_ref.get_connectivity(tets, elem_nodes,
false);
106 auto &gauss_pts = levelGaussPtsOnRefMesh[ll];
107 gauss_pts.resize(elem_nodes.size(), 4,
false);
108 std::map<EntityHandle, int> little_map;
109 Range::iterator nit = elem_nodes.begin();
110 for (
int gg = 0; nit != elem_nodes.end(); nit++, gg++) {
111 CHKERR moab_ref.get_coords(&*nit, 1, &gauss_pts(gg, 0));
112 little_map[*nit] = gg;
114 gauss_pts = trans(gauss_pts);
116 auto &ref_tets = levelRef[ll];
117 Range::iterator tit = tets.begin();
118 for (
int tt = 0; tit != tets.end(); ++tit, ++tt) {
121 CHKERR moab_ref.get_connectivity(*tit, conn, num_nodes,
false);
123 ref_tets.resize(tets.size(), num_nodes);
125 for (
int nn = 0; nn != num_nodes; ++nn) {
126 ref_tets(tt, nn) = little_map[conn[nn]];
130 auto &shape_functions = levelShapeFunctions[ll];
131 shape_functions.resize(elem_nodes.size(), 4);
133 &gauss_pts(1, 0), &gauss_pts(2, 0), elem_nodes.size());
138 levelRef.resize(max_level + 1);
139 levelGaussPtsOnRefMesh.resize(max_level + 1);
140 levelShapeFunctions.resize(max_level + 1);
142 CHKERR create_reference_element();
143 CHKERR refine_ref_tetrahedron();
144 CHKERR get_ref_gauss_pts_and_shape_functions();
155 <<
"Refinement for hexes is not implemented";
161 auto create_reference_element = [&moab_ref]() {
163 constexpr
double base_coords[] = {0, 0, 0, 1, 0, 0, 1, 1, 0, 0, 1, 0,
164 0, 0, 1, 1, 0, 1, 1, 1, 1, 0, 1, 1};
166 for (
int nn = 0; nn < 8; nn++)
167 CHKERR moab_ref.create_vertex(&base_coords[3 * nn], nodes[nn]);
169 CHKERR moab_ref.create_element(MBHEX, nodes, 8, hex);
173 auto add_ho_nodes = [&]() {
176 CHKERR moab_ref.get_entities_by_type(0, MBHEX, hexes,
true);
178 CHKERR moab_ref.create_meshset(MESHSET_SET, meshset);
179 CHKERR moab_ref.add_entities(meshset, hexes);
180 CHKERR moab_ref.convert_entities(meshset,
true,
true,
true);
181 CHKERR moab_ref.delete_entities(&meshset, 1);
185 auto set_gauss_pts = [&](std::map<EntityHandle, int> &little_map) {
188 CHKERR moab_ref.get_entities_by_type(0, MBHEX, hexes,
true);
190 CHKERR moab_ref.get_connectivity(hexes, hexes_nodes,
false);
191 auto &gauss_pts = levelGaussPtsOnRefMesh[0];
192 gauss_pts.resize(hexes_nodes.size(), 4,
false);
194 for (
auto node : hexes_nodes) {
195 CHKERR moab_ref.get_coords(&node, 1, &gauss_pts(gg, 0));
196 little_map[node] = gg;
199 gauss_pts = trans(gauss_pts);
203 auto set_ref_hexes = [&](std::map<EntityHandle, int> &little_map) {
206 CHKERR moab_ref.get_entities_by_type(0, MBHEX, hexes,
true);
208 auto &ref_hexes = levelRef[0];
209 for (
auto hex : hexes) {
212 CHKERR moab_ref.get_connectivity(hex, conn, num_nodes,
false);
213 if (ref_hexes.size2() != num_nodes) {
214 ref_hexes.resize(hexes.size(), num_nodes);
216 for (
int nn = 0; nn != num_nodes; ++nn) {
217 ref_hexes(hh, nn) = little_map[conn[nn]];
224 auto set_shape_functions = [&]() {
226 auto &gauss_pts = levelGaussPtsOnRefMesh[0];
227 auto &shape_functions = levelShapeFunctions[0];
228 const auto nb_gauss_pts = gauss_pts.size2();
229 shape_functions.resize(nb_gauss_pts, 8);
230 for (
int gg = 0; gg != nb_gauss_pts; ++gg) {
231 const double ksi = gauss_pts(0, gg);
232 const double zeta = gauss_pts(1, gg);
233 const double eta = gauss_pts(2, gg);
247 levelGaussPtsOnRefMesh.resize(1);
248 levelShapeFunctions.resize(1);
250 CHKERR create_reference_element();
253 std::map<EntityHandle, int> little_map;
254 CHKERR set_gauss_pts(little_map);
255 CHKERR set_ref_hexes(little_map);
256 CHKERR set_shape_functions();
264 const int max_level = defMaxLevel;
269 auto create_reference_element = [&moab_ref]() {
271 constexpr
double base_coords[] = {
284 for (
int nn = 0; nn != 3; ++nn)
285 CHKERR moab_ref.create_vertex(&base_coords[3 * nn], nodes[nn]);
287 CHKERR moab_ref.create_element(MBTRI, nodes, 3, tri);
290 CHKERR moab_ref.get_adjacencies(&tri, 1, 1,
true, edges,
291 moab::Interface::UNION);
296 CHKERR create_reference_element();
301 auto refine_ref_triangles = [
this, &m_field_ref, max_level]() {
309 for (
int ll = 0; ll != max_level; ++ll) {
314 ->getEntitiesByTypeAndRefLevel(
BitRefLevel().set(ll),
318 ->getEntitiesByTypeAndRefLevel(
BitRefLevel().set(ll),
322 CHKERR m_ref->addVerticesInTheMiddleOfEdges(edges,
347 auto get_ref_gauss_pts_and_shape_functions = [
this, max_level, &moab_ref,
350 for (
int ll = 0; ll != max_level + 1; ++ll) {
359 CHKERR moab_ref.create_meshset(MESHSET_SET, meshset);
360 CHKERR moab_ref.add_entities(meshset, tris);
361 CHKERR moab_ref.convert_entities(meshset,
true,
false,
false);
362 CHKERR moab_ref.delete_entities(&meshset, 1);
366 CHKERR moab_ref.get_connectivity(tris, elem_nodes,
false);
368 auto &gauss_pts = levelGaussPtsOnRefMesh[ll];
369 gauss_pts.resize(elem_nodes.size(), 3,
false);
370 std::map<EntityHandle, int> little_map;
371 Range::iterator nit = elem_nodes.begin();
372 for (
int gg = 0; nit != elem_nodes.end(); nit++, gg++) {
373 CHKERR moab_ref.get_coords(&*nit, 1, &gauss_pts(gg, 0));
374 little_map[*nit] = gg;
376 gauss_pts = trans(gauss_pts);
378 auto &ref_tris = levelRef[ll];
379 Range::iterator tit = tris.begin();
380 for (
int tt = 0; tit != tris.end(); ++tit, ++tt) {
383 CHKERR moab_ref.get_connectivity(*tit, conn, num_nodes,
false);
385 ref_tris.resize(tris.size(), num_nodes);
387 for (
int nn = 0; nn != num_nodes; ++nn) {
388 ref_tris(tt, nn) = little_map[conn[nn]];
392 auto &shape_functions = levelShapeFunctions[ll];
393 shape_functions.resize(elem_nodes.size(), 3);
395 &gauss_pts(1, 0), elem_nodes.size());
400 levelRef.resize(max_level + 1);
401 levelGaussPtsOnRefMesh.resize(max_level + 1);
402 levelShapeFunctions.resize(max_level + 1);
404 CHKERR refine_ref_triangles();
405 CHKERR get_ref_gauss_pts_and_shape_functions();
416 <<
"Refinement for quad is not implemented";
422 auto create_reference_element = [&moab_ref]() {
424 constexpr
double base_coords[] = {
440 for (
int nn = 0; nn < 4; nn++)
441 CHKERR moab_ref.create_vertex(&base_coords[3 * nn], nodes[nn]);
443 CHKERR moab_ref.create_element(MBQUAD, nodes, 4, quad);
447 auto add_ho_nodes = [&]() {
450 CHKERR moab_ref.get_entities_by_type(0, MBQUAD, quads,
true);
452 CHKERR moab_ref.create_meshset(MESHSET_SET, meshset);
453 CHKERR moab_ref.add_entities(meshset, quads);
454 CHKERR moab_ref.convert_entities(meshset,
true,
true,
true);
455 CHKERR moab_ref.delete_entities(&meshset, 1);
459 auto set_gauss_pts = [&](std::map<EntityHandle, int> &little_map) {
462 CHKERR moab_ref.get_entities_by_type(0, MBQUAD, quads,
true);
464 CHKERR moab_ref.get_connectivity(quads, quads_nodes,
false);
465 auto &gauss_pts = levelGaussPtsOnRefMesh[0];
466 gauss_pts.resize(quads_nodes.size(), 4,
false);
468 for (
auto node : quads_nodes) {
469 CHKERR moab_ref.get_coords(&node, 1, &gauss_pts(gg, 0));
470 little_map[node] = gg;
473 gauss_pts = trans(gauss_pts);
477 auto set_ref_quads = [&](std::map<EntityHandle, int> &little_map) {
480 CHKERR moab_ref.get_entities_by_type(0, MBQUAD, quads,
true);
482 auto &ref_quads = levelRef[0];
483 for (
auto quad : quads) {
486 CHKERR moab_ref.get_connectivity(quad, conn, num_nodes,
false);
487 if (ref_quads.size2() != num_nodes) {
488 ref_quads.resize(quads.size(), num_nodes);
490 for (
int nn = 0; nn != num_nodes; ++nn) {
491 ref_quads(hh, nn) = little_map[conn[nn]];
498 auto set_shape_functions = [&]() {
500 auto &gauss_pts = levelGaussPtsOnRefMesh[0];
501 auto &shape_functions = levelShapeFunctions[0];
502 const auto nb_gauss_pts = gauss_pts.size2();
503 shape_functions.resize(nb_gauss_pts, 4);
504 for (
int gg = 0; gg != nb_gauss_pts; ++gg) {
505 const double ksi = gauss_pts(0, gg);
506 const double zeta = gauss_pts(1, gg);
516 levelGaussPtsOnRefMesh.resize(1);
517 levelShapeFunctions.resize(1);
519 CHKERR create_reference_element();
522 std::map<EntityHandle, int> little_map;
523 CHKERR set_gauss_pts(little_map);
524 CHKERR set_ref_quads(little_map);
525 CHKERR set_shape_functions();
536 <<
"Refinement for edges is not implemented";
539 auto set_gauss_pts = [&](std::map<EntityHandle, int> &little_map) {
546 auto &gauss_pts = levelGaussPtsOnRefMesh[0];
547 gauss_pts.resize(2, nb_nodes,
false);
551 for (; nn != 2; ++nn) {
552 gauss_pts(0, nn) =
static_cast<double>(nn);
557 gauss_pts(0, nn) = 0.5;
564 auto set_ref_edges = [&](std::map<EntityHandle, int> &little_map) {
568 int nb_edges = level + 1;
574 auto &ref_edges = levelRef[level];
575 ref_edges.resize(nb_edges, nb_nodes,
false);
577 for (
int ee = 0; ee != nb_edges; ++ee) {
579 for (; nn != 2; ++nn) {
580 ref_edges(ee, nn) = nb_nodes * ee + nn;
583 ref_edges(ee, nn) = nb_nodes * ee + 2;
590 auto set_shape_functions = [&]() {
592 auto &gauss_pts = levelGaussPtsOnRefMesh[0];
593 auto &shape_functions = levelShapeFunctions[0];
594 const auto nb_gauss_pts = gauss_pts.size2();
595 shape_functions.resize(nb_gauss_pts, 2);
596 for (
int gg = 0; gg != nb_gauss_pts; ++gg) {
597 const double ksi = gauss_pts(0, gg);
605 levelGaussPtsOnRefMesh.resize(1);
606 levelShapeFunctions.resize(1);
608 std::map<EntityHandle, int> little_map;
609 CHKERR set_gauss_pts(little_map);
610 CHKERR set_ref_edges(little_map);
611 CHKERR set_shape_functions();