[ctml2yaml] Add temperature_polynomial conversion

This commit is contained in:
Bryan W. Weber
2019-11-13 14:48:48 -06:00
parent 0ec1c9d99b
commit 66c1433101
3 changed files with 134 additions and 15 deletions

View File

@@ -489,9 +489,7 @@ class Phase:
kinetics_node = phase.find("kinetics")
has_reactionArray = phase.find("reactionArray") is not None
if kinetics_node is not None and has_reactionArray:
kinetics_model = self.kinetics_model_mapping[
kinetics_node.get("model", "")
]
kinetics_model = self.kinetics_model_mapping[kinetics_node.get("model", "")]
if kinetics_node.get("model", "").lower() == "solidkinetics":
warnings.warn(
"The SolidKinetics type is not implemented and will not be "
@@ -855,16 +853,19 @@ class Phase:
"model": "constant-volume",
const_prop: get_float_or_units(den_node),
}
for node in this_phase_species:
for datasrc, species_names in node.items():
if datasrc == "species":
datasrc = "species_data"
species = species_data.get(datasrc)
if species is None:
continue
for spec in species:
if spec.attribs["name"] in species_names:
spec.attribs["equation-of-state"] = equation_of_state
flat_species = {k: v for d in this_phase_species for k, v in d.items()}
for datasrc, species_names in flat_species.items():
if datasrc == "species":
datasrc = "species_data"
species = species_data.get(datasrc)
if species is None:
continue
for spec in species:
if (
spec.attribs["name"] in species_names
and "equation-of-state" not in spec.attribs
):
spec.attribs["equation-of-state"] = equation_of_state
def get_species_array(
self, speciesArray_node: etree.Element
@@ -1409,6 +1410,8 @@ class Species:
"constant-incompressible": "constant-volume",
"waterPDSS": "liquid-water-IAPWS95",
"waterIAPWS": "liquid-water-IAPWS95",
"temperature_polynomial": "molar-volume-temperature-polynomial",
"density_temperature_polynomial": "density-temperature-polynomial",
}
electrolyte_species_type_mapping = {
"weakAcidAssociated": "weak-acid-associated",
@@ -1444,7 +1447,8 @@ class Species:
thermo = species_node.find("thermo")
if thermo is not None:
thermo_model = thermo.get("model", "")
# This node is not used anywhere
# This node is not used anywhere, but we don't want it to be processed by
# the SpeciesThermo constructor or the hkft method
pseudo_species = thermo.find("pseudoSpecies")
if pseudo_species is not None:
thermo.remove(pseudo_species)
@@ -1561,7 +1565,7 @@ class Species:
eqn_of_state = {
"model": self.standard_state_model_mapping[std_state_model]
} # type: Dict[str, Union[str, float]]
} # type: Dict[str, Union[str, float, List[Union[str, float]]]]
if std_state_model == "constant_incompressible":
molar_volume_node = std_state.find("molarVolume")
if molar_volume_node is None:
@@ -1571,6 +1575,38 @@ class Species:
std_state,
)
eqn_of_state["molar-volume"] = get_float_or_units(molar_volume_node)
elif "temperature_polynomial" in std_state_model:
poly_node = std_state.find("volumeTemperaturePolynomial")
if poly_node is None:
raise MissingXMLNode(
"{} standard state model requires a "
"volumeTemperaturePolynomial node".format(std_state_model),
std_state
)
poly_values_node = poly_node.find("floatArray")
if poly_values_node is None:
raise MissingXMLNode(
"The floatArray node must be specified", std_state
)
values = clean_node_text(poly_values_node).split(",")
poly_units = poly_values_node.get("units", "")
if not poly_units:
eqn_of_state["data"] = FlowList(map(float, values))
else:
poly_units = re.sub(r"([A-Za-z])-([A-Za-z])", r"\1*\2", poly_units)
poly_units = re.sub(r"([A-Za-z])([-\d])", r"\1^\2", poly_units)
# Need to put units on each term in the polynomial because we can't
# reliably parse the units attribute string into a mass and a length
# (for example, if the units are g/L) and there's no way to specify
# YAML node-level units of volume.
data = []
for v, suffix in zip(values, ("", "/K", "/K^2", "/K^3")):
data.append("{} {}{}".format(v.strip(), poly_units, suffix))
eqn_of_state["data"] = FlowList(data)
self.attribs["equation-of-state"] = eqn_of_state
@classmethod

