DUNE-ACFEM (2.5.1)

l2boundaryfunctional.hh
1#ifndef __DUNE_ACFEM_L2_SCALAR_PRODUCT_FUNCTIONAL_HH__
2#define __DUNE_ACFEM_L2_SCALAR_PRODUCT_FUNCTIONAL_HH__
3
4#include "linearfunctional.hh"
5#include "../../models/boundaryindicator.hh"
6#include "../../common/quadrature.hh"
7#include "../../functions/gridfunctionexpression.hh"
8#include "../../functions/boundaryfunctionexpression.hh"
9
10namespace Dune {
11
12 namespace ACFem {
13
22 template<class DiscreteFunctionSpace,
23 class GridFunction,
24 class BndryIndicator = EntireBoundaryIndicatorType,
25 template<class> class QuadratureTraits = DefaultQuadratureTraits>
26 class L2BoundaryFunctional;
27
28 template<class DiscreteFunctionSpace,
29 class GridFunction,
30 class BndryIndicator,
31 template<class> class QuadratureTraits>
32 class LocalL2BoundaryFunctional;
33
34 template<class DiscreteFunctionSpace,
35 class GridFunction,
36 class BndryIndicator,
37 template<class> class QuadratureTraits>
38 struct L2BoundaryFunctionalTraits
39 : public
40 LinearFunctionalTraitsDefault<
41 L2BoundaryFunctional<DiscreteFunctionSpace,
42 GridFunction,
43 BndryIndicator,
44 QuadratureTraits>,
45 LocalL2BoundaryFunctional<DiscreteFunctionSpace,
46 GridFunction,
47 BndryIndicator,
48 QuadratureTraits> >
49 {
50 private:
51 typedef L2BoundaryFunctionalTraits ThisType;
52 public:
53 /*There are two possibilities for zero-expressions:
54 *
55 * - GridFunction is a zero-expression (either zero-function of zero-supported)
56 * - BndryIndicator is a zero-expression
57 */
58 typedef typename
59 std::conditional<ExpressionTraits<GridFunction>::isZero || ExpressionTraits<BndryIndicator>::isZero,
60 ZeroFunctionalExpression<DiscreteFunctionSpace, ThisType>,
61 DiscreteLinearFunctionalExpression<DiscreteFunctionSpace, ThisType>
62 >::type
63 ExpressionBaseType;
64 };
65
66 template<class DiscreteFunctionSpace,
67 class GridFunction,
68 class BndryIndicator,
69 template<class> class QuadratureTraits>
70 class L2BoundaryFunctional
71 : public L2BoundaryFunctionalTraits<DiscreteFunctionSpace,
72 GridFunction,
73 BndryIndicator,
74 QuadratureTraits>::ExpressionBaseType
75 {
76 typedef L2BoundaryFunctional ThisType;
77 public:
78 typedef
79 L2BoundaryFunctionalTraits<DiscreteFunctionSpace, GridFunction, BndryIndicator, QuadratureTraits>
80 TraitsType;
81 typedef GridFunction L2FunctionType;
82 typedef BndryIndicator OuterIndicatorType;
83 protected:
84 typedef typename TraitsType::ExpressionBaseType BaseType;
85 public:
86 typedef
87 decltype(std::declval<OuterIndicatorType>() * std::declval<L2FunctionType>())
88 BndryFunctionType;
89 typedef typename BndryFunctionType::IndicatorType IndicatorType;
90 typedef DiscreteFunctionSpace DiscreteFunctionSpaceType;
91 typedef typename DiscreteFunctionSpaceType::FunctionSpaceType FunctionSpaceType;
92 typedef
93 Fem::Function<typename L2FunctionType::FunctionSpaceType, L2FunctionType>
94 L2FunctionInterfaceType;
95 typedef
96 Fem::DiscreteFunctionSpaceInterface<typename DiscreteFunctionSpaceType::Traits>
97 DiscreteFunctionSpaceInterfaceType;
98 typedef
99 BoundaryIndicatorInterface<OuterIndicatorType>
100 IndicatorInterfaceType;
101
102 L2BoundaryFunctional(const DiscreteFunctionSpaceInterfaceType& space,
103 const L2FunctionInterfaceType& L2Fct,
104 const IndicatorInterfaceType& indicator = OuterIndicatorType(),
105 unsigned degree = 2*DiscreteFunctionSpaceType::polynomialOrder)
106 : BaseType(static_cast<const DiscreteFunctionSpaceType&>(space)),
107 bndryFct_(asImp(indicator) * asImp(L2Fct)),
108 degree_(degree)
109 {}
110
111 using BaseType::operator();
112 using BaseType::coefficients;
113 using BaseType::space;
114 using BaseType::localFunctional;
115
116 std::string name() const
117 {
118 return "[" + bndryFct_().name() + ", . ]";
119 }
120
121 const BndryFunctionType& function() const
122 {
123 return bndryFct_();
124 }
125
126 unsigned quadratureDegree() const
127 {
128 return degree_;
129 }
130
131 const IndicatorType& indicator() const
132 {
133 return function().indicator();
134 }
135
136 IndicatorType& indicator()
137 {
138 return function().indicator();
139 }
140
141 protected:
142 ExpressionStorage<BndryFunctionType> bndryFct_;
143 const unsigned degree_;
144 };
145
146 template<class DiscreteFunctionSpace,
147 class GridFunction,
148 class BndryIndicator,
149 template<class> class QuadratureTraits>
150 class LocalL2BoundaryFunctional
151 : public LocalLinearFunctionalDefault<DiscreteFunctionSpace,
152 L2BoundaryFunctionalTraits<DiscreteFunctionSpace,
153 GridFunction,
154 BndryIndicator,
155 QuadratureTraits> >
156 {
157 public:
158 typedef
159 L2BoundaryFunctionalTraits<DiscreteFunctionSpace,
160 GridFunction,
161 BndryIndicator,
162 QuadratureTraits>
163 TraitsType;
164 private:
165 typedef LocalL2BoundaryFunctional ThisType;
166 typedef LocalLinearFunctionalDefault<DiscreteFunctionSpace, TraitsType> BaseType;
167 public:
168 typedef
169 L2BoundaryFunctional<DiscreteFunctionSpace, GridFunction, BndryIndicator, QuadratureTraits>
170 FunctionalType;
171 typedef DiscreteFunctionSpace DiscreteFunctionSpaceType;
172 typedef typename DiscreteFunctionSpaceType::EntityType EntityType;
173 typedef typename DiscreteFunctionSpaceType::RangeFieldType FieldType;
174 typedef FieldType RangeType;
175 protected:
176 typedef typename FunctionalType::IndicatorType IndicatorType;
177 typedef typename FunctionalType::BndryFunctionType BndryFunctionType;
178 typedef typename BndryFunctionType::LocalFunctionType LocalBndryFunctionType;
179 typedef typename DiscreteFunctionSpaceType::GridPartType GridPartType;
180 typedef QuadratureTraits<GridPartType> QuadratureTraitsType;
181 typedef typename QuadratureTraitsType::BulkQuadratureType QuadratureType;
182 typedef typename QuadratureTraitsType::BulkMassQuadratureType MassQuadratureType;
183 typedef typename QuadratureTraitsType::FaceQuadratureType FaceQuadratureType;
184 typedef typename QuadratureTraitsType::FaceMassQuadratureType FaceMassQuadratureType;
185
186 typedef Dune::Fem::IntersectionQuadrature<FaceMassQuadratureType, true> IntersectionMassQuadratureType;
187 typedef typename IntersectionMassQuadratureType::FaceQuadratureType BndryMassQuadratureType;
188
189 public:
190 LocalL2BoundaryFunctional(const FunctionalType& phi)
191 : BaseType(phi),
192 bndryLocal_(phi.function()),
193 indicator_(phi.function().indicator()),
194 gridPart_(phi.space().gridPart()),
195 degree_(phi.quadratureDegree())
196 {}
197
198 LocalL2BoundaryFunctional(const EntityType& entity, const FunctionalType& phi)
199 : BaseType(entity, phi),
200 bndryLocal_(phi.function()),
201 indicator_(phi.function().indicator()),
202 gridPart_(phi.space().gridPart()),
203 degree_(phi.quadratureDegree())
204 {}
205
206 public:
207
208 template<class LocalFunction>
209 RangeType operator()(const LocalFunction& wLocal) const
210 {
211 if (ExpressionTraits<IndicatorType>::isZero) {
212 // nothing to do
213 return 0;
214 }
215
216 const auto& entity = wLocal.entity();
217
218 if (!entity.hasBoundaryIntersections()) {
219 return 0;
220 }
221
222 return BaseType::operator()(wLocal);
223 }
224
225 template<class LocalFunction>
226 void coefficients(const RangeType& c, LocalFunction& coeffs) const
227 {
228 if (ExpressionTraits<IndicatorType>::isZero) {
229 return;
230 }
231
232 const auto& entity = coeffs.entity();
233
234 if (!entity.hasBoundaryIntersections()) {
235 return;
236 }
237
238 const auto iend = gridPart_.iend(entity);
239 for (auto it = gridPart_.ibegin(entity); it != iend; ++it) {
240
241 const auto &intersection = *it;
242
243 if (intersection.neighbor() || !intersection.boundary()) {
244 continue;
245 }
246
247 if (!indicator_.applies(intersection)) {
248 continue;
249 }
250
251 bndryLocal_.init(entity, intersection); // assume this is cheap ... in this context
252
253 const int quadOrder = degree_;
254
255 IntersectionMassQuadratureType intersectionQuad(gridPart_, intersection, quadOrder);
256 const BndryMassQuadratureType &bndryQuad = intersectionQuad.inside();
257 const int numQuadraturePoints = bndryQuad.nop();
258
259 for (int pt = 0; pt < numQuadraturePoints; ++pt) {
260
261 // quadrature weight
262 const double weight = bndryQuad.weight(pt);
263
264 // integration element
265 const double integrationElement = intersection.geometry().integrationElement(bndryQuad.localPoint(pt));
266
267 typename LocalBndryFunctionType::RangeType f;
268 bndryLocal_.evaluate(bndryQuad[pt], f);
269 f *= weight * integrationElement * c;
270 coeffs.axpy(bndryQuad[pt], f);
271
272 } // end boundary quadrature loop
273
274 } // end Intersection loop
275
276 }
277
278 template<class LocalFunction>
279 void coefficients(LocalFunction& coeffs) const
280 {
282 }
283
284 using BaseType::operator();
285 using BaseType::functional;
286 using BaseType::entity;
287
288 protected:
289 using BaseType::entity_;
290 mutable LocalBndryFunctionType bndryLocal_;
291 const IndicatorType& indicator_;
292 const GridPartType& gridPart_;
293 const unsigned degree_;
294 };
295
297
299
300 } // namespace ACFem
301
302} // namespace Dune
303
304#endif // __DUNE_ACFEM_L2_SCALAR_PRODUCT_FUNCTIONAL_HH__
void coefficients(LocalFunction &coeffs) const
Compute the basis representation, which means: do the assembling stuff.
Definition: linearfunctional.hh:436
RangeType operator()(const LocalFunction &arg) const
Compute the value.
Definition: linearfunctional.hh:410
constexpr bool isZero(Expression &&)
Specialize to evaluate to true for zero expressions.
Definition: expressionoperations.hh:469
const Implementation & asImp(const Fem::BartonNackmanInterface< Interface, Implementation > &arg)
Up-cast to the implementation for any Fem::BartonNackmanInterface.
Definition: expressionoperations.hh:71
Creative Commons License   |  Legal Statements / Impressum  |  Hosted by TU Dresden & Uni Heidelberg  |  generated with Hugo v0.111.3 (Mar 12, 23:28, 2025)