Cantera / cantera

Chemical kinetics, thermodynamics, and transport tool suite
https://cantera.org
Other
580 stars 341 forks source link

[base] Fix repeated slicing of SolutionArray #1725

Closed ischoegl closed 2 days ago

ischoegl commented 2 days ago

Changes proposed in this pull request

Fix SolutionArray slices that are sliced again

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

Closes #1690

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

See example provided in #1690

In [1]: import cantera as ct
   ...: gas = ct.Solution('gri30.yaml')
   ...: gas.TP = 650, 10 * ct.one_atm
   ...: gas.set_equivalence_ratio(.5, "CH4", "N2:0.79,O2:0.21")
   ...:
   ...: r = ct.IdealGasConstPressureReactor(gas)
   ...: sim = ct.ReactorNet([r])
   ...: solnArr = ct.SolutionArray(gas)
   ...: for i in range(1000):
   ...:     sim.step()
   ...:     solnArr.append(r.thermo.state)
   ...:
   ...: print("Original Soln Arr From Reactor Network")
   ...: print(solnArr[0].T)
   ...: print(solnArr.T[0])
   ...:
   ...: print("Truncated Soln Arr From Reactor Network")
   ...: solnArr_trunc = solnArr[800:]
   ...: print(solnArr_trunc[0].T)
   ...: print(solnArr_trunc.T[0])
Original Soln Arr From Reactor Network
650.0
650.0
Truncated Soln Arr From Reactor Network
653.1879043727091
653.1879043727091

In [2]: solnArr[800]
Out[2]:
           T        D           H2            H  ...         C3H7         C3H8      CH2CHO       CH3CHO
800  653.188  5.26327  1.03361e-09  1.58059e-17  ...  1.58630e-13  1.93274e-09  5.1190e-18  2.39309e-18

[1 rows x 55 components; state='TDY']

In [3]: solnArr_trunc[0]
Out[3]:
           T        D           H2            H  ...         C3H7         C3H8      CH2CHO       CH3CHO
800  653.188  5.26327  1.03361e-09  1.58059e-17  ...  1.58630e-13  1.93274e-09  5.1190e-18  2.39309e-18

[1 rows x 55 components; state='TDY']

Checklist

codecov[bot] commented 2 days ago

Codecov Report

All modified and coverable lines are covered by tests :white_check_mark:

Project coverage is 72.80%. Comparing base (bc24169) to head (05a19f3).

Additional details and impacted files ```diff @@ Coverage Diff @@ ## main #1725 +/- ## ======================================= Coverage 72.79% 72.80% ======================================= Files 381 381 Lines 54011 54016 +5 Branches 9207 9209 +2 ======================================= + Hits 39319 39324 +5 Misses 11707 11707 Partials 2985 2985 ```

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.