def test_defaults_priority(self): K0InteractionParameter.objects.all().delete() m = Mixture() m.add(self.methane, 0.5) m.add(self.co2, 0.5) user = User.objects.create(username='******') s = EosSetup.objects.create(eos='SRK', user=user) # default staff set_interaction('lij', self.methane, self.co2, value=0.4, eos='SRK') assert_array_equal(s.lij(m), np.array([[0., 0.4], [0.4, 0.]])) # now user defined set_interaction('lij', self.methane, self.co2, value=0.6, user=user, eos='SRK') assert_array_equal(s.lij(m), np.array([[0., 0.6], [0.6, 0.]])) # now setup s.set_interaction('lij', self.methane, self.co2, value=0.9) assert_array_equal(s.lij(m), np.array([[0., 0.9], [0.9, 0.]]))
def test_set_interaction(self): set_interaction('k0', 'ethane', 'methane', eos='RKPR', value=0.4) k0 = K0InteractionParameter.objects.get() self.assertIn(self.ethane, k0.compounds.all()) self.assertIn(self.methane, k0.compounds.all()) self.assertEqual(k0.value, 0.4) self.assertIsNone(k0.setup) self.assertIsNone(k0.user) self.assertEqual(k0.eos, 'RKPR')
def test_global_k_for_same_custom_for_other_interaction(self): k = set_interaction('k0', self.ethane, self.methane, value=0.1, eos='RKPR') k2 = self.s.set_interaction('k0', self.ethane, self.co2, value=0.2) expected = np.zeros((3, 3)) expected[0, 1] = expected[1, 0] = k2.value expected[0, 2] = expected[2, 0] = k.value assert_array_equal(self.s.k0(self.m), expected)
def test_same_setup_and_user_different_eos_doesn_superpose(self): m = Mixture() m.add(self.methane, 0.2) m.add(self.co2, 0.1) user = User.objects.create(username='******') s1 = EosSetup.objects.create(eos='RKPR', user=user) s2 = EosSetup.objects.create(eos='PR', user=user) s3 = EosSetup.objects.create(eos='SRK', user=user) s1.set_interaction('kij', self.methane, self.co2, value=0.1) s2.set_interaction('kij', self.methane, self.co2, value=0.2) # default for user set_interaction('kij', self.methane, self.co2, eos='SRK', value=0.3, user=user) kij_rkpr = s1.kij(m) kij_pr = s2.kij(m) kij_srk = s3.kij(m) assert_array_equal(kij_pr, np.array([[0., 0.2], [0.2, 0.]])) assert_array_equal(kij_rkpr, np.array([[0., 0.1], [0.1, 0.]])) assert_array_equal(kij_srk, np.array([[0., 0.3], [0.3, 0.]]))
def test_there_is_a_global_k_a_setup_override(self): set_interaction('k0', self.ethane, self.methane, eos='RKPR', value=0.1) k2 = self.s.set_interaction('k0', self.ethane, self.methane, value=0.2) expected = np.zeros((3, 3)) expected[0, 2] = expected[2, 0] = k2.value assert_array_equal(self.s.k0(self.m), expected)