def setUp(self): """ A function run before each unit test in this class. """ self.Tmin = 350. self.Tmax = 1500. self.Pmin = 1e-1 self.Pmax = 1e1 self.pressures = numpy.array([1e-1, 1e1]) self.comment = 'CH3 + C2H6 <=> CH4 + C2H5 (Baulch 2005)' self.arrhenius = [ PDepArrhenius( pressures=(self.pressures, "bar"), arrhenius=[ Arrhenius( A=(9.3e-16, "cm^3/(molecule*s)"), n=0.0, Ea=(4740 * constants.R * 0.001, "kJ/mol"), T0=(1, "K"), Tmin=(self.Tmin, "K"), Tmax=(self.Tmax, "K"), comment=self.comment, ), Arrhenius( A=(9.3e-14, "cm^3/(molecule*s)"), n=0.0, Ea=(4740 * constants.R * 0.001, "kJ/mol"), T0=(1, "K"), Tmin=(self.Tmin, "K"), Tmax=(self.Tmax, "K"), comment=self.comment, ), ], Tmin=(self.Tmin, "K"), Tmax=(self.Tmax, "K"), Pmin=(self.Pmin, "bar"), Pmax=(self.Pmax, "bar"), comment=self.comment, ), PDepArrhenius( pressures=(self.pressures, "bar"), arrhenius=[ Arrhenius( A=(1.4e-11, "cm^3/(molecule*s)"), n=0.0, Ea=(11200 * constants.R * 0.001, "kJ/mol"), T0=(1, "K"), Tmin=(self.Tmin, "K"), Tmax=(self.Tmax, "K"), comment=self.comment, ), Arrhenius( A=(1.4e-9, "cm^3/(molecule*s)"), n=0.0, Ea=(11200 * constants.R * 0.001, "kJ/mol"), T0=(1, "K"), Tmin=(self.Tmin, "K"), Tmax=(self.Tmax, "K"), comment=self.comment, ), ], Tmin=(self.Tmin, "K"), Tmax=(self.Tmax, "K"), Pmin=(self.Pmin, "bar"), Pmax=(self.Pmax, "bar"), comment=self.comment, ), ] self.kinetics = MultiPDepArrhenius( arrhenius=self.arrhenius, Tmin=(self.Tmin, "K"), Tmax=(self.Tmax, "K"), Pmin=(self.Pmin, "bar"), Pmax=(self.Pmax, "bar"), comment=self.comment, )
def setUp(self): """ A function run before each unit test in this class. """ self.Tmin = 350.0 self.Tmax = 1500.0 self.Pmin = 1e-1 self.Pmax = 1e1 self.pressures = numpy.array([1e-1, 1e1]) self.comment = "CH3 + C2H6 <=> CH4 + C2H5 (Baulch 2005)" self.arrhenius = [ PDepArrhenius( pressures=(self.pressures, "bar"), arrhenius=[ Arrhenius( A=(9.3e-16, "cm^3/(molecule*s)"), n=0.0, Ea=(4740 * constants.R * 0.001, "kJ/mol"), T0=(1, "K"), Tmin=(self.Tmin, "K"), Tmax=(self.Tmax, "K"), comment=self.comment, ), Arrhenius( A=(9.3e-14, "cm^3/(molecule*s)"), n=0.0, Ea=(4740 * constants.R * 0.001, "kJ/mol"), T0=(1, "K"), Tmin=(self.Tmin, "K"), Tmax=(self.Tmax, "K"), comment=self.comment, ), ], Tmin=(self.Tmin, "K"), Tmax=(self.Tmax, "K"), Pmin=(self.Pmin, "bar"), Pmax=(self.Pmax, "bar"), comment=self.comment, ), PDepArrhenius( pressures=(self.pressures, "bar"), arrhenius=[ Arrhenius( A=(1.4e-11, "cm^3/(molecule*s)"), n=0.0, Ea=(11200 * constants.R * 0.001, "kJ/mol"), T0=(1, "K"), Tmin=(self.Tmin, "K"), Tmax=(self.Tmax, "K"), comment=self.comment, ), Arrhenius( A=(1.4e-9, "cm^3/(molecule*s)"), n=0.0, Ea=(11200 * constants.R * 0.001, "kJ/mol"), T0=(1, "K"), Tmin=(self.Tmin, "K"), Tmax=(self.Tmax, "K"), comment=self.comment, ), ], Tmin=(self.Tmin, "K"), Tmax=(self.Tmax, "K"), Pmin=(self.Pmin, "bar"), Pmax=(self.Pmax, "bar"), comment=self.comment, ), ] self.kinetics = MultiPDepArrhenius( arrhenius=self.arrhenius, Tmin=(self.Tmin, "K"), Tmax=(self.Tmax, "K"), Pmin=(self.Pmin, "bar"), Pmax=(self.Pmax, "bar"), comment=self.comment, )
class TestMultiPDepArrhenius(unittest.TestCase): """ Contains unit tests of the :class:`MultiPDepArrhenius` class. """ def setUp(self): """ A function run before each unit test in this class. """ self.Tmin = 350. self.Tmax = 1500. self.Pmin = 1e-1 self.Pmax = 1e1 self.pressures = numpy.array([1e-1, 1e1]) self.comment = 'CH3 + C2H6 <=> CH4 + C2H5 (Baulch 2005)' self.arrhenius = [ PDepArrhenius( pressures=(self.pressures, "bar"), arrhenius=[ Arrhenius( A=(9.3e-16, "cm^3/(molecule*s)"), n=0.0, Ea=(4740 * constants.R * 0.001, "kJ/mol"), T0=(1, "K"), Tmin=(self.Tmin, "K"), Tmax=(self.Tmax, "K"), comment=self.comment, ), Arrhenius( A=(9.3e-14, "cm^3/(molecule*s)"), n=0.0, Ea=(4740 * constants.R * 0.001, "kJ/mol"), T0=(1, "K"), Tmin=(self.Tmin, "K"), Tmax=(self.Tmax, "K"), comment=self.comment, ), ], Tmin=(self.Tmin, "K"), Tmax=(self.Tmax, "K"), Pmin=(self.Pmin, "bar"), Pmax=(self.Pmax, "bar"), comment=self.comment, ), PDepArrhenius( pressures=(self.pressures, "bar"), arrhenius=[ Arrhenius( A=(1.4e-11, "cm^3/(molecule*s)"), n=0.0, Ea=(11200 * constants.R * 0.001, "kJ/mol"), T0=(1, "K"), Tmin=(self.Tmin, "K"), Tmax=(self.Tmax, "K"), comment=self.comment, ), Arrhenius( A=(1.4e-9, "cm^3/(molecule*s)"), n=0.0, Ea=(11200 * constants.R * 0.001, "kJ/mol"), T0=(1, "K"), Tmin=(self.Tmin, "K"), Tmax=(self.Tmax, "K"), comment=self.comment, ), ], Tmin=(self.Tmin, "K"), Tmax=(self.Tmax, "K"), Pmin=(self.Pmin, "bar"), Pmax=(self.Pmax, "bar"), comment=self.comment, ), ] self.kinetics = MultiPDepArrhenius( arrhenius=self.arrhenius, Tmin=(self.Tmin, "K"), Tmax=(self.Tmax, "K"), Pmin=(self.Pmin, "bar"), Pmax=(self.Pmax, "bar"), comment=self.comment, ) def test_arrhenius(self): """ Test that the MultiPDepArrhenius arrhenius property was properly set. """ self.assertEqual(self.kinetics.arrhenius, self.arrhenius) def test_Tmin(self): """ Test that the MultiPDepArrhenius Tmin property was properly set. """ self.assertAlmostEqual(self.kinetics.Tmin.value_si, self.Tmin, 6) def test_Tmax(self): """ Test that the MultiPDepArrhenius Tmax property was properly set. """ self.assertAlmostEqual(self.kinetics.Tmax.value_si, self.Tmax, 6) def test_Pmin(self): """ Test that the MultiPDepArrhenius Pmin property was properly set. """ self.assertAlmostEqual(self.kinetics.Pmin.value_si * 1e-5, self.Pmin, 6) def test_Pmax(self): """ Test that the MultiPDepArrhenius Pmax property was properly set. """ self.assertAlmostEqual(self.kinetics.Pmax.value_si * 1e-5, self.Pmax, 6) def test_comment(self): """ Test that the MultiPDepArrhenius comment property was properly set. """ self.assertEqual(self.kinetics.comment, self.comment) def test_isTemperatureValid(self): """ Test the MultiPDepArrhenius.isTemperatureValid() method. """ Tdata = numpy.array( [200, 400, 600, 800, 1000, 1200, 1400, 1600, 1800, 2000]) validdata = numpy.array( [False, True, True, True, True, True, True, False, False, False], numpy.bool) for T, valid in zip(Tdata, validdata): valid0 = self.kinetics.isTemperatureValid(T) self.assertEqual(valid0, valid) def test_isPressureValid(self): """ Test the MultiPDepArrhenius.isPressureValid() method. """ Pdata = numpy.array([1e3, 1e4, 1e5, 1e6, 1e7]) validdata = numpy.array([False, True, True, True, False], numpy.bool) for P, valid in zip(Pdata, validdata): valid0 = self.kinetics.isPressureValid(P) self.assertEqual(valid0, valid) def test_getRateCoefficient(self): """ Test the MultiPDepArrhenius.getRateCoefficient() method. """ Tlist = numpy.array( [200, 400, 600, 800, 1000, 1200, 1400, 1600, 1800, 2000]) Plist = numpy.array([1e4, 1e5, 1e6]) kexplist = numpy.array([ [ 2.85400e-08, 4.00384e-03, 2.73563e-01, 8.50699e+00, 1.20181e+02, 7.56312e+02, 2.84724e+03, 7.71702e+03, 1.67743e+04, 3.12290e+04 ], [ 2.85400e-07, 4.00384e-02, 2.73563e+00, 8.50699e+01, 1.20181e+03, 7.56312e+03, 2.84724e+04, 7.71702e+04, 1.67743e+05, 3.12290e+05 ], [ 2.85400e-06, 4.00384e-01, 2.73563e+01, 8.50699e+02, 1.20181e+04, 7.56312e+04, 2.84724e+05, 7.71702e+05, 1.67743e+06, 3.12290e+06 ], ]).T for i in range(Tlist.shape[0]): for j in range(Plist.shape[0]): kexp = kexplist[i, j] kact = self.kinetics.getRateCoefficient(Tlist[i], Plist[j]) self.assertAlmostEqual(kexp, kact, delta=1e-4 * kexp) def test_getRateCoefficient_diff_plist(self): """ Test the MultiPDepArrhenius.getRateCoefficient() when plists are different. """ # modify the MultiPDepArrhenius object with an additional entry pressures = numpy.array([1e-1, 1e-1, 1e1]) self.kinetics.arrhenius[0].pressures = (pressures, "bar") self.kinetics.arrhenius[0].arrhenius.insert( 0, self.kinetics.arrhenius[0].arrhenius[0]) Tlist = numpy.array( [200, 400, 600, 800, 1000, 1200, 1400, 1600, 1800, 2000]) Plist = numpy.array([1e4, 1e5, 1e6]) kexplist = numpy.array([ [ 2.85400e-08, 4.00384e-03, 2.73563e-01, 8.50699e+00, 1.20181e+02, 7.56312e+02, 2.84724e+03, 7.71702e+03, 1.67743e+04, 3.12290e+04 ], [ 2.85400e-07, 4.00384e-02, 2.73563e+00, 8.50699e+01, 1.20181e+03, 7.56312e+03, 2.84724e+04, 7.71702e+04, 1.67743e+05, 3.12290e+05 ], [ 2.85400e-06, 4.00384e-01, 2.73563e+01, 8.50699e+02, 1.20181e+04, 7.56312e+04, 2.84724e+05, 7.71702e+05, 1.67743e+06, 3.12290e+06 ], ]).T for i in range(Tlist.shape[0]): for j in range(Plist.shape[0]): kexp = kexplist[i, j] kact = self.kinetics.getRateCoefficient(Tlist[i], Plist[j]) self.assertAlmostEqual(kexp, kact, delta=1e-4 * kexp) def test_pickle(self): """ Test that a MultiPDepArrhenius object can be pickled and unpickled with no loss of information. """ import cPickle kinetics = cPickle.loads(cPickle.dumps(self.kinetics, -1)) self.assertEqual(len(self.kinetics.arrhenius), len(kinetics.arrhenius)) self.assertAlmostEqual(self.kinetics.Tmin.value, kinetics.Tmin.value, 4) self.assertEqual(self.kinetics.Tmin.units, kinetics.Tmin.units) self.assertAlmostEqual(self.kinetics.Tmax.value, kinetics.Tmax.value, 4) self.assertEqual(self.kinetics.Tmax.units, kinetics.Tmax.units) self.assertEqual(self.kinetics.comment, kinetics.comment) def test_repr(self): """ Test that a MultiPDepArrhenius object can be reconstructed from its repr() output with no loss of information. """ kinetics = None exec('kinetics = {0!r}'.format(self.kinetics)) self.assertEqual(len(self.kinetics.arrhenius), len(kinetics.arrhenius)) self.assertAlmostEqual(self.kinetics.Tmin.value, kinetics.Tmin.value, 4) self.assertEqual(self.kinetics.Tmin.units, kinetics.Tmin.units) self.assertAlmostEqual(self.kinetics.Tmax.value, kinetics.Tmax.value, 4) self.assertEqual(self.kinetics.Tmax.units, kinetics.Tmax.units) self.assertEqual(self.kinetics.comment, kinetics.comment) def test_changeRate(self): """ Test the PDepMultiArrhenius.changeRate() method. """ Tlist = numpy.array([ 300, 400, 500, 600, 700, 800, 900, 1000, 1100, 1200, 1300, 1400, 1500 ]) k0list = numpy.array( [self.kinetics.getRateCoefficient(T, 1e5) for T in Tlist]) self.kinetics.changeRate(2) for T, kexp in zip(Tlist, k0list): kact = self.kinetics.getRateCoefficient(T, 1e5) self.assertAlmostEqual(2 * kexp, kact, delta=1e-6 * kexp)
class TestMultiPDepArrhenius(unittest.TestCase): """ Contains unit tests of the :class:`MultiPDepArrhenius` class. """ def setUp(self): """ A function run before each unit test in this class. """ self.Tmin = 350.0 self.Tmax = 1500.0 self.Pmin = 1e-1 self.Pmax = 1e1 self.pressures = numpy.array([1e-1, 1e1]) self.comment = "CH3 + C2H6 <=> CH4 + C2H5 (Baulch 2005)" self.arrhenius = [ PDepArrhenius( pressures=(self.pressures, "bar"), arrhenius=[ Arrhenius( A=(9.3e-16, "cm^3/(molecule*s)"), n=0.0, Ea=(4740 * constants.R * 0.001, "kJ/mol"), T0=(1, "K"), Tmin=(self.Tmin, "K"), Tmax=(self.Tmax, "K"), comment=self.comment, ), Arrhenius( A=(9.3e-14, "cm^3/(molecule*s)"), n=0.0, Ea=(4740 * constants.R * 0.001, "kJ/mol"), T0=(1, "K"), Tmin=(self.Tmin, "K"), Tmax=(self.Tmax, "K"), comment=self.comment, ), ], Tmin=(self.Tmin, "K"), Tmax=(self.Tmax, "K"), Pmin=(self.Pmin, "bar"), Pmax=(self.Pmax, "bar"), comment=self.comment, ), PDepArrhenius( pressures=(self.pressures, "bar"), arrhenius=[ Arrhenius( A=(1.4e-11, "cm^3/(molecule*s)"), n=0.0, Ea=(11200 * constants.R * 0.001, "kJ/mol"), T0=(1, "K"), Tmin=(self.Tmin, "K"), Tmax=(self.Tmax, "K"), comment=self.comment, ), Arrhenius( A=(1.4e-9, "cm^3/(molecule*s)"), n=0.0, Ea=(11200 * constants.R * 0.001, "kJ/mol"), T0=(1, "K"), Tmin=(self.Tmin, "K"), Tmax=(self.Tmax, "K"), comment=self.comment, ), ], Tmin=(self.Tmin, "K"), Tmax=(self.Tmax, "K"), Pmin=(self.Pmin, "bar"), Pmax=(self.Pmax, "bar"), comment=self.comment, ), ] self.kinetics = MultiPDepArrhenius( arrhenius=self.arrhenius, Tmin=(self.Tmin, "K"), Tmax=(self.Tmax, "K"), Pmin=(self.Pmin, "bar"), Pmax=(self.Pmax, "bar"), comment=self.comment, ) def test_arrhenius(self): """ Test that the MultiPDepArrhenius arrhenius property was properly set. """ self.assertEqual(self.kinetics.arrhenius, self.arrhenius) def test_Tmin(self): """ Test that the MultiPDepArrhenius Tmin property was properly set. """ self.assertAlmostEqual(self.kinetics.Tmin.value_si, self.Tmin, 6) def test_Tmax(self): """ Test that the MultiPDepArrhenius Tmax property was properly set. """ self.assertAlmostEqual(self.kinetics.Tmax.value_si, self.Tmax, 6) def test_Pmin(self): """ Test that the MultiPDepArrhenius Pmin property was properly set. """ self.assertAlmostEqual(self.kinetics.Pmin.value_si * 1e-5, self.Pmin, 6) def test_Pmax(self): """ Test that the MultiPDepArrhenius Pmax property was properly set. """ self.assertAlmostEqual(self.kinetics.Pmax.value_si * 1e-5, self.Pmax, 6) def test_comment(self): """ Test that the MultiPDepArrhenius comment property was properly set. """ self.assertEqual(self.kinetics.comment, self.comment) def test_isTemperatureValid(self): """ Test the MultiPDepArrhenius.isTemperatureValid() method. """ Tdata = numpy.array([200, 400, 600, 800, 1000, 1200, 1400, 1600, 1800, 2000]) validdata = numpy.array([False, True, True, True, True, True, True, False, False, False], numpy.bool) for T, valid in zip(Tdata, validdata): valid0 = self.kinetics.isTemperatureValid(T) self.assertEqual(valid0, valid) def test_isPressureValid(self): """ Test the MultiPDepArrhenius.isPressureValid() method. """ Pdata = numpy.array([1e3, 1e4, 1e5, 1e6, 1e7]) validdata = numpy.array([False, True, True, True, False], numpy.bool) for P, valid in zip(Pdata, validdata): valid0 = self.kinetics.isPressureValid(P) self.assertEqual(valid0, valid) def test_getRateCoefficient(self): """ Test the MultiPDepArrhenius.getRateCoefficient() method. """ Tlist = numpy.array([200, 400, 600, 800, 1000, 1200, 1400, 1600, 1800, 2000]) Plist = numpy.array([1e4, 1e5, 1e6]) kexplist = numpy.array( [ [ 2.85400e-08, 4.00384e-03, 2.73563e-01, 8.50699e00, 1.20181e02, 7.56312e02, 2.84724e03, 7.71702e03, 1.67743e04, 3.12290e04, ], [ 2.85400e-07, 4.00384e-02, 2.73563e00, 8.50699e01, 1.20181e03, 7.56312e03, 2.84724e04, 7.71702e04, 1.67743e05, 3.12290e05, ], [ 2.85400e-06, 4.00384e-01, 2.73563e01, 8.50699e02, 1.20181e04, 7.56312e04, 2.84724e05, 7.71702e05, 1.67743e06, 3.12290e06, ], ] ).T for i in range(Tlist.shape[0]): for j in range(Plist.shape[0]): kexp = kexplist[i, j] kact = self.kinetics.getRateCoefficient(Tlist[i], Plist[j]) self.assertAlmostEqual(kexp, kact, delta=1e-4 * kexp) def test_pickle(self): """ Test that a MultiPDepArrhenius object can be pickled and unpickled with no loss of information. """ import cPickle kinetics = cPickle.loads(cPickle.dumps(self.kinetics)) self.assertEqual(len(self.kinetics.arrhenius), len(kinetics.arrhenius)) self.assertAlmostEqual(self.kinetics.Tmin.value, kinetics.Tmin.value, 4) self.assertEqual(self.kinetics.Tmin.units, kinetics.Tmin.units) self.assertAlmostEqual(self.kinetics.Tmax.value, kinetics.Tmax.value, 4) self.assertEqual(self.kinetics.Tmax.units, kinetics.Tmax.units) self.assertEqual(self.kinetics.comment, kinetics.comment) def test_repr(self): """ Test that a MultiPDepArrhenius object can be reconstructed from its repr() output with no loss of information. """ kinetics = None exec("kinetics = {0!r}".format(self.kinetics)) self.assertEqual(len(self.kinetics.arrhenius), len(kinetics.arrhenius)) self.assertAlmostEqual(self.kinetics.Tmin.value, kinetics.Tmin.value, 4) self.assertEqual(self.kinetics.Tmin.units, kinetics.Tmin.units) self.assertAlmostEqual(self.kinetics.Tmax.value, kinetics.Tmax.value, 4) self.assertEqual(self.kinetics.Tmax.units, kinetics.Tmax.units) self.assertEqual(self.kinetics.comment, kinetics.comment)