Dune-Fufem 2.12-git
Loading...
Searching...
No Matches
integratedbilinearform.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_INTEGRATEDBILINEARFORM_HH
8#define DUNE_FUFEM_FORMS_INTEGRATEDBILINEARFORM_HH
9
10#include <cstddef>
11#include <type_traits>
12#include <utility>
13
16
23
24
25
26namespace Dune::Fufem::Forms {
27
28
29
44 template<class BilinearOperator, class Domain=Dune::Fufem::Forms::Impl::Bulk, class QuadratureHint=Dune::Fufem::Forms::QuadratureHints::KeepOrder>
45 requires IsSumOperator<BilinearOperator>::value && (BilinearOperator::arity==2)
46 && IsBulkDomain<Domain>::value && QuadratureHints::IsQuadratureHint<QuadratureHint>::value
48 {
50 using TestRootLocalView = typename TestRootBasis::LocalView;
51 using TestRootTree = typename TestRootLocalView::Tree;
52
53 using AnsatzRootBasis = std::decay_t<decltype(std::get<1>(std::declval<BilinearOperator>().basis()))>;
54 using AnsatzRootLocalView = typename AnsatzRootBasis::LocalView;
55 using AnsatzRootTree = typename AnsatzRootLocalView::Tree;
56
57 using LocalOperator = decltype(localOperator(std::declval<BilinearOperator>()));
58
59 public:
60 using Element = typename BilinearOperator::Element;
61
62 IntegratedBilinearForm(const BilinearOperator& sumOperator, const Domain& domain, QuadratureHint quadratureHint)
63 : sumOperator_(sumOperator)
64 , sumLocalOperator_(localOperator(sumOperator_))
65 , domain_(domain)
66 , quadratureHint_(quadratureHint)
67 {}
68
69 IntegratedBilinearForm(const BilinearOperator& sumOperator, const Domain& domain)
71 : IntegratedBilinearForm(sumOperator, domain, QuadratureHint{})
72 {}
73
74 IntegratedBilinearForm(const BilinearOperator& sumOperator, QuadratureHint quadratureHint)
76 : IntegratedBilinearForm(sumOperator, Dune::Fufem::Forms::bulk, quadratureHint)
77 {}
78
79 IntegratedBilinearForm(const BilinearOperator& sumOperator)
81 : IntegratedBilinearForm(sumOperator, Dune::Fufem::Forms::bulk, QuadratureHint{})
82 {}
83
84 // The following constructors are deleted, to avoid storing a reference to a temporary domain.
85 IntegratedBilinearForm(const BilinearOperator&, Domain&&, QuadratureHint) = delete;
86 IntegratedBilinearForm(const BilinearOperator&, const Domain&&, QuadratureHint) = delete;
87 IntegratedBilinearForm(const BilinearOperator&, Domain&&) = delete;
88 IntegratedBilinearForm(const BilinearOperator&, const Domain&&) = delete;
89
90 const BilinearOperator& integrandOperator() const
91 {
92 return sumOperator_;
93 }
94
95 // Dune::Assembler interface
96
97 void bindLocalViews (const TestRootLocalView& testLocalView, const AnsatzRootLocalView& ansatzLocalView)
98 {
99 cacheManager_.clear();
100 sumLocalOperator_.registerLocalViews(testLocalView.rootLocalView(), ansatzLocalView.rootLocalView());
101 sumLocalOperator_.registerCaches(cacheManager_.prototype());
102 }
103
104 void bindElement (const Element& element)
105 {}
106
107 template <class LocalPattern>
108 void assembleElementMatrixPattern(const Element& element, LocalPattern& localPattern)
109 {
110 if (not domain_.contains(element))
111 return;
112 localPattern.addAll();
113 }
114
115 template <class LocalMatrix>
116 void assembleElementMatrix (const Element& element, LocalMatrix& localMatrix)
117 {
118 using namespace Dune::Indices;
119 using namespace Dune::Fufem::Forms::Impl::Tensor;
120
121 if (not domain_.contains(element))
122 return;
123 sumLocalOperator_.bind(element);
124
125 const auto& geometry = element.geometry();
126
127 Impl::forEachTupleEntry(sumLocalOperator_.operators(), [&](auto& op) {
128 cacheManager_[quadratureHint_(op.quadratureRuleKey())].invalidate();
129 });
130
131 // Lift rank by 2 to prepend zero indices for inside
132 auto localTensor = LiftRank(TensorView(localMatrix, _2), _2);
133
134 Impl::forEachTupleEntry(sumLocalOperator_.operators(), [&](auto& op) {
135 auto& cacheForRule = cacheManager_[quadratureHint_(op.quadratureRuleKey())];
136 op.bindToCaches(cacheForRule);
137 const auto& quadRule = cacheForRule.rule();
138 for (auto k : Dune::range(quadRule.size()))
139 {
140 const auto& quadPoint = quadRule[k];
141 const auto integrationWeight = quadPoint.weight() * geometry.integrationElement(quadPoint.position());
142 axpy(integrationWeight, op(k), localTensor);
143 }
144 });
145 }
146
147 // Dune::Fufem interface
148
159 template<class TestLocalView, class AnsatzLocalView>
160 [[deprecated("This method will be removed after 2.11. Use the local interface of dune-assembler instead")]]
161 void preprocess(const TestLocalView& testLocalView, const AnsatzLocalView& ansatzLocalView)
162 {
163 cacheManager_.clear();
164 sumLocalOperator_.registerLocalViews(testLocalView.rootLocalView(), ansatzLocalView.rootLocalView());
165 sumLocalOperator_.registerCaches(cacheManager_.prototype());
166 }
167
172 template<class LocalMatrix, class TestLocalView, class AnsatzLocalView>
173 [[deprecated("This method will be removed after 2.11. Use the local interface of dune-assembler instead")]]
174 void operator()(const Element& element, LocalMatrix& localMatrix, const TestLocalView& testSubspaceLocalView, const AnsatzLocalView& ansatzSubspaceLocalView)
175 {
176 bindElement(element);
177 assembleElementMatrix(element, localMatrix);
178 }
179
180 private:
181 const BilinearOperator sumOperator_;
182 mutable LocalOperator sumLocalOperator_;
184 const Domain& domain_;
185 QuadratureHint quadratureHint_;
186 };
187
188 template<class BilinearOperator, class Domain>
189 IntegratedBilinearForm(const BilinearOperator&, const Domain&) -> IntegratedBilinearForm<BilinearOperator, Domain>;
190
191
192
193 template<class BilinearOperator, class Domain, class QuadratureHint>
194 struct IsLocalAssembler<IntegratedBilinearForm<BilinearOperator, Domain, QuadratureHint>> : public std::true_type {};
195
196
197
198} // namespace Dune::Fufem::Forms
199
200
201#endif // DUNE_FUFEM_FORMS_INTEGRATEDBILINEARFORM_HH
virtual void operator()()=0
ALBERTA EL Element
A cache providing multiple versions for different quadrature rules.
Definition shapefunctioncache.hh:466
T forward(T... args)
constexpr Impl::Bulk bulk
Object representing the full grid view as integration domain.
Definition domains.hh:234
Definition baseclass.hh:22
IntegratedBilinearForm(const BilinearOperator &, const Domain &) -> IntegratedBilinearForm< BilinearOperator, Domain >
Definition localsumassembler.hh:80