Template Class Mesh3DInterpolator

Nested Relationships

Nested Types

Class Documentation

template<size_t NF = 1>
class Mesh3DInterpolator

A class to perform interpolation on a 3D mesh.

This class performs interpolation on a 3D mesh where the y and z coordinates are arranged in a tensor grid (one y value per y-plane, one z value per z-plane), while the x coordinates may vary at each (y, z) position. The function values and x coordinates are copied into internal storage on construction. The number of quantities to be interpolated is determined by the template parameter NF.

Template Parameters:

NF – Number of quantities to interpolate

Public Types

using Array4D = std::mdspan<double, std::dextents<size_t, 4>>
using Array3D = std::mdspan<double, std::dextents<size_t, 3>>
using Array1D = std::mdspan<double, std::dextents<size_t, 1>>

Public Functions

inline Mesh3DInterpolator(const Array3D &x, const Array1D &y, const Array1D &z, const Array4D &f, const gsl_interp_type *interpType = gsl_interp_steffen, const bool monotonic = false)

Construct a Mesh3DInterpolator.

If monotonic is set to true, the interpolation type will always be gsl_interp_linear regardless of the value of interpType.

Parameters:
  • x – A 3D array (Nx × Ny × Nz) giving the x coordinates of the mesh points

  • y – A 1D array (Ny) giving the y coordinates of the mesh points

  • z – A 1D array (Nz) giving the z coordinates of the mesh points

  • f – A 4D array (Nx × Ny × Nz × NF) giving the values of the quantities to be interpolated

  • interpType – The type of interpolation to use

  • monotonic – Enforce that interpolation is monotonicity-preserving

inline Mesh3DInterpolator(const Array3D &x, const Array1D &y, const Array1D &z, const Array3D &f, const gsl_interp_type *interpType = gsl_interp_steffen, const bool monotonic = false)

Construct a Mesh3DInterpolator for a single quantity (NF == 1)

This constructor is valid only if NF == 1. It wraps the 3D array f in a 4D view with a trailing extent of 1 before delegating to the primary constructor.

Parameters:
  • x – A 3D array (Nx × Ny × Nz) giving the x coordinates of the mesh points

  • y – A 1D array (Ny) giving the y coordinates of the mesh points

  • z – A 1D array (Nz) giving the z coordinates of the mesh points

  • f – A 3D array (Nx × Ny × Nz) giving the values of the quantity to be interpolated

  • interpType – The type of interpolation to use

  • monotonic – Enforce that interpolation is monotonicity-preserving

virtual ~Mesh3DInterpolator() = default
Mesh3DInterpolator(const Mesh3DInterpolator&) = delete
Mesh3DInterpolator(Mesh3DInterpolator&&) = default
auto operator=(const Mesh3DInterpolator&) -> Mesh3DInterpolator& = delete
auto operator=(Mesh3DInterpolator&&) noexcept -> Mesh3DInterpolator& = default
inline auto size() const

Return total number of mesh points.

Returns:

nx() * ny() * nz()

inline auto nx() const

Return number of mesh points in the x direction.

Returns:

Number of mesh points in the x direction

inline auto ny() const

Return number of mesh points in the y direction.

Returns:

Number of mesh points in the y direction

inline auto nz() const

Return number of mesh points in the z direction.

Returns:

Number of mesh points in the z direction

inline auto x() const

Return an mdspan view of the x coordinate data.

Returns:

x as an mdspan of shape (Nx, Ny, Nz)

inline auto y() const

Return an mdspan view of the y coordinate data.

Returns:

y as an mdspan of shape (Ny)

inline auto z() const

Return an mdspan view of the z coordinate data.

Returns:

z as an mdspan of shape (Nz)

inline auto f() const

Return an mdspan view of the function value data.

Returns:

f as an mdspan of shape (Nx, Ny, Nz, NF)

inline auto xMin() const

Minimum x value across the entire mesh.

Returns:

Minimum x value in mesh

inline auto xMax() const

Maximum x value across the entire mesh.

Returns:

Maximum x value in mesh

inline auto yMin() const

Minimum y value in mesh.

Returns:

Minimum y value in mesh

inline auto yMax() const

Maximum y value in mesh.

Returns:

Maximum y value in mesh

