Loading [MathJax]/extensions/tex2jax.js

DUNE PDELab (unstable)

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/functions/common/staticforloop.hh>
19#include <dune/functions/common/type_traits.hh>
20#include <dune/functions/common/utility.hh>
21#include <dune/functions/functionspacebases/basistags.hh>
22#include <dune/functions/functionspacebases/nodes.hh>
23#include <dune/functions/functionspacebases/concepts.hh>
24#include <dune/functions/functionspacebases/defaultglobalbasis.hh>
25
26
27namespace Dune {
28namespace Functions {
29namespace Experimental {
30
31// *****************************************************************************
32// *****************************************************************************
33
50template<class RPB, class T>
52{
53 using Transformation = T;
54
56
57public:
58
59 using RawPreBasis = RPB;
60
62 using GridView = typename RawPreBasis::GridView;
63
65 using size_type = std::size_t;
66
68 using Node = typename RawPreBasis::Node;
69
70 static constexpr size_type maxMultiIndexSize = Transformation::maxIndexSize;
71 static constexpr size_type minMultiIndexSize = Transformation::minIndexSize;
72 static constexpr size_type multiIndexBufferSize = std::max(RawPreBasis::multiIndexBufferSize, maxMultiIndexSize);
73
79 template<class RPB_R, class T_R>
80 TransformedIndexPreBasis(RPB_R&& rawPreBasis, T_R&& transformation) :
81 rawPreBasis_(std::forward<RPB_R>(rawPreBasis)),
82 transformation_(std::forward<T_R>(transformation))
83 {}
84
87 {
88 rawPreBasis_.initializeIndices();
89 }
90
92 const GridView& gridView() const
93 {
94 return rawPreBasis_.gridView();
95 }
96
98 void update(const GridView& gv)
99 {
100 rawPreBasis_.update(gv);
101 }
102
114 {
115 return rawPreBasis_.makeNode();
116 }
117
120 {
122 }
123
125 template<class SizePrefix>
126 size_type size(const SizePrefix& prefix) const
127 {
128 return transformation_.size(prefix, rawPreBasis_);
129 }
130
133 {
134 return transformation_.containerDescriptor(rawPreBasis_);
135 }
136
139 {
140 return transformation_.dimension(rawPreBasis_);
141 }
142
145 {
146 return rawPreBasis_.maxNodeSize();
147 }
148
149 const RawPreBasis& rawPreBasis() const
150 {
151 return rawPreBasis_;
152 }
153
154 RawPreBasis& rawPreBasis()
155 {
156 return rawPreBasis_;
157 }
158
159 template<class MultiIndex>
160 void transformIndex(MultiIndex& multiIndex) const
161 {
162 transformation_.transformIndex(multiIndex, rawPreBasis_);
163 }
164
165 template<typename It>
166 It indices(const Node& node, It it) const
167 {
168 rawPreBasis().indices(node, it);
169 for(std::size_t i=0; i<node.size(); ++i)
170 {
171 transformIndex(*it);
172 ++it;
173 }
174 return it;
175 }
176
177protected:
178 RawPreBasis rawPreBasis_;
179 Transformation transformation_;
180};
181
182template<class RPB, class T>
183TransformedIndexPreBasis(RPB&&, T&&) -> TransformedIndexPreBasis<std::decay_t<RPB>, std::decay_t<T>>;
184
185
186} // end namespace Experimental
187
188
189namespace BasisFactory {
190namespace Experimental {
191
203template<class RawPreBasisFactory, class Transformation>
204auto transformIndices(
205 RawPreBasisFactory&& preBasisFactory,
206 Transformation&& transformation)
207{
208 return [
209 preBasisFactory=std::forward<RawPreBasisFactory>(preBasisFactory),
210 transformation =std::forward<Transformation>(transformation)
211 ](const auto& gridView) {
212 return Dune::Functions::Experimental::TransformedIndexPreBasis(preBasisFactory(gridView), std::move(transformation));
213 };
214}
215
216
217
236template<class IndexTransformation, class SizeImplementation, class ContainerDescriptorImplementation, std::size_t minIS, std::size_t maxIS>
238{
239public:
240
241 static constexpr std::size_t minIndexSize = minIS;
242 static constexpr std::size_t maxIndexSize = maxIS;
243
244 template<class IT_R, class SI_R, class CD_R>
245 GenericIndexingTransformation(IT_R&& indexTransformation, SI_R&& sizeImplementation, CD_R&& containerDescriptorImplementation) :
246 indexTransformation_(std::forward<IT_R>(indexTransformation)),
247 sizeImplementation_(std::forward<SI_R>(sizeImplementation)),
248 containerDescriptorImplementation_(std::forward<CD_R>(containerDescriptorImplementation))
249 {}
250
251 template<class MultiIndex, class PreBasis>
252 void transformIndex(MultiIndex& multiIndex, const PreBasis& preBasis) const
253 {
254 indexTransformation_(multiIndex, preBasis);
255 }
256
257 template<class Prefix, class PreBasis>
258 auto size(const Prefix& prefix, const PreBasis& preBasis) const
259 {
260 return sizeImplementation_(prefix, preBasis);
261 }
262
263 template<class PreBasis>
264 auto dimension(const PreBasis& preBasis) const
265 {
266 return preBasis.dimension();
267 }
268
269 template<class PreBasis>
270 auto containerDescriptor(const PreBasis& preBasis) const
271 {
272 return containerDescriptorImplementation_(preBasis);
273 }
274
275private:
276 IndexTransformation indexTransformation_;
277 SizeImplementation sizeImplementation_;
278 ContainerDescriptorImplementation containerDescriptorImplementation_;
279};
280
281
282
302template<class IndexTransformation, class SizeImplementation, class ContainerDescriptorImplementation, std::size_t minIndexSize, std::size_t maxIndexSize>
303auto indexTransformation(IndexTransformation&& indexTransformation,
304 SizeImplementation&& sizeImplementation,
305 ContainerDescriptorImplementation&& containerDescriptorImplementation,
308{
310 std::decay_t<IndexTransformation>,
311 std::decay_t<SizeImplementation>,
312 std::decay_t<ContainerDescriptorImplementation>,
313 minIndexSize, maxIndexSize>(
314 std::forward<IndexTransformation>(indexTransformation),
315 std::forward<SizeImplementation>(sizeImplementation),
316 std::forward<ContainerDescriptorImplementation>(containerDescriptorImplementation));
317}
318
320template<class IndexTransformation, class SizeImplementation,
321 std::size_t minIndexSize, std::size_t maxIndexSize>
322auto indexTransformation(IndexTransformation&& indexTrafo,
323 SizeImplementation&& sizeImpl,
326{
327 return indexTransformation(indexTrafo, sizeImpl,
328 [](auto&&) { return Dune::Functions::ContainerDescriptors::Unknown{}; },
329 minSize, maxSize);
330}
331
332} // end namespace Experimental
333} // end namespace BasisFactory
334} // end namespace Functions
335} // end namespace Dune
336
337
338#endif // DUNE_FUNCTIONS_FUNCTIONSPACEBASES_TRANSFORMEDINDEXBASIS_HH
A generic implementation of a transformation.
Definition: transformedindexbasis.hh:238
A pre-basis transforming multi-indices.
Definition: transformedindexbasis.hh:52
void initializeIndices()
Initialize the global indices.
Definition: transformedindexbasis.hh:86
typename RawPreBasis::GridView GridView
The grid view that the FE basis is defined on.
Definition: transformedindexbasis.hh:62
typename RawPreBasis::Node Node
Template mapping root tree path to type of created tree node.
Definition: transformedindexbasis.hh:68
TransformedIndexPreBasis(RPB_R &&rawPreBasis, T_R &&transformation)
Constructor for given child pre-basis objects.
Definition: transformedindexbasis.hh:80
void update(const GridView &gv)
Update the stored grid view, to be called if the grid has changed.
Definition: transformedindexbasis.hh:98
Node makeNode() const
Create tree node with given root tree path.
Definition: transformedindexbasis.hh:113
const GridView & gridView() const
Obtain the grid view that the basis is defined on.
Definition: transformedindexbasis.hh:92
size_type size(const SizePrefix &prefix) const
Return number of possible values for next position in multi index.
Definition: transformedindexbasis.hh:126
size_type size() const
Same as size(prefix) with empty prefix.
Definition: transformedindexbasis.hh:119
size_type maxNodeSize() const
Get the maximal number of DOFs associated to node for any element.
Definition: transformedindexbasis.hh:144
std::size_t size_type
Type used for indices and size information.
Definition: transformedindexbasis.hh:65
size_type dimension() const
Get the total dimension of the space spanned by this basis.
Definition: transformedindexbasis.hh:138
auto containerDescriptor() const
Return the container descriptor of the transformed pre-basis.
Definition: transformedindexbasis.hh:132
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:485
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:52
Utilities for type computations, constraining overloads, ...
Creative Commons License   |  Legal Statements / Impressum  |  Hosted by TU Dresden & Uni Heidelberg  |  generated with Hugo v0.111.3 (Apr 10, 22:40, 2025)