[Cython] Move equilibrium tests from old Python module to Cython module
This commit is contained in:
parent
6ec7d04839
commit
59564659b3
3 changed files with 28 additions and 30 deletions
|
|
@ -5,6 +5,7 @@ cantera.add_directory(os.path.join(os.path.dirname(__file__), 'data'))
|
|||
|
||||
from .test_thermo import *
|
||||
from .test_purefluid import *
|
||||
from .test_equilibrium import *
|
||||
from .test_kinetics import *
|
||||
from .test_transport import *
|
||||
from .test_mixture import *
|
||||
|
|
|
|||
|
|
@ -4,26 +4,24 @@ import unittest
|
|||
|
||||
import numpy as np
|
||||
|
||||
import Cantera as ct
|
||||
import cantera as ct
|
||||
from . import utilities
|
||||
|
||||
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)
|
||||
for name,X in moles.items():
|
||||
self.assertAlmostEqual(gas[name].X[0], 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 = ct.Solution('equilibrium.cti', 'complete')
|
||||
gas.TPX = 298, 100000, 'CH4:1.0, O2:2.0'
|
||||
gas.equilibrate('TP', self.solver)
|
||||
self.check(gas, CH4=0, O2=0, H2O=2, CO2=1)
|
||||
|
||||
|
|
@ -32,61 +30,61 @@ class EquilTestCases(object):
|
|||
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 = ct.Solution('equilibrium.cti', 'complete')
|
||||
gas.TPX = 298, 100000, 'CH4:1.0, O2:3.0'
|
||||
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 = ct.Solution('equilibrium.cti', 'incomplete')
|
||||
gas.TPX = 301, 100000, 'CH4:1.0, O2:2.0'
|
||||
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 = ct.Solution('equilibrium.cti', 'incomplete')
|
||||
gas.TPX = 301, 100000, 'CH4:1.0, O2:3.0'
|
||||
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 = ct.Solution('gri30.xml')
|
||||
gas.TPX = 301, 100000, 'CH4:1.0, O2:2.0'
|
||||
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 = ct.Solution('gri30.xml')
|
||||
gas.TPX = 301, 100000, 'CH4:1.0, O2:3.0'
|
||||
gas.equilibrate('TP', self.solver)
|
||||
self.check(gas, CH4=0, O2=1, H2O=2, CO2=1)
|
||||
|
||||
def test_equil_overconstrained1(self):
|
||||
gas = ct.importPhase('equilibrium.cti', 'overconstrained-1')
|
||||
gas.set(X='CH4:1.0, O2:1.0', T=301, P=100000)
|
||||
gas = ct.Solution('equilibrium.cti', 'overconstrained-1')
|
||||
gas.TPX = 301, 100000, 'CH4:1.0, O2:1.0'
|
||||
gas.equilibrate('TP', self.solver)
|
||||
self.check(gas, CH4=1, O2=1)
|
||||
|
||||
def test_equil_overconstrained2(self):
|
||||
gas = ct.importPhase('equilibrium.cti', 'overconstrained-2')
|
||||
gas.set(X='CH4:1.0, O2:1.0', T=301, P=100000)
|
||||
gas = ct.Solution('equilibrium.cti', 'overconstrained-2')
|
||||
gas.TPX = 301, 100000, 'CH4:1.0, O2:1.0'
|
||||
gas.equilibrate('TP', self.solver)
|
||||
self.check(gas, CH4=1, O2=1)
|
||||
|
||||
|
||||
class ChemEquilTest(EquilTestCases, unittest.TestCase):
|
||||
class ChemEquilTest(EquilTestCases, utilities.CanteraTest):
|
||||
def __init__(self, *args, **kwargs):
|
||||
EquilTestCases.__init__(self, 0)
|
||||
EquilTestCases.__init__(self, 'element_potential')
|
||||
unittest.TestCase.__init__(self, *args, **kwargs)
|
||||
|
||||
|
||||
class MultiphaseEquilTest(EquilTestCases, unittest.TestCase):
|
||||
class MultiphaseEquilTest(EquilTestCases, utilities.CanteraTest):
|
||||
def __init__(self, *args, **kwargs):
|
||||
EquilTestCases.__init__(self, 1)
|
||||
EquilTestCases.__init__(self, 'gibbs')
|
||||
unittest.TestCase.__init__(self, *args, **kwargs)
|
||||
|
||||
|
||||
class VCS_EquilTest(EquilTestCases, unittest.TestCase):
|
||||
class VCS_EquilTest(EquilTestCases, utilities.CanteraTest):
|
||||
def __init__(self, *args, **kwargs):
|
||||
EquilTestCases.__init__(self, 2)
|
||||
EquilTestCases.__init__(self, 'vcs')
|
||||
unittest.TestCase.__init__(self, *args, **kwargs)
|
||||
|
|
@ -21,8 +21,7 @@ if __name__ == '__main__':
|
|||
|
||||
loader = unittest.TestLoader()
|
||||
runner = unittest.TextTestRunner(verbosity=2)
|
||||
suite = loader.loadTestsFromName('testEquilibrium')
|
||||
suite.addTests(loader.loadTestsFromName('testReactors'))
|
||||
suite = loader.loadTestsFromName('testReactors')
|
||||
suite.addTests(loader.loadTestsFromName('testConvert'))
|
||||
|
||||
results = runner.run(suite)
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue