Wildmeshing Toolkit
LocalNeighborsSumFunction.cpp
Go to the documentation of this file.
2 
3 #include "PerSimplexFunction.hpp"
4 
6 
7 
8 namespace wmtk::function {
9 
10 
12  Mesh& mesh,
13  const attribute::MeshAttributeHandle& handle,
14  PerSimplexFunction& function)
15  : Function(mesh, handle)
16  , m_function(function)
17 {
19 }
20 
21 std::vector<simplex::Simplex> LocalNeighborsSumFunction::domain(
22  const simplex::Simplex& variable_simplex) const
23 {
25  mesh(),
26  variable_simplex,
28 }
29 
30 double LocalNeighborsSumFunction::get_value(const simplex::Simplex& variable_simplex) const
31 {
32  const auto neighs = domain(variable_simplex);
33  assert(variable_simplex.primitive_type() == attribute_type());
34 
36  assert(mesh() == m_function.mesh());
37  // assert(attribute_handle() == m_function.attribute_handle());
38 
39  double res = 0;
40  for (const simplex::Simplex& cell : neighs) {
41  assert(cell.primitive_type() == m_domain_simplex_type);
42  res += m_function.get_value(cell);
43  }
44 
45  return res;
46 }
47 
49  const simplex::Simplex& variable_simplex) const
50 {
51  const auto neighs = domain(variable_simplex);
52  assert(variable_simplex.primitive_type() == attribute_type());
54  assert(mesh() == m_function.mesh());
55  // assert(attribute_handle() == m_function.attribute_handle());
56 
57  Eigen::VectorXd res = Eigen::VectorXd::Zero(embedded_dimension());
58 
59  for (const simplex::Simplex& cell : neighs) {
60  assert(cell.primitive_type() == m_domain_simplex_type);
61  res += m_function.get_gradient(cell, variable_simplex);
62  }
63 
64  return res;
65 }
66 
68  const simplex::Simplex& variable_simplex) const
69 {
70  const auto neighs = domain(variable_simplex);
71  assert(variable_simplex.primitive_type() == attribute_type());
73  assert(mesh() == m_function.mesh());
74  // assert(attribute_handle() == m_function.attribute_handle());
75 
76  Eigen::MatrixXd res = Eigen::MatrixXd::Zero(embedded_dimension(), embedded_dimension());
77 
78  for (const simplex::Simplex& cell : neighs) {
79  assert(cell.primitive_type() == m_domain_simplex_type);
80  res += m_function.get_hessian(cell, variable_simplex);
81  }
82 
83  return res;
84 }
85 
86 } // namespace wmtk::function
PrimitiveType top_simplex_type() const
Definition: Mesh.hpp:996
int64_t embedded_dimension() const
Definition: Function.cpp:15
PrimitiveType attribute_type() const
Definition: Function.hpp:49
double get_value(const simplex::Simplex &variable_simplex) const override
collects the local neigh and call the same m_function on all simplicies
Eigen::MatrixXd get_hessian(const simplex::Simplex &variable_simplex) const override
get_hessian evaluates the hessian of the function f(x) defined wrt the variable x.
Eigen::VectorXd get_gradient(const simplex::Simplex &variable_simplex) const override
get_gradient collects the local neigh and call the gradient of m_function on all simplicies
std::vector< simplex::Simplex > domain(const simplex::Simplex &variable_simplex) const override
LocalNeighborsSumFunction(Mesh &mesh, const attribute::MeshAttributeHandle &handle, PerSimplexFunction &function)
virtual Eigen::VectorXd get_gradient(const simplex::Simplex &domain_simplex, const simplex::Simplex &variable_simplex) const
virtual double get_value(const simplex::Simplex &domain_simplex) const =0
This function is defined over a simplex (normally a triangle or tetrahedron).
virtual Eigen::MatrixXd get_hessian(const simplex::Simplex &domain_simplex, const simplex::Simplex &variable_simplex) const
PrimitiveType primitive_type() const
Definition: Simplex.hpp:51
std::vector< Simplex > cofaces_single_dimension_simplices(const Mesh &mesh, const Simplex &simplex, PrimitiveType cofaces_type)