Skip to content

Commit

Permalink
[samples] Fix heat release in ic_engine.py
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
ischoegl committed Mar 11, 2020
1 parent c16c4b0 commit 4ecee45
Showing 1 changed file with 4 additions and 7 deletions.
11 changes: 4 additions & 7 deletions interfaces/cython/cantera/examples/reactors/ic_engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -169,17 +169,14 @@ 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,
t=sim.time, ca=crank_angle(sim.time),
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)


#######################################################################
Expand Down Expand Up @@ -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)
Expand All @@ -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.))

Expand Down

0 comments on commit 4ecee45

Please sign in to comment.