chemmisol 0.1
|
#include <unordered_map>
#include <string>
Go to the source code of this file.
Namespaces | |
namespace | chemmisol |
Macros | |
#define | UNITS(F) |
Defines available units. | |
#define | UNIT_DEF(NAME, VALUE, CATEGORY) extern const double NAME; |
#define | UNIT_VALUE(NAME, VALUE, CATEGORY) const double NAME = VALUE; |
#define | UNIT_NAME_TO_CATEGORY(NAME, VALUE, CATEGORY) {#NAME, Category::CATEGORY}, |
Enumerations | |
enum | chemmisol::Category { MASS , LENGTH , VOLUME , SURFACE , QUANTITY } |
Variables | |
const double | chemmisol::NA |
Defines units related features.
#define UNITS | ( | F | ) |
Defines available units.
Chemmisol defines a unit system inspired from GAMA units.
However, even if very useful when directly using the library, the unit system might be problematic when attempting to embed the library in other systems or languages.
In order to solve those issues, it is necessary to enforce the specification of the unit system used by chemmisol.
Any quantity specified with units is converted internally to a value that corresponds to the same value expressed in the core unit of the same category.
In consequence, it is safe to use raw values without units in chemmisol, as long as it can be ensure that it's value corresponds to a value expressed in a core unit.
Internally, core units corresponds to UNITS() with a value of 1.
For example, the core unit for volumes is the liter l
. This means that the value 1.5*l
is represented internally by 1.5f
, while 1.2*cm3
is represented as 1.2 * 10-3 = 1.2e-3f
. The interest of this system is that unit conversion is automatically performed by the library. For example, it is perfectly possible to write double distance = 1*km + 15*m
without bothering about unit conversion (in this example, distance
is automatically converted to the core unit m
with a value of 1015.0
). Considering the definition of core units, specifying directly double distance = 1015.0
is equivalent in chemmisol.
A value defined with a chemmisol unit can still be expressed in an other unit, dividing the value by the desired unit. For example:
The following table sums up all the core units used by chemmisol:
Use case | Unit |
---|---|
Distance | m |
Surface | m2 |
Volume | l |
Mass | g |
Quantity | mol |
The core unit of derived units can be obtained with the same expression as the derived unit expressed in core units. For example, the core unit for molar concentrations is mol/l
.
is equivalent to
#define UNIT_DEF | ( | NAME, | |
VALUE, | |||
CATEGORY | |||
) | extern const double NAME; |
Defines an unit.
#define UNIT_VALUE | ( | NAME, | |
VALUE, | |||
CATEGORY | |||
) | const double NAME = VALUE; |
Defines the value of an unit.
#define UNIT_NAME_TO_CATEGORY | ( | NAME, | |
VALUE, | |||
CATEGORY | |||
) | {#NAME, Category::CATEGORY}, |
Defines the caterory of an unit.