-
Notifications
You must be signed in to change notification settings - Fork 6
Description
Abstract
While Reaction objects are mostly created using YAML (or CTI/XML) input files, they can be instantiated by themselves, which at least in Python involves awkward syntax.
Further, a more uniform handling of reaction rate objects would be nice: at the moment, they lack a common base class, which makes handling more difficult than necessary (and also makes their central role in handling of underlying computations less obvious).
Motivation
In Python, reactions are currently instantiated using a YAML (or previously CTI/XML) string, which assumes that a user knows the corresponding syntax. The alternative is to use a somewhat awkward instantiation as in
rxn = ElementaryReaction({'O':1, 'H2':1}, {'H':1, 'OH':1})
rxn.rate = Arrhenius(38.7, 2.7, 2.619184e+07)It would be nice if the implementation would be more intuitive, for example
rxn = ElementaryReaction(equation='H2 + O <=> H + OH',
rate={'A': 38.7, 'b': 2.7, 'Ea': 2.619184e+07},
kinetics=gas)where equation and rate are intuitive (correspond directly to YAML input), whereas kinetics is used to obtain unit and species information.
Regarding reaction rates, there is no common base class for rxn.rate (Arrhenius, Falloff, etc.), and Plog uses an alternative formulation that does not match (property rates), which complicates a programmatic interaction with Reaction objects. It would be convenient and instructive to obtain a parameterization using a property parameters as in
>>> rxn.rate.parameters
{'A': 38.7, 'b': 2.7, 'Ea': 26191840.0}
(which would be the same as the dictionary imported from the reaction-rate field in YAML). As an aside, reaction rate objects also cannot be instantiated from YAML by themselves.
A more comprehensive output string for Reaction objects would be likewise beneficial.
Possible Solutions
A. A more intuitive Python interface is relatively straight-forward (mainly involves an implementation of __init__ in reaction.pyx). The (currently) simplest way would be to generate a YAML string from parameters, and create the reaction using the existing fromYaml method. If a python_to_anymap utility were available (e.g. Cantera/cantera#984?), instantiation would just involve a call to CxxNewReaction.
B. To make uniform handling of reaction rates more intuitive in Python there are two options:
- Collecting existing C++ reaction rate objects in a common Python base class is relatively straight-forward
- As the same rationale (lack of uniform interfaces) applies in the underlying C++ core, a direct mapping of a new C++ base class
RxnRatecould be implemented (see also Make reactions extendable #63).
While a complete implementation goes beyond the scope of Cantera/cantera#982, examples for (A) are implemented, and an initial framework for (B.2) is created. Output of reaction rate parameters will become trivial once Cantera/cantera#984 is merged.
References