Skip to content

Fix 2129 nasa9 reference pressure - #2174

Merged
speth merged 6 commits into
Cantera:mainfrom
hazalkoom:fix-2129-nasa9-reference-pressure
Nov 22, 2026
Merged

speth merged 6 commits into
Cantera:mainfrom
hazalkoom:fix-2129-nasa9-reference-pressure

Conversation

@hazalkoom

Copy link
Copy Markdown
Contributor

Changes proposed in this pull request

  • Explicitly sets reference-pressure: 1 bar on all species in data/airNASA9.yaml and test YAML reference files.
  • Updates ck2yaml.py and ctml2yaml.py to emit reference-pressure: 1 bar when converting NASA9 polynomials to YAML.
  • Updates _SpeciesThermoInput TypedDict in ctml2yaml.py and speciesthermo.py to include "reference-pressure".
  • Adds regression tests in test/python/test_thermo.py to verify that NASA9 species load with 1 bar reference pressure and evaluate standard entropy matching NIST values.

Background:
NASA 9-coefficient polynomials (McBride et al. 2002, NASA TP-2002-211556 / NASA ThermoBuild) use a standard reference pressure of 1 bar (100,000 Pa). When reference-pressure was omitted in YAML files, Cantera defaulted to 1 atm (101,325 Pa), causing a ~0.109 J/mol/K offset in standard entropy calculations ($R \ln(101325 / 100000)$).

If applicable, fill in the issue number this pull request is fixing

Closes #2129

If applicable, provide an example illustrating new features this pull request is introducing

(Bug fix / standard-state correction only).

import cantera as ct
gas = ct.Solution("airNASA9.yaml")
n2 = gas.species("N2")
assert n2.thermo.reference_pressure == 1e5  # was previously 101325.0 Pa

AI Statement (required)

  • Extensive use of generative AI.
    Significant portions of code or documentation were generated with AI, including
    logic and implementation decisions. All generated code and documentation were
    reviewed and understood by the contributor. Examples: Output from agentic coding
    tools and/or substantial refactoring by LLMs (web-based or local).

Checklist

  • The pull request includes a clear description of this code change
  • Commit messages have short titles and reference relevant issues
  • Build passes (scons build & scons test) and unit tests address code coverage
  • Style & formatting of contributed code follows contributing guidelines
  • AI Statement is included
  • The pull request is ready for review

NASA 9-coefficient polynomials (McBride et al. 2002, NASA TP-2002-211556)
use a standard reference pressure of 1 bar (100,000 Pa). When the
reference-pressure field was omitted in YAML files, Cantera defaulted to
1 atm (101,325 Pa), causing a slight offset in standard entropy calculations.

- Emit reference-pressure: 1 bar for NASA9 entries in ck2yaml and ctml2yaml
- Explicitly specify reference-pressure: 1 bar for species in airNASA9.yaml and test datasets
- Add regression tests in test_thermo.py

Fixes Cantera#2129
Fixes mypy / stubtest type check error.
Copilot AI lite review requested due to automatic review settings September 15, 2026 08:20

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 Needs a closer look

The NASA9 converters may incorrectly apply 1 bar to condensed-phase species instead of preserving their 1 atm reference pressure.

Pull request overview

Fixes NASA9 reference-pressure handling by applying the 1 bar standard and adding regression coverage.

Changes:

  • Updates NASA9 YAML data and fixtures with explicit reference pressures.
  • Updates CK/CTML conversion metadata and Python typing.
  • Adds pressure and entropy regression tests.
File summaries
File Reviewed change
test/python/test_thermo.py Adds NASA9 pressure and entropy tests.
test/data/nasa9-test.yaml Updates NASA9 reference-pressure fixtures.
test/data/nasa9-test-subset.yaml Updates subset fixture pressures.
test/data/nasa9-embedded.yaml Updates embedded NASA9 pressures.
interfaces/cython/cantera/speciesthermo.py Extends thermo input typing.
interfaces/cython/cantera/ctml2yaml.py Updates NASA9 reference-pressure conversion.
interfaces/cython/cantera/ck2yaml.py Updates NASA9 reference-pressure conversion.
data/airNASA9.yaml Sets explicit 1 bar references.
Review details

Suppressed comments (2)

interfaces/cython/cantera/ck2yaml.py:225

  • This hard-codes 1 bar for every NASA9 entry, but NASA9 is also used for condensed species: Nasa9Poly1 documents 1 bar for gases and 1 atm for condensed phases (include/cantera/thermo/Nasa9Poly1.h:48-50). ck2yaml has no phase information here, so converting condensed NASA9 data such as the nasa_condensed.yaml source will silently change its reference pressure from the current 1 atm default. Please make the emission phase-aware or preserve the condensed-phase default.
        out['reference-pressure'] = '1 bar'

