pub struct Grid1D<F: SemiflowFloat = f64> {
pub xmin: F,
pub xmax: F,
pub n: usize,
pub boundary: BoundaryPolicy<F>,
pub interp: InterpKind,
}Expand description
Uniform 1-D grid [xmin, xmax] with n nodes.
Node positions: x_i = xmin + i · dx, dx = (xmax − xmin) / (n − 1),
i = 0..n. Minimum size: n >= 4 (Catmull-Rom stencil).
The grid owns the geometry and hosts both adapters (boundary policy and
interpolation kind). Function values reside in crate::GridFn1D.
§Generic-over-Float (ADR-0025)
Grid1D<F: SemiflowFloat = f64> — the = f64 default keeps all existing
call-sites compiling unchanged. The f64 path (including SIMD catmull_rom)
is used when F = f64; a fully-scalar generic path is used otherwise.
SepticHermite, OctonicHermite, and ChebyshevSpectralWithBC are all
supported for F: SemiflowFloat via generic scalar samplers
(§46.5.bis, v8.1+, ADR-0133/ADR-0139).
§Example
use semiflow::{Grid1D, BoundaryPolicy, InterpKind};
let grid = Grid1D::new(-1.0, 1.0, 100).unwrap();
assert_eq!(grid.n, 100);
assert!((grid.dx() - 2.0 / 99.0).abs() < 1e-15);
assert_eq!(grid.boundary, BoundaryPolicy::Reflect);
// Opt-in to ZeroExtend and CubicHermite
let grid2 = grid
.with_boundary(BoundaryPolicy::ZeroExtend)
.with_interp(InterpKind::CubicHermite);
assert_eq!(grid2.boundary, BoundaryPolicy::ZeroExtend);Fields§
§xmin: FLeft endpoint. Invariant: xmin < xmax.
xmax: FRight endpoint. Invariant: xmin < xmax.
n: usizeNumber of nodes. Invariant: n >= 4.
boundary: BoundaryPolicy<F>Out-of-grid lookup policy. Default: BoundaryPolicy::Reflect.
interp: InterpKindSub-grid interpolation strategy. Default: InterpKind::CubicHermite.
Implementations§
Source§impl<F: SemiflowFloat> Grid1D<F>
impl<F: SemiflowFloat> Grid1D<F>
Sourcepub fn new_generic(xmin: F, xmax: F, n: usize) -> Result<Self, SemiflowError>
pub fn new_generic(xmin: F, xmax: F, n: usize) -> Result<Self, SemiflowError>
Construct a Grid1D<F> for non-f64 scalar types.
For F = f64, use the backward-compatible Grid1D::new(f64, f64, usize)
on the concrete impl Grid1D<f64> block — it preserves type inference
at existing call-sites (e.g. Grid1D::new(-10.0, 10.0, 1000)).
Defaults: boundary = Reflect, interp = SepticHermite (v8.0+, §46.5.bis).
Matches the Grid1D::new default so that kernels at F = Dual<f64>
compose with the same spatial interpolant as the f64 production path.
§Errors
SemiflowError::DomainViolationifxminorxmaxis non-finite.SemiflowError::DomainViolationifxmin >= xmax.SemiflowError::DomainViolationifn < 4(minimum Catmull-Rom stencil).
Sourcepub fn x_at(&self, i: usize) -> F
pub fn x_at(&self, i: usize) -> F
Coordinate of the i-th node: xmin + i · dx.
For i >= n the result is outside the domain; callers should use
sample for out-of-domain queries.
Sourcepub fn with_boundary(self, policy: BoundaryPolicy<F>) -> Self
pub fn with_boundary(self, policy: BoundaryPolicy<F>) -> Self
Builder: replace the boundary policy.
Sourcepub fn with_interp(self, kind: InterpKind) -> Self
pub fn with_interp(self, kind: InterpKind) -> Self
Builder: replace the interpolation kind.
Sourcepub fn interp_generic(&self, values: &[F], x: F) -> Result<F, SemiflowError>
pub fn interp_generic(&self, values: &[F], x: F) -> Result<F, SemiflowError>
Evaluate the function given by values at arbitrary x.
For F = f64, prefer interp_f64 which uses the SIMD catmull_rom and the
SIMD SepticHermite. This generic version uses scalar-only paths.
SepticHermite, OctonicHermite, and ChebyshevSpectralWithBC are all
supported for F: SemiflowFloat via generic scalar samplers
(§46.5.bis, v8.1+, ADR-0139).
§Errors
SemiflowError::UnsupportedforInterpKind::Linearwithout thelinear-interpfeature.SemiflowError::DomainViolationforInterpKind::ChebyshevSpectralWithBCifmis not in the supported set {8,16,32,64,128,256,512}.
Source§impl Grid1D<f64>
impl Grid1D<f64>
Sourcepub fn new(xmin: f64, xmax: f64, n: usize) -> Result<Self, SemiflowError>
pub fn new(xmin: f64, xmax: f64, n: usize) -> Result<Self, SemiflowError>
Construct a Grid1D<f64> (backward-compatible signature).
This is the historic Grid1D::new(xmin: f64, xmax: f64, n: usize) API.
It takes concrete f64 arguments, preserving type inference at existing
call-sites (e.g. Grid1D::new(-10.0, 10.0, 1000)).
For non-f64 types, use Grid1D::<F>::new_generic(xmin, xmax, n).
Defaults: boundary = Reflect, interp = SepticHermite (v6.0+, ADR-0109).
§Migration (v5 → v6)
The default interp changed from CubicHermite to SepticHermite.
If you need the pre-v6 behaviour, call .with_interp(InterpKind::CubicHermite).
See docs/migration/v5-to-v6.md for details.
§Errors
SemiflowError::DomainViolationifxminorxmaxis non-finite.SemiflowError::DomainViolationifxmin >= xmax.SemiflowError::DomainViolationifn < 4.
Sourcepub fn cheb_m(
xmin: f64,
xmax: f64,
n: usize,
m: usize,
) -> Result<Self, SemiflowError>
pub fn cheb_m( xmin: f64, xmax: f64, n: usize, m: usize, ) -> Result<Self, SemiflowError>
Convenience constructor: Grid1D<f64> with ChebyshevSpectralWithBC interp.
Defaults: boundary = Reflect, oob_policy = OobPolicy::Inherit.
Equivalent to:
Grid1D::new(xmin, xmax, n).unwrap().with_interp(InterpKind::ChebyshevSpectralWithBC {
m,
oob_policy: OobPolicy::Inherit,
});§Migration (v4 → v5)
Replace Grid1D::new(xmin, xmax, n)? + with_interp(ChebyshevSpectral { m })
with Grid1D::cheb_m(xmin, xmax, n, m)?.
§Errors
Propagates SemiflowError::DomainViolation from Grid1D::new.
Sourcepub fn interp(&self, values: &[f64], x: f64) -> Result<f64, SemiflowError>
pub fn interp(&self, values: &[f64], x: f64) -> Result<f64, SemiflowError>
Evaluate at x using f64-specific SIMD catmull_rom and SepticHermite.
This is the historic Grid1D::interp from v0.8.x — now renamed to
interp_f64 to distinguish it from the generic interp_generic.
All existing code that called self.grid.interp(...) on a Grid1D<f64>
should use this method.
§Errors
SemiflowError::UnsupportedforInterpKind::Linearwithout thelinear-interpfeature.