3 #include <dune/common/rangeutilities.hh> 5 #include <dune/typetree/nodetags.hh> 6 #include <dune/typetree/treepath.hh> 8 #include <amdis/common/ForEach.hpp> 9 #include <amdis/common/TypeTraits.hpp> 27 template <
bool dynamic = true,
class Tree>
28 auto traversalDegree(
Tree const& tree)
30 if constexpr (dynamic && Tree::isPower)
31 return std::size_t(tree.degree());
32 else if constexpr (Tree::isPower || Tree::isComposite)
33 return std::integral_constant<std::size_t, Tree::degree()>{};
47 template <
class Tree,
class TreePath,
class PreFunc,
class LeafFunc,
class PostFunc>
48 void for_each_node(
Tree&& tree, TreePath treePath, PreFunc&& preFunc, LeafFunc&& leafFunc, PostFunc&& postFunc)
50 using TreeType = std::decay_t<Tree>;
51 if constexpr (TreeType::isLeaf) {
53 leafFunc(tree, treePath);
58 preFunc(tree, treePath);
59 Dune::Hybrid::forEach(Dune::range(traversalDegree(tree)), [&](
auto i) {
60 auto childTreePath = push_back(treePath, i);
61 Impl::for_each_node(tree.child(i), childTreePath, preFunc, leafFunc, postFunc);
63 postFunc(tree, treePath);
80 template <
class Tree,
class PreFunc,
class LeafFunc,
class PostFunc>
81 void for_each_node(
Tree&& tree, PreFunc&& preFunc, LeafFunc&& leafFunc, PostFunc&& postFunc)
83 auto root = Dune::TypeTree::hybridTreePath();
84 Impl::for_each_node(tree, root, preFunc, leafFunc, postFunc);
96 template <
class Tree,
class InnerFunc,
class LeafFunc>
99 auto root = Dune::TypeTree::hybridTreePath();
100 Impl::for_each_node(tree, root, innerFunc, leafFunc,
NoOp{});
111 template <
class Tree,
class NodeFunc>
114 auto root = Dune::TypeTree::hybridTreePath();
115 Impl::for_each_node(tree, root, nodeFunc, nodeFunc,
NoOp{});
126 template <
class Tree,
class LeafFunc>
129 auto root = Dune::TypeTree::hybridTreePath();
130 Impl::for_each_node(tree, root,
NoOp{}, leafFunc,
NoOp{});
void for_each_leaf_node(Tree &&tree, LeafFunc &&leafFunc)
Traverse tree and visit each leaf node.
Definition: Traversal.hpp:127
A functor with no operation.
Definition: TypeTraits.hpp:99
Contains all classes needed for solving linear and non linear equation systems.
Definition: AdaptBase.hpp:6
void for_each_node(Tree &&tree, PreFunc &&preFunc, LeafFunc &&leafFunc, PostFunc &&postFunc)
Traverse tree and visit each node.
Definition: Traversal.hpp:81