From b58ba638be5da56715be4eca09663e55a6aea5dc Mon Sep 17 00:00:00 2001 From: Ray Speth Date: Thu, 12 Apr 2012 21:35:36 +0000 Subject: [PATCH] Added some tests for the equilibrium solvers --- test/python/runTests.py | 4 ++ test/python/testEquilibrium.py | 80 ++++++++++++++++++++++++++++++++++ 2 files changed, 84 insertions(+) create mode 100644 test/python/testEquilibrium.py diff --git a/test/python/runTests.py b/test/python/runTests.py index 7dc9fa361..377c955a6 100644 --- a/test/python/runTests.py +++ b/test/python/runTests.py @@ -5,10 +5,13 @@ This script gathers all the tests defined in all of the test.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) diff --git a/test/python/testEquilibrium.py b/test/python/testEquilibrium.py new file mode 100644 index 000000000..42bb46369 --- /dev/null +++ b/test/python/testEquilibrium.py @@ -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)