3#ifndef DUNE_FUNCTIONS_FUNCTIONSPACEBASES_NODES_HH
4#define DUNE_FUNCTIONS_FUNCTIONSPACEBASES_NODES_HH
9#include <dune/common/indices.hh>
11#include <dune/typetree/leafnode.hh>
12#include <dune/typetree/powernode.hh>
13#include <dune/typetree/compositenode.hh>
14#include <dune/typetree/traversal.hh>
15#include <dune/typetree/visitor.hh>
24 struct ClearSizeVisitor
25 :
public TypeTree::TreeVisitor
26 ,
public TypeTree::DynamicTraversal
29 template<
typename Node,
typename TreePath>
36 template<
typename Node,
typename TreePath>
39 node.setOffset(offset_);
42 ClearSizeVisitor(std::size_t offset)
46 const std::size_t offset_;
51 template<
typename Entity>
53 :
public TypeTree::TreeVisitor
54 ,
public TypeTree::DynamicTraversal
57 template<
typename Node,
typename TreePath>
58 void pre(Node& node, TreePath)
60 node.setOffset(offset_);
63 template<
typename Node,
typename TreePath>
64 void post(Node& node, TreePath)
66 node.setSize(offset_ - node.offset());
69 template<
typename Node,
typename TreePath>
70 void leaf(Node& node, TreePath)
72 node.setOffset(offset_);
74 offset_ += node.size();
77 BindVisitor(
const Entity& entity, std::size_t offset = 0)
82 const Entity& entity_;
88 struct InitializeTreeVisitor :
89 public TypeTree::TreeVisitor,
90 public TypeTree::DynamicTraversal
92 template<
typename Node,
typename TreePath>
93 void pre(Node& node, TreePath)
95 node.setTreeIndex(treeIndex_);
99 template<
typename Node,
typename TreePath>
100 void leaf(Node& node, TreePath)
102 node.setTreeIndex(treeIndex_);
106 InitializeTreeVisitor(std::size_t treeIndexOffset = 0) :
107 treeIndex_(treeIndexOffset)
110 std::size_t treeIndex_;
119 friend struct Impl::ClearSizeVisitor;
122 friend struct Impl::BindVisitor;
124 friend struct Impl::InitializeTreeVisitor;
128 using size_type = std::size_t;
136 size_type localIndex(size_type i)
const
142 size_type size()
const
147 size_type treeIndex()
const
154 size_type offset()
const
159 void setOffset(
const size_type offset)
164 void setSize(
const size_type size)
169 void setTreeIndex(size_type treeIndex)
171 treeIndex_ = treeIndex;
178 size_type treeIndex_;
183 class LeafBasisNode :
184 public BasisNodeMixin,
185 public TypeTree::LeafNode
189 template<
typename T, std::
size_t n>
190 class PowerBasisNode :
191 public BasisNodeMixin,
192 public TypeTree::PowerNode<T,n>
195 using Node = TypeTree::PowerNode<T,n>;
199 using Element =
typename T::Element;
201 PowerBasisNode() =
default;
207 const Element& element()
const
215 template<
typename... T>
216 class CompositeBasisNode :
217 public BasisNodeMixin,
218 public TypeTree::CompositeNode<T...>
221 using Node = TypeTree::CompositeNode<T...>;
225 using Element =
typename Node::template Child<0>::Type::Element;
227 CompositeBasisNode() =
default;
233 template<
typename... Children>
234 CompositeBasisNode(
const std::shared_ptr<Children>&... children) :
238 const Element& element()
const
246 template<
typename Tree>
247 void clearSize(Tree& tree, std::size_t offset)
252 template<
typename Tree,
typename Entity>
253 void bindTree(Tree& tree,
const Entity& entity, std::size_t offset = 0)
255 Impl::BindVisitor<Entity> visitor(entity,offset);
259 template<
typename Tree>
260 void initializeTree(Tree& tree, std::size_t treeIndexOffset = 0)
262 Impl::InitializeTreeVisitor visitor(treeIndexOffset);
std::tuple< std::shared_ptr< Children >... > NodeStorage
The type used for storing the children.
Definition: compositenode.hh:34
std::array< std::shared_ptr< T >, k > NodeStorage
The type used for storing the children.
Definition: powernode.hh:79
constexpr index_constant< 0 > _0
Compile time index with value 0.
Definition: indices.hh:53
constexpr HybridTreePath< T... > treePath(const T &... t)
Constructs a new HybridTreePath from the given indices.
Definition: treepath.hh:191
void applyToTree(Tree &&tree, Visitor &&visitor)
Apply visitor to TypeTree.
Definition: traversal.hh:237
Dune namespace.
Definition: alignedallocator.hh:13
void post(T &&, TreePath) const
Method for postfix tree traversal.
Definition: visitor.hh:81
void leaf(T &&, TreePath) const
Method for leaf traversal.
Definition: visitor.hh:91
void pre(T &&, TreePath) const
Method for prefix tree traversal.
Definition: visitor.hh:58