Skip to content

Commit

Permalink
[Examples] Add plots to Python 1D flame examples
Browse files Browse the repository at this point in the history
  • Loading branch information
speth committed Dec 1, 2024
1 parent 27b18f3 commit 400f481
Show file tree
Hide file tree
Showing 8 changed files with 347 additions and 11 deletions.
53 changes: 52 additions & 1 deletion samples/python/onedim/adiabatic_flame.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,15 @@
A freely-propagating, premixed hydrogen flat flame with multicomponent
transport properties.
Requires: cantera >= 3.0
Requires: cantera >= 3.0, matplotlib >= 2.0
.. tags:: Python, combustion, 1D flow, premixed flame, multicomponent transport,
saving output
"""

from pathlib import Path
import numpy as np
import matplotlib.pyplot as plt
import cantera as ct


Expand Down Expand Up @@ -57,3 +59,52 @@

# write the velocity, temperature, density, and mole fractions to a CSV file
f.save('adiabatic_flame.csv', basis="mole", overwrite=True)


# %%
# Temperature and Heat Release Rate
# ---------------------------------

# Find the region that covers most of the temperature rise
z = 1000 * f.grid # convert to mm
i_left = np.where(f.T > f.T[0] + 0.01 * (f.T[-1] - f.T[0]))[0][0]
i_right = np.where(f.T > f.T[0] + 0.95 * (f.T[-1] - f.T[0]))[0][0]
z_left = z[i_left]
z_right = z[i_right]
dz = z_right - z_left
z_left -= 0.3 * dz
z_right += 0.3 * dz

fig, ax1 = plt.subplots()
ax1.plot(z, f.heat_release_rate / 1e6, color='C4')
ax1.set_ylabel('heat release rate [MW/m³]', color='C4')
ax1.set(xlabel='flame coordinate [mm]', xlim=[z_left, z_right])

ax2 = ax1.twinx()
ax2.plot(z, f.T, color='C3')
ax2.set_ylabel('temperature [K]', color='C3')
plt.show()

# %%
# Major Species Profiles
# ----------------------
fig, ax = plt.subplots()
major = ('O2', 'H2', 'H2O')
states = f.to_array()
ax.plot(z, states(*major).X, label=major)
ax.set(xlabel='flame coordinate [mm]', ylabel='mole fractions')
ax.set_xlim(z_left, z_right)
ax.legend()
plt.show()

# %%
# Minor Species Profiles
# ----------------------
fig, ax = plt.subplots()
minor = ('OH', 'H', 'O')

ax.plot(z, states(*minor).X, label=minor, linestyle='--')
ax.set(xlabel='flame coordinate [mm]', ylabel='mole fractions')
ax.set_xlim(z_left, z_right)
ax.legend()
plt.show()
42 changes: 41 additions & 1 deletion samples/python/onedim/burner_flame.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,14 @@
A burner-stabilized lean premixed hydrogen-oxygen flame at low pressure.
Requires: cantera >= 3.0
Requires: cantera >= 3.0, matplotlib >= 2.0
.. tags:: Python, combustion, 1D flow, premixed flame, saving output,
multicomponent transport
"""

from pathlib import Path
import matplotlib.pyplot as plt
import cantera as ct

p = 0.05 * ct.one_atm
Expand Down Expand Up @@ -45,3 +46,42 @@
f.save(output, name="multi", description="solution with multicomponent transport")

f.save('burner_flame.csv', basis="mole", overwrite=True)

# %%
# Temperature and Heat Release Rate
# ---------------------------------
fig, ax1 = plt.subplots()

ax1.plot(f.grid, f.heat_release_rate / 1e6, color='C4')
ax1.set_ylabel('heat release rate [MW/m³]', color='C4')
ax1.set_xlim(0, 0.2)
ax1.set(xlabel='distance from burner [m]')

ax2 = ax1.twinx()
ax2.plot(f.grid, f.T, color='C3')
ax2.set_ylabel('temperature [K]', color='C3')
plt.show()

# %%
# Major Species Profiles
# ----------------------
fig, ax = plt.subplots()
major = ('O2', 'H2', 'H2O')
states = f.to_array()
ax.plot(states.grid, states(*major).X, label=major)
ax.set(xlabel='distance from burner [m]', ylabel='mole fractions')
ax.set_xlim(0, 0.2)
ax.legend()
plt.show()

# %%
# Minor Species Profiles
# ----------------------
fig, ax = plt.subplots()
minor = ('OH', 'H', 'O')

ax.plot(states.grid, states(*minor).X, label=minor, linestyle='--')
ax.set(xlabel='distance from burner [m]', ylabel='mole fractions', )
ax.set_xlim(0, 0.2)
ax.legend()
plt.show()
26 changes: 24 additions & 2 deletions samples/python/onedim/catalytic_combustion.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,13 @@
The catalytic combustion mechanism is from Deutschmann et al., 26th
Symp. (Intl.) on Combustion,1996 pp. 1747-1754
Requires: cantera >= 3.0
Requires: cantera >= 3.0, matplotlib >= 2.0
.. tags:: Python, catalysis, combustion, 1D flow, surface chemistry
"""

import numpy as np
import matplotlib.pyplot as plt
import cantera as ct

# %%
Expand Down Expand Up @@ -131,9 +132,30 @@
filename = "catalytic_combustion.h5"
else:
filename = "catalytic_combustion.yaml"
sim.save(filename, "soln1", description="catalytic combustion example")
sim.save(filename, "soln1", description="catalytic combustion example",
overwrite=True)

# save selected solution components in a CSV file for plotting in Excel or MATLAB.
sim.save('catalytic_combustion.csv', basis="mole", overwrite=True)

sim.show_stats(0)

# %%
# Temperature Profile
# -------------------
fig, ax = plt.subplots()
ax.plot(sim.grid, sim.T, color='C3')
ax.set_ylabel('heat release rate [MW/m³]')
ax.set(xlabel='distance from inlet [m]')
plt.show()

# %%
# Major Species Profiles
# ----------------------
fig, ax = plt.subplots()
major = ('O2', 'CH4', 'H2O', 'CO2')
states = sim.to_array()
ax.plot(states.grid, states(*major).X, label=major)
ax.set(xlabel='distance from inlet [m]', ylabel='mole fractions')
ax.legend()
plt.show()
42 changes: 41 additions & 1 deletion samples/python/onedim/flame_fixed_T.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,15 @@
A burner-stabilized, premixed methane/air flat flame with multicomponent
transport properties and a specified temperature profile.
Requires: cantera >= 3.0
Requires: cantera >= 3.0, matplotlib >= 2.0
.. tags:: Python, combustion, 1D flow, burner-stabilized flame, premixed flame, plotting,
saving output
"""

from pathlib import Path
import numpy as np
import matplotlib.pyplot as plt
import cantera as ct


Expand Down Expand Up @@ -116,3 +117,42 @@
# write the velocity, temperature, density, and mole fractions to a CSV file
f.save('flame_fixed_T.csv', basis="mole", overwrite=True)
f.show_stats()

# %%
# Temperature and Heat Release Rate
# ---------------------------------
fig, ax1 = plt.subplots()

ax1.plot(f.grid, f.heat_release_rate / 1e6, color='C4')
ax1.set_ylabel('heat release rate [MW/m³]', color='C4')
ax1.set_xlim(0, 0.01)
ax1.set(xlabel='distance from burner [m]')

ax2 = ax1.twinx()
ax2.plot(f.grid, f.T, color='C3')
ax2.set_ylabel('temperature [K]', color='C3')
plt.show()

# %%
# Major Species Profiles
# ----------------------
fig, ax = plt.subplots()
major = ('O2', 'H2', 'H2O')
states = f.to_array()
ax.plot(states.grid, states(*major).X, label=major)
ax.set(xlabel='distance from burner [m]', ylabel='mole fractions')
ax.set_xlim(0, 0.01)
ax.legend()
plt.show()

# %%
# Minor Species Profiles
# ----------------------
fig, ax = plt.subplots()
minor = ('OH', 'H', 'O')