inline auto zMin() const

Minimum z value in mesh.

Returns:

Minimum z value in mesh

inline auto zMax() const

Maximum z value in mesh.

Returns:

Maximum z value in mesh

inline auto sy() const

Return an mdspan view of the y arc-lengths.

Returns:

sy as an mdspan of shape (Nx, Nz, Ny); sy[i,k,j] is the cumulative arc-length along the y direction from j=0 to j, at mesh position (i, k) in (x, z)

inline auto sz() const

Return an mdspan view of the z arc-lengths.

Returns:

sz as an mdspan of shape (Nx, Ny, Nz); sz[i,j,k] is the cumulative arc-length along the z direction from k=0 to k, at mesh position (i, j) in (x, y)

inline auto yInterp() const

Return an mdspan view of the y-direction interpolators.

Returns:

yInterp as an mdspan of shape (Nx, Nz); yInterp[i,k] is the Interpolator1D<NF> that interpolates f in the y direction at fixed (i,k), using sy as the interpolation variable

inline auto zInterp() const

Return an mdspan view of the z-direction interpolators.

Returns:

zInterp as an mdspan of shape (Nx, Ny); zInterp[i,j] is the Interpolator1D<NF> that interpolates f in the z direction at fixed (i,j), using sz as the interpolation variable

inline auto sliceConstYCopy(double y0) const -> Mesh2DInterpolator<NF>

Construct a new, independent 2D slice of the mesh at fixed y.

Builds the slice eagerly: every (x, z) mesh point’s own x and f values are interpolated to y = y0 – using the y-direction interpolators returned by yInterp(), evaluated at the sy arc-length coordinate corresponding to y0 in each (i,k) column – and a Mesh2DInterpolator is then built from them, with its own rib and spine interpolators. The result owns all of its own data, independently of this Mesh3DInterpolator. An exact match of y0 with a mesh y value copies that plane directly, without interpolating.

Parameters:

y0 – The y coordinate at which to slice

Returns:

A newly-constructed Mesh2DInterpolator<NF> representing the (x, z) slice of the mesh at y = y0

inline auto sliceConstZCopy(double z0) const -> Mesh2DInterpolator<NF>

Construct a new, independent 2D slice of the mesh at fixed z.

Builds the slice eagerly: every (x, y) mesh point’s own x value is linearly interpolated between the two z planes bracketing z0, and its f values by the z-direction interpolators returned by zInterp(), evaluated at the sz arc-length coordinate interpolated likewise; a Mesh2DInterpolator is then built from them, with its own rib and spine interpolators. The result owns all of its own data, independently of this Mesh3DInterpolator

– but costs O(Nx *

Ny) time and memory, with a large constant (see

lazySliceConstZ() for a much cheaper alternative, when the slice need not outlive this object). An exact match of z0 with a mesh z value copies that plane directly, without interpolating.

Parameters:

z0 – The z coordinate at which to slice

Returns:

A newly-constructed Mesh2DInterpolator<NF> representing the (x, y) slice of the mesh at z = z0

inline auto lazySliceConstZ(double z0) const -> Mesh2DInterpolator<NF>

Construct a lazily-evaluated 2D slice of the mesh at fixed z.

Represents exactly the same slice as sliceConstZCopy(), but without building it: the slice’s x coordinates are interpolated between the two z planes bracketing z0 only when read (see Mesh2DGrid::XView), and its function values only at the mesh points a query actually needs, each by the same zInterp()/sz() interpolation sliceConstZCopy() applies to every point (see LazyValueSource). So it costs O(Ny) time and memory to construct, rather than the O(Nx * Ny) time and memory (with a large constant: one pair of Interpolator1D objects per rib and per spine) of sliceConstZCopy(), at the price of some extra work per query; and it has no shared mutable state, so any number of threads can construct and query their own slices concurrently. Query results agree with sliceConstZCopy()’s to within floating-point rounding. The returned object refers to this Mesh3DInterpolator’s own heap storage (which survives a move of this object, but not its destruction), so it must not outlive it.

Parameters:

z0 – The z coordinate at which to slice

Returns:

A Mesh2DInterpolator<NF> representing the (x, y) slice of the mesh at z = z0, which computes its mesh coordinates and function values on demand