1 #ifndef DUNE_ACFEM_NORMFUNCTION_HH
2 #define DUNE_ACFEM_NORMFUNCTION_HH
13 template<
class Gr
idFunction,
unsigned int p>
14 class LocalNormAdapter;
19 template<
class Gr
idFunction>
20 class LocalNormAdapter<GridFunction, 2>
22 typedef GridFunction NormFunctionType;
23 typedef typename NormFunctionType::DiscreteFunctionSpaceType DiscreteFunctionSpaceType;
24 typedef typename NormFunctionType::LocalFunctionType LocalNormFunctionType;
26 typedef typename DiscreteFunctionSpaceType::FunctionSpaceType NormFunctionSpaceType;
27 typedef typename NormFunctionSpaceType::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 LocalNormAdapter(
const Fem::Function<NormFunctionSpaceType, NormFunctionType>&
function,
36 const std::string& name =
"")
37 : function_(
function),
38 localFunction_(function_()),
39 name_(name ==
"" ?
"|" + function_().name() +
"|_2" : name)
42 LocalNormAdapter(
const LocalNormAdapter& other)
43 : function_(other.function_()),
44 localFunction_(function_()),
48 const std::string& name()
const {
return name_; }
50 void init(
const EntityType& entity)
52 localFunction_.init(entity);
55 template<
class Po
intType>
56 void evaluate(
const PointType& x, RangeType& ret)
const
58 typename NormFunctionType::RangeType value;
59 localFunction_.evaluate(x, value);
60 ret = value.two_norm();
63 template<
class Po
intType>
64 void jacobian(
const PointType& x, JacobianRangeType& ret)
const
66 typename NormFunctionType::RangeType value;
67 typename NormFunctionType::JacobianRangeType jacobian;
68 localFunction_.evaluate(x, value);
69 localFunction_.jacobian(x, jacobian);
70 const auto norm = value.two_norm();
73 for (
int j = 0; j < NormFunctionSpaceType::dimDomain; ++j) {
74 for (
int i = 0; i < NormFunctionSpaceType::dimRange; ++i) {
75 ret[0][j] += (value[i] / norm) * jacobian[i][j];
81 template<
class Po
intType>
82 void hessian(
const PointType& x, HessianRangeType& ret)
const
84 #if __DUNE_ACFEM_MAKE_CHECK__
88 DUNE_THROW(NotImplemented,
"Hessian of the norm of a given function is not implemented.");
94 return localFunction_.order() == 0 ? 0 : 111;
99 mutable LocalNormFunctionType localFunction_;
100 const std::string name_;
106 template<
class Gr
idFunction>
108 twoNorm(
const Fem::Function<typename GridFunction::FunctionSpaceType, GridFunction>& f,
109 const std::string& name =
"")
111 const auto& f_ =
static_cast<const GridFunction&
>(f);
115 (local.name(), local, f_.space().gridPart(), f_.space().order() == 0 ? 0 : 111);
LocalFunctionWrapper wraps a class with a local evaluate method into a grid function.
Definition: localfunctionwrapper.hh:71
An adapter class to represent the pointwise euclidean norm of a (usually vector-valued) GridFunction.
Definition: normfunction.hh:21
LocalFunctionWrapper< LocalNormAdapter< GridFunction, 2 >, typename GridFunction::GridPartType > twoNorm(const Fem::Function< typename GridFunction::FunctionSpaceType, GridFunction > &f, const std::string &name="")
Pointwise euclidean norm of a given function.
Definition: normfunction.hh:108