![]() |
Cantera
3.0.0
|
Unit conversion utility. More...
#include <Units.h>
Unit conversion utility.
Provides functions for converting dimensional values from a given unit system. The main use is for converting values specified in input files to Cantera's native unit system, which is SI units except for the use of kmol as the base unit of quantity, that is, kilogram, meter, second, kelvin, ampere, and kmol.
String representations of units can be written using multiplication, division, and exponentiation. Spaces are ignored. Positive, negative, and decimal exponents are permitted. Examples:
kg*m/s^2 J/kmol m*s^-2 J/kg/K
Metric prefixes are recognized for all units, such as nm, hPa, mg, EJ, mL, kcal.
Special functions for converting activation energies allow these values to be expressed as either energy per quantity, energy (for example, eV), or temperature by applying a factor of the Avogadro number or the gas constant where needed.
Public Member Functions | |
UnitSystem (std::initializer_list< string > units) | |
Create a unit system with the specified default units. | |
UnitSystem () | |
Default constructor for unit system (needed as VS2019 does not recognize an optional argument with a default value) | |
map< string, string > | defaults () const |
Return default units used by the unit system. | |
void | setDefaults (std::initializer_list< string > units) |
Set the default units to convert from when explicit units are not provided. | |
void | setDefaults (const map< string, string > &units) |
Set the default units using a map of dimension to unit pairs. | |
void | setDefaultActivationEnergy (const string &e_units) |
Set the default units to convert from when using the convertActivationEnergy function. | |
double | convert (double value, const string &src, const string &dest) const |
Convert value from the units of src to the units of dest . | |
double | convert (double value, const Units &src, const Units &dest) const |
double | convertTo (double value, const string &dest) const |
Convert value to the specified dest units from the appropriate units for this unit system (defined by setDefaults ) | |
double | convertTo (double value, const Units &dest) const |
double | convertFrom (double value, const string &src) const |
Convert value from the specified src units to units appropriate for this unit system (defined by setDefaults ) | |
double | convertFrom (double value, const Units &src) const |
double | convert (const AnyValue &val, const string &dest) const |
Convert a generic AnyValue node to the units specified in dest . | |
double | convert (const AnyValue &val, const Units &dest) const |
double | convertRateCoeff (const AnyValue &val, const Units &dest) const |
Convert a generic AnyValue node representing a reaction rate coefficient to the units specified in dest . | |
vector< double > | convert (const vector< AnyValue > &vals, const string &dest) const |
Convert an array of AnyValue nodes to the units specified in dest . | |
vector< double > | convert (const vector< AnyValue > &vals, const Units &dest) const |
double | convertActivationEnergy (double value, const string &src, const string &dest) const |
Convert value from the units of src to the units of dest , allowing for the different dimensions that can be used for activation energies. | |
double | convertActivationEnergyTo (double value, const string &dest) const |
Convert value to the units specified by dest from the default activation energy units. | |
double | convertActivationEnergyTo (double value, const Units &dest) const |
double | convertActivationEnergyFrom (double value, const string &src) const |
Convert value from the units specified by src to the default activation energy units. | |
double | convertActivationEnergy (const AnyValue &val, const string &dest) const |
Convert a generic AnyValue node to the units specified in dest . | |
AnyMap | getDelta (const UnitSystem &other) const |
Get the changes to the defaults from other to this UnitSystem. | |
Private Attributes | |
double | m_mass_factor = 1.0 |
Factor to convert mass from this unit system to kg. | |
double | m_length_factor = 1.0 |
Factor to convert length from this unit system to meters. | |
double | m_time_factor = 1.0 |
Factor to convert time from this unit system to seconds. | |
double | m_pressure_factor = 1.0 |
Factor to convert pressure from this unit system to Pa. | |
double | m_energy_factor = 1.0 |
Factor to convert energy from this unit system to J. | |
double | m_activation_energy_factor = 1.0 |
Factor to convert activation energy from this unit system to J/kmol. | |
double | m_quantity_factor = 1.0 |
Factor to convert quantity from this unit system to kmol. | |
bool | m_explicit_activation_energy = false |
True if activation energy units are set explicitly, rather than as a combination of energy and quantity units. | |
map< string, string > | m_defaults |
Map of dimensions (mass, length, etc.) to names of specified default units. | |
UnitSystem | ( | std::initializer_list< string > | units | ) |
|
inline |
map< string, string > defaults | ( | ) | const |
void setDefaults | ( | std::initializer_list< string > | units | ) |
Set the default units to convert from when explicit units are not provided.
Defaults can be set for mass, length, time, quantity, energy, and pressure. Conversion using the pressure or energy units is done only when the target units explicitly contain pressure or energy units.
setDefaults({"kg", "m", "s", "Pa", "J", "kmol"});
setDefaults({"cm", "g", "dyn/cm^2", "erg", "mol"});
void setDefaults | ( | const map< string, string > & | units | ) |
Set the default units using a map of dimension to unit pairs.
Defaults for dimensions not specified will be left unchanged. To use Cantera's default units:
void setDefaultActivationEnergy | ( | const string & | e_units | ) |
double convert | ( | double | value, |
const string & | src, | ||
const string & | dest | ||
) | const |
double convertTo | ( | double | value, |
const string & | dest | ||
) | const |
double convertTo | ( | double | value, |
const Units & | dest | ||
) | const |
double convertFrom | ( | double | value, |
const string & | src | ||
) | const |
double convertFrom | ( | double | value, |
const Units & | src | ||
) | const |
double convert | ( | const AnyValue & | val, |
const string & | dest | ||
) | const |
vector< double > convert | ( | const vector< AnyValue > & | vals, |
const string & | dest | ||
) | const |
double convertActivationEnergy | ( | double | value, |
const string & | src, | ||
const string & | dest | ||
) | const |
double convertActivationEnergyTo | ( | double | value, |
const string & | dest | ||
) | const |
double convertActivationEnergyTo | ( | double | value, |
const Units & | dest | ||
) | const |
double convertActivationEnergyFrom | ( | double | value, |
const string & | src | ||
) | const |
double convertActivationEnergy | ( | const AnyValue & | val, |
const string & | dest | ||
) | const |
AnyMap getDelta | ( | const UnitSystem & | other | ) | const |
Get the changes to the defaults from other
to this UnitSystem.
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |