walberla::field::FieldIterator< T, fieldFSize > Class Template Reference

Detailed Description

template<typename T, uint_t fieldFSize>
class walberla::field::FieldIterator< T, fieldFSize >

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

Implementation

#include <FieldIterator.h>

+ Inheritance diagram for walberla::field::FieldIterator< T, fieldFSize >:

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 FieldTypegetField () 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 FieldTypef_
 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_tcurX_
 
cell_idx_tcurY_
 
cell_idx_tcurZ_
 
cell_idx_tcurF_
 
void initCoordinateAccessOptimizationPointers ()
 Initializes pointers required for the optimized x(),y(),z(),f() functions See documentation of fastestCoord_, curX_, curY_, curZ_ and curF_. More...
 

Member Typedef Documentation

◆ difference_type

template<typename T , uint_t fieldFSize>
using walberla::field::FieldIterator< T, fieldFSize >::difference_type = std::ptrdiff_t

◆ FieldType

template<typename T , uint_t fieldFSize>
using walberla::field::FieldIterator< T, fieldFSize >::FieldType = Field<typename std::remove_const<T>::type, fieldFSize>

◆ iterator_category

template<typename T , uint_t fieldFSize>
using walberla::field::FieldIterator< T, fieldFSize >::iterator_category = std::forward_iterator_tag

◆ pointer

template<typename T , uint_t fieldFSize>
using walberla::field::FieldIterator< T, fieldFSize >::pointer = T*

◆ reference

template<typename T , uint_t fieldFSize>
using walberla::field::FieldIterator< T, fieldFSize >::reference = T&

◆ value_type

template<typename T , uint_t fieldFSize>
using walberla::field::FieldIterator< T, fieldFSize >::value_type = T

Constructor & Destructor Documentation

◆ FieldIterator() [1/3]

template<typename T , uint_t fieldFSize>
walberla::field::FieldIterator< T, fieldFSize >::FieldIterator ( const FieldIterator< T, fieldFSize > &  other)

◆ FieldIterator() [2/3]

template<typename T , uint_t fs>
walberla::field::FieldIterator< T, fs >::FieldIterator
explicitprotected

Constructs an end iterator, which is represented by NULL pointers.

◆ FieldIterator() [3/3]

template<typename T , uint_t fieldFSize>
walberla::field::FieldIterator< T, fieldFSize >::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 
)
explicitprotected

Member Function Documentation

◆ cell()

template<typename T , uint_t fs>
Cell walberla::field::FieldIterator< T, fs >::cell
inline

◆ decrementLine()

template<typename T , uint_t fs>
void walberla::field::FieldIterator< T, fs >::decrementLine
inlineprotected

Decrements the slower 3 coordinates, if innermost coordinate is at beginning.

◆ f()

template<typename T , uint_t fs>
cell_idx_t walberla::field::FieldIterator< T, fs >::f
inline

◆ getF() [1/2]

template<typename T , uint_t fs>
T & walberla::field::FieldIterator< T, fs >::getF ( cell_idx_t  cf) const
inline

For beginXYZ iterators, one often needs a specific f Assumes that iterator stands at f==0.

Parameters
cfDelta for f

◆ getF() [2/2]

template<typename T , uint_t fs>
T & walberla::field::FieldIterator< T, fs >::getF ( uint_t  cf) const
inline

Equivalent to neighbor(cell_idx_t) see above.

Takes an uint_t instead a cell_idx_t, since stencil::toIndex() returns uint_t

Parameters
cfDelta for f

◆ getField()

template<typename T , uint_t fieldFSize>
const FieldType* walberla::field::FieldIterator< T, fieldFSize >::getField ( ) const
inline

◆ incrementLine()

template<typename T , uint_t fs>
void walberla::field::FieldIterator< T, fs >::incrementLine
inlineprotected

Increments the slower 3 coordinates, if innermost coordinate is at end.

◆ initCoordinateAccessOptimizationPointers()

template<typename T , uint_t fs>
void walberla::field::FieldIterator< T, fs >::initCoordinateAccessOptimizationPointers
protected

Initializes pointers required for the optimized x(),y(),z(),f() functions See documentation of fastestCoord_, curX_, curY_, curZ_ and curF_.

◆ neighbor() [1/4]

template<typename T , uint_t fs>
T & walberla::field::FieldIterator< T, fs >::neighbor ( cell_idx_t  cx,
cell_idx_t  cy,
cell_idx_t  cz,
cell_idx_t  cf = 0 
) const
inline

Neighbor access relative to current position.

Parameters
cxDelta for x
cyDelta for y
czDelta for z
cfDelta for f

◆ neighbor() [2/4]

template<typename T , uint_t fs>
T & walberla::field::FieldIterator< T, fs >::neighbor ( cell_idx_t  cx,
cell_idx_t  cy,
cell_idx_t  cz,
uint_t  cf 
) const
inline

Neighbor variant that takes unsigned int as f parameter, needed since the stencil toIdx() is an unsigned int.

Parameters
cxDelta for x
cyDelta for y
czDelta for z
cfDelta for f

◆ neighbor() [3/4]

template<typename T , uint_t fs>
T & walberla::field::FieldIterator< T, fs >::neighbor ( stencil::Direction  d,
cell_idx_t  cf = 0 
) const
inline

Neighbor access relative to current position.

Parameters
dDirection enumeration which defines deltas for x,y,z
cfDelta for f

◆ neighbor() [4/4]

template<typename T , uint_t fs>
T & walberla::field::FieldIterator< T, fs >::neighbor ( stencil::Direction  d,
uint_t  cf 
) const
inline

uint_t variant of above function

