[ctml2yaml] Add Shomate species thermo

Fixes error when speciesData has an id attribute other than species_data
and the phase is StoichSubstance.
This commit is contained in:
Bryan W. Weber
2019-10-06 22:49:09 -04:00
parent 449fbd2b94
commit be0e17e2b9
3 changed files with 49 additions and 9 deletions

View File

@@ -395,11 +395,28 @@ class SpeciesThermo:
def __init__(self, thermo):
thermo_type = thermo[0].tag
if thermo_type not in ["NASA", "NASA9", "const_cp"]:
if thermo_type not in ["NASA", "NASA9", "const_cp", "Shomate"]:
raise TypeError("Unknown thermo model type: '{}'".format(thermo[0].tag))
func = getattr(self, thermo_type)
self.thermo_attribs = func(thermo)
def Shomate(self, thermo):
"""Process a Shomate polynomial from XML to a dictionary."""
thermo_attribs = BlockMap({"model": "Shomate", "data": []})
temperature_ranges = set()
model_nodes = thermo.findall("Shomate")
for node in model_nodes:
temperature_ranges.add(float(node.get("Tmin")))
temperature_ranges.add(float(node.get("Tmax")))
coeffs = node.find("floatArray").text.replace("\n", " ").strip().split(",")
thermo_attribs["data"].append(FlowList(map(float, coeffs)))
if len(temperature_ranges) != len(model_nodes) + 1:
raise ValueError(
"The midpoint temperature is not consistent between Shomate entries"
)
thermo_attribs["temperature-ranges"] = FlowList(sorted(temperature_ranges))
return thermo_attribs
def NASA(self, thermo):
"""Process a NASA 7 thermo entry from XML to a dictionary."""
thermo_attribs = BlockMap({"model": "NASA7", "data": []})
@@ -955,11 +972,28 @@ def convert(inpfile, outfile):
act_cross_params[this_phase.phase_attribs["thermo"]].extend(
list(ac_coeff_node.iterfind("crossFluidParameters"))
)
# The density previously associated with the phase has been moved
# to the species definition in the YAML format. StoichSubstance is
# the only model I know of that uses this node
phase_thermo_node = phase_node.find("thermo")
if phase_thermo_node.get("model") == "StoichSubstance":
for den_node in phase_thermo_node:
if den_node.tag == "density":
for spec in this_phase.phase_attribs["species"]:
den_node = phase_thermo_node.find("density")
if den_node is None:
den_node = phase_thermo_node.find("molar-density")
if den_node is None:
den_node = phase_thermo_node.find("molar-volume")
if den_node is None:
raise ValueError(
"Phase node '{}' is missing a density node.".format(
this_phase.phase_attribs["name"]
)
)
for spec_or_dict in this_phase.phase_attribs["species"]:
if isinstance(spec_or_dict, str):
const_density_specs[spec_or_dict] = den_node
else:
for spec in list(spec_or_dict.values())[0]:
const_density_specs[spec] = den_node
# Species

View File

@@ -1005,4 +1005,10 @@ class ctml2yamlTest(utilities.CanteraTest):
yamlWater.TD = T, dens
self.assertNear(ctmlWater.viscosity, yamlWater.viscosity)
self.assertNear(ctmlWater.thermal_conductivity,
yamlWater.thermal_conductivity)
yamlWater.thermal_conductivity)
def test_NaCl_solid_phase(self):
ctml2yaml.convert(Path(self.test_data_dir).joinpath("NaCl_Solid.xml"),
Path(self.test_work_dir).joinpath("NaCl_Solid.yaml"))
ctmlPhase, yamlPhase = self.checkConversion("NaCl_Solid")
self.checkThermo(ctmlPhase, yamlPhase, [300, 500, 1300, 2000])

View File

@@ -2,8 +2,8 @@
<?xml version="1.0"?>
<ctml>
<validate reactions="yes" species="yes"/>
<!-- phase NaCl(S) -->
<!-- phase NaCl(S) -->
<phase dim="3" id="NaCl(S)">
<elementArray datasrc="elements.xml">
O H C Fe Ca N Na Cl
@@ -16,7 +16,7 @@
<kinetics model="none"/>
</phase>
<!-- species definitions -->
<!-- species definitions -->
<speciesData id="species_NaCl(S)">
<!-- species NaCl(S) -->
@@ -27,7 +27,7 @@
<floatArray size="7">
50.72389, 6.672267, -2.517167,
10.15934, -0.200675, -427.2115,
130.3973
130.3973
</floatArray>
</Shomate>
</thermo>