Dune-Fufem 2.11-git
Loading...
Searching...
No Matches
integratedboundarybilinearform.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_INTEGRATEDBOUNDARYBILINEARFORM_HH
8#define DUNE_FUFEM_FORMS_INTEGRATEDBOUNDARYBILINEARFORM_HH
9
10#include <cstddef>
11#include <type_traits>
12#include <utility>
13
16
21
22
23
24namespace Dune::Fufem::Forms {
25
26
27
41 template<class BilinearOperator, class Domain>
43 {
45 using TestRootLocalView = typename TestRootBasis::LocalView;
46 using TestRootTree = typename TestRootLocalView::Tree;
47
49 using AnsatzRootLocalView = typename AnsatzRootBasis::LocalView;
50 using AnsatzRootTree = typename AnsatzRootLocalView::Tree;
51
52 using LocalOperator = decltype(localOperator(std::declval<BilinearOperator>()));
53
55
56 public:
57
58 using Element = typename LocalOperator::Element;
59 using Intersection = typename LocalOperator::Intersection;
60
61 IntegratedBoundaryBilinearForm(const BilinearOperator& sumOperator, const Domain& domain) :
62 sumOperator_(sumOperator),
63 sumLocalOperator_(localOperator(sumOperator_)),
64 domain_(domain)
65 {}
66
67 const BilinearOperator& integrandOperator() const
68 {
69 return sumOperator_;
70 }
71
72 // Dune::Assembler interface
73
74 void bindLocalViews (const TestRootLocalView& testLocalView, const AnsatzRootLocalView& ansatzLocalView)
75 {
76 cacheManager_.clear();
77 sumLocalOperator_.registerLocalViews(testLocalView.rootLocalView(), ansatzLocalView.rootLocalView());
78 sumLocalOperator_.registerCaches(cacheManager_.prototype());
79 insidePtr_ = &testLocalView.element();
80 }
81
82 void bindElement (const Element& element)
83 {}
84
85 template <class LocalPattern>
86 void assembleBoundaryIntersectionMatrixPattern(const Intersection& intersection, LocalPattern& localPattern)
87 {
88 if (not domain_.contains(intersection))
89 return;
90 localPattern.addAll();
91 }
92
93 template<class LocalMatrix>
94 void assembleBoundaryIntersectionMatrix(const Intersection& intersection, LocalMatrix& localMatrix)
95 {
96 using namespace Dune::Indices;
97 using namespace Dune::Fufem::Forms::Impl::Tensor;
98
99 if (not domain_.contains(intersection))
100 return;
101
102 sumLocalOperator_.bind(intersection, *insidePtr_, *insidePtr_);
103
104 auto facet = intersection.indexInInside();
105
106 const auto& geometry = intersection.geometry();
107
108 Impl::forEachTupleEntry(sumLocalOperator_.operators(), [&](auto& op) {
109 cacheManager_[FacetKey(op.quadratureRuleKey(), facet)].invalidate();
110 });
111
112 // Lift rank by 2 to prepend zero indices for inside
113 auto localTensor = LiftRank(TensorView(localMatrix, _2), _2);
114
115 Impl::forEachTupleEntry(sumLocalOperator_.operators(), [&](auto& op) {
116 auto& cacheForRule = cacheManager_[FacetKey(op.quadratureRuleKey(), facet)];
117 op.bindToCaches(cacheForRule);
118 const auto& quadRule = cacheForRule.rule();
119 for (auto k : Dune::range(quadRule.size()))
120 {
121 const auto& quadPoint = quadRule[k];
122 auto quadPointPositionInFacet = intersection.geometryInInside().local(quadPoint.position());
123 const auto integrationWeight = quadPoint.weight() * geometry.integrationElement(quadPointPositionInFacet);
124 axpy(integrationWeight, op(k), localTensor);
125 }
126 });
127 }
128
129 // Dune::Fufem interface
130
138 template<class TestLocalView, class AnsatzLocalView>
139 void preprocess(const TestLocalView& testLocalView, const AnsatzLocalView& ansatzLocalView)
140 {
141 cacheManager_.clear();
142 sumLocalOperator_.registerLocalViews(testLocalView.rootLocalView(), ansatzLocalView.rootLocalView());
143 sumLocalOperator_.registerCaches(cacheManager_.prototype());
144 insidePtr_ = &testLocalView.element();
145 }
146
147 template<class LocalMatrix, class TestLocalView, class AnsatzLocalView>
148 void operator()(const Element& element, LocalMatrix& localMatrix, const TestLocalView& testSubspaceLocalView, const AnsatzLocalView& ansatzSubspaceLocalView)
149 {
150 bool processElement = true;
151 if constexpr (requires{domain_.containsFaceOf(element);})
152 processElement = domain_.containsFaceOf(element);
153 if (processElement)
154 {
155 bindElement(element);
156 const auto& gridView = testSubspaceLocalView.globalBasis().rootBasis().gridView();
157 for(const auto& intersection : intersections(gridView, element))
158 if (intersection.boundary() && !intersection.neighbor())
159 assembleBoundaryIntersectionMatrix(intersection, localMatrix);
160 }
161 }
162
163 private:
164 const BilinearOperator sumOperator_;
165 mutable LocalOperator sumLocalOperator_;
166 const Element* insidePtr_ = nullptr;
168 const Domain& domain_;
169 };
170
171
172
173 template<class BilinearOperator, class Domain>
174 struct IsLocalAssembler<IntegratedBoundaryBilinearForm<BilinearOperator, Domain>> : public std::true_type {};
175
176
177
178} // namespace Dune::Fufem::Forms
179
180
181#endif // DUNE_FUFEM_FORMS_INTEGRATEDBOUNDARYBILINEARFORM_HH
Definition baseclass.hh:22
Local assembler corresponding to a boundary bilinear form.
Definition integratedboundarybilinearform.hh:43
void assembleBoundaryIntersectionMatrixPattern(const Intersection &intersection, LocalPattern &localPattern)
Definition integratedboundarybilinearform.hh:86
void preprocess(const TestLocalView &testLocalView, const AnsatzLocalView &ansatzLocalView)
Register local views.
Definition integratedboundarybilinearform.hh:139
void bindLocalViews(const TestRootLocalView &testLocalView, const AnsatzRootLocalView &ansatzLocalView)
Definition integratedboundarybilinearform.hh:74
IntegratedBoundaryBilinearForm(const BilinearOperator &sumOperator, const Domain &domain)
Definition integratedboundarybilinearform.hh:61
const BilinearOperator & integrandOperator() const
Definition integratedboundarybilinearform.hh:67
typename LocalOperator::Element Element
Definition integratedboundarybilinearform.hh:58
void assembleBoundaryIntersectionMatrix(const Intersection &intersection, LocalMatrix &localMatrix)
Definition integratedboundarybilinearform.hh:94
void bindElement(const Element &element)
Definition integratedboundarybilinearform.hh:82
void operator()(const Element &element, LocalMatrix &localMatrix, const TestLocalView &testSubspaceLocalView, const AnsatzLocalView &ansatzSubspaceLocalView)
Definition integratedboundarybilinearform.hh:148
typename LocalOperator::Intersection Intersection
Definition integratedboundarybilinearform.hh:59
Definition localsumassembler.hh:80
A cache providing multiple versions for different quadrature rules.
Definition shapefunctioncache.hh:467
T forward(T... args)