Cantera
2.5.1
|
Unit conversion utility. More...
#include <Units.h>
Public Member Functions | |
UnitSystem (std::initializer_list< std::string > units) | |
Create a unit system with the specified default units. More... | |
UnitSystem () | |
Default constructor for unit system (needed as VS2019 does not recognize an optional argument with a default value) More... | |
void | setDefaults (std::initializer_list< std::string > units) |
Set the default units to convert from when explicit units are not provided. More... | |
void | setDefaults (const std::map< std::string, std::string > &units) |
Set the default units using a map of dimension to unit pairs. More... | |
void | setDefaultActivationEnergy (const std::string &e_units) |
Set the default units to convert from when using the convertActivationEnergy function. More... | |
double | convert (double value, const std::string &src, const std::string &dest) const |
Convert value from the units of src to the units of dest . More... | |
double | convert (double value, const Units &src, const Units &dest) const |
double | convert (double value, const std::string &dest) const |
Convert value from this unit system (defined by setDefaults ) to the specified units. More... | |
double | convert (double value, const Units &dest) const |
double | convert (const AnyValue &val, const std::string &dest) const |
Convert a generic AnyValue node to the units specified in dest . More... | |
double | convert (const AnyValue &val, const Units &dest) const |
vector_fp | convert (const std::vector< AnyValue > &vals, const std::string &dest) const |
Convert an array of AnyValue nodes to the units specified in dest . More... | |
vector_fp | convert (const std::vector< AnyValue > &vals, const Units &dest) const |
double | convertActivationEnergy (double value, const std::string &src, const std::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. More... | |
double | convertActivationEnergy (double value, const std::string &dest) const |
Convert value from the default activation energy units to the specified units. More... | |
double | convertActivationEnergy (const AnyValue &val, const std::string &dest) const |
Convert a generic AnyValue node to the units specified in dest . More... | |
Private Attributes | |
double | m_mass_factor |
Factor to convert mass from this unit system to kg. More... | |
double | m_length_factor |
Factor to convert length from this unit system to meters. More... | |
double | m_time_factor |
Factor to convert time from this unit system to seconds. More... | |
double | m_pressure_factor |
Factor to convert pressure from this unit system to Pa. More... | |
double | m_energy_factor |
Factor to convert energy from this unit system to J. More... | |
double | m_activation_energy_factor |
Factor to convert activation energy from this unit system to J/kmol. More... | |
double | m_quantity_factor |
Factor to convert quantity from this unit system to kmol. More... | |
bool | m_explicit_activation_energy |
True if activation energy units are set explicitly, rather than as a combination of energy and quantity units. More... | |
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, i.e. 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, e.g. nm, hPa, mg, EJ, mL, kcal.
Special functions for converting activation energies allow these values to be expressed as either energy per quantity, energy (e.g. eV), or temperature by applying a factor of the Avogadro number or the gas constant where needed.
UnitSystem | ( | std::initializer_list< std::string > | units | ) |
Create a unit system with the specified default units.
Definition at line 228 of file Units.cpp.
References UnitSystem::setDefaults().
|
inline |
void setDefaults | ( | std::initializer_list< std::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"});
Definition at line 241 of file Units.cpp.
References UnitSystem::m_activation_energy_factor, UnitSystem::m_energy_factor, UnitSystem::m_explicit_activation_energy, UnitSystem::m_length_factor, UnitSystem::m_mass_factor, UnitSystem::m_pressure_factor, UnitSystem::m_quantity_factor, and UnitSystem::m_time_factor.
Referenced by AnyValue::applyUnits(), AnyMap::applyUnits(), and UnitSystem::UnitSystem().
void setDefaults | ( | const std::map< std::string, std::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:
Definition at line 270 of file Units.cpp.
References Units::convertible(), Units::factor(), UnitSystem::m_activation_energy_factor, UnitSystem::m_energy_factor, UnitSystem::m_explicit_activation_energy, UnitSystem::m_length_factor, UnitSystem::m_mass_factor, UnitSystem::m_pressure_factor, UnitSystem::m_quantity_factor, UnitSystem::m_time_factor, UnitSystem::setDefaultActivationEnergy(), and Units::str().
void setDefaultActivationEnergy | ( | const std::string & | e_units | ) |
Set the default units to convert from when using the convertActivationEnergy
function.
Definition at line 306 of file Units.cpp.
References Cantera::Avogadro, Units::convertible(), Units::factor(), Cantera::GasConstant, UnitSystem::m_activation_energy_factor, and UnitSystem::m_explicit_activation_energy.
Referenced by UnitSystem::setDefaults().
double convert | ( | double | value, |
const std::string & | src, | ||
const std::string & | dest | ||
) | const |
Convert value
from the units of src
to the units of dest
.
Definition at line 322 of file Units.cpp.
Referenced by AnyMap::convert(), UnitSystem::convert(), AnyMap::convertVector(), PDSS_SSVol::initThermo(), and RedlichKwongMFTP::initThermo().
double convert | ( | double | value, |
const std::string & | dest | ||
) | const |
Convert value
from this unit system (defined by setDefaults
) to the specified units.
Definition at line 338 of file Units.cpp.
References UnitSystem::convert().
double convert | ( | const AnyValue & | val, |
const std::string & | dest | ||
) | const |
Convert a generic AnyValue node to the units specified in dest
.
If the input is a double, convert it using the default units. If the input is a string, treat this as a dimensioned value, e.g. '988 kg/m^3' and convert from the specified units.
Definition at line 372 of file Units.cpp.
References UnitSystem::convert().
Convert an array of AnyValue nodes to the units specified in dest
.
For each node, if the value is a double, convert it using the default units, and if it is a string, treat it as a value with the given dimensions.
Definition at line 389 of file Units.cpp.
References UnitSystem::convert().
double convertActivationEnergy | ( | double | value, |
const std::string & | src, | ||
const std::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.
Definition at line 405 of file Units.cpp.
References Cantera::Avogadro, Units::convertible(), Units::factor(), and Cantera::GasConstant.
Referenced by UnitSystem::convertActivationEnergy().
double convertActivationEnergy | ( | double | value, |
const std::string & | dest | ||
) | const |
Convert value
from the default activation energy units to the specified units.
Definition at line 437 of file Units.cpp.
References Cantera::Avogadro, Units::convertible(), Units::factor(), Cantera::GasConstant, and UnitSystem::m_activation_energy_factor.
double convertActivationEnergy | ( | const AnyValue & | val, |
const std::string & | dest | ||
) | const |
Convert a generic AnyValue node to the units specified in dest
.
If the input is a double, convert it using the default units. If the input is a string, treat this as a dimensioned value, e.g. '2.7e4 J/kmol' and convert from the specified units.
Definition at line 453 of file Units.cpp.
References UnitSystem::convertActivationEnergy().
|
private |
Factor to convert mass from this unit system to kg.
Definition at line 187 of file Units.h.
Referenced by UnitSystem::setDefaults().
|
private |
Factor to convert length from this unit system to meters.
Definition at line 190 of file Units.h.
Referenced by UnitSystem::setDefaults().
|
private |
Factor to convert time from this unit system to seconds.
Definition at line 193 of file Units.h.
Referenced by UnitSystem::setDefaults().
|
private |
Factor to convert pressure from this unit system to Pa.
Definition at line 196 of file Units.h.
Referenced by UnitSystem::setDefaults().
|
private |
Factor to convert energy from this unit system to J.
Definition at line 199 of file Units.h.
Referenced by UnitSystem::setDefaults().
|
private |
Factor to convert activation energy from this unit system to J/kmol.
Definition at line 202 of file Units.h.
Referenced by UnitSystem::convertActivationEnergy(), UnitSystem::setDefaultActivationEnergy(), and UnitSystem::setDefaults().
|
private |
Factor to convert quantity from this unit system to kmol.
Definition at line 205 of file Units.h.
Referenced by UnitSystem::setDefaults().
|
private |
True if activation energy units are set explicitly, rather than as a combination of energy and quantity units.
Definition at line 209 of file Units.h.
Referenced by UnitSystem::setDefaultActivationEnergy(), and UnitSystem::setDefaults().