3#ifndef DUNE_FUNCTIONS_FUNCTIONSPACEBASES_COMPOSITEBASIS_HH
4#define DUNE_FUNCTIONS_FUNCTIONSPACEBASES_COMPOSITEBASIS_HH
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#include <dune/common/tupleutility.hh>
15#include <dune/common/tuplevector.hh>
51template<
class IMS,
class... SPB>
54 static const bool isBlocked = std::is_same_v<IMS,BasisFactory::BlockedLexicographic> or std::is_same_v<IMS,BasisFactory::BlockedInterleaved>;
61 template<std::
size_t i>
65 using GridView =
typename std::tuple_element_t<0, SubPreBases>::GridView;
74 static const std::size_t
children =
sizeof...(SPB);
92 template<
class... SFArgs,
96 subPreBases_(std::forward<SFArgs>(sfArgs)...)
98 Hybrid::forEach(subPreBases_, [&](
const auto&
subPreBasis){
99 static_assert(models<Concept::PreBasis<GridView>, std::decay_t<
decltype(
subPreBasis)>>(),
"Subprebases passed to CompositePreBasis does not model the PreBasis concept.");
110 std::enable_if_t<std::conjunction_v<
112 std::is_same<GV, GridView>,
113 std::is_constructible<SPB, GridView>...
116 subPreBases_(SPB(gv)...)
118 Hybrid::forEach(subPreBases_, [&](
const auto&
subPreBasis){
119 static_assert(models<Concept::PreBasis<GridView>, std::decay_t<
decltype(
subPreBasis)>>(),
"Subprebases passed to CompositePreBasis does not model the PreBasis concept.");
134 return std::get<0>(subPreBases_).gridView();
160 return size(Dune::ReservedVector<size_type, multiIndexBufferSize>{});
164 template<
class SizePrefix>
172 template<
class SizePrefix>
175 if (prefix.size() == 0)
178 return Hybrid::switchCases(
ChildIndices(), prefix[0], [&] (
auto i) {
179 SizePrefix subPrefix;
180 for(std::size_t i=1; i<prefix.size(); ++i)
181 subPrefix.push_back(prefix[i]);
182 return this->subPreBasis(i).size(subPrefix);
188 template<
class SizePrefix>
189 size_type size(
const SizePrefix& prefix, BasisFactory::FlatLexicographic)
const
192 if (prefix.size() == 0)
198 staticFindInRange<0, children>([&](
auto i) {
200 if (shiftedFirstDigit < firstDigitSize)
202 SizePrefix subPrefix;
203 subPrefix.push_back(shiftedFirstDigit);
204 for(std::size_t i=1; i<prefix.size(); ++i)
205 subPrefix.push_back(prefix[i]);
209 shiftedFirstDigit -= firstDigitSize;
241 template<std::
size_t i>
244 return std::get<i>(subPreBases_);
248 template<std::
size_t i>
251 return std::get<i>(subPreBases_);
255 template<
typename It>
263 template<
typename It>
273 subPreBasis(child).indices(node.child(child), multiIndices);
274 for (std::size_t i = 0; i<subTreeSize; ++i)
275 multiIndices[i][0] += firstComponentOffset;
279 multiIndices += subTreeSize;
284 template<
class MultiIndex>
285 static void multiIndexPushFront(MultiIndex& M,
size_type M0)
287 M.resize(M.size()+1);
288 for(std::size_t i=M.size()-1; i>0; --i)
293 template<
typename It>
294 It
indices(
const Node& node, It multiIndices, BasisFactory::BlockedLexicographic)
const
300 subPreBasis(child).indices(node.child(child), multiIndices);
302 for (std::size_t i = 0; i<subTreeSize; ++i)
303 this->multiIndexPushFront(multiIndices[i], child);
305 multiIndices += subTreeSize;
310 std::tuple<SPB...> subPreBases_;
315namespace BasisFactory {
319template<
class IndexMergingStrategy,
class... ChildPreBasisFactory>
320class CompositePreBasisFactory
323 template<
class GridView,
class... ChildPreBasis>
324 auto makePreBasisFromChildPreBases(
const GridView&, ChildPreBasis&&... childPreBasis)
const
326 return CompositePreBasis<IndexMergingStrategy, std::decay_t<ChildPreBasis>...>(std::forward<ChildPreBasis>(childPreBasis)...);
331 CompositePreBasisFactory(
const ChildPreBasisFactory&... childPreBasisFactory) :
332 childPreBasisFactories_(childPreBasisFactory...)
335 CompositePreBasisFactory(ChildPreBasisFactory&&... childPreBasisFactory) :
336 childPreBasisFactories_(std::move(childPreBasisFactory)...)
339 template<
class Gr
idView>
340 auto operator()(
const GridView& gridView)
const
343 return std::apply([&](
const auto&... childPreBasisFactory) {
344 return this->makePreBasisFromChildPreBases(gridView, childPreBasisFactory(gridView)...);
345 }, childPreBasisFactories_);
349 std::tuple<ChildPreBasisFactory...> childPreBasisFactories_;
374 using ArgTuple = std::tuple<std::decay_t<Args>...>;
377 constexpr std::size_t children = Dune::SizeOf<Args...>::value-1;
383 auto childIndices = std::make_index_sequence<children>{};
386 return applyPartial([](
auto&&... childPreBasisFactory){
387 return Imp::CompositePreBasisFactory<
IndexMergingStrategy, std::decay_t<
decltype(childPreBasisFactory)>...>(std::forward<
decltype(childPreBasisFactory)>(childPreBasisFactory)...);
389 std::forward_as_tuple(std::forward<Args>(args)...),
409 return Imp::CompositePreBasisFactory<BasisFactory::BlockedLexicographic, std::decay_t<Args>...>(std::forward<Args>(args)...);
415namespace BasisBuilder {
417 using namespace BasisFactory;
auto composite(Args &&... args)
Create a factory builder that can build a CompositePreBasis.
Definition: compositebasis.hh:369
typename std::enable_if< std::is_constructible< T, Args... >::value, int >::type enableIfConstructible
Helper to constrain forwarding constructors.
Definition: type_traits.hh:26
Definition: polynomial.hh:10
static constexpr bool isIndexMergingStrategy()
Definition: basistags.hh:23
Get last entry of type list.
Definition: utility.hh:222
Base class for index merging strategies to simplify detection.
Definition: basistags.hh:44
Lexicographic merging of direct children without blocking.
Definition: basistags.hh:80
Lexicographic merging of direct children with blocking (i.e. creating one block per direct child).
Definition: basistags.hh:148
A pre-basis for composite bases.
Definition: compositebasis.hh:53
SubPreBasis< i > & subPreBasis(Dune::index_constant< i >={})
Mutable access to the stored prebasis of the factor in the power space.
Definition: compositebasis.hh:249
IMS IndexMergingStrategy
Strategy used to merge the global indices of the child pre-bases.
Definition: compositebasis.hh:71
size_type maxNodeSize() const
Get the maximal number of DOFs associated to node for any element.
Definition: compositebasis.hh:230
const SubPreBasis< i > & subPreBasis(Dune::index_constant< i >={}) const
Const access to the stored prebasis of the factor in the power space.
Definition: compositebasis.hh:242
std::size_t size_type
Type used for indices and size information.
Definition: compositebasis.hh:68
CompositeBasisNode< typename SPB::Node... > Node
Template mapping root tree path to type of created tree node.
Definition: compositebasis.hh:81
size_type size(const SizePrefix &prefix) const
Return number of possible values for next position in multi index.
Definition: compositebasis.hh:165
CompositePreBasis(SFArgs &&... sfArgs)
Constructor for given child pre-basis objects.
Definition: compositebasis.hh:95
size_type dimension() const
Get the total dimension of the space spanned by this basis.
Definition: compositebasis.hh:219
CompositePreBasis(const GV &gv)
Constructor for given GridView.
Definition: compositebasis.hh:115
It indices(const Node &node, It it) const
Maps from subtree index set [0..size-1] to a globally unique multi index in global basis.
Definition: compositebasis.hh:256
size_type size() const
Same as size(prefix) with empty prefix.
Definition: compositebasis.hh:158
typename std::tuple_element_t< 0, SubPreBases >::GridView GridView
The grid view that the FE basis is defined on.
Definition: compositebasis.hh:65
static const std::size_t children
Definition: compositebasis.hh:74
std::tuple< SPB... > SubPreBases
Tuple of child pre-bases.
Definition: compositebasis.hh:58
Node makeNode() const
Create tree node.
Definition: compositebasis.hh:148
void initializeIndices()
Initialize the global indices.
Definition: compositebasis.hh:124
std::tuple_element_t< i, SubPreBases > SubPreBasis
Export individual child pre-bases by index.
Definition: compositebasis.hh:62
std::make_index_sequence< children > ChildIndices
Definition: compositebasis.hh:76
void update(const GridView &gv)
Update the stored grid view, to be called if the grid has changed.
Definition: compositebasis.hh:138
static constexpr size_type multiIndexBufferSize
Definition: compositebasis.hh:85
const GridView & gridView() const
Obtain the grid view that the basis is defined on.
Definition: compositebasis.hh:132
static constexpr size_type minMultiIndexSize
Definition: compositebasis.hh:84
static constexpr size_type maxMultiIndexSize
Definition: compositebasis.hh:83