Skip to main content

Tolerances

Struct Tolerances 

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

Compare two ledgers and name the first quantity that moved by more than rel_tol, in the fixed order the ledger keeps its names.

The change is measured against the largest of the two totals and the largest single entry either ledger recorded. See the module docs for why the totals alone are not enough: a correct system whose books cancel to zero would otherwise turn every rounding error into a 100% relative error.

Quantities present in only one of the two are treated as having been zero in the other, so a process that starts reporting momentum halfway through gets caught rather than excused. What each conserved quantity is allowed to drift by, relatively, across a step.

§Why this is not one number

It was, and the reason it stopped being is worth stating: the loosest quantity in a simulation was setting what every other one was checked against. A Barnes-Hut N-body gives up exact momentum by construction — each body sees its own approximation of the rest, so their mutual forces no longer cancel — and the drift is a knob set by the opening angle, worth perhaps 1e-6. Energy in a rigid room is exact to 1e-15. Run both in one simulation under a single number and either the momentum check refuses a correct run or the energy check stops being able to see anything.

A quantity’s achievable accuracy is a property of the scheme that carries it, and different quantities in one simulation are carried by different schemes. So it is a number per quantity, with a default for the ones nobody has thought about.

§What this does not fix

Two domains holding the same quantity to different accuracies. A molecular fluid under a thermostat and an acoustic room both hold energy, and the audit sums their ledgers before comparing — so a small domain’s leak is invisible against a large domain’s total, whatever tolerance is set. That needs per-domain attribution rather than a per-quantity number, and it is a different and harder change: it requires knowing which domain took what from the bus. Recorded in ARCHITECTURE.md rather than half-done here.

Implementations§

Source§

impl Tolerances

Source

pub fn uniform(tol: f64) -> Tolerances

The same number for every quantity — what a simulation has until it says otherwise.

Source

pub fn with(self, quantity: &'static str, tol: f64) -> Tolerances

Override one quantity.

Takes &'static str because a quantity name is a compile-time fact — quantity::ENERGY — and not something read from a file. Two spellings of the same channel are two channels, which is a mistake worth making impossible rather than catching.

Source

pub fn for_quantity(&self, quantity: &str) -> f64

What applies to this quantity.

Source

pub fn default_tolerance(&self) -> f64

What applies to a quantity nobody has named.

Source

pub fn overrides(&self) -> impl Iterator<Item = (&'static str, f64)> + '_

Every override, in name order.

Public so a report can say what a run was actually checked against. A tolerance nobody can read is a tolerance nobody can question.

Trait Implementations§

Source§

impl Clone for Tolerances

Source§

fn clone(&self) -> Tolerances

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 Debug for Tolerances

Source§

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

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

impl Default for Tolerances

Source§

fn default() -> Tolerances

1e-9 everywhere, which is what a single-number simulation used to default to.

Source§

impl PartialEq for Tolerances

Source§

fn eq(&self, other: &Tolerances) -> 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 Tolerances

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> 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.