def test_simple_rkpr_env(self): m = Mixture() m.add_many('methane propane n-pentane n-decane n-hexadecane', '0.822 0.088 0.050 0.020 0.020') s = EosSetup.objects.create(eos='RKPR', kij_mode=EosSetup.T_DEP, lij_mode='constants') m.get_envelope(setup=s)
class TestIsochore(TestCase): def setUp(self): self.m = Mixture() self.m.add_many('methane propane n-pentane n-decane n-hexadecane', '0.822 0.088 0.050 0.020 0.020') self.s = EosSetup.objects.create(eos='RKPR', kij_mode=EosSetup.T_DEP, lij_mode='constants') def test_isochore_input(self): flash_txt = Isochore(v=10., ts=467.01, ps=3.86, t_sup=465.0, t_step=5.0, t_inf=270.0, mixture=self.m, setup=self.s).get_txt() #open('isochore_input_generated.txt', 'w').write(flash_txt) self.assertEqual( flash_txt, open(os.path.join(__location__, 'isochore_input_expected.txt')).read()) def test_simple_isochore(self): iso = Isochore(v=10., ts=467.01, ps=3.86, t_sup=465.0, t_step=5.0, t_inf=270.0, mixture=self.m, setup=self.s) iso._calc() #assert_array_equal(.x, np.array([0., 1., 0])) assert_array_almost_equal(iso.t[[0, -1]], np.array([467.01, 270.0])) assert_array_almost_equal(iso.p[[0, -1]], np.array([3.86, 2.1])) self.assertEqual(iso.t.size, 41) self.assertEqual(iso.p.size, 41) assert_array_almost_equal(iso.t_monophasic[[0, -1]], np.array([467.01, 1002.01])) assert_array_almost_equal(iso.p_monophasic[[0, -1]], np.array([3.86, 8.356])) self.assertEqual(iso.t_monophasic.size, 108) self.assertEqual(iso.p_monophasic.size, 108)
class TestMixtureAdd(TestCase): def setUp(self): MixtureFraction.objects.all().delete() self.m = Mixture() self.ethane = Compound.objects.get(name='ETHANE') self.co2 = Compound.objects.get(name='CARBON DIOXIDE') self.methane = Compound.objects.get(name='METHANE') def test_simple_add(self): assert MixtureFraction.objects.all().count() == 0 self.m.add(self.ethane, 0.1) self.assertEqual(MixtureFraction.objects.count(), 1) mf = MixtureFraction.objects.all().get() self.assertEqual(mf.mixture, self.m) self.assertEqual(mf.compound, self.ethane) self.assertEqual(mf.fraction, Decimal('0.1')) def test_add_by_name(self): self.m.add('ethane', 0.1) mf = MixtureFraction.objects.all().get() self.assertEqual(mf.mixture, self.m) self.assertEqual(mf.compound, self.ethane) self.assertEqual(mf.fraction, Decimal('0.1')) def test_add_by_formula(self): self.m.add('co2', 0.1) mf = MixtureFraction.objects.all().get() self.assertEqual(mf.mixture, self.m) self.assertEqual(mf.compound, self.co2) self.assertEqual(mf.fraction, Decimal('0.1')) def test_add_fraction_as_str(self): self.m.add('ethane', '0.1') mf = MixtureFraction.objects.all().get() self.assertEqual(mf.mixture, self.m) self.assertEqual(mf.compound, self.ethane) self.assertEqual(mf.fraction, Decimal('0.1')) def test_add_many_iterables(self): self.m.add_many([self.ethane, self.methane, self.co2], [0.1, 0.2, 0.3]) expected = [(self.ethane, Decimal('0.1')), (self.methane, Decimal('0.2')), (self.co2, Decimal('0.3'))] self.assertEqual([i for i in self.m], expected) def test_add_many_string(self): self.m.add_many("ethane methane co2", "0.1 0.2 0.3") expected = [(self.ethane, Decimal('0.1')), (self.methane, Decimal('0.2')), (self.co2, Decimal('0.3'))] self.assertEqual([i for i in self.m], expected) def test_add_many_must_have_same_size(self): with self.assertRaises(ValueError): self.m.add_many("ethane methane", "0.1 0.2 0.3") def test_cant_add_greater_than_1(self): with self.assertRaises(ValueError) as v: self.m.add('ethane', '1.2') self.assertEqual( v.exception.message, 'Add this fraction would exceed 1.0. ' 'Max fraction allowed is 1.0') def test_cant_add_greater_than_remaining(self): self.m.add('ethane', '0.6') with self.assertRaises(ValueError) as v: self.m.add('methane', '0.6') self.assertEqual( v.exception.message, 'Add this fraction would exceed 1.0. ' 'Max fraction allowed is 0.400000') def test_add_without_fraction_add_remaining(self): self.m.add('ethane', '0.6') self.m.add('co2') mf = MixtureFraction.objects.get(mixture=self.m, compound=self.co2) self.assertEqual(mf.fraction, Decimal('0.4'))