PSCF v1.1
Public Member Functions | List of all members
Util::Grid Class Reference

A grid of points indexed by integer coordinates. More...

#include <Grid.h>

Public Member Functions

 Grid ()
 Default constructor. More...
 
 Grid (const IntVector &dimensions)
 Constructor. More...
 
void setDimensions (const IntVector &dimensions)
 Set the grid dimensions in all directions. More...
 
IntVector dimensions () const
 Get an IntVector of the grid dimensions. More...
 
int dimension (int i) const
 Get grid dimension along Cartesian direction i. More...
 
int size () const
 Get total number of grid points. More...
 
IntVector position (int rank) const
 Get the position IntVector of a grid point with a specified rank. More...
 
int rank (const IntVector &position) const
 Get the rank of a grid point with specified position. More...
 
bool isInGrid (int coordinate, int i) const
 Is this coordinate in range? More...
 
bool isInGrid (IntVector &position) const
 Is this IntVector grid position within the grid? More...
 
int shift (int &coordinate, int i) const
 Shift a periodic coordinate into range. More...
 
IntVector shift (IntVector &position) const
 Shift a periodic position into primary grid. More...
 

Detailed Description

A grid of points indexed by integer coordinates.

The coordinates of a point on a grid form an IntVector, referred to here as a grid position. Each element of a grid position must lie in the range 0 <= position[i] < dimension(i), where i indexes a Cartesian axis, and dimension(i) is the dimension of the grid along axis i.

Each grid position is also assigned a non-negative integer rank.
Grid position ranks are ordered sequentially like elements in a multi-dimensional C array, with the last coordinate being the most rapidly varying.

Definition at line 33 of file Grid.h.

Constructor & Destructor Documentation

◆ Grid() [1/2]

Util::Grid::Grid ( )

Default constructor.

Definition at line 15 of file Grid.cpp.

References dimensions(), and setDimensions().

◆ Grid() [2/2]

Util::Grid::Grid ( const IntVector dimensions)

Constructor.

Parameters
dimensionsIntVector of grid dimensions

Definition at line 24 of file Grid.cpp.

References dimensions(), and setDimensions().

Member Function Documentation

◆ setDimensions()

void Util::Grid::setDimensions ( const IntVector dimensions)

Set the grid dimensions in all directions.

Parameters
dimensionsIntVector of grid dimensions.

Definition at line 32 of file Grid.cpp.

References Util::Dimension, dimensions(), and UTIL_THROW.

Referenced by Grid().

◆ dimensions()

IntVector Util::Grid::dimensions ( ) const
inline

Get an IntVector of the grid dimensions.

Definition at line 156 of file Grid.h.

Referenced by Grid(), and setDimensions().

◆ dimension()

int Util::Grid::dimension ( int  i) const
inline

Get grid dimension along Cartesian direction i.

Parameters
iindex of Cartesian direction 0 <=i < Util::Dimension

Definition at line 159 of file Grid.h.

References Util::Dimension.

◆ size()

int Util::Grid::size ( ) const
inline

◆ position()

IntVector Util::Grid::position ( int  rank) const

Get the position IntVector of a grid point with a specified rank.

Parameters
rankinteger rank of a grid point.
Returns
IntVector containing coordinates of specified point.

Definition at line 64 of file Grid.cpp.

References Util::Dimension, and position().

Referenced by isInGrid(), position(), rank(), and shift().

◆ rank()

int Util::Grid::rank ( const IntVector position) const

Get the rank of a grid point with specified position.

Parameters
positioninteger position of a grid point
Returns
integer rank of specified grid point

Definition at line 49 of file Grid.cpp.

References Util::Dimension, and position().

◆ isInGrid() [1/2]

bool Util::Grid::isInGrid ( int  coordinate,
int  i 
) const

Is this coordinate in range?

Parameters
coordinatecoordinate value for direction i
iindex for Cartesian direction
Returns
true iff 0 <= coordinate < dimension(i).

Definition at line 78 of file Grid.cpp.

◆ isInGrid() [2/2]

bool Util::Grid::isInGrid ( IntVector position) const

Is this IntVector grid position within the grid?

Returns true iff 0 <= coordinate[i] < dimension(i) for all i.

Parameters
positiongrid point position
Returns
true iff 0 <= coordinate[i] < dimension(i) for all i.

Definition at line 88 of file Grid.cpp.

References Util::Dimension, and position().

◆ shift() [1/2]

int Util::Grid::shift ( int &  coordinate,
int  i 
) const

Shift a periodic coordinate into range.

Upon return, the coordinate will be shifted to lie within the range 0 <= coordinate < dimension(i) by subtracting an integer multiple of dimension(i), giving coordinate - shift*dimension(i). The return value is the required integer ‘shift’.

Parameters
coordinatecoordinate in Cartesian direction i.
iindex of Cartesian direction, i >= 0.
Returns
multiple of dimension(i) subtracted from input value.

Definition at line 100 of file Grid.cpp.

References shift().

Referenced by shift().

◆ shift() [2/2]

IntVector Util::Grid::shift ( IntVector position) const

Shift a periodic position into primary grid.

Upon return, each element of the parameter position is shifted to lie within the range 0 <= position[i] < dimension(i) by adding or subtracting an integer multiple of dimension(i). The IntVector of shift values is returned.

Parameters
positionIntVector position within a grid.
Returns
IntVector of integer shifts.

Definition at line 112 of file Grid.cpp.

References Util::Dimension, position(), and shift().


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