View File

@@ -1179,3 +1179,10 @@ class ctml2yamlTest(utilities.CanteraTest):
ctmlPhase, yamlPhase = self.checkConversion("reaction-orders")
self.checkThermo(ctmlPhase, yamlPhase, [300, 500])
self.checkKinetics(ctmlPhase, yamlPhase, [300, 1001, 2500], [1e5, 10e5])
def test_species_ss_temperature_polynomials(self):
ctml2yaml.convert(Path(self.test_data_dir).joinpath("Li_Liquid.xml"),
Path(self.test_work_dir).joinpath("Li_Liquid.yaml"))
ctmlPhase, yamlPhase = self.checkConversion("Li_Liquid")
self.checkThermo(ctmlPhase, yamlPhase, [300, 500])

76
test/data/Li_Liquid.xml Normal file
View File

@@ -0,0 +1,76 @@
<?xml version="1.0"?>
<ctml>
<validate reactions="yes" species="yes"/>
<!-- phase Li(L) -->
<phase dim="3" id="Li(L)">
<elementArray datasrc="elements.xml">
Li
</elementArray>
<speciesArray datasrc="#species_Li(L)"> Li(L) Li(L)2 </speciesArray>
<thermo model="Margules"/>
<state>
<temperature units="K">300.0</temperature>
<pressure units="Pa">101325.0</pressure>
<moleFractions> Li(L):0.5 Li(L)2:0.5</moleFractions>
</state>
<transport model="None"/>
<kinetics model="none"/>
</phase>
<!-- species definitions -->
<speciesData id="species_Li(L)">
<!-- species Li(L) -->
<!-- melting temperature = 180.5 C -->
<species name="Li(L)">
<atomArray> Li:1 </atomArray>
<standardState model="density_temperature_polynomial">
<!-- density from Goodfellows. Metals, Alloys, Compounds, Ceramcs, Polymers, Composites. Catalogue 1993/1994 -->
<volumeTemperaturePolynomial>
<floatArray size="4" units="g/L">
0.536504, -1.04279e-4, 3.84825e-9, -5.2853e-12
</floatArray>
</volumeTemperaturePolynomial>
</standardState>
<thermo>
<Shomate Pref="1 bar" Tmax="700" Tmin="298">
<floatArray size="7">
26.3072, 30.4657, -69.1692, 44.1951, 0.0776, -6.0337, 59.8106
</floatArray>
</Shomate>
<Shomate Pref="1 bar" Tmax="3000" Tmin="700">
<floatArray size="7">
22.6832, 10.476, -6.5428, 1.3255, 0.8783, -2.0426, 62.8859
</floatArray>
</Shomate>
</thermo>
</species>
<!-- species Li(L)2 -->
<!-- This species is invented for the purposes of the test -->
<species name="Li(L)2">
<atomArray> Li:1 </atomArray>
<standardState model="temperature_polynomial">
<volumeTemperaturePolynomial>
<floatArray size="4" units="cm3/mol">
0.536504, -1.04279e-4, 3.84825e-9, -5.2853e-12
</floatArray>
</volumeTemperaturePolynomial>
</standardState>
<thermo>
<Shomate Pref="1 bar" Tmax="700" Tmin="298">
<floatArray size="7">
26.3072, 30.4657, -69.1692, 44.1951, 0.0776, -6.0337, 59.8106
</floatArray>
</Shomate>
<Shomate Pref="1 bar" Tmax="3000" Tmin="700">
<floatArray size="7">
22.6832, 10.476, -6.5428, 1.3255, 0.8783, -2.0426, 62.8859
</floatArray>
</Shomate>
</thermo>
</species>
</speciesData>
</ctml>