diff --git a/samples/python/onedim/adiabatic_flame.py b/samples/python/onedim/adiabatic_flame.py index 72e59856c6..9bc76332b9 100644 --- a/samples/python/onedim/adiabatic_flame.py +++ b/samples/python/onedim/adiabatic_flame.py @@ -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 @@ -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() diff --git a/samples/python/onedim/burner_flame.py b/samples/python/onedim/burner_flame.py index 99600b4201..4c2ae6c580 100644 --- a/samples/python/onedim/burner_flame.py +++ b/samples/python/onedim/burner_flame.py @@ -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 @@ -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() diff --git a/samples/python/onedim/catalytic_combustion.py b/samples/python/onedim/catalytic_combustion.py index 3b13f90fa3..56ab4bfdaa 100644 --- a/samples/python/onedim/catalytic_combustion.py +++ b/samples/python/onedim/catalytic_combustion.py @@ -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 # %% @@ -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() diff --git a/samples/python/onedim/flame_fixed_T.py b/samples/python/onedim/flame_fixed_T.py index b37c2a5486..a3123e75ff 100644 --- a/samples/python/onedim/flame_fixed_T.py +++ b/samples/python/onedim/flame_fixed_T.py @@ -5,7 +5,7 @@ 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 @@ -13,6 +13,7 @@ from pathlib import Path import numpy as np +import matplotlib.pyplot as plt import cantera as ct @@ -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() diff --git a/samples/python/onedim/ion_burner_flame.py b/samples/python/onedim/ion_burner_flame.py index 418628691e..abfeb2a1b3 100644 --- a/samples/python/onedim/ion_burner_flame.py +++ b/samples/python/onedim/ion_burner_flame.py @@ -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 @@ -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() diff --git a/samples/python/onedim/ion_free_flame.py b/samples/python/onedim/ion_free_flame.py index 3d33ce2c2e..4081edc2e8 100644 --- a/samples/python/onedim/ion_free_flame.py +++ b/samples/python/onedim/ion_free_flame.py @@ -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 @@ -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 diff --git a/samples/python/onedim/premixed_counterflow_flame.py b/samples/python/onedim/premixed_counterflow_flame.py index d2d67078a6..e8e5442c60 100644 --- a/samples/python/onedim/premixed_counterflow_flame.py +++ b/samples/python/onedim/premixed_counterflow_flame.py @@ -5,15 +5,15 @@ This script simulates a lean hydrogen-oxygen flame stabilized in a strained flowfield, with an opposed flow consisting of equilibrium products. -Requires: cantera >= 3.0 +Requires: cantera >= 3.0, matplotlib >= 2.0 .. tags:: Python, combustion, 1D flow, premixed flame, strained flame """ from pathlib import Path +import matplotlib.pyplot as plt import cantera as ct - # parameter values p = 0.05 * ct.one_atm # pressure T_in = 373.0 # inlet temperature @@ -58,3 +58,38 @@ sim.save("premixed_counterflow_flame.csv", basis="mole", overwrite=True) sim.show_stats() sim.show() + +# %% +# Temperature and Heat Release Rate +# --------------------------------- +fig, ax1 = plt.subplots() + +ax1.plot(sim.grid, sim.heat_release_rate / 1e6, color='C4') +ax1.set_ylabel('heat release rate [MW/m³]', color='C4') +ax1.set(xlabel='flame coordinate [m]') + +ax2 = ax1.twinx() +ax2.plot(sim.grid, sim.T, color='C3') +ax2.set_ylabel('temperature [K]', color='C3') +plt.show() + +# %% +# Major Species Profiles +# ---------------------- +fig, ax = plt.subplots() +major = ('O2', 'H2', 'H2O') +states = sim.to_array() +ax.plot(states.grid, states(*major).X, label=major) +ax.set(xlabel='flame coordinate [m]', ylabel='mole fractions') +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='flame coordinate [m]', ylabel='mole fractions', ) +ax.legend() +plt.show() diff --git a/samples/python/onedim/stagnation_flame.py b/samples/python/onedim/stagnation_flame.py index a3707227bf..0a1bf087bd 100644 --- a/samples/python/onedim/stagnation_flame.py +++ b/samples/python/onedim/stagnation_flame.py @@ -15,12 +15,13 @@ points would be concentrated upstream of the flame, where the flamefront had been previously. (To see this, try setting prune to zero.) -Requires: cantera >= 3.0 +Requires: cantera >= 3.0, matplotlib >= 2.0 .. tags:: Python, combustion, 1D flow, premixed flame, strained flame """ from pathlib import Path +import matplotlib.pyplot as plt import cantera as ct # %% @@ -87,12 +88,66 @@ output = output_path / "stagnation_flame.yaml" output.unlink(missing_ok=True) +results = [] for m, md in enumerate(mdot): sim.inlet.mdot = md sim.solve(loglevel) + results.append(sim.to_array()) sim.save(output, name=f"mdot-{m}", description=f"mdot = {md} kg/m2/s") # write the velocity, temperature, and mole fractions to a CSV file sim.save(output_path / f"stagnation_flame_{m}.csv", basis="mole", overwrite=True) sim.show_stats() + +# %% +# Temperature and Heat Release Rate +# --------------------------------- +fig, ax1 = plt.subplots() +ax2 = ax1.twinx() +styles = ['-', '--'] +for n, i in enumerate([1, -1]): + ax1.plot(results[i].grid, results[i].heat_release_rate / 1e6, + linestyle=styles[n], color='C4', label=rf'$\dot m = {mdot[i]:.2f}$ kg/s') + ax2.plot(results[i].grid, results[i].T, + linestyle=styles[n], color='C3', label=rf'$\dot m = {mdot[i]:.2f}$ kg/s') + +ax1.set_ylabel('heat release rate [MW/m³]', color='C4') +ax1.set(xlabel='distance from inlet [m]') +ax2.set_ylabel('temperature [K]', color='C3') +ax2.legend() +plt.show() + +# %% +# Major Species Profiles +# ---------------------- +fig, ax = plt.subplots() +major = ('O2', 'H2', 'H2O') +states = sim.to_array() +handles = [] +for n, i in enumerate([1, -1]): + for k, spec in enumerate(major): + h = ax.plot(results[i].grid, results[i](spec).X, + linestyle=styles[n], color=f'C{k}', + label=rf'{spec}, $\dot m = {mdot[i]}$ kg/s') + +ax.set(xlabel='distance from inlet [m]', ylabel='mole fractions') +ax.legend() +plt.show() + +# %% +# Minor Species Profiles +# ---------------------- +fig, ax = plt.subplots() +minor = ('OH', 'H', 'O') +states = sim.to_array() +handles = [] +for n, i in enumerate([1, -1]): + for k, spec in enumerate(minor): + h = ax.plot(results[i].grid, results[i](spec).X, + linestyle=styles[n], color=f'C{k+5}', + label=rf'{spec}, $\dot m = {mdot[i]}$ kg/s') + +ax.set(xlabel='distance from inlet [m]', ylabel='mole fractions') +ax.legend() +plt.show()