From d94f7faea0bc8e825e0f4f2ccf9b93c9c82205f9 Mon Sep 17 00:00:00 2001 From: Ingmar Schoegl Date: Thu, 13 Jan 2022 20:24:46 -0600 Subject: [PATCH] [Python] Shorten derivative suffixes to ddT, ddP, ddC and ddX --- interfaces/cython/cantera/kinetics.pyx | 54 ++++---- .../cython/cantera/test/test_jacobian.py | 119 +++++++++--------- .../cython/cantera/test/test_reaction.py | 37 +++--- 3 files changed, 107 insertions(+), 103 deletions(-) diff --git a/interfaces/cython/cantera/kinetics.pyx b/interfaces/cython/cantera/kinetics.pyx index ca7b56b3a2..ad91cdb94d 100644 --- a/interfaces/cython/cantera/kinetics.pyx +++ b/interfaces/cython/cantera/kinetics.pyx @@ -479,7 +479,7 @@ cdef class Kinetics(_SolutionBase): def __set__(self, settings): self.kinetics.setDerivativeSettings(dict_to_anymap(settings)) - property forward_rate_constants_temperature_derivatives: + property forward_rate_constants_ddT: """ Calculate derivatives for forward rate constants with respect to temperature at constant pressure, molar concentration and mole fractions. @@ -487,7 +487,7 @@ cdef class Kinetics(_SolutionBase): def __get__(self): return get_reaction_array(self, kin_getFwdRateConstants_ddT) - property forward_rate_constants_pressure_derivatives: + property forward_rate_constants_ddP: """ Calculate derivatives for forward rate constants with respect to pressure at constant temperature, molar concentration and mole fractions. @@ -495,7 +495,7 @@ cdef class Kinetics(_SolutionBase): def __get__(self): return get_reaction_array(self, kin_getFwdRateConstants_ddP) - property forward_rate_constants_concentration_derivatives: + property forward_rate_constants_ddC: """ Calculate derivatives for forward rate constants with respect to molar concentration at constant temperature, pressure and mole fractions. @@ -503,7 +503,7 @@ cdef class Kinetics(_SolutionBase): def __get__(self): return get_reaction_array(self, kin_getFwdRateConstants_ddC) - property forward_rop_temperature_derivatives: + property forward_rates_of_progress_ddT: """ Calculate derivatives for forward rates-of-progress with respect to temperature at constant pressure, molar concentration and mole fractions. @@ -511,7 +511,7 @@ cdef class Kinetics(_SolutionBase): def __get__(self): return get_reaction_array(self, kin_getFwdRatesOfProgress_ddT) - property forward_rop_pressure_derivatives: + property forward_rates_of_progress_ddP: """ Calculate derivatives for forward rates-of-progress with respect to pressure at constant temperature, molar concentration and mole fractions. @@ -519,7 +519,7 @@ cdef class Kinetics(_SolutionBase): def __get__(self): return get_reaction_array(self, kin_getFwdRatesOfProgress_ddP) - property forward_rop_concentration_derivatives: + property forward_rates_of_progress_ddC: """ Calculate derivatives for forward rates-of-progress with respect to molar concentration at constant temperature, pressure and mole fractions. @@ -527,7 +527,7 @@ cdef class Kinetics(_SolutionBase): def __get__(self): return get_reaction_array(self, kin_getFwdRatesOfProgress_ddC) - property forward_rop_species_derivatives: + property forward_rates_of_progress_ddX: """ Calculate derivatives for forward rates-of-progress with respect to species concentrations at constant temperature, pressure and molar concentration. @@ -543,7 +543,7 @@ cdef class Kinetics(_SolutionBase): return _scipy_sparse.csc_matrix(tup, shape=shape) return get_dense(self, kin_fwdRatesOfProgress_ddX) - property reverse_rop_temperature_derivatives: + property reverse_rates_of_progress_ddT: """ Calculate derivatives for reverse rates-of-progress with respect to temperature at constant pressure, molar concentration and mole fractions. @@ -551,7 +551,7 @@ cdef class Kinetics(_SolutionBase): def __get__(self): return get_reaction_array(self, kin_getRevRatesOfProgress_ddT) - property reverse_rop_pressure_derivatives: + property reverse_rates_of_progress_ddP: """ Calculate derivatives for reverse rates-of-progress with respect to pressure at constant temperature, molar concentration and mole fractions. @@ -559,7 +559,7 @@ cdef class Kinetics(_SolutionBase): def __get__(self): return get_reaction_array(self, kin_getRevRatesOfProgress_ddP) - property reverse_rop_concentration_derivatives: + property reverse_rates_of_progress_ddC: """ Calculate derivatives for reverse rates-of-progress with respect to molar concentration at constant temperature, pressure and mole fractions. @@ -567,7 +567,7 @@ cdef class Kinetics(_SolutionBase): def __get__(self): return get_reaction_array(self, kin_getRevRatesOfProgress_ddC) - property reverse_rop_species_derivatives: + property reverse_rates_of_progress_ddX: """ Calculate derivatives for reverse rates-of-progress with respect to species concentrations at constant temperature, pressure and molar concentration. @@ -583,7 +583,7 @@ cdef class Kinetics(_SolutionBase): return _scipy_sparse.csc_matrix(tup, shape=shape) return get_dense(self, kin_revRatesOfProgress_ddX) - property net_rop_temperature_derivatives: + property net_rates_of_progress_ddT: """ Calculate derivatives for net rates-of-progress with respect to temperature at constant pressure, molar concentration and mole fractions. @@ -591,7 +591,7 @@ cdef class Kinetics(_SolutionBase): def __get__(self): return get_reaction_array(self, kin_getNetRatesOfProgress_ddT) - property net_rop_pressure_derivatives: + property net_rates_of_progress_ddP: """ Calculate derivatives for net rates-of-progress with respect to pressure at constant temperature, molar concentration and mole fractions. @@ -599,7 +599,7 @@ cdef class Kinetics(_SolutionBase): def __get__(self): return get_reaction_array(self, kin_getNetRatesOfProgress_ddP) - property net_rop_concentration_derivatives: + property net_rates_of_progress_ddC: """ Calculate derivatives for net rates-of-progress with respect to molar concentration at constant temperature, pressure and mole fractions. @@ -607,7 +607,7 @@ cdef class Kinetics(_SolutionBase): def __get__(self): return get_reaction_array(self, kin_getNetRatesOfProgress_ddC) - property net_rop_species_derivatives: + property net_rates_of_progress_ddX: """ Calculate derivatives for net rates-of-progress with respect to species concentrations at constant temperature, pressure and molar concentration. @@ -623,7 +623,7 @@ cdef class Kinetics(_SolutionBase): return _scipy_sparse.csc_matrix(tup, shape=shape) return get_dense(self, kin_netRatesOfProgress_ddX) - property creation_rate_temperature_derivatives: + property creation_rate_ddT: """ Calculate derivatives of species creation rates with respect to temperature at constant pressure, molar concentration and mole fractions. @@ -631,7 +631,7 @@ cdef class Kinetics(_SolutionBase): def __get__(self): return get_species_array(self, kin_getCreationRates_ddT) - property creation_rate_pressure_derivatives: + property creation_rate_ddP: """ Calculate derivatives of species creation rates with respect to pressure at constant temperature, molar concentration and mole fractions. @@ -639,7 +639,7 @@ cdef class Kinetics(_SolutionBase): def __get__(self): return get_species_array(self, kin_getCreationRates_ddP) - property creation_rate_concentration_derivatives: + property creation_rate_ddC: """ Calculate derivatives of species creation rates with respect to molar concentration at constant temperature, pressure and mole fractions. @@ -647,7 +647,7 @@ cdef class Kinetics(_SolutionBase): def __get__(self): return get_species_array(self, kin_getCreationRates_ddC) - property creation_rate_species_derivatives: + property creation_rate_ddX: """ Calculate derivatives for species creation rates with respect to species concentrations at constant temperature, pressure and molar concentration. @@ -663,7 +663,7 @@ cdef class Kinetics(_SolutionBase): return _scipy_sparse.csc_matrix(tup, shape=shape) return get_dense(self, kin_creationRates_ddX) - property destruction_rate_temperature_derivatives: + property destruction_rate_ddT: """ Calculate derivatives of species destruction rates with respect to temperature at constant pressure, molar concentration and mole fractions. @@ -671,7 +671,7 @@ cdef class Kinetics(_SolutionBase): def __get__(self): return get_species_array(self, kin_getDestructionRates_ddT) - property destruction_rate_pressure_derivatives: + property destruction_rate_ddP: """ Calculate derivatives of species destruction rates with respect to pressure at constant temperature, molar concentration and mole fractions. @@ -679,7 +679,7 @@ cdef class Kinetics(_SolutionBase): def __get__(self): return get_species_array(self, kin_getDestructionRates_ddP) - property destruction_rate_concentration_derivatives: + property destruction_rate_ddC: """ Calculate derivatives of species destruction rates with respect to molar concentration at constant temperature, pressure and mole fractions. @@ -687,7 +687,7 @@ cdef class Kinetics(_SolutionBase): def __get__(self): return get_species_array(self, kin_getDestructionRates_ddC) - property destruction_rate_species_derivatives: + property destruction_rate_ddX: """ Calculate derivatives for species destruction rates with respect to species concentrations at constant temperature, pressure and molar concentration. @@ -703,7 +703,7 @@ cdef class Kinetics(_SolutionBase): return _scipy_sparse.csc_matrix(tup, shape=shape) return get_dense(self, kin_destructionRates_ddX) - property net_production_rate_temperature_derivatives: + property net_production_rate_ddT: """ Calculate derivatives of species net production rates with respect to temperature at constant pressure, molar concentration and mole fractions. @@ -711,7 +711,7 @@ cdef class Kinetics(_SolutionBase): def __get__(self): return get_species_array(self, kin_getNetProductionRates_ddT) - property net_production_rate_pressure_derivatives: + property net_production_rate_ddP: """ Calculate derivatives of species net production rates with respect to pressure at constant temperature, molar concentration and mole fractions. @@ -719,7 +719,7 @@ cdef class Kinetics(_SolutionBase): def __get__(self): return get_species_array(self, kin_getNetProductionRates_ddP) - property net_production_rate_concentration_derivatives: + property net_production_rate_ddC: """ Calculate derivatives of species net production rates with respect to molar density at constant temperature, pressure and mole fractions. @@ -727,7 +727,7 @@ cdef class Kinetics(_SolutionBase): def __get__(self): return get_species_array(self, kin_getNetProductionRates_ddC) - property net_production_rate_species_derivatives: + property net_production_rate_ddX: """ Calculate derivatives for species net production rates with respect to species concentrations at constant temperature, pressure and molar concentration. diff --git a/interfaces/cython/cantera/test/test_jacobian.py b/interfaces/cython/cantera/test/test_jacobian.py index 9f9088d385..5c0994eb08 100644 --- a/interfaces/cython/cantera/test/test_jacobian.py +++ b/interfaces/cython/cantera/test/test_jacobian.py @@ -81,11 +81,11 @@ def calc(): def test_forward_rop_ddX(self): # check derivatives of forward rates of progress with respect to mole fractions # against analytic result - dropm = self.gas.forward_rop_species_derivatives - dropp = self.gas.forward_rop_pressure_derivatives + dropm = self.gas.forward_rates_of_progress_ddX + dropp = self.gas.forward_rates_of_progress_ddP self.gas.derivative_settings = {"skip-third-bodies": True} - drop = self.gas.forward_rop_species_derivatives + drop = self.gas.forward_rates_of_progress_ddX rop = self.gas.forward_rates_of_progress for spc_ix in self.rix: if self.orders is None: @@ -110,11 +110,11 @@ def test_forward_rop_ddX(self): def test_reverse_rop_ddX(self): # check derivatives of reverse rates of progress with respect to mole fractions # against analytic result - dropm = self.gas.reverse_rop_species_derivatives - dropp = self.gas.reverse_rop_pressure_derivatives + dropm = self.gas.reverse_rates_of_progress_ddX + dropp = self.gas.reverse_rates_of_progress_ddP self.gas.derivative_settings = {"skip-third-bodies": True} - drop = self.gas.reverse_rop_species_derivatives + drop = self.gas.reverse_rates_of_progress_ddX rop = self.gas.reverse_rates_of_progress for spc_ix in self.pix: order = self.p_stoich[spc_ix, self.rxn_idx] @@ -136,8 +136,8 @@ def test_reverse_rop_ddX(self): def test_net_rop_ddX(self): # check derivatives of net rates of progress with respect to mole fractions # against numeric result - drop = self.gas.net_rop_species_derivatives - dropp = self.gas.net_rop_pressure_derivatives + drop = self.gas.net_rates_of_progress_ddX + dropp = self.gas.net_rates_of_progress_ddP for spc_ix in self.rix + self.pix: drop_num = self.rop_ddX(spc_ix, mode="net") @@ -163,7 +163,6 @@ def calc(): return self.gas.reverse_rates_of_progress if mode == "net": return self.gas.net_rates_of_progress - return None, None dt = self.tpx[0] * rtol dp = 0 if const_p else self.tpx[1] * rtol @@ -178,15 +177,15 @@ def test_forward_rop_ddT(self): # constant pressure - need to account for density change dcdt = - self.gas.density_mole / self.gas.T - drop = self.gas.forward_rop_temperature_derivatives - drop += self.gas.forward_rop_concentration_derivatives * dcdt + drop = self.gas.forward_rates_of_progress_ddT + drop += self.gas.forward_rates_of_progress_ddC * dcdt drop_num = self.rop_ddT(mode="forward", const_p=True) self.assertNear(drop[self.rxn_idx], drop_num, self.rtol) # constant density (volume) - need to account for pressure change dpdt = self.gas.P / self.gas.T - drop = self.gas.forward_rop_temperature_derivatives - drop += self.gas.forward_rop_pressure_derivatives * dpdt + drop = self.gas.forward_rates_of_progress_ddT + drop += self.gas.forward_rates_of_progress_ddP * dpdt drop_num = self.rop_ddT(mode="forward") self.assertNear(drop[self.rxn_idx], drop_num, self.rtol) @@ -203,15 +202,15 @@ def test_reverse_rop_ddT(self): # constant pressure - need to account for density change dcdt = - self.gas.density_mole / self.gas.T - drop = self.gas.reverse_rop_temperature_derivatives - drop += self.gas.reverse_rop_concentration_derivatives * dcdt + drop = self.gas.reverse_rates_of_progress_ddT + drop += self.gas.reverse_rates_of_progress_ddC * dcdt drop_num = self.rop_ddT(mode="reverse", const_p=True) self.assertNear(drop[self.rxn_idx], drop_num, self.rtol) # constant density (volume) - need to account for pressure change dpdt = self.gas.P / self.gas.T - drop = self.gas.reverse_rop_temperature_derivatives - drop += self.gas.reverse_rop_pressure_derivatives * dpdt + drop = self.gas.reverse_rates_of_progress_ddT + drop += self.gas.reverse_rates_of_progress_ddP * dpdt drop_num = self.rop_ddT(mode="reverse") self.assertNear(drop[self.rxn_idx], drop_num, self.rtol) @@ -228,15 +227,15 @@ def test_net_rop_ddT(self): # constant pressure - need to account for density change dcdt = - self.gas.density_mole / self.gas.T - drop = self.gas.net_rop_temperature_derivatives - drop += self.gas.net_rop_concentration_derivatives * dcdt + drop = self.gas.net_rates_of_progress_ddT + drop += self.gas.net_rates_of_progress_ddC * dcdt drop_num = self.rop_ddT(mode="net", const_p=True) self.assertNear(drop[self.rxn_idx], drop_num, self.rtol) # constant density (volume) - need to account for pressure change dpdt = self.gas.P / self.gas.T - drop = self.gas.net_rop_temperature_derivatives - drop += self.gas.net_rop_pressure_derivatives * dpdt + drop = self.gas.net_rates_of_progress_ddT + drop += self.gas.net_rates_of_progress_ddP * dpdt drop_num = self.rop_ddT(mode="forward") - self.rop_ddT(mode="reverse") self.assertNear(drop[self.rxn_idx], drop_num, self.rtol) @@ -257,7 +256,6 @@ def calc(): return self.gas.reverse_rates_of_progress if mode == "net": return self.gas.net_rates_of_progress - return None, None dp = self.tpx[1] * rtol self.gas.TP = self.tpx[0], self.tpx[1] + dp @@ -271,9 +269,9 @@ def test_forward_rop_ddP(self): # constant temperature - need to account for density change dcdp = self.gas.density_mole / self.gas.P - drop = self.gas.forward_rop_pressure_derivatives - drop += self.gas.forward_rop_concentration_derivatives * dcdp - drop_num = self.rop_ddP(mode="forward") #, const_p=True) + drop = self.gas.forward_rates_of_progress_ddP + drop += self.gas.forward_rates_of_progress_ddC * dcdp + drop_num = self.rop_ddP(mode="forward") self.assertNear(drop[self.rxn_idx], drop_num, self.rtol) def test_reverse_rop_ddP(self): @@ -281,9 +279,9 @@ def test_reverse_rop_ddP(self): # constant temperature - need to account for density change dcdp = self.gas.density_mole / self.gas.P - drop = self.gas.reverse_rop_pressure_derivatives - drop += self.gas.reverse_rop_concentration_derivatives * dcdp - drop_num = self.rop_ddP(mode="reverse") #, const_p=True) + drop = self.gas.reverse_rates_of_progress_ddP + drop += self.gas.reverse_rates_of_progress_ddC * dcdp + drop_num = self.rop_ddP(mode="reverse") self.assertNear(drop[self.rxn_idx], drop_num, self.rtol) def test_net_rop_ddP(self): @@ -291,9 +289,9 @@ def test_net_rop_ddP(self): # constant temperature - need to account for density change dcdp = self.gas.density_mole / self.gas.P - drop = self.gas.net_rop_pressure_derivatives - drop += self.gas.net_rop_concentration_derivatives * dcdp - drop_num = self.rop_ddP(mode="net") #, const_p=True) + drop = self.gas.net_rates_of_progress_ddP + drop += self.gas.net_rates_of_progress_ddC * dcdp + drop_num = self.rop_ddP(mode="net") self.assertNear(drop[self.rxn_idx], drop_num, self.rtol) def rate_ddX(self, spc_ix, mode=None, const_t=True, rtol_deltac=1e-6, atol_deltac=1e-20): @@ -329,8 +327,8 @@ def calc(mode): def test_creation_ddX(self): # check derivatives of creation rates with respect to mole fractions - drate = self.gas.creation_rate_species_derivatives - dratep = self.gas.creation_rate_pressure_derivatives + drate = self.gas.creation_rate_ddX + dratep = self.gas.creation_rate_ddP for spc_ix in self.rix + self.pix: drate_num = self.rate_ddX(spc_ix, "creation") ix = drate[:, spc_ix] != 0 @@ -339,8 +337,8 @@ def test_creation_ddX(self): def test_destruction_ddX(self): # check derivatives of destruction rates with respect to mole fractions - drate = self.gas.destruction_rate_species_derivatives - dratep = self.gas.destruction_rate_pressure_derivatives + drate = self.gas.destruction_rate_ddX + dratep = self.gas.destruction_rate_ddP for spc_ix in self.rix + self.pix: drate_num = self.rate_ddX(spc_ix, "destruction") ix = drate[:, spc_ix] != 0 @@ -349,8 +347,8 @@ def test_destruction_ddX(self): def test_net_production_ddX(self): # check derivatives of destruction rates with respect to mole fractions - drate = self.gas.net_production_rate_species_derivatives - dratep = self.gas.net_production_rate_pressure_derivatives + drate = self.gas.net_production_rate_ddX + dratep = self.gas.net_production_rate_ddP for spc_ix in self.rix + self.pix: drate_num = self.rate_ddX(spc_ix, "net") ix = drate[:, spc_ix] != 0 @@ -403,17 +401,17 @@ def setUpClass(cls): cls.ix3b = list(range(cls.gas.n_species)) def test_thirdbodies_forward(self): - drop = self.gas.forward_rop_species_derivatives + drop = self.gas.forward_rates_of_progress_ddX self.gas.derivative_settings = {"skip-third-bodies": True} - drops = self.gas.forward_rop_species_derivatives + drops = self.gas.forward_rates_of_progress_ddX dropm = drop - drops rop = self.gas.forward_rates_of_progress self.assertNear(rop[self.rxn_idx], (dropm[self.rxn_idx] * self.gas.X).sum()) def test_thirdbodies_reverse(self): - drop = self.gas.reverse_rop_species_derivatives + drop = self.gas.reverse_rates_of_progress_ddX self.gas.derivative_settings = {"skip-third-bodies": True} - drops = self.gas.reverse_rop_species_derivatives + drops = self.gas.reverse_rates_of_progress_ddX dropm = drop - drops rop = self.gas.reverse_rates_of_progress self.assertNear(rop[self.rxn_idx], (dropm[self.rxn_idx] * self.gas.X).sum()) @@ -480,8 +478,17 @@ def setUpClass(cls): # species: [AR, O, H2, H, OH, O2, H2O, H2O2, HO2] cls.gas.X = [0.1, 3e-4, 5e-5, 6e-6, 3e-3, 0.6, 0.25, 1e-6, 2e-5] cls.gas.TP = 2000, 5 * ct.one_atm + + # suppress user warning (e.g. temperature derivative of Blowers-Masel) + cls.warnings_suppressed = ct.warnings_suppressed() + ct.suppress_warnings() + super().setUpClass() + @classmethod + def tearDownClass(cls): + if not cls.warnings_suppressed: + ct.make_warnings_fatal() class TestPlog(FromScratchCases, utilities.CanteraTest): # Plog reaction @@ -505,15 +512,15 @@ class TestBlowersMasel(FromScratchCases, utilities.CanteraTest): @utilities.unittest.skip("change of reaction enthalpy is not considered") def test_forward_rop_ddT(self): - pass + super().test_forward_rop_ddT() @utilities.unittest.skip("change of reaction enthalpy is not considered") def test_reverse_rop_ddT(self): - pass + super().test_reverse_rop_ddT() @utilities.unittest.skip("change of reaction enthalpy is not considered") def test_net_rop_ddT(self): - pass + super().test_net_rop_ddT() class FullTests: @@ -560,8 +567,8 @@ def calc(): def test_forward_rop_ddX(self): # check forward rop against numerical derivative with respect to mole fractions - drop = self.gas.forward_rop_species_derivatives - dropp = self.gas.forward_rop_pressure_derivatives + drop = self.gas.forward_rates_of_progress_ddX + dropp = self.gas.forward_rates_of_progress_ddP drop_num = self.rop_ddX(mode="forward") stoich = self.gas.reactant_stoich_coeffs3 for i in range(self.gas.n_reactions): @@ -578,8 +585,8 @@ def test_forward_rop_ddX(self): def test_reverse_rop_ddX(self): # check reverse rop against numerical derivative with respect to mole fractions - drop = self.gas.reverse_rop_species_derivatives - dropp = self.gas.reverse_rop_pressure_derivatives + drop = self.gas.reverse_rates_of_progress_ddX + dropp = self.gas.reverse_rates_of_progress_ddP drop_num = self.rop_ddX(mode="reverse") stoich = self.gas.product_stoich_coeffs3 for i in range(self.gas.n_reactions): @@ -596,8 +603,8 @@ def test_reverse_rop_ddX(self): def test_net_rop_ddX(self): # check net rop against numerical derivative with respect to mole fractions - drop = self.gas.net_rop_species_derivatives - dropp = self.gas.net_rop_pressure_derivatives + drop = self.gas.net_rates_of_progress_ddX + dropp = self.gas.net_rates_of_progress_ddP drop_num = self.rop_ddX(mode="net") stoich = self.gas.product_stoich_coeffs3 - self.gas.reactant_stoich_coeffs3 for i in range(self.gas.n_reactions): @@ -633,24 +640,24 @@ def calc(): def test_forward_rop_ddT(self): # check forward rop against numerical derivative with respect to temperature dcdt = - self.gas.density_mole / self.gas.T - drop = self.gas.forward_rop_temperature_derivatives - drop += self.gas.forward_rop_concentration_derivatives * dcdt + drop = self.gas.forward_rates_of_progress_ddT + drop += self.gas.forward_rates_of_progress_ddC * dcdt drop_num = self.rop_ddT(mode="forward") self.assertArrayNear(drop, drop_num, self.rtol) def test_reverse_rop_ddT(self): # check reverse rop against numerical derivative with respect to temperature dcdt = - self.gas.density_mole / self.gas.T - drop = self.gas.reverse_rop_temperature_derivatives - drop += self.gas.reverse_rop_concentration_derivatives * dcdt + drop = self.gas.reverse_rates_of_progress_ddT + drop += self.gas.reverse_rates_of_progress_ddC * dcdt drop_num = self.rop_ddT(mode="reverse") self.assertArrayNear(drop, drop_num, self.rtol) def test_net_rop_ddT(self): # check net rop against numerical derivative with respect to temperature dcdt = - self.gas.density_mole / self.gas.T - drop = self.gas.net_rop_temperature_derivatives - drop += self.gas.net_rop_concentration_derivatives * dcdt + drop = self.gas.net_rates_of_progress_ddT + drop += self.gas.net_rates_of_progress_ddC * dcdt drop_num = self.rop_ddT(mode="net") try: self.assertArrayNear(drop, drop_num, self.rtol) diff --git a/interfaces/cython/cantera/test/test_reaction.py b/interfaces/cython/cantera/test/test_reaction.py index 1b9950f123..8275be7908 100644 --- a/interfaces/cython/cantera/test/test_reaction.py +++ b/interfaces/cython/cantera/test/test_reaction.py @@ -133,6 +133,15 @@ def setUpClass(cls): ct.use_legacy_rate_constants(False) cls.gas = ct.Solution("kineticsfromscratch.yaml") + # suppress user warning (e.g. temperature derivative of Blowers-Masel) + cls.warnings_suppressed = ct.warnings_suppressed() + ct.suppress_warnings() + + @classmethod + def tearDownClass(cls): + if not cls.warnings_suppressed: + ct.make_warnings_fatal() + def setUp(self): self.gas.X = "H2:0.1, H2O:0.2, O2:0.7, O:1e-4, OH:1e-5, H:2e-5, H2O2:1e-7" self.gas.TP = 900, 2 * ct.one_atm @@ -215,9 +224,6 @@ def test_with_units(self): def test_temperature_derivative(self): # check temperature derivative against numerical derivative - warnings_suppressed = ct.warnings_suppressed() - ct.suppress_warnings() - deltaT = self.gas.derivative_settings["rtol-delta"] deltaT *= self.gas.T rate = self.from_yaml() @@ -225,15 +231,12 @@ def test_temperature_derivative(self): # derivative at constant pressure dcdt = - self.gas.density_mole / self.gas.T - drate = self.gas.forward_rate_constants_temperature_derivatives - drate += self.gas.forward_rate_constants_concentration_derivatives * dcdt + drate = self.gas.forward_rate_constants_ddT + drate += self.gas.forward_rate_constants_ddC * dcdt self.gas.TP = self.gas.T + deltaT, self.gas.P k1 = self.eval(rate) self.assertNear((k1 - k0) / deltaT, drate[self._index], 1e-6) - if warnings_suppressed: - ct.make_warnings_fatal() - def test_pressure_derivative(self): # check pressure derivative against numerical derivative deltaP = self.gas.derivative_settings["rtol-delta"] @@ -241,7 +244,7 @@ def test_pressure_derivative(self): rate = self.from_yaml() k0 = self.eval(rate) - drate = self.gas.forward_rate_constants_pressure_derivatives + drate = self.gas.forward_rate_constants_ddP self.gas.TP = self.gas.T, self.gas.P + deltaP k1 = self.eval(rate) self.assertNear((k1 - k0) / deltaP, drate[self._index], 1e-6) @@ -296,7 +299,7 @@ def test_temperature_derivative_exact(self): scaled_ddT = (Ea / R / T + b) / T - dkdT = self.gas.forward_rate_constants_temperature_derivatives[self._index] + dkdT = self.gas.forward_rate_constants_ddT[self._index] self.assertNear(dkdT, k0 * scaled_ddT) # exact dT = 1.e-6 @@ -404,9 +407,6 @@ def test_data(self): rate.falloff_coeffs = np.random.rand(n) def test_temperature_derivative(self): - warnings_suppressed = ct.warnings_suppressed() - ct.suppress_warnings() - pert = self.gas.derivative_settings["rtol-delta"] deltaT = self.gas.T * pert TP = self.gas.TP @@ -414,7 +414,7 @@ def test_temperature_derivative(self): k0 = self.eval(rate) # derivative at constant volume - drate = self.gas.forward_rate_constants_temperature_derivatives + drate = self.gas.forward_rate_constants_ddT self.gas.TP = self.gas.T * (1 + pert), self.gas.P * (1 + pert) k1 = self.eval(rate) self.assertNear((k1 - k0) / deltaT, drate[self._index], 1e-6) @@ -422,14 +422,11 @@ def test_temperature_derivative(self): # derivative at constant pressure self.gas.TP = TP dcdt = - self.gas.density_mole / self.gas.T - drate += self.gas.forward_rate_constants_concentration_derivatives * dcdt + drate += self.gas.forward_rate_constants_ddC * dcdt self.gas.TP = self.gas.T * (1 + pert), self.gas.P k1 = self.eval(rate) self.assertNear((k1 - k0) / deltaT, drate[self._index], 1e-6) - if warnings_suppressed: - ct.make_warnings_fatal() - def test_pressure_derivative(self): pert = self.gas.derivative_settings["rtol-delta"] deltaP = self.gas.P * pert @@ -437,9 +434,9 @@ def test_pressure_derivative(self): k0 = self.eval(rate) # derivative at constant temperature - drate = self.gas.forward_rate_constants_pressure_derivatives + drate = self.gas.forward_rate_constants_ddP dcdp = self.gas.density_mole / self.gas.P - drate += self.gas.forward_rate_constants_concentration_derivatives * dcdp + drate += self.gas.forward_rate_constants_ddC * dcdp self.gas.TP = self.gas.T, self.gas.P + deltaP k1 = self.eval(rate) self.assertNear((k1 - k0) / deltaP, drate[self._index], 1e-6)