DUNE-FUNCTIONS (unstable)

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
4// SPDX-FileCopyrightText: Copyright © DUNE Project contributors, see file AUTHORS.md
5// SPDX-License-Identifier: LicenseRef-GPL-2.0-only-with-DUNE-exception OR LGPL-3.0-or-later
6
7#ifndef DUNE_FUNCTIONS_FUNCTIONSPACEBASES_DEFAULTNODETORANGEMAP_HH
8#define DUNE_FUNCTIONS_FUNCTIONSPACEBASES_DEFAULTNODETORANGEMAP_HH
9
10#warning The header dune/functions/common/defaultnodetorangemap.hh is deprecated and will be removed after release 2.10.
11
12#include <dune/common/concept.hh>
13
14#include <dune/functions/functionspacebases/concepts.hh>
15
16#include <dune/typetree/traversal.hh>
17#include <dune/typetree/visitor.hh>
18
19
20namespace Dune {
21namespace Functions {
22
23
24
44template<class Tree>
45struct
46[[deprecated("DefaultNodeToRangeMap is deprecated and will be removed after release 2.10.")]]
48{
49
50 // A simple visitor for computing lexicographic
51 // subtree indices. To identify a leaf node
52 // we use its treeIndex() which is unique
53 // wrt the whole tree and store the computed
54 // index in a vector indexed by the tree indices.
55 struct Visitor
56 : public TypeTree::TreeVisitor
57 , public TypeTree::DynamicTraversal
58 {
59 Visitor(std::vector<std::size_t>& indices) :
60 indices_(indices),
61 counter_(0)
62 {}
63
64 template<typename Node, typename TreePath>
65 void leaf(Node& node, TreePath treePath)
66 {
67 if (indices_.size() < node.treeIndex()+1)
68 indices_.resize(node.treeIndex()+1);
69 indices_[node.treeIndex()] = counter_;
70 ++counter_;
71 }
72
73 std::vector<std::size_t>& indices_;
74 std::size_t counter_;
75 };
76
87 DefaultNodeToRangeMap(const Tree& tree)
88 {
89 TypeTree::applyToTree(tree, Visitor(indices_));
90 }
91
92 template<class Node, class TreePath, class Range,
93 std::enable_if_t<models<Concept::HasIndexAccess, Range, decltype(std::declval<Node>().treeIndex())>() and not Tree::isLeaf, int> = 0>
94 decltype(auto) operator()(const Node& node, const TreePath& treePath, Range&& y) const
95 {
96 return y[indices_[node.treeIndex()]];
97 }
98
99 template<class Node, class TreePath, class Range,
100 std::enable_if_t< not models<Concept::HasIndexAccess, Range, decltype(std::declval<Node>().treeIndex())>() or Tree::isLeaf, int> = 0>
101 decltype(auto) operator()(const Node& node, const TreePath& treePath, Range&& y) const
102 {
103 return std::forward<Range>(y);
104 }
105
106 std::vector<std::size_t> indices_;
107};
108
109
110
111template<class Tree>
112DefaultNodeToRangeMap<Tree> makeDefaultNodeToRangeMap(const Tree& tree)
113{
114 return DefaultNodeToRangeMap<Tree>(tree);
115}
116
117
118
119template<class Basis, class TreePath>
120auto makeDefaultNodeToRangeMap(const Basis& basis, TreePath&& treePath)
121 -> decltype(makeDefaultNodeToRangeMap(TypeTree::child(basis.localView().tree(),treePath)))
122{
123 auto&& localView = basis.localView();
124 localView.bind(*basis.gridView().template begin<0>());
125 auto&& tree = TypeTree::child(localView.tree(),treePath);
126 return makeDefaultNodeToRangeMap(tree);
127}
128
129
130
131} // namespace Dune::Functions
132} // namespace Dune
133
134
135#endif // DUNE_FUNCTIONS_FUNCTIONSPACEBASES_DEFAULTNODETORANGEMAP_HH
Definition: polynomial.hh:17
A simple node to range map using lexicographic ordering.
Definition: defaultnodetorangemap.hh:48
DefaultNodeToRangeMap(const Tree &tree)
Construct DefaultNodeToRangeMap.
Definition: defaultnodetorangemap.hh:87
Creative Commons License   |  Legal Statements / Impressum  |  Hosted by TU Dresden  |  generated with Hugo v0.111.3 (Aug 14, 22:29, 2024)