OPAL (Object Oriented Parallel Accelerator Library) 2022.1
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 (const NDGrid &grid)
 
 ~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::Iterator begin () const =0
 
virtual Mesh::Iterator end () const =0
 
virtual Meshclone ()=0
 
virtual Meshdual () const =0
 
virtual ~Mesh ()
 
virtual void getPosition (const Mesh::Iterator &it, double *position) const =0
 
virtual int getPositionDimension () const =0
 
virtual int toInteger (const Mesh::Iterator &lhs) const =0
 
virtual Mesh::Iterator getNearest (const double *position) const =0
 

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
 
virtual Mesh::IteratoraddEquals (Mesh::Iterator &lhs, int difference) const =0
 
virtual Mesh::IteratorsubEquals (Mesh::Iterator &lhs, int difference) const =0
 
virtual Mesh::IteratoraddEquals (Mesh::Iterator &lhs, const Mesh::Iterator &rhs) const =0
 
virtual Mesh::IteratorsubEquals (Mesh::Iterator &lhs, const Mesh::Iterator &rhs) const =0
 
virtual Mesh::IteratoraddOne (Mesh::Iterator &lhs) const =0
 
virtual Mesh::IteratorsubOne (Mesh::Iterator &lhs) const =0
 
virtual bool isGreater (const Mesh::Iterator &lhs, const Mesh::Iterator &rhs) const =0
 

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() [1/5]

interpolation::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() [2/5]

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

Build a regular grid

Parameters
nDimensionsnumber of dimensions of the grid
sizearray 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.
spacingarray of doubles of length nDimensions. Gives the grid spacing in each dimension. Caller owns memory pointed to by spacing.
minarray of doubles of length nDimensions. Gives the coordinate of the zeroth element (origin). Caller owns the memory pointed to by min.

Definition at line 56 of file NDGrid.cpp.

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

Here is the call graph for this function:

◆ NDGrid() [3/5]

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

Build an irregular grid

Parameters
sizeThe number of grid points in each dimension. This vector must be the same length as gridCoordinates vector.
gridCoordinatesvector 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 43 of file NDGrid.cpp.

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

Here is the call graph for this function:

◆ NDGrid() [4/5]

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

Build an irregular grid

Parameters
gridCoordinatesVector 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 70 of file NDGrid.cpp.

References setConstantSpacing(), and size().

Here is the call graph for this function:

◆ NDGrid() [5/5]

interpolation::NDGrid::NDGrid ( const NDGrid grid)

Copy constructor

Definition at line 39 of file NDGrid.cpp.

◆ ~NDGrid()

interpolation::NDGrid::~NDGrid ( )
inline

Destructor

Definition at line 113 of file NDGrid.h.

Member Function Documentation

◆ addEquals() [1/2]

Mesh::Iterator & interpolation::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 143 of file NDGrid.cpp.

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

Here is the call graph for this function:

◆ addEquals() [2/2]

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

Add difference to lhs and then return lhs

Implements interpolation::Mesh.

Definition at line 92 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:

◆ addOne()

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

Increment position of lhs by one and then return lhs

Implements interpolation::Mesh.

Definition at line 151 of file NDGrid.cpp.

References coord_m, and size().

Here is the call graph for this function:

◆ begin()

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

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

Implements interpolation::Mesh.

Definition at line 358 of file NDGrid.h.

References coord_m.

Referenced by DumpEMFields::writeFieldThis().

◆ clone()

NDGrid * interpolation::NDGrid::clone ( )
inlinevirtual

Inheritable copy constructor

Implements interpolation::Mesh.

Definition at line 350 of file NDGrid.h.

References NDGrid().

Referenced by DumpEMFields::clone(), and PyOpal::PyPolynomialPatch::initialiseFromSolveFactory().

Here is the call graph for this function:

◆ coord() [1/2]

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

Get the coordinate of a set of grid points

Parameters
indexthe index of the grid point to be found; indexed from 1. Should be in range 1 <= index <= length
dimensionthe 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 302 of file NDGrid.h.

References coord_m.

Referenced by dual().

◆ coord() [2/2]

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

Get the coordinate of a set of grid points

Parameters
indexthe index of the grid point to be found; indexed from 1. Should be in range 1 <= index <= length
dimensionthe 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 306 of file NDGrid.h.

References coord_m.

◆ coordLowerBound()

void interpolation::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
xposition in the grid coordinate
dimensionthe grid coordinate to search along
xIndexwill 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 318 of file NDGrid.h.

References constantSpacing_m, coord_m, and floor().

Referenced by lowerBound().

Here is the call graph for this function:

◆ coordVector()

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

Get the vector of grid points along a particular dimension

Parameters
dimensionthe 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 314 of file NDGrid.h.

References coord_m.

Referenced by PyOpal::PyNDGrid::coordVector().

◆ dual()

