示例#1
0
class TestMixture(TestCase):
    def setUp(self):
        self.m = Mixture()
        self.ethane = Compound.objects.get(name='ETHANE')
        self.methane = Compound.objects.get(name='METHANE')
        self.co2 = Compound.objects.get(name='CARBON DIOXIDE')

    def test_add_order_is_preserved(self):
        self.m.add(self.ethane, 0.1)
        self.m.add(self.co2, 0.3)
        self.m.add(self.methane, 0.2)
        expected = [self.ethane, self.co2, self.methane]
        self.assertEqual(list(self.m.compounds), expected)

    def test_sort(self):
        self.m.add(self.ethane, 0.1)
        self.m.add(self.co2, 0.3)
        self.m.add(self.methane, 0.2)
        expected = [
            self.methane,
            self.ethane,
            self.co2,
        ]
        self.m.sort()
        self.assertEqual(list(self.m.compounds), expected)
        assert_array_equal(self.m.z, np.array([0.2, 0.1, 0.3]))

    def test_fraction_order_is_preserved(self):
        self.m.add(self.ethane, 0.1)
        self.m.add(self.methane, 0.2)
        self.m.add(self.co2, 0.3)
        assert_array_equal(self.m.z, np.array([0.1, 0.2, 0.3]))

    def test_field_tc(self):
        self.m.add(self.methane, 0.2)
        self.m.add(self.co2, 0.1)
        self.m.add(self.ethane, 0.3)
        assert_array_equal(self.m.tc,
                           [self.methane.tc, self.co2.tc, self.ethane.tc])

    def test_field_pc(self):
        self.m.add(self.methane, 0.2)
        self.m.add(self.co2, 0.1)
        self.m.add(self.ethane, 0.3)
        assert_array_equal(self.m.pc,
                           [self.methane.pc, self.co2.pc, self.ethane.pc])

    def test_field_vc(self):
        self.m.add(self.methane, 0.2)
        self.m.add(self.co2, 0.1)
        self.m.add(self.ethane, 0.3)
        assert_array_equal(self.m.vc,
                           [self.methane.vc, self.co2.vc, self.ethane.vc])

    def test_decimal_round(self):
        self.m['ETHANE'] = u'0.4'
        self.m['CARBON DIOXIDE'] = u'0.3'
        self.m['n-PENTANE'] = u'0.2'
        self.m['n-HEXANE'] = 0.1
        self.assertIsNone(self.m.clean())
示例#2
0
    def test_complex_lij_(self):
        GC = Mixture()
        elementos = [
            'methane', 'n-butane', 'n-heptane', 'n-decane', 'n-tetradecane'
        ]
        fracciones = [0.80, 0.14, 0.04, 0.014, 0.006]
        for elemento, fraccion in zip(elementos, fracciones):
            GC[elemento] = fraccion
        GC.sort(True)
        setup1 = EosSetup.objects.create(eos='RKPR',
                                         kij_mode=EosSetup.T_DEP,
                                         lij_mode=EosSetup.CONSTANTS)
        setup1.set_interaction('k0', 'methane', 'n-butane', 0.02613)
        setup1.set_interaction('k0', 'methane', 'n-heptane', 0.05613)
        setup1.set_interaction('k0', 'methane', 'n-decane', 0.08224)
        setup1.set_interaction('k0', 'methane', 'n-tetradecane', 0.10738)

        setup1.set_interaction('lij', 'methane', 'n-butane', -0.06565)
        setup1.set_interaction('lij', 'methane', 'n-heptane', -0.11875)
        setup1.set_interaction('lij', 'methane', 'n-decane', -0.14551)
        setup1.set_interaction('lij', 'methane', 'n-tetradecane', -0.13602)
        setup1.set_interaction('lij', 'n-butane', 'n-heptane', -0.01754)
        setup1.set_interaction('lij', 'n-butane', 'n-decane', -0.02433)
        setup1.set_interaction('lij', 'n-butane', 'n-tetradecane', -0.02203)
        setup1.set_interaction('lij', 'n-heptane', 'n-decane', -0.00586)
        setup1.set_interaction('lij', 'n-heptane', 'n-tetradecane', -0.00388)
        setup1.set_interaction('lij', 'n-decane', 'n-tetradecane', 0.00188)

        setup_lij_menos20 = EosSetup.objects.create(
            eos='RKPR', kij_mode=EosSetup.T_DEP, lij_mode=EosSetup.CONSTANTS)

        setup_lij_menos20.set_interaction_matrix('k0', GC, setup1.k0(GC))
        assert_array_equal(
            setup1.k0(GC) - setup_lij_menos20.k0(GC), np.zeros((5, 5)))

        setup_lij_menos20.set_interaction_matrix('lij', GC, setup1.lij(GC))
        assert_array_equal(
            setup1.lij(GC) - setup_lij_menos20.lij(GC), np.zeros((5, 5)))
