conspire/math/optimize/tolerance/mod.rs
1use super::super::{Quantity, Scalar};
2use crate::ABS_TOL;
3
4/// Absolute error tolerances.
5///
6/// A constrained problem meets two quantities of different units, so one
7/// number cannot serve them both. Which units those are is settled by the
8/// problem rather than chosen here, so each is named where it is read back
9/// rather than where it is set.
10#[derive(Clone, Copy, Debug)]
11pub struct Tolerances {
12 /// Absolute error tolerance on the constraints.
13 pub constraint: Scalar,
14 /// Absolute error tolerance on the residual.
15 pub residual: Scalar,
16}
17
18impl Tolerances {
19 /// The tolerance on the constraint violation, as the unit it is met in.
20 pub const fn constraint<U>(&self) -> Quantity<U> {
21 Quantity::new(self.constraint)
22 }
23 /// The tolerance on the residual, as the unit it is met in.
24 pub const fn residual<U>(&self) -> Quantity<U> {
25 Quantity::new(self.residual)
26 }
27}
28
29impl Default for Tolerances {
30 fn default() -> Self {
31 Self {
32 constraint: ABS_TOL,
33 residual: ABS_TOL,
34 }
35 }
36}