[test] add test_convert.py

This commit is contained in:
Bang-Shiuh Chen 2023-10-01 11:06:06 -04:00 committed by Ray Speth
parent 4b2c2e865b
commit fd6ae0571a
3 changed files with 222 additions and 1 deletions

View File

@ -0,0 +1,68 @@
<!-- This file is for testing only. The format is simplified of https://nl.lxcat.net/data/xml/lxcat_xml.zip -->
<zcross>
<database id="test">
<groups>
<group id="CO2">
<processes>
<!-- The electron energy starts from a value larger than the threshold-->
<process collisionType="inelastic" inelasticType="ionization">
<reactants>
<electron/>
<molecule>CO2</molecule>
</reactants>
<products>
<electron/>
<electron/>
<molecule charge="1" state="Total Ionization">CO2</molecule>
</products>
<parameters>
<parameter name="E" units="eV">15.0</parameter>
</parameters>
<data_x type="energy" units="eV">20.0</data_x>
<data_y type="cross_section" units="m2">5.5e-22</data_y>
</process>
</processes>
</group>
<group id="O2">
<processes>
<!-- The electron energy starts from the threshold in this process-->
<process collisionType="inelastic" inelasticType="ionization">
<reactants>
<electron/>
<molecule>O2</molecule>
</reactants>
<products>
<electron/>
<electron/>
<molecule charge="1" state="Total Ionization">O2</molecule>
</products>
<parameters>
<parameter name="E" units="eV">15.0</parameter>
</parameters>
<data_x type="energy" units="eV">15.0 20.0</data_x>
<data_y type="cross_section" units="m2">0.0 5.5e-22</data_y>
</process>
</processes>
</group>
<group id="O2">
<processes>
<!-- The electron energy starts from the threshold in this process-->
<process collisionType="inelastic" inelasticType="attachment">
<reactants>
<electron/>
<molecule>O2</molecule>
</reactants>
<products>
<molecule charge="-1">O2</molecule>
</products>
<parameters>
<parameter name="E" units="eV">0.0</parameter>
</parameters>
<data_x type="energy" units="eV">0.0 1.0</data_x>
<data_y type="cross_section" units="m2">0.0 1.0e-22</data_y>
</process>
</processes>
</group>
</groups>
</database>
</zcross>

View File

@ -0,0 +1,74 @@
description: |-
This file is for testing purpose. We use constant Cp for electron with no Tmax.
units: {length: cm, quantity: molec, activation-energy: K}
phases:
- name: isotropic-electron-energy-plasma
thermo: plasma
elements: [O, E]
species:
- species: [E, O2(Total-Ionization)+]
- nasa_gas.yaml/species: [O2, O2-]
kinetics: gas
reactions:
- reactions: all
transport: Ion
electron-energy-distribution:
type: isotropic
shape-factor: 2.0
mean-electron-energy: 1.0 eV
energy-levels: [0.0, 0.1, 1.0, 10.0]
- name: discretized-electron-energy-plasma
thermo: plasma
elements: [O, E]
species:
- species: [E]
- nasa_gas.yaml/species: [O2, O2-]
kinetics: gas
reactions:
- reactions: all
transport: Ion
electron-energy-distribution:
type: discretized
energy-levels: [0.0, 0.1, 1.0, 10.0]
distribution: [0.0, 0.2, 0.7, 0.01]
normalize: False
species:
- name: E
composition: {E: 1}
thermo:
model: constant-cp
T0: 200 K
h0: -2.04 kJ/mol
s0: 12.679 J/mol/K
cp0: 20.786 J/mol/K
- name: O2(Total-Ionization)+
composition: {O: 2, E: -1}
thermo:
model: NASA7
temperature-ranges: [298.15, 1000.0, 6000.0]
data:
- [4.61017167, -6.35951952e-03, 1.42425624e-05, -1.20997923e-08, 3.70956878e-12,
1.39742229e+05, -0.201326874]
- [3.31675922, 1.11522244e-03, -3.83492556e-07, 5.72784687e-11, -2.77648381e-15,
1.39876823e+05, 5.44726476]
note: TPIS89
reactions:
- equation: E + O2 + O2 => O2- + O2
type: two-temperature-plasma
rate-constant: {A: 4.2e-27, b: -1.0, Ea-gas: 600, Ea-electron: 700}
- equation: O2 + E => E + O2
type: electron-collision-plasma
energy-levels: [0.0, 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0]
cross-sections: [0.0, 5.97e-20, 6.45e-20, 6.74e-20, 6.93e-20, 7.2e-20,
7.52e-20, 7.86e-20, 8.21e-20, 8.49e-20, 8.8e-20]

