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>
52 template<
class MI,
class IMS,
class... SPB>
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);
84 using IndexSet = Impl::DefaultNodeIndexSet<CompositePreBasis>;
97 template<
class... SFArgs,
101 subPreBases_(std::forward<SFArgs>(sfArgs)...)
103 Hybrid::forEach(subPreBases_, [&](
const auto&
subPreBasis){
119 return std::get<0>(subPreBases_).gridView();
149 [[deprecated(
"Warning: The IndexSet typedef and the makeIndexSet method are deprecated. "\
150 "As a replacement use the indices() method of the PreBasis directly.")]]
172 if (prefix.size() == 0)
175 return Hybrid::switchCases(
ChildIndices(), prefix[0], [&] (
auto i) {
176 typename SubPreBasis<i>::SizePrefix subPrefix;
177 for(std::size_t i=1; i<prefix.size(); ++i)
178 subPrefix.push_back(prefix[i]);
179 return this->subPreBasis(i).size(subPrefix);
188 if (prefix.size() == 0)
194 staticFindInRange<0, children>([&](
auto i) {
196 if (shiftedFirstDigit < firstDigitSize)
198 typename SubPreBasis<i>::SizePrefix subPrefix;
199 subPrefix.push_back(shiftedFirstDigit);
200 for(std::size_t i=1; i<prefix.size(); ++i)
201 subPrefix.push_back(prefix[i]);
205 shiftedFirstDigit -= firstDigitSize;
237 template<std::
size_t i>
240 return std::get<i>(subPreBases_);
244 template<std::
size_t i>
247 return std::get<i>(subPreBases_);
251 template<
typename It>
259 template<
typename It>
269 Impl::preBasisIndices(
subPreBasis(child), node.child(child), multiIndices);
270 for (std::size_t i = 0; i<subTreeSize; ++i)
271 multiIndices[i][0] += firstComponentOffset;
273 firstComponentOffset +=
subPreBasis(child).size({});
275 multiIndices += subTreeSize;
282 M.resize(M.size()+1);
283 for(std::size_t i=M.size()-1; i>0; --i)
288 template<
typename It>
289 It
indices(
const Node& node, It multiIndices, BasisFactory::BlockedLexicographic)
const
295 Impl::preBasisIndices(
subPreBasis(child), node.child(child), multiIndices);
297 for (std::size_t i = 0; i<subTreeSize; ++i)
298 this->multiIndexPushFront(multiIndices[i], child);
300 multiIndices += subTreeSize;
305 std::tuple<SPB...> subPreBases_;
310 namespace BasisFactory {
315 constexpr std::size_t maxHelper(ST0&& i0)
320 template<
class ST0,
class... ST>
321 constexpr std::size_t maxHelper(ST0&& i0, ST&&... i)
323 return (i0 > maxHelper(i...)) ? i0 : maxHelper(i...);
326 template<
class IndexMergingStrategy,
class... ChildPreBasisFactory>
327 class CompositePreBasisFactory
329 static const bool isBlocked = std::is_same<IndexMergingStrategy,BlockedLexicographic>::value or std::is_same<IndexMergingStrategy,BlockedInterleaved>::value;
331 static const std::size_t maxChildIndexSize = maxHelper(ChildPreBasisFactory::requiredMultiIndexSize...);
333 template<
class MultiIndex,
class GridView,
class... ChildPreBasis>
334 auto makePreBasisFromChildPreBases(
const GridView&, ChildPreBasis&&... childPreBasis)
const
336 return CompositePreBasis<MultiIndex, IndexMergingStrategy, std::decay_t<ChildPreBasis>...>(std::forward<ChildPreBasis>(childPreBasis)...);
341 static const std::size_t requiredMultiIndexSize = isBlocked ? (maxChildIndexSize+1) : maxChildIndexSize;
343 CompositePreBasisFactory(
const ChildPreBasisFactory&... childPreBasisFactory) :
344 childPreBasisFactories_(childPreBasisFactory...)
347 CompositePreBasisFactory(ChildPreBasisFactory&&... childPreBasisFactory) :
348 childPreBasisFactories_(std::move(childPreBasisFactory)...)
351 template<
class MultiIndex,
class Gr
idView>
352 auto makePreBasis(
const GridView& gridView)
const
355 return std::apply([&](
const auto&... childPreBasisFactory) {
356 return this->makePreBasisFromChildPreBases<MultiIndex>(gridView, childPreBasisFactory.template makePreBasis<MultiIndex>(gridView)...);
357 }, childPreBasisFactories_);
361 std::tuple<ChildPreBasisFactory...> childPreBasisFactories_;
386 using ArgTuple = std::tuple<std::decay_t<Args>...>;
389 constexpr std::size_t children = Dune::SizeOf<Args...>::value-1;
395 auto childIndices = std::make_index_sequence<children>{};
398 return applyPartial([](
auto&&... childPreBasisFactory){
399 return Imp::CompositePreBasisFactory<
IndexMergingStrategy, std::decay_t<decltype(childPreBasisFactory)>...>(std::forward<decltype(childPreBasisFactory)>(childPreBasisFactory)...);
401 std::forward_as_tuple(std::forward<Args>(args)...),
421 return Imp::CompositePreBasisFactory<BasisFactory::BlockedLexicographic, std::decay_t<Args>...>(std::forward<Args>(args)...);
427 namespace BasisBuilder {
429 using namespace BasisFactory;
auto composite(Args &&... args)
Create a factory builder that can build a CompositePreBasis.
Definition: compositebasis.hh:381
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:54
SubPreBasis< i > & subPreBasis(Dune::index_constant< i >={})
Mutable access to the stored prebasis of the factor in the power space.
Definition: compositebasis.hh:245
typename std::tuple_element_t< 0, SubPreBases >::GridView GridView
The grid view that the FE basis is defined on.
Definition: compositebasis.hh:65
Node makeNode() const
Create tree node.
Definition: compositebasis.hh:133
size_type size() const
Same as size(prefix) with empty prefix.
Definition: compositebasis.hh:157
static const std::size_t children
Definition: compositebasis.hh:74
Dune::ReservedVector< size_type, MultiIndex::max_size()> SizePrefix
Type used for prefixes handed to the size() method.
Definition: compositebasis.hh:90
size_type dimension() const
Get the total dimension of the space spanned by this basis.
Definition: compositebasis.hh:215
std::size_t size_type
Type used for indices and size information.
Definition: compositebasis.hh:68
size_type size(const SizePrefix &prefix) const
Return number of possible values for next position in multi index.
Definition: compositebasis.hh:163
IndexSet makeIndexSet() const
Create tree node index set.
Definition: compositebasis.hh:151
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:123
CompositePreBasis(SFArgs &&... sfArgs)
Constructor for given child pre-basis objects.
Definition: compositebasis.hh:100
Impl::DefaultNodeIndexSet< CompositePreBasis > IndexSet
Type of created tree node index set.
Definition: compositebasis.hh:84
IMS IndexMergingStrategy
Strategy used to merge the global indices of the child pre-bases.
Definition: compositebasis.hh:71
std::tuple_element_t< i, SubPreBases > SubPreBasis
Export individual child pre-bases by index.
Definition: compositebasis.hh:62
MI MultiIndex
Type used for global numbering of the basis vectors.
Definition: compositebasis.hh:87
size_type maxNodeSize() const
Get the maximal number of DOFs associated to node for any element.
Definition: compositebasis.hh:226
const GridView & gridView() const
Obtain the grid view that the basis is defined on.
Definition: compositebasis.hh:117
CompositeBasisNode< typename SPB::Node... > Node
Template mapping root tree path to type of created tree node.
Definition: compositebasis.hh:81
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:252
std::tuple< SPB... > SubPreBases
Tuple of child pre-bases.
Definition: compositebasis.hh:58
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:238
void initializeIndices()
Initialize the global indices.
Definition: compositebasis.hh:109
Definition: functionspacebases/concepts.hh:182