mirror of
https://github.com/Cantera/cantera.git
synced 2025-02-25 18:55:29 -06:00
[ctml2yaml] Combine duplicate section ids
If a reactionData or speciesData node has a duplicated id attribute, combine the duplicate sections together. If duplicate reaction id attributes or species names are found, either warn or raise an error.
This commit is contained in:
@@ -2059,21 +2059,14 @@ def create_species_from_data_node(ctml_tree: etree.Element) -> Dict[str, List[Sp
|
||||
for species_data_node in ctml_tree.iterfind("speciesData"):
|
||||
this_data_node_id = species_data_node.get("id", "")
|
||||
if this_data_node_id in species:
|
||||
raise ValueError(
|
||||
"Duplicate speciesData id found: '{}'".format(this_data_node_id)
|
||||
warnings.warn(
|
||||
"Duplicate 'speciesData' id found: '{}'. Only the first section will "
|
||||
"be included in the output file.".format(this_data_node_id)
|
||||
)
|
||||
this_node_species = [] # type: List[Species]
|
||||
for species_node in species_data_node.iterfind("species"):
|
||||
this_species = Species(species_node)
|
||||
for s in this_node_species:
|
||||
if this_species.attribs["name"] == s.attribs["name"]:
|
||||
raise ValueError(
|
||||
"Duplicate specification of species '{}' in node '{}'".format(
|
||||
this_species.attribs["name"], this_data_node_id
|
||||
)
|
||||
)
|
||||
this_node_species.append(this_species)
|
||||
species[this_data_node_id] = this_node_species
|
||||
continue
|
||||
species[this_data_node_id] = [
|
||||
Species(s) for s in species_data_node.iterfind("species")
|
||||
]
|
||||
|
||||
return species
|
||||
|
||||
@@ -2084,18 +2077,19 @@ def create_reactions_from_data_node(
|
||||
"""Take a reactionData node and return a dictionary of Reaction objects."""
|
||||
reactions = {} # type: Dict[str, List[Reaction]]
|
||||
for reactionData_node in ctml_tree.iterfind("reactionData"):
|
||||
this_data_node_id = reactionData_node.get("id", "")
|
||||
if this_data_node_id in reactions:
|
||||
raise ValueError(
|
||||
"Duplicate reactionData id found: '{}'".format(this_data_node_id)
|
||||
)
|
||||
node_motz_wise = False
|
||||
if reactionData_node.get("motz_wise", "").lower() == "true":
|
||||
node_motz_wise = True
|
||||
this_node_reactions = [] # type: List[Reaction]
|
||||
for reaction_node in reactionData_node.iterfind("reaction"):
|
||||
this_node_reactions.append(Reaction(reaction_node, node_motz_wise))
|
||||
reactions[this_data_node_id] = this_node_reactions
|
||||
this_data_node_id = reactionData_node.get("id", "")
|
||||
if this_data_node_id in reactions:
|
||||
warnings.warn(
|
||||
"Duplicate 'reactionData' id found: '{}'. Only the first section will "
|
||||
"be included in the output file.".format(this_data_node_id)
|
||||
)
|
||||
continue
|
||||
reactions[this_data_node_id] = [
|
||||
Reaction(r, node_motz_wise) for r in reactionData_node.iterfind("reaction")
|
||||
]
|
||||
|
||||
return reactions
|
||||
|
||||
|
||||
@@ -1186,3 +1186,15 @@ class ctml2yamlTest(utilities.CanteraTest):
|
||||
|
||||
ctmlPhase, yamlPhase = self.checkConversion("Li_Liquid")
|
||||
self.checkThermo(ctmlPhase, yamlPhase, [300, 500])
|
||||
|
||||
def test_duplicate_section_ids(self):
|
||||
with self.assertWarnsRegex(UserWarning, "Duplicate 'speciesData' id"):
|
||||
ctml2yaml.convert(
|
||||
Path(self.test_data_dir).joinpath("duplicate-speciesData-ids.xml"),
|
||||
Path(self.test_work_dir).joinpath("duplicate-speciesData-ids.yaml")
|
||||
)
|
||||
with self.assertWarnsRegex(UserWarning, "Duplicate 'reactionData' id"):
|
||||
ctml2yaml.convert(
|
||||
Path(self.test_data_dir).joinpath("duplicate-reactionData-ids.xml"),
|
||||
Path(self.test_work_dir).joinpath("duplicate-reactionData-ids.yaml")
|
||||
)
|
||||
89
test/data/duplicate-reactionData-ids.xml
Normal file
89
test/data/duplicate-reactionData-ids.xml
Normal file
@@ -0,0 +1,89 @@
|
||||
<?xml version="1.0"?>
|
||||
<ctml>
|
||||
<validate reactions="yes" species="yes"/>
|
||||
|
||||
<!-- phase gas -->
|
||||
<phase dim="3" id="gas">
|
||||
<elementArray datasrc="elements.xml">H C</elementArray>
|
||||
<speciesArray datasrc="#species_data">R1A R1B</speciesArray>
|
||||
<reactionArray datasrc="#reaction_data"/>
|
||||
<state>
|
||||
<temperature units="K">300.0</temperature>
|
||||
<pressure units="Pa">101325.0</pressure>
|
||||
</state>
|
||||
<thermo model="IdealGas"/>
|
||||
<kinetics model="GasKinetics"/>
|
||||
<transport model="None"/>
|
||||
</phase>
|
||||
|
||||
<!-- species definitions -->
|
||||
<speciesData id="species_data">
|
||||
<!-- species R1A -->
|
||||
<species name="R1A">
|
||||
<atomArray>H:4 C:1 </atomArray>
|
||||
<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,
|
||||
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,
|
||||
-1.018152300E-13, -9.468344590E+03, 1.843731800E+01</floatArray>
|
||||
</NASA>
|
||||
</thermo>
|
||||
</species>
|
||||
|
||||
<!-- species R1B -->
|
||||
<species name="R1B">
|
||||
<atomArray>H:4 C:1 </atomArray>
|
||||
<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,
|
||||
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,
|
||||
-1.018152300E-13, -9.468344590E+03, 1.843731800E+01</floatArray>
|
||||
</NASA>
|
||||
</thermo>
|
||||
</species>
|
||||
|
||||
</speciesData>
|
||||
<reactionData id="reaction_data">
|
||||
|
||||
<!-- reaction 0001 -->
|
||||
<reaction id="0001">
|
||||
<equation>R1A [=] R1B</equation>
|
||||
<rateCoeff>
|
||||
<Arrhenius>
|
||||
<A>1.000000E+09</A>
|
||||
<b>0.0</b>
|
||||
<E units="cal/mol">20000.000000</E>
|
||||
</Arrhenius>
|
||||
</rateCoeff>
|
||||
<reactants>R1A:1.0</reactants>
|
||||
<products>R1B:1.0</products>
|
||||
</reaction>
|
||||
</reactionData>
|
||||
<reactionData id="reaction_data">
|
||||
|
||||
<!-- reaction 0001 -->
|
||||
<reaction id="0001">
|
||||
<equation>R1B [=] R1A</equation>
|
||||
<rateCoeff>
|
||||
<Arrhenius>
|
||||
<A>1.000000E+09</A>
|
||||
<b>0.0</b>
|
||||
<E units="cal/mol">20000.000000</E>
|
||||
</Arrhenius>
|
||||
</rateCoeff>
|
||||
<reactants>R1B:1.0</reactants>
|
||||
<products>R1A:1.0</products>
|
||||
</reaction>
|
||||
|
||||
</reactionData>
|
||||
</ctml>
|
||||
57
test/data/duplicate-speciesData-ids.xml
Normal file
57
test/data/duplicate-speciesData-ids.xml
Normal file
@@ -0,0 +1,57 @@
|
||||
<?xml version="1.0"?>
|
||||
<ctml>
|
||||
<validate reactions="yes" species="yes"/>
|
||||
|
||||
<!-- phase gas -->
|
||||
<phase dim="3" id="gas">
|
||||
<elementArray datasrc="elements.xml">H</elementArray>
|
||||
<speciesArray datasrc="#species_data">H H</speciesArray>
|
||||
<state>
|
||||
<temperature units="K">300.0</temperature>
|
||||
<pressure units="Pa">101325.0</pressure>
|
||||
</state>
|
||||
<thermo model="IdealGas"/>
|
||||
<kinetics model="none"/>
|
||||
<transport model="None"/>
|
||||
</phase>
|
||||
|
||||
<!-- species definitions -->
|
||||
<speciesData id="species_data">
|
||||
|
||||
<!-- species H -->
|
||||
<species name="H">
|
||||
<atomArray>H:1 </atomArray>
|
||||
<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,
|
||||
-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,
|
||||
4.981973570E-22, 2.547365990E+04, -4.466829140E-01</floatArray>
|
||||
</NASA>
|
||||
</thermo>
|
||||
</species>
|
||||
</speciesData>
|
||||
<speciesData id="species_data">
|
||||
|
||||
<!-- species H -->
|
||||
<species name="H">
|
||||
<atomArray>H:1 </atomArray>
|
||||
<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,
|
||||
-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,
|
||||
4.981973570E-22, 2.547365990E+04, -4.466829140E-01</floatArray>
|
||||
</NASA>
|
||||
</thermo>
|
||||
</species>
|
||||
</speciesData>
|
||||
</ctml>
|
||||
@@ -25,12 +25,12 @@
|
||||
<thermo>
|
||||
<NASA Tmax="1000.0" Tmin="200.0" P0="100000.0">
|
||||
<floatArray name="coeffs" size="7">
|
||||
2.344331120E+00, 7.980520750E-03, -1.947815100E-05, 2.015720940E-08,
|
||||
2.344331120E+00, 7.980520750E-03, -1.947815100E-05, 2.015720940E-08,
|
||||
-7.376117610E-12, -9.179351730E+02, 6.830102380E-01</floatArray>
|
||||
</NASA>
|
||||
<NASA Tmax="3500.0" Tmin="1000.0" P0="100000.0">
|
||||
<floatArray name="coeffs" size="7">
|
||||
3.337279200E+00, -4.940247310E-05, 4.994567780E-07, -1.795663940E-10,
|
||||
3.337279200E+00, -4.940247310E-05, 4.994567780E-07, -1.795663940E-10,
|
||||
2.002553760E-14, -9.501589220E+02, -3.205023310E+00</floatArray>
|
||||
</NASA>
|
||||
</thermo>
|
||||
@@ -42,12 +42,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>
|
||||
@@ -59,12 +59,12 @@
|
||||
<thermo>
|
||||
<NASA Tmax="1000.0" Tmin="200.0" P0="100000.0">
|
||||
<floatArray name="coeffs" size="7">
|
||||
3.168267100E+00, -3.279318840E-03, 6.643063960E-06, -6.128066240E-09,
|
||||
3.168267100E+00, -3.279318840E-03, 6.643063960E-06, -6.128066240E-09,
|
||||
2.112659710E-12, 2.912225920E+04, 2.051933460E+00</floatArray>
|
||||
</NASA>
|
||||
<NASA Tmax="3500.0" Tmin="1000.0" P0="100000.0">
|
||||
<floatArray name="coeffs" size="7">
|
||||
2.569420780E+00, -8.597411370E-05, 4.194845890E-08, -1.001777990E-11,
|
||||
2.569420780E+00, -8.597411370E-05, 4.194845890E-08, -1.001777990E-11,
|
||||
1.228336910E-15, 2.921757910E+04, 4.784338640E+00</floatArray>
|
||||
</NASA>
|
||||
</thermo>
|
||||
@@ -76,12 +76,12 @@
|
||||
<thermo>
|
||||
<NASA Tmax="1000.0" Tmin="200.0" P0="100000.0">
|
||||
<floatArray name="coeffs" size="7">
|
||||
3.782456360E+00, -2.996734160E-03, 9.847302010E-06, -9.681295090E-09,
|
||||
3.782456360E+00, -2.996734160E-03, 9.847302010E-06, -9.681295090E-09,
|
||||
3.243728370E-12, -1.063943560E+03, 3.657675730E+00</floatArray>
|
||||
</NASA>
|
||||
<NASA Tmax="3500.0" Tmin="1000.0" P0="100000.0">
|
||||
<floatArray name="coeffs" size="7">
|
||||
3.282537840E+00, 1.483087540E-03, -7.579666690E-07, 2.094705550E-10,
|
||||
3.282537840E+00, 1.483087540E-03, -7.579666690E-07, 2.094705550E-10,
|
||||
-2.167177940E-14, -1.088457720E+03, 5.453231290E+00</floatArray>
|
||||
</NASA>
|
||||
</thermo>
|
||||
@@ -93,12 +93,12 @@
|
||||
<thermo>
|
||||
<NASA Tmax="1000.0" Tmin="200.0" P0="100000.0">
|
||||
<floatArray name="coeffs" size="7">
|
||||
3.992015430E+00, -2.401317520E-03, 4.617938410E-06, -3.881133330E-09,
|
||||
3.992015430E+00, -2.401317520E-03, 4.617938410E-06, -3.881133330E-09,
|
||||
1.364114700E-12, 3.615080560E+03, -1.039254580E-01</floatArray>
|
||||
</NASA>
|
||||
<NASA Tmax="3500.0" Tmin="1000.0" P0="100000.0">
|
||||
<floatArray name="coeffs" size="7">
|
||||
3.092887670E+00, 5.484297160E-04, 1.265052280E-07, -8.794615560E-11,
|
||||
3.092887670E+00, 5.484297160E-04, 1.265052280E-07, -8.794615560E-11,
|
||||
1.174123760E-14, 3.858657000E+03, 4.476696100E+00</floatArray>
|
||||
</NASA>
|
||||
</thermo>
|
||||
@@ -110,12 +110,12 @@
|
||||
<thermo>
|
||||
<NASA Tmax="1000.0" Tmin="200.0" P0="100000.0">
|
||||
<floatArray name="coeffs" size="7">
|
||||
4.198640560E+00, -2.036434100E-03, 6.520402110E-06, -5.487970620E-09,
|
||||
4.198640560E+00, -2.036434100E-03, 6.520402110E-06, -5.487970620E-09,
|
||||
1.771978170E-12, -3.029372670E+04, -8.490322080E-01</floatArray>
|
||||
</NASA>
|
||||
<NASA Tmax="3500.0" Tmin="1000.0" P0="100000.0">
|
||||
<floatArray name="coeffs" size="7">
|
||||
3.033992490E+00, 2.176918040E-03, -1.640725180E-07, -9.704198700E-11,
|
||||
3.033992490E+00, 2.176918040E-03, -1.640725180E-07, -9.704198700E-11,
|
||||
1.682009920E-14, -3.000429710E+04, 4.966770100E+00</floatArray>
|
||||
</NASA>
|
||||
</thermo>
|
||||
@@ -154,7 +154,8 @@
|
||||
<products>H2O:1.0</products>
|
||||
</reaction>
|
||||
|
||||
<reaction reversible="no" id="0002" negative_orders="yes">
|
||||
<!-- reaction 0003 -->
|
||||
<reaction reversible="no" id="0003" negative_orders="yes">
|
||||
<equation>H2 + 0.5 O2 =] H2O</equation>
|
||||
<order species="H2">1.0</order>
|
||||
<order species="O2">-0.25</order>
|
||||
|
||||
Reference in New Issue
Block a user