dune-functions 2.9.0
transformedindexbasis.hh
Go to the documentation of this file.
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_TRANSFORMEDINDEXBASIS_HH
4#define DUNE_FUNCTIONS_FUNCTIONSPACEBASES_TRANSFORMEDINDEXBASIS_HH
5
6#include <tuple>
7#include <utility>
8
9#include <dune/common/std/apply.hh>
10#include <dune/common/hybridutilities.hh>
11#include <dune/common/reservedvector.hh>
12#include <dune/common/typeutilities.hh>
13#include <dune/common/hybridutilities.hh>
14
15#include <dune/typetree/compositenode.hh>
16#include <dune/typetree/utility.hh>
17
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 {
121 return size(Dune::ReservedVector<size_type, multiIndexBufferSize>{});
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_.dimension(rawPreBasis_);
135 }
136
139 {
140 return rawPreBasis_.maxNodeSize();
141 }
142
144 {
145 return rawPreBasis_;
146 }
147
149 {
150 return rawPreBasis_;
151 }
152
153 template<class MultiIndex>
154 void transformIndex(MultiIndex& multiIndex) const
155 {
156 transformation_.transformIndex(multiIndex, rawPreBasis_);
157 }
158
159 template<typename It>
160 It indices(const Node& node, It it) const
161 {
162 rawPreBasis().indices(node, it);
163 for(std::size_t i=0; i<node.size(); ++i)
164 {
165 transformIndex(*it);
166 ++it;
167 }
168 return it;
169 }
170
171protected:
173 Transformation transformation_;
174};
175
176template<class RPB, class T>
178
179
180} // end namespace Experimental
181
182
183namespace BasisFactory {
184namespace Experimental {
185
197template<class RawPreBasisFactory, class Transformation>
199 RawPreBasisFactory&& preBasisFactory,
200 Transformation&& transformation)
201{
202 return [
203 preBasisFactory=std::forward<RawPreBasisFactory>(preBasisFactory),
204 transformation =std::forward<Transformation>(transformation)
205 ](const auto& gridView) {
206 return Dune::Functions::Experimental::TransformedIndexPreBasis(preBasisFactory(gridView), std::move(transformation));
207 };
208}
209
210
211
230template<class IndexTransformation, class SizeImplementation, std::size_t minIS, std::size_t maxIS>
232{
233public:
234
235 static constexpr std::size_t minIndexSize = minIS;
236 static constexpr std::size_t maxIndexSize = maxIS;
237
238 template<class IT_R, class SI_R>
239 GenericIndexingTransformation(IT_R&& indexTransformation, SI_R&& sizeImplementation) :
240 indexTransformation_(std::forward<IT_R>(indexTransformation)),
241 sizeImplementation_(std::forward<SI_R>(sizeImplementation))
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
262private:
263 IndexTransformation indexTransformation_;
264 SizeImplementation sizeImplementation_;
265};
266
267
268
287template<class IndexTransformation, class SizeImplementation, std::size_t minIndexSize, std::size_t maxIndexSize>
288auto indexTransformation(IndexTransformation&& indexTransformation, SizeImplementation&& sizeImplementation, Dune::index_constant<minIndexSize>, Dune::index_constant<maxIndexSize>)
289{
291 std::decay_t<IndexTransformation>,
292 std::decay_t<SizeImplementation>,
293 minIndexSize, maxIndexSize>(
294 std::forward<IndexTransformation>(indexTransformation),
295 std::forward<SizeImplementation>(sizeImplementation));
296}
297
298
299} // end namespace Experimental
300} // end namespace BasisFactory
301} // end namespace Functions
302} // end namespace Dune
303
304
305#endif // DUNE_FUNCTIONS_FUNCTIONSPACEBASES_TRANSFORMEDINDEXBASIS_HH
Definition: polynomial.hh:10
auto transformIndices(RawPreBasisFactory &&preBasisFactory, Transformation &&transformation)
Create a TransformedIndexPreBasisFactory.
Definition: transformedindexbasis.hh:198
auto indexTransformation(IndexTransformation &&indexTransformation, SizeImplementation &&sizeImplementation, Dune::index_constant< minIndexSize >, Dune::index_constant< maxIndexSize >)
A generic implementation of a transformation.
Definition: transformedindexbasis.hh:288
TransformedIndexPreBasis(RPB &&, T &&) -> TransformedIndexPreBasis< std::decay_t< RPB >, std::decay_t< T > >
A pre-basis transforming multi-indices.
Definition: transformedindexbasis.hh:52
It indices(const Node &node, It it) const
Definition: transformedindexbasis.hh:160
Transformation transformation_
Definition: transformedindexbasis.hh:173
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
void transformIndex(MultiIndex &multiIndex) const
Definition: transformedindexbasis.hh:154
RawPreBasis rawPreBasis_
Definition: transformedindexbasis.hh:172
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
RawPreBasis & rawPreBasis()
Definition: transformedindexbasis.hh:148
static constexpr size_type maxMultiIndexSize
Definition: transformedindexbasis.hh:70
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
RPB RawPreBasis
Definition: transformedindexbasis.hh:59
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:138
std::size_t size_type
Type used for indices and size information.
Definition: transformedindexbasis.hh:65
static constexpr size_type multiIndexBufferSize
Definition: transformedindexbasis.hh:72
size_type dimension() const
Get the total dimension of the space spanned by this basis.
Definition: transformedindexbasis.hh:132
const RawPreBasis & rawPreBasis() const
Definition: transformedindexbasis.hh:143
static constexpr size_type minMultiIndexSize
Definition: transformedindexbasis.hh:71
A generic implementation of a transformation.
Definition: transformedindexbasis.hh:232
auto dimension(const PreBasis &preBasis) const
Definition: transformedindexbasis.hh:257
GenericIndexingTransformation(IT_R &&indexTransformation, SI_R &&sizeImplementation)
Definition: transformedindexbasis.hh:239
void transformIndex(MultiIndex &multiIndex, const PreBasis &preBasis) const
Definition: transformedindexbasis.hh:245
static constexpr std::size_t maxIndexSize
Definition: transformedindexbasis.hh:236
static constexpr std::size_t minIndexSize
Definition: transformedindexbasis.hh:235
auto size(const Prefix &prefix, const PreBasis &preBasis) const
Definition: transformedindexbasis.hh:251