interfaces/cython/cantera/ctml2yaml.py:1663

  • The fallback has the same phase ambiguity for XML conversion: when P0/Pref is absent, this changes NASA9 condensed species to 1 bar even though the model documentation specifies 1 atm for condensed phases. SpeciesThermo.NASA9 only receives the thermo node, so it cannot safely choose 1 bar without phase context; otherwise this conversion changes the prior default behavior.
                thermo_attribs["reference-pressure"] = 1.0e5
  • Files reviewed: 8/8 changed files
  • Comments generated: 0
  • Review effort level: Lite

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

@codecov

codecov Bot commented Sep 15, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 92.85714% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 77.45%. Comparing base (6143316) to head (777d49e).
⚠️ Report is 8 commits behind head on main.

Files with missing lines Patch % Lines
interfaces/cython/cantera/ctml2yaml.py 80.00% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2174      +/-   ##
==========================================
- Coverage   78.46%   77.45%   -1.02%     
==========================================
  Files         463      470       +7     
  Lines       55849    57184    +1335     
  Branches     9169     9195      +26     
==========================================
+ Hits        43823    44292     +469     
- Misses       8960     9823     +863     
- Partials     3066     3069       +3     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Only write reference-pressure when P0/Pref is explicitly present in
the source XML. This avoids incorrect defaults for condensed-phase
species where the standard state pressure is 1 atm, not 1 bar.
…erage

- In ck2yaml, inspect column 52 (phase flag) of NASA9 entries. Gas-phase
  species (flag 0) emit reference-pressure: 1 bar, while condensed-phase
  species (flag > 0) omit reference-pressure, preserving the 1 atm default.
- In ctml2yaml, only check P0 on NASA9 elements to eliminate partial branch.
- Add tests in test_convert.py covering both gas and condensed NASA9
  conversion in ck2yaml and CTML conversion without P0.
Fixes stubtest consistency check in typing workflow.
@hazalkoom

Copy link
Copy Markdown
Contributor Author

Summary of Updates & Fixes Since Initial Submission

Following CI checks and review feedback, here is what was identified and updated:

  1. Phase-Aware Reference Pressure in ck2yaml & ctml2yaml:

    • What was wrong: The initial change unconditionally emitted reference-pressure: 1 bar for all NASA9 entries. While gas-phase NASA9 polynomials (McBride 2002) use 1 bar, condensed-phase species (e.g., solid-state polynomials from McBride 1993 with phase transitions) specify standard state pressure of 1 atm.
    • What is now different:
      • ck2yaml.py now inspects column 52 (phase flag) of Card 2 in the Chemkin/NASA9 format: gas-phase species (flag 0) emit reference-pressure: 1 bar, while condensed-phase species (flag > 0) omit reference-pressure, preserving Cantera's 1 atm default.
      • ctml2yaml.py only sets reference-pressure when P0 is explicitly provided in the XML <NASA9> element, avoiding an unsafe fallback.
  2. Typing & Stub Consistency (mypy & stubtest):

    • What was wrong: The TypedDict for species thermo input was missing "reference-pressure", and the .pyi stub for Nasa9 was missing the newly added ref_pressure parameter.
    • What is now different:
      • Added "reference-pressure" to _SpeciesThermoInput in ctml2yaml.py and speciesthermo.py.
      • Updated interfaces/cython/cantera/ck2yaml.pyi to declare ref_pressure on Nasa9.__init__.
  3. Test Coverage & Branch Clean-up:

    • Added unit tests in test/python/test_convert.py covering both gas-phase and condensed-phase NASA9 conversions in ck2yaml, as well as CTML XML conversion without P0.

@speth speth left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for putting this together, @hazalkoom, and sorry for the delayed review. I think this all looks good, with one minor suggestion for a comment noted below.

Comment thread interfaces/cython/cantera/ck2yaml.py Resolved
@hazalkoom

Copy link
Copy Markdown
Contributor Author

Thanks for putting this together, @hazalkoom, and sorry for the delayed review. I think this all looks good, with one minor suggestion for a comment noted below.

no problem about the delay, updated the comment like you suggested.

@speth speth left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the quick update! Looks good to me.

@speth
speth merged commit 096972d into Cantera:main Nov 22, 2026
49 of 51 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Incorrect reference state in some of the YAML files.

3 participants