QCalc is a free, open-source Modelica library to represent quantities using various units, including but not limited to SI. The approach is based on quantity calculus (hence the name "QCalc").
QCalc can be used like this:
import Q = QCalc.Quantities;
import U = QCalc.Units;
Q.Pressure p = U.atm + 50*U.Pa;
Nonscalar units such as degree Celsius and decibel are also supported. The
* and / operators are overloaded to call the unit's transformation (number
→ quantity) and its inverse, respectively. For example, this will give a
value of x = 100:
Real x = (0*U.degC + 100*U.K)/U.degC;
and this will too:
Real x = (10/U.dB + 10/U.dB)*U.dB;
since we have multiplied the numbers by adding their logarithms.
The quantities are not directly compatible with the Modelica Standard Library since MSL expresses quantities in SI units. To convert between QCalc and MSL, create an adapter with equations like this:
p = p_SI*U.Pa;
where p is pressure as a quantity (in QCalc), p_SI is pressure in
pascal (in MSL), and U.Pa is
the pascal from QCalc.Units.
More information is available in the documentation, which can be accessed online or from the top level of the package. If you wish to use the same approach with Modelica results in Python, consider ModelicaRes and natu.
QCalc is published under the Modelica License 2 (see the
User's Guide).
If you find a bug, have a suggestion, or just want to leave a comment, please
open an issue. If possible,
please share any fixes and improvements as pull requests to the master branch
of the GitHub repository.