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
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
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
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
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:48
DefaultNodeToRangeMap(const Tree &tree)
Construct DefaultNodeToRangeMap.
Definition: defaultnodetorangemap.hh:87
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 (Nov 12, 23:30, 2024)