Dune-Fufem 2.11-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 <type_traits>
11#include <utility>
12
14
15#include <dune/istl/matrix.hh>
17
21
22
23
24namespace Dune::Fufem::Forms {
25
26
27
39 template<class GV>
41 {
42 public:
43
44 using GridView = GV;
45 using Element = typename GridView::template Codim<0>::Entity;
46 using Intersection = typename GridView::Intersection;
48
50 : cacheId_(*this)
51 {}
52
54 : cacheId_(*this)
55 {}
56
58 {
59 static constexpr int dimension = FaceNormalOperator::Element::dimension;
61 public:
62
63 using Element = typename GridView::template Codim<0>::Entity;
64 using Intersection = typename GridView::Intersection;
67
69 : cacheId_(cacheId)
70 {}
71
72 auto quadratureRuleKey() const
73 {
74 return quadratureRuleKey_;
75 }
76
77 template<class... LV>
78 void registerLocalViews(const LV&... lvs)
79 {}
80
81 template<class... LV>
82 void registerOutsideLocalViews(const LV&... lvs)
83 {}
84
85 void registerCaches(CacheManager& cacheManager)
86 {
87 cacheIndex_ = cacheManager.registerCache(cacheId_, ValueCache(true));
88 }
89
91 {}
92
93 template<class Dummy=void>
94 void bind(const Element&)
95 {
96 static_assert(Dune::AlwaysFalse<Dummy>::value, "FaceNormalOperator can only be used for forms integrated over intersections");
97 }
98
99 void bind(const Intersection& intersection, const Element& element, const Element& otherElement)
100 {
101 intersection_ = &intersection;
102 intersectionIsOriented_ = (intersection_->inside() == element);
103 quadratureRuleKey_ = QuadratureRuleKey(element.type(), 0);
104 }
105
106 template<class... OutsideCacheManager>
107 void bindToCaches(CacheManager& cacheManager, OutsideCacheManager&... outsideCacheManager)
108 {
109 valueCache_ = &cacheManager.template getCache<ValueCache>(cacheIndex_);
110 if (valueCache_->isEmpty())
111 {
112 auto& values = valueCache_->getValues();
113 const auto& rule = valueCache_->rule();
114 if (intersectionIsOriented_)
115 for (auto k : Dune::range(rule.size()))
116 {
117 auto xInIntersection = intersection_->geometryInInside().local(rule[k].position());
118 values[k] = intersection_->unitOuterNormal(xInIntersection);
119 }
120 else
121 for (auto k : Dune::range(rule.size()))
122 {
123 auto xInIntersection = intersection_->geometryInOutside().local(rule[k].position());
124 values[k] = -intersection_->unitOuterNormal(xInIntersection);
125 }
126 valueCache_->setEmpty(false);
127 }
128 }
129
131 {
132 return Impl::Tensor::RankZeroTensor(valueCache_->getValues()[index]);
133 }
134
135 private:
136 QuadratureRuleKey quadratureRuleKey_;
137 const Intersection* intersection_ = nullptr;
138 bool intersectionIsOriented_ = false;
139 UniqueCacheId cacheId_;
140 std::size_t cacheIndex_ = 0;
141 ValueCache* valueCache_;
142 };
143
144 friend LocalOperator localOperator(const FaceNormalOperator& faceNormalOperator)
145 {
146 return LocalOperator(faceNormalOperator.cacheId_);
147 }
148
149 auto basis() const
150 {
151 return std::tuple<>();
152 }
153
154 auto treePath() const
155 {
156 return std::tuple<>();
157 }
158
159 private:
160 UniqueCacheId cacheId_;
161 };
162
163
164
177 template<class GV>
179 {
180 public:
181
182 using GridView = GV;
183 using Element = typename GridView::template Codim<0>::Entity;
184 using Intersection = typename GridView::Intersection;
185 using Range = double;
186
187 MeshSizeOperator() = default;
188
189 MeshSizeOperator(const GridView& gridView)
190 {}
191
193 {
194 static constexpr int dimension = MeshSizeOperator::Element::dimension;
195 public:
196
197 using Element = typename GridView::template Codim<0>::Entity;
198 using Intersection = typename GridView::Intersection;
200 using Range = double;
201
202 auto quadratureRuleKey() const
203 {
204 return quadratureRuleKey_;
205 }
206
207 template<class... LV>
208 void registerLocalViews(const LV&... lvs)
209 {}
210
211 template<class... LV>
212 void registerOutsideLocalViews(const LV&... lvs)
213 {}
214
215 void registerCaches(CacheManager& cacheManager)
216 {}
217
219 {}
220
221 void bind(const Element& element)
222 {
223 const auto& geometry = element.geometry();
224 auto&& re = Dune::referenceElement(geometry);
225 h_ = std::pow(geometry.integrationElement(re.position(0, 0)), 1./dimension);
226 quadratureRuleKey_ = QuadratureRuleKey(element.type(), 0);
227 }
228
229 void bind(const Intersection& intersection, const Element& element, const Element& otherElement)
230 {
231 const auto& geometry = intersection.geometry();
232 auto&& re = Dune::referenceElement(geometry);
233 h_ = std::pow(geometry.integrationElement(re.position(0, 0)), 1./(dimension-1));
234 quadratureRuleKey_ = QuadratureRuleKey(element.type(), 0);
235 }
236
237 template<class... OutsideCacheManager>
238 void bindToCaches(CacheManager& cacheManager, OutsideCacheManager&... outsideCacheManager)
239 {}
240
242 {
243 return Impl::Tensor::RankZeroTensor(h_);
244 }
245
246 private:
247 QuadratureRuleKey quadratureRuleKey_;
248 double h_ = 0;
249 };
250
251 friend LocalOperator localOperator(const MeshSizeOperator& meshSizeOperator)
252 {
253 return LocalOperator();
254 }
255
256 auto basis() const
257 {
258 return std::tuple<>();
259 }
260
261 auto treePath() const
262 {
263 return std::tuple<>();
264 }
265 };
266
267
268
269} // namespace Dune::Fufem::Forms
270
271
272
273#endif // DUNE_FUFEM_FORMS_GEOMETRYOPERATORS_HH
unspecified value type referenceElement(T &&... t)
static constexpr IntegralRange< std::decay_t< T > > range(T &&from, U &&to) noexcept
std::ptrdiff_t index() const
Definition baseclass.hh:22
Geometry::GlobalCoordinate GlobalCoordinate
Base class for multilinear operator implementations.
Definition baseclass.hh:73
Operator representing the normal field on intersection.
Definition geometryoperators.hh:41
typename GridView::Intersection Intersection
Definition geometryoperators.hh:46
auto basis() const
Definition geometryoperators.hh:149
FaceNormalOperator(const GridView &gridView)
Definition geometryoperators.hh:53
typename GridView::template Codim< 0 >::Entity Element
Definition geometryoperators.hh:45
auto treePath() const
Definition geometryoperators.hh:154
FaceNormalOperator()
Definition geometryoperators.hh:49
GV GridView
Definition geometryoperators.hh:44
friend LocalOperator localOperator(const FaceNormalOperator &faceNormalOperator)
Definition geometryoperators.hh:144
typename Intersection::GlobalCoordinate Range
Definition geometryoperators.hh:47
typename Intersection::GlobalCoordinate Range
Definition geometryoperators.hh:66
void bindToCaches(CacheManager &cacheManager, OutsideCacheManager &... outsideCacheManager)
Definition geometryoperators.hh:107
auto quadratureRuleKey() const
Definition geometryoperators.hh:72
LocalOperator(UniqueCacheId cacheId)
Definition geometryoperators.hh:68
void bind(const Intersection &intersection, const Element &element, const Element &otherElement)
Definition geometryoperators.hh:99
auto operator()(std::size_t index) const
Definition geometryoperators.hh:130
typename GridView::template Codim< 0 >::Entity Element
Definition geometryoperators.hh:63
void registerLocalViews(const LV &... lvs)
Definition geometryoperators.hh:78
typename GridView::Intersection Intersection
Definition geometryoperators.hh:64
void bind(const Element &)
Definition geometryoperators.hh:94
void registerCaches(CacheManager &cacheManager)
Definition geometryoperators.hh:85
void registerOutsideLocalViews(const LV &... lvs)
Definition geometryoperators.hh:82
void registerOutsideCaches(CacheManager &cacheManager)
Definition geometryoperators.hh:90
Operator representing the mesh size of entities.
Definition geometryoperators.hh:179
typename GridView::Intersection Intersection
Definition geometryoperators.hh:184
GV GridView
Definition geometryoperators.hh:182
auto treePath() const
Definition geometryoperators.hh:261
double Range
Definition geometryoperators.hh:185
typename GridView::template Codim< 0 >::Entity Element
Definition geometryoperators.hh:183
auto basis() const
Definition geometryoperators.hh:256
friend LocalOperator localOperator(const MeshSizeOperator &meshSizeOperator)
Definition geometryoperators.hh:251
MeshSizeOperator(const GridView &gridView)
Definition geometryoperators.hh:189
Definition geometryoperators.hh:193
void registerOutsideCaches(CacheManager &cacheManager)
Definition geometryoperators.hh:218
auto quadratureRuleKey() const
Definition geometryoperators.hh:202
void bind(const Element &element)
Definition geometryoperators.hh:221
typename GridView::Intersection Intersection
Definition geometryoperators.hh:198
typename GridView::template Codim< 0 >::Entity Element
Definition geometryoperators.hh:197
auto operator()(std::size_t index) const
Definition geometryoperators.hh:241
double Range
Definition geometryoperators.hh:200
void bind(const Intersection &intersection, const Element &element, const Element &otherElement)
Definition geometryoperators.hh:229
void registerOutsideLocalViews(const LV &... lvs)
Definition geometryoperators.hh:212
void bindToCaches(CacheManager &cacheManager, OutsideCacheManager &... outsideCacheManager)
Definition geometryoperators.hh:238
void registerLocalViews(const LV &... lvs)
Definition geometryoperators.hh:208
void registerCaches(CacheManager &cacheManager)
Definition geometryoperators.hh:215
Objects of this class are used to uniquely identifies a cache.
Definition shapefunctioncache.hh:569
A class for managing caches of different types.
Definition shapefunctioncache.hh:615
size_type registerCache(UniqueCacheId uniqueCacheId, Cache &&cache)
Register a new cache.
Definition shapefunctioncache.hh:753
A simple cache implementation storing values.
Definition shapefunctioncache.hh:808
auto & getValues()
Definition shapefunctioncache.hh:855
bool isEmpty()
Definition shapefunctioncache.hh:845
void setEmpty(bool isEmpty)
Definition shapefunctioncache.hh:850
const QuadratureRule & rule() const
Definition shapefunctioncache.hh:829
A token that specifies a quadrature rule.
Definition quadraturerulecache.hh:39
T forward(T... args)
T pow(T... args)