Skip to content

Commit

Permalink
[Kinetics] Ensure correct units for pre-exponential factor
Browse files Browse the repository at this point in the history
  • Loading branch information
ischoegl committed Jul 22, 2021
1 parent a890c5e commit f4595d2
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 1 deletion.
8 changes: 7 additions & 1 deletion include/cantera/kinetics/ReactionRateFactory.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,13 @@ shared_ptr<ReactionRateBase> newReactionRate(const std::string& type);
* @param rate_units Unit system of the reaction rate
*/
shared_ptr<ReactionRateBase> newReactionRate(
const AnyMap& rate_node, const Units& rate_units=Units(1.0));
const AnyMap& rate_node, const Units& rate_units);

//! Create a new Rate object using the specified parameters
/*!
* @param rate_node AnyMap node describing reaction rate.
*/
shared_ptr<ReactionRateBase> newReactionRate(const AnyMap& rate_node);

//! Retrieve the canoncial rate object name
/*!
Expand Down
3 changes: 3 additions & 0 deletions interfaces/cython/cantera/reaction.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,9 @@ cdef class ReactionRate:
rate = ReactionRate.from_yaml(
"rate-constant: {A: 38.7, b: 2.7, Ea: 6260.0 cal/mol}")
Units for ``A`` require a unit system with length in ``m`` and quantity in
``kmol`` (standard Cantera units).
:param text:
The YAML reaction rate string.
"""
Expand Down
7 changes: 7 additions & 0 deletions interfaces/cython/cantera/test/test_reaction.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from math import exp
from pathlib import Path
import textwrap

import cantera as ct
import numpy as np
Expand Down Expand Up @@ -188,6 +189,12 @@ def test_from_yaml(self):
self.assertNear(rate(self.gas.T, self.gas.P),
self.rate(self.gas.T, self.gas.P))

def test_with_units(self):
units = "units: {length: cm, quantity: mol}"
yaml = f"{textwrap.dedent(self._yaml)}\n{units}"
with self.assertRaisesRegex(Exception, "not supported"):
rate = ct.ReactionRate.from_yaml(yaml)


class TestArrheniusRate(ReactionRateTests, utilities.CanteraTest):
# test Arrhenius rate expressions
Expand Down
11 changes: 11 additions & 0 deletions src/kinetics/ReactionRateFactory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,17 @@ shared_ptr<ReactionRateBase> newReactionRate(
ReactionRateFactory::factory()->create(type, rate_node, rate_units));
}

shared_ptr<ReactionRateBase> newReactionRate(const AnyMap& rate_node)
{
UnitSystem system = rate_node.units();
if (system.convertTo(1., "m") != 1. || system.convertTo(1., "kmol") != 1.) {
throw InputFileError("ReactionRateFactory::newReactionRate", rate_node,
"Alternative units for 'length' or 'quantity` are not supported "
"when creating a standalone 'ReactionBase' object.");
}
return newReactionRate(rate_node, Units(1.));
}

std::string canonicalRateName(const std::string& type)
{
if (ReactionRateFactory::factory()->exists(type)) {
Expand Down

0 comments on commit f4595d2

Please sign in to comment.