From 4ecee451ad864f8ac6bffa675aa811da2f4def9d Mon Sep 17 00:00:00 2001 From: Ingmar Schoegl Date: Wed, 11 Mar 2020 09:52:18 -0500 Subject: [PATCH] [samples] Fix heat release in ic_engine.py This commit fixes a bug caused by the recently introduced `heat_release_rate` method of `SolutionArray` objects: the new method masked the pre-existing homonymous `extra` column. --- .../cython/cantera/examples/reactors/ic_engine.py | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/interfaces/cython/cantera/examples/reactors/ic_engine.py b/interfaces/cython/cantera/examples/reactors/ic_engine.py index 4dbf527be36..8da6a3c5652 100644 --- a/interfaces/cython/cantera/examples/reactors/ic_engine.py +++ b/interfaces/cython/cantera/examples/reactors/ic_engine.py @@ -155,7 +155,7 @@ def piston_speed(t): # set up output data arrays states = ct.SolutionArray( cyl.thermo, - extra=('t', 'ca', 'V', 'm', 'mdot_in', 'mdot_out', 'dWv_dt', 'heat_release_rate'), + extra=('t', 'ca', 'V', 'm', 'mdot_in', 'mdot_out', 'dWv_dt'), ) # simulate with a maximum resolution of 1 deg crank angle @@ -169,8 +169,6 @@ def piston_speed(t): # calculate results to be stored dWv_dt = - (cyl.thermo.P - ambient_air.thermo.P) * A_piston * \ piston_speed(sim.time) - heat_release_rate = - cyl.volume * ct.gas_constant * cyl.T * \ - np.sum(gas.standard_enthalpies_RT * cyl.thermo.net_production_rates, 0) # append output data states.append(cyl.thermo.state, @@ -178,8 +176,7 @@ def piston_speed(t): V=cyl.volume, m=cyl.mass, mdot_in=inlet_valve.mdot(sim.time), mdot_out=outlet_valve.mdot(sim.time), - dWv_dt=dWv_dt, - heat_release_rate=heat_release_rate) + dWv_dt=dWv_dt) ####################################################################### @@ -221,7 +218,7 @@ def ca_ticks(t): # heat of reaction and expansion work fig, ax = plt.subplots() -ax.plot(t, 1.e-3 * states.heat_release_rate, label=r'$\dot{Q}$') +ax.plot(t, 1.e-3 * states.heat_release_rate * states.V, label=r'$\dot{Q}$') ax.plot(t, 1.e-3 * states.dWv_dt, label=r'$\dot{W}_v$') ax.set_ylim(-1e2, 1e3) ax.legend(loc=0) @@ -247,7 +244,7 @@ def ca_ticks(t): ###################################################################### # heat release -Q = trapz(states.heat_release_rate, t) +Q = trapz(states.heat_release_rate * states.V, t) print('{:45s}{:>4.1f} kW'.format('Heat release rate per cylinder (estimate):', Q / t[-1] / 1000.))