OPAL (Object Oriented Parallel Accelerator Library)  2.2.0
OPAL
Public Member Functions | Protected Member Functions | Private Attributes | Friends | List of all members
interpolation::NDGrid Class Reference

#include <NDGrid.h>

Inheritance diagram for interpolation::NDGrid:
Inheritance graph
[legend]
Collaboration diagram for interpolation::NDGrid:
Collaboration graph
[legend]

Public Member Functions

NDGridclone ()
 
Meshdual () const
 
 NDGrid ()
 ////// NDGrid /////// More...
 
 NDGrid (int nDimensions, int *size, double *spacing, double *min)
 
 NDGrid (std::vector< int > size, std::vector< const double * > gridCoordinates)
 
 NDGrid (std::vector< std::vector< double > > gridCoordinates)
 
 ~NDGrid ()
 
double & coord (const int &index, const int &dimension)
 
const double & coord (const int &index, const int &dimension) const
 
int size (const int &dimension) const
 
std::vector< double > coordVector (const int &dimension) const
 
double * newCoordArray (const int &dimension) const
 
void coordLowerBound (const double &x, const int &dimension, int &xIndex) const
 
void lowerBound (const std::vector< double > &pos, std::vector< int > &xIndex) const
 
double min (const int &dimension) const
 
double max (const int &dimension) const
 
void setCoord (int dimension, int nCoords, double *x)
 
Mesh::Iterator begin () const
 
Mesh::Iterator end () const
 
void getPosition (const Mesh::Iterator &it, double *position) const
 
int getPositionDimension () const
 
bool getConstantSpacing () const
 
void setConstantSpacing (bool spacing)
 
void setConstantSpacing (double tolerance_m=1e-9)
 
int toInteger (const Mesh::Iterator &lhs) const
 
Mesh::Iterator getNearest (const double *position) const
 
- Public Member Functions inherited from interpolation::Mesh
 Mesh ()
 
virtual ~Mesh ()
 

Protected Member Functions

virtual Mesh::IteratoraddEquals (Mesh::Iterator &lhs, int difference) const
 
virtual Mesh::IteratorsubEquals (Mesh::Iterator &lhs, int difference) const
 
virtual Mesh::IteratoraddEquals (Mesh::Iterator &lhs, const Mesh::Iterator &rhs) const
 
virtual Mesh::IteratorsubEquals (Mesh::Iterator &lhs, const Mesh::Iterator &rhs) const
 
virtual Mesh::IteratoraddOne (Mesh::Iterator &lhs) const
 
virtual Mesh::IteratorsubOne (Mesh::Iterator &lhs) const
 
virtual bool isGreater (const Mesh::Iterator &lhs, const Mesh::Iterator &rhs) const
 

Private Attributes

std::vector< std::vector
< double > > 
coord_m
 
std::vector< VectorMap * > maps_m
 
bool constantSpacing_m
 

Friends

Mesh::Iterator operator++ (Mesh::Iterator &lhs, int)
 
Mesh::Iterator operator-- (Mesh::Iterator &lhs, int)
 
Mesh::Iteratoroperator++ (Mesh::Iterator &lhs)
 
Mesh::Iteratoroperator-- (Mesh::Iterator &lhs)
 
Mesh::Iterator operator- (const Mesh::Iterator &lhs, const Mesh::Iterator &rhs)
 
Mesh::Iterator operator+ (const Mesh::Iterator &lhs, const Mesh::Iterator &rhs)
 
Mesh::Iteratoroperator-= (Mesh::Iterator &lhs, const Mesh::Iterator &rhs)
 
Mesh::Iteratoroperator+= (Mesh::Iterator &lhs, const Mesh::Iterator &rhs)
 
bool operator== (const Mesh::Iterator &lhs, const Mesh::Iterator &rhs)
 
bool operator!= (const Mesh::Iterator &lhs, const Mesh::Iterator &rhs)
 
bool operator>= (const Mesh::Iterator &lhs, const Mesh::Iterator &rhs)
 
bool operator<= (const Mesh::Iterator &lhs, const Mesh::Iterator &rhs)
 
bool operator< (const Mesh::Iterator &lhs, const Mesh::Iterator &rhs)
 
bool operator> (const Mesh::Iterator &lhs, const Mesh::Iterator &rhs)
 

Detailed Description

NDGrid holds grid information for a rectilinear grid in some arbitrary dimensional space.

NDGrid holds the necessary information for regular and irregular grid data for interpolation routines (but it all has to be rectilinear).

Where an irregular grid is used, we use std::lower_bound to find mapping from a generic point to the grid points.

NDGrid holds a list of pointers to VectorMaps that use the grid for interpolation and functions to Add and Remove VectorMaps. If the Remove function removes the last VectorMap, then the ThreeDGrid is deleted. It's a sort of smart pointer.

In general NDGrid is not bound checked.

Definition at line 57 of file NDGrid.h.

Constructor & Destructor Documentation

NDGrid::NDGrid ( )

////// NDGrid ///////

Build a default, empty grid with zero dimension

Definition at line 36 of file NDGrid.cpp.

Referenced by clone(), and dual().

NDGrid::NDGrid ( int  nDimensions,
int *  size,
double *  spacing,
double *  min 
)

Build a regular grid

Parameters
nDimensions,:number of dimensions of the grid
size,:array of ints of length nDimensions. Gives the number of grid points in each dimension. Caller owns the memory pointed to by size. Must be at least 1 grid point in each dimension.
spacing,:array of doubles of length nDimensions. Gives the grid spacing in each dimension. Caller owns memory pointed to by spacing.
min,:array of doubles of length nDimensions. Gives the coordinate of the zeroth element (origin). Caller owns the memory pointed to by min.

Definition at line 52 of file NDGrid.cpp.

References coord_m.

NDGrid::NDGrid ( std::vector< int >  size,
std::vector< const double * >  gridCoordinates 
)

Build an irregular grid

Parameters
size,:The number of grid points in each dimension. This vector must be the same length as gridCoordinates vector.
gridCoordinates,:vector of doubles, with the same length as size. Set the coordinates of the grid in each dimension. Caller owns the memory pointed to by gridCoordinates.

Definition at line 39 of file NDGrid.cpp.

References coord_m, and setConstantSpacing().

Here is the call graph for this function:

NDGrid::NDGrid ( std::vector< std::vector< double > >  gridCoordinates)

Build an irregular grid

Parameters
gridCoordinates,:Vector of size equal to the dimension of the grid. Element gridCoordinates[i][j] is the position of the jth grid coordinate in the ith dimension. i.e. to find the coordinates of the grid point (23, 17, 21) we would lookup gridCoordinate[0][23] gridCoordinate[1][17] gridCoordinate[2][21]

Definition at line 66 of file NDGrid.cpp.

References setConstantSpacing(), and size().

Here is the call graph for this function:

interpolation::NDGrid::~NDGrid ( )
inline

Destructor

Definition at line 110 of file NDGrid.h.

Member Function Documentation

Mesh::Iterator & NDGrid::addEquals ( Mesh::Iterator lhs,
int  difference 
) const
protectedvirtual

Add difference to lhs and then return lhs

Implements interpolation::Mesh.

Definition at line 88 of file NDGrid.cpp.

References coord_m, interpolation::Mesh::Iterator::state_m, and subEquals().

Referenced by addEquals(), and subEquals().

Here is the call graph for this function:

Mesh::Iterator & NDGrid::addEquals ( Mesh::Iterator lhs,
const Mesh::Iterator rhs 
) const
protectedvirtual

Add difference to lhs and then return lhs

Implements interpolation::Mesh.

Definition at line 139 of file NDGrid.cpp.

References addEquals(), and interpolation::Mesh::Iterator::toInteger().

Here is the call graph for this function:

Mesh::Iterator & NDGrid::addOne ( Mesh::Iterator lhs) const
protectedvirtual

Increment position of lhs by one and then return lhs

Implements interpolation::Mesh.

Definition at line 147 of file NDGrid.cpp.

