Dune-Fufem 2.12-git
Loading...
Searching...
No Matches
geometryoperators.hh
Go to the documentation of this file.
1// -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
2// vi: set et ts=4 sw=2 sts=2:
3
4// SPDX-FileCopyrightText: Copyright © DUNE-FUFEM Project contributors, see file AUTHORS.md
5// SPDX-License-Identifier: LicenseRef-GPL-2.0-only-with-DUNE-exception OR LGPL-3.0-or-later
6
7#ifndef DUNE_FUFEM_FORMS_GEOMETRYOPERATORS_HH
8#define DUNE_FUFEM_FORMS_GEOMETRYOPERATORS_HH
9
10#include <cmath>
11#include <type_traits>
12#include <utility>
13
15
16#include <dune/istl/matrix.hh>
18
22
23
24
25namespace Dune::Fufem::Forms {
26
27
28
40 template<class GV>
42 {
43 public:
44
45 using GridView = GV;
46 using Element = typename GridView::template Codim<0>::Entity;
47 using Intersection = typename GridView::Intersection;
49
51 : cacheId_(UniqueCacheId::makeUniqueCacheId())
52 {}
53
55 : cacheId_(UniqueCacheId::makeUniqueCacheId())
56 {}
57
59 {
60 static constexpr int dimension = FaceNormalOperator::Element::dimension;
62 public:
63
64 using Element = typename GridView::template Codim<0>::Entity;
65 using Intersection = typename GridView::Intersection;
68
70 : cacheId_(cacheId)
71 {}
72
73 auto quadratureRuleKey() const
74 {
75 return quadratureRuleKey_;
76 }
77
78 template<class... LV>
79 void registerLocalViews(const LV&... lvs)
80 {}
81
82 template<class... LV>
83 void registerOutsideLocalViews(const LV&... lvs)
84 {}
85
86 void registerCaches(CacheManager& cacheManager)
87 {
88 cacheIndex_ = cacheManager.registerCache(cacheId_, ValueCache(true));
89 }
90
92 {}
93
94 template<class Dummy=void>
95 void bind(const Element&)
96 {
97 static_assert(Dune::AlwaysFalse<Dummy>::value, "FaceNormalOperator can only be used for forms integrated over intersections");
98 }
99
100 void bind(const Intersection& intersection, const Element& element, const Element& otherElement)
101 {
102 intersection_ = &intersection;
103 intersectionIsOriented_ = (intersection_->inside() == element);
104 quadratureRuleKey_ = QuadratureRuleKey(element.type(), 0);
105 }
106
107 void unbind()
108 {
109 intersection_ = nullptr;
110 }
111
112 template<class... OutsideCacheManager>
113 void bindToCaches(CacheManager& cacheManager, OutsideCacheManager&... outsideCacheManager)
114 {
115 valueCache_ = &cacheManager.template getCache<ValueCache>(cacheIndex_);
116 if (valueCache_->isEmpty())
117 {
118 auto& values = valueCache_->getValues();
119 const auto& rule = valueCache_->rule();
120 if (intersectionIsOriented_)
121 for (auto k : Dune::range(rule.size()))
122 {
123 auto xInIntersection = intersection_->geometryInInside().local(rule[k].position());
124 values[k] = intersection_->unitOuterNormal(xInIntersection);
125 }
126 else
127 for (auto k : Dune::range(rule.size()))
128 {
129 auto xInIntersection = intersection_->geometryInOutside().local(rule[k].position());
130 values[k] = -intersection_->unitOuterNormal(xInIntersection);
131 }
132 valueCache_->setEmpty(false);
133 }
134 }
135
137 {
138 return Impl::Tensor::RankZeroTensor(valueCache_->getValues()[index]);
139 }
140
141 private:
142 QuadratureRuleKey quadratureRuleKey_;
143 const Intersection* intersection_ = nullptr;
144 bool intersectionIsOriented_ = false;
145 UniqueCacheId cacheId_;
146 std::size_t cacheIndex_ = 0;
147 ValueCache* valueCache_ = nullptr;
148 };
149
150 friend LocalOperator localOperator(const FaceNormalOperator& faceNormalOperator)
151 {
152 return LocalOperator(faceNormalOperator.cacheId_);
153 }
154
155 auto basis() const
156 {
157 return std::tuple<>();
158 }
159
160 auto treePath() const
161 {
162 return std::tuple<>();
163 }
164
165 private:
166 UniqueCacheId cacheId_;
167 };
168
169
170
187 template<class GV>
189 {
190 public:
191
192 using GridView = GV;
193 using Element = typename GridView::template Codim<0>::Entity;
194 using Intersection = typename GridView::Intersection;
195 using Range = double;
196
197 MeshSizeOperator() = default;
198
199 MeshSizeOperator(const GridView& gridView)
200 {}
201
203 {
204 static constexpr int dimension = MeshSizeOperator::Element::dimension;
205 public:
206
207 using Element = typename GridView::template Codim<0>::Entity;
208 using Intersection = typename GridView::Intersection;
210 using Range = double;
211
212 auto quadratureRuleKey() const
213 {
214 return quadratureRuleKey_;
215 }
216
217 template<class... LV>
218 void registerLocalViews(const LV&... lvs)
219 {}
220
221 template<class... LV>
222 void registerOutsideLocalViews(const LV&... lvs)
223 {}
224
225 void registerCaches(CacheManager& cacheManager)
226 {}
227
229 {}
230
231 void bind(const Element& element)
232 {
233 if constexpr (dimension>1)
234 {
235 const auto& geometry = element.geometry();
236 auto&& re = Dune::referenceElement(geometry);
237 h_ = std::pow(geometry.integrationElement(re.position(0, 0)), 1./dimension);
238 }
239 else
240 h_ = element.geometry().volume();
241 quadratureRuleKey_ = QuadratureRuleKey(element.type(), 0);
242 }
243
244 void bind(const Intersection& intersection, const Element& element, const Element& otherElement)
245 {
246 if constexpr (dimension>1)
247 {
248 const auto& geometry = intersection.geometry();
249 auto&& re = Dune::referenceElement(geometry);
250 h_ = std::pow(geometry.integrationElement(re.position(0, 0)), 1./(dimension-1));
251 }
252 else
253 h_ = (element.geometry().volume() + otherElement.geometry().volume()) / 2;
254 quadratureRuleKey_ = QuadratureRuleKey(element.type(), 0);
255 }
256
257 void unbind()
258 {}
259
260 template<class... OutsideCacheManager>
261 void bindToCaches(CacheManager& cacheManager, OutsideCacheManager&... outsideCacheManager)
262 {}
263
265 {
266 return Impl::Tensor::RankZeroTensor(h_);
267 }
268
269 private:
270 QuadratureRuleKey quadratureRuleKey_;
271 double h_ = 0;
272 };
273
274 friend LocalOperator localOperator(const MeshSizeOperator& meshSizeOperator)
275 {
276 return LocalOperator();
277 }
278
279 auto basis() const
280 {
281 return std::tuple<>();
282 }
283
284 auto treePath() const
285 {
286 return std::tuple<>();
287 }
288 };
289
290
291
292} // namespace Dune::Fufem::Forms
293
294
295
296#endif // DUNE_FUFEM_FORMS_GEOMETRYOPERATORS_HH
unspecified value type referenceElement(T &&... t)
static constexpr IntegralRange< T > range(T from, T to) noexcept
std::ptrdiff_t index() const
Geometry::GlobalCoordinate GlobalCoordinate
A class for managing caches of different types.
Definition shapefunctioncache.hh:644
size_type registerCache(UniqueCacheId uniqueCacheId, Cache &&cache)
Register a new cache.
Definition shapefunctioncache.hh:782
typename Intersection::GlobalCoordinate Range
Definition geometryoperators.hh:67
void bindToCaches(CacheManager &cacheManager, OutsideCacheManager &... outsideCacheManager)
Definition geometryoperators.hh:113
void unbind()
Definition geometryoperators.hh:107
auto quadratureRuleKey() const
Definition geometryoperators.hh:73
LocalOperator(UniqueCacheId cacheId)
Definition geometryoperators.hh:69
void bind(const Intersection &intersection, const Element &element, const Element &otherElement)
Definition geometryoperators.hh:100
auto operator()(std::size_t index) const
Definition geometryoperators.hh:136
typename GridView::template Codim< 0 >::Entity Element
Definition geometryoperators.hh:64
void registerLocalViews(const LV &... lvs)
Definition geometryoperators.hh:79
typename GridView::Intersection Intersection
Definition geometryoperators.hh:65
void bind(const Element &)
Definition geometryoperators.hh:95
void registerCaches(CacheManager &cacheManager)
Definition geometryoperators.hh:86
void registerOutsideLocalViews(const LV &... lvs)
Definition geometryoperators.hh:83
void registerOutsideCaches(CacheManager &cacheManager)
Definition geometryoperators.hh:91
Operator representing the normal field on intersection.
Definition geometryoperators.hh:42
typename GridView::Intersection Intersection
Definition geometryoperators.hh:47
auto basis() const
Definition geometryoperators.hh:155
FaceNormalOperator(const GridView &gridView)
Definition geometryoperators.hh:54
typename GridView::template Codim< 0 >::Entity Element
Definition geometryoperators.hh:46
auto treePath() const
Definition geometryoperators.hh:160
FaceNormalOperator()
Definition geometryoperators.hh:50
GV GridView
Definition geometryoperators.hh:45
friend LocalOperator localOperator(const FaceNormalOperator &faceNormalOperator)
Definition geometryoperators.hh:150
typename Intersection::GlobalCoordinate Range
Definition geometryoperators.hh:48
Definition geometryoperators.hh:203
void registerOutsideCaches(CacheManager &cacheManager)
Definition geometryoperators.hh:228
void unbind()
Definition geometryoperators.hh:257
auto quadratureRuleKey() const
Definition geometryoperators.hh:212
void bind(const Element &element)
Definition geometryoperators.hh:231
typename GridView::Intersection Intersection
Definition geometryoperators.hh:208
typename GridView::template Codim< 0 >::Entity Element
Definition geometryoperators.hh:207
auto operator()(std::size_t index) const
Definition geometryoperators.hh:264
double Range
Definition geometryoperators.hh:210
void bind(const Intersection &intersection, const Element &element, const Element &otherElement)
Definition geometryoperators.hh:244
void registerOutsideLocalViews(const LV &... lvs)
Definition geometryoperators.hh:222
void bindToCaches(CacheManager &cacheManager, OutsideCacheManager &... outsideCacheManager)
Definition geometryoperators.hh:261
void registerLocalViews(const LV &... lvs)
Definition geometryoperators.hh:218
void registerCaches(CacheManager &cacheManager)
Definition geometryoperators.hh:225
Operator representing the mesh size of entities.
Definition geometryoperators.hh:189
typename GridView::Intersection Intersection
Definition geometryoperators.hh:194
GV GridView
Definition geometryoperators.hh:192
auto treePath() const
Definition geometryoperators.hh:284
double Range
Definition geometryoperators.hh:195
typename GridView::template Codim< 0 >::Entity Element
Definition geometryoperators.hh:193
auto basis() const
Definition geometryoperators.hh:279
friend LocalOperator localOperator(const MeshSizeOperator &meshSizeOperator)
Definition geometryoperators.hh:274
MeshSizeOperator(const GridView &gridView)
Definition geometryoperators.hh:199
Base class for multilinear operator implementations.
Definition baseclass.hh:73
A simple cache implementation storing values.
Definition shapefunctioncache.hh:837
auto & getValues()
Definition shapefunctioncache.hh:884
bool isEmpty()
Definition shapefunctioncache.hh:874
void setEmpty(bool isEmpty)
Definition shapefunctioncache.hh:879
const QuadratureRule & rule() const
Definition shapefunctioncache.hh:858
Objects of this class are used to uniquely identifies a cache.
Definition shapefunctioncache.hh:571
A token that specifies a quadrature rule.
Definition quadraturerulecache.hh:40
T forward(T... args)
Definition baseclass.hh:22
T pow(T... args)