Wildmeshing Toolkit
SeparateSubstructuresInvariant.cpp
Go to the documentation of this file.
2 
3 #include <algorithm>
4 #include <set>
5 #include <wmtk/Mesh.hpp>
6 
7 namespace wmtk::invariants {
8 
10  const Mesh& m,
11  bool check_condition_2)
12  : Invariant(m, true, false, false)
13  , m_check_condition_2(check_condition_2)
14 {}
15 
17 {
18  assert(s.primitive_type() == PrimitiveType::Edge);
19 
20  const Tuple& t = s.tuple();
21 
22  const simplex::Simplex& e = s;
24  const simplex::Simplex v1 =
26 
27  const Mesh& m = mesh();
28 
29  const auto substructures = m.get_all_child_meshes();
30  std::vector<std::vector<int64_t>> subs_e;
31  std::vector<std::vector<int64_t>> subs_v0;
32  std::vector<std::vector<int64_t>> subs_v1;
33  subs_e.reserve(substructures.size());
34  subs_v0.reserve(substructures.size());
35  subs_v1.reserve(substructures.size());
36 
37  for (const auto& sub : substructures) {
38  const std::vector<int64_t> id = sub->absolute_multi_mesh_id();
39 
40  if (!m.map_to_child_tuples(*sub, e).empty()) {
41  subs_e.emplace_back(id);
42  }
43  if (!m.map_to_child_tuples(*sub, v0).empty()) {
44  subs_v0.emplace_back(id);
45  }
46  if (!m.map_to_child_tuples(*sub, v1).empty()) {
47  subs_v1.emplace_back(id);
48  }
49  }
50  std::sort(subs_e.begin(), subs_e.end());
51  std::sort(subs_v0.begin(), subs_v0.end());
52  std::sort(subs_v1.begin(), subs_v1.end());
53 
54  // Condition 1: The intersection of subs(V0) and subs(V1) is a subset of subs(E).
55  std::vector<std::vector<int64_t>> subs_v0v1;
57  subs_v0.begin(),
58  subs_v0.end(),
59  subs_v1.begin(),
60  subs_v1.end(),
61  std::back_inserter(subs_v0v1));
62 
63  if (!std::includes(subs_e.begin(), subs_e.end(), subs_v0v1.begin(), subs_v0v1.end())) {
64  return false;
65  }
66 
67  if (!m_check_condition_2) {
68  return true;
69  }
70 
71  // Condition 2: subs(V0) is a subset of subs(V1) or subs(V1) is a subset of subs(V0).
72  const bool v1_includes_v0 =
73  std ::includes(subs_v1.begin(), subs_v1.end(), subs_v0.begin(), subs_v0.end());
74  const bool v0_includes_v1 =
75  std ::includes(subs_v0.begin(), subs_v0.end(), subs_v1.begin(), subs_v1.end());
76  return v0_includes_v1 || v1_includes_v0;
77 }
78 
79 } // namespace wmtk::invariants
std::vector< std::shared_ptr< Mesh > > get_all_child_meshes() const
returns all multimesh child meshes
std::vector< Tuple > map_to_child_tuples(const Mesh &child_mesh, const simplex::Simplex &my_simplex) const
optimized map fromsimplex from this mesh to one of its direct children
const Mesh & mesh() const
Definition: Invariant.cpp:35
SeparateSubstructuresInvariant(const Mesh &m, bool check_condition_2=true)
bool before(const simplex::Simplex &s) const override
const Tuple & tuple() const
Definition: Simplex.hpp:53
static Simplex vertex(const Mesh &m, const Tuple &t)
Definition: Simplex.hpp:56
PrimitiveType primitive_type() const
Definition: Simplex.hpp:51
void set_intersection(const std::unordered_set< int > &s1, const std::unordered_set< int > &s2, std::vector< int > &v)