7#ifndef DUNE_FUNCTIONS_FUNCTIONSPACEBASES_NODES_HH
8#define DUNE_FUNCTIONS_FUNCTIONSPACEBASES_NODES_HH
16#include <dune/common/indices.hh>
17#include <dune/common/tuplevector.hh>
18#include <dune/common/typelist.hh>
20#include <dune/common/hybridmultiindex.hh>
21#include <dune/common/typetree/traversal.hh>
23#ifdef HAVE_DUNE_TYPETREE
24#include <dune/typetree/nodetags.hh>
37 struct BasisNodeSetupHelper
40 template<
class Node,
class size_type>
41 static void setSize(Node& node,
const size_type size)
46 template<
class Node,
class size_type>
47 static void setOffset(Node& node,
const size_type offset)
49 node.setOffset(offset);
52 template<
class Node,
class size_type>
53 static void setTreeIndex(Node& node,
const size_type index)
55 node.setTreeIndex(index);
67 class ChildAccessMixIn
72 return static_cast<Impl&
>(*this);
75 const Impl& asImpl()
const
77 return static_cast<const Impl&
>(*this);
88 const auto& child(II... ii)
const
89 requires (
sizeof...(II) != 1)
91 return Dune::TypeTree::child(asImpl(), ii...);
100 template<
class... II>
101 auto& child(II... ii)
102 requires (
sizeof...(II) != 1)
104 return Dune::TypeTree::child(asImpl(), ii...);
112 template<
class... II>
113 const auto& child(Dune::HybridMultiIndex<II...> treePath)
const
115 return Dune::TypeTree::child(asImpl(), treePath);
123 template<
class... II>
124 auto& child(Dune::HybridMultiIndex<II...> treePath)
126 return Dune::TypeTree::child(asImpl(), treePath);
137 friend struct Impl::BasisNodeSetupHelper;
225 return Dune::index_constant<0>{};
230 static const bool isLeaf [[deprecated]] =
true;
231 static const bool isPower [[deprecated]] =
false;
233#ifdef HAVE_DUNE_TYPETREE
234 using NodeTag [[deprecated]] = Dune::TypeTree::LeafNodeTag;
243 template<
typename Node,
typename Element>
249 void bind(
const Element& entity)
251 Node& self = *
static_cast<Node*
>(
this);
253 Dune::Hybrid::forEach(Dune::range(self.degree()), [&](
auto i) {
254 bindTree(self.child(i), entity, offset);
255 offset += self.child(i).size();
264 template<
typename T, std::
size_t n>
267 public Impl::ChildAccessMixIn<PowerBasisNode<T, n>>
275 return Dune::index_constant<n>{};
278 template<
class Index>
279 requires (std::is_convertible_v<Index, std::size_t>)
282 return children_[i].value();
285 template<
class Index>
286 requires (std::is_convertible_v<Index, std::size_t>)
289 return children_[i].value();
296 using ChildType [[deprecated]] = T;
298 static const bool isLeaf [[deprecated]] =
false;
299 static const bool isPower [[deprecated]] =
true;
301#ifdef HAVE_DUNE_TYPETREE
302 using NodeTag [[deprecated]] = Dune::TypeTree::PowerNodeTag;
313 return child(Dune::Indices::_0).element();
316 template<
class Index,
class TT>
319 children_[i].emplace(std::forward<TT>(t));
323 std::array<std::optional<T>, n> children_;
331 public Impl::ChildAccessMixIn<DynamicPowerBasisNode<T>>
339 return children_.size();
342 template<
class Index>
343 requires (std::is_convertible_v<Index, std::size_t>)
346 return children_[i].value();
349 template<
class Index>
350 requires (std::is_convertible_v<Index, std::size_t>)
353 return children_[i].value();
360 using ChildType [[deprecated]] = T;
362 static const bool isLeaf [[deprecated]] =
false;
363 static const bool isPower [[deprecated]] =
true;
365#ifdef HAVE_DUNE_TYPETREE
366 using NodeTag [[deprecated]] = Dune::TypeTree::DynamicPowerNodeTag;
374 : children_(children)
379 return child(Dune::Indices::_0).element();
382 template<
class Index,
class TT>
385 children_[i].emplace(std::forward<TT>(t));
389 std::vector<std::optional<T>> children_;
393 template<
typename... T>
395 public InnerBasisNodeMixin<CompositeBasisNode<T...>, typename TypeListEntry_t<0, TypeList<T...>>::Element>,
396 public Impl::ChildAccessMixIn<CompositeBasisNode<T...>>
404 return Dune::index_constant<
sizeof...(T)>{};
407 template<std::
size_t i>
408 const auto&
child(Dune::index_constant<i> ii)
const
410 return children_[ii].value();
413 template<std::
size_t i>
414 auto&
child(Dune::index_constant<i> ii)
416 return children_[ii].value();
423 using ChildTypes [[deprecated]] = std::tuple<T...>;
425 static const bool isLeaf [[deprecated]] =
false;
426 static const bool isPower [[deprecated]] =
false;
428#ifdef HAVE_DUNE_TYPETREE
429 using NodeTag [[deprecated]] = Dune::TypeTree::CompositeNodeTag;
432 template<std::
size_t k>
434 static_assert((k <
degree()),
"child index out of range");
437 using Type =
typename std::tuple_element_t<k, std::tuple<T...>>;
449 children_(children...)
454 return child(Dune::Indices::_0).element();
457 template<std::
size_t i,
class TT>
458 void setChild (TT&& t, Dune::index_constant<i> ii = {})
460 children_[ii].emplace(std::forward<TT>(t));
464 Dune::TupleVector<std::optional<T>...> children_;
468 template<
typename Tree,
typename Entity>
469 void bindTree(Tree& tree,
const Entity& entity, std::size_t offset = 0)
471 Impl::BasisNodeSetupHelper::setOffset(tree, offset);
475 template<
typename Tree>
478 Dune::TypeTree::forEachNode(tree, [&](
auto& node,
const auto& treePath) {
479 Impl::BasisNodeSetupHelper::setTreeIndex(node, treeIndexOffset);
Definition monomialset.hh:19
Definition monomialset.hh:19
void bindTree(Tree &tree, const Entity &entity, std::size_t offset=0)
Definition nodes.hh:469
void initializeTree(Tree &tree, std::size_t treeIndexOffset=0)
Definition nodes.hh:476
size_type treeIndex() const
Definition nodes.hh:180
size_type localIndex(size_type i) const
Definition nodes.hh:149
size_type offset() const
Definition nodes.hh:187
bool empty() const
Check if the node is empty.
Definition nodes.hh:175
size_type size() const
Obtain the number of basis function in the local node.
Definition nodes.hh:162
void setOffset(const size_type offset)
Definition nodes.hh:192
std::size_t size_type
Definition nodes.hh:141
BasisNodeMixin()
Definition nodes.hh:143
void setSize(const size_type size)
Definition nodes.hh:197
void setTreeIndex(size_type treeIndex)
Definition nodes.hh:202
static const bool isLeaf
Definition nodes.hh:230
static const bool isComposite
Definition nodes.hh:232
static const bool isPower
Definition nodes.hh:231
static constexpr auto degree()
Definition nodes.hh:223
void bind(const Element &entity)
Definition nodes.hh:249
auto & child(Index i)
Definition nodes.hh:287
static const bool isLeaf
Definition nodes.hh:298
const Element & element() const
Definition nodes.hh:311
typename T::Element Element
Definition nodes.hh:307
const auto & child(Index i) const
Definition nodes.hh:280
static constexpr auto degree()
Definition nodes.hh:273
static const bool isPower
Definition nodes.hh:299
static const bool isComposite
Definition nodes.hh:300
void setChild(Index i, TT &&t)
Definition nodes.hh:317
const Element & element() const
Definition nodes.hh:377
static const bool isLeaf
Definition nodes.hh:362
void setChild(Index i, TT &&t)
Definition nodes.hh:383
const auto & child(Index i) const
Definition nodes.hh:344
static const bool isPower
Definition nodes.hh:363
DynamicPowerBasisNode(std::size_t children)
Definition nodes.hh:373
auto & child(Index i)
Definition nodes.hh:351
static const bool isComposite
Definition nodes.hh:364
std::size_t degree() const
Definition nodes.hh:337
typename typename SubPreBasis::Node::Element Element
Definition nodes.hh:371
CompositeBasisNode()=default
static constexpr auto degree()
Definition nodes.hh:402
static const bool isLeaf
Definition nodes.hh:425
auto & child(Dune::index_constant< i > ii)
Definition nodes.hh:414
static const bool isPower
Definition nodes.hh:426
typename std::tuple_element_t< 0, std::tuple< T... > >::Element Element
Definition nodes.hh:444
const Element & element() const
Definition nodes.hh:452
const auto & child(Dune::index_constant< i > ii) const
Definition nodes.hh:408
static const bool isComposite
Definition nodes.hh:427
void setChild(TT &&t, Dune::index_constant< i > ii={})
Definition nodes.hh:458
CompositeBasisNode(const T &... children)
Definition nodes.hh:448
typename std::tuple_element_t< k, std::tuple< T... > > Type
The type of the child.
Definition nodes.hh:437
Type type
Definition nodes.hh:439