7#ifndef DUNE_FUNCTIONS_FUNCTIONSPACEBASES_NODES_HH
8#define DUNE_FUNCTIONS_FUNCTIONSPACEBASES_NODES_HH
13#include <dune/common/indices.hh>
15#include <dune/typetree/leafnode.hh>
16#include <dune/typetree/powernode.hh>
17#include <dune/typetree/dynamicpowernode.hh>
18#include <dune/typetree/compositenode.hh>
19#include <dune/typetree/traversal.hh>
20#include <dune/typetree/visitor.hh>
29 struct ClearSizeVisitor
30 :
public TypeTree::TreeVisitor
31 ,
public TypeTree::DynamicTraversal
34 template<
typename Node,
typename TreePath>
41 template<
typename Node,
typename TreePath>
44 node.setOffset(offset_);
47 ClearSizeVisitor(std::size_t offset)
51 const std::size_t offset_;
56 template<
typename Entity>
58 :
public TypeTree::TreeVisitor
59 ,
public TypeTree::DynamicTraversal
62 template<
typename Node,
typename TreePath>
63 void pre(Node& node, TreePath)
65 node.setOffset(offset_);
68 template<
typename Node,
typename TreePath>
69 void post(Node& node, TreePath)
71 node.setSize(offset_ - node.offset());
74 template<
typename Node,
typename TreePath>
75 void leaf(Node& node, TreePath)
77 node.setOffset(offset_);
79 offset_ += node.size();
82 BindVisitor(
const Entity& entity, std::size_t offset = 0)
87 const Entity& entity_;
93 struct InitializeTreeVisitor :
94 public TypeTree::TreeVisitor,
95 public TypeTree::DynamicTraversal
97 template<
typename Node,
typename TreePath>
98 void pre(Node& node, TreePath)
100 node.setTreeIndex(treeIndex_);
104 template<
typename Node,
typename TreePath>
105 void leaf(Node& node, TreePath)
107 node.setTreeIndex(treeIndex_);
111 InitializeTreeVisitor(std::size_t treeIndexOffset = 0) :
112 treeIndex_(treeIndexOffset)
115 std::size_t treeIndex_;
124 friend struct Impl::ClearSizeVisitor;
127 friend struct Impl::BindVisitor;
129 friend struct Impl::InitializeTreeVisitor;
133 using size_type = std::size_t;
141 size_type localIndex(size_type i)
const
147 size_type
size()
const
152 size_type treeIndex()
const
159 size_type offset()
const
164 void setOffset(
const size_type offset)
169 void setSize(
const size_type
size)
174 void setTreeIndex(size_type treeIndex)
176 treeIndex_ = treeIndex;
183 size_type treeIndex_;
188 class LeafBasisNode :
189 public BasisNodeMixin,
190 public TypeTree::LeafNode
194 template<
typename T, std::
size_t n>
195 class PowerBasisNode :
196 public BasisNodeMixin,
197 public TypeTree::PowerNode<T,n>
200 using Node = TypeTree::PowerNode<T,n>;
204 using Element =
typename T::Element;
206 PowerBasisNode() =
default;
212 const Element& element()
const
221 class DynamicPowerBasisNode :
222 public BasisNodeMixin,
223 public TypeTree::DynamicPowerNode<T>
226 using Node = TypeTree::DynamicPowerNode<T>;
230 using Element =
typename T::Element;
232 DynamicPowerBasisNode (std::size_t children)
237 : Node(
std::move(children))
240 const Element& element()
const
242 return this->
child(0).element();
248 template<
typename... T>
249 class CompositeBasisNode :
250 public BasisNodeMixin,
251 public TypeTree::CompositeNode<T...>
254 using Node = TypeTree::CompositeNode<T...>;
258 using Element =
typename Node::template Child<0>::Type::Element;
260 CompositeBasisNode() =
default;
266 template<
typename... Children>
267 CompositeBasisNode(
const std::shared_ptr<Children>&... children) :
271 const Element& element()
const
279 template<
typename Tree>
280 void clearSize(Tree& tree, std::size_t offset)
285 template<
typename Tree,
typename Entity>
286 void bindTree(Tree& tree,
const Entity& entity, std::size_t offset = 0)
288 Impl::BindVisitor<Entity> visitor(entity,offset);
292 template<
typename Tree>
293 void initializeTree(Tree& tree, std::size_t treeIndexOffset = 0)
295 Impl::InitializeTreeVisitor visitor(treeIndexOffset);
std::tuple< std::shared_ptr< Children >... > NodeStorage
The type used for storing the children.
Definition: compositenode.hh:36
std::vector< ChildStorageType > NodeStorage
The type used for storing the children.
Definition: dynamicpowernode.hh:67
std::array< std::shared_ptr< T >, k > NodeStorage
The type used for storing the children.
Definition: powernode.hh:77
constexpr index_constant< 0 > _0
Compile time index with value 0.
Definition: indices.hh:52
constexpr auto treePath(const T &... t)
Constructs a new HybridTreePath from the given indices.
Definition: treepath.hh:326
void applyToTree(Tree &&tree, Visitor &&visitor)
Apply visitor to TypeTree.
Definition: traversal.hh:239
Dune namespace.
Definition: alignedallocator.hh:13
constexpr std::integral_constant< std::size_t, sizeof...(II)> size(std::integer_sequence< T, II... >)
Return the size of the sequence.
Definition: integersequence.hh:75
void post(T &&, TreePath) const
Method for postfix tree traversal.
Definition: visitor.hh:83
void leaf(T &&, TreePath) const
Method for leaf traversal.
Definition: visitor.hh:93
void pre(T &&, TreePath) const
Method for prefix tree traversal.
Definition: visitor.hh:60