Dune-Fufem 2.11-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
22
23
24
25namespace Dune::Fufem::Forms {
26
27
28
42 template<class BilinearOperator, class Domain=Dune::Fufem::Forms::Bulk>
44 {
46 using TestRootLocalView = typename TestRootBasis::LocalView;
47 using TestRootTree = typename TestRootLocalView::Tree;
48
50 using AnsatzRootLocalView = typename AnsatzRootBasis::LocalView;
51 using AnsatzRootTree = typename AnsatzRootLocalView::Tree;
52
53 using LocalOperator = decltype(localOperator(std::declval<BilinearOperator>()));
54
55 public:
56 using Element = typename BilinearOperator::Element;
57
58 IntegratedBilinearForm(const BilinearOperator& sumOperator, const Domain& domain) :
59 sumOperator_(sumOperator),
60 sumLocalOperator_(localOperator(sumOperator_)),
61 domain_(domain)
62 {}
63
68
69 const BilinearOperator& integrandOperator() const
70 {
71 return sumOperator_;
72 }
73
74 // Dune::Assembler interface
75
76 void bindLocalViews (const TestRootLocalView& testLocalView, const AnsatzRootLocalView& ansatzLocalView)
77 {
78 cacheManager_.clear();
79 sumLocalOperator_.registerLocalViews(testLocalView.rootLocalView(), ansatzLocalView.rootLocalView());
80 sumLocalOperator_.registerCaches(cacheManager_.prototype());
81 }
82
83 void bindElement (const Element& element)
84 {}
85
86 template <class LocalPattern>
87 void assembleElementMatrixPattern(const Element& element, LocalPattern& localPattern)
88 {
89 if (not domain_.contains(element))
90 return;
91 localPattern.addAll();
92 }
93
94 template <class LocalMatrix>
95 void assembleElementMatrix (const Element& element, LocalMatrix& localMatrix)
96 {
97 using namespace Dune::Indices;
98 using namespace Dune::Fufem::Forms::Impl::Tensor;
99
100 if (not domain_.contains(element))
101 return;
102 sumLocalOperator_.bind(element);
103
104 const auto& geometry = element.geometry();
105
106 Impl::forEachTupleEntry(sumLocalOperator_.operators(), [&](auto& op) {
107 cacheManager_[op.quadratureRuleKey()].invalidate();
108 });
109
110 // Lift rank by 2 to prepend zero indices for inside
111 auto localTensor = LiftRank(TensorView(localMatrix, _2), _2);
112
113 Impl::forEachTupleEntry(sumLocalOperator_.operators(), [&](auto& op) {
114 auto& cacheForRule = cacheManager_[op.quadratureRuleKey()];
115 op.bindToCaches(cacheForRule);
116 const auto& quadRule = cacheForRule.rule();
117 for (auto k : Dune::range(quadRule.size()))
118 {
119 const auto& quadPoint = quadRule[k];
120 const auto integrationWeight = quadPoint.weight() * geometry.integrationElement(quadPoint.position());
121 axpy(integrationWeight, op(k), localTensor);
122 }
123 });
124 }
125
126 // Dune::Fufem interface
127
135 template<class TestLocalView, class AnsatzLocalView>
136 void preprocess(const TestLocalView& testLocalView, const AnsatzLocalView& ansatzLocalView)
137 {
138 cacheManager_.clear();
139 sumLocalOperator_.registerLocalViews(testLocalView.rootLocalView(), ansatzLocalView.rootLocalView());
140 sumLocalOperator_.registerCaches(cacheManager_.prototype());
141 }
142
143 template<class LocalMatrix, class TestLocalView, class AnsatzLocalView>
144 void operator()(const Element& element, LocalMatrix& localMatrix, const TestLocalView& testSubspaceLocalView, const AnsatzLocalView& ansatzSubspaceLocalView)
145 {
146 bindElement(element);
147 assembleElementMatrix(element, localMatrix);
148 }
149
150 private:
151 const BilinearOperator sumOperator_;
152 mutable LocalOperator sumLocalOperator_;
154 const Domain& domain_;
155 };
156
157
158
159 template<class BilinearOperator, class Domain>
160 struct IsLocalAssembler<IntegratedBilinearForm<BilinearOperator, Domain>> : public std::true_type {};
161
162
163
164} // namespace Dune::Fufem::Forms
165
166
167#endif // DUNE_FUFEM_FORMS_INTEGRATEDBILINEARFORM_HH
constexpr Bulk bulk
Object representing the full grid view as integration domain.
Definition domains.hh:233
Definition baseclass.hh:22
Local assembler corresponding to a bulk bilinear form.
Definition integratedbilinearform.hh:44
void assembleElementMatrix(const Element &element, LocalMatrix &localMatrix)
Definition integratedbilinearform.hh:95
void assembleElementMatrixPattern(const Element &element, LocalPattern &localPattern)
Definition integratedbilinearform.hh:87
const BilinearOperator & integrandOperator() const
Definition integratedbilinearform.hh:69
void preprocess(const TestLocalView &testLocalView, const AnsatzLocalView &ansatzLocalView)
Register local views.
Definition integratedbilinearform.hh:136
IntegratedBilinearForm(const BilinearOperator &sumOperator)
Definition integratedbilinearform.hh:64
void bindLocalViews(const TestRootLocalView &testLocalView, const AnsatzRootLocalView &ansatzLocalView)
Definition integratedbilinearform.hh:76
void bindElement(const Element &element)
Definition integratedbilinearform.hh:83
IntegratedBilinearForm(const BilinearOperator &sumOperator, const Domain &domain)
Definition integratedbilinearform.hh:58
typename BilinearOperator::Element Element
Definition integratedbilinearform.hh:56
void operator()(const Element &element, LocalMatrix &localMatrix, const TestLocalView &testSubspaceLocalView, const AnsatzLocalView &ansatzSubspaceLocalView)
Definition integratedbilinearform.hh:144
Definition localsumassembler.hh:80
A cache providing multiple versions for different quadrature rules.
Definition shapefunctioncache.hh:467
T forward(T... args)