DUNE PDELab (unstable)

restrictedbasis.hh
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 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_FUNCTIONS_FUNCTIONSPACEBASES_RESTRICTEDBASIS_HH
8#define DUNE_FUNCTIONS_FUNCTIONSPACEBASES_RESTRICTEDBASIS_HH
9
10#include <cstddef>
11#include <utility>
12
13#include <dune/typetree/traversal.hh>
14
15#include <dune/functions/functionspacebases/nodes.hh>
16
17
18namespace Dune::Functions::Experimental {
19
20
21
42template<class GV, class SDPB, class SD>
44{
46
47public:
48
49 using SubDomain = SD;
50 using SubDomainPreBasis = SDPB;
51 using SubDomainGridView = typename SubDomainPreBasis::GridView;
52
54 using GridView = GV;
55
57 using size_type = std::size_t;
58
60 class Node
61 : public SubDomainPreBasis::Node
62 {
63 using Base = typename SubDomainPreBasis::Node;
64 public:
65
66 using Element = typename Base::Element;
67
68 Node(Base&& base, const SubDomainGridView& subDomainGridView, const SubDomain& subDomain)
69 : Base(base)
70 , subDomainGridView_(subDomainGridView)
71 , subDomain_(subDomain)
72 {}
73
74 void bind(const Element& element)
75 {
76 if (subDomainGridView_.contains(element))
77 Base::bind(element);
78 else
79 {
80 Dune::TypeTree::forEachNode(static_cast<Base&>(*this) , [&](auto& node, const auto& treePath) {
81 Dune::Functions::Impl::BasisNodeSetupHelper::setOffset(node, this->offset());
82 Dune::Functions::Impl::BasisNodeSetupHelper::setSize(node, 0);
83 });
84 }
85 }
86
87 const SubDomain& subDomain() const
88 {
89 return subDomain_;
90 }
91
92 private:
93 const SubDomainGridView& subDomainGridView_;
94 const SubDomain& subDomain_;
95 };
96
97 static constexpr size_type maxMultiIndexSize = SubDomainPreBasis::maxMultiIndexSize;
98 static constexpr size_type minMultiIndexSize = SubDomainPreBasis::minMultiIndexSize;
99 static constexpr size_type multiIndexBufferSize = SubDomainPreBasis::multiIndexBufferSize;
100
107 RestrictedPreBasis(const GridView& gridView, SubDomainPreBasis&& subDomainPreBasis, const SubDomain& subDomain)
108 : gridView_(gridView)
109 , subDomainPreBasis_(std::move(subDomainPreBasis))
110 , subDomainPtr_(&subDomain)
111 {}
112
115 {
116 subDomainPreBasis_.initializeIndices();
117 }
118
120 const GridView& gridView() const
121 {
122 return gridView_;
123 }
124
133 void update(const GridView& gv)
134 {
135 gridView_ = gv;
136 subDomainPreBasis_.update(subDomainPtr_->gridView());
137 }
138
150 {
151 return Node(subDomainPreBasis_.makeNode(), subDomainPreBasis_.gridView(), *subDomainPtr_);
152 }
153
156 {
157 return subDomainPreBasis_.size();
158 }
159
161 template<class SizePrefix>
162 size_type size(const SizePrefix& prefix) const
163 {
164 return subDomainPreBasis_.size(prefix);
165 }
166
169 {
170 return subDomainPreBasis_.containerDescriptor();
171 }
172
175 {
176 return subDomainPreBasis_.dimension();
177 }
178
181 {
182 return subDomainPreBasis_.maxNodeSize();
183 }
184
185 const SubDomainPreBasis& subDomainPreBasis() const
186 {
187 return subDomainPreBasis_;
188 }
189
190 SubDomainPreBasis& subDomainPreBasis()
191 {
192 return subDomainPreBasis_;
193 }
194
195 template<typename It>
196 It indices(const Node& node, It it) const
197 {
198 if (node.size() == 0)
199 return it;
200 else
201 return subDomainPreBasis_.indices(node, it);
202 }
203
204protected:
205 GridView gridView_;
206 SubDomainPreBasis subDomainPreBasis_;
207 const SubDomain* subDomainPtr_;
208};
209
210
211
212namespace BasisFactory {
213
231template<class SubDomainBasisFactory, class SubDomain>
232auto restrict(SubDomainBasisFactory&& subPreBasisFactory, const SubDomain& subDomain)
233{
234 return [
235 subPreBasisFactory=std::forward<SubDomainBasisFactory>(subPreBasisFactory),
236 &subDomain
237 ](const auto& gridView) {
238 return Dune::Functions::Experimental::RestrictedPreBasis(gridView, subPreBasisFactory(subDomain.gridView()), subDomain);
239 };
240}
241
242
243} // end namespace BasisFactory
244} // end namespace Dune::Functions::Experimental
245
246
247#endif // DUNE_FUNCTIONS_FUNCTIONSPACEBASES_RESTRICTEDBASIS_HH
Template mapping root tree path to type of created tree node.
Definition: restrictedbasis.hh:62
A pre-basis restricted to a sub-domain.
Definition: restrictedbasis.hh:44
std::size_t size_type
Type used for indices and size information.
Definition: restrictedbasis.hh:57
RestrictedPreBasis(const GridView &gridView, SubDomainPreBasis &&subDomainPreBasis, const SubDomain &subDomain)
Constructor for given sub-domain pre-basis.
Definition: restrictedbasis.hh:107
void initializeIndices()
Initialize the global indices.
Definition: restrictedbasis.hh:114
size_type dimension() const
Get the total dimension of the space spanned by this basis.
Definition: restrictedbasis.hh:174
GV GridView
The grid view that the FE basis is defined on.
Definition: restrictedbasis.hh:54
size_type maxNodeSize() const
Get the maximal number of DOFs associated to node for any element.
Definition: restrictedbasis.hh:180
size_type size() const
Same as size(prefix) with empty prefix.
Definition: restrictedbasis.hh:155
size_type size(const SizePrefix &prefix) const
Return number of possible values for next position in multi index.
Definition: restrictedbasis.hh:162
const GridView & gridView() const
Obtain the grid view that the basis is defined on.
Definition: restrictedbasis.hh:120
auto containerDescriptor() const
Return the container descriptor of the pre-basis.
Definition: restrictedbasis.hh:168
Node makeNode() const
Create tree node with given root tree path.
Definition: restrictedbasis.hh:149
void update(const GridView &gv)
Update the stored grid view, to be called.
Definition: restrictedbasis.hh:133
Class representing a sub-domain of a GridView.
Definition: subdomain.hh:534
GridView gridView() const
Create grid view representing the SubDomain.
Definition: subdomain.hh:565
auto restrict(SubDomainBasisFactory &&subPreBasisFactory, const SubDomain &subDomain)
Create a RestrictedPreBasisFactory.
Definition: restrictedbasis.hh:232
constexpr auto treePath(const T &... t)
Constructs a new HybridTreePath from the given indices.
Definition: treepath.hh:199
void forEachNode(Tree &&tree, PreNodeFunc &&preNodeFunc, LeafNodeFunc &&leafNodeFunc, PostNodeFunc &&postNodeFunc)
Traverse tree and visit each node.
Definition: traversal.hh:259
STL namespace.
Creative Commons License   |  Legal Statements / Impressum  |  Hosted by TU Dresden & Uni Heidelberg  |  generated with Hugo v0.111.3 (Sep 4, 22:38, 2025)