Skip to content

Conversation

ischoegl
Copy link
Member

@ischoegl ischoegl commented Oct 4, 2025

Changes proposed in this pull request

  • Make usage of Sim1D/Domain1D in Python more consistent with SolutionArray.
  • Address syntax error when accessing the radial pressure gradient lambda from Python. The component is internally renamed to Lambda, but it can still be accessed as before through an 'alias' mapping.
  • Introduce getValues/setValues for Domain1D; new methods are also made available to CLib.
  • Introduce more pythonic property names, e.g.: L->radial_pressure_gradient, E->electric_field, Uo->oxidizer_velocity and move them to Domain1D.
  • Provide access of properties/states where they are defined, and start rolling back convenience access via Sim1D.
  • Streamlined access for Sim1D content via SolutionArray

Note: While properties are made available for Domain1D, convenience getters for Sim1D that are not renamed remain unchanged. Future changes to SolutionArray and Domain1D should provide access to various calculated results via CLib; these changes go well beyond the scope of this PR.

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

Closes #1865

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

Fixes SolutionArray:

>>> import cantera as ct
>>> gas = ct.Solution("h2o2.yaml")
>>> arr = ct.SolutionArray(gas)
>>> arr.restore("test/data/flame_lambda.h5", "solution/flame")
>>> print(arr.extra)
['grid', 'velocity', 'spread_rate', 'Lambda']
>>> arr.radial_pressure_gradient
array([-90257.82873678, -90257.82873678, -90257.82873678, -90257.82873678,
       -90257.82873678, -90257.82873678, -90257.82873678, -90257.82873678,
       -90257.82873678, -90257.82873678, -90257.82873678, -90257.82873678,
       -90257.82873678, -90257.82873678, -90257.82873678, -90257.82873678,
       -90257.82873678, -90257.82873678, -90257.82873678, -90257.82873678,
       -90257.82873678, -90257.82873678, -90257.82873678, -90257.82873678,
       -90257.82873678, -90257.82873678, -90257.82873678, -90257.82873678,
       -90257.82873678])
>>> getattr(arr, "lambda")
array([-90257.82873678, -90257.82873678, -90257.82873678, -90257.82873678,
       -90257.82873678, -90257.82873678, -90257.82873678, -90257.82873678,
       -90257.82873678, -90257.82873678, -90257.82873678, -90257.82873678,
       -90257.82873678, -90257.82873678, -90257.82873678, -90257.82873678,
       -90257.82873678, -90257.82873678, -90257.82873678, -90257.82873678,
       -90257.82873678, -90257.82873678, -90257.82873678, -90257.82873678,
       -90257.82873678, -90257.82873678, -90257.82873678, -90257.82873678,
       -90257.82873678])
>>> arr.Lambda
array([-90257.82873678, -90257.82873678, -90257.82873678, -90257.82873678,
       -90257.82873678, -90257.82873678, -90257.82873678, -90257.82873678,
       -90257.82873678, -90257.82873678, -90257.82873678, -90257.82873678,
       -90257.82873678, -90257.82873678, -90257.82873678, -90257.82873678,
       -90257.82873678, -90257.82873678, -90257.82873678, -90257.82873678,
       -90257.82873678, -90257.82873678, -90257.82873678, -90257.82873678,
       -90257.82873678, -90257.82873678, -90257.82873678, -90257.82873678,
       -90257.82873678])

Makes Domain1D more consistent with SolutionArray:

>>> import cantera as ct
>>> gas = ct.Solution("h2o2.yaml")
>>> fl = ct.CounterflowDiffusionFlame(gas)
>>> fl.restore("test/data/flame_lambda.yaml", "solution/flame")
>>> fl.flame.radial_pressure_gradient
array([-90257.82873678, -90257.82873678, -90257.82873678, -90257.82873678,
       -90257.82873678, -90257.82873678, -90257.82873678, -90257.82873678,
       -90257.82873678, -90257.82873678, -90257.82873678, -90257.82873678,
       -90257.82873678, -90257.82873678, -90257.82873678, -90257.82873678,
       -90257.82873678, -90257.82873678, -90257.82873678, -90257.82873678,
       -90257.82873678, -90257.82873678, -90257.82873678, -90257.82873678,
       -90257.82873678, -90257.82873678, -90257.82873678, -90257.82873678,
       -90257.82873678])
