Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 1 addition & 4 deletions interfaces/cython/cantera/examples/reactors/combustor.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,12 +73,9 @@ def mdot(t):
states.append(combustor.thermo.state, tres=residence_time)
residence_time *= 0.9 # decrease the residence time for the next iteration

# Heat release rate [W/m^3]
Q = - np.sum(states.net_production_rates * states.partial_molar_enthalpies, axis=1)

# Plot results
f, ax1 = plt.subplots(1, 1)
ax1.plot(states.tres, Q, '.-', color='C0')
ax1.plot(states.tres, states.heat_release_rate, '.-', color='C0')
ax2 = ax1.twinx()
ax2.plot(states.tres[:-1], states.T[:-1], '.-', color='C1')
ax1.set_xlabel('residence time [s]')
Expand Down
38 changes: 24 additions & 14 deletions interfaces/cython/cantera/examples/reactors/fuel_injection.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

# Use a reduced n-dodecane mechanism with PAH formation pathways
gas = ct.Solution('nDodecane_Reitz.yaml', 'nDodecane_IG')
gas.case_sensitive_species_names = True

# Create a Reservoir for the fuel inlet, set to pure dodecane
gas.TPX = 300, 20*ct.one_atm, 'c12h26:1.0'
Expand Down Expand Up @@ -59,31 +60,40 @@ def fuel_mdot(t):
tprev = tnow
states.append(r.thermo.state, t=tnow)

# nice names for species
labels = {
# nice names for species, including PAH species that can be considered
# as precursors to soot formation
species_aliases = {
'o2': 'O$_2$',
'h2o': 'H$_2$O',
'co': 'CO',
'co2': 'CO$_2$',
'h2': 'H$_2$',
'ch4': 'CH$_4$'
}
for name, alias in species_aliases.items():
gas.add_species_alias(name, alias)

pah_aliases = {
'A1c2h': 'phenylacetylene',
'A1c2h3': 'styrene',
'A1': 'benzene',
'A2': 'naphthalene',
'A2r5': 'acenaphthylene',
'A3': 'phenanthrene',
'A4': 'pyrene',
'o2': 'O$_2$',
'h2o': 'H$_2$O',
'co2': 'CO$_2$',
'h2': 'H$_2$',
'ch4': 'CH$_4$'
'A4': 'pyrene'
}
for name, alias in pah_aliases.items():
gas.add_species_alias(name, alias)

# Plot the concentrations of some species of interest, including PAH species
# which can be considered as precursors to soot formation.
# Plot the concentrations of species of interest
f, ax = plt.subplots(1, 2)

for s in ['o2', 'h2o', 'co2', 'CO', 'h2', 'ch4']:
ax[0].plot(states.t, states(s).X, label=labels.get(s, s))
for s in species_aliases.values():
Comment thread
ischoegl marked this conversation as resolved.
ax[0].plot(states.t, states(s).X, label=s)

for s in pah_aliases.values():
ax[1].plot(states.t, states(s).X, label=s)

for s in ['A1c2h', 'A1c2h3', 'A2r5', 'A1', 'A2', 'A3', 'A4']:
ax[1].plot(states.t, states(s).X, label=labels[s])
for a in ax:
a.legend(loc='best')
a.set_xlabel('time [s]')
Expand Down
11 changes: 9 additions & 2 deletions interfaces/cython/cantera/examples/reactors/periodic_cstr.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,16 @@
network.advance(t)
states.append(cstr.thermo.state, t=t)

aliases = {'H2': 'H$_2$', 'O2': 'O$_2$', 'H2O': 'H$_2$O'}
for name, alias in aliases.items():
gas.add_species_alias(name, alias)

if __name__ == '__main__':
print(__doc__)
plt.figure(1)
plt.plot(states.t, states('H2', 'O2', 'H2O').Y)
plt.title('Mass Fractions')
for spc in aliases.values():
plt.plot(states.t, states(spc).Y, label=spc)
plt.legend(loc='upper right')
plt.xlabel('time [s]')
plt.ylabel('mass fraction')
plt.show()
12 changes: 6 additions & 6 deletions interfaces/cython/cantera/examples/reactors/piston.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@ def v(t):

net = ct.ReactorNet([r1, r2])

states1 = ct.SolutionArray(r1.thermo, extra=['t', 'v'])
states2 = ct.SolutionArray(r2.thermo, extra=['t', 'v'])
states1 = ct.SolutionArray(r1.thermo, extra=['t', 'volume'])
states2 = ct.SolutionArray(r2.thermo, extra=['t', 'volume'])

for n in range(200):
time = (n+1)*0.001
Expand All @@ -63,8 +63,8 @@ def v(t):
print(fmt.format(time, r1.T, r2.T, r1.volume, r2.volume,
r1.volume + r2.volume, r2.thermo['CO'].X[0]))

states1.append(r1.thermo.state, t=1000*time, v=r1.volume)
states2.append(r2.thermo.state, t=1000*time, v=r2.volume)
states1.append(r1.thermo.state, t=1000*time, volume=r1.volume)
states2.append(r2.thermo.state, t=1000*time, volume=r2.volume)

# plot the results if matplotlib is installed.
if '--plot' in sys.argv:
Expand All @@ -74,8 +74,8 @@ def v(t):
plt.xlabel('Time (ms)')
plt.ylabel('Temperature (K)')
plt.subplot(2, 2, 2)
plt.plot(states1.t, states1.v, '-', states2.t, states2.v, 'r-',
states1.t, states1.v + states2.v, 'g-')
plt.plot(states1.t, states1.volume, '-', states2.t, states2.volume, 'r-',
states1.t, states1.volume + states2.volume, 'g-')
plt.xlabel('Time (ms)')
plt.ylabel('Volume (m3)')
plt.subplot(2, 2, 3)
Expand Down
6 changes: 3 additions & 3 deletions interfaces/cython/cantera/examples/thermo/sound_speed.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import math


def equilSoundSpeeds(gas, rtol=1.0e-6, maxiter=5000):
def equilSoundSpeeds(gas, rtol=1.0e-6, max_iter=5000):
"""
Returns a tuple containing the equilibrium and frozen sound speeds for a
gas with an equilibrium composition. The gas is first set to an
Expand All @@ -17,7 +17,7 @@ def equilSoundSpeeds(gas, rtol=1.0e-6, maxiter=5000):
"""

# set the gas to equilibrium at its current T and P
gas.equilibrate('TP', rtol=rtol, maxiter=maxiter)
gas.equilibrate('TP', rtol=rtol, max_iter=max_iter)

# save properties
s0 = gas.s
Expand All @@ -35,7 +35,7 @@ def equilSoundSpeeds(gas, rtol=1.0e-6, maxiter=5000):
afrozen = math.sqrt((p1 - p0)/(gas.density - r0))

# now equilibrate the gas holding S and P constant
gas.equilibrate('SP', rtol=rtol, maxiter=maxiter)
gas.equilibrate('SP', rtol=rtol, max_iter=max_iter)

# equilibrium sound speed
aequil = math.sqrt((p1 - p0)/(gas.density - r0))
Expand Down