28#ifndef _CLASSIC_FIELDS_NDGRID_HH_
29#define _CLASSIC_FIELDS_NDGRID_HH_
84 NDGrid(
int nDimensions,
int*
size,
double* spacing,
double*
min);
94 NDGrid(std::vector<int>
size, std::vector<const double *> gridCoordinates);
107 NDGrid(std::vector< std::vector<double> > gridCoordinates);
125 inline double&
coord(
const int& index,
const int& dimension);
137 inline const double&
coord(
const int& index,
const int& dimension)
const;
147 inline int size(
const int& dimension)
const;
157 inline std::vector<double>
coordVector(
const int& dimension)
const;
181 inline void coordLowerBound(
const double& x,
const int& dimension,
int& xIndex)
const;
195 inline void lowerBound(
const std::vector<double>& pos, std::vector<int>& xIndex)
const;
198 inline double min(
const int& dimension)
const;
201 inline double max(
const int& dimension)
const;
209 inline void setCoord(
int dimension,
int nCoords,
double * x);
303 return coord_m[dimension][index-1];
307 return coord_m[dimension][index-1];
311 return coord_m[dimension].size();
320 double x0 =
coord_m[dimension][0];
321 double x1 =
coord_m[dimension][1];
322 xIndex =
static_cast<int>(
std::floor((x - x0)/(x1-x0)));
323 int coordSize =
static_cast<int>(
coord_m[dimension].size());
324 if (xIndex >= coordSize) {
325 xIndex = coordSize-1;
326 }
else if (xIndex < -1) {
330 const std::vector<double>& c_t(
coord_m[dimension]);
331 xIndex = std::lower_bound(c_t.begin(), c_t.end(), x)-c_t.begin()-1;
336 xIndex = std::vector<int> (pos.size());
337 for(
unsigned int i=0; i < pos.size(); i++) {
355 coord_m[dimension] = std::vector<double>(x, x+nCoords);
373 position[i] =
coord_m[i][it[i]-1];
PETE_TUTree< FnFloor, typename T::PETE_Expr_t > floor(const PETE_Expr< T > &l)
constexpr double e
The value of.
Base class for meshing routines.
Used to loop over some, or all, points in the mesh, as in stl Enables e.g.
std::vector< int > getState() const
Return the internal state of the iterator.
NDGrid holds grid information for a rectilinear grid in some arbitrary dimensional space.
virtual Mesh::Iterator & addEquals(Mesh::Iterator &lhs, int difference) const
Add difference to lhs and then return lhs.
virtual Mesh::Iterator & addOne(Mesh::Iterator &lhs) const
Increment position of lhs by one and then return lhs.
friend bool operator>(const Mesh::Iterator &lhs, const Mesh::Iterator &rhs)
Return true if lhs indexes a position greater than rhs i.e.
virtual Mesh::Iterator & subOne(Mesh::Iterator &lhs) const
Decrement position of lhs by one and then return lhs.
Mesh::Iterator begin() const
Returns the origin of the mesh (lowest possible index in all dimensions)
void coordLowerBound(const double &x, const int &dimension, int &xIndex) const
Get the grid point of the grid lower bound in a particular dimension.
int toInteger(const Mesh::Iterator &lhs) const
Return an integer corresponding to the iterator position.
friend Mesh::Iterator & operator++(Mesh::Iterator &lhs)
Prefix increment operator ++it.
friend bool operator<(const Mesh::Iterator &lhs, const Mesh::Iterator &rhs)
Return true if lhs indexes a position less than rhs i.e.
double max(const int &dimension) const
Return the highest grid coordinate in the given dimension.
Mesh::Iterator end() const
Returns the end of the mesh (highest possible index in all dimensions)
std::vector< std::vector< double > > coord_m
int getPositionDimension() const
Get the dimension of the Mesh.
Mesh::Iterator getNearest(const double *position) const
Return an iterator corresponding to nearest mesh point to position.
void setCoord(int dimension, int nCoords, double *x)
Reset the coordinates in the dimension to a new value.
friend bool operator!=(const Mesh::Iterator &lhs, const Mesh::Iterator &rhs)
Return true if lhs does not index the same position as rhs.
double min(const int &dimension) const
Return the lowest grid coordinate in the given dimension.
double * newCoordArray(const int &dimension) const
Get an array of grid points along a particular dimension.
friend Mesh::Iterator operator-(const Mesh::Iterator &lhs, const Mesh::Iterator &rhs)
Subtraction operator - subtracts offset of rhs relative to Begin() from lhs.
friend Mesh::Iterator & operator--(Mesh::Iterator &lhs)
Prefix decrement operator –it retreats iterator by one
friend Mesh::Iterator & operator+=(Mesh::Iterator &lhs, const Mesh::Iterator &rhs)
Addition operator - adds offset of rhs of rhs relative to Begin() to lhs and returns lhs.
friend bool operator==(const Mesh::Iterator &lhs, const Mesh::Iterator &rhs)
Return true if lhs indexes the same position as rhs.
NDGrid()
Build a default, empty grid with zero dimension.
void lowerBound(const std::vector< double > &pos, std::vector< int > &xIndex) const
Get the grid point of the grid lower bound.
friend bool operator<=(const Mesh::Iterator &lhs, const Mesh::Iterator &rhs)
Return true if lhs indexes a position less than or equal to rhs i.e.
friend Mesh::Iterator operator--(Mesh::Iterator &lhs, int)
Postfix decrement operator it– retreats iterator by one.
void setConstantSpacing(bool spacing)
Set to true to flag the Mesh as a regular grid.
friend Mesh::Iterator operator+(const Mesh::Iterator &lhs, const Mesh::Iterator &rhs)
Addition operator - adds offset of rhs of rhs relative to Begin() to lhs.
virtual Mesh::Iterator & subEquals(Mesh::Iterator &lhs, int difference) const
Subtract difference from lhs and then return lhs.
std::vector< VectorMap * > maps_m
void getPosition(const Mesh::Iterator &it, double *position) const
Get the position of the iterator.
Mesh * dual() const
Not implemented.
friend Mesh::Iterator & operator-=(Mesh::Iterator &lhs, const Mesh::Iterator &rhs)
Subtraction operator - subtracts offset of rhs relative to Begin() from lhs and returns lhs.
int size(const int &dimension) const
Get the size of the grid along a given dimension.
std::vector< double > coordVector(const int &dimension) const
Get the vector of grid points along a particular dimension.
double & coord(const int &index, const int &dimension)
Get the coordinate of a set of grid points.
NDGrid * clone()
Inheritable copy constructor.
bool getConstantSpacing() const
Returns true if the Mesh is a regular grid.
friend bool operator>=(const Mesh::Iterator &lhs, const Mesh::Iterator &rhs)
Return true if lhs indexes a position greater than or equal to rhs i.e.
friend Mesh::Iterator operator++(Mesh::Iterator &lhs, int)
Postfix increment operator it++ advances iterator by one.
virtual bool isGreater(const Mesh::Iterator &lhs, const Mesh::Iterator &rhs) const
Return true if rhs is greater than lhs.