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