DUNE-FUNCTIONS (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>
14#include <dune/common/reservedvector.hh>
15#include <dune/common/typeutilities.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
107 {
108 return rawPreBasis_.makeNode();
109 }
110
113 {
114 return size(Dune::ReservedVector<size_type, multiIndexBufferSize>{});
115 }
116
118 template<class SizePrefix>
119 size_type size(const SizePrefix& prefix) const
120 {
121 return transformation_.size(prefix, rawPreBasis_);
122 }
123
126 {
127 return transformation_.containerDescriptor(rawPreBasis_);
128 }
129
132 {
133 return transformation_.dimension(rawPreBasis_);
134 }
135
138 {
139 return rawPreBasis_.maxNodeSize();
140 }
141
142 const RawPreBasis& rawPreBasis() const
143 {
144 return rawPreBasis_;
145 }
146
147 RawPreBasis& rawPreBasis()
148 {
149 return rawPreBasis_;
150 }
151
152 template<class MultiIndex>
153 void transformIndex(MultiIndex& multiIndex) const
154 {
155 transformation_.transformIndex(multiIndex, rawPreBasis_);
156 }
157
158 template<typename It>
159 It indices(const Node& node, It it) const
160 {
161 rawPreBasis().indices(node, it);
162 for(std::size_t i=0; i<node.size(); ++i)
163 {
164 transformIndex(*it);
165 ++it;
166 }
167 return it;
168 }
169
170protected:
171 RawPreBasis rawPreBasis_;
172 Transformation transformation_;
173};
174
175template<class RPB, class T>
176TransformedIndexPreBasis(RPB&&, T&&) -> TransformedIndexPreBasis<std::decay_t<RPB>, std::decay_t<T>>;
177
178
179} // end namespace Experimental
180
181
182namespace BasisFactory {
183namespace Experimental {
184
196template<class RawPreBasisFactory, class Transformation>
197auto transformIndices(
198 RawPreBasisFactory&& preBasisFactory,
199 Transformation&& transformation)
200{
201 return [
202 preBasisFactory=std::forward<RawPreBasisFactory>(preBasisFactory),
203 transformation =std::forward<Transformation>(transformation)
204 ](const auto& gridView) {
205 return Dune::Functions::Experimental::TransformedIndexPreBasis(preBasisFactory(gridView), std::move(transformation));
206 };
207}
208
209
210
229template<class IndexTransformation, class SizeImplementation, class ContainerDescriptorImplementation, std::size_t minIS, std::size_t maxIS>
231{
232public:
233
234 static constexpr std::size_t minIndexSize = minIS;
235 static constexpr std::size_t maxIndexSize = maxIS;
236
237 template<class IT_R, class SI_R, class CD_R>
238 GenericIndexingTransformation(IT_R&& indexTransformation, SI_R&& sizeImplementation, CD_R&& containerDescriptorImplementation) :
239 indexTransformation_(std::forward<IT_R>(indexTransformation)),
240 sizeImplementation_(std::forward<SI_R>(sizeImplementation)),
241 containerDescriptorImplementation_(std::forward<CD_R>(containerDescriptorImplementation))
242 {}
243
244 template<class MultiIndex, class PreBasis>
245 void transformIndex(MultiIndex& multiIndex, const PreBasis& preBasis) const
246 {
247 indexTransformation_(multiIndex, preBasis);
248 }
249
250 template<class Prefix, class PreBasis>
251 auto size(const Prefix& prefix, const PreBasis& preBasis) const
252 {
253 return sizeImplementation_(prefix, preBasis);
254 }
255
256 template<class PreBasis>
257 auto dimension(const PreBasis& preBasis) const
258 {
259 return preBasis.dimension();
260 }
261
262 template<class PreBasis>
263 auto containerDescriptor(const PreBasis& preBasis) const
264 {
265 return containerDescriptorImplementation_(preBasis);
266 }
267
268private:
269 IndexTransformation indexTransformation_;
270 SizeImplementation sizeImplementation_;
271 ContainerDescriptorImplementation containerDescriptorImplementation_;
272};
273
274
275
295template<class IndexTransformation, class SizeImplementation, class ContainerDescriptorImplementation, std::size_t minIndexSize, std::size_t maxIndexSize>
296auto indexTransformation(IndexTransformation&& indexTransformation,
297 SizeImplementation&& sizeImplementation,
298 ContainerDescriptorImplementation&& containerDescriptorImplementation,
299 Dune::index_constant<minIndexSize>,
300 Dune::index_constant<maxIndexSize>)
301{
303 std::decay_t<IndexTransformation>,
304 std::decay_t<SizeImplementation>,
305 std::decay_t<ContainerDescriptorImplementation>,
306 minIndexSize, maxIndexSize>(
307 std::forward<IndexTransformation>(indexTransformation),
308 std::forward<SizeImplementation>(sizeImplementation),
309 std::forward<ContainerDescriptorImplementation>(containerDescriptorImplementation));
310}
311
313template<class IndexTransformation, class SizeImplementation,
314 std::size_t minIndexSize, std::size_t maxIndexSize>
315auto indexTransformation(IndexTransformation&& indexTrafo,
316 SizeImplementation&& sizeImpl,
317 Dune::index_constant<minIndexSize> minSize,
318 Dune::index_constant<maxIndexSize> maxSize)
319{
320 return indexTransformation(indexTrafo, sizeImpl,
321 [](auto&&) { return Dune::Functions::ContainerDescriptors::Unknown{}; },
322 minSize, maxSize);
323}
324
325} // end namespace Experimental
326} // end namespace BasisFactory
327} // end namespace Functions
328} // end namespace Dune
329
330
331#endif // DUNE_FUNCTIONS_FUNCTIONSPACEBASES_TRANSFORMEDINDEXBASIS_HH
A generic implementation of a transformation.
Definition: transformedindexbasis.hh:231
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.
Definition: transformedindexbasis.hh:106
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:119
size_type size() const
Same as size(prefix) with empty prefix.
Definition: transformedindexbasis.hh:112
size_type maxNodeSize() const
Get the maximal number of DOFs associated to node for any element.
Definition: transformedindexbasis.hh:137
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:131
auto containerDescriptor() const
Return the container descriptor of the transformed pre-basis.
Definition: transformedindexbasis.hh:125
Definition: monomialset.hh:19
Fallback container descriptor if nothing else fits.
Definition: containerdescriptors.hh:52
Creative Commons License   |  Legal Statements / Impressum  |  Hosted by TU Dresden & Uni Heidelberg  |  generated with Hugo v0.111.3 (Jan 9, 23:34, 2026)