Пример #1
0
    def test_corespecies_rate(self):
        """
        Test if a specific core species rate is equal to 0 over time.
        """

        c0 = {self.C2H5: 0.1, self.CH3: 0.1, self.CH4: 0.4, self.C2H6: 0.4}
        rxn1 = Reaction(reactants=[self.C2H6, self.CH3],
                        products=[self.C2H5, self.CH4],
                        kinetics=Arrhenius(A=(686.375 * 6, 'm^3/(mol*s)'),
                                           n=4.40721,
                                           Ea=(7.82799, 'kcal/mol'),
                                           T0=(298.15, 'K')))

        core_species = [self.CH4, self.CH3, self.C2H6, self.C2H5]
        edge_species = []
        core_reactions = [rxn1]
        edge_reactions = []
        sensitivity = []
        termination_conversion = []
        sensitivity_threshold = 0.001
        const_species = ["CH4"]
        sens_conds = {
            self.C2H5: 0.1,
            self.CH3: 0.1,
            self.CH4: 0.4,
            self.C2H6: 0.4,
            'T': self.T
        }

        rxn_system = LiquidReactor(self.T,
                                   c0,
                                   1,
                                   termination_conversion,
                                   sensitivity,
                                   sensitivity_threshold,
                                   const_spc_names=const_species,
                                   sens_conditions=sens_conds)
        # The test regarding the writing of constantSPCindices from input file is check with the previous test.
        rxn_system.const_spc_indices = [0]

        rxn_system.initialize_model(core_species, core_reactions, edge_species,
                                    edge_reactions)

        tlist = np.array([10**(i / 10.0) for i in range(-130, -49)],
                         np.float64)

        # Integrate to get the solution at each time point
        t, y, reaction_rates, species_rates = [], [], [], []
        for t1 in tlist:
            rxn_system.advance(t1)
            t.append(rxn_system.t)
            self.assertEqual(
                rxn_system.core_species_rates[0], 0,
                "Core species rate has to be equal to 0 for species hold constant. "
                "Here it is equal to {0}".format(
                    rxn_system.core_species_rates[0]))