DUNE PDELab (git)

traversalutilities.hh
1// -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
2// vi: set et ts=4 sw=2 sts=2:
3// SPDX-FileCopyrightInfo: Copyright © DUNE Project contributors, see file LICENSE.md in module root
4// SPDX-License-Identifier: LGPL-3.0-or-later OR LicenseRef-GPL-2.0-only-with-PDELab-exception
5
6#ifndef DUNE_TYPETREE_TRAVERSALUTILITIES_HH
7#define DUNE_TYPETREE_TRAVERSALUTILITIES_HH
8
9#include <dune/typetree/traversal.hh>
10
11namespace Dune {
12 namespace TypeTree {
13
19 namespace {
20
22
27 template<typename F, typename R, typename ResultType>
28 struct LeafReductionVisitor
29 : public TypeTree::TreeVisitor
30 {
31
32 static const TreePathType::Type treePathType = TreePathType::dynamic;
33
34 template<typename Node, typename TreePath>
35 void leaf(const Node& node, TreePath treePath)
36 {
37 _value = _reduction(_value,_functor(node,treePath));
38 }
39
40 LeafReductionVisitor(F functor, R reduction, ResultType startValue)
41 : _functor(functor)
42 , _reduction(reduction)
43 , _value(startValue)
44 {}
45
46 ResultType result() { return _value; }
47
48 F _functor;
49 R _reduction;
50 ResultType _value;
51
52 };
53
54 } // anonymous namespace
55
57
82 template<typename ResultType, typename Tree, typename F, typename R>
83 ResultType reduceOverLeafs(const Tree& tree, F functor, R reduction, ResultType startValue)
84 {
85 LeafReductionVisitor<F,R,ResultType> visitor(functor,reduction,startValue);
86 TypeTree::applyToTree(tree,visitor);
87 return visitor.result();
88 }
89
91
92 } // namespace TypeTree
93} //namespace Dune
94
95#endif // DUNE_TYPETREE_TRAVERSALUTILITIES_HH
constexpr auto treePath(const T &... t)
Constructs a new HybridTreePath from the given indices.
Definition: treepath.hh:326
ResultType reduceOverLeafs(const Tree &tree, F functor, R reduction, ResultType startValue)
Calculate a quantity as a reduction over the leaf nodes of a TypeTree.
Definition: traversalutilities.hh:83
void applyToTree(Tree &&tree, Visitor &&visitor)
Apply visitor to TypeTree.
Definition: traversal.hh:239
Dune namespace.
Definition: alignedallocator.hh:13
Creative Commons License   |  Legal Statements / Impressum  |  Hosted by TU Dresden  |  generated with Hugo v0.111.3 (Nov 12, 23:30, 2024)