DUNE PDELab (git)

chunkedblockordering.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_CHUNKEDBLOCKORDERING_HH
5#define DUNE_PDELAB_ORDERING_CHUNKEDBLOCKORDERING_HH
6
7#include <dune/typetree/typetree.hh>
8
9#include <dune/pdelab/ordering/utility.hh>
10#include <dune/pdelab/ordering/orderingbase.hh>
11#include <dune/pdelab/ordering/decorator.hh>
12
13namespace Dune {
14 namespace PDELab {
15
16 namespace ordering {
17
18#ifndef DOXYGEN // implementation internals
19
20 namespace chunked {
21
22 struct tag_base
23 {
24
25 tag_base(std::size_t block_size)
26 : _block_size(block_size)
27 {}
28
29 std::size_t blockSize() const
30 {
31 return _block_size;
32 }
33
34 private:
35
36 const std::size_t _block_size;
37
38 };
39
40 template<std::size_t i>
41 struct base_holder
42 : public tag_base
43 {
44
45 base_holder(std::size_t block_size)
46 : tag_base(block_size)
47 {}
48
49 };
50
51 } // namespace chunked
52
53#endif // DOXYGEN
54
57
65 template<typename OrderingTag>
66 struct Chunked
67 : public chunked::base_holder<decorated_ordering_tag<Chunked<OrderingTag>,OrderingTag>::level>
68 , public decorated_ordering_tag<Chunked<OrderingTag>,OrderingTag>
69 {
70
71 Chunked(std::size_t block_size)
72 : chunked::base_holder<decorated_ordering_tag<Chunked<OrderingTag>,OrderingTag>::level>(block_size)
73 {}
74
75 Chunked(std::size_t block_size, const OrderingTag& tag)
76 : chunked::base_holder<decorated_ordering_tag<Chunked<OrderingTag>,OrderingTag>::level>(block_size)
77 , decorated_ordering_tag<Chunked<OrderingTag>,OrderingTag>(tag)
78 {}
79
80 Chunked(std::size_t block_size, OrderingTag&& tag)
81 : chunked::base_holder<decorated_ordering_tag<Chunked<OrderingTag>,OrderingTag>::level>(block_size)
82 , decorated_ordering_tag<Chunked<OrderingTag>,OrderingTag>(std::move(tag))
83 {}
84
85 template<std::size_t i>
86 const chunked::base_holder<i>& chunked() const
87 {
88 return *this;
89 }
90
91 template<std::size_t i>
92 chunked::base_holder<i>& chunked()
93 {
94 return *this;
95 }
96
97 };
98
99 template<typename Decorated>
100 constexpr bool deactivate_standard_blocking_for_ordering(const Chunked<Decorated>&)
101 {
102 return true;
103 }
104
105 } // namespace ordering
106
109
111 template<typename Ordering>
113 : public TypeTree::CompositeNode<Ordering>
114 , public VirtualOrderingBase<typename Ordering::Traits::DOFIndex,
115 typename Ordering::Traits::ContainerIndex>
116 , public OrderingBase<typename Ordering::Traits::DOFIndex,
117 typename Ordering::Traits::ContainerIndex>
118 {
119 public:
120 typedef typename Ordering::Traits Traits;
121
122 static const bool consume_tree_index = false;
123
124 private:
125
127
128 typedef OrderingBase<
129 typename Ordering::Traits::DOFIndex,
130 typename Ordering::Traits::ContainerIndex
131 > BaseT;
132
133 public:
134
135 Ordering& ordering()
136 {
137 return this->template child<0>();
138 }
139
140 const Ordering& ordering() const
141 {
142 return this->template child<0>();
143 }
144
145
146 ChunkedBlockOrdering(const typename NodeT::NodeStorage& ordering, const ordering::chunked::tag_base& tag)
147 : NodeT(ordering)
148 , BaseT(*this,true,nullptr,this)
149 , _tag(tag)
150 {}
151
153 : NodeT(r.nodeStorage())
154 , BaseT(r)
155 ,_tag(r._tag)
156 {
157 this->setDelegate(this);
158 }
159
161 : NodeT(r.nodeStorage())
162 , BaseT(std::move(r))
163 ,_tag(r._tag)
164 {
165 this->setDelegate(this);
166 }
167
168 virtual ~ChunkedBlockOrdering() override = default;
169
170 virtual void map_index_dynamic(typename Traits::DOFIndexView di, typename Traits::ContainerIndex& ci) const override
171 {
172 ordering().mapIndex(di,ci);
173 std::size_t flat_index = ci.back();
174 std::size_t block_index = flat_index / _tag.blockSize();
175 std::size_t inner_index = flat_index % _tag.blockSize();
176 ci.back() = inner_index;
177 ci.push_back(block_index);
178 }
179
180 template<typename ItIn, typename ItOut>
181 void map_lfs_indices(ItIn in, const ItIn end, ItOut out) const
182 {
183 for (; in != end; ++in, ++out)
184 {
185 std::size_t flat_index = out->back();
186 std::size_t block_index = flat_index / _tag.blockSize();
187 std::size_t inner_index = flat_index % _tag.blockSize();
188 out->back() = inner_index;
189 out->push_back(block_index);
190 }
191 }
192
193 template<typename CIOutIterator>
194 typename Traits::SizeType
195 extract_entity_indices(const typename Traits::DOFIndex::EntityIndex& ei,
196 typename Traits::SizeType child_index,
197 CIOutIterator ci_out, const CIOutIterator ci_end) const
198 {
199 for (; ci_out != ci_end; ++ci_out)
200 {
201 std::size_t flat_index = ci_out->back();
202 std::size_t block_index = flat_index / _tag.blockSize();
203 std::size_t inner_index = flat_index % _tag.blockSize();
204 ci_out->back() = inner_index;
205 ci_out->push_back(block_index);
206 }
207 return 0;
208 }
209
210 void update()
211 {
212 ordering().update();
213 BaseT::update();
214 if (ordering().blockCount() % _tag.blockSize() != 0)
216 "Block size of chunked block ordering does not divide the block count "
217 "of the underlying ordering: "
218 << ordering().blockCount()
219 << " % "
220 << _tag.blockSize()
221 << " != 0"
222 );
223 this->_block_count = ordering().blockCount() / _tag.blockSize();
224 }
225
226 using BaseT::size;
227
228 typename Traits::SizeType size(typename Traits::ContainerIndex suffix) const
229 {
230 if (suffix.size() == 0)
231 return this->_block_count;
232 if (suffix.size() == 1)
233 return _tag.blockSize();
234
235 auto block_index = suffix.back();
236 suffix.pop_back();
237 auto inner_index = suffix.back();
238
239 suffix.back() = _tag.blockSize() * block_index + inner_index;
240 return ordering().size(suffix);
241 }
242
243 private:
244
245 const ordering::chunked::tag_base& _tag;
246
247 };
248
249 namespace ordering {
250
251 namespace chunked {
252
253 template<typename GFS, typename Transformation, typename Undecorated, typename Tag>
254 struct gfs_to_chunked
255 {
256
257 typedef ChunkedBlockOrdering<Undecorated> transformed_type;
258 typedef std::shared_ptr<transformed_type> transformed_storage_type;
259
260 static transformed_type transform(const GFS& gfs, const Transformation& t, std::shared_ptr<Undecorated> undecorated)
261 {
262 return transformed_type(make_tuple(undecorated),gfs.orderingTag().template chunked<Tag::level>());
263 }
264
265 static transformed_storage_type transform_storage(std::shared_ptr<const GFS> gfs_pointer, const Transformation& t, std::shared_ptr<Undecorated> undecorated)
266 {
267 return std::make_shared<transformed_type>(make_tuple(undecorated),gfs_pointer->orderingTag().template chunked<Tag::level>());
268 }
269
270 };
271
272 template<typename GFS, typename Transformation, typename Undecorated, typename GlueTag, typename UndecoratedTag>
273 gfs_to_chunked<GFS,Transformation,Undecorated,GlueTag>
274 register_gfs_to_decorator_descriptor(GFS*,Transformation*,Undecorated*,GlueTag*,Chunked<UndecoratedTag>*);
275
276 } // namespace chunked
277 } // namespace ordering
278
279
280 template<typename GFS, typename Transformation, typename U>
281 struct power_gfs_to_local_ordering_descriptor<GFS,Transformation,ordering::Chunked<U> >
282 : public power_gfs_to_local_ordering_descriptor<GFS,Transformation,U>
283 {};
284
285
286 template<typename GFS, typename Transformation, typename U>
287 struct composite_gfs_to_local_ordering_descriptor<GFS,Transformation,ordering::Chunked<U> >
288 : public composite_gfs_to_local_ordering_descriptor<GFS,Transformation,U>
289 {};
290
292 } // namespace PDELab
293} // namespace Dune
294
295#endif // DUNE_PDELAB_ORDERING_CHUNKEDBLOCKORDERING_HH
The block size of a ChunkedBlockOrdering does not divide the block count of the underlying ordering.
Definition: exceptions.hh:56
Ordering that permutes top-level ContainerIndex entries.
Definition: chunkedblockordering.hh:118
Base class for composite nodes based on variadic templates.
Definition: compositenode.hh:28
std::tuple< std::shared_ptr< Children >... > NodeStorage
The type used for storing the children.
Definition: compositenode.hh:36
#define DUNE_THROW(E, m)
Definition: exceptions.hh:218
Dune namespace.
Definition: alignedallocator.hh:13
Definition: chunkedblockordering.hh:69
Creative Commons License   |  Legal Statements / Impressum  |  Hosted by TU Dresden  |  generated with Hugo v0.111.3 (Nov 23, 23:29, 2024)