3 #ifndef DUNE_FUNCTIONS_FUNCTIONSPACEBASES_COMPOSITEBASIS_HH 4 #define DUNE_FUNCTIONS_FUNCTIONSPACEBASES_COMPOSITEBASIS_HH 9 #include <dune/common/std/utility.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> 15 #include <dune/typetree/compositenode.hh> 16 #include <dune/typetree/utility.hh> 29 template<
typename... T>
31 :
public std::integral_constant<std::size_t,sizeof...(T)>
34 template<
typename... T>
50 template<
class MI,
class TP,
class IT,
class... SF>
65 template<
class MI,
class IMS,
class... SF>
74 using GridView =
typename std::tuple_element<0, SubFactories>::type::GridView;
83 static const std::size_t children =
sizeof...(SF);
85 template<
class,
class,
class,
class...>
99 template<
class F,
class SubTP>
104 template<
class F,
class SubTP>
119 template<std::
size_t k>
120 using SubFactory =
typename std::tuple_element<k, std::tuple<SF...>>::type;
134 using SizePrefix = Dune::ReservedVector<size_type, MultiIndex::max_size()+1>;
141 template<
class... SFArgs,
145 subFactories_(
std::forward<SFArgs>(sfArgs)...)
152 using namespace Dune::Hybrid;
153 forEach(Dune::Std::make_index_sequence<children>(), [&](
auto i) {
154 elementAt(subFactories_, i).initializeIndices();
161 return std::get<0>(subFactories_).gridView();
167 using namespace Dune::Hybrid;
168 forEach(Dune::Std::make_index_sequence<children>(), [&](
auto i) {
169 elementAt(subFactories_, i).update(gv);
187 using namespace Dune::Hybrid;
188 forEach(Dune::Std::make_index_sequence<children>(), [&](
auto i) {
189 node.setChild( elementAt(subFactories_, i).node(TypeTree::push_back(tp, i)), i);
225 if (prefix.size() == 0)
228 return Hybrid::switchCases(std::make_index_sequence<children>(), prefix[0], [&] (
auto i) {
229 const auto& subFactory = std::get<i.value>(subFactories_);
230 typename std::decay<decltype(subFactory)>::type::SizePrefix subPrefix;
231 for(std::size_t i=1; i<prefix.size(); ++i)
232 subPrefix.push_back(prefix[i]);
233 return subFactory.size(subPrefix);
239 struct Lambda_size_flat_sizeInSubtree
241 template<
class I,
class SFT>
244 using SubFactory =
typename std::tuple_element<I::value, SFT>::type;
245 const SubFactory& subFactory = std::get<I::value>(subFactories);
246 if (shiftedFirst < subFactory.size())
248 typename SubFactory::SizePrefix subPrefix;
249 subPrefix.push_back(shiftedFirst);
250 for(std::size_t i=1; i<prefix.size(); ++i)
251 subPrefix.push_back(prefix[i]);
252 r = subFactory.size(subPrefix);
255 shiftedFirst -= subFactory.size();
263 using namespace Dune::Hybrid;
264 if (prefix.size() == 0)
265 forEach(Dune::Std::make_index_sequence<children>(), [&](
auto i) {
266 r += elementAt(subFactories_, i).size();
270 staticFindInRange<0,
sizeof...(SF)>(Lambda_size_flat_sizeInSubtree(), subFactories_, prefix, shiftedFirst, r);
282 using namespace Dune::Hybrid;
283 forEach(Dune::Std::make_index_sequence<children>(), [&](
auto i) {
284 r += elementAt(subFactories_, i).dimension();
294 using namespace Dune::Hybrid;
295 forEach(Dune::Std::make_index_sequence<children>(), [&](
auto i) {
296 r += elementAt(subFactories_, i).maxNodeSize();
307 template<
class MI,
class TP,
class IMS,
class... SF>
310 static const std::size_t children =
sizeof...(SF);
314 template<std::
size_t k>
315 using SubFactory =
typename std::tuple_element<k, std::tuple<SF...>>::type;
328 using SubTreePaths =
typename NodeFactory::template FixedTP<TP>::SubTreePaths;
329 using SubIndexSets =
typename NodeFactory::template FixedTP<TP>::SubIndexSets;
335 template<
class Factory,
class SubTP>
337 ->decltype(factory.template indexSet<SubTP>())
339 return factory.template indexSet<SubTP>();
344 nodeFactory_(&nodeFactory),
351 using namespace Dune::Hybrid;
352 forEach(Dune::Std::make_index_sequence<children>(), [&](
auto i) {
353 elementAt(subNodeIndexSetTuple_, i).bind(node.child(i));
360 using namespace Dune::Hybrid;
361 forEach(Dune::Std::make_index_sequence<children>(), [&](
auto i) {
362 elementAt(subNodeIndexSetTuple_, i).unbind();
368 return node_->size();
378 template<
class I,
class SNIT,
class SFT>
381 const auto& subNodeIndexSet = std::get<I::value>(subNodeIndexSetTuple);
383 if (localIndex < size)
385 multiIndex = subNodeIndexSet.index(localIndex);
386 multiIndex[0] += rootOffset;
390 rootOffset += std::get<I::value>(subFactories).size();
397 size_type shiftedLocalIndex = localIndex;
406 template<
class I,
class SNIT>
409 const auto& subNodeIndexSet = std::get<I::value>(subNodeIndexSetTuple);
411 if (localIndex < size)
413 multiIndex = subNodeIndexSet.index(localIndex);
424 size_type shiftedLocalIndex = localIndex;
428 mi.resize(mi.size()+1);
430 for(std::size_t i=mi.size()-1; i>0; --i)
444 namespace BasisBuilder {
454 template<
class ST0,
class... ST>
460 template<
class IndexTag,
class... SubFactoryTags>
463 static const bool isBlocked = std::is_same<IndexTag,BlockedLexicographic>::value or std::is_same<IndexTag,LeafBlockedInterleaved>::value;
465 static const std::size_t requiredMultiIndexSize=
maxHelper(SubFactoryTags::requiredMultiIndexSize...) + (std::size_t)(isBlocked);
467 template<
class MultiIndex,
class Gr
idView>
468 auto build(
const GridView& gridView)
469 ->
CompositeNodeFactory<MultiIndex, IndexTag, decltype(SubFactoryTags().
template build<MultiIndex, GridView>(gridView))...>
471 return {SubFactoryTags().template build<MultiIndex, GridView>(gridView)...};
475 template<
class... Args>
520 return Imp::compositeImp(std::tuple<BasisBuilder::BlockedLexicographic,Args...>{});
531 #endif // DUNE_FUNCTIONS_FUNCTIONSPACEBASES_COMPOSITEBASIS_HH Definition: compositebasis.hh:461
IntegerSequenceTuple< Imp::index_sequence_for< SF... > > ChildIndexTuple
Definition: compositebasis.hh:88
Definition: compositebasis.hh:332
A factory for composite bases.
Definition: compositebasis.hh:66
friend class CompositeNodeIndexSet
Definition: compositebasis.hh:86
const GridView & gridView() const
Obtain the grid view that the basis is defined on.
Definition: compositebasis.hh:159
std::tuple< SF... > SubFactories
Tuple of child factories.
Definition: compositebasis.hh:71
MultiIndex index(size_type localIndex) const
Definition: compositebasis.hh:371
MultiIndex index(const size_type &localIndex, BasisBuilder::BlockedLexicographic) const
Definition: compositebasis.hh:422
Node< TP > node(const TP &tp) const
Create tree node with given root tree path.
Definition: compositebasis.hh:184
ExpandTuple< SubNodesToNode, SubNodes > Node
Definition: compositebasis.hh:112
Lexicographic merging of direct children without blocking.
Definition: basistags.hh:61
typename SubFactory< 0 >::GridView GridView
Definition: compositebasis.hh:317
typename NodeFactory::template Node< TP > Node
Definition: compositebasis.hh:326
CompositeNodeFactory(SFArgs &&... sfArgs)
Constructor for given child factory objects.
Definition: compositebasis.hh:144
typename Imp::RotateHelper< std::tuple< T... >, std::make_index_sequence< sizeof...(T) -1 > >::type type
Definition: utility.hh:249
Get last entry of type list.
Definition: utility.hh:218
Definition: compositebasis.hh:404
size_type dimension() const
Get the total dimension of the space spanned by this basis.
Definition: compositebasis.hh:278
void update(const GridView &gv)
Update the stored grid view, to be called if the grid has changed.
Definition: compositebasis.hh:165
Lexicographic merging of direct children with blocking (i.e. creating one block per direct child)...
Definition: basistags.hh:95
auto compositeImp(std::tuple< Args... >) -> Imp::CompositeNodeFactoryBuilder< Args... >
Definition: compositebasis.hh:476
bool operator()(const I &i, SNIT &subNodeIndexSetTuple, const SFT &subFactories, size_type localIndex, size_type &rootOffset, MultiIndex &multiIndex)
Definition: compositebasis.hh:379
Dune::ReservedVector< size_type, MultiIndex::max_size()+1 > SizePrefix
Type used for prefixes handed to the size() method.
Definition: compositebasis.hh:134
void initializeIndices()
Initialize the global indices.
Definition: compositebasis.hh:150
Definition: polynomial.hh:7
typename std::enable_if< std::is_constructible< T, Args... >::value, int >::type enableIfConstructible
Helper to constrain forwarding constructors.
Definition: type_traits.hh:26
constexpr std::size_t maxHelper(ST0 &&i0, ST &&... i)
Definition: compositebasis.hh:455
MI MultiIndex
Type used for global numbering of the basis vectors.
Definition: compositebasis.hh:322
TransformTuple< IndexToSubTreePath, ChildIndexTuple > SubTreePaths
Definition: compositebasis.hh:97
MultiIndex index(const size_type &localIndex, BasisBuilder::FlatLexicographic) const
Definition: compositebasis.hh:395
bool operator()(const I &i, SNIT &subNodeIndexSetTuple, size_type &localIndex, size_type &component, MultiIndex &multiIndex)
Definition: compositebasis.hh:407
size_type size(const SizePrefix &prefix) const
Return number of possible values for next position in multi index.
Definition: compositebasis.hh:216
std::make_index_sequence< SizeOf< T... >{}> index_sequence_for
Definition: compositebasis.hh:35
MI MultiIndex
Type used for global numbering of the basis vectors.
Definition: compositebasis.hh:131
Definition: compositebasis.hh:30
std::size_t size_type
Type used for indices and size information.
Definition: compositebasis.hh:77
auto operator()(const Factory &factory, const SubTP &subTP) -> decltype(factory.template indexSet< SubTP >())
Definition: compositebasis.hh:336
static constexpr bool isIndexMergingStrategy()
Definition: basistags.hh:23
decltype(TypeTree::push_back(TP(), I())) IndexToSubTreePath
Definition: compositebasis.hh:95
auto transformTuple(F &&f, const std::tuple< T... > &tuple) -> decltype(Imp::transformTupleHelper(std::forward< F >(f), tuple, std::index_sequence_for< T... >
Transform tuple value using a functor.
Definition: utility.hh:162
TransformTuple< FactoryToSubNode, SubFactories, SubTreePaths > SubNodes
Definition: compositebasis.hh:102
auto composite(Args &&... args)
Create a factory builder that can build a CompositeNodeFactory.
Definition: compositebasis.hh:499
typename Imp::ExpandTupleHelper< T, ArgTuple >::Type ExpandTuple
Expand tuple arguments as template arguments.
Definition: utility.hh:91
IndexSet< TP > indexSet() const
Create tree node index set with given root tree path.
Definition: compositebasis.hh:204
typename Imp::IntegerSequenceTupleHelper< IntegerSequence >::Type IntegerSequenceTuple
Transform integer_sequence<I,k...> to tuple<integral_constant<I,k>...>
Definition: utility.hh:208
void staticFindInRange(F &&f, Args &&... args)
Static find loop.
Definition: staticforloop.hh:56
IMS IndexMergingStrategy
Strategy used to merge the global indices of the child factories.
Definition: compositebasis.hh:80
typename std::tuple_element< k, std::tuple< SF... > >::type SubFactory
Template mapping index of child to its factory type.
Definition: compositebasis.hh:120
Definition: compositebasis.hh:51
TransformTuple< FactoryToSubIndexSet, SubFactories, SubTreePaths > SubIndexSets
Definition: compositebasis.hh:107
std::size_t size_type
Definition: compositebasis.hh:318
IMS IndexMergingStrategy
Definition: compositebasis.hh:319
typename F::template IndexSet< SubTP > FactoryToSubIndexSet
Definition: compositebasis.hh:105
size_type maxNodeSize() const
Get the maximal number of DOFs associated to node for any element.
Definition: compositebasis.hh:290
typename F::template Node< SubTP > FactoryToSubNode
Definition: compositebasis.hh:100
size_type size() const
Definition: compositebasis.hh:366
std::tuple< SF... > subFactories_
Definition: compositebasis.hh:302
Definition: compositebasis.hh:376
void unbind()
Definition: compositebasis.hh:357
typename FixedTP< TP >::Node Node
Template mapping root tree path to type of created tree node.
Definition: compositebasis.hh:124
auto build(const GridView &gridView) -> CompositeNodeFactory< MultiIndex, IndexTag, decltype(SubFactoryTags().template build< MultiIndex, GridView >(gridView))... >
Definition: compositebasis.hh:468
typename std::tuple_element< k, std::tuple< SF... > >::type SubFactory
Definition: compositebasis.hh:315
CompositeNodeIndexSet(const NodeFactory &nodeFactory)
Definition: compositebasis.hh:343
typename NodeFactory::template FixedTP< TP >::SubTreePaths SubTreePaths
Definition: compositebasis.hh:328
typename std::tuple_element< 0, SubFactories >::type::GridView GridView
The grid view that the FE basis is defined on.
Definition: compositebasis.hh:74
size_type size() const
Same as size(prefix) with empty prefix.
Definition: compositebasis.hh:210
Definition: compositebasis.hh:91
void bind(const Node &node)
Definition: compositebasis.hh:348
typename Imp::TransformTupleHelper< F, Tuples... >::Type TransformTuple
Transform tuple types argument using type-functor.
Definition: utility.hh:128
typename NodeFactory::template FixedTP< TP >::SubIndexSets SubIndexSets
Definition: compositebasis.hh:329