Skip to main content

DiffScheme

Enum DiffScheme 

Source
pub enum DiffScheme {
    Forward,
    Backward,
    Central,
    Central4th,
}
Expand description

Which finite-difference stencil to use.

The choice is a cost against accuracy trade, and both halves are measured — see the module-level “Achievable accuracy” table for the observed error floors and “Cost” for the evaluation counts.

§Units

Dimensionless — a mode selector, not a quantity.

Variants§

§

Forward

(f(x + h) - f(x)) / h. Truncation error O(h).

The cheapest scheme for a Jacobian: the base evaluation f(x) is shared by every column, so an n-dimensional Jacobian costs n + 1 evaluations rather than 2n.

§

Backward

(f(x) - f(x - h)) / h. Truncation error O(h).

Same cost and accuracy as Forward; it exists for callers whose function is undefined or unphysical just above x — a saturation pressure at the phase boundary, a volume fraction at 1.

§

Central

(f(x + h) - f(x - h)) / (2h). Truncation error O(h^2). The default.

This is the scheme both existing workspace implementations use — see the module-level “Provenance” section.

§

Central4th

Richardson extrapolation of two central differences, (4*D(h/2) - D(h)) / 3. Truncation error O(h^4).

The most accurate scheme here and the most expensive: 4 evaluations per derivative and 4n per Jacobian, because the h and h/2 stencils share no points.

Implementations§

Source§

impl DiffScheme

Source

pub fn default_relative_step(self) -> f64

The relative step size that balances truncation against round-off for this scheme in f64.

Truncation error goes as h^p and round-off as eps/h, so the balance is at h ~ eps^(1/(p+1)):

SchemeOrder pOptimal relative step
Forward, Backward1crate::math::minimise::SQRT_EPSILON = 1.4901161193847656e-8
Central2CBRT_EPSILON = 6.0554544523933395e-6
Central4th4FIFTH_ROOT_EPSILON = 7.40095979741405e-4
§Units

Dimensionless — it multiplies a length scale in x to give a step in x.

Source

pub fn evaluations_per_derivative(self) -> usize

How many evaluations of the function one scalar derivative costs.

§Units

A count, dimensionless.

Source

pub fn evaluations_per_jacobian(self, n: usize) -> usize

How many evaluations of the vector function an n-dimensional Jacobian costs.

Forward and Backward get n + 1 because the unperturbed evaluation is shared across all n columns; Central gets 2n and Central4th 4n because their stencils are symmetric about x and so share nothing.

§Arguments
  • n — the dimension of the point, dimensionless.
§Units

A count, dimensionless.

§Example
use outram_foam_basic_lib::math::differentiate::DiffScheme;

assert_eq!(DiffScheme::Forward.evaluations_per_jacobian(10), 11);
assert_eq!(DiffScheme::Central.evaluations_per_jacobian(10), 20);
assert_eq!(DiffScheme::Central4th.evaluations_per_jacobian(10), 40);
Source

pub fn label(self) -> &'static str

A short human-readable label, for benchmark tables and log lines.

Trait Implementations§

Source§

impl Clone for DiffScheme

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 Copy for DiffScheme

Source§

impl Debug for DiffScheme

Source§

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

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

impl Default for DiffScheme

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl Eq for DiffScheme

Source§

impl Hash for DiffScheme

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl PartialEq for DiffScheme

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for DiffScheme

Auto Trait Implementations§

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

Source§

type Output = T

Should always be Self
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.