Skip to content

Commit

Permalink
Merge branch 'main' into ext_prec
Browse files Browse the repository at this point in the history
  • Loading branch information
anthony-walker authored Dec 22, 2023
2 parents 96bd8af + 87317b7 commit a78547c
Show file tree
Hide file tree
Showing 8 changed files with 143 additions and 30 deletions.
14 changes: 7 additions & 7 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ jobs:
timeout-minutes: 60
strategy:
matrix:
python-version: ['3.8', '3.10', '3.11']
python-version: ['3.8', '3.10', '3.11', '3.12']
os: ['ubuntu-20.04', 'ubuntu-22.04']
fail-fast: false
env:
Expand Down Expand Up @@ -157,7 +157,7 @@ jobs:
timeout-minutes: 90
strategy:
matrix:
python-version: ['3.8', '3.10', '3.11']
python-version: ['3.8', '3.10', '3.11', '3.12']
fail-fast: false
env:
PYTHON_CMD: "python${{ matrix.python-version }}"
Expand Down Expand Up @@ -189,7 +189,7 @@ jobs:
brew link --force --overwrite python@${{ matrix.python-version }}
brew install --display-times scons
- name: Upgrade pip
run: $PYTHON_CMD -m pip install -U pip 'setuptools>=47.0.0,<48' wheel
run: $PYTHON_CMD -m pip install -U pip setuptools wheel
- name: Install Python dependencies
run: |
$PYTHON_CMD -m pip install ruamel.yaml numpy cython pandas pytest pytest-github-actions-annotate-failures pint
Expand Down Expand Up @@ -379,7 +379,7 @@ jobs:
strategy:
matrix:
os: ["ubuntu-20.04", "ubuntu-22.04"]
python-version: ['3.8', '3.10', '3.11']
python-version: ['3.8', '3.10', '3.11', '3.12']
fail-fast: false
env:
HDF5_LIBDIR: /usr/lib/x86_64-linux-gnu/hdf5/serial
Expand Down Expand Up @@ -423,7 +423,7 @@ jobs:
-exec sh -c 'for n; do echo "$n" | tee -a results.txt && python3 "$n" >> results.txt || exit 1; done' sh {} +
env:
# The ignore setting here is due to a new warning introduced in Matplotlib==3.6.0
PYTHONWARNINGS: "error,ignore:warn_name_set_on_empty_Forward::pyparsing"
PYTHONWARNINGS: "error,ignore:warn_name_set_on_empty_Forward::pyparsing,ignore:datetime.datetime.utcfromtimestamp:DeprecationWarning:"
MPLBACKEND: Agg
- name: Save the results file for inspection
uses: actions/upload-artifact@v3
Expand Down Expand Up @@ -517,7 +517,7 @@ jobs:
matrix:
os: ["windows-2022"]
vs-toolset: ["14.1", "14.3"]
python-version: ["3.8", "3.10", "3.11"]
python-version: ["3.8", "3.10", "3.11", "3.12"]
include:
- python-version: 3.8
fmt-ver: 10
Expand Down Expand Up @@ -595,7 +595,7 @@ jobs:
strategy:
matrix:
vs-toolset: ['14.2']
python-version: ["3.8", "3.10", "3.11"]
python-version: ["3.8", "3.10", "3.11", "3.12"]
fail-fast: false
steps:
- uses: actions/checkout@v3
Expand Down
2 changes: 1 addition & 1 deletion SConstruct
Original file line number Diff line number Diff line change
Expand Up @@ -1720,7 +1720,7 @@ env['python_cmd_esc'] = quoted(env['python_cmd'])
# Python Package Settings
python_min_version = parse_version("3.8")
# Newest Python version not supported/tested by Cantera
python_max_p1_version = parse_version("3.12")
python_max_p1_version = parse_version("3.13")
# The string is used to set python_requires in setup.cfg.in
env["py_requires_ver_str"] = f">={python_min_version}"
if env["python_sdist"] or env["package_build"]:
Expand Down
45 changes: 25 additions & 20 deletions interfaces/cython/cantera/ck2yaml.py
Original file line number Diff line number Diff line change
Expand Up @@ -1991,13 +1991,14 @@ def write_yaml(self, name='gas', out_name='mech.yaml'):

