Dune Core Modules (2.8.0)

defaultlocalview.hh
1// -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
2// vi: set et ts=4 sw=2 sts=2:
3#ifndef DUNE_FUNCTIONS_FUNCTIONSPACEBASES_DEFAULTLOCALVIEW_HH
4#define DUNE_FUNCTIONS_FUNCTIONSPACEBASES_DEFAULTLOCALVIEW_HH
5
6
7#include <tuple>
8#include <optional>
9
11#include <dune/common/hybridutilities.hh>
12
13#include <dune/functions/functionspacebases/concepts.hh>
14
15
16
17namespace Dune {
18namespace Functions {
19
20namespace Impl {
21
22// Concept for a PreBasis implementing the indices() method.
23//
24// This concept is deprecated.
25template<typename PreBasis>
26using PreBasisHasIndicesConcept = decltype(std::declval<PreBasis>().indices(std::declval<typename PreBasis::Node>(), std::declval<std::vector<typename PreBasis::MultiIndex>>().begin()), true);
27
28// Concept checking if a PreBasis implements the indices() method.
29//
30// This check is deprecated.
31template<typename PreBasis>
32using preBasisHasIndices = Std::is_detected<PreBasisHasIndicesConcept, PreBasis>;
33
34// Backward compatible version of preBasis.indices(node, it)
35// If the preBasis implements the method it's called directly.
36// Otherwise this is forwarded to the old dprecated interface
37// by creating a temporary NodeIndexSet. This may be expensive
38// if the NodeIndexSet's member variables or bind() method are
39// non-trivial.
40//
41// Once the old interface is gone and the new one is mandatory,
42// this can be replaced by preBasis.indices(node, it).
43template<typename PreBasis, typename Node, typename It>
44It preBasisIndices(const PreBasis& preBasis, const Node& node, It multiIndices)
45{
46 if constexpr (preBasisHasIndices<PreBasis>{})
47 return preBasis.indices(node, multiIndices);
48 else
49 {
50 auto indexSet = preBasis().makeIndexSet();
51 indexSet.bind(node);
52 return indexSet.indices(multiIndices);
53 }
54}
55
56// This class exists for backward compatibility only.
57// A PreBasis providing indices(node,iterator) can
58// simpe export a DefaultNodeIndexSet<PreBasis>
59// which will forward the old-style interface to the
60// new one.
61//
62// This class is deprecated.
63template<class PB>
64class DefaultNodeIndexSet
65{
66public:
67
68 using size_type = std::size_t;
69 using PreBasis = PB;
70 using MultiIndex = typename PreBasis::MultiIndex;
71 using Node = typename PreBasis::Node;
72
73 DefaultNodeIndexSet(const PreBasis& preBasis) :
74 preBasis_(&preBasis),
75 node_(nullptr)
76 {}
77
78 void bind(const Node& node) {
79 node_ = &node;
80 }
81
82 void unbind() {
83 node_ = nullptr;
84 }
85
86 size_type size() const {
87 assert(node_ != nullptr);
88 return node_->size();
89 }
90
91 template<typename It>
92 It indices(It it) const {
93 assert(node_ != nullptr);
94 return preBasis_->indices(*node_, it);
95 }
96
97protected:
98 const PreBasis* preBasis_;
99 const Node* node_;
100};
101
102}
103
104
105
107template<class GB>
109{
110public:
111
113 using GlobalBasis = GB;
114
116 using GridView = typename GlobalBasis::GridView;
117
119 using Element = typename GridView::template Codim<0>::Entity;
120
122 using size_type = std::size_t;
123
125 using Tree = typename GlobalBasis::PreBasis::Node;
126
128 using MultiIndex = typename GlobalBasis::PreBasis::MultiIndex;
129
130private:
131
132 // The following helpers should be removed after 2.8
133 template<typename NodeIndexSet_>
134 using hasIndices = decltype(std::declval<NodeIndexSet_>().indices(std::declval<std::vector<typename NodeIndexSet_::MultiIndex>>().begin()));
135
136 // A dummy NodeIndexSet to be used if the PreBasis provides
137 // the new indices() method.
138 struct DummyNodeIndexSet {};
139
140 static auto makeIndexSet(const typename GlobalBasis::PreBasis& preBasis)
141 {
142 if constexpr (Impl::preBasisHasIndices<typename GlobalBasis::PreBasis>{})
143 return DummyNodeIndexSet{};
144 else
145 return preBasis.makeIndexSet();
146 }
147
148 using NodeIndexSet = std::decay_t<decltype(makeIndexSet(std::declval<typename GlobalBasis::PreBasis>()))>;
149
150public:
151
154 globalBasis_(&globalBasis),
155 tree_(globalBasis_->preBasis().makeNode()),
156 nodeIndexSet_(makeIndexSet(globalBasis_->preBasis()))
157 {
158 static_assert(models<Concept::BasisTree<GridView>, Tree>(), "Tree type passed to DefaultLocalView does not model the BasisNode concept.");
159 initializeTree(tree_);
160 }
161
167 void bind(const Element& e)
168 {
169 element_ = e;
170 bindTree(tree_, *element_);
171 indices_.resize(size());
172 if constexpr (Impl::preBasisHasIndices<typename GlobalBasis::PreBasis>{})
173 globalBasis_->preBasis().indices(tree_, indices_.begin());
174 else
175 {
176 nodeIndexSet_.bind(tree_);
178 nodeIndexSet_.indices(indices_.begin());
179 else
180 for (size_type i = 0 ; i < this->size() ; ++i)
181 indices_[i] = nodeIndexSet_.index(i);
182 }
183 }
184
187 bool isBound() const {
188 return static_cast<bool>(element_);
189 }
190
195 const Element& element() const
196 {
197 return *element_;
198 }
199
204 void unbind()
205 {
206 if constexpr (not Impl::preBasisHasIndices<typename GlobalBasis::PreBasis>{})
207 nodeIndexSet_.unbind();
208 element_.reset();
209 }
210
215 const Tree& tree() const
216 {
217 return tree_;
218 }
219
223 {
224 return tree_.size();
225 }
226
234 {
235 return globalBasis_->preBasis().maxNodeSize();
236 }
237
240 {
241 return indices_[i];
242 }
243
247 {
248 return *globalBasis_;
249 }
250
251 const DefaultLocalView& rootLocalView() const
252 {
253 return *this;
254 }
255
256protected:
257 const GlobalBasis* globalBasis_;
258 std::optional<Element> element_;
259 Tree tree_;
260 NodeIndexSet nodeIndexSet_;
261 std::vector<MultiIndex> indices_;
262};
263
264
265
266} // end namespace Functions
267} // end namespace Dune
268
269
270
271#endif // DUNE_FUNCTIONS_FUNCTIONSPACEBASES_DEFAULTLOCALVIEW_HH
The restriction of a finite element basis to a single element.
Definition: defaultlocalview.hh:109
void unbind()
Unbind from the current element.
Definition: defaultlocalview.hh:204
typename GlobalBasis::GridView GridView
The grid view the global FE basis lives on.
Definition: defaultlocalview.hh:116
typename GridView::template Codim< 0 >::Entity Element
Type of the grid element we are bound to.
Definition: defaultlocalview.hh:119
const Tree & tree() const
Return the local ansatz tree associated to the bound entity.
Definition: defaultlocalview.hh:215
void bind(const Element &e)
Bind the view to a grid element.
Definition: defaultlocalview.hh:167
const Element & element() const
Return the grid element that the view is bound to.
Definition: defaultlocalview.hh:195
MultiIndex index(size_type i) const
Maps from subtree index set [0..size-1] to a globally unique multi index in global basis.
Definition: defaultlocalview.hh:239
size_type size() const
Total number of degrees of freedom on this element.
Definition: defaultlocalview.hh:222
GB GlobalBasis
The global FE basis that this is a view on.
Definition: defaultlocalview.hh:113
size_type maxSize() const
Maximum local size for any element on the GridView.
Definition: defaultlocalview.hh:233
std::size_t size_type
The type used for sizes.
Definition: defaultlocalview.hh:122
bool isBound() const
Return if the view is bound to a grid element.
Definition: defaultlocalview.hh:187
typename GlobalBasis::PreBasis::MultiIndex MultiIndex
Type used for global numbering of the basis vectors.
Definition: defaultlocalview.hh:128
typename GlobalBasis::PreBasis::Node Tree
Tree of local finite elements / local shape function sets.
Definition: defaultlocalview.hh:125
DefaultLocalView(const GlobalBasis &globalBasis)
Construct local view for a given global finite element basis.
Definition: defaultlocalview.hh:153
const GlobalBasis & globalBasis() const
Return the global basis that we are a view on.
Definition: defaultlocalview.hh:246
Infrastructure for concepts.
typename detected_or< nonesuch, Op, Args... >::value_t is_detected
Detects whether Op<Args...> is valid.
Definition: type_traits.hh:326
Dune namespace.
Definition: alignedallocator.hh:11
Static tag representing a codimension.
Definition: dimension.hh:22
Creative Commons License   |  Legal Statements / Impressum  |  Hosted by TU Dresden  |  generated with Hugo v0.111.3 (Nov 22, 23:33, 2024)