Mesh * interpolation::NDGrid::dual ( ) const
virtual

Not implemented

Implements interpolation::Mesh.

Definition at line 232 of file NDGrid.cpp.

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

Here is the call graph for this function:

◆ end()

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

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

Implements interpolation::Mesh.

Definition at line 362 of file NDGrid.h.

References coord_m, and end().

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

Here is the call graph for this function:

◆ getConstantSpacing()

bool interpolation::NDGrid::getConstantSpacing ( ) const
inline

Returns true if the Mesh is a regular grid

Definition at line 380 of file NDGrid.h.

References constantSpacing_m.

◆ getNearest()

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

Return an iterator corresponding to nearest mesh point to position

Parameters
positionArray 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 210 of file NDGrid.cpp.

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

Here is the call graph for this function:

◆ getPosition()

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

Get the position of the iterator

Parameters
ititerator on this Mesh
positiondouble 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 371 of file NDGrid.h.

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

Here is the call graph for this function:

◆ getPositionDimension()

int interpolation::NDGrid::getPositionDimension ( ) const
inlinevirtual

Get the dimension of the Mesh

Implements interpolation::Mesh.

Definition at line 376 of file NDGrid.h.

References coord_m.

Referenced by PyOpal::PyNDGrid::BOOST_PYTHON_MODULE(), and PyOpal::PyNDGrid::coordVector().

◆ isGreater()

bool interpolation::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 188 of file NDGrid.cpp.

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

◆ lowerBound()

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

Get the grid point of the grid lower bound

Parameters
posposition in the grid coordinate. Should have a length equal to the dimension of the grid.
xIndexwill 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 335 of file NDGrid.h.

References coordLowerBound().

Referenced by getNearest().

Here is the call graph for this function:

◆ max()

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

Return the highest grid coordinate in the given dimension

Definition at line 346 of file NDGrid.h.

References coord_m.

◆ min()

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

Return the lowest grid coordinate in the given dimension

Definition at line 342 of file NDGrid.h.

References coord_m.

Referenced by NDGrid().

◆ newCoordArray()

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

Get an array of grid points along a particular dimension

Parameters
dimensionthe 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 82 of file NDGrid.cpp.

References coord_m.

◆ setConstantSpacing() [1/2]

void interpolation::NDGrid::setConstantSpacing ( bool  spacing)
inline

Set to true to flag the Mesh as a regular grid

Parameters
spacingflag 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 384 of file NDGrid.h.

References constantSpacing_m.

Referenced by NDGrid().

◆ setConstantSpacing() [2/2]

void interpolation::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 172 of file NDGrid.cpp.

References abs(), constantSpacing_m, and coord_m.

Here is the call graph for this function:

◆ setCoord()

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

Reset the coordinates in the dimension to a new value

Parameters
dimensionthe dimension of the coordinates that will be reset
nCoordsthe length of array x
xarray of points. Caller owns the memory allocated to x.

Definition at line 354 of file NDGrid.h.

References coord_m.

◆ size()

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

Get the size of the grid along a given dimension

Parameters
dimensionthe 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 310 of file NDGrid.h.

References coord_m.

Referenced by addOne(), PyOpal::PyNDGrid::BOOST_PYTHON_MODULE(), dual(), getNearest(), getPosition(), and NDGrid().

◆ subEquals() [1/2]

Mesh::Iterator & interpolation::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 147 of file NDGrid.cpp.

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

Here is the call graph for this function:

◆ subEquals() [2/2]

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

Subtract difference from lhs and then return lhs

Implements interpolation::Mesh.

Definition at line 118 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:

◆ subOne()

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

Decrement position of lhs by one and then return lhs

Implements interpolation::Mesh.

Definition at line 160 of file NDGrid.cpp.

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

◆ toInteger()

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

Return an integer corresponding to the iterator position

Parameters
lhsiterator 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 197 of file NDGrid.cpp.

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

Friends And Related Function Documentation

◆ operator!=

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

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

◆ operator+

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

◆ operator++ [1/2]

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

Prefix increment operator ++it

◆ operator++ [2/2]

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

Postfix increment operator it++ advances iterator by one

◆ operator+=

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

◆ operator-

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

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

◆ operator-- [1/2]

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

Prefix decrement operator –it retreats iterator by one

◆ operator-- [2/2]

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

Postfix decrement operator it– retreats iterator by one

◆ operator-=

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

◆ operator<

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

◆ operator<=

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

◆ operator==

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

Return true if lhs indexes the same position as rhs

◆ operator>

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

◆ operator>=

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

◆ constantSpacing_m

bool interpolation::NDGrid::constantSpacing_m
private

Definition at line 283 of file NDGrid.h.

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

◆ coord_m

std::vector< std::vector<double> > interpolation::NDGrid::coord_m
private

◆ maps_m

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

Definition at line 282 of file NDGrid.h.


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