11#include <autodiff/forward/dual/dual.hpp>
12#include <autodiff/forward/dual/eigen.hpp>
29 template <
typename RealFE_,
typename FERequirementType_ = FERequirements<>,
bool useEigenRef = false,
30 bool forceAutoDiff = false>
34 using Basis =
typename RealFE::Basis;
48 if constexpr (
requires { RealFE::calculateMatrix(req, h); } and not forceAutoDiff) {
49 RealFE::calculateMatrix(req, h);
50 }
else if constexpr (
requires {
51 this->
template calculateVectorImpl<autodiff::dual>(
52 req, std::declval<
typename Traits::template VectorType<autodiff::dual>>(),
53 std::declval<const Eigen::VectorXdual&>());
56 Eigen::VectorXdual dx(this->localView().size());
57 Eigen::VectorXdual g(this->localView().size());
59 auto f = [&](
auto& x) ->
auto& {
61 this->
template calculateVectorImpl<autodiff::dual>(req, g, x);
64 jacobian(f, autodiff::wrt(dx), at(dx), g, h);
65 }
else if constexpr (
requires {
66 this->
template calculateScalarImpl<autodiff::dual2nd>(
67 req, std::declval<
typename Traits::template VectorType<autodiff::dual2nd>>());
70 Eigen::VectorXdual2nd dx(this->localView().size());
74 auto f = [&](
auto& x) {
return this->
template calculateScalarImpl<autodiff::dual2nd>(req, x); };
75 hessian(f, autodiff::wrt(dx), at(dx), e, g, h);
77 static_assert(Dune::AlwaysFalse<AutoDiffFE>::value,
78 "Appropriate calculateScalarImpl or calculateVectorImpl functions are not implemented for the "
90 if constexpr (
requires {
91 this->
template calculateVectorImpl<double>(
92 req, std::declval<
typename Traits::template VectorType<double>>(),
93 std::declval<const Eigen::VectorXd&>());
95 and not forceAutoDiff) {
96 return this->
template calculateVectorImpl<double>(req, g);
97 }
else if constexpr (
requires {
98 this->
template calculateScalarImpl<autodiff::dual>(
99 req, std::declval<const Eigen::VectorXdual&>());
102 Eigen::VectorXdual dx(this->localView().size());
105 auto f = [&](
auto& x) {
return this->
template calculateScalarImpl<autodiff::dual>(req, x); };
106 gradient(f, autodiff::wrt(dx), at(dx), e, g);
108 static_assert(Dune::AlwaysFalse<AutoDiffFE>::value,
109 "Appropriate calculateScalarImpl function is not implemented for the "
121 typename Traits::template VectorType<> g)
const {
122 Eigen::VectorXdual2nd dx(this->localView().size());
124 auto f = [&](
auto& x) {
return this->calculateScalarImpl(req, x); };
125 hessian(f, autodiff::wrt(dx), at(dx), g, h);
136 if constexpr (
requires { RealFE::calculateScalar(par); }) {
137 return RealFE::calculateScalar(par);
138 }
else if constexpr (
requires { this->calculateScalarImpl(par); }) {
140 return this->calculateScalarImpl(par);
142 static_assert(Dune::AlwaysFalse<AutoDiffFE>::value,
143 "Appropriate calculateScalar and calculateScalarImpl functions are not implemented for the "
162 template <
typename... Args>
Contains stl-like type traits.
Material property functions and conversion utilities.
Definition of the LinearElastic class for finite element mechanics computations.
Definition: simpleassemblers.hh:21
AutoDiffFE class, an automatic differentiation wrapper for finite elements.
Definition: autodifffe.hh:31
AutoDiffFE(Args &&... args)
Constructor for the AutoDiffFE class. Forward the construction to the underlying element.
Definition: autodifffe.hh:163
typename Traits::Element Element
Type of the element.
Definition: autodifffe.hh:37
double calculateScalar(const FERequirementType &par) const
Calculate the scalar value associated with the finite element.
Definition: autodifffe.hh:134
void calculateMatrix(const FERequirementType &req, typename Traits::template MatrixType<> h) const
Calculate the matrix associated with the finite element.
Definition: autodifffe.hh:46
void calculateVector(const FERequirementType &req, typename Traits::template VectorType<> g) const
Calculate the vector associated with the finite element.
Definition: autodifffe.hh:88
typename Traits::LocalView LocalView
Type of the local view.
Definition: autodifffe.hh:36
typename Traits::FERequirementType FERequirementType
Type of the Finite Element Requirements.
Definition: autodifffe.hh:38
typename RealFE::Basis Basis
Type of the basis.
Definition: autodifffe.hh:34
void calculateLocalSystem(const FERequirementType &req, typename Traits::template MatrixType<> h, typename Traits::template VectorType<> g) const
Calculate the local system associated with the finite element.
Definition: autodifffe.hh:120
RealFE_ RealFE
Type of the base finite element.
Definition: autodifffe.hh:33
const RealFE & realFE() const
Get the reference to the base finite element.
Definition: autodifffe.hh:153
Traits for handling finite elements.see https://en.wikipedia.org/wiki/Lam%C3%A9_parameters.
Definition: physicshelper.hh:68
typename LocalView::Element Element
Type of the grid element.
Definition: physicshelper.hh:88
typename FlatBasis::LocalView LocalView
Type of the local view.
Definition: physicshelper.hh:82
FERequirements_ FERequirementType
Type of the requirements for the finite element.
Definition: physicshelper.hh:73