7#ifndef DUNE_FUNCTIONS_FUNCTIONSPACEBASES_CONTAINERDESCRIPTORS_HH
8#define DUNE_FUNCTIONS_FUNCTIONSPACEBASES_CONTAINERDESCRIPTORS_HH
49namespace ContainerDescriptors {
57template<
class PreBasis>
60 if constexpr (
requires{ preBasis.containerDescriptor(); })
61 return preBasis.containerDescriptor();
67namespace ContainerDescriptors {
81template<
class... Children>
86template<
class Child0,
class... Children,
91 using Descriptor =
Tuple<Child0,Children...>;
92 return Descriptor{std::move(child0),std::move(children)...};
97template<
class Child, std::
size_t n>
101template<
class Child0,
class... Children,
105 using Descriptor =
Array<Child0,1+
sizeof...(Children)>;
106 return Descriptor{std::move(child),std::move(children)...};
115template<
class Child, std::
size_t n>
119 template<
class C = Child,
127 : child_{
std::move(child)}
131 template<
class Index>
132 const Child&
operator[] (
const Index& )
const {
return child_; }
142template<std::
size_t n>
146template<
class Child, std::
size_t n>
158 template<
class C = Child,
168 , child_{
std::move(child)}
172 template<
class Index>
173 const Child&
operator[] (
const Index& )
const {
return child_; }
195template<
class InnerFunc,
class LeafFunc>
198 TreeTransform (
const InnerFunc& innerFunc,
const LeafFunc& leafFunc)
199 : innerFunc_(innerFunc)
200 , leafFunc_(leafFunc)
203 Unknown
operator() (
const Unknown& tree)
const
210 return leafFunc_(tree);
214 auto operator() (
const Tuple<V...>& tree)
const
221 template<
class V, std::
size_t n>
222 auto operator() (
const Array<V,n>& tree)
const
232 using W =
decltype(innerFunc_(tree[0]));
234 result.reserve(tree.size());
236 result.emplace_back(innerFunc_(tree[i]));
240 template<
class V, std::
size_t n>
241 auto operator() (
const UniformArray<V,n>& tree)
const
247 auto operator() (
const UniformVector<V>& tree)
const
253 InnerFunc innerFunc_;
268template<
class Size,
class T>
269auto appendToTree (Size s,
const T& tree)
272 [s](
auto&& node) {
return appendToTree(s, node); },
278template<
class...
Child>
281 if constexpr ((std::is_same_v<Child, FlatVector> && ...))
288template<
class N,
class Child>
289auto flatLexicographicN (
N n, Child child)
295template<
class N,
class GrandChild>
296auto flatLexicographicN (
N n, UniformVector<GrandChild> child)
298 return UniformVector<GrandChild>{
child.size()*n,
child[0]};
302template<
class N,
class GrandChild, std::
size_t m>
303auto flatLexicographicN (
N n, UniformArray<GrandChild, m> child)
305 if constexpr (std::is_same_v<N, std::size_t>)
306 return UniformVector<GrandChild>{n*m,
child[0]};
308 return UniformArray<GrandChild, N::value*m>{
child[0]};
312template<
class N,
class GrandChild>
313auto flatLexicographicN (
N n, Vector<GrandChild> child)
315 auto result = Vector<GrandChild>{};
316 result.reserve(
child.size()*n);
319 result.emplace_back(
child[i]);
324template<
class N,
class GrandChild, std::
size_t m>
325auto flatLexicographicN (
N n, Array<GrandChild, m> child)
327 if constexpr (std::is_same_v<N, std::size_t>)
329 auto result = Vector<GrandChild>{};
330 result.reserve(
child.size()*n);
333 result.emplace_back(
child[i]);
338 auto result = Array<GrandChild, N::value*m>{};
341 result.emplace_back(
child[i]);
347template<
class N,
class... GrandChild>
348auto flatLexicographicN (
N n, Tuple<GrandChild...> child)
357template<
class N,
class Child>
358auto flatInterleavedN (
N n, Child child)
364template<
class N,
class GrandChild>
365auto flatInterleavedN (
N n, UniformVector<GrandChild> child)
367 return UniformVector<GrandChild>{
child.size()*n,
child[0]};
371template<
class N,
class GrandChild, std::
size_t m>
372auto flatInterleavedN (
N n, UniformArray<GrandChild, m> child)
374 if constexpr (std::is_integral_v<N>)
375 return UniformVector<GrandChild>{n*m,
child[0]};
377 return UniformArray<GrandChild, N::value*m>{
child[0]};
381template<
class N,
class GrandChild>
382auto flatInterleavedN (
N n, Vector<GrandChild> child)
384 auto result = Vector<GrandChild>{};
385 result.reserve(
child.size()*n);
388 result.emplace_back(
child[i]);
393template<
class N,
class GrandChild, std::
size_t m>
394auto flatInterleavedN (
N n, Array<GrandChild, m> child)
396 if constexpr (std::is_integral_v<N>)
398 auto result = Vector<GrandChild>{};
399 result.reserve(
child.size()*n);
402 result.emplace_back(
child[i]);
407 auto result = Array<GrandChild, N::value*m>{};
410 result.emplace_back(
child[i]);
416template<
class N,
class... GrandChild>
417auto flatInterleavedN (
N n, Tuple<GrandChild...> child)
constexpr FlatLexicographic flatLexicographic()
Creates a lexicographic merging of direct children without blocking.
Definition basistags.hh:192
Definition monomialset.hh:19
auto containerDescriptor(const PreBasis &preBasis)
Return the container descriptor of the pre-basis, if defined, otherwise ContainerDescriptor::Unknown.
Definition containerdescriptors.hh:58
auto makeUniformDescriptor(std::integral_constant< std::size_t, n >, Child child)
Generate a uniform descriptor in case the size is a static constant.
Definition containerdescriptors.hh:147
auto makeDescriptor(Child0 child, Children... children)
Generate a descriptor in case the children are all of the same type.
Definition containerdescriptors.hh:103
UniformVector< Value > FlatVector
Alias for a uniform vector storing value placeholders.
Definition containerdescriptors.hh:184
decltype(auto) constexpr unpackIntegerSequence(F &&f, std::integer_sequence< I, i... > sequence)
static constexpr IntegralRange< std::decay_t< T > > range(T &&from, U &&to) noexcept
static constexpr size_type N()
virtual void operator()()=0
decltype(auto) child(Node &&node, TreePath< Indices... > treePath)
typename Impl::ChildTraits< Node, indices... >::type Child
Fallback container descriptor if nothing else fits.
Definition containerdescriptors.hh:52
The node in the descriptor tree representing a value placeholder.
Definition containerdescriptors.hh:71
static constexpr std::size_t size()
A value placeholder does not have any sub-descriptors, thus its size is zero.
Definition containerdescriptors.hh:77
Value operator[](const Index &) const
The child access method is only available for the interface, but should not be called.
Definition containerdescriptors.hh:74
Descriptor for arrays with all children identical and the number of children a static size.
Definition containerdescriptors.hh:117
static constexpr std::size_t size()
The static size information, i.e., number of children.
Definition containerdescriptors.hh:135
UniformArray()
Default constructor. Is enable if the child-type is default constructible.
Definition containerdescriptors.hh:121
UniformArray(Child child)
Constructor that stores a single child only.
Definition containerdescriptors.hh:126
const Child & operator[](const Index &) const
Access the i'th child that is always the same, i.e., child_.
Definition containerdescriptors.hh:132
Uniform descriptor with dynamic size.
Definition containerdescriptors.hh:156
UniformVector(std::size_t size, Child child)
Constructor that stores the size and a single child only.
Definition containerdescriptors.hh:166
std::size_t size() const
The dynamic size information, i.e., number of children.
Definition containerdescriptors.hh:176
UniformVector(std::size_t size)
Default constructor with size. Is enable if the child-type is default constructible.
Definition containerdescriptors.hh:160
const Child & operator[](const Index &) const
Access the i'th child that is always the same, i.e., child_.
Definition containerdescriptors.hh:173