Template Class Grid

Inheritance Relationships

Base Type

Class Documentation

template<typename T>
class Grid : public Referenced

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

The grid spacing is constant with diffrent resolution 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

inline Grid(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

inline Grid(Vector3d origin, size_t Nx, size_t Ny, size_t Nz, 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

  • Nz – Number of grid points in z-direction

  • spacing – Spacing between grid points

inline Grid(Vector3d origin, size_t Nx, size_t Ny, size_t Nz, 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

  • Nz – Number of grid points in z-direction

  • spacing – Spacing vector between grid points

inline Grid(const GridProperties &p)

Constructor for GridProperties

Parameters:

pGridProperties instance

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

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

inline void setSpacing(Vector3d spacing)
inline void setReflective(bool b)
inline void setClipVolume(bool b)
inline void setInterpolationType(interpolationType ipolType)

Change the interpolation type to the routine specified by the user. Check if this routine is contained in the enum interpolationType and thus supported by CRPropa.

inline Vector3d getOrigin() const

returns the position of the lower left front corner of the volume

inline bool getClipVolume() const
inline size_t getNx() const
inline size_t getNy() const
inline size_t getNz() const
inline size_t getSizeOf() const

Calculates the total size of the grid in bytes

inline Vector3d getSpacing() const
inline bool isReflective() const
inline T interpolate(const Vector3d &position)

Choose the interpolation algorithm based on the set interpolation type. By default this it the trilinear interpolation. The user can change the routine with the setInterpolationType function.

inline T &get(size_t ix, size_t iy, size_t iz)

Inspector & Mutator

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

Inspector

inline const T &periodicGet(size_t ix, size_t iy, size_t iz) const
inline const T &reflectiveGet(size_t ix, size_t iy, size_t iz) const
inline T getValue(size_t ix, size_t iy, size_t iz)
inline void setValue(size_t ix, size_t iy, size_t iz, T value)
inline std::vector<T> &getGrid()

Return a reference to the grid values

inline Vector3d positionFromIndex(int index) const

Position of the grid point of a given index

inline T closestValue(const Vector3d &position) const

Value of a grid point that is closest to a given position / nearest neighbour interpolation

inline size_t addReference() const
inline size_t removeReference() const
inline int removeReferenceNoDelete() const
inline size_t getReferenceCount() const

Protected Attributes

mutable size_t _referenceCount