DUNE PDELab (git)

defaultnodetorangemap.hh
1// -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
2// vi: set et ts=4 sw=2 sts=2:
3#ifndef DUNE_FUNCTIONS_FUNCTIONSPACEBASES_DEFAULTNODETORANGEMAP_HH
4#define DUNE_FUNCTIONS_FUNCTIONSPACEBASES_DEFAULTNODETORANGEMAP_HH
5
6#warning The header dune/functions/common/defaultnodetorangemap.hh is deprecated and will be removed after release 2.10.
7
9
10#include <dune/functions/functionspacebases/concepts.hh>
11
12#include <dune/typetree/traversal.hh>
13#include <dune/typetree/visitor.hh>
14
15
16namespace Dune {
17namespace Functions {
18
19
20
40template<class Tree>
41struct
42[[deprecated("DefaultNodeToRangeMap is deprecated and will be removed after release 2.10.")]]
44{
45
46 // A simple visitor for computing lexicographic
47 // subtree indices. To identify a leaf node
48 // we use its treeIndex() which is unique
49 // wrt the whole tree and store the computed
50 // index in a vector indexed by the tree indices.
51 struct Visitor
54 {
55 Visitor(std::vector<std::size_t>& indices) :
56 indices_(indices),
57 counter_(0)
58 {}
59
60 template<typename Node, typename TreePath>
61 void leaf(Node& node, TreePath treePath)
62 {
63 if (indices_.size() < node.treeIndex()+1)
64 indices_.resize(node.treeIndex()+1);
65 indices_[node.treeIndex()] = counter_;
66 ++counter_;
67 }
68
69 std::vector<std::size_t>& indices_;
70 std::size_t counter_;
71 };
72
83 DefaultNodeToRangeMap(const Tree& tree)
84 {
85 TypeTree::applyToTree(tree, Visitor(indices_));
86 }
87
88 template<class Node, class TreePath, class Range,
89 std::enable_if_t<models<Concept::HasIndexAccess, Range, decltype(std::declval<Node>().treeIndex())>() and not Tree::isLeaf, int> = 0>
90 decltype(auto) operator()(const Node& node, const TreePath& treePath, Range&& y) const
91 {
92 return y[indices_[node.treeIndex()]];
93 }
94
95 template<class Node, class TreePath, class Range,
96 std::enable_if_t< not models<Concept::HasIndexAccess, Range, decltype(std::declval<Node>().treeIndex())>() or Tree::isLeaf, int> = 0>
97 decltype(auto) operator()(const Node& node, const TreePath& treePath, Range&& y) const
98 {
99 return std::forward<Range>(y);
100 }
101
102 std::vector<std::size_t> indices_;
103};
104
105
106
107template<class Tree>
108DefaultNodeToRangeMap<Tree> makeDefaultNodeToRangeMap(const Tree& tree)
109{
110 return DefaultNodeToRangeMap<Tree>(tree);
111}
112
113
114
115template<class Basis, class TreePath>
116auto makeDefaultNodeToRangeMap(const Basis& basis, TreePath&& treePath)
117 -> decltype(makeDefaultNodeToRangeMap(TypeTree::child(basis.localView().tree(),treePath)))
118{
119 auto&& localView = basis.localView();
120 localView.bind(*basis.gridView().template begin<0>());
121 auto&& tree = TypeTree::child(localView.tree(),treePath);
122 return makeDefaultNodeToRangeMap(tree);
123}
124
125
126
127} // namespace Dune::Functions
128} // namespace Dune
129
130
131#endif // DUNE_FUNCTIONS_FUNCTIONSPACEBASES_DEFAULTNODETORANGEMAP_HH
Infrastructure for concepts.
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
ImplementationDefined child(Node &&node, Indices... indices)
Extracts the child of a node given by a sequence of compile-time and run-time indices.
Definition: childextraction.hh:128
Dune namespace.
Definition: alignedallocator.hh:13
A simple node to range map using lexicographic ordering.
Definition: defaultnodetorangemap.hh:44
DefaultNodeToRangeMap(const Tree &tree)
Construct DefaultNodeToRangeMap.
Definition: defaultnodetorangemap.hh:83
Mixin base class for visitors that only need a dynamic TreePath during traversal.
Definition: visitor.hh:426
Convenience base class for visiting the entire tree.
Definition: visitor.hh:435
Creative Commons License   |  Legal Statements / Impressum  |  Hosted by TU Dresden  |  generated with Hugo v0.111.3 (Jul 15, 22:36, 2024)