Skip to content

Commit

Permalink
[Python] Clarify use of unit conversion functions
Browse files Browse the repository at this point in the history
  • Loading branch information
speth authored and ischoegl committed Apr 18, 2023
1 parent 8f3b106 commit e82f932
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
16 changes: 13 additions & 3 deletions interfaces/cython/cantera/reaction.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -742,9 +742,9 @@ cdef class ExtensibleRate(ReactionRate):
of the rate parameterization and its corresponding data class, and to make these
rates constructible through factory functions and input files.
Classes derived from `ExtensibleRate` should implement the `set_parameters` and
`eval` methods, which will be called as delegates from the C++ :ct:`ReactionRate`
class.
Classes derived from `ExtensibleRate` should implement the `set_parameters`,
`get_parameters`, `eval`, and (optionally) `validate` methods, which will be called
as delegates from the C++ :ct:`ReactionRate` class.
**Warning:** The delegatable methods defined here are an experimental part of the
Cantera API and may change without notice.
Expand Down Expand Up @@ -779,13 +779,23 @@ cdef class ExtensibleRate(ReactionRate):
for reactions created from YAML, ``params`` is the YAML reaction entry converted
to an ``AnyMap``. ``rate_coeff_units`` specifies the units of the rate
coefficient.

Input values contained in ``params`` may be in non-default unit systems,
specified in the user-provided input file. To convert them to Cantera's native
mks+kmol unit system, use the functions `AnyMap.convert`,
`AnyMap.convert_activation_energy`, and `AnyMap.convert_rate_coeff` as needed.
"""
raise NotImplementedError(f"{self.__class__.__name__}.set_parameters")

def get_parameters(self, params: AnyMap) -> None:
"""
Responsible for serializing the state of the ExtensibleRate object, using the
same format as a YAML reaction entry. This is the inverse of `set_parameters`.

Serialization methods may request output in unit systems other than Cantera's
native mks+kmol system. To enable conversions to the user-specified unit system,
dimensional values should be added to ``params`` using the methods
`AnyMap.set_quantity` and `AnyMap.set_activation_energy`.
"""
raise NotImplementedError(f"{self.__class__.__name__}.get_parameters")

Expand Down
3 changes: 3 additions & 0 deletions interfaces/cython/cantera/units.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,9 @@ cdef class UnitSystem:
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.
Generally, this class is used indirectly, through methods interacting with `AnyMap`
objects such as `ExtensibleRate.set_parameters` and `ExtensibleRate.get_parameters`.
The default unit system used by Cantera is SI+kmol::
ct.UnitSystem({
Expand Down

0 comments on commit e82f932

Please sign in to comment.