[Python/1D] Fix FlameBase.write_csv

Also add a test for this method
This commit is contained in:
Ray Speth 2015-07-08 23:57:22 -04:00
parent d44f46aab8
commit 7d36e1eb13
2 changed files with 15 additions and 1 deletions

View file

@ -1,5 +1,6 @@
import numpy as np
from ._cantera import *
import csv as _csv
try:
# Python 2.7 or 3.2+
@ -265,7 +266,7 @@ class FlameBase(Sim1D):
V = self.V
csvfile = open(filename, 'w')
writer = csv.writer(csvfile)
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):

View file

@ -353,6 +353,19 @@ class TestFreeFlame(utilities.CanteraTest):
k1 = gas1.species_index(species)
self.assertArrayNear(Y1[k1], Y2[k2])
def test_write_csv(self):
filename = 'onedim-write_csv{0}.csv'.format(utilities.python_version)
if os.path.exists(filename):
os.remove(filename)
self.create_sim(2e5, 350, 'H2:1.0, O2:2.0', mech='h2o2.xml')
self.sim.write_csv(filename)
data = np.genfromtxt(filename, delimiter=',', skiprows=1)
self.assertArrayNear(data[:,0], self.sim.grid)
self.assertArrayNear(data[:,3], self.sim.T)
k = self.gas.species_index('H2')
self.assertArrayNear(data[:,5+k], self.sim.X[k,:])
def test_refine_criteria_boundscheck(self):
self.create_sim(ct.one_atm, 300.0, 'H2:1.1, O2:1, AR:5')
good = [3.0, 0.1, 0.2, 0.05]