View File

@ -5,12 +5,13 @@ from pathlib import Path
import logging
import io
import pytest
from pytest import approx
from . import utilities
from .utilities import allow_deprecated
import cantera as ct
from cantera import ck2yaml, cti2yaml, ctml2yaml, yaml2ck
from cantera import ck2yaml, cti2yaml, ctml2yaml, yaml2ck, lxcat2yaml
class ck2yamlTest(utilities.CanteraTest):
def convert(self, inputFile, thermo=None, transport=None,
@ -1395,3 +1396,81 @@ class ctml2yamlTest(utilities.CanteraTest):
self.convert("duplicate-speciesData-ids")
with self.assertWarnsRegex(UserWarning, "Duplicate 'reactionData' id"):
self.convert("duplicate-reactionData-ids")
class lxcat2yamlTest(utilities.CanteraTest):
def convert(self, inputFile=None, database=None, mechFile=None, phase=None,
insert=True, output=None):
if inputFile is not None:
inputFile = self.test_data_path / inputFile
if mechFile is not None:
mechFile = self.test_data_path / mechFile
if output is None:
output = Path(inputFile).stem # strip '.xml'
# output to work dir
output = self.test_work_path / output
lxcat2yaml.convert(inputFile, database, mechFile, phase, insert, output)
return output
def test_mechanism_with_lxcat(self):
# get Solution from the mechanism file
phase = "isotropic-electron-energy-plasma"
mechFile = "lxcat-test-convert.yaml"
gas1 = ct.Solution(self.test_data_path / mechFile,
phase=phase, transport_model=None)
# get a stand-alone collisions
standAloneFile = "stand-alone-lxcat.yaml"
self.convert(inputFile='lxcat-test-convert.xml', database="test",
mechFile=mechFile, insert=False,
output=standAloneFile)
# add collisions to the reaction list
rxn_list = ct.Reaction.list_from_file(self.test_work_path / standAloneFile,
gas1, section="collisions")
for R in rxn_list:
gas1.add_reaction(R)
# get Solution from the output file
output = "output-lxcat.yaml"
self.convert(inputFile="lxcat-test-convert.xml", database="test",
mechFile=mechFile, insert=True,
output=output)
gas2 = ct.Solution(self.test_work_path / output,
phase=phase, transport_model=None)
# check number of reactions
assert gas1.n_reactions == gas2.n_reactions == 4
for i in range(1, gas1.n_reactions):
assert (gas1.reaction(i).rate.energy_levels
== approx(gas2.reaction(i).rate.energy_levels))
assert (gas1.reaction(i).rate.cross_sections
== approx(gas2.reaction(i).rate.cross_sections))
def test_stand_alone_lxcat(self):
outfile = "stand-alone-lxcat-without-mech.yaml"
self.convert(inputFile='lxcat-test-convert.xml',
database="test", insert=False,
output=outfile)
# get Solution from the mechanism file
phase = "isotropic-electron-energy-plasma"
mechFile = "lxcat-test-convert.yaml"
gas = ct.Solution(self.test_data_path / mechFile,
phase=phase, transport_model=None)
# add collisions to the reaction list
rxn_list = ct.Reaction.list_from_file(self.test_work_path / outfile,
gas, section="collisions")
# verify the data
assert len(rxn_list) == 2
assert rxn_list[0].equation == "O2 + e => O2(Total-Ionization)+ + e + e"
assert rxn_list[0].reaction_type == "three-body-electron-collision-plasma"
assert rxn_list[0].rate.energy_levels == approx([15., 20.])
assert rxn_list[0].rate.cross_sections == approx([0.0, 5.5e-22])
assert rxn_list[1].equation == "O2 + e => O2-"
assert rxn_list[1].reaction_type == "electron-collision-plasma"
assert rxn_list[1].rate.energy_levels == approx([0.0, 1.0])
assert rxn_list[1].rate.cross_sections == approx([0.0, 1.0e-22])