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
impl Tolerances
Sourcepub fn uniform(tol: f64) -> Tolerances
pub fn uniform(tol: f64) -> Tolerances
The same number for every quantity — what a simulation has until it says otherwise.
Sourcepub fn with(self, quantity: &'static str, tol: f64) -> Tolerances
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.
Sourcepub fn for_quantity(&self, quantity: &str) -> f64
pub fn for_quantity(&self, quantity: &str) -> f64
What applies to this quantity.
Sourcepub fn default_tolerance(&self) -> f64
pub fn default_tolerance(&self) -> f64
What applies to a quantity nobody has named.
Trait Implementations§
Source§impl Clone for Tolerances
impl Clone for Tolerances
Source§fn clone(&self) -> Tolerances
fn clone(&self) -> Tolerances
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for Tolerances
impl Debug for Tolerances
Source§impl Default for Tolerances
impl Default for Tolerances
Source§fn default() -> Tolerances
fn default() -> Tolerances
1e-9 everywhere, which is what a single-number simulation used to default to.