ax.plot(states.grid, states(*minor).X, label=minor, linestyle='--')
ax.set(xlabel='distance from burner [m]', ylabel='mole fractions', )
ax.set_xlim(0, 0.01)
ax.legend()
plt.show()
45 changes: 43 additions & 2 deletions samples/python/onedim/ion_burner_flame.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@
A burner-stabilized premixed methane-air flame with charged species.
Requires: cantera >= 3.0
Requires: cantera >= 3.0, matplotlib >= 2.0
.. tags:: Python, combustion, 1D flow, burner-stabilized flame, plasma, premixed flame
"""

from pathlib import Path
import matplotlib.pyplot as plt
import cantera as ct


p = ct.one_atm
tburner = 600.0
reactants = 'CH4:1.0, O2:2.0, N2:7.52' # premixed gas composition
Expand Down Expand Up @@ -40,3 +40,44 @@
f.save(output, name="mix", description="solution with mixture-averaged transport")

f.save('ion_burner_flame.csv', basis="mole", overwrite=True)

# %%
# Temperature and Heat Release Rate
# ---------------------------------
fig, ax1 = plt.subplots()

ax1.plot(f.grid * 1000, f.heat_release_rate / 1e6, color='C4')
ax1.set_ylabel('heat release rate [MW/m³]', color='C4')
ax1.set_xlim(0, 3.0)
ax1.set(xlabel='distance from burner [mm]')

ax2 = ax1.twinx()
ax2.plot(f.grid * 1000, f.T, color='C3')
ax2.set_ylabel('temperature [K]', color='C3')
plt.show()

# %%
# Major Species Profiles
# ----------------------
fig, ax = plt.subplots()
major = ('O2', 'CH4', 'H2O', 'CO2')
states = f.to_array()
ax.plot(states.grid * 1000, states(*major).X, label=major)
ax.set(xlabel='distance from burner [mm]', ylabel='mole fractions')
ax.set_xlim(0, 3.0)
ax.legend()
plt.show()

#sphinx_gallery_thumbnail_number = 2

# %%
# Ionized Species Profiles
# ------------------------
fig, ax = plt.subplots()
minor = ('E', 'H3O+', 'HCO+')

ax.semilogy(states.grid * 1000, states(*minor).X, label=minor, linestyle='--')
ax.set(xlabel='distance from burner [mm]', ylabel='mole fractions', )
ax.set_xlim(0, 3.0)
ax.legend()
plt.show()
54 changes: 53 additions & 1 deletion samples/python/onedim/ion_free_flame.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,14 @@
A freely-propagating, premixed methane-air flat flame with charged species.
Requires: cantera >= 3.0
Requires: cantera >= 3.0, matplotlib >= 2.0
.. tags:: Python, combustion, 1D flow, burner-stabilized flame, plasma, premixed flame
"""

from pathlib import Path
import numpy as np
import matplotlib.pyplot as plt
import cantera as ct


Expand Down Expand Up @@ -49,3 +51,53 @@

# write the velocity, temperature, density, and mole fractions to a CSV file
f.save('ion_free_flame.csv', basis="mole", overwrite=True)

# %%
# Temperature and Heat Release Rate
# ---------------------------------

# Find the region that covers most of the temperature rise
z = 1000 * f.grid # convert to mm
i_left = np.where(f.T > f.T[0] + 0.01 * (f.T[-1] - f.T[0]))[0][0]
i_right = np.where(f.T > f.T[0] + 0.95 * (f.T[-1] - f.T[0]))[0][0]
z_left = z[i_left]
z_right = z[i_right]
dz = z_right - z_left
z_left -= 0.3 * dz
z_right += 0.3 * dz

fig, ax1 = plt.subplots()
ax1.plot(z, f.heat_release_rate / 1e6, color='C4')
ax1.set_ylabel('heat release rate [MW/m³]', color='C4')
ax1.set(xlabel='flame coordinate [mm]', xlim=[z_left, z_right])

ax2 = ax1.twinx()
ax2.plot(z, f.T, color='C3')
ax2.set_ylabel('temperature [K]', color='C3')
plt.show()

# %%
# Major Species Profiles
# ----------------------
fig, ax = plt.subplots()
major = ('O2', 'CH4', 'H2O', 'CO2')
states = f.to_array()
ax.plot(z, states(*major).X, label=major)
ax.set(xlabel='flame coordinate [mm]', ylabel='mole fractions')
ax.set_xlim(z_left, z_right)
ax.legend()
plt.show()

# %%
# Minor / Ionized Species Profiles
# --------------------------------
fig, ax = plt.subplots()
minor = ('OH', 'H', 'O', 'E', 'HCO+', 'H3O+')

ax.semilogy(z, states(*minor).X, label=minor, linestyle='--')
ax.set(xlabel='flame coordinate [mm]', ylabel='mole fractions')
ax.set_xlim(z_left, z_right)
ax.legend()
plt.show()

#sphinx_gallery_thumbnail_number = -1
Loading

0 comments on commit 400f481

Please sign in to comment.