1#ifndef DUNE_ACFEM_DIVERGENCEFUNCTION_HH
2#define DUNE_ACFEM_DIVERGENCEFUNCTION_HH
4#include "../functions/localfunctionwrapper.hh"
5#include "../functions/gridfunctionexpression.hh"
19 template<
class Gr
idFunction>
22 typedef GridFunction DivergenceFunctionType;
23 typedef typename DivergenceFunctionType::DiscreteFunctionSpaceType DiscreteFunctionSpaceType;
24 typedef typename DivergenceFunctionType::LocalFunctionType LocalDivergenceFunctionType;
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;
31 typedef typename FunctionSpaceType::RangeType RangeType;
32 typedef typename FunctionSpaceType::JacobianRangeType JacobianRangeType;
33 typedef typename FunctionSpaceType::HessianRangeType HessianRangeType;
35 static_assert((int)DivergenceFunctionSpaceType::dimRange == (
int)FunctionSpaceType::dimDomain,
36 "Divergence Adapter needs dimRange == dimDomain for underlying function");
39 const std::string& name =
"")
40 : function_(function),
41 localFunction_(function_()),
42 name_(name ==
"" ?
"div(" + function_().name() +
")" : name)
46 : function_(other.function_()),
47 localFunction_(function_()),
51 const std::string& name()
const {
return name_; }
54 void init(
const EntityType& entity)
56 localFunction_.init(entity);
60 template<
class Po
intType>
61 void evaluate(
const PointType& x, RangeType& ret)
const
63 typename DivergenceFunctionType::JacobianRangeType divJacobian;
64 localFunction_.jacobian(x, divJacobian);
67 for (
int i = 0; i < FunctionSpaceType::dimDomain; ++i) {
68 ret[0] += divJacobian[i][i];
73 template<
class Po
intType>
74 void jacobian(
const PointType& x, JacobianRangeType& ret)
const
76 typename DivergenceFunctionType::HessianRangeType divHessian;
77 localFunction_.hessian(x, divHessian);
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];
88 template<
class Po
intType>
89 void hessian(
const PointType& x, HessianRangeType& ret)
const
91#if __DUNE_ACFEM_MAKE_CHECK__
95 DUNE_THROW(NotImplemented,
"Hessian of the divergence of a given function is NEVER implemented.");
100 ExpressionStorage<DivergenceFunctionType> function_;
101 mutable LocalDivergenceFunctionType localFunction_;
102 const std::string name_;
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