dune-functions  2.8.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 
27 namespace Dune {
28 namespace Functions {
29 namespace Experimental {
30 
31 // *****************************************************************************
32 // *****************************************************************************
33 
51 template<class MI, class RPB, class T>
53 {
54  using Transformation = T;
55 
57 
58 public:
59 
60  using RawPreBasis = RPB;
61 
63  using GridView = typename RawPreBasis::GridView;
64 
66  using size_type = std::size_t;
67 
69  using Node = typename RawPreBasis::Node;
70 
72  using IndexSet = Impl::DefaultNodeIndexSet<TransformedIndexPreBasis>;
73 
75  using MultiIndex = MI;
76 
78  using SizePrefix = Dune::ReservedVector<size_type, MultiIndex::max_size()+1>;
79 
85  template<class RPB_R, class T_R>
86  TransformedIndexPreBasis(RPB_R&& rawPreBasis, T_R&& transformation) :
87  rawPreBasis_(std::forward<RPB_R>(rawPreBasis)),
88  transformation_(std::forward<T_R>(transformation))
89  {}
90 
93  {
94  rawPreBasis_.initializeIndices();
95  }
96 
98  const GridView& gridView() const
99  {
100  return rawPreBasis_.gridView();
101  }
102 
104  void update(const GridView& gv)
105  {
106  rawPreBasis_.update(gv);
107  }
108 
119  Node makeNode() const
120  {
121  return rawPreBasis_.makeNode();
122  }
123 
131  [[deprecated("Warning: The IndexSet typedef and the makeIndexSet method are deprecated. "\
132  "As a replacement use the indices() method of the PreBasis directly.")]]
134  {
135  return IndexSet{*this};
136  }
137 
139  size_type size() const
140  {
141  return size({});
142  }
143 
145  size_type size(const SizePrefix& prefix) const
146  {
147  return transformation_.size(prefix, rawPreBasis_);
148  }
149 
152  {
153  return transformation_.dimension(rawPreBasis_);
154  }
155 
158  {
159  return rawPreBasis_.maxNodeSize();
160  }
161 
162  const RawPreBasis& rawPreBasis() const
163  {
164  return rawPreBasis_;
165  }
166 
168  {
169  return rawPreBasis_;
170  }
171 
172  void transformIndex(MultiIndex& multiIndex) const
173  {
174  transformation_.transformIndex(multiIndex, rawPreBasis_);
175  }
176 
177  template<typename It>
178  It indices(const Node& node, It it) const
179  {
180  Impl::preBasisIndices(rawPreBasis(), node, it);
181  for(std::size_t i=0; i<node.size(); ++i)
182  {
183  transformIndex(*it);
184  ++it;
185  }
186  return it;
187  }
188 
189 protected:
191  Transformation transformation_;
192 };
193 
194 
195 
196 } // end namespace Experimental
197 
198 
199 namespace BasisFactory {
200 namespace Experimental {
201 
202 namespace Imp {
203 
204 template<class RawPreBasisFactory, class Transformation>
205 class TransformedIndexPreBasisFactory
206 {
207 public:
208 
209  static const std::size_t requiredMultiIndexSize = Transformation::maxIndexSize;
210 
211  template<class RPBF_R, class T_R>
212  TransformedIndexPreBasisFactory(RPBF_R&& rawPreBasisFactory, T_R&& transformation) :
213  rawPreBasisFactory_(std::forward<RPBF_R>(rawPreBasisFactory)),
214  transformation_(std::forward<T_R>(transformation))
215  {}
216 
217  template<class MultiIndex, class GridView>
218  auto makePreBasis(const GridView& gridView) const
219  {
220  auto rawPreBasis = rawPreBasisFactory_.template makePreBasis<MultiIndex>(gridView);
221  using RawPreBasis = std::decay_t<decltype(rawPreBasis)>;
222  return Dune::Functions::Experimental::TransformedIndexPreBasis<MultiIndex, RawPreBasis, Transformation>(std::move(rawPreBasis), std::move(transformation_));
223  }
224 
225 private:
226  RawPreBasisFactory rawPreBasisFactory_;
227  Transformation transformation_;
228 };
229 
230 } // end namespace BasisFactory::Experimental::Imp
231 
232 
233 
245 template<class RawPreBasisFactory, class Transformation>
247  RawPreBasisFactory&& preBasisFactory,
248  Transformation&& transformation)
249 {
250  return Imp::TransformedIndexPreBasisFactory<std::decay_t<RawPreBasisFactory>, std::decay_t<Transformation>>(
251  std::forward<RawPreBasisFactory>(preBasisFactory),
252  std::forward<Transformation>(transformation));
253 }
254 
255 
256 
275 template<class IndexTransformation, class SizeImplementation, std::size_t minIS, std::size_t maxIS>
277 {
278 public:
279 
280  static constexpr std::size_t minIndexSize = minIS;
281  static constexpr std::size_t maxIndexSize = maxIS;
282 
283  template<class IT_R, class SI_R>
284  GenericIndexingTransformation(IT_R&& indexTransformation, SI_R&& sizeImplementation) :
285  indexTransformation_(std::forward<IT_R>(indexTransformation)),
286  sizeImplementation_(std::forward<SI_R>(sizeImplementation))
287  {}
288 
289  template<class MultiIndex, class PreBasis>
290  void transformIndex(MultiIndex& multiIndex, const PreBasis& preBasis) const
291  {
292  indexTransformation_(multiIndex, preBasis);
293  }
294 
295  template<class Prefix, class PreBasis>
296  auto size(const Prefix& prefix, const PreBasis& preBasis) const
297  {
298  return sizeImplementation_(prefix, preBasis);
299  }
300 
301  template<class PreBasis>
302  auto dimension(const PreBasis& preBasis) const
303  {
304  return preBasis.dimension();
305  }
306 
307 private:
308  IndexTransformation indexTransformation_;
309  SizeImplementation sizeImplementation_;
310 };
311 
312 
313 
332 template<class IndexTransformation, class SizeImplementation, std::size_t minIndexSize, std::size_t maxIndexSize>
333 auto indexTransformation(IndexTransformation&& indexTransformation, SizeImplementation&& sizeImplementation, Dune::index_constant<minIndexSize>, Dune::index_constant<maxIndexSize>)
334 {
336  std::decay_t<IndexTransformation>,
337  std::decay_t<SizeImplementation>,
338  minIndexSize, maxIndexSize>(
339  std::forward<IndexTransformation>(indexTransformation),
340  std::forward<SizeImplementation>(sizeImplementation));
341 }
342 
343 
344 } // end namespace Experimental
345 } // end namespace BasisFactory
346 } // end namespace Functions
347 } // end namespace Dune
348 
349 
350 #endif // DUNE_FUNCTIONS_FUNCTIONSPACEBASES_TRANSFORMEDINDEXBASIS_HH
Definition: polynomial.hh:10
auto transformIndices(RawPreBasisFactory &&preBasisFactory, Transformation &&transformation)
Create a TransformedIndexPreBasisFactory.
Definition: transformedindexbasis.hh:246
auto indexTransformation(IndexTransformation &&indexTransformation, SizeImplementation &&sizeImplementation, Dune::index_constant< minIndexSize >, Dune::index_constant< maxIndexSize >)
A generic implementation of a transformation.
Definition: transformedindexbasis.hh:333
A pre-basis transforming multi-indices.
Definition: transformedindexbasis.hh:53
Transformation transformation_
Definition: transformedindexbasis.hh:191
size_type maxNodeSize() const
Get the maximal number of DOFs associated to node for any element.
Definition: transformedindexbasis.hh:157
size_type size(const SizePrefix &prefix) const
Return number of possible values for next position in multi index.
Definition: transformedindexbasis.hh:145
RawPreBasis rawPreBasis_
Definition: transformedindexbasis.hh:190
const RawPreBasis & rawPreBasis() const
Definition: transformedindexbasis.hh:162
Dune::ReservedVector< size_type, MultiIndex::max_size()+1 > SizePrefix
Type used for prefixes handed to the size() method.
Definition: transformedindexbasis.hh:78
typename RawPreBasis::Node Node
Template mapping root tree path to type of created tree node.
Definition: transformedindexbasis.hh:69
Impl::DefaultNodeIndexSet< TransformedIndexPreBasis > IndexSet
Type of created tree node index set.
Definition: transformedindexbasis.hh:72
IndexSet makeIndexSet() const
Create tree node index set.
Definition: transformedindexbasis.hh:133
void transformIndex(MultiIndex &multiIndex) const
Definition: transformedindexbasis.hh:172
void initializeIndices()
Initialize the global indices.
Definition: transformedindexbasis.hh:92
size_type dimension() const
Get the total dimension of the space spanned by this basis.
Definition: transformedindexbasis.hh:151
size_type size() const
Same as size(prefix) with empty prefix.
Definition: transformedindexbasis.hh:139
Node makeNode() const
Create tree node with given root tree path.
Definition: transformedindexbasis.hh:119
TransformedIndexPreBasis(RPB_R &&rawPreBasis, T_R &&transformation)
Constructor for given child pre-basis objects.
Definition: transformedindexbasis.hh:86
MI MultiIndex
Type used for global numbering of the basis vectors.
Definition: transformedindexbasis.hh:75
RawPreBasis & rawPreBasis()
Definition: transformedindexbasis.hh:167
It indices(const Node &node, It it) const
Definition: transformedindexbasis.hh:178
std::size_t size_type
Type used for indices and size information.
Definition: transformedindexbasis.hh:66
typename RawPreBasis::GridView GridView
The grid view that the FE basis is defined on.
Definition: transformedindexbasis.hh:63
void update(const GridView &gv)
Update the stored grid view, to be called if the grid has changed.
Definition: transformedindexbasis.hh:104
const GridView & gridView() const
Obtain the grid view that the basis is defined on.
Definition: transformedindexbasis.hh:98
RPB RawPreBasis
Definition: transformedindexbasis.hh:60
A generic implementation of a transformation.
Definition: transformedindexbasis.hh:277
auto dimension(const PreBasis &preBasis) const
Definition: transformedindexbasis.hh:302
GenericIndexingTransformation(IT_R &&indexTransformation, SI_R &&sizeImplementation)
Definition: transformedindexbasis.hh:284
void transformIndex(MultiIndex &multiIndex, const PreBasis &preBasis) const
Definition: transformedindexbasis.hh:290
static constexpr std::size_t maxIndexSize
Definition: transformedindexbasis.hh:281
static constexpr std::size_t minIndexSize
Definition: transformedindexbasis.hh:280
auto size(const Prefix &prefix, const PreBasis &preBasis) const
Definition: transformedindexbasis.hh:296