Skip to content

Commit 4c1cb82

Browse files
authored
added C and Python support for custom reactant data (#53)
added C and Python support for custom reactant data
1 parent f9b4002 commit 4c1cb82

File tree

13 files changed

+911
-220
lines changed

13 files changed

+911
-220
lines changed

CHANGELOG.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,20 @@ All notable user-visible changes to this project are documented here.
55
## [Unreleased]
66

77
### Changed
8+
- Python `Mixture` input validation now accepts `str` and `cea.Reactant` entries (including mixed lists) and no longer accepts raw `bytes` species names (`#53`).
9+
- Added SI-focused custom-reactant handling at the Python API layer: `Reactant.temperature` is specified in K and `Reactant.enthalpy` in J/kg (converted internally for core input) (`#53`).
10+
- Legacy input parsing now supports repeated `outp` dataset keywords (including multiline forms) by merging successive `outp` entries during dataset assembly (`#52`).
811

912
### Fixed
13+
- Legacy CLI equilibrium/rocket/shock workflows now propagate `include_ions` into generated product mixtures so ionized products are retained when requested (`#52`).
1014

1115
### Added
16+
- Added C and Python support for custom reactant data (including species not present in `thermo.lib`) in parity with the main interface workflow used by RP-1311 Example 5 (`#53`).
17+
- Added new C-API constructors for generating product mixtures from input-reactant payloads:
18+
- `cea_mixture_create_products_from_input_reactants` (`#53`).
19+
- `cea_mixture_create_products_from_input_reactants_w_ions` (`#53`).
20+
- Added a shared bindc parser path for `cea_reactant_input -> ReactantInput` conversion to reduce duplicated C-binding logic (`#53`).
21+
- Added Python `cea.Reactant` and mixed-input `Mixture(...)` support in the Cython binding (`#53`).
1222

1323
## [3.1.0] - 2026-03-02
1424

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
Example 5 from RP-1311
2+
======================
3+
.. note:: The python script for this example is available in the `source/bind/python/cea/samples` directory of the CEA repository.
4+
5+
Here we describe how to run example 5 from RP-1311 [1]_ using the Python API.
6+
This is an HP equilibrium problem for a solid propellant blend with five reactants,
7+
including one custom reactant (``CHOS-Binder``) that is not present in ``thermo.lib``.
8+
9+
First import the required libraries:
10+
11+
.. code-block:: python
12+
13+
import numpy as np
14+
import cea
15+
16+
Define the pressure schedule and reactant composition by weight fraction:
17+
18+
.. code-block:: python
19+
20+
pressures = np.array([34.473652, 17.236826, 8.618413, 3.447365, 0.344737])
21+
weights = np.array([0.7206, 0.1858, 0.09, 0.002, 0.0016], dtype=np.float64)
22+
T_reac = np.array([298.15, 298.15, 298.15, 298.15, 298.15], dtype=np.float64)
23+
24+
Create a :class:`~cea.Reactant` for ``CHOS-Binder`` using SI values.
25+
In the Python API, custom reactant ``enthalpy`` is in J/kg and ``temperature`` is in K.
26+
Use :mod:`cea.units` helpers for pre-conversion as needed.
27+
28+
.. code-block:: python
29+
30+
chos_binder_mw_kg_per_mol = 14.6652984484e-3
31+
chos_binder_h_si = cea.units.cal_to_joule(-2999.082) / chos_binder_mw_kg_per_mol
32+
33+
reactants = [
34+
"NH4CLO4(I)",
35+
cea.Reactant(
36+
name="CHOS-Binder",
37+
formula={"C": 1.0, "H": 1.86955, "O": 0.031256, "S": 0.008415},
38+
molecular_weight=14.6652984484,
39+
enthalpy=chos_binder_h_si,
40+
temperature=298.15,
41+
),
42+
"AL(cr)",
43+
"MgO(cr)",
44+
"H2O(L)",
45+
]
46+
47+
Then build reactant/product mixtures, solve the HP problem, and print the full table output:
48+
49+
.. literalinclude:: ../../../../source/bind/python/cea/samples/rp1311/example5.py
50+
:language: python
51+
52+
.. rubric:: References
53+
54+
.. [1] B. J. McBride and S. Gordon, *Computer Program for Calculation of Complex Chemical Equilibrium Compositions and Applications*, NASA RP-1311, 1996.

docs/source/examples/equilibrium_examples.rst

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,5 @@ This section describes how to solve equilibrium problems using the Python interf
1010
equilibrium/example2
1111
equilibrium/example3
1212
equilibrium/example4
13-
equilibrium/example14
13+
equilibrium/example5
14+
equilibrium/example14

docs/source/interfaces/python_api.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,11 @@ Mixture
99
-------
1010
The :class:`~cea.Mixture` class is used to define a mixture of product or reactant species. It allows the user to specify the composition of the mixture and provides methods to compute thermodynamic curve fit properties.
1111
The instances of this class are then passed as inputs to the available solver classes (e.g., :class:`~cea.EqSolver`, :class:`~cea.RocketSolver`, :class:`~cea.ShockSolver`, or :class:`~cea.DetonationSolver`).
12+
Custom reactants can be provided through :class:`~cea.Reactant` objects (including mixed lists of strings and Reactant objects).
13+
For :class:`~cea.Reactant`, ``enthalpy`` and ``temperature`` are SI-only in the Python API (J/kg and K, respectively); use :mod:`cea.units` helpers for pre-conversion.
14+
15+
.. autoclass:: cea.Reactant
16+
:members:
1217

1318
.. autoclass:: cea.Mixture
1419
:members:

source/bind/c/CMakeLists.txt

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,15 @@ if (CEA_BUILD_TESTING)
5656
COMMAND cea_bindc_rp1311_ex3
5757
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
5858
)
59+
60+
add_executable(cea_bindc_rp1311_ex5 samples/rp1311_example5.c)
61+
target_link_libraries(cea_bindc_rp1311_ex5 PRIVATE cea::bindc)
62+
add_test(
63+
NAME cea_bindc_rp1311_ex5
64+
COMMAND cea_bindc_rp1311_ex5
65+
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
66+
)
67+
5968
add_executable(cea_bindc_rp1311_ex6 samples/rp1311_example6.c)
6069
target_link_libraries(cea_bindc_rp1311_ex6 PRIVATE cea::bindc)
6170
add_test(
@@ -89,4 +98,3 @@ if (CEA_BUILD_TESTING)
8998
)
9099

91100
endif()
92-

0 commit comments

Comments
 (0)