5#include <CGAL/Exact_predicates_inexact_constructions_kernel.h>
6#include <CGAL/squared_distance_3.h>
26 auto node = [](
int i,
int j,
int k) {
return i + 5 * (
j + 5 *
k); };
27 for (
int k = 0;
k <=
n; ++
k)
28 for (
int j = 0;
j <=
n; ++
j)
29 for (
int i = 0;
i <=
n; ++
i) {
30 mesh.points.push_back({-1. + .5 *
i, -1. + .5 *
j, -1. + .5 *
k});
31 mesh.vertexIds.push_back(
mesh.points.size());
33 for (
int k = 0;
k <
n; ++
k)
34 for (
int j = 0;
j <
n; ++
j)
35 for (
int i = 0;
i <
n; ++
i) {
36 std::array<int, 3> permutation{0, 1, 2};
38 std::array<int, 3> x{
i,
j,
k};
39 std::array<int, 4> cell{node(
i,
j,
k), 0, 0,
40 node(
i + 1,
j + 1,
k + 1)};
42 cell[1] = node(x[0], x[1], x[2]);
44 cell[2] = node(x[0], x[1], x[2]);
45 mesh.cells.push_back(cell);
46 }
while (std::next_permutation(permutation.begin(), permutation.end()));
48 std::set<std::array<int, 3>>
faces;
50 for (
int opposite = 0; opposite != 4; ++opposite) {
53 for (
int i = 0;
i != 4; ++
i)
56 if (std::all_of(
f.begin(),
f.end(), [&](
int v) {
57 return mesh.points[v][2] == 0 && mesh.points[v][0] < .01;
59 std::sort(
f.begin(),
f.end());
64 mesh.surfaceLabels.assign(
faces.size(), 7);
65 for (
int j = 0;
j !=
n; ++
j) {
66 mesh.featureEdges.push_back({node(2,
j, 2), node(2,
j + 1, 2)});
67 mesh.edgeLabels.push_back(9);
69 mesh.fixedVertices.push_back(node(2, 2, 2));
75 auto centre = [&](
const auto &cell) {
76 std::array<double, 3> x{};
78 for (
int d = 0;
d != 3; ++
d)
82 mesh.cells.erase(std::remove_if(
mesh.cells.begin(),
mesh.cells.end(),
83 [&](
const auto &cell) {
84 const auto x = centre(cell);
85 return cavity ? (x[0] > 0 && x[0] < .5 &&
86 x[1] > 0 && x[1] < .5 &&
87 x[2] > 0 && x[2] < .5)
88 : (x[0] > 0 && x[1] > 0);
93 used.insert(cell.begin(), cell.
end());
94 std::map<int, int> indices;
106 for (
size_t i = 0;
i !=
mesh.boundary.size(); ++
i) {
107 auto face =
mesh.boundary[
i];
108 if (!std::all_of(face.begin(), face.end(),
109 [&](
int v) { return used.count(v); }))
116 for (
size_t i = 0;
i !=
mesh.featureEdges.size(); ++
i) {
117 auto edge =
mesh.featureEdges[
i];
123 for (
int i :
mesh.fixedVertices)
124 result.fixedVertices.push_back(indices.at(
i));
130 using K = CGAL::Exact_predicates_inexact_constructions_kernel;
133 {-1, 0, 0}, {1, 0, 0}, {0, 1, 0}, {.1, .25, 1}, {.2, .3, -1}};
134 source.vertexIds = {11, 23, 47, 59, 97};
135 source.cells = {{0, 1, 3, 4}, {1, 2, 3, 4}, {2, 0, 3, 4}};
136 source.boundary = {{0, 3, 4}};
137 source.surfaceLabels = {7};
138 source.featureEdges = {{3, 4}};
144 settings.relativeSurfaceTolerance = 1e-30;
146 auto messages = boost::make_shared<std::ostringstream>();
148 logging::core::get()->add_sink(sink);
150 logging::core::get()->remove_sink(sink);
152 messages->str().find(
"[CGALTools]") != std::string::npos &&
153 messages->str().find(
"exceeds surface geometry tolerance") !=
155 "Surface tolerance did not produce a tagged warning");
157 report.insertedVertices > 0 &&
report.removedVertices == 0 &&
158 report.movedVertices == 0 &&
161 "Recovery did not preserve source vertices and add Steiner points");
162 std::map<int, std::array<double, 3>> original;
163 for (
size_t i = 0;
i !=
source.points.size(); ++
i)
165 auto point = [](
const auto &x) {
return K::Point_3(x[0], x[1], x[2]); };
167 std::map<std::array<int, 3>,
int> incidence;
169 for (
int d = 0;
d != 4; ++
d) {
170 std::array<int, 3> face;
172 for (
int j = 0;
j != 4; ++
j)
175 std::sort(face.begin(), face.end());
179 for (
const auto &[face, count] : incidence)
185 for (
size_t i = 0;
i != output.
points.size(); ++
i) {
187 CHKERR require(
id > 0 && seen.insert(
id).second,
188 "Invalid recovery vertex ID");
189 const auto found = original.find(
id);
190 if (found != original.end())
192 "Recovery moved a source vertex");
195 "Recovery reused a source ID for a Steiner point");
196 const auto p = point(output.
points[
i]);
199 [&](
const auto &triangle) {
200 return CGAL::squared_distance(p, triangle) < 1e-24;
202 "Recovery added a point away from its constraint surfaces");
205 for (
int id :
source.vertexIds)
206 CHKERR require(seen.count(id),
"Recovery dropped a source vertex ID");
208 for (
const auto &cell : output.
cells) {
209 const double v = CGAL::to_double(CGAL::volume(
210 point(output.
points[cell[0]]), point(output.
points[cell[1]]),
211 point(output.
points[cell[2]]), point(output.
points[cell[3]])));
212 CHKERR require(
v > 0,
"Recovery produced a nonpositive tetrahedron");
216 std::abs(volume - 2. / 3.) < 1e-12 &&
221 "Recovery changed the volume or lost a protected classification");
228 const std::array<std::array<int, 4>, 6>
cells{{{0, 1, 3, 7},
234 for (
int body = 0; body != 2; ++body) {
235 for (
int i = 0;
i != 8; ++
i) {
237 double((
i >> 1) & 1),
double((
i >> 2) & 1)});
240 for (
auto cell :
cells) {
243 source.cells.push_back(cell);
246 source.featureEdges = {{1, 3}, {8, 10}};
247 source.edgeLabels = {11, 12};
254 settings.relativeSurfaceTolerance = 1e-3;
261 std::set<int>{11, 12},
262 "Nearby independent curves lost their labels");
271 bool strict_quality =
false) {
274 output.
points.push_back({9, 8, 7});
277 bool rejected =
false;
280 }
catch (
const std::exception &) {
283 const bool unchanged =
284 output.
points == std::vector<std::array<double, 3>>{{9, 8, 7}} &&
285 output.
cells.empty() &&
report.minQualityAfter == 42;
289 report.minQualityBefore > 0 &&
291 "Candidate violated rejection or strict-quality contract");
297 invalid_settings.targetEdgeLength = -1;
298 CHKERR reject(input, {0}, invalid_settings);
300 invalid_settings.minimumQuality = 1;
301 std::vector<int> all(input.cells.size());
302 std::iota(all.begin(), all.end(), 0);
303 CHKERR reject(input, all, invalid_settings,
true);
304 invalid_settings.minimumQuality = 2;
305 CHKERR reject(input, all, invalid_settings);
306 input.cells.push_back(input.cells.front());
309 input.cells[0][1] = input.cells[0][0];
312 input.points[0] = input.points[1];
315 input.fixedVertices.push_back(input.points.size());
318 input.featureEdges.push_back({-1, 0});
319 input.edgeLabels.push_back(2);
327 using K = CGAL::Exact_predicates_inexact_constructions_kernel;
330 source.surfaceLabels.clear();
331 source.featureEdges.clear();
332 source.edgeLabels.clear();
333 source.fixedVertices.clear();
334 std::set<std::array<int, 3>> sheet;
336 for (
int opposite = 0; opposite != 4; ++opposite) {
337 std::array<int, 3> face;
339 for (
int i = 0;
i != 4; ++
i)
342 if (std::all_of(face.begin(), face.end(), [&](
int v) {
343 const auto &x = source.points[v];
344 return x[2] == 0 && x[0] <= -.5;
346 std::sort(face.begin(), face.end());
350 source.boundary.assign(sheet.begin(), sheet.end());
351 source.surfaceLabels.assign(sheet.size(), 7);
353 std::map<std::array<int, 2>,
int> counts;
354 for (
size_t i = 0;
i !=
mesh.boundary.size(); ++
i)
355 if (
mesh.surfaceLabels[
i] == 7)
356 for (
int d = 0;
d != 3; ++
d) {
357 std::array<int, 2> edge{
mesh.boundary[
i][
d],
358 mesh.boundary[
i][(
d + 1) % 3]};
359 std::sort(edge.begin(), edge.end());
362 std::vector<std::array<int, 2>> edges;
363 for (
const auto &[edge, count] : counts)
365 edges.push_back(edge);
368 const auto point = [](
const auto &x) {
return K::Point_3(x[0], x[1], x[2]); };
369 std::map<int, std::array<double, 3>> original;
370 std::vector<K::Segment_3> segments;
371 for (
const auto &edge : front(
source)) {
372 segments.emplace_back(point(
source.points[edge[0]]),
373 point(
source.points[edge[1]]));
382 std::map<int, std::array<double, 3>> retained;
383 for (
const auto &edge : front(output)) {
384 const auto a = point(output.
points[edge[0]]),
385 b = point(output.
points[edge[1]]);
387 std::any_of(segments.begin(), segments.end(),
388 [&](
const auto &segment) {
389 return CGAL::squared_distance(a, segment) < 1e-24 &&
390 CGAL::squared_distance(b, segment) < 1e-24;
392 "Coarsening changed the internal surface front polyline");
394 retained.emplace(output.vertexIds[
v], output.
points[
v]);
396 for (
const auto &[
id, x] : original)
397 CHKERR require(retained.count(id) && retained.at(id) == x,
398 "Coarsening removed or moved an original front vertex");
401 "Front preservation disabled volume coarsening");
410 for (
int j = 0;
j <=
n; ++
j)
411 for (
int i = 0;
i <=
n; ++
i)
412 mesh.
points.push_back({-1. + 2. * i / n, -1. + 2. * j / n, 0});
413 const int upper =
mesh.points.size(), lower = upper + 1;
414 mesh.points.push_back({0, 0, 2});
415 mesh.points.push_back({0, 0, -2});
416 for (
int j = 0;
j !=
n; ++
j)
417 for (
int i = 0;
i !=
n; ++
i) {
418 const int a =
i + (
n + 1) *
j, b =
a + 1,
d =
a +
n + 1,
c =
d + 1;
420 const std::array<std::array<int, 3>, 2>
faces =
422 ? std::array<std::array<int, 3>, 2>{{{
a, b,
d}, {b,
c,
d}}}
423 : std::array<std::array<int, 3>, 2>{{{
a, b,
c}, {
a,
c,
d}}};
424 for (
const auto &
f :
faces) {
425 mesh.boundary.push_back(
f);
426 mesh.surfaceLabels.push_back(7);
427 mesh.cells.push_back({
f[0],
f[1],
f[2], upper});
428 mesh.cells.push_back({
f[0],
f[1],
f[2], lower});
431 for (
size_t i = 0;
i !=
mesh.points.size(); ++
i) {
432 mesh.vertexIds.push_back(
i + 1);
433 mesh.fixedVertices.push_back(
i);
441 std::set<std::array<int, 3>>
faces;
442 for (
size_t i = 0;
i != data.boundary.size(); ++
i)
443 if (data.surfaceLabels[
i] == 7) {
444 auto f = data.boundary[
i];
446 v = data.vertexIds[
v];
447 std::sort(
f.begin(),
f.end());
452 const auto before = keys(
mesh), after = keys(output);
453 CHKERR require(!after.empty(),
"Remeshing removed the tested internal sheet");
455 "Constrained surface remeshing changed fixed source vertices");
456 CHKERR require(before != after,
457 "Constrained surface remeshing did not change connectivity");
460 "Inserted-vertex report does not match the fixed mesh");
463 std::map<std::array<int, 2>,
int> edges;
465 for (
size_t i = 0;
i != output.
boundary.size(); ++
i) {
470 std::array<double, 3>
a, b;
471 for (
int d = 0;
d != 3; ++
d) {
475 area += .5 * std::abs(
a[0] * b[1] -
a[1] * b[0]);
476 for (
int d = 0;
d != 3; ++
d) {
477 used.insert(face[
d]);
479 "Remeshed sheet left its reference plane");
480 std::array<int, 2> edge{face[
d], face[(
d + 1) % 3]};
481 std::sort(edge.begin(), edge.end());
482 CHKERR require(++edges[edge] <= 2,
"Nonmanifold remeshed sheet edge");
485 CHKERR require(std::abs(area - 4) < 1e-10 &&
486 static_cast<long>(used.size()) - edges.size() +
faces == 1,
487 "Remeshing changed the area or topology of the sheet");
498 {-1, 0, 0}, {1, 0, 0}, {0, 1, 0}, {.1, .25, .4}, {.1, .25, -.4}};
499 mesh.vertexIds = {1, 2, 3, 4, 5};
500 mesh.cells = {{0, 1, 2, 3}, {0, 1, 2, 4}};
502 EntityHandle volume,
surface, quadratic;
506 const auto simplices = subtract(
source,
source.subset_by_type(MBVERTEX));
507 CHKERR mb.create_meshset(MESHSET_SET, quadratic);
508 CHKERR mb.add_entities(quadratic, simplices);
509 CHKERR mb.convert_entities(quadratic,
true,
false,
false);
510 CHKERR mb.delete_entities(&quadratic, 1);
512 CHKERR mb.get_connectivity(simplices, nodes,
false);
513 for (
auto node : subtract(nodes,
source.subset_by_type(MBVERTEX))) {
519 std::map<EntityHandle, std::vector<EntityHandle>> original_connectivity;
520 for (
auto entity : simplices) {
521 const EntityHandle *conn;
523 CHKERR mb.get_connectivity(entity, conn, count,
false);
524 if (
mb.type_from_handle(entity) == MBTET)
525 CHKERR require(count == 10,
"Expected higher-order source cells");
526 original_connectivity[entity] =
527 std::vector<EntityHandle>(conn, conn + count);
529 std::vector<double> original_coordinates(3 * nodes.size());
530 CHKERR mb.get_coords(nodes, original_coordinates.data());
531 auto unchanged = [&]() {
533 for (
const auto &[entity, original] : original_connectivity) {
534 const EntityHandle *conn;
536 CHKERR mb.get_connectivity(entity, conn, count,
false);
537 CHKERR require(std::vector<EntityHandle>(conn, conn + count) == original,
538 "CGAL changed higher-order source connectivity");
540 std::vector<double>
coordinates(original_coordinates.size());
543 "CGAL removed or moved higher-order source nodes");
549 "CGAL export included non-topological nodes");
553 CHKERR require(reconstructed.num_of_type(MBTET) == 3,
554 "Higher-order source reconstruction did not flip cells");
562 CHKERR require(remeshed.subset_by_type(MBTET) ==
cells,
563 "Empty selection should reuse higher-order cells");
575 &
settings.targetEdgeLength,
nullptr);
577 &
settings.relativeSurfaceTolerance,
nullptr);
580 char case_name[64] =
"local", file_name[PETSC_MAX_PATH_LEN] =
"";
582 sizeof(case_name),
nullptr);
584 sizeof(file_name),
nullptr);
585 const std::string test = case_name;
586 PetscBool auto_size = PETSC_FALSE;
589 if (test ==
"recovery") {
590 CHKERR recoveryOnly(bridge->getTools());
593 if (test ==
"near_curves") {
594 CHKERR nearbyCurves(bridge->getTools());
597 if (test ==
"quadratic") {
598 CHKERR higherOrderInput(m_field);
601 if (test ==
"reject") {
605 if (test ==
"surface") {
609 if (test ==
"front") {
615 auto centreOf = [&](EntityHandle cell,
double *centre) {
617 const EntityHandle *conn;
619 CHKERR mb.get_connectivity(cell, conn, count,
true);
620 std::vector<double> coords(3 * count);
621 CHKERR mb.get_coords(conn, count, coords.data());
622 for (
int d = 0;
d != 3; ++
d) {
624 for (
int i = 0;
i != count; ++
i)
625 centre[
d] += coords[3 *
i +
d] / count;
632 CHKERR sets->setMeshsetFromFile();
635 Range database_vertices, missing_ids;
636 CHKERR mb.get_entities_by_type(0, MBVERTEX, database_vertices);
637 std::set<int> vertex_ids;
639 for (
auto v : database_vertices) {
641 CHKERR mb.tag_get_data(
mb.globalId_tag(), &
v, 1, &
id);
643 missing_ids.insert(
v);
645 CHKERR require(vertex_ids.insert(
id).second,
646 "Duplicate source vertex GLOBAL_ID");
647 max_id = std::max(max_id,
id);
650 for (
auto v : missing_ids) {
651 CHKERR require(max_id < std::numeric_limits<int>::max(),
652 "Source vertex IDs exhausted");
653 const int id = ++max_id;
654 CHKERR mb.tag_set_data(
mb.globalId_tag(), &
v, 1, &
id);
661 const auto mesh = test ==
"nonconvex" || test ==
"cavity"
662 ? domainFixture(test ==
"cavity")
668 cells = imported.subset_by_type(MBTET);
669 input_vertices = imported.subset_by_type(MBVERTEX);
678 if (test ==
"surface_closure") {
681 CHKERR mb.get_adjacencies(sheet, 1,
false, edges, moab::Interface::UNION);
687 for (
auto cell :
cells) {
689 CHKERR centreOf(cell, centre);
696 for (
const auto &edge :
mesh.featureEdges) {
697 const EntityHandle conn[] = {input_vertices[edge[0]],
698 input_vertices[edge[1]]};
700 CHKERR mb.get_adjacencies(conn, 2, 1,
false, segment,
701 moab::Interface::INTERSECT);
702 front.merge(segment);
708 Range(front.front(), front.front()));
710 const EntityHandle anchor = input_vertices[
mesh.fixedVertices.front()];
715 using Geometry = CGAL::Exact_predicates_inexact_constructions_kernel;
716 std::vector<Geometry::Triangle_3> source_exterior;
720 moab::Interface::UNION);
721 for (
auto face : source_faces) {
723 CHKERR mb.get_adjacencies(&face, 1, 3,
false, incident);
724 if (intersect(incident,
cells).
size() != 1)
726 const EntityHandle *conn;
728 std::array<std::array<double, 3>, 3> x;
729 CHKERR mb.get_connectivity(face, conn,
n,
true);
730 CHKERR mb.get_coords(conn, 3, x[0].data());
731 source_exterior.emplace_back(
732 Geometry::Point_3(x[0][0], x[0][1], x[0][2]),
733 Geometry::Point_3(x[1][0], x[1][1], x[1][2]),
734 Geometry::Point_3(x[2][0], x[2][1], x[2][2]));
737 std::vector<double> old_coords(3 * input_vertices.size());
738 CHKERR mb.get_coords(input_vertices, old_coords.data());
740 CHKERR require(!
cells.empty() && !input_vertices.empty(),
741 "No tetrahedra to size");
742 std::array<double, 3> lo{old_coords[0], old_coords[1], old_coords[2]},
744 for (
size_t i = 0;
i != input_vertices.size(); ++
i)
745 for (
int d = 0;
d != 3; ++
d) {
746 lo[
d] = std::min(lo[
d], old_coords[3 *
i +
d]);
747 hi[
d] = std::max(hi[
d], old_coords[3 *
i +
d]);
750 1.5 * std::cbrt((hi[0] - lo[0]) * (hi[1] - lo[1]) * (hi[2] - lo[2]) /
754 if (file_name[0] && test ==
"local") {
756 for (
auto set : sets->getCubitMeshsetPtr(
std::regex(
"CRACK(.*)")))
757 CHKERR mb.get_entities_by_dimension(set->getMeshset(), 2,
crack, true);
758 if (!
crack.empty()) {
764 moab::Interface::UNION);
765 front_cells = intersect(front_cells,
cells);
769 for (
auto cell :
cells) {
771 CHKERR centreOf(cell, centre);
772 if (test ==
"whole" || test ==
"coarse" ||
773 (file_name[0] && (front_cells.empty() ||
774 front_cells.find(cell) != front_cells.end())) ||
775 (!file_name[0] && test !=
"empty" && std::abs(centre[0]) < .51 &&
776 std::abs(centre[2]) < .51))
779 settings.remeshSurfaces = test !=
"fixed";
780 if (test ==
"coarse")
785 const auto path =
"cgal_remesh_" + test +
"_source.h5m";
788 if (test ==
"rollback") {
791 EntityHandle duplicate = 0;
792 for (
auto face :
faces) {
794 CHKERR mb.get_adjacencies(&face, 1, 3,
false, adjacent);
795 if (intersect(adjacent,
cells).
size() == 1) {
800 CHKERR require(duplicate != 0,
"Missing exterior rollback fixture face");
801 const EntityHandle *conn;
803 CHKERR mb.get_connectivity(duplicate, conn, count,
true);
804 const std::array<EntityHandle, 3> copied{conn[0], conn[1], conn[2]};
805 ReadUtilIface *reader;
807 EntityHandle start, *new_conn;
808 CHKERR reader->get_element_connect(1, 3, MBTRI, 0, start, new_conn);
809 std::copy(copied.begin(), copied.end(), new_conn);
810 CHKERR reader->update_adjacencies(start, 1, 3, new_conn);
812 CHKERR mb.get_entities_by_handle(0, before);
813 output.insert(
cells.front());
814 const auto sentinel = output;
815 report.minQualityAfter = 42;
816 CHKERR PetscPushErrorHandler(PetscReturnErrorHandler,
nullptr);
819 CHKERR PetscPopErrorHandler();
820 CHKERR mb.get_entities_by_handle(0, after);
821 CHKERR require(error && before == after && output == sentinel &&
822 report.minQualityAfter == 42,
823 "Failed publication was not rolled back");
827 CHKERR require(published.empty(),
"Failed publication left an output bit");
828 std::vector<double> restored(old_coords.size());
829 CHKERR mb.get_coords(input_vertices, restored.data());
830 CHKERR require(restored == old_coords,
831 "Failed publication moved the source mesh");
836 std::vector<double> current_coords(old_coords.size());
837 CHKERR mb.get_coords(input_vertices, current_coords.data());
838 CHKERR require(current_coords == old_coords,
839 "Remeshing moved source-level vertices");
844 "Remeshing lost source-level cells");
846 CHKERR require(output.subset_by_type(MBTET) ==
cells &&
847 report.changedCells.empty(),
848 "Empty selection changed connectivity");
851 "Remeshing did not exercise connectivity changes");
852 if (test ==
"coarse")
854 "Coarse target did not exercise collapse");
857 "Fine target did not exercise splitting");
858 if (test ==
"whole" && !file_name[0]) {
859 const auto first_vertices = output.subset_by_type(MBVERTEX);
860 std::vector<double> before(3 * first_vertices.size()), after(before.size());
861 CHKERR mb.get_coords(first_vertices, before.data());
864 CHKERR bridge->remesh(output.subset_by_type(MBTET),
865 output.subset_by_type(MBTET),
BitRefLevel().set(2),
867 CHKERR mb.get_coords(first_vertices, after.data());
868 CHKERR require(before == after && !repeated.subset_by_type(MBTET).empty(),
869 "Repeated remeshing changed its source level");
873 const auto output_cells = output.subset_by_type(MBTET);
874 auto signedVolume = [&](
const Range ®ion,
double &total) {
877 for (
auto cell : region) {
878 const EntityHandle *conn;
880 std::array<std::array<double, 3>, 4> x;
881 CHKERR mb.get_connectivity(cell, conn, count,
true);
882 CHKERR mb.get_coords(conn, 4, x[0].data());
883 for (
int i = 1;
i != 4; ++
i)
884 for (
int d = 0;
d != 3; ++
d)
886 const double det = x[1][0] * (x[2][1] * x[3][2] - x[2][2] * x[3][1]) -
887 x[1][1] * (x[2][0] * x[3][2] - x[2][2] * x[3][0]) +
888 x[1][2] * (x[2][0] * x[3][1] - x[2][1] * x[3][0]);
889 CHKERR require(det > 0,
"Nonpositive remeshing cell volume");
906 "Remeshing removed an unselected source support vertex");
907 Range material, anchor;
909 sets->getCubitMeshsetPtr(1,
BLOCKSET)->getMeshset(), MBTET, material);
910 CHKERR require(intersect(material, output) == output_cells,
911 "Remeshing changed material membership");
913 sets->getCubitMeshsetPtr(5,
NODESET)->getMeshset(), MBVERTEX, anchor);
914 CHKERR require(anchor.size() == 1 && intersect(anchor, output) == anchor,
915 "Remeshing lost its fixed anchor");
917 if (test ==
"nonconvex" || test ==
"cavity") {
918 auto volume = [&](
const Range &
cells,
bool check_void,
double &total) {
921 for (
auto cell :
cells) {
922 const EntityHandle *conn;
924 std::array<std::array<double, 3>, 4> x;
925 CHKERR mb.get_connectivity(cell, conn,
n,
true);
926 CHKERR mb.get_coords(conn, 4, x[0].data());
927 std::array<double, 3> centre{};
928 for (
const auto &p : x)
929 for (
int d = 0;
d != 3; ++
d)
930 centre[
d] += p[
d] / 4;
932 const bool inside_void = test ==
"cavity"
933 ? centre[0] > 0 && centre[0] < .5 &&
934 centre[1] > 0 && centre[1] < .5 &&
935 centre[2] > 0 && centre[2] < .5
936 : centre[0] > 0 && centre[1] > 0;
937 CHKERR require(!inside_void,
938 "Constrained remeshing filled the excluded region");
940 for (
int i = 1;
i != 4; ++
i)
941 for (
int d = 0;
d != 3; ++
d)
943 const double det = x[1][0] * (x[2][1] * x[3][2] - x[2][2] * x[3][1]) -
944 x[1][1] * (x[2][0] * x[3][2] - x[2][2] * x[3][0]) +
945 x[1][2] * (x[2][0] * x[3][1] - x[2][1] * x[3][0]);
946 CHKERR require(det > 0,
"Nonpositive constrained-domain cell");
951 double before, after;
953 CHKERR volume(output_cells,
true, after);
954 CHKERR require(std::abs(before - after) < 1e-8 * before,
955 "Constrained remeshing changed physical volume");
959 moab::Interface::UNION);
960 for (
auto face :
faces) {
962 CHKERR mb.get_adjacencies(&face, 1, 3,
false, incident);
963 incident = intersect(incident, output_cells);
964 const auto count = incident.size();
965 CHKERR require(count == 1 || count == 2,
"Invalid output facet incidence");
968 CHKERR mb.side_number(incident.front(), face, side, sense, offset);
969 CHKERR require(sense == 1,
"Remeshing reversed an output skin face");
971 if (count == 1 && !file_name[0]) {
972 const EntityHandle *conn;
974 CHKERR mb.get_connectivity(face, conn,
n,
true);
975 std::array<double, 9> coords;
976 CHKERR mb.get_coords(conn, 3, coords.data());
977 for (
int i = 0;
i != 3; ++
i) {
978 const Geometry::Point_3 point(coords[3 *
i], coords[3 *
i + 1],
980 const bool exterior = std::any_of(
981 source_exterior.begin(), source_exterior.end(),
982 [&](
const auto &triangle) {
983 return CGAL::squared_distance(point, triangle) < 1e-16;
985 CHKERR require(exterior,
"Output contains an unmatched internal face");
991 CHKERR mb.get_entities_by_dimension(
992 sets->getCubitMeshsetPtr(2,
BLOCKSET)->getMeshset(), 2,
crack);
994 CHKERR require(!
crack.empty(),
"Remeshing lost the CRACK meshset");
995 for (
auto face :
crack) {
997 CHKERR mb.get_adjacencies(&face, 1, 3,
false, incident);
998 CHKERR require(intersect(incident, output_cells).
size() == 2,
999 "Crack ceased to be an internal sheet");
1001 if (test ==
"surface_closure") {
1002 const auto group = sets->getCubitMeshsetPtr(2,
BLOCKSET)->getMeshset();
1003 Range expected_edges, expected_nodes, edges, nodes;
1005 moab::Interface::UNION);
1007 CHKERR mb.get_entities_by_type(group, MBEDGE, edges);
1008 CHKERR mb.get_entities_by_type(group, MBVERTEX, nodes);
1009 CHKERR require(intersect(edges, output) == expected_edges &&
1010 intersect(nodes, output) == expected_nodes,
1011 "Surface closure did not follow the reconstructed faces");
1014 CHKERR mb.get_entities_by_dimension(
1015 sets->getCubitMeshsetPtr(4,
BLOCKSET)->getMeshset(), 1, front);
1017 "Remeshing lost the FRONT meshset");
1019 const std::string path =
"cgal_remesh_" + test +
".h5m";
1021 CHKERR mb.create_meshset(MESHSET_SET, saved);
1022 CHKERR mb.add_entities(saved, output);
1023 std::vector<EntityHandle> written_sets{saved};
1024 for (
auto it = sets->getBegin();
it != sets->getEnd(); ++
it)
1025 written_sets.push_back(
it->getMeshset());
1026 std::map<EntityHandle, Range> memberships;
1027 for (
size_t i = 1;
i < written_sets.size(); ++
i) {
1028 const auto set = written_sets[
i];
1029 if (memberships.count(set))
1032 CHKERR mb.get_entities_by_handle(set, members,
false);
1033 memberships.emplace(set, members);
1034 const auto children = members.subset_by_type(MBENTITYSET);
1035 written_sets.insert(written_sets.end(), children.begin(), children.end());
1039 for (
const auto &[set, members] : memberships) {
1042 unite(intersect(members, output), members.subset_by_type(MBENTITYSET));
1045 const auto write_error =
mb.write_file(
1046 path.c_str(),
"MOAB",
nullptr, written_sets.data(), written_sets.size());
1047 for (
const auto &[set, members] : memberships) {
1049 CHKERR mb.add_entities(set, members);
1053 CHKERR reload.load_file(path.c_str());
1055 CHKERR reload.get_entities_by_type(0, MBTET, reloaded);
1056 CHKERR require(reloaded.size() == output_cells.size(),
1057 "H5M round trip changed output cells");
1061 Range expected_crack, saved_crack;
1062 for (
auto set : sets->getCubitMeshsetPtr(
std::regex(
"CRACK(.*)"))) {
1064 CHKERR mb.get_entities_by_dimension(set->getMeshset(), 2,
faces,
true);
1065 expected_crack.merge(intersect(
faces, output));
1067 for (
auto set : reload_sets->getCubitMeshsetPtr(
std::regex(
"CRACK(.*)")))
1068 CHKERR reload.get_entities_by_dimension(set->getMeshset(), 2, saved_crack,
1070 CHKERR require(saved_crack.size() == expected_crack.size(),
1071 "H5M round trip lost the CRACK classification");
1073 std::filesystem::remove(path);
1075 <<
"Remeshed " <<
cells.size() <<
" -> " << output_cells.size()
1076 <<
" cells; selected " <<
selected.size() <<
"; changed "
1077 <<
report.changedCells.size() <<
"; vertices inserted/removed/moved "
1078 <<
report.insertedVertices <<
'/' <<
report.removedVertices <<
'/'
1079 <<
report.movedVertices <<
"; minimum quality " <<
report.minQualityBefore
1080 <<
" -> " <<
report.minQualityAfter;
1087 "Tetrahedral remeshing checks\n");
std::vector< std::array< EntityHandle, 3 > > faces
Sorted keys.
std::vector< int > source
const Settings & settings
const std::vector< Vec > * points
std::vector< int > vertices
bool closure
The face (f0, f1, w) closes a corner at f0 or f1.
std::unordered_map< int, NodeConstraint > constraints
std::vector< Cell > cells
std::vector< double > empty
One value per component.
std::vector< std::array< double, 3 > > coordinates
#define CATCH_ERRORS
Catch errors.
#define MoFEMFunctionReturnHot(a)
Last executable line of each PETSc function used for error handling. Replaces return()
#define MoFEMFunctionBegin
First executable line of each MoFEM function, used for error handling. Final line of MoFEM functions ...
@ MOFEM_ATOM_TEST_INVALID
#define MoFEMFunctionReturn(a)
Last executable line of each PETSc function used for error handling. Replaces return()
#define CHKERR
Inline error check.
#define MOFEM_LOG(channel, severity)
Log.
FTensor::Index< 'i', SPACE_DIM > i
const double c
speed of light (cm/ns)
const double v
phase velocity of light in medium (cm/ns)
FTensor::Index< 'j', 3 > j
FTensor::Index< 'k', 3 > k
PetscErrorCode MoFEMErrorCode
MoFEM/PETSc error code.
std::bitset< BITREFLEVEL_SIZE > BitRefLevel
Bit structure attached to each entity identifying to what mesh entity is attached.
implementation of Data Operators for Forces and Sources
PetscErrorCode PetscOptionsGetReal(PetscOptions *, const char pre[], const char name[], PetscReal *dval, PetscBool *set)
PetscErrorCode PetscOptionsGetBool(PetscOptions *, const char pre[], const char name[], PetscBool *bval, PetscBool *set)
MoFEMErrorCode TestingInterface::checkValue< TestType::SCALAR >(const std::string &check_name, PetscReal actual, PetscReal expected, Tolerance tolerance, Sev error_severity, Sev success_severity) const
PetscErrorCode PetscOptionsGetString(PetscOptions *, const char pre[], const char name[], char str[], size_t size, PetscBool *set)
MoFEMErrorCode run(MoFEM::Interface &m_field)
virtual moab::Interface & get_moab()=0
virtual MoFEMErrorCode rebuild_database(int verb=DEFAULT_VERBOSITY)=0
Clear database and initialize it once again.
static MoFEMErrorCode Initialize(int *argc, char ***args, const char file[], const char help[])
Initializes the MoFEM database PETSc, MOAB and MPI.
static MoFEMErrorCode Finalize()
Checks for options to be called at the conclusion of the program.
Deprecated interface functions.
static boost::shared_ptr< SinkType > createSink(boost::shared_ptr< std::ostream > stream_ptr, std::string comm_filter)
Create a sink object.
Interface for managing meshsets containing materials and boundary conditions.
MoFEMErrorCode setMeshsetFromFile(const string file_name, const bool clean_file_options=true)
add blocksets reading config file
std::vector< std::array< int, 3 > > boundary
std::vector< std::array< int, 2 > > featureEdges
std::vector< int > edgeLabels
std::vector< std::array< int, 4 > > cells
Zero-based point indices.
std::vector< std::array< double, 3 > > points
std::vector< int > vertexIds
std::vector< int > surfaceLabels
MoFEMErrorCode getInterface(IFACE *&iface) const
Get interface reference to pointer of interface.