Skip to main content

Grid1D

Struct Grid1D 

Source
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: F

Left endpoint. Invariant: xmin < xmax.

§xmax: F

Right endpoint. Invariant: xmin < xmax.

§n: usize

Number of nodes. Invariant: n >= 4.

§boundary: BoundaryPolicy<F>

Out-of-grid lookup policy. Default: BoundaryPolicy::Reflect.

§interp: InterpKind

Sub-grid interpolation strategy. Default: InterpKind::CubicHermite.

Implementations§

Source§

impl<F: SemiflowFloat> Grid1D<F>

Source

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
Source

pub fn dx(&self) -> F

Grid spacing dx = (xmax − xmin) / (n − 1).

Source

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.

Source

pub fn nodes(&self) -> Vec<F>

Node coordinates as a Vec<F> (length n).

Source

pub fn with_boundary(self, policy: BoundaryPolicy<F>) -> Self

Builder: replace the boundary policy.

Source

pub fn with_interp(self, kind: InterpKind) -> Self

Builder: replace the interpolation kind.

Source

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
Source§

impl Grid1D<f64>

Source

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
Source

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.

Source

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

Trait Implementations§

Source§

impl<F: Clone + SemiflowFloat> Clone for Grid1D<F>

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<F: Copy + SemiflowFloat> Copy for Grid1D<F>

Source§

impl<F: Debug + SemiflowFloat> Debug for Grid1D<F>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<F> Freeze for Grid1D<F>

§

impl<F> RefUnwindSafe for Grid1D<F>

§

impl<F> Send for Grid1D<F>
where BoundaryPolicy<F>: Send,

§

impl<F> Sync for Grid1D<F>
where BoundaryPolicy<F>: Sync,

§

impl<F> Unpin for Grid1D<F>
where F: Unpin, BoundaryPolicy<F>: Unpin,

§

impl<F> UnsafeUnpin for Grid1D<F>

§

impl<F> UnwindSafe for Grid1D<F>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.