DUNE-ACFEM (2.5.1)

gradientfunction.hh
1#ifndef DUNE_ACFEM_GRADIENTFUNCTION_HH
2#define DUNE_ACFEM_GRADIENTFUNCTION_HH
3
4#include "../functions/localfunctionwrapper.hh"
5#include "../functions/gridfunctionexpression.hh"
6
7namespace Dune {
8 namespace ACFem {
9
23 template<class GridFunction>
25 {
26 typedef GridFunction GradientFunctionType;
27 typedef typename GradientFunctionType::DiscreteFunctionSpaceType DiscreteFunctionSpaceType;
28 typedef typename GradientFunctionType::LocalFunctionType LocalGradientFunctionType;
29 public:
30 typedef typename DiscreteFunctionSpaceType::FunctionSpaceType GradientFunctionSpaceType;
31 typedef typename
32 Fem::ToNewDimRangeFunctionSpace<GradientFunctionSpaceType, GradientFunctionSpaceType::dimDomain>::Type
33 FunctionSpaceType;
34 typedef typename GridFunction::GridPartType GridPartType;
35 typedef typename GridPartType::template Codim<0>::EntityType EntityType;
36
37 typedef typename FunctionSpaceType::RangeType RangeType;
38 typedef typename FunctionSpaceType::JacobianRangeType JacobianRangeType;
39 typedef typename FunctionSpaceType::HessianRangeType HessianRangeType;
40
41 static_assert((int)GradientFunctionSpaceType::dimRange == 1,
42 "Gradient Adapter needs dimRange == 1 for underlying function");
43
44 LocalGradientAdapter(const Fem::Function<GradientFunctionSpaceType, GradientFunctionType>& function,
45 const std::string& name = "")
46 : function_(function),
47 localFunction_(function_()),
48 name_(name == "" ? "grad(" + function_().name() + ")" : name)
49 {}
50
52 : function_(other.function_()),
53 localFunction_(function_()),
54 name_(other.name_)
55 {}
56
57 const std::string& name() const { return name_; }
58
59 // Implement needed interface method for the adapter class
60 void init(const EntityType& entity)
61 {
62 localFunction_.init(entity);
63 }
64
66 template<class PointType>
67 void evaluate(const PointType& x, RangeType& ret) const
68 {
69 typename GradientFunctionType::JacobianRangeType myValue;
70 localFunction_.jacobian(x, myValue);
71
72 // Now, the gradient is always a matrix. Convert it ...
73 ret = myValue[0];
74 }
75
77 template<class PointType>
78 void jacobian(const PointType& x, JacobianRangeType& ret) const
79 {
80 typename GradientFunctionType::HessianRangeType myJacobian;
81 localFunction_.hessian(x, myJacobian);
82
83 // The Hessian is a tensor. The actual jacobian in this case
84 // indeed is just the Hessian of the one and only component of
85 // the original function ...
86 ret = myJacobian[0];
87 }
88
89 // hessian of local function
90 template<class PointType>
91 void hessian(const PointType& x, HessianRangeType& ret) const
92 {
93#if __DUNE_ACFEM_MAKE_CHECK__
94 // in order not to disturb the test-suite, which greedily takes hessians from anything
95 ret = 0;
96#else
97 DUNE_THROW(NotImplemented, "Hessian of the gradient of a given function is NEVER implemented.");
98#endif
99 }
100
101 int order() const
102 {
103 return std::max(0, localFunction_.order() - 1);
104 }
105
106 protected:
107 ExpressionStorage<GradientFunctionType> function_;
108 mutable LocalGradientFunctionType localFunction_;
109 const std::string name_;
110 };
111
113
115
116 } // ACFem::
117
118} // Dune::
119
120
121#endif // DUNE_ACFEM_GRADIENTFUNCTION_HH
An adapter class to compute the gradient of a scalar GridFunction.
Definition: gradientfunction.hh:25
void jacobian(const PointType &x, JacobianRangeType &ret) const
gradient of local function
Definition: gradientfunction.hh:78
void evaluate(const PointType &x, RangeType &ret) const
evaluate local function
Definition: gradientfunction.hh:67
LocalFunctionWrapper< LocalMaxAdapter< GridFunction1, GridFunction2 >, typename GridFunction1::GridPartType > max(const Fem::Function< typename GridFunction1::FunctionSpaceType, GridFunction1 > &f1, const Fem::Function< typename GridFunction2::FunctionSpaceType, GridFunction2 > &f2, const std::string &name="")
Pointwise maximum of two given functions.
Definition: maxfunction.hh:121
Creative Commons License   |  Legal Statements / Impressum  |  Hosted by TU Dresden  |  generated with Hugo v0.111.3 (Aug 13, 22:30, 2024)