Wildmeshing Toolkit
MaxFunctionInvariant.cpp
Go to the documentation of this file.
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  const std::optional<TypedAttributeHandle<Rational>>& coordinate)
12  : Invariant(func->mesh(), coordinate.has_value(), true, true)
13  , m_func(func)
14  , m_type(type)
15  , m_coordinate_handle(coordinate)
16 {
17  if (true) {
18  }
19 }
20 
22 {
23  if (m_coordinate_handle) {
24  const auto accessor = m_func->mesh().create_const_accessor(m_coordinate_handle.value());
25  const auto coord = accessor.const_vector_attribute(simplex.tuple());
26  was_v0_rounded = true;
27  for (int64_t i = 0; i < accessor.dimension(); ++i) {
28  if (!coord[i].is_rounded()) {
29  was_v0_rounded = false;
30  break;
31  }
32  }
33  }
34  return true;
35 }
36 
38  const std::vector<Tuple>& top_dimension_tuples_before,
39  const std::vector<Tuple>& top_dimension_tuples_after) const
40 {
41  if (m_coordinate_handle && !was_v0_rounded) return true;
42 
43  auto max = [&](const std::vector<Tuple>& tuples) {
44  double value = std::numeric_limits<double>::lowest();
45  for (const auto& t : tuples) {
46  value = std::max(value, m_func->get_value(simplex::Simplex(mesh(), m_type, t)));
47  }
48 
49 
50  return value;
51  };
52  const double before = mesh().parent_scope(max, top_dimension_tuples_before);
53 
54 
55  const double after = max(top_dimension_tuples_after);
56 
57  return after <= before;
58 }
59 } // namespace wmtk::invariants
decltype(auto) parent_scope(Functor &&f, Args &&... args) const
Evaluate the passed in function inside the parent scope.
Handle that represents attributes for some mesh.
const Mesh & mesh() const
Definition: Invariant.cpp:35
bool after(const std::vector< Tuple > &top_dimension_tuples_before, const std::vector< Tuple > &top_dimension_tuples_after) const override
std::shared_ptr< function::PerSimplexFunction > m_func
const std::optional< TypedAttributeHandle< Rational > > m_coordinate_handle
bool before(const simplex::Simplex &simplex) const override
MaxFunctionInvariant(const PrimitiveType type, const std::shared_ptr< function::PerSimplexFunction > &func, const std::optional< TypedAttributeHandle< Rational >> &coordinate={})
const Tuple & tuple() const
Definition: Simplex.hpp:53