Dune-Fufem 2.12-git
Loading...
Searching...
No Matches
integratedskeletonbilinearform.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_INTEGRATEDSKELETONBILINEARFORM_HH
8#define DUNE_FUFEM_FORMS_INTEGRATEDSKELETONBILINEARFORM_HH
9
10#include <cstddef>
11#include <type_traits>
12#include <utility>
13
17
24
25
26
27namespace Dune::Fufem::Forms {
28
29
30
45 template<class BilinearOperator, class Domain, class QuadratureHint=Dune::Fufem::Forms::QuadratureHints::KeepOrder>
46 requires IsSumOperator<BilinearOperator>::value && (BilinearOperator::arity==2)
47 && IsSkeletonDomain<Domain>::value && QuadratureHints::IsQuadratureHint<QuadratureHint>::value
49 {
51 using TestRootLocalView = typename TestRootBasis::LocalView;
52 using TestRootTree = typename TestRootLocalView::Tree;
53
54 using AnsatzRootBasis = std::decay_t<decltype(std::get<1>(std::declval<BilinearOperator>().basis()))>;
55 using AnsatzRootLocalView = typename AnsatzRootBasis::LocalView;
56 using AnsatzRootTree = typename AnsatzRootLocalView::Tree;
57
58 using LocalOperator = decltype(localOperator(std::declval<BilinearOperator>()));
59
61 using QuadratureRule = typename CacheManager::QuadratureRule;
62 using QuadraturePoint = typename QuadratureRule::value_type;
63
64 public:
65 using Element = typename BilinearOperator::Element;
66 using Intersection = typename TestRootBasis::GridView::Intersection;
67
68 IntegratedSkeletonBilinearForm(const BilinearOperator& sumOperator, const Domain& domain, QuadratureHint quadratureHint)
69 : sumOperator_(sumOperator)
70 , sumLocalOperator_(localOperator(sumOperator_))
71 , sumLocalOperatorFlipped_(localOperator(sumOperator_))
72 , domain_(domain)
73 , quadratureHint_(quadratureHint)
74 {}
75
76 IntegratedSkeletonBilinearForm(const BilinearOperator& sumOperator, const Domain& domain)
78 : IntegratedSkeletonBilinearForm(sumOperator, domain, QuadratureHint{})
79 {}
80
81 // The following constructors are deleted, to avoid storing a reference to a temporary domain.
82 IntegratedSkeletonBilinearForm(const BilinearOperator&, Domain&&, QuadratureHint) = delete;
83 IntegratedSkeletonBilinearForm(const BilinearOperator&, const Domain&&, QuadratureHint) = delete;
84 IntegratedSkeletonBilinearForm(const BilinearOperator&, Domain&&) = delete;
85 IntegratedSkeletonBilinearForm(const BilinearOperator&, const Domain&&) = delete;
86
87 const BilinearOperator& integrandOperator() const
88 {
89 return sumOperator_;
90 }
91
92 // Dune::Assembler interface
93
94 void bindLocalViews (const TestRootLocalView& testLocalView, const AnsatzRootLocalView& ansatzLocalView)
95 {
96 insideCache_.clear();
97 sumLocalOperator_.registerLocalViews(testLocalView.rootLocalView(), ansatzLocalView.rootLocalView());
98 sumLocalOperator_.registerCaches(insideCache_);
99 sumLocalOperatorFlipped_.registerOutsideLocalViews(testLocalView.rootLocalView(), ansatzLocalView.rootLocalView());
100 sumLocalOperatorFlipped_.registerOutsideCaches(insideCache_);
101 insidePtr_ = &testLocalView.element();
102 }
103
104 void bindOutsideLocalViews (const TestRootLocalView& testLocalView, const AnsatzRootLocalView& ansatzLocalView)
105 {
106 outsideCache_.clear();
107 sumLocalOperator_.registerOutsideLocalViews(testLocalView.rootLocalView(), ansatzLocalView.rootLocalView());
108 sumLocalOperator_.registerOutsideCaches(outsideCache_);
109 sumLocalOperatorFlipped_.registerLocalViews(testLocalView.rootLocalView(), ansatzLocalView.rootLocalView());
110 sumLocalOperatorFlipped_.registerCaches(outsideCache_);
111 outsidePtr_ = &testLocalView.element();
112 }
113
114 void bindElement (const Element& element)
115 {}
116
117 template <class LocalPatterns>
118 void assembleInteriorIntersectionMatrixPattern (const Intersection& intersection, LocalPatterns& localPatterns)
119 {
120 if (not domain_.contains(intersection))
121 return;
122 localPatterns[0][0].addAll();
123 localPatterns[0][1].addAll();
124 localPatterns[1][0].addAll();
125 localPatterns[1][1].addAll();
126 }
127
128 template <class LocalMatrices>
129 void assembleInteriorIntersectionMatrix (const Intersection& intersection, LocalMatrices& localMatrices)
130 {
131 using namespace Dune::Indices;
132 using namespace Dune::Fufem::Forms::Impl::Tensor;
133
134 if (not domain_.contains(intersection))
135 return;
136
137 bool isOriented = true;
138 if constexpr (requires { domain_.isOriented(intersection); })
139 isOriented = domain_.isOriented(intersection);
140
141 // LocalMatrices only supports localMatrices[i][j][k][l] and localMatrices[i][j](k,l).
142 // The TensorView provides the unified access via localTensor(i,j,k,l).
143 auto localTensor = TensorView(localMatrices, _4);
144
145 if (isOriented)
146 {
147 sumLocalOperator_.bind(intersection, *insidePtr_, *outsidePtr_);
148
149 const auto& geometry = intersection.geometry();
150 const auto& geometryInInside = intersection.geometryInInside();
151 const auto& geometryInOutside = intersection.geometryInOutside();
152
153 // Since we will often have many boundary terms (e.g. for DG)
154 // while evaluations are currently not cached across elements,
155 // we use a single quadrature rule for all addends despite the
156 // fact that a lower order might also be sufficient for some of them.
157 auto key = quadratureHint_(sumLocalOperator_.quadratureRuleKey());
158 key.setGeometryType(geometry.type());
160
161 // Notice that we cannot easily cache evaluation by identifying quadrature rules
162 // on intersections across different elements. To guarantee that quadrature
163 // points match up on inside and outside, we have to compute the element coordinates
164 // of intersection quadrature points using the intersection. This has the effect
165 // that the e.g. points on face 2 may be different on two elements because the
166 // intersections are not oriented consistently. The latter problem could be solved
167 // by computing the element coordinates using the reference element embedding, but
168 // then inside and outside quadrature points would not match up.
169 //
170 // Hence we take the intersection approach (which is also robust wrt. non-conforming
171 // intersections) and do not cache across different intersections so far.
172 // Since the operator expects a cache, we use caches that are reset for any intersection.
173 insideRule_.resize(rule.size(), QuadraturePoint(typename QuadraturePoint::Vector(), 0));
174 for (auto k : Dune::range(rule.size()))
175 insideRule_[k] = QuadraturePoint(geometryInInside.global(rule[k].position()), 0);
176 insideCache_.setRule(insideRule_);
177
178 outsideRule_.resize(rule.size(), QuadraturePoint(typename QuadraturePoint::Vector(), 0));
179 for (auto k : Dune::range(rule.size()))
180 outsideRule_[k] = QuadraturePoint(geometryInOutside.global(rule[k].position()), 0);
181 outsideCache_.setRule(outsideRule_);
182
183 sumLocalOperator_.bindToCaches(insideCache_, outsideCache_);
184
185 for (auto k : Dune::range(rule.size()))
186 {
187 Impl::forEachTupleEntry(sumLocalOperator_.operators(), [&](auto& op) {
188 const auto integrationWeight = rule[k].weight() * geometry.integrationElement(rule[k].position());
189 axpy(integrationWeight, op(k), localTensor);
190 });
191 }
192 }
193 else
194 {
195 // If the intersection is not oriented, we need to flip the two leading indices
196 auto flippedLocalTensor = FlipIndices(localTensor, _2);
197
198 sumLocalOperatorFlipped_.bind(intersection, *outsidePtr_, *insidePtr_);
199
200 const auto& geometry = intersection.geometry();
201 const auto& geometryInInside = intersection.geometryInInside();
202 const auto& geometryInOutside = intersection.geometryInOutside();
203
204 // Since we will often have many boundary terms (e.g. for DG)
205 // while evaluations are currently not cached across elements,
206 // we use a single quadrature rule for all addends despite the
207 // fact that a lower order might also be sufficient for some of them.
208 auto key = quadratureHint_(sumLocalOperatorFlipped_.quadratureRuleKey());
209 key.setGeometryType(geometry.type());
211
212 // Notice that we cannot easily cache evaluation by identifying quadrature rules
213 // on intersections across different elements. To guarantee that quadrature
214 // points match up on inside and outside, we have to compute the element coordinates
215 // of intersection quadrature points using the intersection. This has the effect
216 // that the e.g. points on face 2 may be different on two elements because the
217 // intersections are not oriented consistently. The latter problem could be solved
218 // by computing the element coordinates using the reference element embedding, but
219 // then inside and outside quadrature points would not match up.
220 //
221 // Hence we take the intersection approach (which is also robust wrt. non-conforming
222 // intersections) and do not cache across different intersections so far.
223 // Since the operator expects a cache, we use caches that are reset for any intersection.
224 insideRule_.resize(rule.size(), QuadraturePoint(typename QuadraturePoint::Vector(), 0));
225 for (auto k : Dune::range(rule.size()))
226 insideRule_[k] = QuadraturePoint(geometryInInside.global(rule[k].position()), 0);
227 insideCache_.setRule(insideRule_);
228
229 outsideRule_.resize(rule.size(), QuadraturePoint(typename QuadraturePoint::Vector(), 0));
230 for (auto k : Dune::range(rule.size()))
231 outsideRule_[k] = QuadraturePoint(geometryInOutside.global(rule[k].position()), 0);
232 outsideCache_.setRule(outsideRule_);
233
234 sumLocalOperatorFlipped_.bindToCaches(outsideCache_, insideCache_);
235
236 for (auto k : Dune::range(rule.size()))
237 {
238 Impl::forEachTupleEntry(sumLocalOperatorFlipped_.operators(), [&](auto& op) {
239 const auto integrationWeight = rule[k].weight() * geometry.integrationElement(rule[k].position());
240 axpy(integrationWeight, op(k), flippedLocalTensor);
241 });
242 }
243 }
244
245 }
246
247 private:
248 const BilinearOperator sumOperator_;
249 mutable LocalOperator sumLocalOperator_;
250 mutable LocalOperator sumLocalOperatorFlipped_;
251 const Element* insidePtr_ = nullptr;
252 const Element* outsidePtr_ = nullptr;
253 mutable QuadratureRule insideRule_;
254 mutable QuadratureRule outsideRule_;
255 CacheManager insideCache_;
256 CacheManager outsideCache_;
257 const Domain& domain_;
258 QuadratureHint quadratureHint_;
259 };
260
261 template<class BilinearOperator, class Domain>
262 IntegratedSkeletonBilinearForm(const BilinearOperator&, const Domain&) -> IntegratedSkeletonBilinearForm<BilinearOperator, Domain>;
263
264
265
266 template<class BilinearOperator, class Domain, class QuadratureHint>
267 struct IsLocalAssembler<IntegratedSkeletonBilinearForm<BilinearOperator, Domain, QuadratureHint>> : public std::true_type {};
268
269
270
271} // namespace Dune::Fufem::Forms
272
273
274#endif // DUNE_FUFEM_FORMS_INTEGRATEDSKELETONBILINEARFORM_HH
int size() const
static constexpr IntegralRange< T > range(T from, T to) noexcept
const GlobalIndex & global() const
ALBERTA EL Element
A class for managing caches of different types.
Definition shapefunctioncache.hh:644
Dune::QuadratureRule< CT, dimension > QuadratureRule
Definition shapefunctioncache.hh:646
static const Dune::QuadratureRule< coord_type, dim > & rule(const Dune::GeometryType &gt, const int order, int refinement)
Definition quadraturerulecache.hh:206
T forward(T... args)
Definition baseclass.hh:22
IntegratedSkeletonBilinearForm(const BilinearOperator &, const Domain &) -> IntegratedSkeletonBilinearForm< BilinearOperator, Domain >
Definition localsumassembler.hh:80