G+Smo  23.12.0
Geometry + Simulation Modules
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
gsGridIterator< Z, mode, d, true > Class Template Reference

Detailed Description

template<class Z, int mode, short_t d>
class gismo::gsGridIterator< Z, mode, d, true >

Iterator over the Cartesian product of integer points in a tensor-product grid.

The iteration is done in lexicographic order.

  • mode = 0 : iteration over [a, b) or [a, b] gsGridIterator<T,CUBE> grid(a,b);
  • mode = 1 : iteration over the boundry points of [a, b) or [a, b] gsGridIterator<T,BDR> grid(a,b);
  • mode = 2 : iteration over the vertices of [a, b) or [a, b] gsGridIterator<T,VERTEX> grid(a,b);

The open or closed case is determined by a constructor flag. A third argument, eg. gsGridIterator<T,CUBE,d> grid(a,b); specifies fixed size dimension d

Note
Iteration over the boundary including offsets is possible using the free functions in gsUtils/gsCombinatorics.h
Template Parameters
Ztype of the integer coordinates of the index vector
dstatically known dimension, or dynamic dimension if d = -1 (default value)
mode0: all integer points in [a,b], 1: all points in [a,b), 2: vertices of cube [a,b]
+ Collaboration diagram for gsGridIterator< Z, mode, d, true >:

Public Member Functions

 gsGridIterator ()
 Empty constructor.
 
 gsGridIterator (point const &a, point const &b, bool open=true)
 Constructor using lower and upper limits. More...
 
 gsGridIterator (point const &b, bool open=true)
 Constructor using upper limit. The iteration starts from zero. More...
 
 gsGridIterator (gsMatrix< Z, d, 2 > const &ab, bool open=true)
 Constructor using lower and upper limits. More...
 
bool isBoundary () const
 Returns true if the current point lies on a boundary.
 
bool isCeil (int i) const
 Returns true if the i-th coordinate has maximal value.
 
bool isFloor (int i) const
 Returns true if the i-th coordinate has minimal value.
 
const pointlower () const
 Returns the first point in the iteration.
 
index_t numPoints () const
 Returns the total number of points that are iterated.
 
point numPointsCwise () const
 Returns the total number of points per coordinate which are iterated.
 
void reset (point const &a, point const &b, bool open=true)
 Resets the iterator using new lower and upper limits. More...
 
void reset ()
 Resets the iterator, so that a new iteration over the points may start.
 
point strides () const
 Utility function which returns the vector of strides. More...
 
const pointupper () const
 Returns the last point in the iteration.
 

Private Attributes

point m_cur
 Current point pointed at by the iterator.
 
point m_upp
 Iteration lower and upper limits.
 
bool m_valid
 Indicates the state of the iterator.
 

Constructor & Destructor Documentation

gsGridIterator ( point const &  a,
point const &  b,
bool  open = true 
)
inline

Constructor using lower and upper limits.

Parameters
alower limit (vertex of a cube)
bupper limit (vertex of a cube)
openif true, the iteration is performed for the points in $[a_i,b_i)$
gsGridIterator ( point const &  b,
bool  open = true 
)
inlineexplicit

Constructor using upper limit. The iteration starts from zero.

Parameters
bupper limit (vertex of a cube)
openif true, the iteration is performed for the points in $[0,b_i)$
gsGridIterator ( gsMatrix< Z, d, 2 > const &  ab,
bool  open = true 
)
inlineexplicit

Constructor using lower and upper limits.

Parameters
abMatrix with two columns, corresponding to lower and upper limits
openif true, the iteration is performed for the points in $[a_i,b_i)$

Member Function Documentation

void reset ( point const &  a,
point const &  b,
bool  open = true 
)
inline

Resets the iterator using new lower and upper limits.

Parameters
alower limit (vertex of a cube)
bupper limit (vertex of a cube)
openif true, the iteration is performed for the points in $[a_i,b_i)$
point strides ( ) const
inline

Utility function which returns the vector of strides.

Returns
An integer vector (stride vector). the entry \(s_i\) implies that the current \(i\)-th coordinate of the iterated point will appear again after \(s_i\) increments. Moreover, the dot product of (*this - this->lower()) with the stride vector results in the "flat index", i.e. the cardinal index of the point in the iteration sequence.

If the iteration starts from the point zero (this->lower()==zero), then the stride vector has the property that that when we add it to *this we obtain the next point in the iteration sequence. In this case the flat index is obtained by taking the dot product with *this.