Wildmeshing Toolkit
Invariant.cpp
Go to the documentation of this file.
1 #include "Invariant.hpp"
2 #include <wmtk/Mesh.hpp>
6 
7 namespace wmtk::invariants {
8 
9 
11  : Invariant(mesh, true, true, true)
12 {}
14  const Mesh& mesh,
15  bool use_before,
16  bool use_old_state_in_after,
17  bool use_new_state_in_after)
18  : m_mesh(mesh)
19  , m_use_before(use_before)
20  , m_use_old_state_in_after(use_old_state_in_after)
21  , m_use_new_state_in_after(use_new_state_in_after)
22 {}
24 bool Invariant::before(const simplex::Simplex& t) const
25 {
26  return true;
27 }
29  const std::vector<Tuple>& top_dimension_tuples_before,
30  const std::vector<Tuple>& top_dimension_tuples_after) const
31 {
32  return true;
33 }
34 
35 const Mesh& Invariant::mesh() const
36 {
37  return m_mesh;
38 }
40  const std::vector<simplex::Simplex>& simplices_before,
41  const std::vector<simplex::Simplex>& simplices_after) const
42 {
43  if (use_after()) {
44  const std::vector<Tuple> tuples_after = use_new_state_in_after()
45  ? get_top_dimension_cofaces(simplices_after)
46  : std::vector<Tuple>{};
47  const std::vector<Tuple> tuples_before =
49  ? m_mesh.parent_scope([&]() { return get_top_dimension_cofaces(simplices_before); })
50  : std::vector<Tuple>{};
51 
52 
53  if (!after(tuples_before, tuples_after)) {
54  return false;
55  }
56  }
57 
58  return true;
59 }
60 
62 {
64 }
66 {
68 }
70 {
72 }
74 {
75  return m_use_before;
76 }
77 const std::vector<Tuple> Invariant::get_top_dimension_cofaces(
78  const std::vector<simplex::Simplex>& simplices) const
79 {
80  simplex::SimplexCollection all_simplices(mesh());
81 
82  for (const simplex::Simplex& s : simplices) {
83  all_simplices.add(simplex::top_dimension_cofaces(mesh(), s, false));
84  }
85  all_simplices.sort_and_clean();
86 
87  const std::vector<Tuple> all_tuples =
89 
90  assert(all_tuples.size() == all_simplices.simplex_vector().size());
91 
92  return all_tuples;
93 }
94 } // namespace wmtk::invariants
PrimitiveType top_simplex_type() const
Definition: Mesh.hpp:997
decltype(auto) parent_scope(Functor &&f, Args &&... args) const
Evaluate the passed in function inside the parent scope.
virtual bool directly_modified_after(const std::vector< simplex::Simplex > &simplices_before, const std::vector< simplex::Simplex > &simplices_after) const
Definition: Invariant.cpp:39
const bool m_use_new_state_in_after
Definition: Invariant.hpp:48
bool use_old_state_in_after() const
Definition: Invariant.cpp:61
const bool m_use_old_state_in_after
Definition: Invariant.hpp:47
bool use_new_state_in_after() const
Definition: Invariant.cpp:65
const std::vector< Tuple > get_top_dimension_cofaces(const std::vector< simplex::Simplex > &simplices) const
Definition: Invariant.cpp:77
Invariant(const Mesh &m)
Definition: Invariant.cpp:10
const Mesh & mesh() const
Definition: Invariant.cpp:35
virtual bool before(const simplex::Simplex &t) const
Definition: Invariant.cpp:24
virtual bool after(const std::vector< Tuple > &top_dimension_tuples_before, const std::vector< Tuple > &top_dimension_tuples_after) const
Definition: Invariant.cpp:28
void add(const Simplex &simplex)
Add simplex to the collection.
const std::vector< Simplex > & simplex_vector() const
Return const reference to the simplex vector.
void sort_and_clean()
Sort simplex vector and remove duplicates.
std::vector< Tuple > simplex_vector_tuples(PrimitiveType ptype) const
Return vector of all simplices of the requested type, as tuples.
void top_dimension_cofaces(const Simplex &simplex, SimplexCollection &simplex_collection, const bool sort_and_clean)
Get all top dimension cofaces of the given simplex.