DUNE-ACFEM (2.5.1)

maxfunction.hh
1#ifndef DUNE_ACFEM_MAXFUNCTION_HH
2#define DUNE_ACFEM_MAXFUNCTION_HH
3
4#include "constantfunction.hh"
5
6namespace Dune {
7 namespace ACFem {
8
15 template<class GridFunction1, class GridFunction2>
17 {
18 static_assert(std::is_same<typename GridFunction1::FunctionSpaceType,
19 typename GridFunction2::FunctionSpaceType>::value, "Functions have different FunctionSpaceType");
20
21 typedef typename GridFunction1::LocalFunctionType LocalFunctionType1;
22 typedef typename GridFunction2::LocalFunctionType LocalFunctionType2;
23
24 public:
25 typedef typename GridFunction1::FunctionSpaceType FunctionSpaceType;
26 typedef typename GridFunction1::GridPartType GridPartType;
27 typedef typename GridPartType::template Codim<0>::EntityType EntityType;
28
29 typedef typename FunctionSpaceType::RangeType RangeType;
30 typedef typename FunctionSpaceType::JacobianRangeType JacobianRangeType;
31 typedef typename FunctionSpaceType::HessianRangeType HessianRangeType;
32 enum{dimRange = FunctionSpaceType::dimRange};
33
34 LocalMaxAdapter(const Fem::Function<FunctionSpaceType, GridFunction1>& f1,
35 const Fem::Function<FunctionSpaceType, GridFunction2>& f2,
36 const std::string& name = "")
37 : f1_(f1), f2_(f2),
38 locf1_(f1_()), locf2_(f2_()),
39 name_(name == "" ? "max{" + f1_().name() + "," + f2_().name() + "}" : name)
40 {}
41
43 : f1_(other.f1_()), f2_(other.f2_()),
44 locf1_(f1_()), locf2_(f2_()),
45 name_(other.name_)
46 {}
47
48 const std::string& name() const
49 {
50 return name_;
51 }
52
53 void init(const EntityType& entity)
54 {
55 locf1_.init(entity);
56 locf2_.init(entity);
57 }
58
59 template<class PointType>
60 void evaluate(const PointType& x, RangeType& ret) const
61 {
62 RangeType value2;
63
64 locf1_.evaluate(x, ret);
65 locf2_.evaluate(x, value2);
66 for(int i = 0; i < dimRange; ++ i)
67 if (ret[i] < value2[i])
68 ret[i] = value2[i];
69 }
70
71 template<class PointType>
72 void jacobian(const PointType& x, JacobianRangeType& ret) const
73 {
74 RangeType value1;
75 RangeType value2;
76 locf1_.evaluate(x, value1);
77 locf2_.evaluate(x, value2);
78 JacobianRangeType jacValue2;
79 locf1_.jacobian(x, ret);
80 locf2_.jacobian(x, jacValue2);
81
82 for(int i = 0; i < dimRange; ++i)
83 if (value1[i] < value2[i])
84 ret[i] = jacValue2[i];
85 }
86
87 template<class PointType>
88 void hessian(const PointType& x, HessianRangeType& ret) const
89 {
90 RangeType value1;
91 RangeType value2;
92 locf1_.evaluate(x, value1);
93 locf2_.evaluate(x, value2);
94 HessianRangeType hesValue2;
95 locf1_.hessian(x, ret);
96 locf2_.hessian(x, hesValue2);
97
98 for(int i = 0; i < dimRange; ++i)
99 if (value1[i] < value2[i])
100 ret[i] = hesValue2[i];
101 }
102
103 int order() const
104 {
105 return std::max(locf1_.order(), locf2_.order());
106 }
107
108 protected:
111 mutable LocalFunctionType1 locf1_;
112 mutable LocalFunctionType2 locf2_;
113 const std::string name_;
114 };
115
116
119 template<class GridFunction1, class GridFunction2>
120 LocalFunctionWrapper<LocalMaxAdapter<GridFunction1, GridFunction2>, typename GridFunction1::GridPartType>
121 max(const Fem::Function<typename GridFunction1::FunctionSpaceType, GridFunction1>& f1,
122 const Fem::Function<typename GridFunction2::FunctionSpaceType, GridFunction2>& f2,
123 const std::string& name = "")
124 {
125 const auto& f1_ = static_cast<const GridFunction1&>(f1);
126 const auto& f2_ = static_cast<const GridFunction2&>(f2);
128
129 return LocalFunctionWrapper<LocalMaxAdapter<GridFunction1, GridFunction2>, typename GridFunction1::GridPartType>
130 (local.name(), local, f1_.space().gridPart(), std::max(f1_.space().order(), f2_.space().order()));
131 }
132
136 template<class GridFunction1>
137 LocalFunctionWrapper<LocalMaxAdapter<GridFunction1, ConstantGridFunction< typename GridFunction1::FunctionSpaceType, typename GridFunction1::GridPartType> >, typename GridFunction1::GridPartType>
138 max(const Fem::Function<typename GridFunction1::FunctionSpaceType, GridFunction1>& f1,
139 const typename GridFunction1::FunctionSpaceType::RangeType value2,
140 const std::string& name = "")
141 {
143 const auto& f1_ = static_cast<const GridFunction1&>(f1);
144 const GridFunction2 f2_(value2 , f1_.space().gridPart() );
146
147 return LocalFunctionWrapper<LocalMaxAdapter<GridFunction1, GridFunction2>, typename GridFunction1::GridPartType>
148 (local.name(), local, f1_.space().gridPart(), std::max(f1_.space().order(), f2_.space().order()));
149 }
150
151
153
154 } // ACFem::
155
156} // Dune::
157
158
159#endif // DUNE_ACFEM_MAXFUNCTION_HH
ConstantGridFunction implements a constant function.
Definition: constantfunction.hh:108
LocalFunctionWrapper wraps a class with a local evaluate method into a grid function.
Definition: localfunctionwrapper.hh:71
An adapter class to compute the (pointwise) maximum of two scalar GridFunctions.
Definition: maxfunction.hh:17
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
LocalFunctionWrapper< LocalMaxAdapter< GridFunction1, ConstantGridFunction< typename GridFunction1::FunctionSpaceType, typename GridFunction1::GridPartType > >, typename GridFunction1::GridPartType > max(const Fem::Function< typename GridFunction1::FunctionSpaceType, GridFunction1 > &f1, const typename GridFunction1::FunctionSpaceType::RangeType value2, const std::string &name="")
Pointwise maximum of two given functions where one is given by a RangeType value.
Definition: maxfunction.hh:138
Creative Commons License   |  Legal Statements / Impressum  |  Hosted by TU Dresden  |  generated with Hugo v0.111.3 (Aug 13, 22:30, 2024)