DUNE PDELab (git)

transformedindexbasis.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_TRANSFORMEDINDEXBASIS_HH
8#define DUNE_FUNCTIONS_FUNCTIONSPACEBASES_TRANSFORMEDINDEXBASIS_HH
9
10#include <tuple>
11#include <utility>
12
13#include <dune/common/hybridutilities.hh>
16#include <dune/common/hybridutilities.hh>
17
18#include <dune/typetree/compositenode.hh>
19#include <dune/typetree/utility.hh>
20
21#include <dune/functions/common/staticforloop.hh>
22#include <dune/functions/common/type_traits.hh>
23#include <dune/functions/common/utility.hh>
24#include <dune/functions/functionspacebases/basistags.hh>
25#include <dune/functions/functionspacebases/nodes.hh>
26#include <dune/functions/functionspacebases/concepts.hh>
27#include <dune/functions/functionspacebases/defaultglobalbasis.hh>
28
29
30namespace Dune {
31namespace Functions {
32namespace Experimental {
33
34// *****************************************************************************
35// *****************************************************************************
36
53template<class RPB, class T>
55{
56 using Transformation = T;
57
59
60public:
61
62 using RawPreBasis = RPB;
63
65 using GridView = typename RawPreBasis::GridView;
66
68 using size_type = std::size_t;
69
71 using Node = typename RawPreBasis::Node;
72
73 static constexpr size_type maxMultiIndexSize = Transformation::maxIndexSize;
74 static constexpr size_type minMultiIndexSize = Transformation::minIndexSize;
75 static constexpr size_type multiIndexBufferSize = std::max(RawPreBasis::multiIndexBufferSize, maxMultiIndexSize);
76
82 template<class RPB_R, class T_R>
83 TransformedIndexPreBasis(RPB_R&& rawPreBasis, T_R&& transformation) :
84 rawPreBasis_(std::forward<RPB_R>(rawPreBasis)),
85 transformation_(std::forward<T_R>(transformation))
86 {}
87
90 {
91 rawPreBasis_.initializeIndices();
92 }
93
95 const GridView& gridView() const
96 {
97 return rawPreBasis_.gridView();
98 }
99
101 void update(const GridView& gv)
102 {
103 rawPreBasis_.update(gv);
104 }
105
117 {
118 return rawPreBasis_.makeNode();
119 }
120
123 {
125 }
126
128 template<class SizePrefix>
129 size_type size(const SizePrefix& prefix) const
130 {
131 return transformation_.size(prefix, rawPreBasis_);
132 }
133
136 {
137 return transformation_.containerDescriptor(rawPreBasis_);
138 }
139
142 {
143 return transformation_.dimension(rawPreBasis_);
144 }
145
148 {
149 return rawPreBasis_.maxNodeSize();
150 }
151
152 const RawPreBasis& rawPreBasis() const
153 {
154 return rawPreBasis_;
155 }
156
157 RawPreBasis& rawPreBasis()
158 {
159 return rawPreBasis_;
160 }
161
162 template<class MultiIndex>
163 void transformIndex(MultiIndex& multiIndex) const
164 {
165 transformation_.transformIndex(multiIndex, rawPreBasis_);
166 }
167
168 template<typename It>
169 It indices(const Node& node, It it) const
170 {
171 rawPreBasis().indices(node, it);
172 for(std::size_t i=0; i<node.size(); ++i)
173 {
174 transformIndex(*it);
175 ++it;
176 }
177 return it;
178 }
179
180protected:
181 RawPreBasis rawPreBasis_;
182 Transformation transformation_;
183};
184
185template<class RPB, class T>
186TransformedIndexPreBasis(RPB&&, T&&) -> TransformedIndexPreBasis<std::decay_t<RPB>, std::decay_t<T>>;
187
188
189} // end namespace Experimental
190
191
192namespace BasisFactory {
193namespace Experimental {
194
206template<class RawPreBasisFactory, class Transformation>
207auto transformIndices(
208 RawPreBasisFactory&& preBasisFactory,
209 Transformation&& transformation)
210{
211 return [
212 preBasisFactory=std::forward<RawPreBasisFactory>(preBasisFactory),
213 transformation =std::forward<Transformation>(transformation)
214 ](const auto& gridView) {
215 return Dune::Functions::Experimental::TransformedIndexPreBasis(preBasisFactory(gridView), std::move(transformation));
216 };
217}
218
219
220
239template<class IndexTransformation, class SizeImplementation, class ContainerDescriptorImplementation, std::size_t minIS, std::size_t maxIS>
241{
242public:
243
244 static constexpr std::size_t minIndexSize = minIS;
245 static constexpr std::size_t maxIndexSize = maxIS;
246
247 template<class IT_R, class SI_R, class CD_R>
248 GenericIndexingTransformation(IT_R&& indexTransformation, SI_R&& sizeImplementation, CD_R&& containerDescriptorImplementation) :
249 indexTransformation_(std::forward<IT_R>(indexTransformation)),
250 sizeImplementation_(std::forward<SI_R>(sizeImplementation)),
251 containerDescriptorImplementation_(std::forward<CD_R>(containerDescriptorImplementation))
252 {}
253
254 template<class MultiIndex, class PreBasis>
255 void transformIndex(MultiIndex& multiIndex, const PreBasis& preBasis) const
256 {
257 indexTransformation_(multiIndex, preBasis);
258 }
259
260 template<class Prefix, class PreBasis>
261 auto size(const Prefix& prefix, const PreBasis& preBasis) const
262 {
263 return sizeImplementation_(prefix, preBasis);
264 }
265
266 template<class PreBasis>
267 auto dimension(const PreBasis& preBasis) const
268 {
269 return preBasis.dimension();
270 }
271
272 template<class PreBasis>
273 auto containerDescriptor(const PreBasis& preBasis) const
274 {
275 return containerDescriptorImplementation_(preBasis);
276 }
277
278private:
279 IndexTransformation indexTransformation_;
280 SizeImplementation sizeImplementation_;
281 ContainerDescriptorImplementation containerDescriptorImplementation_;
282};
283
284
285
305template<class IndexTransformation, class SizeImplementation, class ContainerDescriptorImplementation, std::size_t minIndexSize, std::size_t maxIndexSize>
306auto indexTransformation(IndexTransformation&& indexTransformation,
307 SizeImplementation&& sizeImplementation,
308 ContainerDescriptorImplementation&& containerDescriptorImplementation,
311{
313 std::decay_t<IndexTransformation>,
314 std::decay_t<SizeImplementation>,
315 std::decay_t<ContainerDescriptorImplementation>,
316 minIndexSize, maxIndexSize>(
317 std::forward<IndexTransformation>(indexTransformation),
318 std::forward<SizeImplementation>(sizeImplementation),
319 std::forward<ContainerDescriptorImplementation>(containerDescriptorImplementation));
320}
321
323template<class IndexTransformation, class SizeImplementation,
324 std::size_t minIndexSize, std::size_t maxIndexSize>
325auto indexTransformation(IndexTransformation&& indexTrafo,
326 SizeImplementation&& sizeImpl,
329{
330 return indexTransformation(indexTrafo, sizeImpl,
331 [](auto&&) { return Dune::Functions::ContainerDescriptors::Unknown{}; },
332 minSize, maxSize);
333}
334
335} // end namespace Experimental
336} // end namespace BasisFactory
337} // end namespace Functions
338} // end namespace Dune
339
340
341#endif // DUNE_FUNCTIONS_FUNCTIONSPACEBASES_TRANSFORMEDINDEXBASIS_HH
A generic implementation of a transformation.
Definition: transformedindexbasis.hh:241
A pre-basis transforming multi-indices.
Definition: transformedindexbasis.hh:55
void initializeIndices()
Initialize the global indices.
Definition: transformedindexbasis.hh:89
typename RawPreBasis::GridView GridView
The grid view that the FE basis is defined on.
Definition: transformedindexbasis.hh:65
typename RawPreBasis::Node Node
Template mapping root tree path to type of created tree node.
Definition: transformedindexbasis.hh:71
TransformedIndexPreBasis(RPB_R &&rawPreBasis, T_R &&transformation)
Constructor for given child pre-basis objects.
Definition: transformedindexbasis.hh:83
void update(const GridView &gv)
Update the stored grid view, to be called if the grid has changed.
Definition: transformedindexbasis.hh:101
Node makeNode() const
Create tree node with given root tree path.
Definition: transformedindexbasis.hh:116
const GridView & gridView() const
Obtain the grid view that the basis is defined on.
Definition: transformedindexbasis.hh:95
size_type size(const SizePrefix &prefix) const
Return number of possible values for next position in multi index.
Definition: transformedindexbasis.hh:129
size_type size() const
Same as size(prefix) with empty prefix.
Definition: transformedindexbasis.hh:122
size_type maxNodeSize() const
Get the maximal number of DOFs associated to node for any element.
Definition: transformedindexbasis.hh:147
std::size_t size_type
Type used for indices and size information.
Definition: transformedindexbasis.hh:68
size_type dimension() const
Get the total dimension of the space spanned by this basis.
Definition: transformedindexbasis.hh:141
auto containerDescriptor() const
Return the container descriptor of the transformed pre-basis.
Definition: transformedindexbasis.hh:135
A Vector class with statically reserved memory.
Definition: reservedvector.hh:47
std::integral_constant< std::size_t, i > index_constant
An index constant with value i.
Definition: indices.hh:29
constexpr auto max
Function object that returns the greater of the given values.
Definition: hybridutilities.hh:484
Dune namespace.
Definition: alignedallocator.hh:13
STL namespace.
An stl-compliant random-access container which stores everything on the stack.
Fallback container descriptor if nothing else fits.
Definition: containerdescriptors.hh:50
Utilities for type computations, constraining overloads, ...
Creative Commons License   |  Legal Statements / Impressum  |  Hosted by TU Dresden  |  generated with Hugo v0.111.3 (Nov 12, 23:30, 2024)