Handler classes related to residuals¶
Residuals are used both by Model and by simu.ThermoContribution.
Residual¶
- class simu.core.utilities.residual.Residual¶
Class representing a single residual.
The post-constructor will raise a
DimensionalityErrorif thetoleranceunit is not compatible with thevalueunit.A possible offset in the tolerance unit, such as in degrees Celsius or gauge pressures, will be eliminated automatically. That is:
>>> from simu import SymbolQuantity as S, Quantity as Q >>> val = S("r", "barg") >>> r1 = Residual(val, Q(1e-7, "barg")) >>> r2 = Residual(val, Q(1e-7, "bar")) >>> f"{r1.tolerance - r2.tolerance:.15f~}" '0.000000000000000 bar'
(there is a silly rounding error, hence the trick with the formatting to make this doctest work)
ResidualHandler¶
- class simu.core.utilities.residual.ResidualHandler¶
This class, being instantiated as the
simu.Model.residualsattribute, allows to define residuals, i.e. process constraints.- __init__()¶
- add( )¶
Define a residual, to approach zero withing its tolerance when the model is solved.
- Parameters:
name – A unique name within the local context
residual – The residual to be zero.
tol_unit – The unit of the tolerance, which must be compatible with the unit of the residual quantity.
tol – The tolerance value. A normal recommendation is to give
1e-7for a typical unit of measurement, which for extensive variables is largely problem size dependent. An industrial flow is typically characterized bykg/h, while a lab scale experiment can operate withg/h.