[Cython] Added write_csv method to FlameBase

This commit is contained in:
Ray Speth 2013-02-01 23:40:31 +00:00
parent 16f69f3738
commit 430e28e413
4 changed files with 35 additions and 43 deletions

View file

@ -3,7 +3,6 @@ A freely-propagating, premixed hydrogen flat flame with multicomponent
transport properties.
"""
import csv
import cantera as ct
# Simulation parameters
@ -58,15 +57,4 @@ f.save('h2_adiabatic.xml','energy_multi',
'solution with multicomponent transport')
# write the velocity, temperature, density, and mole fractions to a CSV file
z = f.flame.grid
T = f.T
u = f.u
V = f.V
with open('h2_adiabatic.csv', 'w') as csvfile:
writer = csv.writer(csvfile)
writer.writerow(['z (m)', 'u (m/s)', 'V (1/s)', 'T (K)', 'rho (kg/m3)'] +
list(gas.species_names))
for n in range(f.flame.n_points):
f.set_gas_state(n)
writer.writerow([z[n], u[n], V[n], T[n], gas.density] + list(gas.X))
f.write_csv('h2_adiabatic.csv', quiet=False)

View file

@ -3,7 +3,6 @@ A burner-stabilized lean premixed hydrogen-oxygen flame at low pressure.
"""
import cantera as ct
import csv
p = 0.05 * ct.one_atm
tburner = 373.0
@ -52,17 +51,4 @@ print('multicomponent flamespeed = ', f.u[0])
f.save('h2_burner_flame.xml','energy_multi',
'solution with the energy equation enabled and multicomponent transport')
z = f.flame.grid
T = f.T
u = f.u
V = f.V
with open('h2_burner_flame.csv', 'w') as csvfile:
writer = csv.writer(csvfile)
writer.writerow(['z (m)', 'u (m/s)', 'V (1/s)', 'T (K)', 'rho (kg/m3)'] +
list(gas.species_names))
for n in range(f.flame.n_points):
f.set_gas_state(n)
writer.writerow([z[n], u[n], V[n], T[n], gas.density] + list(gas.X))
print('solution saved to h2_burner_flame.csv')
f.write_csv('h2_burner_flame.csv', quiet=False)

View file

@ -4,7 +4,6 @@ An opposed-flow ethane/air diffusion flame
import cantera as ct
import numpy as np
import csv
# Input parameters
p = ct.one_atm # pressure
@ -68,20 +67,7 @@ f.solve(loglevel, refine_grid=refine_grid)
f.show_solution()
f.save('c2h6_diffusion.xml')
z = f.flame.grid
T = f.T
u = f.u
V = f.V
# write the velocity, temperature, and mole fractions to a CSV file
with open('c2h6_diffusion.csv', 'w') as csvfile:
writer = csv.writer(csvfile)
writer.writerow(['z (m)', 'u (m/s)', 'V (1/s)', 'T (K)', 'rho (kg/m3)'] +
list(gas.species_names))
for n in range(f.flame.n_points):
f.set_gas_state(n)
writer.writerow([z[n], u[n], V[n], T[n], gas.density] + list(gas.X))
print('solution saved to c2h6_diffusion.csv')
f.write_csv('c2h6_diffusion.csv', quiet=False)
f.show_stats(0)

View file

@ -1,3 +1,5 @@
import csv
cdef class Domain1D:
cdef CxxDomain1D* domain
def __cinit__(self, *args, **kwargs):
@ -831,6 +833,36 @@ class FlameBase(Sim1D):
for k in range(k0, k0 + self.gas.n_species)]
self.gas.TPY = self.value(self.flame, 'T', point), self.P, Y
def write_csv(self, filename, species='X', quiet=True):
"""
Write the velocity, temperature, density, and species profiles
to a CSV file.
:param filename:
Output file name
:param species:
Attribute to use obtaining species profiles, e.g. ``X`` for
mole fractions or ``Y`` for mass fractions.
"""
z = self.grid
T = self.T
u = self.u
V = self.V
csvfile = open(filename, 'w')
writer = csv.writer(csvfile)
writer.writerow(['z (m)', 'u (m/s)', 'V (1/s)',
'T (K)', 'rho (kg/m3)'] + self.gas.species_names)
for n in range(self.flame.n_points):
self.set_gas_state(n)
writer.writerow([z[n], u[n], V[n], T[n], self.gas.density] +
list(getattr(self.gas, species)))
csvfile.close()
if not quiet:
print("Solution saved to '{}'.".format(filename))
def _trim(docstring):
"""Remove block indentation from a docstring."""
if not docstring: