2#include <spdlog/spdlog.h>
23 assert(o.mesh() ==
mesh());
35 if (&
mesh() != &invariant->mesh()) {
37 if (!invariant->before(
43 if (!invariant->before(t)) {
51 const std::vector<Tuple>& top_dimension_tuples_before,
52 const std::vector<Tuple>& top_dimension_tuples_after)
const
55 if (&
mesh() != &invariant->mesh()) {
56 const bool invariant_uses_old_state = invariant->use_old_state_in_after();
57 const bool invariant_uses_new_state = invariant->use_new_state_in_after();
58 if (!(invariant_uses_old_state || invariant_uses_new_state)) {
61 auto map = [&](
const auto& tuples) {
64 const std::vector<Tuple> mapped_tuples_after =
65 invariant_uses_new_state ? map(top_dimension_tuples_after) : std::vector<Tuple>{};
66 const std::vector<Tuple> mapped_tuples_before =
67 invariant_uses_old_state ?
mesh().
parent_scope(map, top_dimension_tuples_before)
68 : std::vector<Tuple>{};
69 if (!invariant->after(mapped_tuples_before, mapped_tuples_after)) {
73 if (!invariant->after(top_dimension_tuples_before, top_dimension_tuples_after)) {
86 const std::vector<simplex::Simplex>& simplices_before,
87 const std::vector<simplex::Simplex>& simplices_after)
const
90 for (
const auto& s : simplices_before) {
93 for (
const auto& s : simplices_after) {
94 assert(
mesh().is_valid(s.tuple()));
99 if (&
mesh() != &invariant->mesh()) {
100 auto mapped_simplices_after =
mesh().
map(invariant->mesh(), simplices_after);
102 [&]() {
return mesh().
map(invariant->mesh(), simplices_before); });
104 for (
const auto& s : mapped_simplices_before) {
105 mesh().
parent_scope([&]() { assert(invariant->mesh().is_valid(s.tuple())); });
107 for (
const auto& s : mapped_simplices_after) {
108 assert(invariant->mesh().is_valid(s.tuple()));
110 assert(
mesh().is_from_same_multi_mesh_structure(invariant->mesh()));
112 if (!invariant->directly_modified_after(
113 mapped_simplices_before,
114 mapped_simplices_after)) {
118 if (!invariant->directly_modified_after(simplices_before, simplices_after)) {
143std::map<Mesh const*, std::vector<std::shared_ptr<Invariant>>>
148 throw std::runtime_error(
"Untested code. Potentially wrong.");
157 for (
const auto& [mptr, i] : sub_map) {
158 auto& vec = mesh_invariants_map[mptr];
159 vec.insert(vec.end(), i.begin(), i.end());
162 mesh_invariants_map[&(inv->mesh())].push_back(inv);
std::vector< Tuple > map_tuples(const Mesh &other_mesh, const simplex::Simplex &my_simplex) const
maps a simplex from this mesh to any other mesh
std::vector< simplex::Simplex > map(const Mesh &other_mesh, const simplex::Simplex &my_simplex) const
maps a simplex from this mesh to any other mesh
decltype(auto) parent_scope(Functor &&f, Args &&... args) const
Evaluate the passed in function inside the parent scope.
The Tuple is the basic navigation tool in our mesh data structure.
bool directly_modified_after(const std::vector< simplex::Simplex > &simplices_before, const std::vector< simplex::Simplex > &simplices_after) const override
void add(std::shared_ptr< Invariant > invariant)
std::map< Mesh const *, std::vector< std::shared_ptr< Invariant > > > get_map_mesh_to_invariants()
bool before(const simplex::Simplex &t) const override
InvariantCollection(const Mesh &m)
bool after(const std::vector< Tuple > &top_dimension_tuples_before, const std::vector< Tuple > &top_dimension_tuples_after) const override
std::vector< std::shared_ptr< Invariant > > m_invariants
const std::shared_ptr< Invariant > & get(int64_t index) const
const std::vector< std::shared_ptr< Invariant > > & invariants() const
InvariantCollection & operator=(const InvariantCollection &)
const Mesh & mesh() const
PrimitiveType primitive_type() const