FEAT 3
Finite Element Analysis Toolbox
Loading...
Searching...
No Matches
struct_index_set.hpp
1// FEAT3: Finite Element Analysis Toolbox, Version 3
2// Copyright (C) 2010 by Stefan Turek & the FEAT group
3// FEAT3 is released under the GNU General Public License version 3,
4// see the file 'copyright.txt' in the top level directory for details.
5
6#pragma once
7
8// includes, FEAT
9#include <kernel/shape.hpp>
10#include <kernel/geometry/index_set.hpp>
11#include <kernel/geometry/intern/struct_num_entities.hpp>
12#include <kernel/geometry/intern/struct_index_mapping.hpp>
13
14namespace FEAT
15{
16 namespace Geometry
17 {
25 template<
26 int shape_dim_,
27 int cell_dim_,
28 int face_dim_>
30 {
31 static_assert(shape_dim_ >= cell_dim_, "invalid shape dimension");
32 static_assert(cell_dim_ > face_dim_, "invalid cell dimension");
33 static_assert(face_dim_ >= 0, "invalid face dimension");
34
35 public:
42
47 {
48 private:
55
56 public:
59 _num_slices(nullptr),
60 _i(0),
61 _j(0)
62 {
63 }
64
66 explicit ImageIterator(const Index* num_slices, Index i, Index j) :
67 _num_slices(num_slices),
68 _i(i),
69 _j(j)
70 {
71 }
72
75 {
76 return Intern::StructIndexMapping<shape_dim_, cell_dim_, face_dim_>::compute(_i, _j, _num_slices);
77 }
78
81 {
82 ++_j;
83 return *this;
84 }
85
87 bool operator!=(const ImageIterator& other) const
88 {
89 return (_i != other._i) || (_j != other._j);
90 }
91 }; // class ImageIterator
92
97 {
98 public:
101
102 private:
107
108 public:
111 _num_slices(nullptr),
112 _i(0)
113 {
114 }
115
117 explicit IndexTupleType(const Index* num_slices, Index i) :
118 _num_slices(num_slices),
119 _i(i)
120 {
121 }
122
124 Index operator[](int j) const
125 {
126 return Intern::StructIndexMapping<shape_dim_, cell_dim_, face_dim_>::compute(_i, Index(j), _num_slices);
127 }
128 }; // class IndexTupleType
129
130 private:
132 Index _num_slices[shape_dim_];
137
138 public:
145 explicit StructIndexSet(const Index num_slices[]) :
146 _num_entities(Intern::StructNumEntities<shape_dim_, cell_dim_>::compute(num_slices)),
147 _index_bound(Intern::StructNumEntities<shape_dim_, face_dim_>::compute(num_slices))
148 {
149 for(int i(0); i < shape_dim_; ++i)
150 {
151 _num_slices[i] = num_slices[i];
152 }
153 }
154
159 {
160 for(int i(0); i < shape_dim_; ++i)
161 {
162 _num_slices[i] = other._num_slices[i];
163 }
164 }
165
168 {
169 // avoid self-move
170 if(this == &other)
171 return *this;
172
173 _num_entities = other._num_entities;
174 _index_bound = other._index_bound;
175 for(int i(0); i < shape_dim_; ++i)
176 {
177 _num_slices[i] = other._num_slices[i];
178 }
179 return *this;
180 }
181
183 std::size_t bytes() const
184 {
185 return std::size_t(0);
186 }
187
193 int get_num_indices() const
194 {
195 return num_indices;
196 }
197
204 {
205 return _num_entities;
206 }
207
214 {
215 return _index_bound;
216 }
217
228 {
230 return IndexTupleType(_num_slices, i);
231 }
232
245 Index operator()(Index i, int j) const
246 {
248 ASSERT(j < num_indices);
249 return Intern::StructIndexMapping<shape_dim_, cell_dim_, face_dim_>::compute(i, Index(j), _num_slices);
250 }
251
258 void copy_to(IndexSet<num_indices>& idx_set) const
259 {
260 XASSERT(idx_set.get_num_entities() == this->get_num_entities());
261 XASSERT(idx_set.get_index_bound() == this->get_index_bound());
262 for(Index i(0); i < _num_entities; ++i)
263 {
264 for(int j(0); j < num_indices; ++j)
265 {
266 idx_set(i, j) = Intern::StructIndexMapping<shape_dim_, cell_dim_, face_dim_>::compute(i, Index(j), _num_slices);
267 }
268 }
269 }
270
271 /* *************************************************************************************** */
272 /* A D J A C T O R I N T E R F A C E I M P L E M E N T A T I O N */
273 /* *************************************************************************************** */
276 {
277 return _num_entities;
278 }
279
282 {
283 return _index_bound;
284 }
285
287 ImageIterator image_begin(Index domain_node) const
288 {
289 ASSERT(domain_node < Index(_num_entities));
290 return ImageIterator(_num_slices, domain_node, 0);
291 }
292
294 ImageIterator image_end(Index domain_node) const
295 {
296 ASSERT(domain_node < Index(_num_entities));
297 return ImageIterator(_num_slices, domain_node, num_indices);
298 }
299 }; // class StructIndexSet<...>
300
301
302 /* ***************************************************************************************** */
303 /* ***************************************************************************************** */
304 /* ***************************************************************************************** */
305
307 template<
308 int shape_dim_,
309 int cell_dim_ = shape_dim_,
310 int face_dim_ = cell_dim_ - 1>
311 class StructIndexSetWrapper :
312 public StructIndexSetWrapper<shape_dim_, cell_dim_, face_dim_ - 1>
313 {
314 protected:
315 typedef StructIndexSetWrapper<shape_dim_, cell_dim_, face_dim_ - 1> BaseClass;
316
317 StructIndexSet<shape_dim_, cell_dim_, face_dim_> _index_set;
318
319 public:
320 explicit StructIndexSetWrapper(const Index num_slices[]) :
321 BaseClass(num_slices),
322 _index_set(num_slices)
323 {
324 }
325
326 StructIndexSetWrapper(StructIndexSetWrapper&& other) :
327 BaseClass(std::forward<BaseClass>(other)),
328 _index_set(std::forward<StructIndexSet<shape_dim_, cell_dim_, face_dim_>>(other._index_set))
329 {
330 }
331
332 StructIndexSetWrapper& operator=(StructIndexSetWrapper&& other)
333 {
334 if(this == &other)
335 return *this;
336
337 BaseClass::operator=(std::forward<BaseClass>(other));
338 _index_set = std::forward<StructIndexSet<shape_dim_, cell_dim_, face_dim_>>(other._index_set);
339
340 return *this;
341 }
342
343 template<int face_dim__>
344 const StructIndexSet<shape_dim_, cell_dim_, face_dim__>& get_index_set() const
345 {
346 static_assert((face_dim__ >= 0) && (face_dim__ <= face_dim_), "invalid face dimension");
347 return StructIndexSetWrapper<shape_dim_, cell_dim_, face_dim__>::_index_set;
348 }
349
350 std::size_t bytes() const
351 {
352 return BaseClass::bytes() + _index_set.bytes();
353 }
354
355 void copy_to(IndexSetWrapper<Shape::Hypercube<cell_dim_>, face_dim_>& idx_set_wrp) const
356 {
357 BaseClass::copy_to(idx_set_wrp);
358 _index_set.copy_to(idx_set_wrp.template get_index_set<face_dim_>());
359 }
360 };
361
362 template<
363 int shape_dim_,
364 int cell_dim_>
365 class StructIndexSetWrapper<shape_dim_, cell_dim_, 0>
366 {
367 protected:
368 StructIndexSet<shape_dim_, cell_dim_, 0> _index_set;
369
370 public:
371 explicit StructIndexSetWrapper(const Index num_slices[]) :
372 _index_set(num_slices)
373 {
374 }
375
376 StructIndexSetWrapper(StructIndexSetWrapper&& other) :
377 _index_set(std::forward<StructIndexSet<shape_dim_, cell_dim_, 0>>(other._index_set))
378 {
379 }
380
381 StructIndexSetWrapper& operator=(StructIndexSetWrapper&& other)
382 {
383 if(this == &other)
384 return *this;
385
386 _index_set = std::forward<StructIndexSet<shape_dim_, cell_dim_, 0>>(other._index_set);
387
388 return *this;
389 }
390
391 template<int face_dim__>
392 const StructIndexSet<shape_dim_, cell_dim_, face_dim__>& get_index_set() const
393 {
394 static_assert(face_dim__ == 0, "invalid face dimension");
395 return _index_set;
396 }
397
398 std::size_t bytes() const
399 {
400 return _index_set.bytes();
401 }
402
403 void copy_to(IndexSetWrapper<Shape::Hypercube<cell_dim_>, 0>& idx_set_wrp) const
404 {
405 _index_set.copy_to(idx_set_wrp.template get_index_set<0>());
406 }
407 };
408
409 template<
410 int shape_dim_,
411 int cell_dim_ = shape_dim_>
412 class StructIndexSetHolder :
413 public StructIndexSetHolder<shape_dim_, cell_dim_ - 1>
414 {
415 protected:
416 typedef StructIndexSetHolder<shape_dim_, cell_dim_ - 1> BaseClass;
417
418 StructIndexSetWrapper<shape_dim_, cell_dim_> _index_set_wrapper;
419
420 public:
421 explicit StructIndexSetHolder(const Index num_slices[]) :
422 BaseClass(num_slices),
423 _index_set_wrapper(num_slices)
424 {
425 }
426
427 StructIndexSetHolder(StructIndexSetHolder&& other) :
428 BaseClass(std::forward<BaseClass>(other)),
429 _index_set_wrapper(std::forward<StructIndexSetWrapper<shape_dim_, cell_dim_>>(other._index_set_wrapper))
430 {
431 }
432
433 StructIndexSetHolder& operator=(StructIndexSetHolder&& other)
434 {
435 if(this == &other)
436 return *this;
437
438 BaseClass::operator=(std::forward<BaseClass>(other));
439 _index_set_wrapper = std::forward<StructIndexSetWrapper<shape_dim_, cell_dim_>>(other._index_set_wrapper);
440
441 return *this;
442 }
443
444 template<int cell_dim__>
445 const StructIndexSetWrapper<shape_dim_, cell_dim__>& get_index_set_wrapper() const
446 {
447 return StructIndexSetHolder<shape_dim_, cell_dim__>::_index_set_wrapper;
448 }
449
450 template<int cell_dim__, int face_dim__>
451 const StructIndexSet<shape_dim_, cell_dim__, face_dim__>& get_index_set() const
452 {
453 return get_index_set_wrapper<cell_dim__>().template get_index_set<face_dim__>();
454 }
455
456 std::size_t bytes() const
457 {
458 return BaseClass::bytes() + _index_set_wrapper.bytes();
459 }
460
461 void copy_to(IndexSetHolder<Shape::Hypercube<cell_dim_>>& idx_set_hld) const
462 {
463 BaseClass::copy_to(idx_set_hld);
464 _index_set_wrapper.copy_to(idx_set_hld.template get_index_set_wrapper<cell_dim_>());
465 }
466 };
467
468 template<int shape_dim_>
469 class StructIndexSetHolder<shape_dim_, 0>
470 {
471 public:
472 explicit StructIndexSetHolder(const Index /*num_slices*/[])
473 {
474 }
475
476 StructIndexSetHolder(StructIndexSetHolder&&)
477 {
478 }
479
480 StructIndexSetHolder& operator=(StructIndexSetHolder&&)
481 {
482 return *this;
483 }
484
485 std::size_t bytes() const
486 {
487 return std::size_t(0);
488 }
489
490 void copy_to(IndexSetHolder<Shape::Vertex>&) const
491 {
492 }
493 };
495 } // namespace Geometry
496} // namespace FEAT
#define ASSERT(expr)
Debug-Assertion macro definition.
Definition: assertion.hpp:229
#define XASSERT(expr)
Assertion macro definition.
Definition: assertion.hpp:262
Conformal Index-Set class template.
Definition: index_set.hpp:82
Index get_index_bound() const
Returns the index bound.
Definition: index_set.hpp:190
Index get_num_entities() const
Returns the number of entities.
Definition: index_set.hpp:180
ImageIterator implementation for Adjactor interface.
ImageIterator & operator++()
Pre-increment operator.
bool operator!=(const ImageIterator &other) const
Checks two iterators for inequality.
ImageIterator(const Index *num_slices, Index i, Index j)
constructor
const Index * _num_slices
pointer to num_slices array of the index-set
Index operator*() const
Dereferentiation operator.
Index tuple class for structured meshes.
const Index * _num_slices
pointer to num_slices array of the index-set
Index operator[](int j) const
access operator
IndexTupleType(const Index *num_slices, Index i)
constructor
static constexpr int num_indices
number of indices per tuple
Structured Index-Set class template.
Shape::Hypercube< shape_dim_ > ShapeType
shape type
StructIndexSet(StructIndexSet &&other)
move constructor
Index get_num_nodes_domain() const
Returns the number of domain nodes.
void copy_to(IndexSet< num_indices > &idx_set) const
Copies this index set into a (conformal) index set.
Shape::FaceTraits< ShapeType, cell_dim_ >::ShapeType CellType
cell type
ImageIterator image_end(Index domain_node) const
Returns an iterator for the first position past the last adjacent image node.
Index get_index_bound() const
Returns the index bound.
ImageIterator image_begin(Index domain_node) const
Returns an iterator for the first adjacent image node.
static constexpr int num_indices
number of indices
Index _num_slices[shape_dim_]
number of slices
int get_num_indices() const
Returns the number of indices per entity.
IndexTupleType operator[](Index i) const
Returns an index tuple.
StructIndexSet & operator=(StructIndexSet &&other)
move-assignment operator
StructIndexSet(const Index num_slices[])
Constructor.
Index get_num_entities() const
Returns the number of entities.
Index _num_entities
number of entities
Index get_num_nodes_image() const
Returns the number of image nodes.
Index operator()(Index i, int j) const
Maps a face index.
@ other
generic/other permutation strategy
FEAT namespace.
Definition: adjactor.hpp:12
std::uint64_t Index
Index data type.
Face traits tag struct template.
Definition: shape.hpp:106
Hypercube shape tag struct template.
Definition: shape.hpp:64