DUNE PDELab (git)

subordering.hh
1// -*- tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*-
2// vi: set et ts=8 sw=2 sts=2:
3
4#ifndef DUNE_PDELAB_ORDERING_SUBORDERING_HH
5#define DUNE_PDELAB_ORDERING_SUBORDERING_HH
6
7#include <algorithm>
8#include <array>
9#include <iterator>
10#include <memory>
11
12#include <dune/typetree/treepath.hh>
13#include <dune/typetree/proxynode.hh>
14#include <dune/typetree/childextraction.hh>
15
16#include <dune/pdelab/ordering/utility.hh>
17
18namespace Dune {
19 namespace PDELab {
20
23
25
47 template<typename BaseOrdering_, typename TreePath>
49 : public TypeTree::ProxyNode<const TypeTree::ChildForTreePath<BaseOrdering_,TreePath>>
50 {
51
53
54 public:
55
57 typedef BaseOrdering_ BaseOrdering;
58
61
63 typedef typename BaseOrdering::Traits Traits;
64
66 typedef typename BaseOrdering::ContainerAllocationTag ContainerAllocationTag;
67
69 typedef typename BaseOrdering::CacheTag CacheTag;
70
72 static const bool has_dynamic_ordering_children = TargetOrdering::has_dynamic_ordering_children;
73
75 static const bool consume_tree_index = TargetOrdering::consume_tree_index;
76
77
79
92 explicit SubOrdering(std::shared_ptr<const BaseOrdering> base_ordering)
93 : NodeT(base_ordering->child(TreePath()))
94 , _base_ordering(base_ordering)
95 {
96 update();
97 }
98
100 void update()
101 {}
102
103
104 template<typename ItIn, typename ItOut>
105 void map_lfs_indices(ItIn begin, const ItIn end, ItOut out) const
106 {
107 // Do the mapping up to the root ordering.
108 // Avoid spelling out the type of ItIn here (it has to be a DOFIndexViewIterator),
109 // so we don't need to include lfsindexcache.hh.
110 map_lfs_indices_to_root_space(TreePath(),
111 begin,
112 end,
113 out);
114 }
115
116
117 private:
118
119
121 template<typename TP, typename ItIn, typename ItOut>
122 void map_lfs_indices_in_ancestor(TP tp, ItIn& begin, ItIn& end, ItOut out) const
123 {
125
126 // This logic needs to be replicated from the IndexCache visitor, as we bypass
127 // the tree-visiting algorithm and work our way up the tree all by ourselves.
128 // Don't consume the first entry in the tree path to the parent before it has
129 // been used!
130 if (!std::is_same<TreePath,TP>::value && Ordering::consume_tree_index)
131 {
132 begin.restore_back();
133 end.restore_back();
134 }
135
136 // Call the single-level mapping step of our ancestor ordering.
137 TypeTree::child(baseOrdering(),tp).map_lfs_indices(begin,end,out);
138 }
139
140 // Template recursion for walking up the TreePath to the BaseOrdering
141 template<typename TP, typename ItIn, typename ItOut>
142 typename std::enable_if<
143 (TypeTree::TreePathSize<TP>::value > 0)
144 >::type
145 map_lfs_indices_to_root_space(TP, ItIn begin, ItIn end, ItOut out) const
146 {
147 map_lfs_indices_in_ancestor(TP(),begin,end,out);
148 // recurse further up to the tree
149 map_lfs_indices_to_root_space(typename TypeTree::TreePathPopBack<TP>::type(),begin,end,out);
150 }
151
152 // End of template recursion for walking up the TreePath to the BaseOrdering
153 template<typename TP, typename ItIn, typename ItOut>
154 typename std::enable_if<
155 (TypeTree::TreePathSize<TP>::value == 0)
156 >::type
157 map_lfs_indices_to_root_space(TP, ItIn begin, ItIn end, ItOut out) const
158 {
159 map_lfs_indices_in_ancestor(TP(),begin,end,out);
160 }
161
162 public:
163
165 typename Traits::ContainerIndex mapIndex(const typename Traits::DOFIndex& di) const
166 {
167 typename Traits::ContainerIndex ci;
168 mapIndex(di,ci);
169 return ci;
170 }
171
173 void mapIndex(typename Traits::DOFIndexView di, typename Traits::ContainerIndex& ci) const
174 {
175 baseOrdering().mapIndex(di,ci);
176 }
177
179 typename Traits::SizeType size() const
180 {
181 return baseOrdering().size();
182 }
183
184 typename Traits::SizeType size(const typename Traits::ContainerIndex& suffix) const
185 {
186 return baseOrdering().size(suffix);
187 }
188
190 typename Traits::SizeType blockCount() const
191 {
192 return baseOrdering().blockCount();
193 }
194
196 typename Traits::SizeType maxLocalSize() const
197 {
198 return targetOrdering().maxLocalSize();
199 }
200
202 bool contains(typename Traits::SizeType codim) const
203 {
204 return targetOrdering().contains(codim);
205 }
206
208 bool fixedSize(typename Traits::SizeType codim) const
209 {
210 return targetOrdering().fixedSize(codim);
211 }
212
215 {
216 return *_base_ordering;
217 }
218
221 {
222 return this->proxiedNode();
223 }
224
225 private:
226
227 std::shared_ptr<const BaseOrdering> _base_ordering;
228
229 };
230
232
233 } // namespace PDELab
234} // namespace Dune
235
236#endif // DUNE_PDELAB_ORDERING_SUBORDERING_HH
A view on a subtree of a multi-component ordering.
Definition: subordering.hh:50
SubOrdering(std::shared_ptr< const BaseOrdering > base_ordering)
Constructs a SubOrdering for base_ordering.
Definition: subordering.hh:92
BaseOrdering_ BaseOrdering
The type of the BaseOrdering for which to represent a SubOrdering view.
Definition: subordering.hh:57
const BaseOrdering & baseOrdering() const
Returns the BaseOrdering.
Definition: subordering.hh:214
bool fixedSize(typename Traits::SizeType codim) const
Returns whether the TargetOrdering is of fixed size for entities of codimension codim.
Definition: subordering.hh:208
BaseOrdering::Traits Traits
Forwarded Ordering traits from BaseOrdering.
Definition: subordering.hh:63
static const bool consume_tree_index
Forwarded ordering property from TargetOrdering, required by PDELab internals.
Definition: subordering.hh:75
bool contains(typename Traits::SizeType codim) const
Returns whether the TargetOrdering has DOFs attached to entities of codimension codim.
Definition: subordering.hh:202
BaseOrdering::CacheTag CacheTag
Forwarded tag from BaseOrdering, required by PDELab internals.
Definition: subordering.hh:69
Traits::SizeType maxLocalSize() const
Returns the maximum per-entity size of the TargetOrdering.
Definition: subordering.hh:196
Traits::ContainerIndex mapIndex(const typename Traits::DOFIndex &di) const
Maps di from the DOFIndex subtree to the ContainerIndex in the BaseOrdering.
Definition: subordering.hh:165
BaseOrdering::ContainerAllocationTag ContainerAllocationTag
Forwarded tag from BaseOrdering, required by PDELab internals.
Definition: subordering.hh:66
const TargetOrdering & targetOrdering() const
Returns the TargetOrdering.
Definition: subordering.hh:220
Traits::SizeType size() const
Returns the size of the BaseOrdering.
Definition: subordering.hh:179
TypeTree::ChildForTreePath< BaseOrdering, TreePath > TargetOrdering
The target ordering that makes up the root of this SubOrdering view.
Definition: subordering.hh:60
static const bool has_dynamic_ordering_children
Forwarded ordering property from TargetOrdering, required by PDELab internals.
Definition: subordering.hh:72
void update()
Updates this SubOrdering.
Definition: subordering.hh:100
void mapIndex(typename Traits::DOFIndexView di, typename Traits::ContainerIndex &ci) const
Maps di from the DOFIndex subtree to the ContainerIndex in the BaseOrdering - inplace version.
Definition: subordering.hh:173
Traits::SizeType blockCount() const
Returns the block count of the BaseOrdering.
Definition: subordering.hh:190
Base class for nodes acting as a proxy for an existing node.
Definition: proxynode.hh:255
std::enable_if< enabled, const TypeTree::ChildForTreePath< BaseOrdering_, TreePath > & >::type proxiedNode()
Returns the proxied node.
Definition: proxynode.hh:306
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
typename impl::_ChildForTreePath< Node, TreePath >::type ChildForTreePath
Template alias for the type of a child node given by a TreePath or a HybridTreePath type.
Definition: childextraction.hh:252
Dune namespace.
Definition: alignedallocator.hh:13
Creative Commons License   |  Legal Statements / Impressum  |  Hosted by TU Dresden  |  generated with Hugo v0.111.3 (Nov 23, 23:29, 2024)