DUNE-ACFEM (2.5.1)

normfunction.hh
1 #ifndef DUNE_ACFEM_NORMFUNCTION_HH
2 #define DUNE_ACFEM_NORMFUNCTION_HH
3 
4 
5 namespace Dune {
6  namespace ACFem {
7 
12  // TODO: implement
13  template<class GridFunction, unsigned int p>
14  class LocalNormAdapter;
15 
16 
19  template<class GridFunction>
20  class LocalNormAdapter<GridFunction, 2>
21  {
22  typedef GridFunction NormFunctionType;
23  typedef typename NormFunctionType::DiscreteFunctionSpaceType DiscreteFunctionSpaceType;
24  typedef typename NormFunctionType::LocalFunctionType LocalNormFunctionType;
25  public:
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;
30 
31  typedef typename FunctionSpaceType::RangeType RangeType;
32  typedef typename FunctionSpaceType::JacobianRangeType JacobianRangeType;
33  typedef typename FunctionSpaceType::HessianRangeType HessianRangeType;
34 
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)
40  {}
41 
42  LocalNormAdapter(const LocalNormAdapter& other)
43  : function_(other.function_()),
44  localFunction_(function_()),
45  name_(other.name_)
46  {}
47 
48  const std::string& name() const { return name_; }
49 
50  void init(const EntityType& entity)
51  {
52  localFunction_.init(entity);
53  }
54 
55  template<class PointType>
56  void evaluate(const PointType& x, RangeType& ret) const
57  {
58  typename NormFunctionType::RangeType value;
59  localFunction_.evaluate(x, value);
60  ret = value.two_norm();
61  }
62 
63  template<class PointType>
64  void jacobian(const PointType& x, JacobianRangeType& ret) const
65  {
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();
71 
72  ret = 0;
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];
76  }
77  }
78  }
79 
80  // hessian of local function
81  template<class PointType>
82  void hessian(const PointType& x, HessianRangeType& ret) const
83  {
84 #if __DUNE_ACFEM_MAKE_CHECK__
85  // in order not to disturb the test-suite, which greedily takes hessians from anything
86  ret = 0;
87 #else
88  DUNE_THROW(NotImplemented, "Hessian of the norm of a given function is not implemented.");
89 #endif
90  }
91 
92  int order() const
93  {
94  return localFunction_.order() == 0 ? 0 : 111;
95  }
96 
97  protected:
99  mutable LocalNormFunctionType localFunction_;
100  const std::string name_;
101  };
102 
103 
106  template<class GridFunction>
107  LocalFunctionWrapper<LocalNormAdapter<GridFunction, 2>, typename GridFunction::GridPartType>
108  twoNorm(const Fem::Function<typename GridFunction::FunctionSpaceType, GridFunction>& f,
109  const std::string& name = "")
110  {
111  const auto& f_ = static_cast<const GridFunction&>(f);
112  LocalNormAdapter<GridFunction, 2> local(f_, name);
113 
114  return LocalFunctionWrapper<LocalNormAdapter<GridFunction, 2>, typename GridFunction::GridPartType>
115  (local.name(), local, f_.space().gridPart(), f_.space().order() == 0 ? 0 : 111);
116  }
117 
119 
120  } // ACFem::
121 
122 } // Dune::
123 
124 
125 #endif // DUNE_ACFEM_NORMFUNCTION_HH
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
Creative Commons License   |  Legal Statements / Impressum  |  Hosted by TU Dresden  |  generated with Hugo v0.80.0 (May 16, 22:29, 2024)