References coord_m, and size().

Here is the call graph for this function:

Mesh::Iterator NDGrid::begin ( ) const
inlinevirtual

Returns the origin of the mesh (lowest possible index in all dimensions)

Implements interpolation::Mesh.

Definition at line 355 of file NDGrid.h.

References coord_m.

Referenced by DumpEMFields::writeFieldThis().

NDGrid * NDGrid::clone ( )
inlinevirtual

Inheritable copy constructor

Implements interpolation::Mesh.

Definition at line 347 of file NDGrid.h.

References NDGrid().

Referenced by DumpEMFields::clone().

Here is the call graph for this function:

double & NDGrid::coord ( const int &  index,
const int &  dimension 
)
inline

Get the coordinate of a set of grid points

Parameters
index,:the index of the grid point to be found; indexed from 1. Should be in range 1 <= index <= length
dimension,:the dimension of the grid point to be found. Should be in range 0 <= dimension < grid dimension

Note the coord is NOT bound checked - so it is a memory error to go out of the bounds.

Definition at line 299 of file NDGrid.h.

References coord_m.

Referenced by dual().

const double & NDGrid::coord ( const int &  index,
const int &  dimension 
) const
inline

Get the coordinate of a set of grid points

Parameters
index,:the index of the grid point to be found; indexed from 1. Should be in range 1 <= index <= length
dimension,:the dimension of the grid point to be found. Should be in range 0 <= dimension < grid dimension

Note the call is NOT bound checked - so it is a memory error to go out of the bounds.

Definition at line 303 of file NDGrid.h.

References coord_m.

void NDGrid::coordLowerBound ( const double &  x,
const int &  dimension,
int &  xIndex 
) const
inline

Get the grid point of the grid lower bound in a particular dimension

Parameters
x,:position in the grid coordinate
dimension,:the grid coordinate to search along
xIndex,:will be set with the resultant grid index

Sets xIndex to the index of the largest mesh position that is less than x in the given dimension. If x is less than all mesh positions, sets xIndex to -1.

Definition at line 315 of file NDGrid.h.

References constantSpacing_m, coord_m, and floor().

Referenced by lowerBound().

Here is the call graph for this function:

std::vector< double > NDGrid::coordVector ( const int &  dimension) const
inline

Get the vector of grid points along a particular dimension

Parameters
dimension,:the dimension of the grid point to be found. Should be in range 0 <= dimension < grid dimension

Note the call is NOT bound checked - so it is a memory error to go out of the bounds.

Definition at line 311 of file NDGrid.h.

References coord_m.

Mesh * NDGrid::dual ( ) const
virtual

Not implemented

Implements interpolation::Mesh.

Definition at line 228 of file NDGrid.cpp.

References coord(), coord_m, NDGrid(), and size().

Here is the call graph for this function:

Mesh::Iterator NDGrid::end ( ) const
inlinevirtual

Returns the end of the mesh (highest possible index in all dimensions)

Implements interpolation::Mesh.

Definition at line 359 of file NDGrid.h.

References coord_m.

Referenced by DumpEMFields::writeFieldThis(), and DumpEMFields::writeHeader().

bool NDGrid::getConstantSpacing ( ) const
inline

Returns true if the Mesh is a regular grid

Definition at line 377 of file NDGrid.h.

References constantSpacing_m.

Mesh::Iterator NDGrid::getNearest ( const double *  position) const
virtual

Return an iterator corresponding to nearest mesh point to position

Parameters
position,:Array of length dimension, giving a position near the grid.
Returns
iterator that points to the grid location closest to position.

Implements interpolation::Mesh.

Definition at line 206 of file NDGrid.cpp.

References coord_m, lowerBound(), and size().

Here is the call graph for this function:

void NDGrid::getPosition ( const Mesh::Iterator it,
double *  position 
) const
inlinevirtual

Get the position of the iterator

Parameters
it,:iterator on this Mesh
position,:double array of length equal to the mesh dimension. Filled with the iterator position. Caller owns the memory to which position points.

Implements interpolation::Mesh.

