13struct CGALInterfaceImpl;
16template <
class T, std::
size_t N> std::array<T, N> sorted(std::array<T, N>
a) {
17 std::sort(
a.begin(),
a.end());
23 std::vector<std::array<double, 3>> &
points,
24 std::vector<int> &ids) {
26 std::vector<double> coords(3 *
vertices.size());
31 for (std::size_t
i = 0;
i !=
points.size(); ++
i)
32 points[
i] = {coords[3 *
i], coords[3 *
i + 1], coords[3 *
i + 2]};
38struct CrackExtensionImpl final : CGALInterface::CrackExtension {
39 explicit CrackExtensionImpl(CGALInterfaceImpl &owner);
42 const Range &crack_faces,
44 const std::vector<CrackFrontRequest> &requests,
45 const CGALTools::CrackExtensionSettings &
settings,
46 Range &entities, EntityHandle &new_face,
47 CGALTools::CrackExtensionCandidate *applied,
48 CGALTools::CrackExtensionReport *
report,
49 Range *closure_faces)
override;
53 const CGALTools::CrackExtensionSettings &
settings,
Range &entities,
54 EntityHandle &new_face, CGALTools::CrackExtensionCandidate *applied,
55 CGALTools::CrackExtensionReport *
report,
Range *closure_faces)
override;
58 const std::vector<CrackFrontRequest> &requests,
59 const CGALTools::CrackExtensionSettings &
settings,
60 Range &entities, EntityHandle &new_face,
61 CGALTools::CrackExtensionCandidate *applied,
62 CGALTools::CrackExtensionReport *
report,
63 Range *closure_faces)
override;
66 Range &fill_faces)
override;
69 std::vector<int> *categories,
70 const std::vector<EntityHandle> &front_order,
71 EntityHandle *selected_front,
72 bool gaps_only)
override;
79 void closeSearchCache()
override {
80 if (--searchCacheDepth == 0)
87 enum class Change { EXTEND, CLOSE, JOIN };
92 const std::vector<CrackFrontRequest> &requests,
93 const CGALTools::CrackExtensionSettings &
settings,
94 Range &entities, EntityHandle &new_face,
95 CGALTools::CrackExtensionCandidate *applied,
96 CGALTools::CrackExtensionReport *
report,
97 Range *closure_faces);
101 struct CrackClassification {
104 std::vector<std::array<EntityHandle, 3>>
faces;
105 std::vector<std::array<EntityHandle, 2>>
curves;
106 bool isFace(
const std::array<EntityHandle, 3> &
key)
const {
109 bool isCurve(
const std::array<EntityHandle, 2> &
key)
const {
120 template <std::
size_t N>
121 std::array<EntityHandle, N>
key(
const std::array<int, N> &indices)
const {
122 std::array<EntityHandle, N> handles;
123 for (std::size_t
n = 0;
n !=
N; ++
n)
125 return sorted(handles);
142 const Range &constrained)
const {
152 std::shared_ptr<SearchState> &
state);
155 const CrackPatch *&patch)
const;
160 std::shared_ptr<SearchState> &
state,
161 const CrackPatch *&patch);
163 const Range &crack_faces,
165 CrackClassification &
result)
const;
167 const Range &crack_faces,
169 CrackPatch &patch)
const;
185 const Range &source_cells,
186 CrackChange &change)
const;
190 publishCrackChange(
const CrackPatch &patch,
const CrackChange &change,
193 Range &entities, EntityHandle &new_face,
194 Range *closure_faces);
198 resolveCrackFaces(
const CrackPatch &patch,
199 const CGALTools::CrackExtensionCandidate &
candidate,
200 EntityHandle moved_vertex,
bool create,
const Range *within,
201 EntityHandle &new_face,
Range *closure_faces)
const;
206 const std::vector<std::array<int, 3>> &indexed,
210struct CGALInterfaceImpl final : CGALInterface {
211 explicit CGALInterfaceImpl(
const Core &core)
214 logging::core::get()->add_sink(
222 UnknownInterface **iface)
const override {
223 *iface =
const_cast<CGALInterfaceImpl *
>(
this);
227 CGALTools &getTools()
override {
return tools; }
229 Range &entities, EntityHandle &volume,
230 EntityHandle &
surface)
override;
235 const CGALTools::RemeshSettings &
settings,
236 CGALTools::RemeshReport &
report)
override;
249 CrackExtension &getCrackExtension()
override {
return crackExtension; }
253 friend struct CrackExtensionImpl;
263 moab::Interface::UNION);
264 for (
auto face :
faces) {
266 CHKERR mb.get_adjacencies(&face, 1, 3,
false, adjacent);
267 adjacent = intersect(adjacent,
cells);
268 if (adjacent.size() != 1)
271 CHKERR mb.side_number(adjacent.front(), face, side, sense, offset);
274 const EntityHandle *nodes;
276 CHKERR mb.get_connectivity(face, nodes, count,
false);
277 std::vector<EntityHandle> conn(nodes, nodes + count);
278 std::swap(conn[1], conn[2]);
280 const auto first = moab::CN::HONodeIndex(MBTRI, count, 1, 0);
281 const auto last = moab::CN::HONodeIndex(MBTRI, count, 1, 2);
282 if (first >= 0 && last >= 0)
283 std::swap(conn[first], conn[last]);
284 CHKERR mb.set_connectivity(face, conn.data(), count);
297 for (
int dim : {1, 2}) {
300 moab::Interface::UNION);
309 "%s runs on one rank; the distributed workflow is not "
322 std::map<unsigned long long, std::unique_ptr<ManagedMesh>>
meshes;
327 MoFEMErrorCode allocateVertexIds(
size_t count, std::vector<int> &ids)
const {
335 CHKERR mb.tag_get_data(
mb.globalId_tag(), &vertex, 1, &
id);
336 maximum = std::max(maximum,
id);
338 if (count >
static_cast<size_t>(INT_MAX - maximum))
341 std::iota(ids.begin(), ids.end(),
static_cast<long long>(maximum) + 1);
350 [&](EntityHandle,
BitRefLevel &level) { level &= ~bit; });
352 CHKERR mb.get_entities_by_handle(0, after);
353 const auto created = subtract(after, before);
354 const auto geometry =
359 for (
int dim = 3; dim >= 0; --dim)
360 CHKERR mb.delete_entities(geometry.subset_by_dimension(dim));
371 subtract(sets, before.subset_by_type(MBENTITYSET)));
379 "CGAL mesh level must be nonzero");
394 <<
"Higher-order nodes are ignored by CGAL; using corner connectivity";
396 std::map<EntityHandle, int> indices;
398 indices.emplace(
v, static_cast<
int>(indices.
size()));
401 const EntityHandle *conn;
404 if (
mb.type_from_handle(
c) != MBTET ||
n != 4)
407 CHKERR mb.tag_get_data(pc->part_tag(), &
c, 1, &part);
408 next.cells.push_back({indices.at(conn[0]), indices.at(conn[1]),
409 indices.at(conn[2]), indices.at(conn[3])});
410 next.partitions.push_back(part);
412 data = std::move(next);
417CGALInterfaceImpl::remesh(
const Range &source_entities,
420 const CGALTools::RemeshSettings &
settings,
421 CGALTools::RemeshReport &
report) {
423 CHKERR checkLevel(output_bit);
428 if (!occupied.empty())
430 "Output bit level is occupied");
431 const auto cells = source_entities.subset_by_type(MBTET);
432 if (
cells.empty() || !subtract(selected_cells,
cells).empty())
434 "Remeshing requires source tetrahedra and a selection within them");
438 for (
int d : {1, 2}) {
441 moab::Interface::UNION);
446 if (!subtract(source_entities, unite(
closure, all_nodes)).empty())
448 "Remeshing constraints must belong to the source cell closure");
449 for (
auto entity :
closure.subset_by_dimension(3)) {
450 const EntityHandle *conn;
452 CHKERR mb.get_connectivity(entity, conn, count,
true);
455 "Remeshing requires tetrahedra");
459 std::map<EntityHandle, int> indices;
462 indices.emplace(
v,
index++);
465 std::map<EntityHandle, Range> groups;
466 std::map<EntityHandle, int> group_dimensions;
467 std::vector<EntityHandle> pending;
469 for (
auto it = manager->getBegin();
it != manager->getEnd(); ++
it)
470 pending.push_back(
it->getMeshset());
471 for (
size_t i = 0;
i != pending.size(); ++
i) {
472 const auto group = pending[
i];
473 if (groups.count(group))
475 Range members, nested;
476 CHKERR mb.get_entities_by_handle(group, members,
false);
477 CHKERR mb.get_entities_by_type(group, MBENTITYSET, nested,
false);
478 pending.insert(pending.end(), nested.begin(), nested.end());
480 while (dim >= 0 && members.subset_by_dimension(dim).empty())
482 group_dimensions[group] = dim;
483 groups.emplace(group, intersect(members,
closure));
487 auto signature = [&](EntityHandle entity) {
488 std::vector<EntityHandle> value;
489 const int dim =
mb.dimension_from_handle(entity);
490 for (
const auto &[group, members] : groups)
491 if (group_dimensions.at(group) == dim &&
492 members.find(entity) != members.
end())
493 value.push_back(group);
496 std::map<std::vector<EntityHandle>,
int> cell_classes, face_classes,
498 auto label = [](
auto &classes,
auto value) {
499 return classes.emplace(std::move(value), classes.size() + 1).first->second;
501 for (
auto cell :
cells)
502 source.cellLabels.push_back(
label(cell_classes, signature(cell)));
503 auto connectivity = [&](EntityHandle entity,
auto &conn) {
505 const EntityHandle *
v;
507 CHKERR mb.get_connectivity(entity,
v, count,
true);
508 if (count !=
static_cast<int>(conn.size()))
510 "Remeshing constraints must be simplices");
511 for (
int d = 0;
d != count; ++
d)
512 conn[
d] = indices.at(
v[
d]);
515 for (
auto face :
closure.subset_by_type(MBTRI)) {
516 auto membership = signature(face);
517 if (membership.empty() &&
518 source_entities.find(face) == source_entities.end())
520 std::array<int, 3> conn;
522 source.boundary.push_back(conn);
523 source.surfaceLabels.push_back(
label(face_classes, membership));
525 for (
auto edge :
closure.subset_by_type(MBEDGE)) {
526 auto membership = signature(edge);
527 if (membership.empty() &&
528 source_entities.find(edge) == source_entities.end())
530 std::array<int, 2> conn;
532 source.featureEdges.push_back(conn);
533 source.edgeLabels.push_back(
label(edge_classes, membership));
536 if (source_entities.find(vertex) != source_entities.
end() ||
537 !signature(vertex).
empty())
538 source.fixedVertices.push_back(indices.at(vertex));
540 for (
auto cell : selected_cells)
542 CGALTools::RemeshReport next_report;
545 }
catch (
const std::exception &e) {
547 "Tetrahedral remeshing rejected the candidate: %s", e.what());
549 std::set<int> source_ids(
source.vertexIds.begin(),
source.vertexIds.end());
550 const auto fresh_count =
552 [&](
int id) { return !source_ids.count(id); });
553 std::vector<int> fresh_ids;
554 CHKERR allocateVertexIds(fresh_count, fresh_ids);
555 auto next_id = fresh_ids.begin();
557 if (!source_ids.count(id))
560 CHKERR mb.get_entities_by_handle(0, before);
562 std::map<EntityHandle, Range> additions;
563 bool memberships_ready =
false;
564 const auto publish = [&]() {
568 std::map<int, EntityHandle> by_id;
569 for (
auto vertex : output.subset_by_type(MBVERTEX)) {
571 CHKERR mb.tag_get_data(
mb.globalId_tag(), &vertex, 1, &
id);
572 by_id.emplace(
id, vertex);
574 auto find = [&](
const auto &conn,
int dim, EntityHandle &entity) {
576 std::vector<EntityHandle> handles;
578 handles.push_back(by_id.at(
candidate.vertexIds[
i]));
580 CHKERR mb.get_adjacencies(handles.data(), handles.size(), dim,
false,
581 matches, moab::Interface::INTERSECT);
582 matches = intersect(matches, output);
583 if (matches.size() != 1)
585 "Missing remeshed simplex during classification transfer");
586 entity = matches.front();
589 auto members = [&](
const auto &classes,
int id, EntityHandle entity) {
590 for (
const auto &[signature,
label] : classes)
592 for (auto group : signature)
593 additions[group].insert(entity);
598 members(cell_classes,
candidate.cellLabels[
i], entity);
600 for (
size_t i = 0;
i !=
candidate.boundary.size(); ++
i) {
603 members(face_classes,
candidate.surfaceLabels[
i], entity);
605 for (
size_t i = 0;
i !=
candidate.featureEdges.size(); ++
i) {
608 members(edge_classes,
candidate.edgeLabels[
i], entity);
610 for (
const auto &[group, original] : groups) {
611 for (
auto vertex : original.subset_by_type(MBVERTEX)) {
613 CHKERR mb.tag_get_data(
mb.globalId_tag(), &vertex, 1, &
id);
615 additions[group].insert(by_id.at(
id));
618 for (
auto &[group, added] : additions) {
619 const auto &original = groups.at(group);
620 const int dim = group_dimensions.at(group);
621 const auto top = added.subset_by_dimension(dim);
623 for (
int d = 0;
d < dim; ++
d) {
624 if (original.subset_by_dimension(
d).empty() || top.empty())
631 moab::Interface::UNION);
635 CHKERR mb.get_entities_by_handle(group, present,
false);
636 added = subtract(added, present);
638 memberships_ready =
true;
639 for (
const auto &[group, added] : additions) {
640 CHKERR mb.add_entities(group, added);
642 CHKERR discardImportContainers(before);
645 const auto error = publish();
647 if (memberships_ready)
648 for (
const auto &[group, added] : additions)
649 CHKERR mb.remove_entities(group, added);
650 CHKERR rollback(before, output_bit);
653 entities = std::move(output);
654 report = std::move(next_report);
659CGALInterfaceImpl::reconstructDelaunay(
const Range &source_entities,
663 CHKERR checkLevel(output_bit);
668 if (!occupied.empty())
670 "Output bit level is occupied");
671 Range before, output;
672 CHKERR mb.get_entities_by_handle(0, before);
673 const auto publish = [&]() {
675 const auto cells = source_entities.subset_by_type(MBTET);
681 for (
int dim : {1, 2}) {
684 moab::Interface::UNION);
689 if (!subtract(source_entities, unite(
closure, all_nodes)).empty())
691 "Preserved output must belong to the selected cell closure");
693 const auto type =
mb.type_from_handle(entity);
694 if (
type == MBVERTEX)
696 const EntityHandle *conn;
698 CHKERR mb.get_connectivity(entity, conn, count,
true);
699 if ((
type != MBEDGE &&
type != MBTRI &&
type != MBTET) ||
700 count != moab::CN::Dimension(
type) + 1)
702 "Reconstruction requires simplices");
704 TetMeshData
source, reconstructed;
706 std::map<EntityHandle, int> indices;
709 indices.emplace(vertex,
index++);
710 Range protected_faces = source_entities.subset_by_type(MBTRI);
711 for (
auto face :
closure.subset_by_type(MBTRI)) {
713 CHKERR mb.get_adjacencies(&face, 1, 3,
false, incident);
714 if (intersect(incident,
cells).
size() == 1)
715 protected_faces.insert(face);
717 std::vector<Range> memberships;
719 std::vector<EntityHandle> groups;
720 for (
auto it = manager->getBegin();
it != manager->getEnd(); ++
it)
721 groups.push_back(
it->getMeshset());
722 std::set<EntityHandle> visited;
723 for (
size_t i = 0;
i != groups.size(); ++
i) {
724 const auto group = groups[
i];
725 if (!visited.insert(group).second)
727 Range nested, members;
728 CHKERR mb.get_entities_by_type(group, MBENTITYSET, nested,
false);
729 groups.insert(groups.end(), nested.begin(), nested.end());
730 CHKERR mb.get_entities_by_handle(group, members,
true);
731 members = intersect(members,
closure);
732 const auto volume = members.subset_by_type(MBTET);
733 if (!volume.empty() && volume !=
cells)
735 "A volume meshset has an interface; constrained classification "
737 memberships.push_back(std::move(members));
739 std::vector<EntityHandle> carriers(protected_faces.begin(),
740 protected_faces.end());
741 std::map<std::vector<int>,
int> classes;
742 for (
auto face : carriers) {
743 const EntityHandle *conn;
745 CHKERR mb.get_connectivity(face, conn, count,
true);
746 source.boundary.push_back(
747 {indices.at(conn[0]), indices.at(conn[1]), indices.at(conn[2])});
748 std::vector<int> signature;
749 for (
size_t i = 0;
i != memberships.size(); ++
i)
750 if (memberships[
i].find(face) != memberships[
i].
end())
751 signature.push_back(
i);
753 classes.emplace(signature, classes.size() + 1).first->second;
756 std::vector<std::array<int, 2>> protected_edges;
757 for (
auto edge : source_entities.subset_by_type(MBEDGE)) {
758 const EntityHandle *conn;
760 CHKERR mb.get_connectivity(edge, conn, count,
true);
761 protected_edges.push_back({indices.at(conn[0]), indices.at(conn[1])});
763 std::vector<int> parents;
765 source.featureEdges = protected_edges;
770 }
catch (
const std::exception &e) {
772 "Delaunay reconstruction cannot preserve this input: %s",
776 CHKERR mb.get_entities_by_type(0, MBENTITYSET, import_sets);
778 CHKERR importMesh(reconstructed, output_bit, output, volume,
surface);
783 std::map<EntityHandle, int> surface_parents;
784 auto identity = [&](
int parent) {
788 std::sort(face.begin(), face.end());
791 auto remember = [&](EntityHandle child,
int parent) {
794 auto [
it, added] = surface_parents.emplace(child,
parent);
795 if (!added && identity(
parent) < identity(
it->second))
798 for (
size_t i = 0;
i != reconstructed.boundary.size(); ++
i) {
799 std::array<EntityHandle, 3> conn;
800 for (
int n = 0;
n != 3; ++
n)
803 CHKERR mb.get_adjacencies(conn.data(), 3, 2,
false, face,
804 moab::Interface::INTERSECT);
805 face = intersect(face, output);
806 if (face.size() != 1)
808 "Missing reconstructed surface face");
809 remember(face.front(), parents[
i]);
811 CHKERR mb.get_adjacencies(face, 1,
false, edges, moab::Interface::UNION);
812 for (
auto edge : edges)
813 remember(edge, parents[
i]);
816 for (
const auto &[child,
parent] : surface_parents) {
817 const auto entry = refs->find(child);
818 if (entry == refs->end() ||
819 !refs->modify(entry, RefEntity_change_parent(carriers.at(
parent))))
821 "Could not register surface ancestry");
823 CHKERR discardImportContainers(import_sets);
826 const auto error = publish();
828 CHKERR rollback(before, output_bit);
831 entities = std::move(output);
835MoFEMErrorCode CGALInterfaceImpl::importMesh(
const TetMeshData &data,
837 EntityHandle &volume,
843 const auto count = data.points.size();
844 std::vector<int> vertex_ids = data.vertexIds;
845 if (vertex_ids.empty())
846 CHKERR allocateVertexIds(count, vertex_ids);
847 if (count != vertex_ids.size() || count > INT_MAX ||
848 data.cells.size() > INT_MAX || data.boundary.size() > INT_MAX ||
849 (!data.partitions.empty() &&
850 data.partitions.size() != data.cells.size()) ||
851 (!data.cellLabels.empty() &&
852 data.cellLabels.size() != data.cells.size()) ||
853 (!data.surfaceLabels.empty() &&
854 data.surfaceLabels.size() != data.boundary.size()))
856 "Invalid indexed mesh dimensions");
858 for (
size_t i = 0;
i != count; ++
i) {
859 if (vertex_ids[
i] <= 0 || !ids.insert(vertex_ids[
i]).second ||
860 !std::all_of(data.points[
i].begin(), data.points[
i].end(),
861 [](
double x) { return std::isfinite(x); }))
864 auto validate = [&](
const auto &simplices) {
866 std::set<std::vector<int>> keys;
867 for (
const auto &
s : simplices) {
868 std::set<int> unique;
870 if (
v < 0 || static_cast<size_t>(
v) >= count ||
871 !unique.insert(
v).second)
873 "Invalid mesh connectivity");
874 std::vector<int>
key(
s.begin(),
s.end());
875 std::sort(
key.begin(),
key.end());
876 if (!keys.insert(
key).second)
881 CHKERR validate(data.cells);
882 CHKERR validate(data.boundary);
884 auto point = [&](
int i) {
885 const auto &x = data.points[
i];
886 return K::Point_3(x[0], x[1], x[2]);
888 std::vector<std::array<int, 4>>
cells = data.cells;
890 const auto orientation =
891 CGAL::orientation(point(
c[0]), point(
c[1]), point(
c[2]), point(
c[3]));
892 if (orientation == CGAL::COPLANAR)
894 "Degenerate mesh tetrahedron");
895 if (orientation == CGAL::NEGATIVE)
896 std::swap(
c[0],
c[1]);
898 std::map<int, EntityHandle> existing;
900 CHKERR mb.get_entities_by_type(0, MBVERTEX, all_vertices);
901 for (
auto v : all_vertices) {
903 CHKERR mb.tag_get_data(
mb.globalId_tag(), &
v, 1, &
id);
904 if (ids.count(
id) && !existing.emplace(
id,
v).second)
906 "Duplicate local vertex ID");
908 std::vector<EntityHandle>
vertices(count);
909 std::vector<int> missing;
910 for (
size_t i = 0;
i != count; ++
i) {
911 if (
auto it = existing.find(vertex_ids[
i]);
it != existing.end()) {
912 std::array<double, 3> x;
913 CHKERR mb.get_coords(&
it->second, 1, x.data());
914 if (x != data.points[
i])
916 "Coordinates disagree for vertex ID %d", vertex_ids[
i]);
919 missing.push_back(
i);
921 ReadUtilIface *reader;
923 if (!missing.empty()) {
925 std::vector<double *> arrays;
926 CHKERR reader->get_node_coords(3, missing.size(), 0, start, arrays);
927 for (
size_t n = 0;
n != missing.size(); ++
n) {
928 const auto i = missing[
n];
930 for (
int d = 0;
d != 3; ++
d)
931 arrays[
d][
n] = data.points[
i][
d];
936 auto import = [&](const auto &simplices, EntityType type, Range &result) {
938 const int width = moab::CN::VerticesPerEntity(
type);
939 std::vector<EntityHandle> new_conn;
940 for (
const auto &
s : simplices) {
941 std::vector<EntityHandle> conn;
945 CHKERR mb.get_adjacencies(conn.data(), width, moab::CN::Dimension(
type),
946 false, matches, moab::Interface::INTERSECT);
947 matches = matches.subset_by_type(
type);
948 if (matches.size() > 1)
950 if (!matches.empty())
953 new_conn.insert(new_conn.end(), conn.begin(), conn.end());
955 if (!new_conn.empty()) {
956 EntityHandle start, *conn;
957 const int n = new_conn.size() / width;
958 CHKERR reader->get_element_connect(
n, width,
type, 0, start, conn);
959 std::copy(new_conn.begin(), new_conn.end(), conn);
960 CHKERR reader->update_adjacencies(start,
n, width, conn);
961 result.insert(start, start +
n - 1);
968 std::map<std::array<int, 4>,
size_t> cell_indices;
969 for (
size_t n = 0;
n !=
cells.size(); ++
n) {
970 std::array<int, 4>
key;
971 for (
int d = 0;
d != 4; ++
d)
973 std::sort(
key.begin(),
key.end());
974 cell_indices.emplace(
key,
n);
977 for (
auto tet : tets) {
978 const EntityHandle *conn;
980 std::array<int, 4>
key;
981 CHKERR mb.get_connectivity(tet, conn, count,
true);
982 CHKERR mb.tag_get_data(
mb.globalId_tag(), conn, 4,
key.data());
983 std::sort(
key.begin(),
key.end());
984 if (!data.partitions.empty())
985 CHKERR mb.tag_set_data(pc->part_tag(), &tet, 1,
986 &data.partitions[cell_indices.at(
key)]);
991 entities.merge(
faces);
993 for (
int dim : {1, 2}) {
995 CHKERR mb.get_adjacencies(tets, dim,
true, adj, moab::Interface::UNION);
1001 if (!data.partitions.empty())
1002 for (
auto entity : subtract(entities, tets)) {
1004 CHKERR mb.get_adjacencies(&entity, 1, 3,
false, incident);
1005 incident = intersect(incident, tets);
1006 int owner = INT_MAX;
1007 for (
auto cell : incident) {
1009 CHKERR mb.tag_get_data(pc->part_tag(), &cell, 1, &part);
1012 if (
owner != INT_MAX)
1016 if (!tets.empty()) {
1017 CHKERR mb.create_meshset(MESHSET_SET, volume);
1018 CHKERR mb.add_entities(volume, tets);
1020 if (!
faces.empty()) {
1026 CHKERR mb.tag_get_handle(
"CGAL_LABEL", 1, MB_TYPE_INTEGER,
label,
1027 MB_TAG_SPARSE | MB_TAG_CREAT);
1028 std::map<int, Range> labelled_cells;
1029 for (
auto tet : tets) {
1030 const EntityHandle *conn;
1032 std::array<int, 4>
key;
1033 CHKERR mb.get_connectivity(tet, conn, count,
true);
1034 CHKERR mb.tag_get_data(
mb.globalId_tag(), conn, 4,
key.data());
1035 std::sort(
key.begin(),
key.end());
1037 data.cellLabels.empty() ? 1 : data.cellLabels[cell_indices.at(
key)];
1038 labelled_cells[id].insert(tet);
1040 for (
const auto &[
id, range] : labelled_cells) {
1041 EntityHandle set = volume;
1042 if (labelled_cells.size() > 1) {
1043 CHKERR mb.create_meshset(MESHSET_SET, set);
1044 CHKERR mb.add_entities(set, range);
1048 std::map<std::array<int, 3>,
int> face_labels;
1049 for (
size_t n = 0;
n != data.boundary.size(); ++
n) {
1050 std::array<int, 3>
key;
1051 for (
int d = 0;
d != 3; ++
d)
1052 key[
d] = vertex_ids[data.boundary[
n][
d]];
1053 std::sort(
key.begin(),
key.end());
1054 face_labels[
key] = data.surfaceLabels.empty() ? 1 : data.surfaceLabels[
n];
1056 std::map<int, Range> labelled_faces;
1057 for (
auto face :
faces) {
1058 const EntityHandle *conn;
1060 std::array<int, 3>
key;
1061 CHKERR mb.get_connectivity(face, conn, count,
true);
1062 CHKERR mb.tag_get_data(
mb.globalId_tag(), conn, 3,
key.data());
1063 std::sort(
key.begin(),
key.end());
1064 labelled_faces[face_labels.at(
key)].insert(face);
1066 for (
const auto &[
id, range] : labelled_faces) {
1068 if (labelled_faces.size() > 1) {
1069 CHKERR mb.create_meshset(MESHSET_SET, set);
1070 CHKERR mb.add_entities(set, range);
1081 auto next = std::make_unique<ManagedMesh>();
1083 bit, mask, next->sourceEntities, verb);
1084 next->sourceEntities = subtract(
1085 next->sourceEntities, next->sourceEntities.subset_by_type(MBENTITYSET));
1086 next->knownVertices = next->sourceEntities.subset_by_type(MBVERTEX);
1087 std::vector<std::array<double, 3>>
points(next->knownVertices.size());
1088 std::vector<std::uint64_t> identifiers;
1089 identifiers.reserve(
points.size());
1093 identifiers.push_back(vertex);
1097 }
catch (
const std::exception &e) {
1099 "MOAB to CGAL transfer failed: %s", e.what());
1101 meshes[
bit.to_ullong()] = std::move(next);
1112 "No CGAL mesh for the requested level; call moabToCgal first");
1113 mesh = &
it->second->mesh;
1125 "No CGAL mesh for the requested level");
1126 for (
auto v =
it->second->mesh.tr.finite_vertices_begin();
1127 v !=
it->second->mesh.tr.finite_vertices_end(); ++
v)
1144 CHKERR checkLevel(output_bit);
1147 auto &managed = *
meshes.at(source_bit.to_ullong());
1151 std::set<std::uint64_t> seen;
1152 for (
auto v =
mesh->tr.finite_vertices_begin();
1153 v !=
mesh->tr.finite_vertices_end(); ++
v) {
1154 const auto &p =
v->point();
1155 if (!std::isfinite(CGAL::to_double(p.x())) ||
1156 !std::isfinite(CGAL::to_double(p.y())) ||
1157 !std::isfinite(CGAL::to_double(p.z())))
1159 "Cannot export non-finite CGAL coordinates");
1160 if (
v->moabHandle && (managed.knownVertices.find(
v->moabHandle) ==
1161 managed.knownVertices.end() ||
1162 !seen.insert(
v->moabHandle).second))
1164 "CGAL vertex has an unknown or duplicate MOAB identifier");
1167 const auto source_vertices = managed.sourceEntities.subset_by_type(MBVERTEX);
1168 std::vector<CGALTools::Simplex> sources;
1169 for (
auto entity : subtract(managed.
sourceEntities, source_vertices)) {
1170 const auto type =
mb.type_from_handle(entity);
1173 "CGAL ancestry requires a linear simplicial source mesh");
1174 const EntityHandle *conn;
1176 CHKERR mb.get_connectivity(entity, conn, count,
false);
1177 if (count != moab::CN::Dimension(
type) + 1)
1179 "CGAL ancestry requires linear source connectivity");
1180 CGALTools::Simplex
source{entity, {}};
1181 source.vertices.resize(count);
1182 for (
int n = 0;
n != count; ++
n) {
1183 if (source_vertices.find(conn[
n]) == source_vertices.end())
1185 "Selected source mesh is missing a bounding vertex");
1188 sources.push_back(std::move(
source));
1191 using Vertex = CGALMesh::Delaunay::Vertex_handle;
1192 std::vector<Vertex> new_vertices, classified_vertices;
1193 std::vector<std::array<double, 3>> new_coords, classified_coords;
1195 for (
auto v =
mesh->tr.finite_vertices_begin();
1196 v !=
mesh->tr.finite_vertices_end(); ++
v) {
1197 const std::array<double, 3> coords{CGAL::to_double(
v->point().x()),
1198 CGAL::to_double(
v->point().y()),
1199 CGAL::to_double(
v->point().z())};
1200 EntityHandle
handle =
v->moabHandle;
1203 std::array<double, 3> old_coords;
1205 create = old_coords != coords;
1208 new_vertices.push_back(
v);
1209 new_coords.push_back(coords);
1213 if (!sources.empty() &&
1214 (create || source_vertices.find(
handle) == source_vertices.end())) {
1215 classified_vertices.push_back(
v);
1216 classified_coords.push_back(coords);
1220 std::vector<std::uint64_t> parent_ids;
1221 if (!sources.empty()) {
1224 }
catch (
const std::exception &e) {
1226 "CGAL vertex ancestry failed: %s", e.what());
1229 if (new_vertices.size() >
1230 static_cast<size_t>(std::numeric_limits<int>::max()) ||
1231 mesh->tr.number_of_finite_cells() >
1232 static_cast<size_t>(std::numeric_limits<int>::max()))
1234 "CGAL export exceeds MOAB bulk allocation count limits");
1236 std::vector<int> fresh_ids;
1237 CHKERR allocateVertexIds(new_vertices.size(), fresh_ids);
1238 ReadUtilIface *read_util;
1239 CHKERR mb.query_interface(read_util);
1240 if (!new_vertices.empty()) {
1242 std::vector<double *> arrays;
1243 CHKERR read_util->get_node_coords(3,
static_cast<int>(new_vertices.size()),
1245 for (
size_t n = 0;
n != new_vertices.size(); ++
n) {
1246 for (
int d = 0;
d != 3; ++
d)
1247 arrays[
d][
n] = new_coords[
n][
d];
1248 const EntityHandle vertex = start +
n;
1249 CHKERR mb.tag_set_data(
mb.globalId_tag(), &vertex, 1, &fresh_ids[
n]);
1250 new_vertices[
n]->moabHandle = start +
n;
1251 managed.knownVertices.insert(start +
n);
1255 std::map<EntityHandle, EntityHandle> vertex_parents;
1256 for (
size_t n = 0;
n != classified_vertices.size(); ++
n)
1257 vertex_parents.emplace(classified_vertices[
n]->moabHandle, parent_ids[
n]);
1260 std::vector<EntityHandle> new_connectivity;
1261 if (
mesh->tr.dimension() == 3) {
1262 for (
auto c =
mesh->tr.finite_cells_begin();
1263 c !=
mesh->tr.finite_cells_end(); ++
c) {
1264 std::array<EntityHandle, 4> conn;
1265 for (
int n = 0;
n != 4; ++
n)
1266 conn[
n] =
c->vertex(
n)->moabHandle;
1268 CHKERR mb.get_adjacencies(conn.data(), 4, 3,
false, candidates,
1269 moab::Interface::INTERSECT);
1270 EntityHandle tet = 0;
1271 for (
auto candidate : candidates.subset_by_type(MBTET)) {
1272 const EntityHandle *old_conn;
1281 tetrahedra.insert(tet);
1283 new_connectivity.insert(new_connectivity.end(), conn.begin(),
1287 if (!new_connectivity.empty()) {
1289 const int count =
static_cast<int>(new_connectivity.size() / 4);
1290 CHKERR read_util->get_element_connect(count, 4, MBTET, 0, start,
1292 std::copy(new_connectivity.begin(), new_connectivity.end(),
connectivity);
1294 tetrahedra.insert(start, start + count - 1);
1298 children.merge(tetrahedra);
1299 for (
int dim : {1, 2}) {
1301 CHKERR mb.get_adjacencies(tetrahedra, dim,
true, adjacent,
1302 moab::Interface::UNION);
1303 children.merge(adjacent);
1305 if (sources.empty()) {
1307 children, output_bit,
false, verb);
1310 managed.sourceEntities, children, vertex_parents, output_bit, verb);
1312 CHKERR orientSkin(output_bit);
1316CrackExtensionImpl::CrackExtensionImpl(CGALInterfaceImpl &
owner)
1321 CrackClassification &
result)
const {
1324 result = CrackClassification();
1327 std::map<EntityHandle, std::vector<int>> signatures;
1330 std::vector<EntityHandle> groups;
1331 for (
auto it = manager->getBegin();
it != manager->getEnd(); ++
it)
1332 groups.push_back(
it->getMeshset());
1333 std::set<EntityHandle> visited;
1334 for (
size_t i = 0;
i != groups.size(); ++
i) {
1335 const auto group = groups[
i];
1336 if (!visited.insert(group).second)
1338 Range nested, members;
1339 CHKERR mb.get_entities_by_type(group, MBENTITYSET, nested,
false);
1340 groups.insert(groups.end(), nested.begin(), nested.end());
1341 CHKERR mb.get_entities_by_handle(group, members,
true);
1342 members = subtract(members, members.subset_by_type(MBENTITYSET));
1343 for (
int dim = 3; dim >= 0; --dim) {
1344 const auto top = members.subset_by_dimension(dim);
1348 for (
auto cell : intersect(top,
cells))
1349 signatures[cell].push_back(
i);
1351 faces.merge(top.subset_by_type(MBTRI));
1353 curves.merge(top.subset_by_type(MBEDGE));
1355 result.vertices.merge(top);
1363 std::map<std::vector<int>,
int> classes;
1364 for (
const auto &[cell, signature] : signatures)
1366 classes.emplace(signature, classes.
size() + 1).first->second;
1367 const auto keys_of = [&](
const Range &entities,
auto &keys) {
1369 for (
auto entity : entities) {
1370 const EntityHandle *conn;
1372 CHKERR mb.get_connectivity(entity, conn, count,
true);
1373 auto &
key = keys.emplace_back();
1374 std::copy(conn, conn +
key.size(),
key.begin());
1377 std::sort(keys.begin(), keys.end());
1386 const Range &source_cells,
const Range &patch_cells,
1388 CrackPatch &patch)
const {
1391 patch = CrackPatch();
1396 Range crack_vertices;
1397 CHKERR mb.get_connectivity(crack_faces, crack_vertices,
true);
1399 CHKERR readVertices(
mb,
vertices, patch.mesh.points, patch.mesh.vertexIds);
1401 const int i = patch.vertices.size();
1402 if (patch.mesh.vertexIds[
i] <= 0)
1404 "Crack extension needs positive vertex GLOBAL_IDs");
1405 patch.index.emplace(
v,
i);
1406 patch.vertices.push_back(
v);
1408 patch.mesh.fixedVertices.push_back(
i);
1412 std::map<std::array<int, 3>,
int>
faces;
1413 std::set<std::array<int, 2>> edges;
1414 for (
auto cell : patch_cells) {
1415 const EntityHandle *conn;
1417 CHKERR mb.get_connectivity(cell, conn, count,
true);
1418 if (
mb.type_from_handle(cell) != MBTET || count != 4)
1420 "Crack extension needs tetrahedra");
1421 std::array<int, 4>
c;
1422 for (
int n = 0;
n != 4; ++
n)
1423 c[
n] = patch.index.at(conn[
n]);
1424 patch.mesh.cells.push_back(
c);
1425 patch.cells.push_back(cell);
1427 patch.mesh.cellLabels.push_back(
1429 for (
int a = 0;
a != 4; ++
a)
1430 for (
int b =
a + 1; b != 4; ++b) {
1431 edges.insert(sorted(std::array<int, 2>{
c[
a],
c[b]}));
1432 for (
int d = b + 1;
d != 4; ++
d)
1433 ++
faces[sorted(std::array<int, 3>{
c[
a],
c[b],
c[
d]})];
1439 std::vector<std::array<int, 3>> crack_keys;
1440 for (
auto handle : crack_faces) {
1441 const EntityHandle *conn;
1444 crack_keys.push_back(
1445 sorted(std::array<int, 3>{patch.index.at(conn[0]),
1446 patch.index.at(conn[1]),
1447 patch.index.at(conn[2])}));
1449 const std::set<std::array<int, 3>>
crack(crack_keys.begin(),
1451 for (
const auto &[
f, patch_count] :
faces) {
1453 patch.crack.push_back(patch.mesh.boundary.size());
1454 patch.mesh.boundary.push_back(
f);
1457 const auto key = patch.key(
f);
1461 if (!
boundary && patch_count == 1) {
1463 CHKERR mb.get_adjacencies(
key.data(), 3, 3,
false, incident,
1464 moab::Interface::INTERSECT);
1465 boundary = intersect(incident, source_cells).size() == 1;
1468 patch.mesh.boundary.push_back(
f);
1470 for (
const auto &face : crack_keys)
1471 if (!
faces.count(face)) {
1472 patch.crack.push_back(patch.mesh.boundary.size());
1473 patch.mesh.boundary.push_back(face);
1475 for (
const auto &e : edges)
1477 patch.
mesh.featureEdges.push_back(e);
1482 BitRefLevel source_bit, BitRefLevel output_bit,
const Range &crack_faces,
1484 const CGALTools::CrackExtensionSettings &
settings,
Range &entities,
1485 EntityHandle &new_face, CGALTools::CrackExtensionCandidate *applied,
1486 CGALTools::CrackExtensionReport *
report,
Range *closure_faces) {
1487 return changeCrack(Change::EXTEND, source_bit, output_bit, crack_faces,
1489 applied,
report, closure_faces);
1493 BitRefLevel source_bit, BitRefLevel output_bit,
const Range &crack_faces,
1495 const CGALTools::CrackExtensionSettings &
settings,
Range &entities,
1496 EntityHandle &new_face, CGALTools::CrackExtensionCandidate *applied,
1497 CGALTools::CrackExtensionReport *
report,
Range *closure_faces) {
1498 return changeCrack(Change::CLOSE, source_bit, output_bit, crack_faces,
1500 applied,
report, closure_faces);
1504 BitRefLevel source_bit, BitRefLevel output_bit,
const Range &crack_faces,
1506 const CGALTools::CrackExtensionSettings &
settings,
Range &entities,
1507 EntityHandle &new_face, CGALTools::CrackExtensionCandidate *applied,
1508 CGALTools::CrackExtensionReport *
report,
Range *closure_faces) {
1509 return changeCrack(Change::JOIN, source_bit, output_bit, crack_faces,
1511 applied,
report, closure_faces);
1515 Change operation, BitRefLevel source_bit, BitRefLevel output_bit,
1517 const std::vector<CrackFrontRequest> &requests,
1518 const CGALTools::CrackExtensionSettings &
settings,
Range &entities,
1519 EntityHandle &new_face, CGALTools::CrackExtensionCandidate *applied,
1520 CGALTools::CrackExtensionReport *
report,
Range *closure_faces) {
1525 if ((source_bit & output_bit).any())
1527 "Crack extension needs distinct source and output levels");
1532 if (!occupied.empty())
1534 "Output bit level is occupied");
1538 closure_faces->clear();
1539 std::shared_ptr<SearchState>
state;
1542 if (source_cells.empty())
1544 "Source level has no tetrahedra");
1546 for (
const auto &request : requests) {
1547 if (
mb.type_from_handle(request.edge) != MBEDGE)
1549 "Crack extension request is not an edge");
1550 const EntityHandle *edge_conn;
1552 CHKERR mb.get_connectivity(request.edge, edge_conn, count,
true);
1553 const CrackPatch *patch_ptr;
1555 const CrackPatch &patch = *patch_ptr;
1556 const std::array<int, 2> front_edge{patch.index.at(edge_conn[0]),
1557 patch.index.at(edge_conn[1])};
1558 const auto candidates =
1559 operation == Change::CLOSE
1560 ?
tools.crackClosureCandidates(patch.mesh, patch.crack, front_edge,
1562 : operation == Change::JOIN
1563 ?
tools.crackJoiningCandidates(patch.mesh, patch.crack, front_edge,
1565 :
tools.crackExtensionCandidates(patch.mesh, patch.crack,
1566 front_edge, request.direction,
1568 if (candidates.empty())
1572 change.candidate = candidates.front();
1573 change.result = patch.mesh;
1574 auto result_crack = patch.crack;
1575 tools.applyCrackExtension(change.result, result_crack, change.candidate);
1576 CHKERR prepareCrackChange(patch, source_cells, change);
1578 Range before, import_sets;
1579 CHKERR mb.get_entities_by_handle(0, before);
1580 CHKERR mb.get_entities_by_type(0, MBENTITYSET, import_sets);
1582 publishCrackChange(patch, change, source_cells, source_bit, output_bit,
1583 import_sets, entities, new_face, closure_faces);
1588 closure_faces->clear();
1593 *applied = change.candidate;
1594 MOFEM_LOG(
"CGALInterface", Sev::verbose)
1595 <<
"Crack extension class " << change.candidate.candidateClass <<
", "
1596 << change.candidate.removedCells.size() <<
" removed and "
1597 << change.candidate.createdCells.size() <<
" created cells"
1598 << (change.moved ?
", free node moved" :
"");
1604MoFEMErrorCode CrackExtensionImpl::cellsAround(
const EntityHandle *edge,
1606 const Range &source_cells,
1611 Range ring(edge[0], edge[0]);
1612 ring.insert(edge[1]);
1613 for (
int r = 0;
r != rings; ++
r) {
1615 CHKERR mb.get_adjacencies(ring, 3,
false, adjacent, moab::Interface::UNION);
1616 cells.merge(intersect(adjacent, source_cells));
1624CrackExtensionImpl::searchState(BitRefLevel
bit,
const Range &crack_faces,
1626 std::shared_ptr<SearchState> &
state) {
1632 state = std::make_shared<SearchState>();
1634 state->crackFaces = crack_faces;
1639 state->classification);
1646 EntityHandle edge,
int rings,
1647 const CrackPatch *&patch)
const {
1649 const auto key = std::make_pair(edge, rings);
1651 if (
it ==
state.edgePatches.end()) {
1652 const EntityHandle *conn;
1656 CHKERR cellsAround(conn, rings,
state.cells, patch_cells);
1657 if (patch_cells.empty())
1659 "Crack extension edge is not on the source level");
1662 state.classification, built);
1663 it =
state.edgePatches.emplace(
key, std::move(built)).first;
1665 patch = &
it->second;
1671 std::shared_ptr<SearchState> &
state,
const CrackPatch *&patch) {
1674 if (!
state->crackNeighbourhood) {
1678 Range crack_vertices, patch_cells;
1679 CHKERR mb.get_connectivity(crack_faces, crack_vertices,
true);
1680 CHKERR mb.get_adjacencies(crack_vertices, 3,
false, patch_cells,
1681 moab::Interface::UNION);
1682 patch_cells = intersect(patch_cells,
state->cells);
1683 auto &neighbourhood =
state->crackNeighbourhood.emplace();
1684 if (!patch_cells.empty())
1685 CHKERR crackPatch(
state->cells, patch_cells, crack_faces,
1686 state->classification, neighbourhood);
1688 patch = &*
state->crackNeighbourhood;
1693CrackExtensionImpl::prepareCrackChange(
const CrackPatch &patch,
1694 const Range &source_cells,
1695 CrackChange &change)
const {
1698 const auto &
candidate = change.candidate;
1700 change.oldVertex = patch.vertices[
w];
1701 change.moved =
candidate.displacement != std::array<double, 3>{};
1706 CHKERR mb.get_adjacencies(&change.oldVertex, 1, 3,
false, star);
1707 change.removed.merge(intersect(star, source_cells));
1709 std::set<std::array<int, 4>> keys;
1710 const auto add_created = [&](
const std::array<int, 4> &cell) {
1712 std::sort(
key.begin(),
key.end());
1713 if (keys.insert(
key).second)
1714 change.created.push_back(cell);
1716 for (
const auto &cell :
candidate.createdCells)
1720 if (
std::count(cell.begin(), cell.
end(),
w))
1726 const CrackPatch &patch,
1727 const CGALTools::CrackExtensionCandidate &
candidate,
1728 EntityHandle moved_vertex,
bool create,
const Range *within,
1729 EntityHandle &new_face,
Range *closure_faces)
const {
1732 const auto resolve = [&](
const std::array<int, 3> &face_vertices,
1735 std::array<EntityHandle, 3> conn;
1736 for (
int n = 0;
n != 3; ++
n) {
1737 const int v = face_vertices[
n];
1738 conn[
n] = moved_vertex &&
v ==
candidate.freeNode ? moved_vertex
1739 : patch.vertices[
v];
1742 CHKERR mb.get_adjacencies(conn.data(), 3, 2, create, face,
1743 moab::Interface::INTERSECT);
1744 face = face.subset_by_type(MBTRI);
1746 face = intersect(face, *within);
1747 if (face.size() != 1)
1749 "Crack extension face is missing on the output level");
1755 for (
const auto &face_vertices :
candidate.closureFaces) {
1766 const CrackPatch &patch,
const CrackChange &change,
1767 const Range &source_cells, BitRefLevel source_bit, BitRefLevel output_bit,
1768 const Range &import_sets,
Range &entities, EntityHandle &new_face,
1769 Range *closure_faces) {
1771 forgetSearchCache();
1774 const auto &
candidate = change.candidate;
1781 if (change.created.empty()) {
1783 CHKERR resolveCrackFaces(patch,
candidate, 0,
true,
nullptr, new_face,
1785 Range added(new_face, new_face);
1787 added.merge(*closure_faces);
1788 CHKERR bits->setBitRefLevel(added, output_bit,
false);
1789 entities = unite(
closure, added);
1795 std::vector<int> new_ids;
1799 std::map<int, int> local;
1800 const auto point = [&](
int v) {
1801 auto it = local.find(
v);
1802 if (
it != local.end())
1804 const int i = data.points.size();
1805 local.emplace(
v,
i);
1806 data.points.push_back(change.result.points[
v]);
1807 data.vertexIds.push_back(change.moved &&
v ==
w ? new_ids[0]
1808 : patch.
mesh.vertexIds[
v]);
1811 for (
const auto &cell : change.
created)
1812 data.
cells.push_back(
1813 {point(cell[0]), point(cell[1]), point(cell[2]), point(cell[3])});
1814 std::vector<std::array<int, 3>> crack_added{
candidate.newFace};
1815 crack_added.insert(crack_added.end(),
candidate.closureFaces.begin(),
1817 for (
const auto &
f : crack_added)
1818 data.
boundary.push_back({point(
f[0]), point(
f[1]), point(
f[2])});
1819 Range existing, imported;
1820 CHKERR mb.get_entities_by_handle(0, existing);
1825 const auto children = subtract(imported, existing);
1831 CHKERR bits->setBitRefLevel(
source, source_bit,
false);
1832 std::map<EntityHandle, EntityHandle> moved_vertices;
1833 EntityHandle moved_vertex = 0;
1835 for (
auto v : imported.subset_by_type(MBVERTEX)) {
1837 CHKERR mb.tag_get_data(
mb.globalId_tag(), &
v, 1, &
id);
1838 if (
id == new_ids[0])
1843 "Moved vertex was not imported");
1844 moved_vertices.emplace(moved_vertex, change.oldVertex);
1847 source, children, output_bit,
QUIET, moved_vertices);
1849 CHKERR resolveCrackFaces(patch,
candidate, moved_vertex,
false, &imported,
1850 new_face, closure_faces);
1851 entities = unite(
closure, imported);
1852 CHKERR owner.discardImportContainers(import_sets);
1857CrackExtensionImpl::crackJoin(BitRefLevel
bit,
const Range &crack_faces,
1859 std::vector<int> *categories,
1860 const std::vector<EntityHandle> &front_order,
1861 EntityHandle *selected_front,
bool gaps_only) {
1867 categories->clear();
1869 *selected_front = 0;
1870 std::shared_ptr<SearchState>
state;
1871 const CrackPatch *patch_ptr;
1873 const CrackPatch &patch = *patch_ptr;
1874 if (patch.cells.empty())
1879 std::vector<std::array<int, 2>> indexed_order;
1880 std::map<std::array<int, 2>, EntityHandle> handles;
1881 for (
auto edge : front_order) {
1882 const EntityHandle *conn;
1884 CHKERR mb.get_connectivity(edge, conn, count,
true);
1885 if (count != 2 || !patch.index.count(conn[0]) ||
1886 !patch.index.count(conn[1]))
1888 "Ordered crack join edge is not in the crack patch");
1889 const auto key = sorted(
1890 std::array<int, 2>{patch.index.at(conn[0]), patch.index.at(conn[1])});
1891 indexed_order.push_back(
key);
1892 handles.emplace(
key, edge);
1896 const auto face_edges = [](
const std::array<int, 3> &
f) {
1897 return std::array<std::array<int, 2>, 3>{
1898 sorted(std::array<int, 2>{
f[0],
f[1]}),
1899 sorted(std::array<int, 2>{
f[1],
f[2]}),
1900 sorted(std::array<int, 2>{
f[0],
f[2]})};
1902 std::set<std::array<int, 2>> crack_edges;
1904 for (
int i : patch.
crack)
1906 crack_edges.insert(edge);
1907 const auto accept = [&](
const std::array<int, 3> &face) {
1911 for (
const auto &edge : face_edges(face))
1912 shared += crack_edges.count(edge);
1916 std::vector<std::array<int, 3>>
faces;
1917 for (
const auto &join :
1919 faces.push_back(join.face);
1921 categories->push_back(join.category);
1922 if (selected_front && !front_order.empty())
1924 handles.at(sorted(std::array<int, 2>{join.face[0], join.face[1]}));
1931 const Range &crack_faces,
1933 Range &fill_faces) {
1938 std::shared_ptr<SearchState>
state;
1939 const CrackPatch *patch;
1941 if (patch->cells.empty())
1944 tools.crackFillFaces(patch->mesh, patch->crack),
"fill",
1950 BitRefLevel
bit,
const CrackPatch &patch,
1951 const std::vector<std::array<int, 3>> &indexed,
const std::string &what,
1955 for (
const auto &
f : indexed) {
1956 const EntityHandle conn[] = {patch.vertices[
f[0]], patch.vertices[
f[1]],
1957 patch.vertices[
f[2]]};
1959 CHKERR mb.get_adjacencies(conn, 3, 2,
true, face,
1960 moab::Interface::INTERSECT);
1961 face = face.subset_by_type(MBTRI);
1962 if (face.size() != 1)
1964 "Crack %s face is ambiguous", what.c_str());
1974 CHKERR requireOneRank(
"retireLevel");
1981 retired = subtract(retired, retired.subset_by_type(MBENTITYSET));
1985 const auto elements = subtract(
active,
active.subset_by_type(MBVERTEX));
1987 CHKERR mb.get_connectivity(elements, used,
false);
1988 for (
int dim : {1, 2}) {
1990 CHKERR mb.get_adjacencies(elements.subset_by_dimension(3), dim,
false,
1991 adjacent, moab::Interface::UNION);
1992 used.merge(adjacent);
1994 if (!intersect(used, retired).empty())
1996 "A retired entity is still used by an entity on another level");
1998 CHKERR bits->lambdaBitRefLevel(
1999 [&](EntityHandle, BitRefLevel &level) { level &= ~bit; });
2006 return new CGALInterfaceImpl(core);
Opt-in CGAL types; not included by MoFEM.hpp.
std::map< EntityHandle, int > labels
CGALInterfaceImpl & owner
std::map< EntityHandle, int > index
int searchCacheDepth
Open SearchCacheScope objects.
std::optional< CrackPatch > crackNeighbourhood
Patch of every cell at a crack node, for joins and the fill.
BitRefLevel bit
The arguments the state was built from.
std::vector< std::array< EntityHandle, 3 > > faces
Sorted keys.
std::vector< std::array< int, 4 > > created
Patch point indices.
CGALTools::CrackExtensionCandidate candidate
CrackExtensionImpl crackExtension
std::vector< std::array< EntityHandle, 2 > > curves
Sorted keys.
std::vector< EntityHandle > cells
Tetrahedra on bit.
CrackClassification classification
std::shared_ptr< SearchState > searchCache
std::map< std::pair< EntityHandle, int >, CrackPatch > edgePatches
Patches by front edge and number of vertex rings.
EntityHandle oldVertex
The free node's vertex.
std::map< unsigned long long, std::unique_ptr< ManagedMesh > > meshes
MoFEM::Interface & mField
std::vector< int > created
std::vector< int > source
const Settings & settings
const std::vector< Vec > * points
std::vector< Face > closures
Faces closing non-convex front corners.
std::vector< int > removed
std::vector< int > vertices
std::vector< int > parent
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::array< int, 4 > connectivity
std::vector< double > empty
One value per component.
#define MoFEMFunctionReturnHot(a)
Last executable line of each PETSc function used for error handling. Replaces return()
#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 ...
@ MOFEM_DATA_INCONSISTENCY
#define MoFEMFunctionReturn(a)
Last executable line of each PETSc function used for error handling. Replaces return()
#define CHKERR
Inline error check.
virtual const RefEntity_multiIndex * get_ref_ents() const =0
Get the ref ents object.
static LoggerType & setLog(const std::string channel)
Set ans resset chanel logger.
#define MOFEM_LOG(channel, severity)
Log.
#define MOFEM_LOG_TAG(channel, tag)
Tag channel.
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)
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
multi_index_container< boost::shared_ptr< RefEntity >, indexed_by< ordered_unique< tag< Ent_mi_tag >, const_mem_fun< RefEntity, EntityHandle, &RefEntity::getEnt > >, ordered_non_unique< tag< Ent_Ent_mi_tag >, const_mem_fun< RefEntity, EntityHandle, &RefEntity::getParentEnt > >, ordered_non_unique< tag< Composite_EntType_and_ParentEntType_mi_tag >, composite_key< RefEntity, const_mem_fun< RefEntity, EntityType, &RefEntity::getEntType >, const_mem_fun< RefEntity, EntityType, &RefEntity::getParentEntType > > >, ordered_non_unique< tag< Composite_ParentEnt_And_EntType_mi_tag >, composite_key< RefEntity, const_mem_fun< RefEntity, EntityType, &RefEntity::getEntType >, const_mem_fun< RefEntity, EntityHandle, &RefEntity::getParentEnt > > > > > RefEntity_multiIndex
CGAL::Exact_predicates_inexact_constructions_kernel Kernel
virtual int get_comm_size() const =0
virtual moab::Interface & get_moab()=0
virtual MoFEMErrorCode delete_ents_by_bit_ref(const BitRefLevel bit, const BitRefLevel mask, const bool remove_parent=false, int verb=DEFAULT_VERBOSITY, MoFEMTypes mf=MF_ZERO)=0
Delete entities from MoFEM and MOAB database.
virtual MPI_Comm & get_comm() const =0
virtual MoFEMErrorCode remove_ents(const Range ents, int verb=DEFAULT_VERBOSITY)=0
Remove entities from MoFEM database.
virtual MoFEMErrorCode remove_parents_by_ents(const Range &ents, int verb=DEFAULT_VERBOSITY)=0
Remove parents from entities.
Deprecated interface functions.
static boost::shared_ptr< SinkType > createSink(boost::shared_ptr< std::ostream > stream_ptr, std::string comm_filter)
Create a sink object.
static bool checkIfChannelExist(const std::string channel)
Check if channel exist.
static boost::shared_ptr< std::ostream > getStrmSelf()
Get the strm self object.
MoFEMErrorCode getInterface(IFACE *&iface) const
Get interface reference to pointer of interface.