Skip to content

Make Sim1D/Domain1D and SolutionArray usage more consistent#1995

Merged
ischoegl merged 24 commits intoCantera:mainfrom
ischoegl:rename-lambda
Oct 9, 2025
Merged

Make Sim1D/Domain1D and SolutionArray usage more consistent#1995
ischoegl merged 24 commits intoCantera:mainfrom
ischoegl:rename-lambda

Conversation

@ischoegl
Copy link
Copy Markdown
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

@codecov
Copy link
Copy Markdown

codecov bot commented Oct 4, 2025

Codecov Report

❌ Patch coverage is 64.40678% with 147 lines in your changes missing coverage. Please review.
✅ Project coverage is 75.24%. Comparing base (3e99c4e) to head (dd89e76).
⚠️ Report is 24 commits behind head on main.

Files with missing lines Patch % Lines
src/oneD/Flow1D.cpp 55.90% 36 Missing and 20 partials ⚠️
include/cantera/oneD/Domain1D.h 31.25% 22 Missing ⚠️
src/oneD/Boundary1D.cpp 62.50% 13 Missing and 5 partials ⚠️
src/base/SolutionArray.cpp 67.56% 1 Missing and 11 partials ⚠️
interfaces/cython/cantera/_onedim.pyx 81.63% 9 Missing ⚠️
interfaces/cython/cantera/onedim.py 84.61% 8 Missing ⚠️
src/oneD/Domain1D.cpp 20.00% 8 Missing ⚠️
include/cantera/oneD/Sim1D.h 33.33% 6 Missing ⚠️
src/oneD/Sim1D.cpp 84.61% 4 Missing ⚠️
include/cantera/oneD/OneDim.h 0.00% 2 Missing ⚠️
... and 1 more
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1995      +/-   ##
==========================================
- Coverage   75.42%   75.24%   -0.19%     
==========================================
  Files         454      454              
  Lines       56554    56756     +202     
  Branches     9334     9373      +39     
==========================================
+ Hits        42654    42704      +50     
- Misses      10746    10873     +127     
- Partials     3154     3179      +25     

☔ 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 4 times, most recently from 56dd64f to 1f547a2 Compare October 6, 2025 01:55
@ischoegl ischoegl marked this pull request as ready for review October 6, 2025 02:16
@ischoegl ischoegl requested review from a team and speth 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
Copy Markdown
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.

Copy link
Copy Markdown
Member

@speth speth left a comment

Choose a reason for hiding this comment

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

Thanks for the work on this, @ischoegl. It certainly expanded in scope well beyond resolving the issue with accessing the lambda component. Most of the changes here make sense to me, with the exception of "rolling back convenience access via Sim1D".

  • I'm on the fence about the use of vector<double>& as the exchange medium of Domain1D::get/setValues and related methods. While it avoids the unsafe raw pointer usage, it is somewhat inflexible, as seen by the need to create temporary vectors where these methods are used both in the Python interface and CLib. I guess the longer-term solution here is to use std::span, as described in Cantera/enhancements#237.
  • Shifting the Python set_profile and related methods out of Sim1D to the underlying Domain1D seems reasonable, and ultimately leads to some good simplifications of the code. However, I'm not keen on deprecating the methods for accessing the grid, temperature, velocity, etc. arrays for the flame domain via the parent Sim1D object. I think this just makes some of the most common data to be accessed more cumbersome to work with. Also, it seems strange to leave some data accessible via the Sim1D object (such as mass fractions) while moving others to the flow domain. I do think the new, more descriptive names for the solution components are a beneficial change.

Comment on lines +63 to +64
auto fullName = findInputFile(fname);
m_file = make_unique<h5::File>(fullName, h5::File::ReadOnly);
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.

This seems unrelated to the rest of the PR. When would you want to read simulation results from a directory on the data path?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

This will be useful if you keep your YAML input file and simulation data in a folder separate from the code used to analyze your data. In this case, you'd set add_data_directory and have things accessible; if I split hair, this avoids having serialized YAML accessible while HDF5 isn't?

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.

I'll grant the point on consistency. Though if you're saving simulation data to a folder, you need to specify the particular output path -- it's not as though Cantera can/should direct output to an arbitrary directory on the CANTERA_DATA path.

@ischoegl ischoegl force-pushed the rename-lambda branch 3 times, most recently from e05921d to 026cb53 Compare October 8, 2025 17:00
@ischoegl ischoegl force-pushed the rename-lambda branch 2 times, most recently from bf3d735 to 3c6bb0d Compare October 9, 2025 15:31
@ischoegl
Copy link
Copy Markdown
Member Author

ischoegl commented Oct 9, 2025

@speth ... I believe I addressed all concerns.

Copy link
Copy Markdown
Member

@speth speth left a comment

Choose a reason for hiding this comment

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

Thanks, @ischoegl, this looks good to me.

@ischoegl ischoegl merged commit a6a341e into Cantera:main Oct 9, 2025
47 of 49 checks passed
@ischoegl ischoegl deleted the rename-lambda branch October 9, 2025 23:47
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.

2 participants