Template Class Mesh

Template Parameter Order

  1. typename T

Class Documentation

template<typename T>
class Mesh

Mesh class.

Base mesh class with ghost cells and smart access operator. Data is stored in a 1D array with column-major ordering.

Template Parameters:

T – Data type

Public Functions

inline Mesh()

Default constructor for the Mesh class.

This constructor will initialize the Mesh class with zero sizes. The data will not be initialized.

inline Mesh(const Mesh &other)

Copy constructor for the Mesh class.

This constructor will copy the data from the other object of Mesh class.

Parameters:

other – Other Mesh object

inline Mesh(const MeshSize &domain_size)

Mesh constructor using MeshSize struct.

This constructor will initialize the Mesh class with the given MeshSize struct. Initialize the data with the given size.

Parameters:

domain_sizeMeshSize struct containing the mesh size information

inline Mesh(int nx)

1D Mesh constructor

This constructor will initialize 1D Mesh class with zero ghost cells. Initialize the data with the given size.

Parameters:

nx – Number of cells in the X-axis \(n_x\).

inline Mesh(int nx, int ny)

2D Mesh constructor

This constructor will initialize 2D Mesh class with zero ghost cells. Initialize the data with the given size.

Parameters:
  • nx – Number of cells in the X-axis \(n_x\).

  • ny – Number of cells in the Y-axis \(n_y\).

inline Mesh(int nx, int ny, int nz)

3D Mesh constructor

This constructor will initialize 3D Mesh class with zero ghost cells. Initialize the data with the given size.

Parameters:
  • nx – Number of cells in the X-axis \(n_x\).

  • ny – Number of cells in the Y-axis \(n_y\).

  • nz – Number of cells in the Z-axis \(n_z\).

inline Mesh(int nx, int ny, int nz, int ng)

3D Mesh constructor with ghost cells

This constructor will initialize 3D Mesh class with the same number of ghost cells in all axis. Initialize the data with the given size.

Parameters:
  • nx – Number of cells in the X-axis \(n_x\).

  • ny – Number of cells in the Y-axis \(n_y\).

  • nz – Number of cells in the Z-axis \(n_z\).

  • ng – Number of ghost cells \(n_g\) in all axis.

inline Mesh(int nx, int ny, int nz, int ngx, int ngy, int ngz)

3D Mesh constructor with custom ghost cells

This constructor will initialize 3D Mesh class with custom number of ghost cells in each axis. Initialize the data with the given size.

Parameters:
  • nx – Number of cells in the X-axis \(n_x\).

  • ny – Number of cells in the Y-axis \(n_y\).

  • nz – Number of cells in the Z-axis \(n_z\).

  • ngx – Number of ghost cells \(n_{gx}\) in the X-axis.

  • ngy – Number of ghost cells \(n_{gy}\) in the Y-axis.

  • ngz – Number of ghost cells \(n_{gz}\) in the Z-axis.

inline Mesh(Mesh &&other) noexcept

Move constructor for the Mesh class.

This constructor will move the data from the other object of Mesh class. The other object will be reset to the default state.

Parameters:

other – Pointer to the other Mesh object

inline ~Mesh()

Destructor for the Mesh class.

inline T BilinearInterpolation(double x, double y) const

Bilenar interpolation.

Parameters:
  • x – Data point location relative to the mesh \(x^\prime\)

  • y – Data point location relative to the mesh \(y^\prime\)

Returns:

Interpolated value at \((x^\prime, y^\prime)\)

inline void CopyToGhost(const Mesh &other, MeshGhostLocation gl)

Copy data from other Mesh to the current Mesh ghost cells.

Parameters:
  • other – Other mesh

  • gl – Ghost location

inline void InitializeData()

Initialize the data block for the mesh.

inline T Interpolation(double x, double y, double z) const

Interpolation function.

This function will automatically choose the interpolation method based on the mesh dimension. Ignore the extra arguments if the mesh is in lower dimension.

Parameters:
  • x – Data point location relative to the mesh \(x^\prime\)

  • y – Data point location relative to the mesh \(y^\prime\)

  • z – Data point location relative to the mesh \(z^\prime\)

Returns:

Interpolated value at \((x^\prime, y^\prime, z^\prime)\)

inline T LinearInterpolation(double x) const

Linear interpolation.

Parameters:

x – Data point location relative to the mesh \(x^\prime\)

Returns:

Interpolated value at \(x^\prime\)

inline T &operator()(int i)
inline T operator()(int i) const
inline T &operator()(int i, int j, int k)
inline T operator()(int i, int j, int k) const
inline Mesh<T> &operator+=(T value)

Addition assignment operator for the Mesh class object for a scalar value.

Parameters:

value – Scalar value

Returns:

Mesh<T>& Reference to the current Mesh object

inline Mesh<T> &operator=(Mesh<T> other)

Assignment operator for the Mesh class object for another Mesh class object.

Parameters:

other – Other Mesh class object

Returns:

Mesh<T>& Reference to the current Mesh object

inline Mesh<T> &operator=(T value)

Assignment operator for the Mesh class object for a scalar value.

Parameters:

value – Scalar value

Returns:

Mesh<T>& Reference to the current Mesh object

inline void Resize(int nx, int ny, int nz, int ngx, int ngy, int ngz)

Resize the mesh and clean up the data.

This function will resize the mesh and clean up the data. If the size is changed, the data will be reallocated.

Parameters:
  • nx – New X-axis size \(n_x\)

  • ny – New Y-axis size \(n_y\)

  • nz – New Z-axis size \(n_z\)

  • ngx – New X-axis ghost size \(n_{gx}\)

  • ngy – New Y-axis ghost size \(n_{gy}\)

  • ngz – New Z-axis ghost size \(n_{gz}\)

inline bool SameSizeAs(const Mesh &other)

Comparator to check if the mesh size is the same as the other mesh.

Parameters:

other – Other Mesh object

inline void Shrink(int nx, int ny, int nz, int ngx, int ngy, int ngz)

Shrink the mesh inplace.

This function will shrink the mesh inplace. Crash if the new mesh size is different from the current mesh size.

Parameters:
  • nx – New X-axis size \(n_x\)

  • ny – New Y-axis size \(n_y\)

  • nz – New Z-axis size \(n_z\)

  • ngx – New X-axis ghost size \(n_{gx}\)

  • ngy – New Y-axis ghost size \(n_{gy}\)

  • ngz – New Z-axis ghost size \(n_{gz}\)

inline T TrilinearInterpolation(double x, double y, double z) const

Trilinear interpolation.

Parameters:
  • x – Data point location relative to the mesh \(x^\prime\)

  • y – Data point location relative to the mesh \(y^\prime\)

  • z – Data point location relative to the mesh \(z^\prime\)

Returns:

Interpolated value at \((x^\prime, y^\prime, z^\prime)\)

inline void UpdateTotalSizes()

Recalculate the total mesh sizes based on the current sizes.

Friends

inline friend void swap(Mesh<T> &first, Mesh<T> &second) noexcept

Function to swap the data between two Mesh objects.

This function will swap the data between two Mesh objects in-place using std::swap.

Parameters:
  • first – First Mesh object

  • second – Second Mesh object