Skip to content

Commit

Permalink
[samples] Use numpy.trapz instead of scipy version
Browse files Browse the repository at this point in the history
Avoids DeprecationWarning: "'scipy.integrate.trapz' is deprecated
in favour of 'scipy.integrate.trapezoid' and will be removed in
SciPy 1.14.0".
  • Loading branch information
ischoegl authored and speth committed Jan 23, 2024
1 parent b62d83b commit 71e4ccb
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions samples/python/reactors/ic_engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
import cantera as ct
import numpy as np

from scipy.integrate import trapz
import matplotlib.pyplot as plt

#########################################################################
Expand Down Expand Up @@ -253,13 +252,13 @@ def ca_ticks(t):
######################################################################

# heat release
Q = trapz(states.heat_release_rate * states.V, t)
Q = np.trapz(states.heat_release_rate * states.V, t)
output_str = '{:45s}{:>4.1f} {}'
print(output_str.format('Heat release rate per cylinder (estimate):',
Q / t[-1] / 1000., 'kW'))

# expansion power
W = trapz(states.dWv_dt, t)
W = np.trapz(states.dWv_dt, t)
print(output_str.format('Expansion power per cylinder (estimate):',
W / t[-1] / 1000., 'kW'))

Expand All @@ -269,6 +268,6 @@ def ca_ticks(t):

# CO emissions
MW = states.mean_molecular_weight
CO_emission = trapz(MW * states.mdot_out * states('CO').X[:, 0], t)
CO_emission /= trapz(MW * states.mdot_out, t)
CO_emission = np.trapz(MW * states.mdot_out * states('CO').X[:, 0], t)
CO_emission /= np.trapz(MW * states.mdot_out, t)
print(output_str.format('CO emission (estimate):', CO_emission * 1.e6, 'ppm'))

0 comments on commit 71e4ccb

Please sign in to comment.