23using Face = std::array<int, 3>;
24using Cell = std::array<int, 4>;
26constexpr int nx = 6, ny = 4;
27const std::vector<double> levels{-2, -1, 0, 1, 2};
28constexpr int crackLevel = 2, crackX = 3;
37double det(
const std::vector<std::array<double, 3>> &p,
const Cell &
c) {
38 const auto d = [&](
int a,
int b) {
39 return std::array<double, 3>{p[
c[b]][0] - p[
c[
a]][0],
40 p[
c[b]][1] - p[
c[
a]][1],
41 p[
c[b]][2] - p[
c[
a]][2]};
43 const auto u =
d(0, 1),
v =
d(0, 2),
w =
d(0, 3);
44 return u[0] * (
v[1] *
w[2] -
v[2] *
w[1]) -
45 u[1] * (
v[0] *
w[2] -
v[2] *
w[0]) +
46 u[2] * (
v[0] *
w[1] -
v[1] *
w[0]);
52 const int planar = (nx + 1) * (ny + 1);
53 const auto id = [](
int i,
int j) {
return j * (nx + 1) +
i; };
54 std::vector<std::array<double, 3>>
points;
55 for (
double z : levels)
56 for (
int j = 0;
j <= ny; ++
j)
57 for (
int i = 0;
i <= nx; ++
i)
59 std::vector<std::array<int, 3>>
triangles;
60 std::vector<char> cracked;
61 for (
int j = 0;
j != ny; ++
j)
62 for (
int i = 0;
i != nx; ++
i) {
65 cracked.push_back(
i < crackX);
66 cracked.push_back(
i < crackX);
68 std::vector<Cell>
cells;
69 for (
int l = 0;
l + 1 <
static_cast<int>(levels.size()); ++
l)
71 std::sort(
t.begin(),
t.end());
72 const int b0 =
l * planar +
t[0], b1 =
l * planar +
t[1],
73 b2 =
l * planar +
t[2];
74 const int t0 = b0 + planar, t1 = b1 + planar, t2 = b2 + planar;
76 {Cell{b0, b1, b2, t2}, Cell{b0, b1, t1, t2}, Cell{b0, t0, t1, t2}}) {
78 std::swap(
c[2],
c[3]);
83 for (
size_t v = 0;
v !=
points.size(); ++
v) {
86 const int gid =
v + 1;
87 CHKERR mb.tag_set_data(
mb.globalId_tag(), &vertex, 1, &gid);
91 for (
const auto &
c :
cells) {
95 CHKERR mb.create_element(MBTET, conn, 4, tet);
101 const EntityHandle conn[] = {
106 CHKERR mb.get_adjacencies(conn, 3, 2,
true, face);
114 CHKERR mb.write_file(
"crack_input.h5m",
"MOAB");
116 <<
"Wrote crack_input.h5m: " << tets.size() <<
" tetrahedra, "
117 <<
crack.size() <<
" crack faces";
120 Range elements = tets;
121 elements.merge(
crack);
122 EntityHandle quadratic;
123 CHKERR mb.create_meshset(MESHSET_SET, quadratic);
124 CHKERR mb.add_entities(quadratic, elements);
125 CHKERR mb.convert_entities(quadratic,
true,
false,
false);
126 CHKERR mb.delete_entities(&quadratic, 1);
127 CHKERR mb.write_file(
"crack_input_quadratic.h5m",
"MOAB");
133 std::map<int, std::array<double, 3>>
points;
134 std::set<Cell>
cells;
135 std::set<Face>
crack;
136 std::vector<Cell> orderedCells;
138 std::map<int, int>
index;
140 double skinArea = 0, volume = 0;
141 int inverted = 0, overfull = 0, wrongLevel = 0, danglingParents = 0;
142 int wrongCrackTag = -1;
143 int highOrder = 0, orphanNodes = 0;
147 Snapshot &snapshot) {
157 CHKERR mb.get_entities_by_type(0, MBTET, tets);
162 std::array<double, 3> x;
163 CHKERR mb.tag_get_data(
mb.globalId_tag(), &
v, 1, &
id);
165 snapshot.index[id] = snapshot.coordinates.size();
166 snapshot.coordinates.push_back(x);
167 snapshot.points[id] = x;
169 const auto key = [&](EntityHandle entity,
auto &
result) {
171 const EntityHandle *conn;
173 CHKERR mb.get_connectivity(entity, conn, count,
true);
178 Range all, used, nodes;
179 CHKERR mb.get_entities_by_handle(0, all);
180 const auto elements = subtract(subtract(all, all.subset_by_type(MBVERTEX)),
181 all.subset_by_type(MBENTITYSET));
182 for (
auto e : elements) {
183 const EntityHandle *conn;
185 CHKERR mb.get_connectivity(e, conn, count,
false);
186 snapshot.highOrder +=
187 count != moab::CN::VerticesPerEntity(
mb.type_from_handle(e));
189 CHKERR mb.get_connectivity(elements, used,
false);
190 CHKERR mb.get_entities_by_type(0, MBVERTEX, nodes);
191 snapshot.orphanNodes = subtract(nodes, used).size();
193 std::map<Face, int> face_count;
194 for (
auto tet : tets) {
198 for (
int n = 0;
n != 4; ++
n)
199 local[
n] = snapshot.index.at(
c[
n]);
200 const double d = det(snapshot.coordinates, local);
201 snapshot.inverted += !(
d > 0);
202 snapshot.volume +=
d / 6;
204 std::sort(sorted.begin(), sorted.end());
205 snapshot.cells.insert(sorted);
206 snapshot.orderedCells.push_back(local);
207 for (
int f = 0;
f != 4; ++
f) {
209 for (
int n = 0,
k = 0;
n != 4; ++
n)
211 face[
k++] = sorted[
n];
215 for (
const auto &[face, count] : face_count) {
216 snapshot.overfull += count > 2;
218 ++snapshot.skinFaces;
219 const auto &
a = snapshot.points.at(face[0]);
220 const auto &b = snapshot.points.at(face[1]);
221 const auto &
c = snapshot.points.at(face[2]);
222 const std::array<double, 3> u{b[0] -
a[0], b[1] -
a[1], b[2] -
a[2]},
223 v{
c[0] -
a[0],
c[1] -
a[1],
c[2] -
a[2]};
224 const std::array<double, 3>
n{u[1] *
v[2] - u[2] *
v[1],
225 u[2] *
v[0] - u[0] *
v[2],
226 u[0] *
v[1] - u[1] *
v[0]};
228 std::sqrt(
n[0] *
n[0] +
n[1] *
n[1] +
n[2] *
n[2]) / 2;
233 sets->getCubitMeshsetPtr(1,
BLOCKSET)->getMeshset(), MBTRI,
crack,
true);
237 std::sort(face.begin(), face.end());
238 snapshot.crack.insert(face);
241 if (
mb.tag_get_handle(
"CRACK_ID", 1, MB_TYPE_INTEGER, crack_tag) ==
245 std::vector<int> ids(
faces.size());
247 snapshot.wrongCrackTag = 0;
248 for (
size_t i = 0;
i !=
faces.size(); ++
i) {
250 snapshot.wrongCrackTag += ids[
i] != (on_crack ? 1 : 0);
253 if (expected_bit >= 0) {
256 CHKERR mb.get_entities_by_handle(0, all);
257 all = subtract(all, all.subset_by_type(MBENTITYSET));
263 on_level = subtract(on_level, on_level.subset_by_type(MBENTITYSET));
264 snapshot.wrongLevel =
265 subtract(tets, on_level).size() + subtract(on_level, all).size();
269 other = subtract(other, other.subset_by_type(MBENTITYSET));
270 snapshot.wrongLevel += other.size();
271 const auto parent_tag = bits->get_th_RefParentHandle();
272 for (
auto entity : all) {
274 if (
mb.tag_get_data(parent_tag, &entity, 1, &
parent) == MB_SUCCESS &&
276 ++snapshot.danglingParents;
282std::string stepFile(
const std::string &output,
int step) {
283 std::filesystem::path path(output);
284 std::ostringstream
name;
285 name << path.stem().string() <<
'_' << std::setw(4) << std::setfill(
'0')
287 << (path.has_extension() ? path.extension().string()
288 : std::string(
".h5m"));
289 return (path.parent_path() /
name.str()).
string();
294 char output[PETSC_MAX_PATH_LEN] =
"crack.h5m";
295 PetscInt steps = 1, input_bit = 0, output_bit = 1;
297 sizeof(output),
nullptr);
305 CHKERR load(
"crack_input.h5m", -1, reference);
306 size_t previous = reference.crack.size();
307 int not_growing = 0, off_plane = 0, non_manifold = 0, crack_on_skin = 0;
308 int inverted = 0, overfull = 0, wrong_level = 0, dangling = 0;
309 int wrong_tag = 0, high_order = 0, orphans = 0;
311 double volume_error = 0, skin_error = 0;
312 for (
int step = 1; step <= steps; ++step) {
313 const auto file = stepFile(output, step);
314 CHKERR require(std::filesystem::exists(file),
"Missing step file " + file);
316 CHKERR load(file, step % 2 ? output_bit : input_bit,
s);
317 not_growing +=
s.crack.size() <
previous + 1;
319 std::map<std::array<int, 2>,
int> edges;
320 for (
const auto &face :
s.
crack) {
322 off_plane +=
s.
points.at(
v)[2] != 0;
323 ++edges[{face[0], face[1]}];
324 ++edges[{face[1], face[2]}];
325 ++edges[{face[0], face[2]}];
327 for (
const auto &[edge, count] : edges)
328 non_manifold += count > 2;
330 std::map<Face, int> face_count;
331 for (
const auto &cell :
s.
cells)
332 for (
int f = 0;
f != 4; ++
f) {
334 for (
int n = 0,
k = 0;
n != 4; ++
n)
339 for (
const auto &face :
s.
crack)
340 crack_on_skin += face_count[face] != 2;
341 inverted +=
s.inverted;
342 overfull +=
s.overfull;
343 wrong_level +=
s.wrongLevel;
344 dangling +=
s.danglingParents;
345 wrong_tag +=
s.wrongCrackTag < 0 ? 1 :
s.wrongCrackTag;
346 high_order +=
s.highOrder;
347 orphans +=
s.orphanNodes;
348 skin_count +=
s.skinFaces != reference.skinFaces;
350 std::max(volume_error, std::abs(
s.volume - reference.volume));
352 std::max(skin_error, std::abs(
s.skinArea - reference.skinArea));
354 CHKERR testing->checkValue<TestType::SCALAR>(
"Crack grows every step",
355 not_growing, 0, {0, 0});
356 CHKERR testing->checkValue<TestType::SCALAR>(
"Crack stays in its plane",
357 off_plane, 0, {0, 0});
358 CHKERR testing->checkValue<TestType::SCALAR>(
"Crack is a manifold",
359 non_manifold, 0, {0, 0});
360 CHKERR testing->checkValue<TestType::SCALAR>(
"Crack faces are interior",
361 crack_on_skin, 0, {0, 0});
362 CHKERR testing->checkValue<TestType::SCALAR>(
"Inverted tetrahedra", inverted,
364 CHKERR testing->checkValue<TestType::SCALAR>(
"Faces with three cells",
365 overfull, 0, {0, 0});
366 CHKERR testing->checkValue<TestType::SCALAR>(
"Entities off the active level",
367 wrong_level, 0, {0, 0});
368 CHKERR testing->checkValue<TestType::SCALAR>(
"Dangling parent references",
369 dangling, 0, {0, 0});
371 "Faces with a wrong CRACK_ID tag", wrong_tag, 0, {0, 0});
372 CHKERR testing->checkValue<TestType::SCALAR>(
"Higher-order elements",
373 high_order, 0, {0, 0});
374 CHKERR testing->checkValue<TestType::SCALAR>(
"Unused nodes", orphans, 0,
376 CHKERR testing->checkValue<TestType::SCALAR>(
"Skin face count changed",
377 skin_count, 0, {0, 0});
378 CHKERR testing->checkError<TestType::SCALAR>(
"Volume", volume_error,
379 reference.volume, {0, 1e-12});
380 CHKERR testing->checkError<TestType::SCALAR>(
"Skin area", skin_error,
381 reference.skinArea, {0, 1e-12});
383 <<
"Verified " << steps <<
" crack extension steps; crack "
384 << reference.crack.size() <<
" -> " <<
previous <<
" faces";
390 char first[PETSC_MAX_PATH_LEN] =
"", second[PETSC_MAX_PATH_LEN] =
"";
391 PetscBool expect_equal = PETSC_TRUE;
395 sizeof(second),
nullptr);
400 CHKERR load(second, -1, b);
402 a.points == b.points &&
a.cells == b.cells &&
a.crack == b.crack;
404 std::string(
"Step files ") + (expect_equal ?
"equal" :
"differ"), equal,
405 expect_equal ? 1 : 0, {0, 0});
416 CHKERR mb.load_file(
"crack_input.h5m");
422 CHKERR mb.get_entities_by_type(0, MBTET, tets);
425 for (
int dim : {1, 2}) {
427 CHKERR mb.get_adjacencies(tets, dim,
true, adjacent,
428 moab::Interface::UNION);
434 sets->getCubitMeshsetPtr(1,
BLOCKSET)->getMeshset(), MBTRI,
crack,
true);
436 std::map<EntityHandle, std::array<double, 3>> before;
437 std::set<int> input_ids;
438 std::array<EntityHandle, 2> ends{0, 0};
440 std::array<double, 3> x;
443 CHKERR mb.tag_get_data(
mb.globalId_tag(), &
v, 1, &
id);
445 input_ids.insert(
id);
446 if (x == std::array<double, 3>{3, 1, 0})
448 if (x == std::array<double, 3>{3, 2, 0})
452 CHKERR mb.get_adjacencies(ends.data(), 2, 1,
false, edge,
453 moab::Interface::INTERSECT);
454 CHKERR require(edge.size() == 1,
"Front edge (3,1,0)-(3,2,0) not found");
455 const double angle = 30 * M_PI / 180;
457 edge.front(), {std::cos(
angle), 0, std::sin(
angle)}};
458 auto volume_of = [&](
const Range &
cells,
double &volume,
int &inverted) {
462 for (
auto tet :
cells) {
463 const EntityHandle *conn;
465 CHKERR mb.get_connectivity(tet, conn, count,
true);
466 std::vector<std::array<double, 3>> p(4);
467 for (
int n = 0;
n != 4; ++
n)
468 CHKERR mb.get_coords(&conn[
n], 1, p[
n].data());
469 const double d = det(p, {0, 1, 2, 3});
470 inverted += !(
d > 0);
475 double reference_volume;
477 CHKERR volume_of(tets, reference_volume, inverted);
481 EntityHandle face = 0;
483 CHKERR bridge->getCrackExtension().extendCrack(
486 CHKERR require(face != 0,
"Kinked extension found no candidate");
492 const auto parent_tag = bits->get_th_RefParentHandle();
493 const auto parent_of = [&](EntityHandle e) {
498 const auto level_of = [&](EntityHandle e) {
504 const EntityHandle *face_conn;
506 CHKERR mb.get_connectivity(face, face_conn, count,
true);
507 EntityHandle
moved = 0;
508 for (
int n = 0;
n != 3; ++
n)
509 if (face_conn[
n] != ends[0] && face_conn[
n] != ends[1])
515 "Bridge moved vertex has a fresh ID", !input_ids.count(moved_id), 1,
518 "Bridge moved vertex parent is the source vertex",
519 before.count(old_vertex) && level_of(old_vertex) ==
source, 1, {0, 0});
520 std::array<double, 3> x;
521 CHKERR mb.get_coords(&old_vertex, 1, x.data());
523 "Bridge source vertex keeps its coordinates", x == before[old_vertex], 1,
527 Range on_output, on_source;
530 on_output = subtract(on_output, on_output.subset_by_type(MBENTITYSET));
532 for (
auto e : subtract(on_output, on_source)) {
537 CHKERR testing->checkValue<TestType::SCALAR>(
"Bridge created entities",
540 "Bridge created entities without a source parent", orphans, 0, {0, 0});
541 int moved_sources = 0;
542 for (
const auto &[
v, coords] : before) {
543 std::array<double, 3> now;
545 moved_sources += now != coords;
548 "Bridge source vertices unchanged", moved_sources, 0, {0, 0});
550 CHKERR volume_of(on_source.subset_by_type(MBTET), volume, inverted);
551 CHKERR testing->checkValue<TestType::SCALAR>(
"Bridge source level cell count",
552 on_source.num_of_type(MBTET),
553 tets.size(), {0, 0});
555 "Bridge source level volume", volume, reference_volume, {0, 1e-12});
556 CHKERR volume_of(on_output.subset_by_type(MBTET), volume, inverted);
557 CHKERR testing->checkValue<TestType::SCALAR>(
"Bridge output volume", volume,
558 reference_volume, {0, 1e-12});
559 CHKERR testing->checkValue<TestType::SCALAR>(
"Bridge output inverted cells",
560 inverted, 0, {0, 0});
562 "Bridge output closure returned", subtract(on_output, entities).empty(),
567 Range remaining, all;
569 CHKERR mb.get_entities_by_handle(0, all);
571 for (
auto e : subtract(all, all.subset_by_type(MBENTITYSET))) {
578 CHKERR testing->checkValue<TestType::SCALAR>(
"Retired level has no entities",
579 remaining.size(), 0, {0, 0});
581 "Retirement leaves no dangling parents", dangling, 0, {0, 0});
583 "Retirement keeps the output cells",
cells.size(),
584 on_output.num_of_type(MBTET), {0, 0});
586 "Retirement keeps volume", volume, reference_volume, {0, 1e-12});
588 "Retired old vertex is deleted", all.find(old_vertex) == all.end(), 1,
593 EntityHandle none = 0;
594 CHKERR PetscPushErrorHandler(PetscIgnoreErrorHandler,
nullptr);
595 const auto error = bridge->getCrackExtension().extendCrack(
598 CHKERR PetscPopErrorHandler();
599 CHKERR testing->checkValue<TestType::SCALAR>(
"Bridge rejects equal levels",
600 error != 0, 1, {0, 0});
610 for (
int mode = 0; mode != 6; ++mode) {
614 CHKERR mb.load_file(
"crack_input.h5m");
616 Range tets, geometry;
617 CHKERR mb.get_entities_by_type(0, MBTET, tets);
619 for (
int dim : {0, 1, 2}) {
622 moab::Interface::UNION);
633 const auto crack_set = sets->getCubitMeshsetPtr(1,
BLOCKSET)->getMeshset();
634 std::map<std::array<int, 3>, EntityHandle> nodes;
640 nodes[{
static_cast<int>(x[0]),
static_cast<int>(x[1]),
641 static_cast<int>(x[2])}] =
v;
643 const auto node = [&](
int x,
int y) {
return nodes.at({x, y, 0}); };
644 const bool joining_fixture = mode == 3 || mode == 4;
645 if (joining_fixture) {
646 for (
const auto &conn :
std::vector<
std::array<EntityHandle, 3>>{
647 {node(3, 0), node(4, 0), node(4, 1)},
648 {node(3, 0), node(4, 1), node(3, 1)},
649 {node(3, 1), node(4, 2), node(3, 2)}}) {
651 CHKERR mb.get_adjacencies(conn.data(), 3, 2,
false, face,
652 moab::Interface::INTERSECT);
653 CHKERR require(face.size() == 1,
"Ordered fixture face exists");
654 CHKERR mb.add_entities(crack_set, face);
659 settings.extension.angleToleranceDegrees = 0.5;
660 settings.extension.maxMoveRelative = mode == 5 ? 0.5 : 0;
661 settings.angleMaxDegrees = mode == 2 || mode == 5 ? 0.5 : 20;
665 "Preview respects join policy",
666 growth.settings().extension.lookAheadJoin,
settings.join, {0, 0});
670 const auto find_edge = [&](EntityHandle
a, EntityHandle b) {
671 for (
auto edge : front) {
672 const EntityHandle *conn;
675 "Ordered fixture edge");
676 if ((conn[0] ==
a && conn[1] == b) || (conn[0] == b && conn[1] ==
a))
679 return EntityHandle(0);
681 const auto first = !joining_fixture ? find_edge(node(3, 1), node(3, 2))
682 : find_edge(node(3, 3), node(3, 4));
683 const auto second = find_edge(node(3, 2), node(3, 3));
684 CHKERR require(first && second,
"Ordered fixture front edges exist");
685 std::vector<EntityHandle> handles{first, second};
686 if (joining_fixture) {
688 for (
auto edge : front)
690 handles.push_back(edge);
696 "Ordered fixture has a later eligible join");
698 const auto it = std::find(handles.begin(), handles.end(),
selected);
699 std::iter_swap(handles.begin(),
it);
702 std::vector<Growth::Pair> pairs;
703 for (
auto edge : handles)
704 pairs.push_back(growth.edgeIds(edge));
705 const auto direction = [&](EntityHandle edge,
const Range &,
706 std::array<double, 3> &
d) {
708 !joining_fixture && edge == first ? std::tan(13 * M_PI / 180) : 0};
713 CHKERR growth.extend(pairs, direction, step);
715 CHKERR growth.advanceOrdered(pairs, direction, step);
716 const int expected = mode == 3 ? step.extended
717 : mode == 0 || mode == 2 || mode == 5 ? 1
719 CHKERR require(step.extended >= 0 &&
720 static_cast<std::size_t
>(step.extended) < pairs.size(),
721 "Selected priority exists");
723 CHKERR require(step.extended > 0,
724 "A global gap beats the earlier feasible extension");
725 const std::string
tag =
"Ordered case " + std::to_string(mode);
727 tag +
" selected priority", step.extended, expected, {0, 0});
729 tag +
" selected edge", step.edge == pairs[expected], 1, {0, 0});
731 tag +
" selected operation",
733 (joining_fixture ? Growth::Kind::Closure : Growth::Kind::Extension),
737 "A flip-only extension beats an earlier vertex move",
738 step.candidate.moveRelative, 0, {0, 0});
741 tag +
" preferred edge exhausts angle tolerance",
742 step.toleranceDegrees >
settings.extension.angleToleranceDegrees, 1,
753 char file[PETSC_MAX_PATH_LEN] =
"";
756 sizeof(file),
nullptr);
763 CHKERR mb.get_entities_by_type(0, MBTET, tets);
765 sets->getCubitMeshsetPtr(block,
BLOCKSET)->getMeshset(), MBTRI,
crack,
767 using P = std::array<double, 3>;
768 const auto coords = [&](
const EntityHandle *conn,
int n) {
770 for (
int i = 0;
i !=
n; ++
i)
775 double min_quality = 1, volume = 0;
776 std::map<std::array<EntityHandle, 3>,
int> face_count;
777 for (
auto tet : tets) {
778 const EntityHandle *conn;
780 CHKERR mb.get_connectivity(tet, conn,
n,
true);
781 const auto p = coords(conn, 4);
782 const double d = det(p, {0, 1, 2, 3});
783 inverted += !(
d > 0);
786 for (
int i = 0;
i != 4; ++
i)
787 for (
int k = 0;
k != 3; ++
k)
788 x[3 *
i +
k] = p[
i][
k];
790 for (
int f = 0;
f != 4; ++
f) {
791 std::array<EntityHandle, 3>
key;
792 for (
int i = 0,
k = 0;
i != 4; ++
i)
795 std::sort(
key.begin(),
key.end());
800 for (
const auto &[
key,
n] : face_count)
802 int not_interior = 0;
804 std::map<std::array<EntityHandle, 2>,
int> crack_edges;
805 std::set<EntityHandle> crack_vertices;
807 const EntityHandle *conn;
810 crack_vertices.insert(conn, conn +
n);
811 std::array<EntityHandle, 3>
key{conn[0], conn[1], conn[2]};
812 std::sort(
key.begin(),
key.end());
813 not_interior += face_count[
key] != 2;
814 const auto p = coords(conn, 3);
816 for (
int k = 0;
k != 3; ++
k) {
817 u[
k] = p[1][
k] - p[0][
k];
818 v[
k] = p[2][
k] - p[0][
k];
820 const P
c{u[1] *
v[2] - u[2] *
v[1], u[2] *
v[0] - u[0] *
v[2],
821 u[0] *
v[1] - u[1] *
v[0]};
822 area += std::sqrt(
c[0] *
c[0] +
c[1] *
c[1] +
c[2] *
c[2]) / 2;
823 for (
int k = 0;
k != 3; ++
k) {
824 std::array<EntityHandle, 2> e{
key[
k],
key[(
k + 1) % 3]};
825 std::sort(e.begin(), e.end());
831 std::set<std::array<EntityHandle, 2>> skin_edges;
832 for (
const auto &[
key,
n] : face_count) {
835 for (
int k = 0;
k != 3; ++
k) {
836 std::array<EntityHandle, 2> e{
key[
k],
key[(
k + 1) % 3]};
837 std::sort(e.begin(), e.end());
838 skin_edges.insert(e);
841 int non_manifold = 0, front = 0;
842 double front_length = 0;
843 std::map<EntityHandle, std::set<EntityHandle>> front_graph;
844 for (
const auto &[e,
n] : crack_edges) {
845 non_manifold +=
n > 2;
846 if (
n == 1 && !skin_edges.count(e)) {
847 front_graph[e[0]].insert(e[1]);
848 front_graph[e[1]].insert(e[0]);
850 const auto p = coords(e.data(), 2);
851 front_length += std::sqrt((p[1][0] - p[0][0]) * (p[1][0] - p[0][0]) +
852 (p[1][1] - p[0][1]) * (p[1][1] - p[0][1]) +
853 (p[1][2] - p[0][2]) * (p[1][2] - p[0][2]));
859 std::vector<int> holes;
861 std::set<std::vector<EntityHandle>> cycles;
862 for (
const auto &[
a,
nb] : front_graph)
866 std::map<EntityHandle, EntityHandle>
previous{{
a,
a}};
867 std::vector<EntityHandle> layer{
a};
868 for (
int depth = 0; depth != 7 && !
previous.count(b); ++depth) {
869 std::vector<EntityHandle> next;
871 for (auto u : front_graph[
v])
872 if (!(
v ==
a && u == b) && !
previous.count(u)) {
880 std::vector<EntityHandle> cycle;
884 std::sort(cycle.begin(), cycle.end());
885 cycles.insert(cycle);
887 for (
const auto &
c : cycles)
888 holes.push_back(
c.
size());
889 std::sort(holes.begin(), holes.end());
891 std::ostringstream hole_sizes;
893 hole_sizes <<
' ' <<
h;
894 const auto euler =
static_cast<long>(crack_vertices.size()) -
895 static_cast<long>(crack_edges.size()) +
896 static_cast<long>(
crack.size());
898 <<
"Validate " <<
file <<
": gaps " << holes.size()
899 <<
" (front edges each:" << hole_sizes.str() <<
"), cells " << tets.size()
900 <<
", volume " << volume <<
", minimum quality " << min_quality
901 <<
", crack faces " <<
crack.size() <<
", crack area " << area
902 <<
", front edges " << front <<
", front length " << front_length
903 <<
", non-manifold crack edges " << non_manifold
904 <<
", Euler characteristic " << euler;
905 PetscInt expected_euler;
906 PetscBool has_expected_euler;
908 &expected_euler, &has_expected_euler);
909 if (has_expected_euler)
910 CHKERR testing->checkValue<TestType::SCALAR>(
"Crack Euler characteristic",
911 euler, expected_euler, {0, 0});
912 CHKERR testing->checkValue<TestType::SCALAR>(
"Inverted tetrahedra", inverted,
914 CHKERR testing->checkValue<TestType::SCALAR>(
"Faces with three cells",
915 overfull, 0, {0, 0});
916 CHKERR testing->checkValue<TestType::SCALAR>(
"Crack faces not interior",
917 not_interior, 0, {0, 0});
923int main(
int argc,
char *argv[]) {
925 "Crack extension tool checks\n");
931 char stage[PETSC_MAX_PATH_LEN] =
"";
933 sizeof(stage),
nullptr);
934 const std::string
name = stage;
935 if (
name ==
"prepare")
937 else if (
name ==
"check")
939 else if (
name ==
"compare")
941 else if (
name ==
"bridge")
942 CHKERR bridgeStage(m_field);
943 else if (
name ==
"validate")
944 CHKERR validateStage(m_field);
945 else if (
name ==
"ordered")
946 CHKERR orderedStage(m_field);
949 "Use -fixture_stage prepare, check, compare, bridge, validate or "
CGALInterfaceImpl & owner
std::map< EntityHandle, int > index
std::vector< std::array< EntityHandle, 3 > > faces
Sorted keys.
CGALTools::CrackExtensionCandidate candidate
std::vector< int > created
int h
Corner vertex and its two front neighbours.
std::vector< int > source
const Settings & settings
const std::vector< Vec > * points
bool angle
Radians between candidate face and target plane.
std::vector< int > vertices
Vec t
Removal: the ring edge.
std::vector< int > parent
bool closure
The face (f0, f1, w) closes a corner at f0 or f1.
std::vector< Cell > cells
Crack growth one step at a time on two bit levels, on top of CGALInterface. Not included by MoFEM....
std::map< EntityHandle, std::pair< bool, std::vector< double > > > previous
std::vector< std::array< double, 3 > > coordinates
#define CATCH_ERRORS
Catch errors.
#define MYPCOMM_INDEX
default communicator number PCOMM
#define MoFEMFunctionBegin
First executable line of each MoFEM function, used for error handling. Final line of MoFEM functions ...
#define CHK_MOAB_THROW(err, msg)
Check error code of MoAB function and throw MoFEM exception.
@ 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.
MoFEMErrorCode addMeshset(const CubitBCType cubit_bc_type, const int ms_id, const std::string name="")
Add CUBIT meshset to manager.
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< 'l', 3 > l
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 PetscOptionsGetInt(PetscOptions *, const char pre[], const char name[], PetscInt *ivalue, 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)
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.
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
MoFEMErrorCode getInterface(IFACE *&iface) const
Get interface reference to pointer of interface.