>>> fl.flame.H2  # access species as attributes (similar to SolutionArray)
array([9.99999978e-01, 9.99997462e-01, 9.99716817e-01, 9.91765815e-01,
       8.54984875e-01, 5.96459227e-01, 3.17798181e-01, 7.52412972e-02,
       3.04125904e-02, 1.06545147e-02, 3.05519330e-03, 4.85621121e-04,
       1.30666385e-04, 3.26773349e-05, 2.21745526e-05, 1.73235417e-05,
       1.62255848e-05, 1.51638920e-05, 1.31289484e-05, 1.11919925e-05,
       9.39325661e-06, 6.38458417e-06, 4.22996912e-06, 1.88624211e-06,
       4.34155891e-07, 3.24375927e-08, 2.47941064e-09, 7.45717397e-11,
       7.17868321e-13])

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
  • The pull request is ready for review

Copy link

codecov bot commented Oct 4, 2025

Codecov Report

❌ Patch coverage is 65.68627% with 105 lines in your changes missing coverage. Please review.
✅ Project coverage is 75.33%. Comparing base (d7f7a0a) to head (fb34cb7).

Files with missing lines Patch % Lines
src/oneD/Flow1D.cpp 60.95% 22 Missing and 19 partials ⚠️
src/oneD/Boundary1D.cpp 60.00% 12 Missing and 4 partials ⚠️
include/cantera/oneD/Domain1D.h 0.00% 12 Missing ⚠️
src/base/SolutionArray.cpp 67.56% 1 Missing and 11 partials ⚠️
src/oneD/Domain1D.cpp 0.00% 8 Missing ⚠️
interfaces/cython/cantera/_onedim.pyx 85.36% 6 Missing ⚠️
interfaces/cython/cantera/onedim.py 86.36% 6 Missing ⚠️
interfaces/cython/cantera/composite.py 50.00% 1 Missing and 1 partial ⚠️
src/oneD/Sim1D.cpp 75.00% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1995      +/-   ##
==========================================
- Coverage   75.43%   75.33%   -0.11%     
==========================================
  Files         454      454              
  Lines       56348    56496     +148     
  Branches     9299     9330      +31     
==========================================
+ Hits        42508    42560      +52     
- Misses      10698    10771      +73     
- Partials     3142     3165      +23     

☔ View full report in Codecov by Sentry.
📢 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.

@ischoegl ischoegl force-pushed the rename-lambda branch 4 times, most recently from 7a9f6bd to b84a8fa Compare October 5, 2025 16:32
@ischoegl ischoegl changed the title Rename lambda Make Sim1D and SolutionArray usage more consistent Oct 5, 2025
@ischoegl ischoegl changed the title Make Sim1D and SolutionArray usage more consistent Make Sim1D/Domain1D and SolutionArray usage more consistent Oct 5, 2025
@ischoegl ischoegl force-pushed the rename-lambda branch 2 times, most recently from 3d0f6a7 to d82202a Compare October 5, 2025 23:14
@ischoegl ischoegl marked this pull request as ready for review October 6, 2025 02:16
@ischoegl ischoegl requested review from speth and a team and removed request for speth October 6, 2025 02:17
@ischoegl ischoegl marked this pull request as draft October 6, 2025 13:12
@ischoegl ischoegl removed the request for review from a team October 6, 2025 13:12
@ischoegl ischoegl marked this pull request as ready for review October 6, 2025 17:00
@ischoegl ischoegl requested a review from a team October 6, 2025 17:00
@ischoegl
Copy link
Member Author

ischoegl commented Oct 6, 2025

@speth ... This should be ready for a review. What started with a simple bug fix ended up being a broader maintenance job. The work has the side effect of streamlining access for CLib, which should benefit future updates of the MATLAB oneD portion.

{"pressure", "P"},
{"density", "D"},
// reserved names used for 1-D objects
{"spread-rate", "spread_rate"},
Copy link
Member Author

@ischoegl ischoegl Oct 6, 2025

Choose a reason for hiding this comment

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

As an aside: spread_rate uses snake_case, while other components don't. Since we're already renaming components, this could also be updated here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Radial pressure gradient name, lambda, breaks some SolutionArray functionality in Python.
1 participant