Skip to content

Commit

Permalink
[yaml2ck] Fix #1415
Browse files Browse the repository at this point in the history
  • Loading branch information
ischoegl committed Dec 31, 2022
1 parent 2ce92ea commit 4f83023
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 3 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.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 4f83023

Please sign in to comment.