7#ifndef DUNE_FUNCTIONS_FUNCTIONSPACEBASES_DYNAMICPOWERBASIS_HH
8#define DUNE_FUNCTIONS_FUNCTIONSPACEBASES_DYNAMICPOWERBASIS_HH
10#include <dune/common/reservedvector.hh>
11#include <dune/common/typeutilities.hh>
12#include <dune/common/indices.hh>
46template<
class IMS,
class SPB>
49 static const bool isBlocked = std::is_same_v<IMS,BasisFactory::BlockedLexicographic> or std::is_same_v<IMS,BasisFactory::BlockedInterleaved>;
77 template<
class... SFArgs,
84 static_assert(models<Concept::PreBasis<GridView>,
SubPreBasis>(),
"Subprebasis passed to DynamicPowerPreBasis does not model the PreBasis concept.");
124 return size(Dune::ReservedVector<size_type, multiIndexBufferSize>{});
128 template<
class SizePrefix>
136 template<
class SizePrefix,
class Children>
142 if (prefix.size() == 0)
152 template<
class SizePrefix,
class Children>
158 if (prefix.size() == 0)
174 template<
class MultiIndex>
177 for(std::size_t i=0; i<M.size()-1; ++i)
179 M.resize(M.size()-1);
182 template<
class SizePrefix,
class Children>
185 if (prefix.size() == 0)
191 template<
class SizePrefix,
class Children>
194 if (prefix.size() == 0)
202 auto tail = prefix.back();
206 prefix.push_back(tail);
246 template<
class NodeType,
typename It,
247 std::enable_if_t<NodeType::isPower, int> = 0>
261 template<
class NodeType,
typename It,
class Children>
264 using namespace Dune::Indices;
265 size_type subTreeSize = node.child(_0).size();
267 auto next =
subPreBasis().indices(node.child(_0), multiIndices);
270 for (std::size_t i = 0; i<subTreeSize; ++i)
272 for (std::size_t child = 1; child<
children; ++child)
274 for (std::size_t i = 0; i<subTreeSize; ++i)
280 (*next) = multiIndices[i];
281 (*next)[0] = multiIndices[i][0]+child;
288 template<
class NodeType,
typename It,
class Children>
291 using namespace Dune::Indices;
292 size_type subTreeSize = node.child(_0).size();
295 auto next =
subPreBasis().indices(node.child(_0), multiIndices);
296 for (std::size_t child = 1; child<
children_; ++child)
298 for (std::size_t i = 0; i<subTreeSize; ++i)
304 (*next) = multiIndices[i];
305 (*next)[0] += child*firstIndexEntrySize;
312 template<
class MultiIndex>
315 M.resize(M.size()+1);
316 for(std::size_t i=M.size()-1; i>0; --i)
321 template<
class NodeType,
typename It,
class Children>
324 using namespace Dune::Indices;
325 size_type subTreeSize = node.child(_0).size();
327 auto next =
subPreBasis().indices(node.child(_0), multiIndices);
329 for (std::size_t i = 0; i<subTreeSize; ++i)
331 for (std::size_t child = 1; child<
children_; ++child)
333 for (std::size_t i = 0; i<subTreeSize; ++i)
339 (*next) = multiIndices[i];
347 template<
class NodeType,
typename It,
class Children>
350 using namespace Dune::Indices;
351 size_type subTreeSize = node.child(_0).size();
353 auto next =
subPreBasis().indices(node.child(_0), multiIndices);
355 for (std::size_t i = 0; i<subTreeSize; ++i)
356 multiIndices[i].push_back(0);
357 for (std::size_t child = 1; child<
children_; ++child)
359 for (std::size_t i = 0; i<subTreeSize; ++i)
363 (*next) = multiIndices[i];
364 (*next).back() = child;
371 template<
class Children>
375 if constexpr(std::is_same_v<IMS, BasisFactory::FlatInterleaved>)
377 else if constexpr(std::is_same_v<IMS, BasisFactory::FlatLexicographic>)
379 else if constexpr(std::is_same_v<IMS, BasisFactory::BlockedLexicographic>)
381 else if constexpr(std::is_same_v<IMS, BasisFactory::BlockedInterleaved>)
382 return ContainerDescriptors::Impl::appendToTree(
children,std::move(subTree));
394namespace BasisFactory {
408template<
class ChildPreBasisFactory,
class IndexMergingStrategy>
411 return [childPreBasisFactory,k](
const auto& gridView) {
412 auto childPreBasis = childPreBasisFactory(gridView);
427template<
class ChildPreBasisFactory>
428auto power(ChildPreBasisFactory&& childPreBasisFactory, std::size_t k)
430 return [childPreBasisFactory,k](
const auto& gridView) {
431 auto childPreBasis = childPreBasisFactory(gridView);
auto power(ChildPreBasisFactory &&childPreBasisFactory, std::size_t k, const IndexMergingStrategy &)
Create a pre-basis factory that can build a PowerPreBasis.
Definition dynamicpowerbasis.hh:409
std::enable_if_t< std::is_constructible_v< T, Args... >, int > enableIfConstructible
Helper to constrain forwarding constructors.
Definition type_traits.hh:31
Definition polynomial.hh:17
auto containerDescriptor(const PreBasis &preBasis)
Return the container descriptor of the pre-basis, if defined, otherwise ContainerDescriptor::Unknown.
Definition containerdescriptors.hh:73
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:159
Base class for index merging strategies to simplify detection.
Definition basistags.hh:48
Lexicographic merging of direct children without blocking.
Definition basistags.hh:84
Interleaved merging of direct children without blocking.
Definition basistags.hh:118
Lexicographic merging of direct children with blocking (i.e. creating one block per direct child).
Definition basistags.hh:152
Interleaved merging of direct children with blocking (i.e. creating blocks at the leaves containing o...
Definition basistags.hh:184
Fallback container descriptor if nothing else fits.
Definition containerdescriptors.hh:50
A pre-basis for dynamic power bases.
Definition dynamicpowerbasis.hh:48
std::size_t size_type
Type used for indices and size information.
Definition dynamicpowerbasis.hh:60
IMS IndexMergingStrategy
Strategy used to merge the global indices of the child factories.
Definition dynamicpowerbasis.hh:63
DynamicPowerPreBasis(std::size_t c, SFArgs &&... sfArgs)
Constructor for given child pre-basis objects.
Definition dynamicpowerbasis.hh:80
static void multiIndexPopFront(MultiIndex &M)
Definition dynamicpowerbasis.hh:175
size_type dimension() const
Get the total dimension of the space spanned by this basis.
Definition dynamicpowerbasis.hh:222
auto containerDescriptorImpl(Children children) const
Definition dynamicpowerbasis.hh:372
It indices(const NodeType &node, It it) const
Maps from subtree index set [0..size-1] to a globally unique multi index in global basis.
Definition dynamicpowerbasis.hh:248
void initializeIndices()
Initialize the global indices.
Definition dynamicpowerbasis.hh:88
size_type sizeImpl(SizePrefix prefix, Children children, BasisFactory::FlatInterleaved) const
Definition dynamicpowerbasis.hh:137
static constexpr size_type maxMultiIndexSize
Definition dynamicpowerbasis.hh:68
void update(const GridView &gv)
Update the stored grid view, to be called if the grid has changed.
Definition dynamicpowerbasis.hh:100
auto containerDescriptor() const
Return the associated container descriptor.
Definition dynamicpowerbasis.hh:254
size_type size() const
Same as size(prefix) with empty prefix.
Definition dynamicpowerbasis.hh:122
It indicesImpl(const NodeType &node, It multiIndices, Children children, BasisFactory::BlockedInterleaved) const
Definition dynamicpowerbasis.hh:348
SubPreBasis & subPreBasis()
Mutable access to the stored prebasis of the factor in the power space.
Definition dynamicpowerbasis.hh:240
size_type sizeImpl(SizePrefix prefix, Children children, BasisFactory::FlatLexicographic) const
Definition dynamicpowerbasis.hh:153
static void multiIndexPushFront(MultiIndex &M, size_type M0)
Definition dynamicpowerbasis.hh:313
SubPreBasis subPreBasis_
Definition dynamicpowerbasis.hh:389
size_type sizeImpl(SizePrefix prefix, Children children, BasisFactory::BlockedLexicographic) const
Definition dynamicpowerbasis.hh:183
size_type sizeImpl(SizePrefix prefix, Children children, BasisFactory::BlockedInterleaved) const
Definition dynamicpowerbasis.hh:192
It indicesImpl(const NodeType &node, It multiIndices, Children children, BasisFactory::BlockedLexicographic) const
Definition dynamicpowerbasis.hh:322
static constexpr size_type multiIndexBufferSize
Definition dynamicpowerbasis.hh:70
SPB SubPreBasis
The child pre-basis.
Definition dynamicpowerbasis.hh:54
Node makeNode() const
Create tree node.
Definition dynamicpowerbasis.hh:108
const SubPreBasis & subPreBasis() const
Const access to the stored prebasis of the factor in the power space.
Definition dynamicpowerbasis.hh:234
It indicesImpl(const NodeType &node, It multiIndices, Children children, BasisFactory::FlatInterleaved) const
Definition dynamicpowerbasis.hh:262
std::size_t children() const
Definition dynamicpowerbasis.hh:116
size_type maxNodeSize() const
Get the maximal number of DOFs associated to node for any element.
Definition dynamicpowerbasis.hh:228
It indicesImpl(const NodeType &node, It multiIndices, Children children, BasisFactory::FlatLexicographic) const
Definition dynamicpowerbasis.hh:289
size_type size(const SizePrefix &prefix) const
Return number of possible values for next position in multi index.
Definition dynamicpowerbasis.hh:129
typename SPB::GridView GridView
The grid view that the FE basis is defined on.
Definition dynamicpowerbasis.hh:57
std::size_t children_
Definition dynamicpowerbasis.hh:388
const GridView & gridView() const
Obtain the grid view that the basis is defined on.
Definition dynamicpowerbasis.hh:94
static constexpr size_type minMultiIndexSize
Definition dynamicpowerbasis.hh:69