Added a test for reactors with wall interactions

This commit is contained in:
Ray Speth
2012-05-24 16:29:23 +00:00
parent ee746bf895
commit 761c2589e3
2 changed files with 281 additions and 4 deletions
+82 -4
View File
@@ -106,8 +106,86 @@ class CombustorTestImplementation(object):
rtol=1e-6, atol=1e-12)
self.assertFalse(bad, bad)
# Keep the implementation separate from the unittest-derived class
# so that it can be run independently to generate the reference data file.
class CombustorTest(CombustorTestImplementation, unittest.TestCase):
pass
class WallTestImplementation(object):
"""
These tests are based on the sample:
python/reactors/reactor2_sim/reactor2.py
with some simplifications so that they run faster and produce more
consistent output.
"""
referenceFile = '../data/WallTest-integrateWithAdvance.csv'
def setUp(self):
# reservoir to represent the environment
self.gas0 = ct.importPhase('../../data/inputs/air.cti')
self.gas0.set(T=300, P=ct.OneAtm)
self.env = reactors.Reservoir(self.gas0)
# reactor to represent the side filled with Argon
self.gas1 = ct.importPhase('../../data/inputs/air.cti')
self.gas1.set(T=1000.0, P=30*ct.OneAtm, X='AR:1.0')
self.r1 = reactors.Reactor(self.gas1)
# reactor to represent the combustible mixture
self.gas2 = ct.importPhase('../../data/inputs/h2o2.cti')
self.gas2.set(T=500.0, P=1.5*ct.OneAtm, X='H2:0.5, O2:1.0, AR:10.0')
self.r2 = reactors.Reactor(self.gas2)
# Wall between the two reactors
self.w1 = reactors.Wall(self.r2, self.r1)
self.w1.set(area=1.0, K=2e-4, U=400.0)
# Wall to represent heat loss to the environment
self.w2 = reactors.Wall(self.r2, self.env)
self.w2.set(area=1.0, U=2000.0)
# Create the reactor network
self.sim = reactors.ReactorNet([self.r1, self.r2])
def test_integrateWithStep(self):
tnow = 0.0
tfinal = 0.01
self.data = []
while tnow < tfinal:
tnow = self.sim.step(tfinal)
self.data.append([tnow,
self.r1.temperature(),
self.r2.temperature(),
self.r1.pressure(),
self.r2.pressure(),
self.r1.volume(),
self.r2.volume()])
self.assertTrue(tnow >= tfinal)
bad = utilities.compareTimeSeries(self.referenceFile, self.data,
rtol=1e-3, atol=1e-8)
self.assertFalse(bad, bad)
def test_integrateWithAdvance(self, saveReference=False):
times = np.linspace(0, 0.01, 200)
self.data = []
for t in times[1:]:
self.sim.advance(t)
self.data.append([t,
self.r1.temperature(),
self.r2.temperature(),
self.r1.pressure(),
self.r2.pressure(),
self.r1.volume(),
self.r2.volume()])
if saveReference:
np.savetxt(self.referenceFile, np.array(self.data), '%11.6e', ', ')
else:
bad = utilities.compareTimeSeries(self.referenceFile, self.data,
rtol=2e-5, atol=1e-9)
self.assertFalse(bad, bad)
# Keep the implementations separate from the unittest-derived class
# so that they can be run independently to generate the reference data files.
class CombustorTest(CombustorTestImplementation, unittest.TestCase): pass
class WallTest(WallTestImplementation, unittest.TestCase): pass