PSCF v1.1
Public Member Functions | List of all members
Util::GridArray< Data > Class Template Reference

Multi-dimensional array with the dimensionality of space. More...

#include <GridArray.h>

Public Member Functions

 GridArray ()
 Constructor. More...
 
 GridArray (GridArray< Data > const &other)
 Copy constructor. More...
 
 ~GridArray ()
 Destructor. More...
 
GridArray< Data > & operator= (GridArray< Data > const &other)
 Assignment. More...
 
void allocate (IntVector const &dimensions)
 Allocate memory for a matrix. More...
 
template<class Archive >
void serialize (Archive &ar, const unsigned int version)
 Serialize a GridArray to/from an Archive. More...
 
bool isAllocated () const
 Return true if the GridArray has been allocated, false otherwise. More...
 
IntVector const & dimensions ()
 Get all dimensions of array as an IntVector. More...
 
int dimension (int i) const
 Get number of grid points along 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 (IntVector const &position) const
 Get the rank of a grid point with specified position. More...
 
bool isInGrid (int coordinate, int i) const
 Is this 1D coordinate in range? More...
 
bool isInGrid (IntVector &position) const
 Is this position within the grid? More...
 
int shift (int &coordinate, int i) const
 Shift a periodic 1D coordinate into primary range. More...
 
IntVector shift (IntVector &position) const
 Shift a periodic position into primary grid. More...
 
Data const & operator[] (int rank) const
 Return element by const reference, indexed by 1D rank. More...
 
Data & operator[] (int rank)
 Return element by reference, indexed by 1D rank. More...
 
Data const & operator() (IntVector const &position) const
 Return element by const reference, indexed by IntVector position. More...
 
Data & operator() (IntVector const &position)
 Return element by reference, indexed by IntVector position. More...
 

Detailed Description

template<typename Data>
class Util::GridArray< Data >

Multi-dimensional array with the dimensionality of space.

The memory for a GridArray is stored in a single one-dimensional C array. The subscript [] operator is overloaded to return an element indexed by a one-dimensional rank, and the () operator is overloaded to return an element indexed by an IntVector of grid coordinates.

Definition at line 28 of file GridArray.h.

Constructor & Destructor Documentation

◆ GridArray() [1/2]

template<typename Data >
Util::GridArray< Data >::GridArray
inline

Constructor.

Constructor (protected).

Definition at line 217 of file GridArray.h.

◆ GridArray() [2/2]

template<typename Data >
Util::GridArray< Data >::GridArray ( GridArray< Data > const &  other)

Copy constructor.

Definition at line 242 of file GridArray.h.

References Util::GridArray< Data >::allocate(), Util::GridArray< Data >::isAllocated(), and UTIL_THROW.

◆ ~GridArray()

template<typename Data >
Util::GridArray< Data >::~GridArray

Destructor.

Delete dynamically allocated C array, if allocated.

Definition at line 230 of file GridArray.h.

Member Function Documentation

◆ operator=()

template<typename Data >
GridArray< Data > & Util::GridArray< Data >::operator= ( GridArray< Data > const &  other)

Assignment.

Definition at line 273 of file GridArray.h.

References UTIL_THROW.

◆ allocate()

template<typename Data >
void Util::GridArray< Data >::allocate ( IntVector const &  dimensions)

Allocate memory for a matrix.

Parameters
dimensionsIntVector containing dimensions

Definition at line 313 of file GridArray.h.

References Util::Dimension, and UTIL_THROW.

Referenced by Util::GridArray< Data >::GridArray().

◆ serialize()

template<class Data >
template<class Archive >
void Util::GridArray< Data >::serialize ( Archive &  ar,
const unsigned int  version 
)

Serialize a GridArray to/from an Archive.

Parameters
ararchive
versionarchive version id

Definition at line 337 of file GridArray.h.

◆ isAllocated()

template<class Data >
bool Util::GridArray< Data >::isAllocated
inline

Return true if the GridArray has been allocated, false otherwise.

Definition at line 519 of file GridArray.h.

Referenced by Util::GridArray< Data >::GridArray().

◆ dimensions()

template<typename Data >
IntVector const & Util::GridArray< Data >::dimensions
inline

Get all dimensions of array as an IntVector.

Returns
IntVector containing number of elements in each direction.

Definition at line 358 of file GridArray.h.

◆ dimension()

template<class Data >
int Util::GridArray< Data >::dimension ( int  i) const
inline

Get number of grid points along direction i.

Parameters
iindex of Cartesian direction 0 <=i < 3.

Definition at line 365 of file GridArray.h.

◆ size()

template<class Data >
int Util::GridArray< Data >::size
inline

◆ position()

template<typename Data >
IntVector Util::GridArray< Data >::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 405 of file GridArray.h.

References Util::Dimension.

◆ rank()

template<typename Data >
int Util::GridArray< Data >::rank ( IntVector const &  position) const
inline

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 395 of file GridArray.h.

◆ isInGrid() [1/2]

template<typename Data >
bool Util::GridArray< Data >::isInGrid ( int  coordinate,
int  i 
) const

Is this 1D coordinate in range?

Returns true iff 0 <= coordinate < dimension(i).

Parameters
coordinatecoordinate value for direction i
iindex for Cartesian direction

Definition at line 423 of file GridArray.h.

◆ isInGrid() [2/2]

template<typename Data >
bool Util::GridArray< Data >::isInGrid ( IntVector position) const

Is this position within the grid?

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

Parameters
positiongrid point position

Definition at line 437 of file GridArray.h.

References Util::Dimension.

◆ shift() [1/2]

template<typename Data >
int Util::GridArray< Data >::shift ( int &  coordinate,
int  i 
) const

Shift a periodic 1D coordinate into primary 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 453 of file GridArray.h.

◆ shift() [2/2]

template<typename Data >
IntVector Util::GridArray< Data >::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 469 of file GridArray.h.

References Util::Dimension.

◆ operator[]() [1/2]

template<typename Data >
Data const & Util::GridArray< Data >::operator[] ( int  rank) const
inline

Return element by const reference, indexed by 1D rank.

Parameters
rank1D array index of element

Definition at line 482 of file GridArray.h.

◆ operator[]() [2/2]

template<typename Data >
Data & Util::GridArray< Data >::operator[] ( int  rank)
inline

Return element by reference, indexed by 1D rank.

Parameters
rank1D rank of element

Definition at line 489 of file GridArray.h.

◆ operator()() [1/2]

template<typename Data >
Data const & Util::GridArray< Data >::operator() ( IntVector const &  position) const
inline

Return element by const reference, indexed by IntVector position.

Parameters
positionIntVector of coordinates.

Definition at line 497 of file GridArray.h.

◆ operator()() [2/2]

template<typename Data >
Data & Util::GridArray< Data >::operator() ( IntVector const &  position)
inline

Return element by reference, indexed by IntVector position.

Parameters
positionIntVector of coordinates.

Definition at line 505 of file GridArray.h.


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