Parameters
dDirection enumeration which defines deltas for x,y,z
cfDelta for f

◆ operator const FieldIterator< const T, fieldFSize > &()

template<typename T , uint_t fieldFSize>
walberla::field::FieldIterator< T, fieldFSize >::operator const FieldIterator< const T, fieldFSize > & ( ) const
inline

◆ operator!=()

template<typename T , uint_t fieldFSize>
bool walberla::field::FieldIterator< T, fs >::operator!= ( const FieldIterator< T, fieldFSize > &  it) const
inline

Unequal operator.

◆ operator*()

template<typename T , uint_t fieldFSize>
T& walberla::field::FieldIterator< T, fieldFSize >::operator* ( ) const
inline

◆ operator->()

template<typename T , uint_t fieldFSize>
T* walberla::field::FieldIterator< T, fieldFSize >::operator-> ( ) const
inline

◆ operator=()

template<typename T , uint_t fieldFSize>
FieldIterator< T, fs > & walberla::field::FieldIterator< T, fs >::operator= ( const FieldIterator< T, fieldFSize > &  other)

Assignment operator.

Required for pointer member cur*_

◆ operator==()

template<typename T , uint_t fieldFSize>
bool walberla::field::FieldIterator< T, fs >::operator== ( const FieldIterator< T, fieldFSize > &  it) const
inline

Equal operator.

Test equality only by comparing the internal pointer

Returns
true if both iterators are equal

◆ operator[]() [1/2]

template<typename T , uint_t fieldFSize>
T& walberla::field::FieldIterator< T, fieldFSize >::operator[] ( cell_idx_t  cf) const
inline

◆ operator[]() [2/2]

template<typename T , uint_t fieldFSize>
T& walberla::field::FieldIterator< T, fieldFSize >::operator[] ( uint_t  cf) const
inline

◆ print()

template<typename T , uint_t fs>
void walberla::field::FieldIterator< T, fs >::print ( std::ostream &  str) const
inline

◆ x()

template<typename T , uint_t fs>
cell_idx_t walberla::field::FieldIterator< T, fs >::x
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.

◆ y()

template<typename T , uint_t fs>
cell_idx_t walberla::field::FieldIterator< T, fs >::y
inline

◆ z()

template<typename T , uint_t fs>
cell_idx_t walberla::field::FieldIterator< T, fs >::z
inline

Friends And Related Function Documentation

◆ Field< typename std::remove_const< T >::type, fieldFSize >

template<typename T , uint_t fieldFSize>
friend class Field< typename std::remove_const< T >::type, fieldFSize >
friend

Member Data Documentation

◆ cur_

template<typename T , uint_t fieldFSize>
cell_idx_t walberla::field::FieldIterator< T, fieldFSize >::cur_[3]
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_.

◆ curF_

template<typename T , uint_t fieldFSize>
cell_idx_t* walberla::field::FieldIterator< T, fieldFSize >::curF_
protected

◆ curX_

template<typename T , uint_t fieldFSize>
cell_idx_t* walberla::field::FieldIterator< T, fieldFSize >::curX_
protected

◆ curY_

template<typename T , uint_t fieldFSize>
cell_idx_t* walberla::field::FieldIterator< T, fieldFSize >::curY_
protected

◆ curZ_

template<typename T , uint_t fieldFSize>
cell_idx_t* walberla::field::FieldIterator< T, fieldFSize >::curZ_
protected

◆ f_

template<typename T , uint_t fieldFSize>
const FieldType* walberla::field::FieldIterator< T, fieldFSize >::f_
protected

Field where iterator belongs to.

◆ F_SIZE

template<typename T , uint_t fieldFSize>
const uint_t walberla::field::FieldIterator< T, fieldFSize >::F_SIZE = fieldFSize
static

◆ fastestCoord_

template<typename T , uint_t fieldFSize>
cell_idx_t walberla::field::FieldIterator< T, fieldFSize >::fastestCoord_
mutableprotected

◆ fBegin_

template<typename T , uint_t fieldFSize>
cell_idx_t walberla::field::FieldIterator< T, fieldFSize >::fBegin_
protected

◆ lineBegin_

template<typename T , uint_t fieldFSize>
T* walberla::field::FieldIterator< T, fieldFSize >::lineBegin_
protected

Points to begin of fastest coordinate line.

◆ lineEnd_

template<typename T , uint_t fieldFSize>
T* walberla::field::FieldIterator< T, fieldFSize >::lineEnd_
protected

Points to end of current line.

◆ linePtr_

template<typename T , uint_t fieldFSize>
T* walberla::field::FieldIterator< T, fieldFSize >::linePtr_
protected

Point to current element.

◆ sizes_

template<typename T , uint_t fieldFSize>
uint_t walberla::field::FieldIterator< T, fieldFSize >::sizes_[4]
protected

Size of each coordinate.

◆ skips_

template<typename T , uint_t fieldFSize>
uint_t walberla::field::FieldIterator< T, fieldFSize >::skips_[4]
protected

Number of elements to skip when coordinate wraps around.

◆ xBegin_

template<typename T , uint_t fieldFSize>
cell_idx_t walberla::field::FieldIterator< T, fieldFSize >::xBegin_
protected

Following offset values are only used in functions x(),y(),z(),f()

◆ yBegin_

template<typename T , uint_t fieldFSize>
cell_idx_t walberla::field::FieldIterator< T, fieldFSize >::yBegin_
protected

◆ zBegin_

template<typename T , uint_t fieldFSize>
cell_idx_t walberla::field::FieldIterator< T, fieldFSize >::zBegin_
protected

The documentation for this class was generated from the following files: