Cantera 2.6.0

Public Member Functions | Private Attributes | List of all members
UnitSystem Class Reference
Input File Handling

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...

## Detailed Description

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.

Definition at line 160 of file Units.h.

## Constructor & Destructor Documentation

## ◆ UnitSystem() [1/2]

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().

## ◆ UnitSystem() [2/2]

UnitSystem | ( |  | ) |
| inline

Default constructor for unit system (needed as VS2019 does not recognize an optional argument with a default value)

Definition at line 168 of file Units.h.

## Member Function Documentation

## ◆ defaults()

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().

## ◆ setDefaults() [1/2]

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.

- To use SI+kmol: `setDefaults({"kg", "m", "s", "Pa", "J", "kmol"});`
- To use CGS+mol: `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().

## ◆ setDefaults() [2/2]

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:

UnitSystem system;
std::map<string, string> defaults{
{"length", "m"}, {"mass", "kg"}, {"time", "s"},
{"quantity", "kmol"}, {"pressure", "Pa"}, {"energy", "J"},
{"activation-energy", "J/kmol"}
};
setDefaults(defaults);
Cantera::UnitSystem
Unit conversion utility.
Definition: Units.h:161
Cantera::UnitSystem::defaults
std::map< std::string, std::string > defaults() const
Return default units used by the unit system.
Definition: Units.cpp:417
Cantera::UnitSystem::setDefaults
void setDefaults(std::initializer_list< std::string > units)
Set the default units to convert from when explicit units are not provided.
Definition: Units.cpp:447

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().

## ◆ setDefaultActivationEnergy()

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().

## ◆ convert() [1/6]

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().

## ◆ convert() [2/6]

double convert | ( | double | value,
|  | const Units & | src,
|  | const Units & | dest
| ) |  | const

Definition at line 564 of file Units.cpp.

## ◆ convertTo() [1/2]

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().

## ◆ convertTo() [2/2]

double convertTo | ( | double | value,
|  | const Units & | dest
| ) |  | const

Definition at line 580 of file Units.cpp.

## ◆ convertFrom() [1/2]

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().

## ◆ convertFrom() [2/2]

double convertFrom | ( | double | value,
|  | const Units & | src
| ) |  | const

Definition at line 596 of file Units.cpp.

## ◆ convert() [3/6]

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() [4/6]

double convert | ( | const AnyValue & | val,
|  | const Units & | dest
| ) |  | const

Definition at line 630 of file Units.cpp.

## ◆ convert() [5/6]

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`.

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().

## ◆ convert() [6/6]

vector_fp convert | ( | const std::vector< AnyValue > & | vals,
|  | const Units & | dest
| ) |  | const

Definition at line 648 of file Units.cpp.

## ◆ convertActivationEnergy() [1/2]

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().

## ◆ convertActivationEnergyTo() [1/2]

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().

## ◆ convertActivationEnergyTo() [2/2]

double convertActivationEnergyTo | ( | double | value,
|  | const Units & | dest
| ) |  | const

Definition at line 696 of file Units.cpp.

## ◆ convertActivationEnergyFrom()

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.

## ◆ convertActivationEnergy() [2/2]

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().

## ◆ getDelta()

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().

## Member Data Documentation

## ◆ m_mass_factor

double m_mass_factor
| 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().

## ◆ m_length_factor

double m_length_factor
| 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().

## ◆ m_time_factor

double m_time_factor
| 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().

## ◆ m_pressure_factor

double m_pressure_factor
| 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().

## ◆ m_energy_factor

double m_energy_factor
| 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().

## ◆ m_activation_energy_factor

double m_activation_energy_factor
| 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().

## ◆ m_quantity_factor

double m_quantity_factor
| 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().

## ◆ m_explicit_activation_energy

bool m_explicit_activation_energy
| 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().

## ◆ m_defaults

std::map<std::string, std::string> m_defaults
| 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().

The documentation for this class was generated from the following files:

- Units.h
- Units.cpp