Cantera 2.6.0
|
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... | |
std::map< std::string, std::string > | defaults () const |
Return default units used by the unit system. 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 | convertTo (double value, const std::string &dest) const |
Convert value to the specified dest units from the appropriate units for this unit system (defined by setDefaults ) More... | |
double | convertTo (double value, const Units &dest) const |
double | convertFrom (double value, const std::string &src) const |
Convert value from the specified src units to units appropriate for this unit system (defined by setDefaults ) More... | |
double | convertFrom (double value, const Units &src) 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 | convertActivationEnergyTo (double value, const std::string &dest) const |
Convert value to the units specified by dest from the default activation energy units. More... | |
double | convertActivationEnergyTo (double value, const Units &dest) const |
double | convertActivationEnergyFrom (double value, const std::string &src) const |
Convert value from the units specified by src to the default activation energy units. More... | |
double | convertActivationEnergy (const AnyValue &val, const std::string &dest) const |
Convert a generic AnyValue node to the units specified in dest . More... | |
AnyMap | getDelta (const UnitSystem &other) const |
Get the changes to the defaults from other to this UnitSystem. 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... | |
std::map< std::string, std::string > | m_defaults |
Map of dimensions (mass, length, etc.) to names of specified default 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, 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.
UnitSystem | ( | std::initializer_list< std::string > | units | ) |
Create a unit system with the specified default units.
Definition at line 404 of file Units.cpp.
References UnitSystem::setDefaults().
|
inline |
std::map< std::string, std::string > defaults | ( | ) | const |
Return default units used by the unit system.
Definition at line 417 of file Units.cpp.
References UnitSystem::defaults(), and UnitSystem::m_defaults.
Referenced by UnitSystem::defaults().
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 447 of file Units.cpp.
References UnitSystem::m_activation_energy_factor, UnitSystem::m_defaults, 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 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 491 of file Units.cpp.
References Units::convertible(), Units::factor(), UnitSystem::m_activation_energy_factor, UnitSystem::m_defaults, 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 541 of file Units.cpp.
References Cantera::Avogadro, Units::convertible(), Units::factor(), Cantera::GasConstant, UnitSystem::m_activation_energy_factor, UnitSystem::m_defaults, 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 558 of file Units.cpp.
References UnitSystem::convert().
Referenced by AnyMap::convert(), UnitSystem::convert(), AnyMap::convertVector(), PDSS_SSVol::initThermo(), PengRobinson::initThermo(), RedlichKwongMFTP::initThermo(), and ChebyshevRate::setParameters().
double convertTo | ( | double | value, |
const std::string & | dest | ||
) | const |
Convert value
to the specified dest
units from the appropriate units for this unit system (defined by setDefaults
)
Definition at line 575 of file Units.cpp.
References UnitSystem::convertTo().
Referenced by UnitSystem::convertTo(), Cantera::newReactionRate(), and ChebyshevRate::setParameters().
double convertTo | ( | double | value, |
const Units & | dest | ||
) | const |
double convertFrom | ( | double | value, |
const std::string & | src | ||
) | const |
Convert value
from the specified src
units to units appropriate for this unit system (defined by setDefaults
)
Definition at line 591 of file Units.cpp.
References UnitSystem::convertFrom().
Referenced by UnitSystem::convertFrom().
double convertFrom | ( | double | value, |
const Units & | src | ||
) | const |
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, such as '988 kg/m^3' and convert from the specified units.
Definition at line 625 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 642 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 658 of file Units.cpp.
References Cantera::Avogadro, Units::convertible(), Units::factor(), and Cantera::GasConstant.
Referenced by UnitSystem::convertActivationEnergy().
double convertActivationEnergyTo | ( | double | value, |
const std::string & | dest | ||
) | const |
Convert value
to the units specified by dest
from the default activation energy units.
Definition at line 690 of file Units.cpp.
References UnitSystem::convertActivationEnergyTo().
Referenced by UnitSystem::convertActivationEnergy(), and UnitSystem::convertActivationEnergyTo().
double convertActivationEnergyTo | ( | double | value, |
const Units & | dest | ||
) | const |
double convertActivationEnergyFrom | ( | double | value, |
const std::string & | src | ||
) | const |
Convert value
from the units specified by src
to the default activation energy units.
Definition at line 711 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, such as '2.7e4 J/kmol', and convert from the specified units.
Definition at line 727 of file Units.cpp.
References UnitSystem::convertActivationEnergy(), and UnitSystem::convertActivationEnergyTo().
AnyMap getDelta | ( | const UnitSystem & | other | ) | const |
Get the changes to the defaults from other
to this UnitSystem.
Definition at line 740 of file Units.cpp.
References UnitSystem::m_activation_energy_factor, UnitSystem::m_defaults, 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 AnyMap::setUnits().
|
private |
Factor to convert mass from this unit system to kg.
Definition at line 257 of file Units.h.
Referenced by UnitSystem::getDelta(), and UnitSystem::setDefaults().
|
private |
Factor to convert length from this unit system to meters.
Definition at line 260 of file Units.h.
Referenced by UnitSystem::getDelta(), and UnitSystem::setDefaults().
|
private |
Factor to convert time from this unit system to seconds.
Definition at line 263 of file Units.h.
Referenced by UnitSystem::getDelta(), and UnitSystem::setDefaults().
|
private |
Factor to convert pressure from this unit system to Pa.
Definition at line 266 of file Units.h.
Referenced by UnitSystem::getDelta(), and UnitSystem::setDefaults().
|
private |
Factor to convert energy from this unit system to J.
Definition at line 269 of file Units.h.
Referenced by UnitSystem::getDelta(), and UnitSystem::setDefaults().
|
private |
Factor to convert activation energy from this unit system to J/kmol.
Definition at line 272 of file Units.h.
Referenced by UnitSystem::convertActivationEnergyFrom(), UnitSystem::getDelta(), UnitSystem::setDefaultActivationEnergy(), and UnitSystem::setDefaults().
|
private |
Factor to convert quantity from this unit system to kmol.
Definition at line 275 of file Units.h.
Referenced by UnitSystem::getDelta(), and UnitSystem::setDefaults().
|
private |
True if activation energy units are set explicitly, rather than as a combination of energy and quantity units.
Definition at line 279 of file Units.h.
Referenced by UnitSystem::getDelta(), UnitSystem::setDefaultActivationEnergy(), and UnitSystem::setDefaults().
|
private |
Map of dimensions (mass, length, etc.) to names of specified default units.
Definition at line 283 of file Units.h.
Referenced by UnitSystem::defaults(), UnitSystem::getDelta(), UnitSystem::setDefaultActivationEnergy(), and UnitSystem::setDefaults().