-
-
Notifications
You must be signed in to change notification settings - Fork 409
Closed
Labels
InputInput parsing and conversion (for example, ck2yaml)Input parsing and conversion (for example, ck2yaml)Pythonbug
Description
Problem description
The Solution.write_chemkin method defines some default arguments that are not accepted by yaml2ck.convert. All the unit tests seem to use yaml2ck.convert directly, leaving Solution.write_chemkin untested and letting this bug slip through.
Steps to reproduce
import cantera as ct
gas = ct.Solution('h2o2.yaml')
gas.write_chemkin('test.ck') # Error - see first traceback
gas.write_chemkin('test.ck', sort_species='alphabetical') # error - see second tracebackBehavior
Traceback for gas.write_chemkin('test.ck'):
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
Cell In [7], line 1
----> 1 gas.write_chemkin('test.ck')
File ~/src/cantera/build/python/cantera/solutionbase.pyx:345, in cantera.solutionbase._SolutionBase.write_chemkin()
343
344 from cantera import yaml2ck
--> 345 output_paths = yaml2ck.convert(
346 self,
347 mechanism_path=mechanism_path,
File ~/src/cantera/build/python/cantera/yaml2ck.py:642, in convert(solution, phase_name, mechanism_path, thermo_path, transport_path, sort_elements, sort_species, overwrite)
640 all_species = solution.species()
641 else:
--> 642 raise ValueError(
643 "sort_species must be None, 'alphabetical', or 'molar-mass'. "
644 f"Got '{sort_species}'"
645 )
647 all_elements = [ct.Element(e) for e in solution.element_names]
648 if sort_elements == "alphabetical":
ValueError: sort_species must be None, 'alphabetical', or 'molar-mass'. Got 'False'Traceback for gas.write_chemkin('test.ck', sort_species='alphabetical')
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
Cell In [8], line 1
----> 1 gas.write_chemkin('test.ck', sort_species='alphabetical')
File ~/src/cantera/build/python/cantera/solutionbase.pyx:345, in cantera.solutionbase._SolutionBase.write_chemkin()
343
344 from cantera import yaml2ck
--> 345 output_paths = yaml2ck.convert(
346 self,
347 mechanism_path=mechanism_path,
File ~/src/cantera/build/python/cantera/yaml2ck.py:653, in convert(solution, phase_name, mechanism_path, thermo_path, transport_path, sort_elements, sort_species, overwrite)
651 all_elements = sorted(all_elements, key=lambda e: e.weight)
652 elif sort_elements is not None:
--> 653 raise ValueError(
654 "sort_elements must be None, 'alphabetical', or 'molar-mass'. "
655 f"Got '{sort_elements}'"
656 )
658 # Write output files
659 header_wrapper = HeaderTextWrapper(
660 [solution_name.name],
661 width=120,
(...)
665 break_on_hyphens=False,
666 )
ValueError: sort_elements must be None, 'alphabetical', or 'molar-mass'. Got 'False'System information
- Cantera version: 3.0.0
- OS: macOS 13.5.1
- Python 3.11
Additional context
Discovered while isolating #1610.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
InputInput parsing and conversion (for example, ck2yaml)Input parsing and conversion (for example, ck2yaml)Pythonbug