Wildmeshing Toolkit
PerSimplexAutodiffFunction.hpp
Go to the documentation of this file.
1 #pragma once
2 
3 #include "PerSimplexFunction.hpp"
4 
9 
10 #include <optional>
11 
12 namespace wmtk::function {
19 {
20 public:
21  using DScalar = DScalar2<double, Eigen::Matrix<double, -1, 1>, Eigen::Matrix<double, -1, -1>>;
22  using Scalar = typename DScalar::Scalar;
23  using DSVec = Eigen::VectorX<DScalar>;
24 
25  static_assert(
26  std::is_same_v<Scalar, double>); // MTAO: i'm leaving scalar here but is it ever not double?
28  const Mesh& mesh,
29  const PrimitiveType primitive_type,
30  const attribute::MeshAttributeHandle& variable_attribute_handle);
31 
33 
34 
35  double get_value(const simplex::Simplex& domain_simplex) const override;
36 
37  Eigen::VectorXd get_gradient(
38  const simplex::Simplex& domain_simplex,
39  const simplex::Simplex& variable_simplex) const override;
40 
41  Eigen::MatrixXd get_hessian(
42  const simplex::Simplex& domain_simplex,
43  const simplex::Simplex& variable_simplex) const override;
44 
45 protected:
63  std::vector<DSVec> get_coordinates(
64  const simplex::Simplex& domain_simplex,
65  const std::optional<simplex::Simplex>& variable_simplex_opt = {}) const;
66 
67  std::vector<DSVec> get_coordinates(
68  const attribute::Accessor<double>& accessor,
69  const simplex::Simplex& domain_simplex,
70  const std::optional<simplex::Simplex>& variable_simplex_opt = {}) const;
71 
72 
83  virtual DScalar eval(
84  const simplex::Simplex& domain_simplex,
85  const std::vector<DSVec>& coordinates) const = 0;
86 };
87 
88 } // namespace wmtk::function
A CachingAccessor that uses tuples for accessing attributes instead of indices.
Definition: Accessor.hpp:25
This is an extension of the PerSimplexFunction class that uses autodiff encoding for differentiations...
Eigen::VectorXd get_gradient(const simplex::Simplex &domain_simplex, const simplex::Simplex &variable_simplex) const override
Eigen::MatrixXd get_hessian(const simplex::Simplex &domain_simplex, const simplex::Simplex &variable_simplex) const override
std::vector< DSVec > get_coordinates(const simplex::Simplex &domain_simplex, const std::optional< simplex::Simplex > &variable_simplex_opt={}) const
This is a helper function that obtains the coordinates of the variables for the function f(x) where f...
PerSimplexAutodiffFunction(const Mesh &mesh, const PrimitiveType primitive_type, const attribute::MeshAttributeHandle &variable_attribute_handle)
double get_value(const simplex::Simplex &domain_simplex) const override
This function is defined over a simplex (normally a triangle or tetrahedron).
virtual DScalar eval(const simplex::Simplex &domain_simplex, const std::vector< DSVec > &coordinates) const =0
This function defines a function f(x) where f is defined over a simplex domain and the variables for ...
Automatic differentiation scalar with first- and second-order derivatives.
Definition: autodiff.h:501
_Scalar Scalar
Definition: autodiff.h:503