Wildmeshing Toolkit
FunctionInvariant.cpp
Go to the documentation of this file.
1 #include "FunctionInvariant.hpp"
2 
3 #include <wmtk/Mesh.hpp>
5 
6 namespace wmtk::invariants {
7 
9  const PrimitiveType type,
10  const std::shared_ptr<function::PerSimplexFunction>& func)
11  : Invariant(func->mesh(), false, true, true)
12  , m_func(func)
13  , m_type(type)
14 {}
15 
17  const std::vector<Tuple>& top_dimension_tuples_before,
18  const std::vector<Tuple>& top_dimension_tuples_after) const
19 {
20  auto sum = [&](const std::vector<Tuple>& tuples) {
21  double _before = 0;
22  for (const auto& t : tuples)
23  _before += m_func->get_value(simplex::Simplex(mesh(), m_type, t));
24 
25  return _before;
26  };
27 
28 
29  const double before = mesh().parent_scope(sum, top_dimension_tuples_before);
30  const double after = sum(top_dimension_tuples_after);
31 
32  return after < before;
33 }
34 } // namespace wmtk::invariants
decltype(auto) parent_scope(Functor &&f, Args &&... args) const
Evaluate the passed in function inside the parent scope.
std::shared_ptr< function::PerSimplexFunction > m_func
FunctionInvariant(const PrimitiveType type, const std::shared_ptr< function::PerSimplexFunction > &func)
bool after(const std::vector< Tuple > &top_dimension_tuples_before, const std::vector< Tuple > &top_dimension_tuples_after) const override
const Mesh & mesh() const
Definition: Invariant.cpp:35
virtual bool before(const simplex::Simplex &t) const
Definition: Invariant.cpp:24