22 assert(o.mesh() ==
mesh());
34 if (&
mesh() != &invariant->mesh()) {
35 for (
const Tuple& ct :
mesh().map_tuples(invariant->mesh(), t)) {
36 if (!invariant->before(
42 if (!invariant->before(t)) {
50 const std::vector<Tuple>& top_dimension_tuples_before,
51 const std::vector<Tuple>& top_dimension_tuples_after)
const
54 if (&
mesh() != &invariant->mesh()) {
55 const bool invariant_uses_old_state = invariant->use_old_state_in_after();
56 const bool invariant_uses_new_state = invariant->use_new_state_in_after();
57 if (!(invariant_uses_old_state || invariant_uses_new_state)) {
60 auto map = [&](
const auto& tuples) {
63 const std::vector<Tuple> mapped_tuples_after =
64 invariant_uses_new_state ? map(top_dimension_tuples_after) : std::vector<Tuple>{};
65 const std::vector<Tuple> mapped_tuples_before =
66 invariant_uses_old_state ?
mesh().
parent_scope(map, top_dimension_tuples_before)
67 : std::vector<Tuple>{};
68 if (!invariant->after(mapped_tuples_before, mapped_tuples_after)) {
72 if (!invariant->after(top_dimension_tuples_before, top_dimension_tuples_after)) {
85 const std::vector<simplex::Simplex>& simplices_before,
86 const std::vector<simplex::Simplex>& simplices_after)
const
89 for (
const auto& s : simplices_before) {
92 for (
const auto& s : simplices_after) {
93 assert(
mesh().is_valid(s.tuple()));
98 if (&
mesh() != &invariant->mesh()) {
99 auto mapped_simplices_after =
mesh().
map(invariant->mesh(), simplices_after);
101 [&]() {
return mesh().
map(invariant->mesh(), simplices_before); });
103 for (
const auto& s : mapped_simplices_before) {
104 mesh().
parent_scope([&]() { assert(invariant->mesh().is_valid(s.tuple())); });
106 for (
const auto& s : mapped_simplices_after) {
107 assert(invariant->mesh().is_valid(s.tuple()));
109 assert(
mesh().is_from_same_multi_mesh_structure(invariant->mesh()));
111 if (!invariant->directly_modified_after(
112 mapped_simplices_before,
113 mapped_simplices_after)) {
117 if (!invariant->directly_modified_after(simplices_before, simplices_after)) {
142 std::map<Mesh const*, std::vector<std::shared_ptr<Invariant>>>
147 throw std::runtime_error(
"Untested code. Potentially wrong.");
156 for (
const auto& [mptr, i] : sub_map) {
157 auto& vec = mesh_invariants_map[mptr];
158 vec.insert(vec.end(), i.begin(), i.end());
161 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.
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)
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
std::map< Mesh const *, std::vector< std::shared_ptr< Invariant > > > get_map_mesh_to_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