Class Mesh2DGrid
Defined in File Mesh2DGrid.hpp
Nested Relationships
Nested Types
Class Documentation
-
class Mesh2DGrid
A class representing a semi-tensor 2D grid.
This class represents a grid where the points in one direction (the y direction) are arranged in a tensor grid (i.e., in an Nx x Ny grid, there is one y value for each of the Nx rows), but not in the other direction (i.e., the values of x can be different from one row of y values to to the next).
Public Types
-
enum class IntersectionType : std::uint8_t
An enum to hold intesection types.
Values:
-
enumerator spine
Intersection with a spine
-
enumerator rib
Intersection with a rib
-
enumerator none
Dummy flag value
-
enumerator spine
-
using Array2D = std::mdspan<double, std::dextents<size_t, 2>>
-
using Array1D = std::mdspan<double, std::dextents<size_t, 1>>
Public Functions
-
Mesh2DGrid(const Array2D &x, const Array1D &y, bool copyData = true)
Construct a Mesh2DGrid.
- Parameters:
x – A 2d array giving the x coordinates of the mesh points
y – A 1d array giving the y coordinates of the mesh points
copyData – If true, copy the data in x and y
-
Mesh2DGrid(const XView &x, const Array1D &y)
Construct a Mesh2DGrid whose x coordinates are read through an XView.
Intended for an XView that lazily interpolates between two planes of a 3D mesh (see XView’s own comment): the slopes and spine lengths are then also computed on demand (see MView/ SView), so constructing the grid costs only O(Ny) time and memory – for the edge-row summaries (xMin(), xMax(), convex()) – rather than O(Nx * Ny). Performs no safety checks on x: each row of x must be non-decreasing and span a non-zero range, and y must be non-decreasing, as for the other constructor – which a linear interpolation between two planes that each satisfy this automatically does.
- Parameters:
x – The x coordinates of the mesh points; not copied, so whatever storage it refers to must outlive this object
y – A 1d array giving the y coordinates of the mesh points; copied
-
virtual ~Mesh2DGrid() = default
-
Mesh2DGrid(const Mesh2DGrid &other)
-
Mesh2DGrid(Mesh2DGrid &&other) noexcept
-
auto operator=(const Mesh2DGrid&) -> Mesh2DGrid& = delete
-
auto operator=(Mesh2DGrid&&) -> Mesh2DGrid& = delete
-
inline auto size() const
Return size of Mesh2DGrid.
- Returns:
Size of mesh
-
inline auto nx() const
Return x dimension of Mesh2DGrid.
- Returns:
Number of mesh points in x direction
-
inline auto ny() const
Return x dimension of Mesh2DGrid.
- Returns:
Number of mesh points in x direction
-
inline auto convex() const
Returns in the mesh is convex.
- Returns:
True if the mesh is convex
-
inline auto xData() const -> const auto&
Return a const reference to the x array.
- Returns:
A const references to the x array
-
inline auto yData() const -> const auto&
Return a const reference to the y array.
- Returns:
A const references to the y array
-
inline auto sData() const -> const auto&
Return a const reference to the s array.
- Returns:
A const references to the s array
-
inline auto xMin() const
Minimum x value in mesh.
- Returns:
Minimum x value in mesh
-
inline auto xMin(const double y) const
Find minimum x value at given y.
- Returns:
Minimum x value at given y
-
inline auto xMax() const
Maximum x value in mesh.
- Returns:
Maximum x value in mesh
-
inline auto xMax(const double y) const
Find maximum x value at given y.
- Returns:
Maximum x value at given y
-
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
-
auto yLim(double x) const -> std::vector<std::pair<double, double>>
Find minimum and maximum y position at a given x.
The return value for this function is a vectors of pairs; each pair contains the minimum and maximum y values where a line segment at a given x value intersects the mesh. For a convex mesh there is at most one minimum and one maximum, so this vector will be of length 0 (if the mesh is missed entirely) or 1, but for a non-convex mesh a line at fixed x can intersect the edge an arbitrary number of times, so the vector can be longer.
- Parameters:
x – x position
- Returns:
Minimum and maximum y values
-
auto yEdgeSlope(double x, bool leftEdge) const -> std::vector<std::pair<double, double>>
Find y and dy/dx at every point where a line of constant x intersects one mesh edge.
Structured exactly like yLim() (see its own comment) – traversing the mesh upward at fixed x – but records only those intersections that land on the requested edge, and for each records the edge segment’s own slope (dy/dx) alongside its y coordinate, rather than pairing every intersection up into (min, max) ranges. For a convex mesh this is empty or a single pair; a non-convex mesh’s edge can fold back on itself, so this can return more.
- Parameters:
x – x position
leftEdge – True to find intersections with the mesh’s left edge (column 0), false for its right edge (column nx()-1)
- Returns:
One (y, dy/dx) pair per intersection with the requested edge, in ascending y order
-
inline auto contains(const double x, const double y) const
Check if a point is contained in the mesh.
- Parameters:
x – x position
y – y position
- Returns:
True if point is within mesh
-
inline auto xIdx(const double x, const size_t j) const -> size_t
Find index of a point in the x direction along a specified rib.
It is an error if the the input point is < x[0,j] or
x[nx()-1,j].
- Parameters:
x – x coordinate of point
j – Index of rib
- Returns:
Index of point along rib
-
inline auto yIdx(const double y) const -> size_t
Find index of point in y direction.
It is an error if the input y is < yMin_ or > yMax_.
- Returns:
Index of point in y direction
-
inline auto xyIdx(const double x, const double y) const
Find index of a given point in the mesh.
It is an error if the input point is outside the mesh
- Parameters:
x – The x position
y – The y position
- Returns:
The indices (i,j) of the lower left corner of the cell containing the point
-
auto onMesh(double x, double y) const -> std::pair<bool, xIntersectionDescriptor>
Check if a given point is exactly on the mesh.
The return value is a pair consisting of a boolean and an xIntersectionDescriptor object. If the point is exactly on a rib or spine, the boolean is set to true and the xIntersectionDescriptor contains the details of the point on the rib or spine; if the point is not on a rib or spine, the boolean is false and the xIntersectionDescriptor is uninitialized and meaningless.
- Parameters:
x – x poistion
y – y position
- Returns:
True or false, and intersection descriptor
-
auto xIntersect(double x, double yLo = std::numeric_limits<double>::lowest(), double yHi = std::numeric_limits<double>::max()) const -> std::vector<xIntersectionDescriptor>
Compute intersection of mesh with line of constant x.
This routine returns the set of points at which a line of constant x starting at yLo and ending at yHi intersects the mesh. The returned points are of type xIntersectionDescriptor. [yLo, yHi] is a closed interval: an intersection exactly at yLo or yHi is included, including where the line touches the interval only at that point.
- Parameters:
x – The x coordinate
yLo – Lower y limit of traversal
yHi – Upper y limit of traversal
- Returns:
List of points where line crosses mesh
-
auto xIntersectN(double x, double y, size_t n) const -> std::vector<xIntersectionDescriptor>
Compute up to N intersections of mesh with line of constant x, centered on a given y coordinate.
This routine is similar to xIntersect, except that rather than returning every intersection point of the line of constant x with the mesh, it returns at most N of them, chosen to be the points closest to y. The points are evenly split between those above and below y if N is even, with one extra point below y if N is odd. If the search for points in one direction from y reaches the edge of the mesh before the requested number of points on that side have been found, the search in the other direction continues past its own quota in an attempt to bring the total number of points found up to N. The returned list may still contain fewer than N points if the mesh has fewer than N intersections with the line of constant x in total. The returned points are of type xIntersectionDescriptor.
- Parameters:
x – The x coordinate
y – The y coordinate to center the search on
n – The maximum number of intersection points to return
- Returns:
List of points where line crosses mesh, up to N of them
-
auto yIntersect(double y, double xLo = std::numeric_limits<double>::lowest(), double xHi = std::numeric_limits<double>::max()) const -> std::vector<yIntersectionDescriptor>
Compute intersection of mesh with line of constant y.
This routine returns the set of points at which a line of constant y starting at xLo and ending at xHi intersects the mesh. The returned points are of type yIntersectionDescriptor.
- Parameters:
y – The y coordinate
xLo – Lower x limit of traversal
xHi – Upper x limit of traversal
- Returns:
List of points where the line crosses mesh
Public Static Attributes
-
static constexpr double bigNum = std::numeric_limits<double>::max()
Shorthand for big number
-
class MView
Read-only view of the slopes of the mesh spines.
Either a plain view of stored (Nx, Ny-1) values, or computed on each access from an XView and the y coordinates, using exactly the same formula computeSlopesAndLengths() uses to fill the stored values.
Public Functions
-
MView() = default
-
inline MView(std::span<const double> data, const size_t ny)
Construct a plain view of stored slopes.
- Parameters:
data – The (Nx, Ny-1) row-major array of slopes
ny – Number of points in the y direction
-
inline MView(const XView &x, std::span<const double> y)
Construct a view computing slopes on demand.
- Parameters:
x – The x coordinates of the mesh points
y – The y coordinates of the mesh points
-
inline auto operator[](const size_t i, const size_t j) const -> double
Return the slope of the spine segment from (i,j) to (i,j+1)
- Parameters:
i – Index in the x direction
j – Index in the y direction
- Returns:
The slope dy/dx, or bigNum if the segment is vertical
-
MView() = default
-
class SView
Read-only view of the cumulative lengths along the mesh spines.
Element (i,j) is the length along spine i from (i,0) to (i,j). Either a plain view of stored (Nx, Ny) values, or computed on each access from an XView and the y coordinates – in O(j) time, accumulating segment by segment in exactly the same order computeSlopesAndLengths() does, so that the result is identical to the stored value.
Public Functions
-
SView() = default
-
inline SView(std::span<const double> data, const size_t ny)
Construct a plain view of stored lengths.
- Parameters:
data – The (Nx, Ny) row-major array of lengths
ny – Number of points in the y direction
-
inline SView(const XView &x, std::span<const double> y)
Construct a view computing lengths on demand.
- Parameters:
x – The x coordinates of the mesh points
y – The y coordinates of the mesh points
-
inline auto operator[](const size_t i, const size_t j) const -> double
Return the cumulative length along spine i up to point j.
- Parameters:
i – Index in the x direction
j – Index in the y direction
- Returns:
The length
-
SView() = default
-
struct xIntersectionDescriptor
A struct to hold an intersection point.
This struct describes the results of traversing the mesh at constant x, which are distinct from the information needed to describe a traversal at constant y.
Public Members
-
double y
y coordinate of intersection
-
double xs
x or s coordinate of intersection, depending on type
-
IntersectionType t
Type of intersection – spine or rib
-
size_t idx
Index of spine or rib at intersection point
-
bool meshExit
True if the line exits the mesh at this intersection point
-
double y
-
class XView
Read-only view of the x coordinates of the mesh points.
Either a plain view of an (Nx, Ny) row-major array, or a lazy linear interpolation between two (Nx, Ny) planes read through arbitrary strides – e.g. two adjacent z planes of a Mesh3DInterpolator’s own (Nx, Ny, Nz) x array – evaluated afresh on every access. The latter lets a Mesh2DGrid represent a slice of a 3D mesh at an arbitrary z without ever storing that slice’s own x values; see the Mesh2DGrid constructor taking an XView.
Public Functions
-
XView() = default
-
inline XView(std::span<const double> data, const size_t nx, const size_t ny)
Construct a plain view of a row-major array.
- Parameters:
data – The (Nx, Ny) row-major array
nx – Number of points in the x direction
ny – Number of points in the y direction
-
inline XView(std::span<const double> p0, std::span<const double> p1, const size_t strideI, const size_t strideJ, const size_t nx, const size_t ny, const double t)
Construct a lazy linear interpolation between two strided planes.
- Parameters:
p0 – Storage holding the first plane
p1 – Storage holding the second plane, laid out identically to p0
strideI – Distance, in elements, between points adjacent in the x direction
strideJ – Distance, in elements, between points adjacent in the y direction
nx – Number of points in the x direction
ny – Number of points in the y direction
t – Interpolation weight: element (i,j) is p0(i,j) + t * (p1(i,j) - p0(i,j))
-
inline auto operator[](const size_t i, const size_t j) const -> double
Return the x coordinate of mesh point (i,j)
- Parameters:
i – Index in the x direction
j – Index in the y direction
- Returns:
The x coordinate
-
inline auto extent(const size_t r) const -> size_t
Return the number of points in one direction.
- Parameters:
r – 0 for the x direction, 1 for the y direction
- Returns:
The number of points
-
inline auto size() const -> size_t
Return the total number of points.
- Returns:
Nx * Ny
-
inline auto lazy() const -> bool
Return whether this is a lazy interpolation between two planes.
- Returns:
True if lazy, false if a plain view
-
XView() = default
-
struct yIntersectionDescriptor
A struct to hold an intersection point.
This struct describes the results of traversing the mesh at constant y, which are distinct from the information needed to describe a traversal at constant x.
-
enum class IntersectionType : std::uint8_t