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>
35 void pre(Node& node, TreePath treePath)
41 template<
typename Node,
typename TreePath>
42 void leaf(Node& node, TreePath 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;
208 PowerBasisNode(
const typename Node::NodeStorage& children) :
212 const Element& element()
const
214 return this->child(Dune::Indices::_0).element();
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)
236 DynamicPowerBasisNode (
typename Node::NodeStorage 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;
262 CompositeBasisNode(
const typename Node::NodeStorage& children) :
266 template<
typename... Children>
267 CompositeBasisNode(
const std::shared_ptr<Children>&... children) :
271 const Element& element()
const
273 return this->child(Dune::Indices::_0).element();
279 template<
typename Tree>
280 void clearSize(Tree& tree, std::size_t offset)
282 TypeTree::applyToTree(tree,Impl::ClearSizeVisitor(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);
289 TypeTree::applyToTree(tree,visitor);
292 template<
typename Tree>
293 void initializeTree(Tree& tree, std::size_t treeIndexOffset = 0)
295 Impl::InitializeTreeVisitor visitor(treeIndexOffset);
296 TypeTree::applyToTree(tree,visitor);
Definition: polynomial.hh:17