Added some tests for the equilibrium solvers

This commit is contained in:
Ray Speth 2012-04-12 21:35:36 +00:00
parent e99bd87586
commit b58ba638be
2 changed files with 84 additions and 0 deletions

View file

@ -5,10 +5,13 @@ This script gathers all the tests defined in all of the test<foo>.py
files, runs them, and prints a report.
"""
import sys
import os
import unittest
import Cantera
Cantera.addDirectory(os.path.join(os.path.split(os.getcwd())[0], 'data'))
if __name__ == '__main__':
print '\n* INFO: using Cantera module found at this location:'
print '* ', repr(Cantera.__file__), '\n'
@ -17,6 +20,7 @@ if __name__ == '__main__':
loader = unittest.TestLoader()
runner = unittest.TextTestRunner(verbosity=2)
suite = loader.loadTestsFromName('testSolution')
suite.addTests(loader.loadTestsFromName('testEquilibrium'))
suite.addTests(loader.loadTestsFromName('testReactors'))
results = runner.run(suite)

View file

@ -0,0 +1,80 @@
from __future__ import division
import unittest
import numpy as np
import Cantera as ct
class EquilTestCases(object):
def __init__(self, solver):
self.solver = solver
"""
Test the ChemEquil equilibrium solver
"""
def check(self, gas, **moles):
nTotal = sum(moles.values())
for name,X in moles.iteritems():
self.assertAlmostEqual(gas.moleFraction(name), X/nTotal)
def test_equil_complete_stoichiometric(self):
"""
Equilibrium should correspond to complete combustion
"""
gas = ct.importPhase('equilibrium.cti', 'complete')
gas.set(X='CH4:1.0, O2:2.0', T=298, P=100000)
gas.equilibrate('TP', self.solver)
self.check(gas, CH4=0, O2=0, H2O=2, CO2=1)
def test_equil_complete_lean(self):
"""
Equilibrium should correspond to complete combustion (with excess O2)
CH4 + 3 O2 -> CO2 + 2 H2O + O2
"""
gas = ct.importPhase('equilibrium.cti', 'complete')
gas.set(X='CH4:1.0, O2:3.0', T=298, P=100000)
gas.equilibrate('TP', self.solver)
self.check(gas, CH4=0, O2=1, H2O=2, CO2=1)
def test_equil_incomplete_stoichiometric(self):
gas = ct.importPhase('equilibrium.cti', 'incomplete')
gas.set(X='CH4:1.0, O2:2.0', T=301, P=100000)
gas.equilibrate('TP', self.solver)
self.check(gas, CH4=0, O2=0, H2O=2, CO2=1)
def test_equil_incomplete_lean(self):
gas = ct.importPhase('equilibrium.cti', 'incomplete')
gas.set(X='CH4:1.0, O2:3.0', T=301, P=100000)
gas.equilibrate('TP', self.solver)
self.check(gas, CH4=0, O2=1, H2O=2, CO2=1)
def test_equil_gri_stoichiometric(self):
gas = ct.importPhase('gri30.xml')
gas.set(X='CH4:1.0, O2:2.0', T=301, P=100000)
gas.equilibrate('TP', self.solver)
self.check(gas, CH4=0, O2=0, H2O=2, CO2=1)
def test_equil_gri_lean(self):
gas = ct.importPhase('gri30.xml')
gas.set(X='CH4:1.0, O2:3.0', T=301, P=100000)
gas.equilibrate('TP', self.solver)
self.check(gas, CH4=0, O2=1, H2O=2, CO2=1)
class ChemEquilTest(EquilTestCases, unittest.TestCase):
def __init__(self, *args, **kwargs):
EquilTestCases.__init__(self, 0)
unittest.TestCase.__init__(self, *args, **kwargs)
class MultiphaseEquilTest(EquilTestCases, unittest.TestCase):
def __init__(self, *args, **kwargs):
EquilTestCases.__init__(self, 1)
unittest.TestCase.__init__(self, *args, **kwargs)
class VCS_EquilTest(EquilTestCases, unittest.TestCase):
def __init__(self, *args, **kwargs):
EquilTestCases.__init__(self, 2)
unittest.TestCase.__init__(self, *args, **kwargs)