Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions data/airNASA9.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ species:
composition: {N: 2}
thermo:
model: NASA9
reference-pressure: 1 bar
temperature-ranges: [200.0, 1000.0, 6000.0, 2.0e+04]
data:
- [2.210371497e+04, -381.846182, 6.08273836, -8.53091441e-03, 1.384646189e-05,
Expand All @@ -35,6 +36,7 @@ species:
composition: {O: 2}
thermo:
model: NASA9
reference-pressure: 1 bar
temperature-ranges: [200.0, 1000.0, 6000.0, 2.0e+04]
data:
- [-3.42556342e+04, 484.700097, 1.119010961, 4.29388924e-03, -6.83630052e-07,
Expand All @@ -48,6 +50,7 @@ species:
composition: {N: 1, O: 1}
thermo:
model: NASA9
reference-pressure: 1 bar
temperature-ranges: [200.0, 1000.0, 6000.0, 2.0e+04]
data:
- [-1.143916503e+04, 153.6467592, 3.43146873, -2.668592368e-03, 8.48139912e-06,
Expand All @@ -61,6 +64,7 @@ species:
composition: {N: 1}
thermo:
model: NASA9
reference-pressure: 1 bar
temperature-ranges: [200.0, 1000.0, 6000.0, 2.0e+04]
data:
- [0.0, 0.0, 2.5, 0.0, 0.0, 0.0, 0.0, 5.61046378e+04, 4.193905036]
Expand All @@ -73,6 +77,7 @@ species:
composition: {O: 1}
thermo:
model: NASA9
reference-pressure: 1 bar
temperature-ranges: [200.0, 1000.0, 6000.0, 2.0e+04]
data:
- [-7953.6113, 160.7177787, 1.966226438, 1.01367031e-03, -1.110415423e-06,
Expand All @@ -87,6 +92,7 @@ species:
composition: {N: 2, E: -1}
thermo:
model: NASA9
reference-pressure: 1 bar
temperature-ranges: [298.15, 1000.0, 6000.0, 2.0e+04]
data:
- [-3.47404747e+04, 269.6222703, 3.16491637, -2.132239781e-03, 6.7304764e-06,
Expand All @@ -100,6 +106,7 @@ species:
composition: {O: 2, E: -1}
thermo:
model: NASA9
reference-pressure: 1 bar
temperature-ranges: [298.15, 1000.0, 6000.0, 2.0e+04]
data:
- [-8.60720545e+04, 1051.875934, -0.543238047, 6.57116654e-03, -3.27426375e-06,
Expand All @@ -113,6 +120,7 @@ species:
composition: {N: 1, O: 1, E: -1}
thermo:
model: NASA9
reference-pressure: 1 bar
temperature-ranges: [298.15, 1000.0, 6000.0, 2.0e+04]
data:
- [1398.106635, -159.0446941, 5.1228954, -6.39438862e-03, 1.123918342e-05,
Expand All @@ -126,6 +134,7 @@ species:
composition: {N: 1, E: -1}
thermo:
model: NASA9
reference-pressure: 1 bar
temperature-ranges: [298.15, 1000.0, 6000.0, 2.0e+04]
data:
- [5237.07921, 2.299958315, 2.487488821, 2.737490756e-05, -3.134447576e-08,
Expand All @@ -140,6 +149,7 @@ species:
composition: {O: 1, E: -1}
thermo:
model: NASA9
reference-pressure: 1 bar
temperature-ranges: [298.15, 1000.0, 6000.0, 2.0e+04]
data:
- [0.0, 0.0, 2.5, 0.0, 0.0, 0.0, 0.0, 1.879352842e+05, 4.39337676]
Expand All @@ -152,6 +162,7 @@ species:
composition: {E: 1}
thermo:
model: NASA9
reference-pressure: 1 bar
temperature-ranges: [298.15, 1000.0, 6000.0, 2.0e+04]
data:
- [0.0, 0.0, 2.5, 0.0, 0.0, 0.0, 0.0, -745.375, -11.72081224]
Expand Down
14 changes: 12 additions & 2 deletions interfaces/cython/cantera/ck2yaml.py
Original file line number Diff line number Diff line change
Expand Up @@ -207,8 +207,9 @@ class Nasa9:
[(T_low, T_high), [a_0, a_1, ..., a_8]]
```
"""
def __init__(self, *, parser, data, note=''):
def __init__(self, *, parser, data, note='', ref_pressure='1 bar'):
self.note = note
self.ref_pressure = ref_pressure
self.data = list(sorted(data))
self.Tranges = [self.data[0][0][0]]
for i in range(1, len(data)):
Expand All @@ -222,6 +223,8 @@ def __init__(self, *, parser, data, note=''):
def to_yaml(cls, representer, node):
out = BlockMap([('model', 'NASA9')])
out['temperature-ranges'] = FlowList(node.Tranges)
if node.ref_pressure:
out['reference-pressure'] = node.ref_pressure
out['data'] = [FlowList(poly) for (trange, poly) in node.data]
if node.note:
out['note'] = node.note
Expand Down Expand Up @@ -1084,6 +1087,13 @@ def read_NASA9_entry(self, entry, comments):

composition = self.parse_composition(entry[1][10:50], 5, 8)

# In NASA 9-coefficient polynomial format (NASA RP-1311 / TP-2002-211556),
# column 52 of line 2 designates phase: 0 for gas, >0 for condensed.
# Gas species have standard pressure 1 bar; condensed species use 1 atm.
Comment thread
speth marked this conversation as resolved.
Resolved
phase_flag = entry[1][51:52].strip() if len(entry[1]) > 51 else '0'
is_condensed = phase_flag not in ('', '0')
ref_pressure = None if is_condensed else '1 bar'

polys = []
try:
for i in range(N):
Expand All @@ -1098,7 +1108,7 @@ def read_NASA9_entry(self, entry, comments):
except (IndexError, ValueError) as err:
logger.error(self.entry("thermo entry") + str(err))

thermo = Nasa9(data=polys, note=note, parser=self)
thermo = Nasa9(data=polys, note=note, parser=self, ref_pressure=ref_pressure)

return species, thermo, composition

Expand Down
2 changes: 2 additions & 0 deletions interfaces/cython/cantera/ck2yaml.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ class Nasa7:

class Nasa9:
note: str
ref_pressure: str | None
data: list[tuple[list[float], list[float]]]
Tranges: list[float]
def __init__(
Expand All @@ -86,6 +87,7 @@ class Nasa9:
parser: Parser,
data: list[tuple[list[float], list[float]]],
note: str = "",
ref_pressure: str | None = "1 bar",
) -> None: ...
@classmethod
def to_yaml(cls, representer: SafeRepresenter, node: Nasa9) -> MappingNode: ...
Expand Down
6 changes: 6 additions & 0 deletions interfaces/cython/cantera/ctml2yaml.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ class _DebyeHuckelBetaMatrix(TypedDict, total=False):
"model": Required[str],
"temperature-ranges": list[float],
"data": _ThermoPolyType,
"reference-pressure": float,
},
total=False,
)
Expand Down Expand Up @@ -1653,6 +1654,11 @@ def NASA9(self, thermo: etree.Element) -> _SpeciesThermoInput:
the tag ``NASA9``.
"""
thermo_attribs = cast(_SpeciesThermoInput, BlockMap({"model": "NASA9"}))
model_node = thermo.find("NASA9")
if model_node is not None:
p0 = model_node.get("P0")
if p0 is not None:
thermo_attribs["reference-pressure"] = float(p0)
data, temperature_ranges = self.process_polynomial(thermo, "NASA9")
thermo_attribs["temperature-ranges"] = temperature_ranges
thermo_attribs["data"] = data
Expand Down
1 change: 1 addition & 0 deletions interfaces/cython/cantera/speciesthermo.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
"temperature-ranges": list[float],
"data": list[list[float]],
"note": str,
"reference-pressure": float | str,
},
total=False,
)
Expand Down
4 changes: 4 additions & 0 deletions test/data/nasa9-embedded.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ species:
composition: {Ar: 1}
thermo:
model: NASA9
reference-pressure: 1 bar
temperature-ranges: [200.0, 2.0e+04]
data:
- [0.0, 0.0, 2.5, 0.0, 0.0, 0.0, 0.0, -745.375, 4.37967491]
Expand All @@ -26,6 +27,7 @@ species:
composition: {C: 1, O: 1}
thermo:
model: NASA9
reference-pressure: 1 bar
temperature-ranges: [200.0, 1000.0, 6000.0, 2.0e+04]
data:
- [1.489045326e+04, -292.2285939, 5.72452717, -8.17623503e-03, 1.456903469e-05,
Expand All @@ -39,6 +41,7 @@ species:
composition: {C: 1, O: 2}
thermo:
model: NASA9
reference-pressure: 1 bar
temperature-ranges: [200.0, 1000.0, 6000.0, 2.0e+04]
data:
- [4.94365054e+04, -626.411601, 5.30172524, 2.503813816e-03, -2.127308728e-07,
Expand All @@ -52,6 +55,7 @@ species:
composition: {O: 1}
thermo:
model: NASA9
reference-pressure: 1 bar
temperature-ranges: [200.0, 1000.0, 6000.0, 2.0e+04]
data:
- [-7953.6113, 160.7177787, 1.966226438, 1.01367031e-03, -1.110415423e-06,
Expand Down
2 changes: 2 additions & 0 deletions test/data/nasa9-test-subset.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ species:
note: Gurvich,1996a pt1 p173 pt2 p134. [tpis96]
thermo:
model: NASA9
reference-pressure: 1 bar
temperature-ranges: [200.0, 1000.0, 6000.0]
data:
- [7.75060097e+04, -1440.779717, 14.01744141, -6.38163124e-03, 5.87167472e-06,
Expand All @@ -27,6 +28,7 @@ species:
note: Ref-Elm. Moore,1971. Gordon,1999.. [g 3/98]
thermo:
model: NASA9
reference-pressure: 1 bar
temperature-ranges: [200.0, 1000.0]
data:
- [0.0, 0.0, 2.5, 0.0, 0.0, 0.0, 0.0, -745.375, 4.37967491]
3 changes: 3 additions & 0 deletions test/data/nasa9-test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ species:
note: Gurvich,1996a pt1 p173 pt2 p134.
thermo:
model: NASA9
reference-pressure: 1 bar
temperature-ranges: [200.0, 1000.0, 6000.0]
data:
- [7.75060097e+04, -1440.779717, 14.01744141, -6.38163124e-03, 5.87167472e-06,
Expand All @@ -27,6 +28,7 @@ species:
note: 'Ref-Species. Chase, 1998 3/82. '
thermo:
model: NASA9
reference-pressure: 1 bar
temperature-ranges: [298.15, 1000.0, 6000.0, 2.0e+04]
data:
- [0.0, 0.0, 2.5, 0.0, 0.0, 0.0, 0.0, -745.375, -11.72081224]
Expand All @@ -37,6 +39,7 @@ species:
note: 'Ref-Elm. Moore,1971. Gordon,1999.. '
thermo:
model: NASA9
reference-pressure: 1 bar
temperature-ranges: [200.0, 1000.0]
data:
- [0.0, 0.0, 2.5, 0.0, 0.0, 0.0, 0.0, -745.375, 4.37967491]
50 changes: 50 additions & 0 deletions test/python/test_convert.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from __future__ import annotations

import io
import itertools
from pathlib import Path
import pytest
Expand Down Expand Up @@ -288,6 +289,38 @@ def test_nasa9_embedded(self):
self.checkThermo(ref, gas, [300, 500, 1200, 5000])
self.checkKinetics(ref, gas, [300, 1200, 9000], [5e3, 1e5, 2e6])

def test_nasa9_condensed_phase(self):
# NASA9 condensed species (phase flag > 0 in col 52) must omit reference-pressure,
# preserving the 1 atm default, whereas gas species (flag == 0) use 1 bar.
parser = ck2yaml.Parser()
entry_cond = [
"Cr(cr) Ref-Elm. Moore,1971. Gordon,1999..",
" 1 g 3/98 Cr 1.00 0.00 0.00 0.00 0.00 1 51.9961000 0.000",
" 200.000 1000.0007 -2.0 -1.0 0.0 1.0 2.0 3.0 4.0 0.0 6197.428",
" 0.000000000D+00 0.000000000D+00 2.500000000D+00 0.000000000D+00 0.000000000D+00",
" 0.000000000D+00 0.000000000D+00 -7.453750000D+02 4.379674910D+00",
]
_, thermo_cond, _ = parser.read_NASA9_entry(entry_cond, [])
assert thermo_cond.ref_pressure is None
emitter = ck2yaml.yaml.YAML()
emitter.register_class(ck2yaml.Nasa9)
s_cond = io.StringIO()
emitter.dump(thermo_cond, s_cond)
assert "reference-pressure" not in s_cond.getvalue()

entry_gas = [
"AR Ref-Elm. Moore,1971. Gordon,1999..",
" 1 g 3/98 Ar 1.00 0.00 0.00 0.00 0.00 0 39.9480000 0.000",
" 200.000 1000.0007 -2.0 -1.0 0.0 1.0 2.0 3.0 4.0 0.0 6197.428",
" 0.000000000D+00 0.000000000D+00 2.500000000D+00 0.000000000D+00 0.000000000D+00",
" 0.000000000D+00 0.000000000D+00 -7.453750000D+02 4.379674910D+00",
]
_, thermo_gas, _ = parser.read_NASA9_entry(entry_gas, [])
assert thermo_gas.ref_pressure == "1 bar"
s_gas = io.StringIO()
emitter.dump(thermo_gas, s_gas)
assert "reference-pressure: 1 bar" in s_gas.getvalue()

def test_sri_falloff(self):
output = self.convert("sri-falloff.inp", thermo="dummy-thermo.dat")
ref, gas = self.checkConversion("sri-falloff.yaml", output)
Expand Down Expand Up @@ -1538,6 +1571,23 @@ def test_nasa9(self):
ctmlGas, yamlGas = self.checkConversion("nasa9-test")
self.checkThermo(ctmlGas, yamlGas, [300, 500, 1300, 2000])

def test_nasa9_no_p0(self):
# When P0 is omitted from NASA9 CTML element, reference-pressure should not be set
from xml.etree import ElementTree as etree
root = etree.fromstring("""
<species name="test">
<thermo>
<NASA9 Tmax="1000.0" Tmin="200.0">
<floatArray name="coeffs" size="9">
0, 0, 2.5, 0, 0, 0, 0, 0, 0
</floatArray>
</NASA9>
</thermo>
</species>
""")
converter = ctml2yaml.SpeciesThermo(root.find("thermo"))
assert "reference-pressure" not in converter.attribs

def test_chemically_activated(self):
self.convert("chemically-activated-reaction")
ctmlGas, yamlGas = self.checkConversion("chemically-activated-reaction")
Expand Down
18 changes: 18 additions & 0 deletions test/python/test_thermo.py
Original file line number Diff line number Diff line change
Expand Up @@ -2939,3 +2939,21 @@ def test_zero_length_slice_SolutionArray(self):
states.TP = [100,300,900,323.23], ct.one_atm
arr2 = states[slice(0)]
assert len(arr2.T) == 0


class TestNASA9ReferenceState:
"""Regression tests for issue #2129 - NASA9 reference pressure."""

def test_airNASA9_reference_pressure(self):
"""NASA9 species in airNASA9.yaml must use 1 bar reference pressure."""
gas = ct.Solution("airNASA9.yaml")
for sp in gas.species():
assert sp.thermo.reference_pressure == approx(1e5)

def test_airNASA9_N2_entropy(self):
"""N2 standard entropy must match NIST value of 191.609 J/mol/K."""
gas = ct.Solution("airNASA9.yaml")
gas.TP = 298.15, 1e5
idx = gas.species_index("N2")
S298 = gas.standard_entropies_R[idx] * ct.gas_constant / 1000 # J/mol/K
assert S298 == approx(191.609, abs=0.01)
Loading