DUNE-ACFEM (2.5.1)

divergencefunction.hh
1#ifndef DUNE_ACFEM_DIVERGENCEFUNCTION_HH
2#define DUNE_ACFEM_DIVERGENCEFUNCTION_HH
3
4#include "../functions/localfunctionwrapper.hh"
5#include "../functions/gridfunctionexpression.hh"
6
7namespace Dune {
8 namespace ACFem {
9
19 template<class GridFunction>
21 {
22 typedef GridFunction DivergenceFunctionType;
23 typedef typename DivergenceFunctionType::DiscreteFunctionSpaceType DiscreteFunctionSpaceType;
24 typedef typename DivergenceFunctionType::LocalFunctionType LocalDivergenceFunctionType;
25 public:
26 typedef typename DiscreteFunctionSpaceType::FunctionSpaceType DivergenceFunctionSpaceType;
27 typedef typename DivergenceFunctionSpaceType::ScalarFunctionSpaceType FunctionSpaceType;
28 typedef typename GridFunction::GridPartType GridPartType;
29 typedef typename GridPartType::template Codim<0>::EntityType EntityType;
30
31 typedef typename FunctionSpaceType::RangeType RangeType;
32 typedef typename FunctionSpaceType::JacobianRangeType JacobianRangeType;
33 typedef typename FunctionSpaceType::HessianRangeType HessianRangeType;
34
35 static_assert((int)DivergenceFunctionSpaceType::dimRange == (int)FunctionSpaceType::dimDomain,
36 "Divergence Adapter needs dimRange == dimDomain for underlying function");
37
38 LocalDivergenceAdapter(const Fem::Function<DivergenceFunctionSpaceType, DivergenceFunctionType>& function,
39 const std::string& name = "")
40 : function_(function),
41 localFunction_(function_()),
42 name_(name == "" ? "div(" + function_().name() + ")" : name)
43 {}
44
46 : function_(other.function_()),
47 localFunction_(function_()),
48 name_(other.name_)
49 {}
50
51 const std::string& name() const { return name_; }
52
53 // Implement needed interface method for the adapter class
54 void init(const EntityType& entity)
55 {
56 localFunction_.init(entity);
57 }
58
60 template<class PointType>
61 void evaluate(const PointType& x, RangeType& ret) const
62 {
63 typename DivergenceFunctionType::JacobianRangeType divJacobian;
64 localFunction_.jacobian(x, divJacobian);
65
66 ret = 0;
67 for (int i = 0; i < FunctionSpaceType::dimDomain; ++i) {
68 ret[0] += divJacobian[i][i];
69 }
70 }
71
73 template<class PointType>
74 void jacobian(const PointType& x, JacobianRangeType& ret) const
75 {
76 typename DivergenceFunctionType::HessianRangeType divHessian;
77 localFunction_.hessian(x, divHessian);
78
79 ret = 0;
80 for (int i = 0; i < FunctionSpaceType::dimDomain; ++i) {
81 for (int j = 0; j < FunctionSpaceType::dimDomain; ++j) {
82 ret[0][i] += divHessian[0][i][j];
83 }
84 }
85 }
86
87 // hessian of local function
88 template<class PointType>
89 void hessian(const PointType& x, HessianRangeType& ret) const
90 {
91#if __DUNE_ACFEM_MAKE_CHECK__
92 // in order not to disturb the test-suite, which greedily takes hessians from anything
93 ret = 0;
94#else
95 DUNE_THROW(NotImplemented, "Hessian of the divergence of a given function is NEVER implemented.");
96#endif
97 }
98
99 protected:
100 ExpressionStorage<DivergenceFunctionType> function_;
101 mutable LocalDivergenceFunctionType localFunction_;
102 const std::string name_;
103 };
104
106
108
109 } // ACFem::
110
111} // Dune::
112
113
114#endif // DUNE_ACFEM_DIVERGENCEFUNCTION_HH
An adapter class to compute the divergence of a GridFunction.
Definition: divergencefunction.hh:21
void jacobian(const PointType &x, JacobianRangeType &ret) const
jacobian of local function
Definition: divergencefunction.hh:74
void evaluate(const PointType &x, RangeType &ret) const
evaluate local function
Definition: divergencefunction.hh:61
Creative Commons License   |  Legal Statements / Impressum  |  Hosted by TU Dresden  |  generated with Hugo v0.111.3 (Aug 13, 22:30, 2024)