Added more tests for the new Python module
This commit is contained in:
parent
c7570dc6c9
commit
4bd19494a6
5 changed files with 95 additions and 0 deletions
|
|
@ -2,3 +2,6 @@ from .test_thermo import *
|
|||
from .test_kinetics import *
|
||||
from .test_transport import *
|
||||
from .test_mixture import *
|
||||
from .test_func1 import *
|
||||
from .test_reactor import *
|
||||
from .test_onedim import *
|
||||
|
|
|
|||
12
interfaces/cython/cantera/test/test_func1.py
Normal file
12
interfaces/cython/cantera/test/test_func1.py
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
import unittest
|
||||
import numpy as np
|
||||
|
||||
import cantera as ct
|
||||
from . import utilities
|
||||
|
||||
class TestFunc1(utilities.CanteraTest):
|
||||
def test_sin(self):
|
||||
f = ct.Sin1(3)
|
||||
self.assertNear(f(0), np.sin(0))
|
||||
self.assertNear(f(0.1), np.sin(3*0.1))
|
||||
self.assertNear(f(0.7), np.sin(3*0.7))
|
||||
22
interfaces/cython/cantera/test/test_onedim.py
Normal file
22
interfaces/cython/cantera/test/test_onedim.py
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
import cantera as ct
|
||||
from . import utilities
|
||||
|
||||
class TestOnedim(utilities.CanteraTest):
|
||||
def test_instantiate(self):
|
||||
gas = ct.Solution('h2o2.xml')
|
||||
|
||||
flame = ct.FreeFlame(gas)
|
||||
|
||||
def test_badInstantiate(self):
|
||||
solid = ct.Solution('diamond.xml', 'diamond')
|
||||
with self.assertRaises(TypeError):
|
||||
flame = ct.FreeFlame(solid)
|
||||
|
||||
def test_instantiateSurface(self):
|
||||
gas = ct.Solution('diamond.xml', 'gas')
|
||||
solid = ct.Solution('diamond.xml', 'diamond')
|
||||
interface = ct.Solution('diamond.xml', 'diamond_100', (gas, solid))
|
||||
|
||||
surface = ct.ReactingSurface1D()
|
||||
surface.setKinetics(interface)
|
||||
|
||||
46
interfaces/cython/cantera/test/test_reactor.py
Normal file
46
interfaces/cython/cantera/test/test_reactor.py
Normal file
|
|
@ -0,0 +1,46 @@
|
|||
import unittest
|
||||
import numpy as np
|
||||
|
||||
import cantera as ct
|
||||
from . import utilities
|
||||
|
||||
class TestReactor(utilities.CanteraTest):
|
||||
def setUp(self):
|
||||
self.gas1 = ct.Solution('h2o2.xml')
|
||||
self.gas2 = ct.Solution('h2o2.xml')
|
||||
X = np.zeros(self.gas1.nSpecies)
|
||||
X[3] = 1.0
|
||||
self.gas2.setMoleFractions(X)
|
||||
|
||||
self.r1 = ct.Reactor(self.gas1)
|
||||
self.r2 = ct.Reactor(self.gas2)
|
||||
|
||||
def test_disjoint(self):
|
||||
T1 = self.gas1.temperature
|
||||
T2 = self.gas2.temperature
|
||||
P1 = self.gas1.pressure
|
||||
P2 = self.gas2.pressure
|
||||
|
||||
net = ct.ReactorNet()
|
||||
net.addReactor(self.r1)
|
||||
net.addReactor(self.r2)
|
||||
net.advance(1.0)
|
||||
|
||||
# Nothing should change from the initial condition
|
||||
self.assertNear(T1, self.gas1.temperature)
|
||||
self.assertNear(T2, self.gas2.temperature)
|
||||
self.assertNear(P1, self.gas1.pressure)
|
||||
self.assertNear(P2, self.gas2.pressure)
|
||||
|
||||
def test_equalizePressure(self):
|
||||
w = ct.Wall()
|
||||
w.install(self.r1, self.r2)
|
||||
w.expansionRateCoeff = 0.1
|
||||
w.area = 1.0
|
||||
|
||||
net = ct.ReactorNet()
|
||||
net.addReactor(self.r1)
|
||||
net.addReactor(self.r2)
|
||||
|
||||
net.advance(1.0)
|
||||
self.assertNear(self.gas1.pressure, self.gas2.pressure)
|
||||
|
|
@ -27,3 +27,15 @@ class TestThermoPhase(utilities.CanteraTest):
|
|||
def test_getState(self):
|
||||
self.assertNear(self.phase.pressure, ct.OneAtm)
|
||||
self.assertNear(self.phase.temperature, 300)
|
||||
|
||||
|
||||
class TestInterfacePhase(utilities.CanteraTest):
|
||||
def setUp(self):
|
||||
self.gas = ct.Solution('diamond.xml', 'gas')
|
||||
self.solid = ct.Solution('diamond.xml', 'diamond')
|
||||
self.interface = ct.Solution('diamond.xml', 'diamond_100',
|
||||
(self.gas, self.solid))
|
||||
|
||||
def test_properties(self):
|
||||
self.interface.siteDensity = 100
|
||||
self.assertEqual(self.interface.siteDensity, 100)
|
||||
Loading…
Add table
Reference in a new issue