Skip to content

Commit

Permalink
[examples] Add plots to 1D ionized gas examples
Browse files Browse the repository at this point in the history
  • Loading branch information
ischoegl authored and Ingmar Schoegl committed Aug 20, 2020
1 parent 1c9e266 commit 309429d
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 10 deletions.
38 changes: 32 additions & 6 deletions interfaces/cython/cantera/examples/onedim/ion_burner_flame.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
"""
A burner-stabilized premixed methane-air flame with charged species.
Requires: cantera >= 2.5.0
Requires: cantera >= 2.5.0, matplotlib >= 2.0
"""

import sys
import cantera as ct

p = ct.one_atm
Expand All @@ -21,14 +22,39 @@
f.set_refine_criteria(ratio=3.0, slope=0.05, curve=0.1)
f.show_solution()

f.transport_model = 'Ion'
f.solve(loglevel, auto=True)
f.solve(loglevel=loglevel, stage=2, enable_energy=True)
try:
# save to HDF container file if h5py is installed
f.write_hdf('ion_burner_flame.h5', group='ion', mode='w',
description='solution with ionized gas transport')
f.write_hdf('ion_burner_flame.h5', group='frozenIon', mode='w',
description='solution with ionized gas transport - stage 1')
except ImportError:
pass

f.solve(loglevel=loglevel, stage=2, enable_energy=True)
try:
f.write_hdf('ion_burner_flame.h5', group='ion',
description='solution with ionized gas transport - stage 2')
except ImportError:
f.save('ion_burner_flame.xml', 'mix', 'solution with mixture-averaged transport')
f.save('ion_burner_flame.xml', 'mix', 'solution with ionized gas transport')

f.write_csv('ion_burner_flame.csv', quiet=False)

if '--plot' in sys.argv:
import matplotlib.pyplot as plt

arr = f.to_solution_array()

fig, (ax1, ax2, ax3) = plt.subplots(3, 1, sharex=True)
ax1.plot(f.grid, f.heat_release_rate)
ax1.set_ylabel(r'$\dot{q}$ [W/m${^3}$]')
for s in ['H3O+', 'HCO+', 'E']:
ax2.plot(f.grid, arr(s).X, label=s)
ax2.legend()
ax2.set_ylabel('X [-]')
ax3.plot(f.grid, f.E)
ax3.set_xlabel('Distance from burner [m]')
ax3.set_ylabel('E [V/m]')
ax3.set_xlim([0, .005])

fig.tight_layout()
plt.show()
34 changes: 30 additions & 4 deletions interfaces/cython/cantera/examples/onedim/ion_free_flame.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
"""
A freely-propagating, premixed methane-air flat flame with charged species.
Requires: cantera >= 2.5.0
Requires: cantera >= 2.5.0, matplotlib >= 2.0
"""

import sys
import cantera as ct

# Simulation parameters
Expand All @@ -25,14 +26,19 @@

# stage one
f.solve(loglevel=loglevel, auto=True)
try:
# save to HDF container file if h5py is installed
f.write_hdf('ion_free_flame.h5', group='frozenIon', mode='w',
description='solution with ionized gas transport - stage 1')
except ImportError:
pass

# stage two
f.solve(loglevel=loglevel, stage=2, enable_energy=True)

try:
# save to HDF container file if h5py is installed
f.write_hdf('ion_free_flame.h5', group='ion', mode='w',
description='solution with ionized gas transport')
f.write_hdf('ion_free_flame.h5', group='ion',
description='solution with ionized gas transport - stage 2')
except ImportError:
f.save('ion_free_flame.xml', 'ion', 'solution with ionized gas transport')

Expand All @@ -41,3 +47,23 @@

# write the velocity, temperature, density, and mole fractions to a CSV file
f.write_csv('ion_free_flame.csv', quiet=False)

if '--plot' in sys.argv:
import matplotlib.pyplot as plt

arr = f.to_solution_array()

fig, (ax1, ax2, ax3) = plt.subplots(3, 1, sharex=True)
ax1.plot(f.grid, f.heat_release_rate)
ax1.set_ylabel(r'$\dot{q}$ [W/m${^3}$]')
for s in ['H3O+', 'HCO+', 'E']:
ax2.plot(f.grid, arr(s).X, label=s)
ax2.legend()
ax2.set_ylabel('X [-]')
ax3.plot(f.grid, f.E)
ax3.set_xlabel('Axial location [m]')
ax3.set_ylabel('E [V/m]')
ax3.set_xlim([.016, .022])

fig.tight_layout()
plt.show()

0 comments on commit 309429d

Please sign in to comment.