# Write the individual species data
all_species = list(self.species_list)
for surf in self.surfaces:
all_species.extend(surf.species_list)

for species in all_species:
if species.composition is None:
raise InputError('No thermo data found for '
'species {!r}'.format(species.label))
f'species {species.label!r}')

for surf in self.surfaces:
all_species.extend(surf.species_list)
speciesMap = BlockMap([('species', all_species)])
speciesMap.yaml_set_comment_before_after_key('species', before='\n')
emitter.dump(speciesMap, dest)
Expand Down Expand Up @@ -2043,6 +2044,19 @@ def convert_mech(input_file, thermo_file=None, transport_file=None,
else:
phase_name = None

if surface_file:
parser.files.append(surface_file)
surface_file = os.path.expanduser(surface_file)
if not os.path.exists(surface_file):
raise IOError('Missing input file: {0!r}'.format(surface_file))
try:
# Read input mechanism files
parser.load_chemkin_file(surface_file, surface=True)
except Exception as err:
logger.warning("\nERROR: Unable to parse '{0}' near line {1}:\n{2}\n".format(
surface_file, parser.line_number, err))
raise

if thermo_file:
parser.files.append(thermo_file)
thermo_file = os.path.expanduser(thermo_file)
Expand Down Expand Up @@ -2070,19 +2084,6 @@ def convert_mech(input_file, thermo_file=None, transport_file=None,
if s.transport is None:
raise InputError("No transport data for species '{}'.", s)

if surface_file:
parser.files.append(surface_file)
surface_file = os.path.expanduser(surface_file)
if not os.path.exists(surface_file):
raise IOError('Missing input file: {0!r}'.format(surface_file))
try:
# Read input mechanism files
parser.load_chemkin_file(surface_file, surface=True)
except Exception as err:
logger.warning("\nERROR: Unable to parse '{0}' near line {1}:\n{2}\n".format(
surface_file, parser.line_number, err))
raise

if extra_file:
parser.files.append(extra_file)
extra_file = os.path.expanduser(extra_file)
Expand All @@ -2104,10 +2105,14 @@ def convert_mech(input_file, thermo_file=None, transport_file=None,
# Write output file
surface_names = parser.write_yaml(name=phase_name, out_name=out_name)
if not quiet:
nReactions = len(parser.reactions) + sum(len(surf.reactions) for surf in parser.surfaces)
logger.info('Wrote YAML mechanism file to {0!r}.'.format(out_name))
logger.info('Mechanism contains {0} species and {1} reactions.'.format(
len(parser.species_list), nReactions))
nSpecies = len(parser.species_list)
nReactions = len(parser.reactions)
for surf in parser.surfaces:
nSpecies += len(surf.species_list)
nReactions += len(surf.reactions)
logger.info(f'Wrote YAML mechanism file to {out_name!r}.')
logger.info(f'Mechanism contains {nSpecies} species and {nReactions} '
'reactions.')
return parser, surface_names

def show_duplicate_reactions(self, error_message):
Expand Down
4 changes: 2 additions & 2 deletions interfaces/sourcegen/sourcegen/_orchestrate.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ def generate_source(lang: str, out_dir: str):
config = {}
if config_path.exists():
with config_path.open() as config_file:
yaml = ruamel.yaml.YAML(typ='safe', pure=True)
config = yaml.load(config_file)
reader = ruamel.yaml.YAML(typ="safe")
config = reader.load(config_file)

ignore_files: List[str] = config.get("ignore_files", [])
ignore_funcs: Dict[str, List[str]] = config.get("ignore_funcs", {})
Expand Down
5 changes: 5 additions & 0 deletions test/data/surface2-gas.inp
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
ELEMENTS H O PT END

SPECIES
H H2 H2O H2O2 HO2 O O2 OH
END
59 changes: 59 additions & 0 deletions test/data/surface2-thermo.dat
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
THERMO
300.0 1000.0 3000.0
H 120186H 1 G 0300.00 5000.00 1000.00 1
0.02500000E+02 0.00000000E+00 0.00000000E+00 0.00000000E+00 0.00000000E+00 2
0.02547162E+06-0.04601176E+01 0.02500000E+02 0.00000000E+00 0.00000000E+00 3
0.00000000E+00 0.00000000E+00 0.02547162E+06-0.04601176E+01 4
H2 121286H 2 G 0300.00 5000.00 1000.00 1
0.02991423E+02 0.07000644E-02-0.05633828E-06-0.09231578E-10 0.15827519E-14 2
-0.08350340E+04-0.13551101E+01 0.03298124E+02 0.08249441E-02-0.08143015E-05 3
-0.09475434E-09 0.04134872E-11-0.10125209E+04-0.03294094E+02 4
H2O 20387H 2O 1 G 0300.00 5000.00 1000.00 1
0.02672145E+02 0.03056293E-01-0.08730260E-05 0.12009964E-09-0.06391618E-13 2
-0.02989921E+06 0.06862817E+02 0.03386842E+02 0.03474982E-01-0.06354696E-04 3
0.06968581E-07-0.02506588E-10-0.03020811E+06 0.02590232E+02 4
H2O2 120186H 2O 2 G 0300.00 5000.00 1000.00 1
0.04573167E+02 0.04336136E-01-0.14746888E-05 0.02348903E-08-0.14316536E-13 2
-0.01800696E+06 0.05011369E+01 0.03388753E+02 0.06569226E-01-0.14850125E-06 3
-0.04625805E-07 0.02471514E-10-0.01766314E+06 0.06785363E+02 4
HO2 20387H 1O 2 G 0300.00 5000.00 1000.00 1
0.04072191E+02 0.02131296E-01-0.05308145E-05 0.06112269E-09-0.02841164E-13 2
-0.15797270E+03 0.03476029E+02 0.02979963E+02 0.04996697E-01-0.03790997E-04 3
0.02354192E-07-0.08089024E-11 0.01762273E+04 0.09222724E+02 4
O 120186O 1 G 0300.00 5000.00 1000.00 1
0.02542059E+02-0.02755061E-03-0.03102803E-07 0.04551067E-10-0.04368051E-14 2
0.02923080E+06 0.04920308E+02 0.02946428E+02-0.16381665E-02 0.02421031E-04 3
-0.16028431E-08 0.03890696E-11 0.02914764E+06 0.02963995E+02 4
O2 121386O 2 G 0300.00 5000.00 1000.00 1
0.03697578E+02 0.06135197E-02-0.12588420E-06 0.01775281E-09-0.11364354E-14 2
-0.12339301E+04 0.03189165E+02 0.03212936E+02 0.11274864E-02-0.05756150E-05 3
0.13138773E-08-0.08768554E-11-0.10052490E+04 0.06034737E+02 4
OH 121286O 1H 1 G 0300.00 5000.00 1000.00 1
0.02882730E+02 0.10139743E-02-0.02276877E-05 0.02174683E-09-0.05126305E-14 2
0.03886888E+05 0.05595712E+02 0.03637266E+02 0.01850910E-02-0.16761646E-05 3
0.02387202E-07-0.08431442E-11 0.03606781E+05 0.13588605E+01 4
O_Pt 92491O 1PT 1 I 300.00 3000.00 1000.00 1
0.19454180E+01 0.91761647E-03-0.11226719E-06-0.99099624E-10 0.24307699E-13 2
-0.14005187E+05-0.11531663E+02-0.94986904E+00 0.74042305E-02-0.10451424E-05 3
-0.61120420E-08 0.33787992E-11-0.13209912E+05 0.36137905E+01 4
O2_Pt 92491O 2PT 3 I 300.00 3000.00 1000.00 1
0.19454180E+01 0.91761647E-03-0.11226719E-06-0.99099624E-10 0.24307699E-13 2
-0.14005187E+05-0.11531663E+02-0.94986904E+00 0.74042305E-02-0.10451424E-05 3
-0.61120420E-08 0.33787992E-11-0.13209912E+05 0.36137905E+01 4
H_Pt 92491H 1PT 1 I 300.00 3000.00 1000.00 1
0.10696996E+01 0.15432230E-02-0.15500922E-06-0.16573165E-09 0.38359347E-13 2
-0.50546128E+04-0.71555238E+01-0.13029877E+01 0.54173199E-02 0.31277972E-06 3
-0.32328533E-08 0.11362820E-11-0.42277075E+04 0.58743238E+01 4
H2O_Pt 92491O 1H 2PT 1 I 300.00 3000.00 1000.00 1
0.25803051E+01 0.49570827E-02-0.46894056E-06-0.52633137E-09 0.11998322E-12 2
-0.38302234E+05-0.17406322E+02-0.27651553E+01 0.13315115E-01 0.10127695E-05 3
-0.71820083E-08 0.22813776E-11-0.36398055E+05 0.12098145E+02 4
OH_Pt 92491O 1H 1PT 1 I 300.00 3000.00 1000.00 1
0.18249973E+01 0.32501565E-02-0.31197541E-06-0.34603206E-09 0.79171472E-13 2
-0.26685492E+05-0.12280891E+02-0.20340881E+01 0.93662683E-02 0.66275214E-06 3
-0.52074887E-08 0.17088735E-11-0.25319949E+05 0.89863186E+01 4
_Pt_ PT 1 S 300.0 3000.0 1000.0 1
0.00000000E+00 0.00000000E+00 0.00000000E+00 0.00000000E+00 0.00000000E+00 2
0.00000000E+00 0.00000000E+00 0.00000000E+00 0.00000000E+00 0.00000000E+00 3
0.00000000E+00 0.00000000E+00 0.00000000E+00 0.00000000E+00 4
END
32 changes: 32 additions & 0 deletions test/data/surface2.inp
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
SITE/PT_SURFACE/ SDEN/2.72E-9/
_Pt_ H_Pt O2_Pt/3/ H2O_Pt OH_Pt O_Pt
END

REACTIONS JOULES/MOLE MWON
H2 + 2_Pt_ => 2H_Pt 4.4579E+10 0.5 0.0
FORD/_Pt_ 1/
2H_Pt => H2 + 2_Pt_ 3.70E+21 0.00 67400.0
COV/H_Pt 0.0 0.0 -6000.0/
COV/OH_Pt 0.0 1.0 -3000.0/
H + _Pt_ => H_Pt 1.00 0.0 0.0
STICK
O2 + 2_Pt_ => 2O_Pt 1.80E+21 -0.5 0.0
DUPLICATE
O2 + 2_Pt_ => 2O_Pt 0.023 0.00 0.00
DUPLICATE STICK MWOFF
2O_Pt => O2 + 2_Pt_ 3.70E+21 0.00 213200.0
COV/O_Pt 0.0 0.0 -60000.0/
O + _Pt_ => O_Pt 1.00 0.0 0.0
STICK
MWON
H2O + _Pt_ => H2O_Pt 0.75 0.0 0.0
STICK
H2O_Pt => H2O + _Pt_ 1.0E+13 0.00 40300.0
OH + _Pt_ => OH_Pt 1.00 0.0 0.0
STICK
OH_Pt => OH + _Pt_ 1.0E+13 0.00 192800.0
H_Pt + O_Pt = OH_Pt + _Pt_ 3.70E+21 0.00 11500.0
H_Pt + OH_Pt = H2O_Pt + _Pt_ 3.70E+21 0.00 17400.0
OH_Pt + OH_Pt = H2O_Pt + O_Pt 3.70E+21 0.00 48200.0
O2_Pt = O2 + 3 _Pt_ 3.70E+21 0.00 11500.0
END
12 changes: 12 additions & 0 deletions test/python/test_convert.py
Original file line number Diff line number Diff line change
Expand Up @@ -440,6 +440,18 @@ def test_surface_mech2(self):
self.assertEqual(covdeps["OH_Pt"]["m"], 1.0)
self.assertNear(covdeps["H_Pt"]["E"], -6e6)

def test_surface_mech3(self):
# This tests the case where the thermo data for both the gas and surface are
# combined in a file separate from the gas and surface definitions.

output = self.convert('surface2-gas.inp', thermo='surface2-thermo.dat',
surface='surface2.inp', output='surface2')
surf = ct.Interface(output, 'PT_SURFACE')

assert surf.n_species == 6
assert surf.n_reactions == 15
assert surf.reaction(4).duplicate is True

def test_third_body_plus_falloff_reactions(self):
output = self.convert("third_body_plus_falloff_reaction.inp")
gas = ct.Solution(output)
Expand Down

0 comments on commit a78547c

Please sign in to comment.