FEAT 3
Finite Element Analysis Toolbox
Loading...
Searching...
No Matches
adjactor.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
10
11namespace FEAT
12{
13 namespace Adjacency
14 {
23 {
24 public:
25 // Note: The following class is just an abstract description of an adjactor for the documentation -- it is not
26 // an actual class that should be compiled, therefore the class is inside a block reserved only for doxygen.
27#ifdef DOXYGEN
36 {
37 public:
42
50
60
68
78
88 bool operator!=(const ImageIterator& other) const;
89 }; // class ImageIterator
90
98
106
117 ImageIterator image_begin(Index domain_node) const;
118
128 ImageIterator image_end(Index domain_node) const;
129#endif // DOXYGEN
130
141 {
142 public:
149 {
150 XABORTM("cannot increment NullImageIterator");
151 return *this;
152 }
153
160 {
161 XABORTM("cannot dereference NullImageIterator");
162 return Index(0);
163 }
164
170 bool operator!=(const NullImageIterator& DOXY(other)) const
171 {
172 // NullImageIterators are always equal
173 return false;
174 }
175 }; // class Adjactor::NullImageIterator
176
185 {
186 protected:
189
190 public:
193 _index(0)
194 {
195 }
196
203 explicit IndexImageIterator(Index index) :
204 _index(index)
205 {
206 }
207
210 _index(other._index)
211 {
212 }
213
216 {
217 _index = other._index;
218 return *this;
219 }
220
229 {
230 ++_index;
231 return *this;
232 }
233
243 {
244 return _index;
245 }
246
256 bool operator!=(const IndexImageIterator& other) const
257 {
258 return _index != other._index;
259 }
260 }; // class Adjactor::IndexImageIterator
261 }; // class Adjactor
262
270 template<
271 typename Adj1_,
272 typename Adj2_>
274 {
275 private:
277 const Adj1_& _adj1;
279 const Adj2_& _adj2;
280
281 public:
283 typedef Adj1_ Adjactor1;
285 typedef Adj2_ Adjactor2;
286
293 {
294 // The CompositeAdjactor class needs to be a friend as it calls the protected constructors.
295 friend class CompositeAdjactor<Adj1_, Adj2_>;
296
297 private:
298
300 typedef typename Adj1_::ImageIterator Iterator1;
302 typedef typename Adj2_::ImageIterator Iterator2;
303
305 const Adj2_* _adj2;
306
315
316 protected:
318 // constructor for image_begin()
320 const Adj1_* adj1,
321 const Adj2_* adj2,
322 Index domain_node)
323 :
324 _adj2(adj2),
325 _cur1(adj1->image_begin(domain_node)),
326 _end1(adj1->image_end(domain_node)),
327 _cur2(),
328 _end2()
329 {
330 if(_cur1 != _end1)
331 {
332 _cur2 = adj2->image_begin(*_cur1);
333 _end2 = adj2->image_end(*_cur1);
334 }
335 }
336
337 // constructor for image_end()
339 const Adj1_* adj1,
340 Index domain_node)
341 :
342 _adj2(nullptr),
343 _cur1(adj1->image_end(domain_node)),
344 _end1(_cur1),
345 _cur2(),
346 _end2()
347 {
348 }
350
351 public:
353 inline ImageIterator() :
354 _adj2(nullptr),
355 _cur1(),
356 _end1(),
357 _cur2(),
358 _end2()
359 {
360 }
361
363 inline ImageIterator(const ImageIterator& other) :
364 _adj2(other._adj2),
365 _cur1(other._cur1),
366 _cur2(other._cur2),
367 _end1(other._end1),
368 _end2(other._end2)
369 {
370 }
371
373 inline Index operator*() const
374 {
375 return *_cur2;
376 }
377
379 inline bool operator!=(const ImageIterator& other) const
380 {
381 return (_cur1 != other._cur1) || (_cur2 != other._cur2);
382 }
383
386 {
387 // increment the second iterator; if it did not reach the end then we have a valid position
388 if(++_cur2 != _end2)
389 {
390 return *this;
391 }
392
393 // second iterator reached its end, so keep incrementing the first iterator until we find the next
394 // non-empty second adjacency list or until we reach its end
395 while(++_cur1 != _end1)
396 {
397 // reset second iterator
398 _cur2 = _adj2->image_begin(*_cur1);
399 _end2 = _adj2->image_end(*_cur1);
400
401 // check whether the second adjacency list is empty, if not then we have a valid position
402 if(_cur2 != _end2)
403 {
404 return *this;
405 }
406 }
407
408 // If we come out here, then there are no more adjacencies left, so we need to set
409 // this iterator to the 'end' position - this setting must be compatible to the iterator
410 // returned by the image_end() function of the CompositeAdjactor class!
411 // Note: see the second protected constructor of this class for the following definition.
412 _cur2 = Iterator2();
413 _end2 = _cur2;
414
415 return *this;
416 }
417 }; // class CompositeAdjactor::ImageIterator
418
429 const Adj1_& adjactor1,
430 const Adj2_& adjactor2)
431 :
432 _adj1(adjactor1),
433 _adj2(adjactor2)
434 {
435 // Ensure that the number of image nodes in the first adjactor is not greater than the number of domain
436 // nodes in the second adjactor; otherwise the composite adjactor is ill-formed.
437 XASSERTM(_adj1.get_num_nodes_image() <= _adj2.get_num_nodes_domain(), "Composite Adjactor is ill-formed");
438 }
439
442 {
443 // The number of domain nodes of the composite adjactor is given by the number of domain nodes of the
444 // first adjactor in the composition.
445 return _adj1.get_num_nodes_domain();
446 }
447
450 {
451 // The number of image nodes of the composite adjactor is given by the number of image nodes of the
452 // second adjactor in the composition.
453 return _adj2.get_num_nodes_image();
454 }
455
457 inline ImageIterator image_begin(Index domain_node) const
458 {
459 ASSERTM(domain_node < get_num_nodes_domain(), "domain_node out of valid range");
460 return ImageIterator(&_adj1, &_adj2, domain_node);
461 }
462
464 inline ImageIterator image_end(Index domain_node) const
465 {
466 ASSERTM(domain_node < get_num_nodes_domain(), "domain_node out of valid range");
467 return ImageIterator(&_adj1, domain_node);
468 }
469
475 inline const Adjactor1& get_adjactor1() const
476 {
477 return _adj1;
478 }
479
485 inline const Adjactor2& get_adjactor2() const
486 {
487 return _adj2;
488 }
489 }; // class CompositeAdjactor
490 } // namespace Adjacency
491} // namespace FEAT
#define XABORTM(msg)
Abortion macro definition with custom message.
Definition: assertion.hpp:192
#define ASSERTM(expr, msg)
Debug-Assertion macro definition with custom message.
Definition: assertion.hpp:230
#define XASSERTM(expr, msg)
Assertion macro definition with custom message.
Definition: assertion.hpp:263
Adjactor image node iterator class.
Definition: adjactor.hpp:36
ImageIterator & operator++()
Pre-increment operator.
Index operator*() const
Dereferentiation operator.
bool operator!=(const ImageIterator &other) const
Checks two iterators for inequality.
ImageIterator(const ImageIterator &other)
Copy constructor.
ImageIterator & operator=(const ImageIterator &other)
Assignment operator.
IndexImageIterator(Index index)
Constructor.
Definition: adjactor.hpp:203
Index operator*() const
Dereferentiation operator.
Definition: adjactor.hpp:242
Index _index
the current index of the iterator
Definition: adjactor.hpp:188
IndexImageIterator(const IndexImageIterator &other)
copy constructor
Definition: adjactor.hpp:209
bool operator!=(const IndexImageIterator &other) const
Checks two iterators for inequality.
Definition: adjactor.hpp:256
IndexImageIterator & operator++()
Pre-increment operator.
Definition: adjactor.hpp:228
IndexImageIterator & operator=(const IndexImageIterator &other)
assignment operator
Definition: adjactor.hpp:215
NullImageIterator & operator++()
Pre-increment operator.
Definition: adjactor.hpp:148
Index operator*() const
Dereferentiation operator.
Definition: adjactor.hpp:159
bool operator!=(const NullImageIterator &other) const
Checks two iterators for inequality.
Definition: adjactor.hpp:170
Adjactor interface.
Definition: adjactor.hpp:23
ImageIterator image_begin(Index domain_node) const
Returns an iterator for the first adjacent image node.
Index get_num_nodes_image() const
Returns the number of image nodes.
ImageIterator image_end(Index domain_node) const
Returns an iterator for the first position past the last adjacent image node.
Index get_num_nodes_domain() const
Returns the number of domain nodes.
Image Node Iterator implementation for CompositeAdjactor.
Definition: adjactor.hpp:293
Iterator2 _cur2
current iterator for second adjactor
Definition: adjactor.hpp:312
Adj1_::ImageIterator Iterator1
Dual iterator of first adjactor.
Definition: adjactor.hpp:300
Iterator2 _end2
end iterator for second adjactor
Definition: adjactor.hpp:314
const Adj2_ * _adj2
pointer to second adjactor
Definition: adjactor.hpp:305
Iterator1 _cur1
current iterator for first adjactor
Definition: adjactor.hpp:308
Index operator*() const
Dereferentiation operator.
Definition: adjactor.hpp:373
bool operator!=(const ImageIterator &other) const
Checks two iterators for inequality.
Definition: adjactor.hpp:379
Adj2_::ImageIterator Iterator2
Dual iterator of second adjactor.
Definition: adjactor.hpp:302
ImageIterator & operator++()
Pre-increment operator.
Definition: adjactor.hpp:385
Iterator1 _end1
end iterator for first adjactor
Definition: adjactor.hpp:310
Composite Adjactor implementation.
Definition: adjactor.hpp:274
Adj2_ Adjactor2
typedef for second adjactor
Definition: adjactor.hpp:285
Index get_num_nodes_image() const
Returns the number of image nodes.
Definition: adjactor.hpp:449
Index get_num_nodes_domain() const
Returns the number of domain nodes.
Definition: adjactor.hpp:441
ImageIterator image_end(Index domain_node) const
Returns an iterator for the first position past the last adjacent image node.
Definition: adjactor.hpp:464
const Adj1_ & _adj1
first adjactor
Definition: adjactor.hpp:277
const Adjactor1 & get_adjactor1() const
Returns the first adjactor.
Definition: adjactor.hpp:475
const Adjactor2 & get_adjactor2() const
Returns the second adjactor.
Definition: adjactor.hpp:485
ImageIterator image_begin(Index domain_node) const
Returns an iterator for the first adjacent image node.
Definition: adjactor.hpp:457
Adj1_ Adjactor1
typedef for first adjactor
Definition: adjactor.hpp:283
const Adj2_ & _adj2
second adjactor
Definition: adjactor.hpp:279
CompositeAdjactor(const Adj1_ &adjactor1, const Adj2_ &adjactor2)
Constructor.
Definition: adjactor.hpp:428
FEAT namespace.
Definition: adjactor.hpp:12
std::uint64_t Index
Index data type.