Skip to content

Commit

Permalink
[yaml2ck] Fix explicit third body reaction output
Browse files Browse the repository at this point in the history
Prior to this fix, third body efficiencies were erroneously specified
for third body reactions with explicit collision partners (see #1415).
  • Loading branch information
ischoegl authored and speth committed Jan 4, 2023
1 parent 2ce92ea commit 957dd24
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 17 deletions.
3 changes: 2 additions & 1 deletion interfaces/cython/cantera/yaml2ck.py
Original file line number Diff line number Diff line change
Expand Up @@ -472,7 +472,8 @@ def build_reactions_text(reactions: Iterable[ct.Reaction]):
else:
raise ValueError(f"Unknown reaction type: '{reac.reaction_type}'")

if reac.third_body is not None:
third = reac.third_body
if third is not None and third.name == "M" and len(third.efficiencies):
reaction_lines.append(
" ".join(
f"{spec}/{value:.3E}/"
Expand Down
3 changes: 3 additions & 0 deletions test/data/explicit-third-bodies.inp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ REACTIONS
R1A+R1B+m = P1+H+M 3.0E19 -2.0 1900 ! An end of line comment
DUPLICATE

R1A+R1B+R2 = P1+H+R2 3.0E19 -2.0 1900 ! An end of line comment
DUPLICATE

R1A+R1B(+ M ) = P1+H(+m) 1.0E18 -2.0 1000
LOW/4.0E25 -3.0 0/
R2/0.0/ SP)X/0/
Expand Down
42 changes: 28 additions & 14 deletions test/data/explicit-third-bodies.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<phase dim="3" id="gas">
<elementArray datasrc="elements.xml">H C Ar</elementArray>
<speciesArray datasrc="#species_data">
H R1A R1B P1 R2
H R1A R1B P1 R2
SP)X</speciesArray>
<reactionArray datasrc="#reaction_data"/>
<state>
Expand All @@ -27,12 +27,12 @@
<thermo>
<NASA Tmax="1000.0" Tmin="200.0" P0="100000.0">
<floatArray name="coeffs" size="7">
2.500000000E+00, 7.053328190E-13, -1.995919640E-15, 2.300816320E-18,
2.500000000E+00, 7.053328190E-13, -1.995919640E-15, 2.300816320E-18,
-9.277323320E-22, 2.547365990E+04, -4.466828530E-01</floatArray>
</NASA>
<NASA Tmax="3500.0" Tmin="1000.0" P0="100000.0">
<floatArray name="coeffs" size="7">
2.500000010E+00, -2.308429730E-11, 1.615619480E-14, -4.735152350E-18,
2.500000010E+00, -2.308429730E-11, 1.615619480E-14, -4.735152350E-18,
4.981973570E-22, 2.547365990E+04, -4.466829140E-01</floatArray>
</NASA>
</thermo>
Expand All @@ -44,12 +44,12 @@
<thermo>
<NASA Tmax="1000.0" Tmin="200.0" P0="100000.0">
<floatArray name="coeffs" size="7">
5.149876130E+00, -1.367097880E-02, 4.918005990E-05, -4.847430260E-08,
5.149876130E+00, -1.367097880E-02, 4.918005990E-05, -4.847430260E-08,
1.666939560E-11, -1.024664760E+04, -4.641303760E+00</floatArray>
</NASA>
<NASA Tmax="3500.0" Tmin="1000.0" P0="100000.0">
<floatArray name="coeffs" size="7">
7.485149500E-02, 1.339094670E-02, -5.732858090E-06, 1.222925350E-09,
7.485149500E-02, 1.339094670E-02, -5.732858090E-06, 1.222925350E-09,
-1.018152300E-13, -9.468344590E+03, 1.843731800E+01</floatArray>
</NASA>
</thermo>
Expand All @@ -61,12 +61,12 @@
<thermo>
<NASA Tmax="1000.0" Tmin="200.0" P0="100000.0">
<floatArray name="coeffs" size="7">
5.149876130E+00, -1.367097880E-02, 4.918005990E-05, -4.847430260E-08,
5.149876130E+00, -1.367097880E-02, 4.918005990E-05, -4.847430260E-08,
1.666939560E-11, -1.024664760E+04, -4.641303760E+00</floatArray>
</NASA>
<NASA Tmax="3500.0" Tmin="1000.0" P0="100000.0">
<floatArray name="coeffs" size="7">
7.485149500E-02, 1.339094670E-02, -5.732858090E-06, 1.222925350E-09,
7.485149500E-02, 1.339094670E-02, -5.732858090E-06, 1.222925350E-09,
-1.018152300E-13, -9.468344590E+03, 1.843731800E+01</floatArray>
</NASA>
</thermo>
Expand All @@ -78,12 +78,12 @@
<thermo>
<NASA Tmax="1000.0" Tmin="200.0" P0="100000.0">
<floatArray name="coeffs" size="7">
5.149876130E+00, -1.367097880E-02, 4.918005990E-05, -4.847430260E-08,
5.149876130E+00, -1.367097880E-02, 4.918005990E-05, -4.847430260E-08,
1.666939560E-11, -1.024664760E+04, -4.641303760E+00</floatArray>
</NASA>
<NASA Tmax="3500.0" Tmin="1000.0" P0="100000.0">
<floatArray name="coeffs" size="7">
7.485149500E-02, 1.339094670E-02, -5.732858090E-06, 1.222925350E-09,
7.485149500E-02, 1.339094670E-02, -5.732858090E-06, 1.222925350E-09,
-1.018152300E-13, -9.468344590E+03, 1.843731800E+01</floatArray>
</NASA>
</thermo>
Expand All @@ -95,12 +95,12 @@
<thermo>
<NASA Tmax="1000.0" Tmin="200.0" P0="100000.0">
<floatArray name="coeffs" size="7">
5.149876130E+00, -1.367097880E-02, 4.918005990E-05, -4.847430260E-08,
5.149876130E+00, -1.367097880E-02, 4.918005990E-05, -4.847430260E-08,
1.666939560E-11, -1.024664760E+04, -4.641303760E+00</floatArray>
</NASA>
<NASA Tmax="3500.0" Tmin="1000.0" P0="100000.0">
<floatArray name="coeffs" size="7">
7.485149500E-02, 1.339094670E-02, -5.732858090E-06, 1.222925350E-09,
7.485149500E-02, 1.339094670E-02, -5.732858090E-06, 1.222925350E-09,
-1.018152300E-13, -9.468344590E+03, 1.843731800E+01</floatArray>
</NASA>
</thermo>
Expand All @@ -112,20 +112,20 @@
<thermo>
<NASA Tmax="1000.0" Tmin="200.0" P0="100000.0">
<floatArray name="coeffs" size="7">
5.149876130E+00, -1.367097880E-02, 4.918005990E-05, -4.847430260E-08,
5.149876130E+00, -1.367097880E-02, 4.918005990E-05, -4.847430260E-08,
1.666939560E-11, -1.024664760E+04, -4.641303760E+00</floatArray>
</NASA>
<NASA Tmax="3500.0" Tmin="1000.0" P0="100000.0">
<floatArray name="coeffs" size="7">
7.485149500E-02, 1.339094670E-02, -5.732858090E-06, 1.222925350E-09,
7.485149500E-02, 1.339094670E-02, -5.732858090E-06, 1.222925350E-09,
-1.018152300E-13, -9.468344590E+03, 1.843731800E+01</floatArray>
</NASA>
</thermo>
</species>
</speciesData>
<reactionData id="reaction_data">

<!-- reaction 0001 -->
<!-- reaction 0001a -->
<reaction duplicate="yes" reversible="yes" type="threeBody" id="0001">
<equation>R1A + R1B + M [=] P1 + H + M</equation>
<rateCoeff>
Expand All @@ -139,6 +139,20 @@
<products>H:1 P1:1.0</products>
</reaction>

<!-- reaction 0001b -->
<reaction duplicate="yes" reversible="yes" type="threeBody" id="0001">
<equation>R1A + R1B + R2 [=] P1 + H + R2</equation>
<rateCoeff>
<Arrhenius>
<A>3.000000E+13</A>
<b>-2.0</b>
<E units="cal/mol">1900.000000</E>
</Arrhenius>
</rateCoeff>
<reactants>R1B:1 R1A:1.0</reactants>
<products>H:1 P1:1.0</products>
</reaction>

<!-- reaction 0002 -->
<reaction duplicate="yes" reversible="yes" type="falloff" id="0002">
<equation>R1A + R1B (+ M) [=] P1 + H (+ M)</equation>
Expand Down
3 changes: 3 additions & 0 deletions test/data/explicit-third-bodies.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,9 @@ reactions:
type: three-body
rate-constant: {A: 3.0e+13, b: -2.0, Ea: 1900.0 cal/mol}
duplicate: true
- equation: R1A + R1B + R2 <=> P1 + H + R2
rate-constant: {A: 3.0e+13, b: -2.0, Ea: 1900.0 cal/mol}
duplicate: true
- equation: R1A + R1B (+ M) <=> P1 + H (+ M)
type: falloff
high-P-rate-constant: {A: 1.0e+15, b: -2.0, Ea: 1000.0 cal/mol}
Expand Down
11 changes: 9 additions & 2 deletions test/python/test_convert.py
Original file line number Diff line number Diff line change
Expand Up @@ -559,7 +559,7 @@ def convert(
thermo: str | Path | None = None,
transport: str | Path | None = None,
permissive: bool = False,
) -> None:
) -> str:
if mech is not None:
mech, thermo, transport = self._convert_to_ck(
input_file,
Expand All @@ -578,6 +578,7 @@ def convert(
quiet=True,
permissive=permissive,
)
return mech

def check_conversion(self, basename, cls=ct.Solution, **kwargs):
# The round-trip YAML->CK->YAML will always have the single phase name 'gas'
Expand Down Expand Up @@ -689,7 +690,13 @@ def test_phase_id(self):

def test_third_body_reactions(self):
input_file = self.test_data_path / "explicit-third-bodies.yaml"
self.convert(input_file)
mech = self.convert(input_file)
with open(mech) as fid:
lines = fid.readlines()
for i, line in enumerate(lines):
if line.startswith("R1A + R1B"):
next = lines[i + 1]
assert next.startswith("LOW") or next.strip() == "DUPLICATE"
ck_phase, yaml_phase = self.check_conversion(input_file)
self.check_kinetics(
ck_phase, yaml_phase, [300, 800, 1450, 2800], [5e3, 1e5, 2e6]
Expand Down

0 comments on commit 957dd24

Please sign in to comment.