Skip to main content

SplinedPotential

Struct SplinedPotential 

Source
pub struct SplinedPotential { /* private fields */ }
Expand description

A splined version of any isotropic twobody potential.

Provides O(1) evaluation via cubic spline interpolation. Supports three grid types:

  • PowerLaw(p): Power-law spacing with denser sampling at short range (default, p=2.0)
  • UniformR: Uniform spacing in r
  • UniformRsq: Uniform spacing in r² (legacy, not recommended)

The splined potential is type-erased after construction—it stores only the precomputed coefficients, not the original potential.

Implementations§

Source§

impl SplinedPotential

Source

pub fn coefficients(&self) -> &[SplineCoeffs]

Returns a reference to the spline coefficients for all grid intervals.

Source

pub const fn f_at_rmin(&self) -> f64

Returns the force at r_min, used for linear extrapolation below the grid.

Source

pub const fn r_min(&self) -> f64

Returns the minimum distance of the spline grid.

Source

pub const fn r_max(&self) -> f64

Returns the maximum distance of the spline grid.

Source

pub const fn grid_type(&self) -> GridType

Returns the grid type used for construction.

Source

pub const fn n_points(&self) -> usize

Returns the number of grid points.

Source

pub const fn inv_delta(&self) -> f64

Returns the inverse grid spacing.

Source

pub const fn delta(&self) -> f64

Returns the grid spacing.

Source

pub fn new<P: IsotropicTwobodyEnergy + Cutoff>( potential: &P, config: SplineConfig, ) -> Self

Create a new splined potential from an analytical potential with a Cutoff.

§Arguments
  • potential - The analytical potential to tabulate (must implement Cutoff)
  • config - Configuration for the spline table
§Panics

Panics if n_points < 4, if rsq_min >= rsq_max, or if cutoff is infinite

Source

pub fn with_cutoff<P: IsotropicTwobodyEnergy + Cutoff>( potential: &P, cutoff: f64, config: SplineConfig, ) -> Self

Create a new splined potential with an explicit cutoff distance.

Use this for potentials that have infinite cutoff, or when you want to override the potential’s native cutoff.

§Arguments
  • potential - The analytical potential to tabulate
  • cutoff - The cutoff distance (must be finite and positive)
  • config - Configuration for the spline table
§Panics

Panics if n_points < 4, if rsq_min >= rsq_max, or if cutoff is not finite/positive

Source§

impl SplinedPotential

Source

pub const fn cutoff_squared(&self) -> f64

Get the squared cutoff distance.

Source

pub fn stats(&self) -> SplineStats

Get table statistics for debugging.

Source

pub fn validate<P: IsotropicTwobodyEnergy>( &self, potential: &P, n_test: usize, ) -> ValidationResult

Validate spline accuracy against the original potential.

Source§

impl SplinedPotential

Source

pub fn energies_batch(&self, rsq_values: &[f64], out: &mut [f64])

Evaluate energy for multiple distances at once (scalar loop).

Source

pub fn evaluate_batch( &self, rsq_values: &[f64], energies: &mut [f64], forces: &mut [f64], )

Evaluate energy and force for multiple distances (scalar loop).

Source

pub fn to_simd(&self) -> SplineTableSimd

Convert to SIMD-friendly SoA layout for batch evaluation (f64).

Source

pub fn to_simd_f32(&self) -> SplineTableSimdF32

Convert to single-precision (f32) SIMD layout for faster evaluation.

Uses architecture-optimal SIMD width: f32x8 on x86_64, f32x4 on aarch64. Provides ~2x memory efficiency at the cost of reduced precision.

Trait Implementations§

Source§

impl Clone for SplinedPotential

Source§

fn clone(&self) -> SplinedPotential

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 Cutoff for SplinedPotential

Source§

fn cutoff(&self) -> f64

Cutoff distance (upper)
Source§

fn cutoff_squared(&self) -> f64

Squared cutoff distance
Source§

fn lower_cutoff(&self) -> f64

Cutoff distance (lower)
Source§

fn is_finite(&self) -> bool

Test if cutoff is finite
Source§

impl Debug for SplinedPotential

Source§

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

Formats the value using the given formatter. Read more
Source§

impl IsotropicTwobodyEnergy for SplinedPotential

Source§

fn isotropic_twobody_energy(&self, distance_squared: f64) -> f64

Evaluate energy at squared distance using cubic spline interpolation.

Returns 0.0 if rsq >= cutoff². For rsq < rsq_min, linearly extrapolates using the slope at r_min to maintain repulsive behavior.

Source§

fn isotropic_twobody_force(&self, distance_squared: f64) -> f64

Evaluate force at squared distance using cubic spline interpolation.

Returns 0.0 if rsq >= cutoff². Below r_min, scales as f(r_min) * r_min / r to stay consistent with the linear energy extrapolation in real-force space.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> AnisotropicTwobodyEnergy for T

Source§

fn anisotropic_twobody_energy(&self, orientation: &RelativeOrientation) -> f64

Interaction energy between a pair of anisotropic particles, 𝑈(𝒓).
Source§

fn anisotropic_twobody_force( &self, orientation: &RelativeOrientation, ) -> Vector3<f64>

Force magnitude due to an anisotropic interaction potential, 𝐹(𝒓) = -𝞩𝑈(𝒓)
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> DynClone for T
where T: Clone,

Source§

fn __clone_box(&self, _: Private) -> *mut ()

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> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<SS, SP> SupersetOf<SS> for SP
where SS: SubsetOf<SP>,

Source§

fn to_subset(&self) -> Option<SS>

The inverse inclusion map: attempts to construct self from the equivalent element of its superset. Read more
Source§

fn is_in_subset(&self) -> bool

Checks if self is actually part of its subset T (and can be converted to it).
Source§

fn to_subset_unchecked(&self) -> SS

Use with care! Same as self.to_subset but without any property checks. Always succeeds.
Source§

fn from_subset(element: &SS) -> SP

The inclusion map: converts self to the equivalent element of its superset.
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 = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.