Template Class Grid2D

Class Documentation

template <typename T>
class Grid2D

Template class for fields on a periodic grid with trilinear interpolation.

The grid spacing is constant and equal along all three axes. Values are calculated by trilinear interpolation of the surrounding 8 grid points. The grid is periodically (default) or reflectively extended. The grid sample positions are at 1/2 * size/N, 3/2 * size/N … (2N-1)/2 * size/N.

Public Functions

Grid2D(Vector3d origin, size_t N, double spacing)

Constructor for cubic grid

Parameters
  • origin: Position of the lower left front corner of the volume
  • N: Number of grid points in one direction
  • spacing: Spacing between grid points

Grid2D(Vector3d origin, size_t Nx, size_t Ny, double spacing)

Constructor for non-cubic grid

Parameters
  • origin: Position of the lower left front corner of the volume
  • Nx: Number of grid points in x-direction
  • Ny: Number of grid points in y-direction
  • spacing: Spacing between grid points

Grid2D(Vector3d origin, size_t Nx, size_t Ny, Vector3d spacing)

Constructor for non-cubic grid with spacing vector

Parameters
  • origin: Position of the lower left front corner of the volume
  • Nx: Number of grid points in x-direction
  • Ny: Number of grid points in y-direction
  • spacing: Spacing vector between grid points

void setOrigin(Vector3d origin)
void setGridSize(size_t Nx, size_t Ny)

Resize grid, also enlarges the volume as the spacing stays constant

size_t getGridSize() const
void setSpacing(Vector3d spacing)
Vector3d getSpacing() const
void setReflective(bool b)
void setVector(const std::vector<float> &v)
void addVector(std::unique_ptr<std::vector<T>> v2)
void pushValue(T value)
Vector3d getOrigin() const
size_t getNx() const
size_t getNy() const
bool isReflective() const
T &get(size_t ix, size_t iy)

Inspector & Mutator

const T &get(size_t ix, size_t iy) const

Inspector

T getValue(size_t ix, size_t iy)
void setValue(size_t ix, size_t iy, T value)
void addValue(size_t ix, size_t iy, T value)
std::vector<T> &getGrid()

Return a reference to the grid values

Vector3d positionFromIndex(int index) const

Position of the grid point of a given index

T closestValue(const Vector3d &position) const

Value of a grid point that is closest to a given position

T interpolate(const Vector3d &position) const

Interpolate the grid at a given position