DUNE PDELab (2.7)

lexicographicordering.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_LEXICOGRAPHICORDERING_HH
5#define DUNE_PDELAB_ORDERING_LEXICOGRAPHICORDERING_HH
6
7#include <cstddef>
8#include <ostream>
9#include <string>
10
14
15#include <dune/typetree/compositenode.hh>
16#include <dune/typetree/powernode.hh>
17#include <dune/typetree/traversal.hh>
18#include <dune/typetree/visitor.hh>
19
20#include <dune/pdelab/gridfunctionspace/tags.hh>
21#include <dune/pdelab/ordering/utility.hh>
22#include <dune/pdelab/ordering/orderingbase.hh>
23
24namespace Dune {
25 namespace PDELab {
26
29
30 namespace lexicographic_ordering {
31
32 template<typename DI, typename CI, typename Node>
33 class Base
34 : public OrderingBase<DI,CI>
35 {
36
37 typedef OrderingBase<DI,CI> BaseT;
38
39 public:
40
41 typedef typename OrderingBase<DI,CI>::Traits Traits;
42
43 typedef LexicographicOrderingTag OrderingTag;
44
45 static const bool consume_tree_index = true;
46
48
53 Base(Node& node, bool container_blocked, typename BaseT::GFSData* gfs_data)
54 : BaseT(node,container_blocked,gfs_data,nullptr)
55 {
56 }
57
58 template<typename ItIn, typename ItOut>
59 void map_lfs_indices(const ItIn begin, const ItIn end, ItOut out) const
60 {
61 if (this->_container_blocked)
62 {
63 for (ItIn in = begin; in != end; ++in, ++out)
64 out->push_back(in->treeIndex().back());
65 }
66 else
67 {
68 for (ItIn in = begin; in != end; ++in, ++out)
69 out->back() += (this->blockOffset(in->treeIndex().back()));
70 }
71 }
72
73 template<typename CIOutIterator, typename DIOutIterator = DummyDOFIndexIterator>
74 typename Traits::SizeType
75 extract_entity_indices(const typename Traits::DOFIndex::EntityIndex& ei,
76 typename Traits::SizeType child_index,
77 CIOutIterator ci_out, const CIOutIterator ci_end) const
78 {
79 if (this->_container_blocked)
80 {
81 for (; ci_out != ci_end; ++ci_out)
82 {
83 ci_out->push_back(child_index);
84 }
85 }
86 else
87 {
88 for (; ci_out != ci_end; ++ci_out)
89 {
90 ci_out->back() += (this->blockOffset(child_index));
91 }
92 }
93
94 // The return value is not used for non-leaf orderings.
95 return 0;
96 }
97
98 };
99 }
100
101
102
103 template<typename DI, typename CI, typename Child, std::size_t k>
104 class PowerLexicographicOrdering
105 : public TypeTree::PowerNode<Child, k>
106 , public lexicographic_ordering::Base<DI,
107 CI,
108 PowerLexicographicOrdering<DI,CI,Child,k>
109 >
110 {
111 typedef TypeTree::PowerNode<Child, k> Node;
112
113 typedef lexicographic_ordering::Base<DI,
114 CI,
115 PowerLexicographicOrdering<DI,CI,Child,k>
116 > Base;
117
118 public:
119
121
129 PowerLexicographicOrdering(bool container_blocked, const typename Node::NodeStorage& children, typename Base::GFSData* gfs_data)
130 : Node(children)
131 , Base(*this,container_blocked,gfs_data)
132 { }
133
134 void update()
135 {
136 for (std::size_t i = 0; i < k; ++i)
137 {
138 this->child(i).update();
139 }
140 Base::update();
141 }
142
143 std::string name() const { return "PowerLexicographicOrdering"; }
144 };
145
146
147 template<typename GFS, typename Transformation>
148 struct power_gfs_to_lexicographic_ordering_descriptor
149 {
150
151 static const bool recursive = true;
152
153 template<typename TC>
154 struct result
155 {
156
157 typedef PowerLexicographicOrdering<
158 typename Transformation::DOFIndex,
159 typename Transformation::ContainerIndex,
160 TC,
161 TypeTree::StaticDegree<GFS>::value
162 > type;
163
164 typedef std::shared_ptr<type> storage_type;
165
166 };
167
168 template<typename TC>
169 static typename result<TC>::type transform(const GFS& gfs, const Transformation& t, const std::array<std::shared_ptr<TC>,TypeTree::StaticDegree<GFS>::value>& children)
170 {
171 return typename result<TC>::type(gfs.backend().blocked(gfs),children,const_cast<GFS*>(&gfs));
172 }
173
174 template<typename TC>
175 static typename result<TC>::storage_type transform_storage(std::shared_ptr<const GFS> gfs, const Transformation& t, const std::array<std::shared_ptr<TC>,TypeTree::StaticDegree<GFS>::value>& children)
176 {
177 return std::make_shared<typename result<TC>::type>(gfs->backend().blocked(*gfs),children,const_cast<GFS*>(gfs.get()));
178 }
179
180 };
181
182 template<typename GFS, typename Transformation>
183 power_gfs_to_lexicographic_ordering_descriptor<GFS,Transformation>
184 register_power_gfs_to_ordering_descriptor(GFS*,Transformation*,LexicographicOrderingTag*);
185
186 // the generic registration for PowerGridFunctionSpace happens in transformations.hh
187
188
190 template<typename DI, typename CI, typename... Children>
192 public TypeTree::CompositeNode<Children...>,
193 public lexicographic_ordering::Base<DI,
194 CI,
195 CompositeLexicographicOrdering<
196 DI,
197 CI,
198 Children...
199 >
200 >
201 {
202 typedef TypeTree::CompositeNode<Children...> Node;
203
204 typedef lexicographic_ordering::Base<
205 DI,
206 CI,
208 DI,
209 CI,
210 Children...
211 >
212 > Base;
213
214 public:
216
224 CompositeLexicographicOrdering(bool backend_blocked, typename Base::GFSData* gfs_data, std::shared_ptr<Children>... children)
225 : Node(children...)
226 , Base(*this,backend_blocked,gfs_data)
227 { }
228
229 std::string name() const { return "CompositeLexicographicOrdering"; }
230
231 void update()
232 {
233 TypeTree::applyToTree(*this,ordering::update_direct_children());
234 Base::update();
235 }
236 };
237
238 template<typename GFS, typename Transformation>
239 struct composite_gfs_to_lexicographic_ordering_descriptor
240 {
241
242 static const bool recursive = true;
243
244 template<typename... TC>
245 struct result
246 {
247
248 typedef CompositeLexicographicOrdering<
249 typename Transformation::DOFIndex,
250 typename Transformation::ContainerIndex,
251 TC...
252 > type;
253
254 typedef std::shared_ptr<type> storage_type;
255
256 };
257
258 template<typename... TC>
259 static typename result<TC...>::type transform(const GFS& gfs, const Transformation& t, std::shared_ptr<TC>... children)
260 {
261 return typename result<TC...>::type(gfs.backend().blocked(gfs),const_cast<GFS*>(&gfs),children...);
262 }
263
264 template<typename... TC>
265 static typename result<TC...>::storage_type transform_storage(std::shared_ptr<const GFS> gfs, const Transformation& t, std::shared_ptr<TC>... children)
266 {
267 return std::make_shared<typename result<TC...>::type>(gfs->backend().blocked(*gfs),const_cast<GFS*>(gfs.get()),children...);
268 }
269
270 };
271
272
273 template<typename GFS, typename Transformation>
274 composite_gfs_to_lexicographic_ordering_descriptor<GFS,Transformation>
275 register_composite_gfs_to_ordering_descriptor(GFS*,Transformation*,LexicographicOrderingTag*);
276
278 } // namespace PDELab
279} // namespace Dune
280
281#endif // DUNE_PDELAB_ORDERING_LEXICOGRAPHICORDERING_HH
Interface for merging index spaces.
Definition: lexicographicordering.hh:201
CompositeLexicographicOrdering(bool backend_blocked, typename Base::GFSData *gfs_data, std::shared_ptr< Children >... children)
Construct ordering object.
Definition: lexicographicordering.hh:224
Base class for composite nodes based on variadic templates.
Definition: compositenode.hh:25
std::array< ChildStorageType, k > NodeStorage
The type used for storing the children.
Definition: powernode.hh:84
A free function to provide the demangled class name of a given object or type as a string.
A few common exception classes.
void applyToTree(Tree &&tree, Visitor &&visitor)
Apply visitor to TypeTree.
Definition: traversal.hh:213
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:179
Dune namespace.
Definition: alignedallocator.hh:14
Standard Dune debug streams.
Creative Commons License   |  Legal Statements / Impressum  |  Hosted by TU Dresden & Uni Heidelberg  |  generated with Hugo v0.111.3 (Sep 4, 22:38, 2025)