Definition at line 368 of file NDGrid.h.

References coord_m, and interpolation::Mesh::Iterator::getState().

Here is the call graph for this function:

int NDGrid::getPositionDimension ( ) const
inlinevirtual

Get the dimension of the Mesh

Implements interpolation::Mesh.

Definition at line 373 of file NDGrid.h.

References coord_m.

bool NDGrid::isGreater ( const Mesh::Iterator lhs,
const Mesh::Iterator rhs 
) const
protectedvirtual

Return true if rhs is greater than lhs

Implements interpolation::Mesh.

Definition at line 184 of file NDGrid.cpp.

References interpolation::Mesh::Iterator::state_m.

void NDGrid::lowerBound ( const std::vector< double > &  pos,
std::vector< int > &  xIndex 
) const
inline

Get the grid point of the grid lower bound

Parameters
pos,:position in the grid coordinate. Should have a length equal to the dimension of the grid.
xIndex,:will be set with the resultant grid index. Should have a lenght equal to the dimension of the grid.

Sets xIndex to the index of the largest mesh position that is less than pos in all dimension.

Note that dimension and xIndex are not bound checked.

Definition at line 332 of file NDGrid.h.

References coordLowerBound().

Referenced by getNearest().

Here is the call graph for this function:

double NDGrid::max ( const int &  dimension) const
inline

Return the highest grid coordinate in the given dimension

Definition at line 343 of file NDGrid.h.

References coord_m.

double NDGrid::min ( const int &  dimension) const
inline

Return the lowest grid coordinate in the given dimension

Definition at line 339 of file NDGrid.h.

References coord_m.

double * NDGrid::newCoordArray ( const int &  dimension) const

Get an array of grid points along a particular dimension

Parameters
dimension,:the dimension of the grid point to be found. Should be in range 0 <= dimension < grid dimension

Note the call is NOT bound checked - so it is a memory error to go out of the bounds.

Returns
an array of length this->size(dimension); caller owns the returned memory.

Definition at line 78 of file NDGrid.cpp.

References coord_m.

void NDGrid::setConstantSpacing ( bool  spacing)
inline

Set to true to flag the Mesh as a regular grid

Parameters
spacing,:flag indicating if the Mesh is regular.

Nb: If this is set for an irregular grid... I don't know what will happen

Definition at line 381 of file NDGrid.h.

References constantSpacing_m.

Referenced by NDGrid().

void NDGrid::setConstantSpacing ( double  tolerance_m = 1e-9)

Automatically detector whether the Mesh is a regular grid

Loops over all grid points and checks the step size is regular, with tolerance given by tolernance_m

Definition at line 168 of file NDGrid.cpp.

References constantSpacing_m, coord_m, and fabs().

Here is the call graph for this function:

void NDGrid::setCoord ( int  dimension,
int  nCoords,
double *  x 
)
inline

Reset the coordinates in the dimension to a new value

Parameters
dimension,:the dimension of the coordinates that will be reset
nCoords,:the length of array x
x,:array of points. Caller owns the memory allocated to x.

Definition at line 351 of file NDGrid.h.

References coord_m.

int NDGrid::size ( const int &  dimension) const
inline

Get the size of the grid along a given dimension

Parameters
dimension,:the dimension of the grid point to be found. Should be in range 0 <= dimension < grid dimension

Note the call is NOT bound checked - so it is a memory error to go out of the bounds.

Definition at line 307 of file NDGrid.h.

References coord_m.

Referenced by addOne(), dual(), getNearest(), and NDGrid().

Mesh::Iterator & NDGrid::subEquals ( Mesh::Iterator lhs,
int  difference 
) const
protectedvirtual

Subtract difference from lhs and then return lhs

Implements interpolation::Mesh.

Definition at line 114 of file NDGrid.cpp.

References addEquals(), coord_m, and interpolation::Mesh::Iterator::state_m.

Referenced by addEquals(), and subEquals().

Here is the call graph for this function:

Mesh::Iterator & NDGrid::subEquals ( Mesh::Iterator lhs,
const Mesh::Iterator rhs 
) const
protectedvirtual