示例#3
0
class TestSetInteractionMatrix(TestCase):
    def setUp(self):
        self.GC = Mixture()
        elementos = ['methane', 'n-butane', 'n-heptane']
        fracciones = [0.5, 0.2, 0.3]
        for elemento, fraccion in zip(elementos, fracciones):
            self.GC[elemento] = fraccion
        self.GC.sort(True)
        self.setup = EosSetup.objects.create(eos='RKPR',
                                             kij_mode=EosSetup.T_DEP,
                                             lij_mode=EosSetup.CONSTANTS)
        self.setup.set_interaction('k0', 'methane', 'n-butane', 0.02613)
        self.setup.set_interaction('k0', 'methane', 'n-heptane', 0.05613)

    def test_matrix_could_be_text(self):
        setup = EosSetup.objects.create(eos='RKPR',
                                        kij_mode=EosSetup.T_DEP,
                                        lij_mode=EosSetup.CONSTANTS)
        matrix = """0.  0.02 0.05
                    0.02  0   0
                    0.05  0   0"""
        setup.set_interaction_matrix('k0', self.GC, matrix)

        assert_array_equal(
            setup.k0(self.GC),
            np.array([[0., .02, 0.05], [0.02, 0, 0], [0.05, 0, 0]]))

    def test_text_matrix_replaces_semicolon(self):
        setup = EosSetup.objects.create(eos='RKPR',
                                        kij_mode=EosSetup.T_DEP,
                                        lij_mode=EosSetup.CONSTANTS)
        matrix = """0  0,02 0,05
                    0,02  0   0
                    0,05  0   0"""
        setup.set_interaction_matrix('k0', self.GC, matrix)

        assert_array_equal(
            setup.k0(self.GC),
            np.array([[0., .02, 0.05], [0.02, 0, 0], [0.05, 0, 0]]))

    def test_set_matrix_could_be_ndarray(self):
        setup = EosSetup.objects.create(eos='RKPR',
                                        kij_mode=EosSetup.T_DEP,
                                        lij_mode=EosSetup.CONSTANTS)
        matrix = np.array([[0., .02, 0.05], [0.02, 0, 0], [0.05, 0, 0]])
        setup.set_interaction_matrix('k0', self.GC, matrix)
        assert_array_equal(setup.k0(self.GC), matrix)

    def test_set_lij_matrix(self):

        setup = EosSetup.objects.create(eos='RKPR',
                                        kij_mode=EosSetup.T_DEP,
                                        lij_mode=EosSetup.CONSTANTS)
        matrix = np.array([[0., .02, 0.05], [0.02, 0, 0], [0.05, 0, 0]])
        setup.set_interaction_matrix('lij', self.GC, matrix)
        assert_array_equal(setup.lij(self.GC), matrix)

    def test_complex_lij_(self):
        GC = Mixture()
        elementos = [
            'methane', 'n-butane', 'n-heptane', 'n-decane', 'n-tetradecane'
        ]
        fracciones = [0.80, 0.14, 0.04, 0.014, 0.006]
        for elemento, fraccion in zip(elementos, fracciones):
            GC[elemento] = fraccion
        GC.sort(True)
        setup1 = EosSetup.objects.create(eos='RKPR',
                                         kij_mode=EosSetup.T_DEP,
                                         lij_mode=EosSetup.CONSTANTS)
        setup1.set_interaction('k0', 'methane', 'n-butane', 0.02613)
        setup1.set_interaction('k0', 'methane', 'n-heptane', 0.05613)
        setup1.set_interaction('k0', 'methane', 'n-decane', 0.08224)
        setup1.set_interaction('k0', 'methane', 'n-tetradecane', 0.10738)

        setup1.set_interaction('lij', 'methane', 'n-butane', -0.06565)
        setup1.set_interaction('lij', 'methane', 'n-heptane', -0.11875)
        setup1.set_interaction('lij', 'methane', 'n-decane', -0.14551)
        setup1.set_interaction('lij', 'methane', 'n-tetradecane', -0.13602)
        setup1.set_interaction('lij', 'n-butane', 'n-heptane', -0.01754)
        setup1.set_interaction('lij', 'n-butane', 'n-decane', -0.02433)
        setup1.set_interaction('lij', 'n-butane', 'n-tetradecane', -0.02203)
        setup1.set_interaction('lij', 'n-heptane', 'n-decane', -0.00586)
        setup1.set_interaction('lij', 'n-heptane', 'n-tetradecane', -0.00388)
        setup1.set_interaction('lij', 'n-decane', 'n-tetradecane', 0.00188)

        setup_lij_menos20 = EosSetup.objects.create(
            eos='RKPR', kij_mode=EosSetup.T_DEP, lij_mode=EosSetup.CONSTANTS)

        setup_lij_menos20.set_interaction_matrix('k0', GC, setup1.k0(GC))
        assert_array_equal(
            setup1.k0(GC) - setup_lij_menos20.k0(GC), np.zeros((5, 5)))

        setup_lij_menos20.set_interaction_matrix('lij', GC, setup1.lij(GC))
        assert_array_equal(
            setup1.lij(GC) - setup_lij_menos20.lij(GC), np.zeros((5, 5)))