Iterator over a 4D array, stored linearized in memory.
The iterator is created by specifying a field slice. It supports neighbor access and knows its own x,y,z,f coordinates.
This is NOT a lightweight object as most iterators are, since it has to store begin and end for each of the four dimensions plus some data to speed up the calculation of current coordinate.
The FieldIterator itself cannot change the position it points to. The ForwardFieldIterator and ReverseFieldIterator are derived from this class and provide the according operators. When writing a function that calculates something in a specific cell should take a FieldIterator as argument ( not Forward- or ReverseFieldIterators ) so that it can be called with both Forward and Reverse iterators. For this case there is also a more generic way: see walberla::field::FieldPointer
#include <FieldIterator.h>
Public Types | |
using | iterator_category = std::forward_iterator_tag |
using | value_type = T |
using | difference_type = std::ptrdiff_t |
using | pointer = T * |
using | reference = T & |
using | FieldType = Field< typename std::remove_const< T >::type, fieldFSize > |
Public Member Functions | |
Copy Operations | |
FieldIterator (const FieldIterator< T, fieldFSize > &other) | |
FieldIterator< T, fieldFSize > & | operator= (const FieldIterator< T, fieldFSize > &other) |
Assignment operator. More... | |
Operators | |
bool | operator== (const FieldIterator &it) const |
Equal operator. More... | |
bool | operator!= (const FieldIterator &it) const |
Unequal operator. More... | |
operator const FieldIterator< const T, fieldFSize > & () const | |
Access Functions | |
T & | operator* () const |
T * | operator-> () const |
T & | getF (cell_idx_t cf) const |
For beginXYZ iterators, one often needs a specific f Assumes that iterator stands at f==0. More... | |
T & | getF (uint_t cf) const |
Equivalent to neighbor(cell_idx_t) see above. More... | |
T & | operator[] (cell_idx_t cf) const |
T & | operator[] (uint_t cf) const |
T & | neighbor (stencil::Direction d, cell_idx_t cf=0) const |
Neighbor access relative to current position. More... | |
T & | neighbor (stencil::Direction d, uint_t cf) const |
uint_t variant of above function More... | |
T & | neighbor (cell_idx_t cx, cell_idx_t cy, cell_idx_t cz, cell_idx_t cf=0) const |
Neighbor access relative to current position. More... | |
T & | neighbor (cell_idx_t cx, cell_idx_t cy, cell_idx_t cz, uint_t cf) const |
Neighbor variant that takes unsigned int as f parameter, needed since the stencil toIdx() is an unsigned int. More... | |
Coordinates of current position | |
cell_idx_t | x () const |
In order to get x(), y(), z(), f() function as fast a possible, no if clause for the layout was introduced. More... | |
cell_idx_t | y () const |
cell_idx_t | z () const |
cell_idx_t | f () const |
Cell | cell () const |
Utility Functions | |
void | print (std::ostream &str) const |
const FieldType * | getField () const |
Static Public Attributes | |
static const uint_t | F_SIZE = fieldFSize |
Constructor/Destructor | |
class | Field< typename std::remove_const< T >::type, fieldFSize > |
T * | lineBegin_ |
Points to begin of fastest coordinate line. More... | |
T * | linePtr_ |
Point to current element. More... | |
T * | lineEnd_ |
Points to end of current line. More... | |
cell_idx_t | cur_ [3] |
In the following vectors [0] is the slowest and [3] the fastest coordinate Current values of the coordinates, forth coordinate implicitly stored in linePtr_ and if needed written to fastestCoord_. More... | |
uint_t | skips_ [4] |
Number of elements to skip when coordinate wraps around. More... | |
uint_t | sizes_ [4] |
Size of each coordinate. More... | |
const FieldType * | f_ |
Field where iterator belongs to. More... | |
cell_idx_t | xBegin_ |
Following offset values are only used in functions x(),y(),z(),f() More... | |
cell_idx_t | yBegin_ |
cell_idx_t | zBegin_ |
cell_idx_t | fBegin_ |
FieldIterator () | |
Constructs an end iterator, which is represented by NULL pointers. More... | |
FieldIterator (const FieldType *f, cell_idx_t xBeg, cell_idx_t yBeg, cell_idx_t zBeg, cell_idx_t fBeg, uint_t xSize, uint_t ySize, uint_t zSize, uint_t fSize, bool forward) | |
void | incrementLine () |
Increments the slower 3 coordinates, if innermost coordinate is at end. More... | |
void | decrementLine () |
Decrements the slower 3 coordinates, if innermost coordinate is at beginning. More... | |
Speeding up x(), y(), z(), f() functions | |
The following members are only needed to speed up the x(), y(), z(), f() functions. In order to get x(), y(), z(), f() function as fast a possible, no if clause for the layout was introduced. Instead there are the cur[XYZF]_ members, that point to the cur_ array. The cur_ array does not store the fastest coordinate, because it is implicitly stored in (linePtr_ - lineBegin_). If it would be stored explicitly there would have to be an extra update operation in operator++() , which should be as fast as possible. The curX_ or curF_ pointer points to the fastestCoord_ member, which always has to be updated before curX_ or curF_ is dereferenced. | |
cell_idx_t | fastestCoord_ |
cell_idx_t * | curX_ |
cell_idx_t * | curY_ |
cell_idx_t * | curZ_ |
cell_idx_t * | curF_ |
void | initCoordinateAccessOptimizationPointers () |
Initializes pointers required for the optimized x(),y(),z(),f() functions See documentation of fastestCoord_, curX_, curY_, curZ_ and curF_. More... | |
using walberla::field::FieldIterator< T, fieldFSize >::difference_type = std::ptrdiff_t |
using walberla::field::FieldIterator< T, fieldFSize >::FieldType = Field<typename std::remove_const<T>::type, fieldFSize> |
using walberla::field::FieldIterator< T, fieldFSize >::iterator_category = std::forward_iterator_tag |
using walberla::field::FieldIterator< T, fieldFSize >::pointer = T* |
using walberla::field::FieldIterator< T, fieldFSize >::reference = T& |
using walberla::field::FieldIterator< T, fieldFSize >::value_type = T |
walberla::field::FieldIterator< T, fieldFSize >::FieldIterator | ( | const FieldIterator< T, fieldFSize > & | other | ) |
|
explicitprotected |
Constructs an end iterator, which is represented by NULL pointers.
|
explicitprotected |
|
inline |
|
inlineprotected |
Decrements the slower 3 coordinates, if innermost coordinate is at beginning.
|
inline |
|
inline |
For beginXYZ iterators, one often needs a specific f Assumes that iterator stands at f==0.
cf | Delta for f |
|
inline |
Equivalent to neighbor(cell_idx_t) see above.
Takes an uint_t instead a cell_idx_t, since stencil::toIndex() returns uint_t
cf | Delta for f |
|
inline |
|
inlineprotected |
Increments the slower 3 coordinates, if innermost coordinate is at end.
|
protected |
|
inline |
Neighbor access relative to current position.
cx | Delta for x |
cy | Delta for y |
cz | Delta for z |
cf | Delta for f |
|
inline |
Neighbor variant that takes unsigned int as f parameter, needed since the stencil toIdx() is an unsigned int.
cx | Delta for x |
cy | Delta for y |
cz | Delta for z |
cf | Delta for f |
|
inline |
Neighbor access relative to current position.
d | Direction enumeration which defines deltas for x,y,z |
cf | Delta for f |
|
inline |
uint_t variant of above function
d | Direction enumeration which defines deltas for x,y,z |
cf | Delta for f |
|
inline |
|
inline |
Unequal operator.
|
inline |
|
inline |
FieldIterator< T, fs > & walberla::field::FieldIterator< T, fs >::operator= | ( | const FieldIterator< T, fieldFSize > & | other | ) |
Assignment operator.
Required for pointer member cur*_
|
inline |
Equal operator.
Test equality only by comparing the internal pointer
|
inline |
|
inline |
|
inline |
|
inline |
In order to get x(), y(), z(), f() function as fast a possible, no if clause for the layout was introduced.
Instead there are the cur[XYZF]_ members, that point to the cur_ array. The cur_ array does not store the fastest coordinate, because it is implicitly stored in (linePtr_ - lineBegin_). If it would be stored explicitly there would have to be an extra update operation in operator++() , which should be as fast as possible. The curX_ or curF_ pointer points to the fastestCoord_ member, which always has to be updated before curX_ or curF_ is dereferenced.
|
inline |
|
inline |
|
friend |
|
protected |
In the following vectors [0] is the slowest and [3] the fastest coordinate Current values of the coordinates, forth coordinate implicitly stored in linePtr_ and if needed written to fastestCoord_.
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
Field where iterator belongs to.
|
static |
|
mutableprotected |
|
protected |
|
protected |
Points to begin of fastest coordinate line.
|
protected |
Points to end of current line.
|
protected |
Point to current element.
|
protected |
Size of each coordinate.
|
protected |
Number of elements to skip when coordinate wraps around.
|
protected |
|
protected |
|
protected |