Subtract difference from lhs and then return lhs

Implements interpolation::Mesh.

Definition at line 143 of file NDGrid.cpp.

References subEquals(), and interpolation::Mesh::Iterator::toInteger().

Here is the call graph for this function:

Mesh::Iterator & NDGrid::subOne ( Mesh::Iterator lhs) const
protectedvirtual

Decrement position of lhs by one and then return lhs

Implements interpolation::Mesh.

Definition at line 156 of file NDGrid.cpp.

References coord_m, and interpolation::Mesh::Iterator::state_m.

int NDGrid::toInteger ( const Mesh::Iterator lhs) const
virtual

Return an integer corresponding to the iterator position

Parameters
lhs,:iterator whose position is returned.
Returns
an integer between 0 and number of grid points; 0 is this->begin(), and each call to iterator++ increments the integer by 1

Implements interpolation::Mesh.

Definition at line 193 of file NDGrid.cpp.

References coord_m, and interpolation::Mesh::Iterator::state_m.

Friends And Related Function Documentation

bool operator!= ( const Mesh::Iterator lhs,
const Mesh::Iterator rhs 
)
friend

Return true if lhs does not index the same position as rhs

Mesh::Iterator operator+ ( const Mesh::Iterator lhs,
const Mesh::Iterator rhs 
)
friend

Addition operator - adds offset of rhs of rhs relative to Begin() to lhs

Mesh::Iterator operator++ ( Mesh::Iterator lhs,
int   
)
friend

Postfix increment operator it++ advances iterator by one

Mesh::Iterator& operator++ ( Mesh::Iterator lhs)
friend

Prefix increment operator ++it

Mesh::Iterator& operator+= ( Mesh::Iterator lhs,
const Mesh::Iterator rhs 
)
friend

Addition operator - adds offset of rhs of rhs relative to Begin() to lhs and returns lhs

Mesh::Iterator operator- ( const Mesh::Iterator lhs,
const Mesh::Iterator rhs 
)
friend

Subtraction operator - subtracts offset of rhs relative to Begin() from lhs

Mesh::Iterator operator-- ( Mesh::Iterator lhs,
int   
)
friend

Postfix decrement operator it– retreats iterator by one

Mesh::Iterator& operator-- ( Mesh::Iterator lhs)
friend

Prefix decrement operator –it retreats iterator by one

Mesh::Iterator& operator-= ( Mesh::Iterator lhs,
const Mesh::Iterator rhs 
)
friend

Subtraction operator - subtracts offset of rhs relative to Begin() from lhs and returns lhs

bool operator< ( const Mesh::Iterator lhs,
const Mesh::Iterator rhs 
)
friend

Return true if lhs indexes a position less than rhs i.e. successive operation of decrement operator would eventually reach lhs

bool operator<= ( const Mesh::Iterator lhs,
const Mesh::Iterator rhs 
)
friend

Return true if lhs indexes a position less than or equal to rhs i.e. successive operation of decrement operator would eventually reach lhs

bool operator== ( const Mesh::Iterator lhs,
const Mesh::Iterator rhs 
)
friend

Return true if lhs indexes the same position as rhs

bool operator> ( const Mesh::Iterator lhs,
const Mesh::Iterator rhs 
)
friend

Return true if lhs indexes a position greater than rhs i.e. successive operation of increment operator would eventually reach lhs

bool operator>= ( const Mesh::Iterator lhs,
const Mesh::Iterator rhs 
)
friend

Return true if lhs indexes a position greater than or equal to rhs i.e. successive operation of increment operator would eventually reach lhs

Member Data Documentation

bool interpolation::NDGrid::constantSpacing_m
private

Definition at line 280 of file NDGrid.h.

Referenced by coordLowerBound(), getConstantSpacing(), and setConstantSpacing().

std::vector< std::vector<double> > interpolation::NDGrid::coord_m
private
std::vector<VectorMap*> interpolation::NDGrid::maps_m
private

Definition at line 279 of file NDGrid.h.


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