コード例 #1
0
def test_ReactionCoeff_constant_with_T():
    """Test when reaction rate coefficient is constant but T entered for some reason
    (should have no effect)"""
    k_parameters = {'k': 10}
    T = 10
    k_test = ReactionRateCoeffs.ReactionCoeff(k_parameters, T).k
    assert k_test == 10
コード例 #2
0
def test_ReactionCoeff_mod_arrhenius_changing_R():
    """Test when reaction rate coefficient is modified
    Arrhenius but R is changed by user"""
    k_parameters = {'A': 10, 'E': 100, 'R': 10.453, 'b': 0.5}
    T = 10
    with pytest.raises(UserWarning):
        k_test = ReactionRateCoeffs.ReactionCoeff(k_parameters, T).k
コード例 #3
0
def test_ReactionCoeff_mod_arrhenius_invalid_R():
    """Test when reaction rate coefficient is modified 
    Arrhenius but R is invalid (non-positive)"""
    k_parameters = {'A': 10, 'E': 100, 'R': -100, 'b': 0.5}
    T = 10
    with pytest.raises(ValueError):
        k_test = ReactionRateCoeffs.ReactionCoeff(k_parameters, T).k
コード例 #4
0
def test_ReactionCoeff_mod_arrhenius_invalid_b():
    """Test when reaction rate coefficient is modified
    Arrhenius but B is invalid (not real)"""
    k_parameters = {'A': 10, 'E': 100, 'b': 0.5j}
    T = 10
    with pytest.raises(TypeError):
        k_test = ReactionRateCoeffs.ReactionCoeff(k_parameters, T).k
コード例 #5
0
def test_backward_coeff():
    """Returns a working (but artificial) example of
    backward reaction rate coefficient."""
    expected_nasa = numpy.array([[1, 0, 0, 0, 0, 0, 0], [1, 0, 0, 0, 0, 0, 0],
                                 [1, 0, 0, 0, 0, 0, 0]])
    k_f = 100
    nu_i = numpy.array([-2, -1, 2])
    bkwd_coeff = ReactionRateCoeffs.BackwardCoeff(nu_i, expected_nasa)
    return bkwd_coeff
コード例 #6
0
    def compute_reaction_rate_coeff(self, T=None):
        """Computes reaction rate coefficients of reaction.

        INPUTS:
        -------
        T : float
            temperature of reaction, in K

        RETURNS:
        --------
        kf : numeric type (or list of numeric type)
            forward reaction rate coefficient
        kb : numeric type (or list of numeric type)
            backward reaction rate coefficient

        NOTES:
        ------
        PRE:
            - Raises ValueError if NASA polynomial coefficients have not been
                set before trying to compute reaction rate coefficients
                (See class function set_NASA_poly_coefs())
        """
        coeffs = ReactionRateCoeffs.ReactionCoeff(self.rate_coeffs_components,
                                                  T=self.temperature)
        self.forward_rxn_rate_coeff = coeffs.k

        reactant_stoich_coeffs = numpy.array(
            self.order_dictionaries(self.reactant_stoich_coeffs))
        product_stoich_coeffs = numpy.array(
            self.order_dictionaries(self.product_stoich_coeffs))
        nui = product_stoich_coeffs - reactant_stoich_coeffs

        if (self.NASA_poly_coefs is None):
            raise ValueError(
                "Must set NASA polynomial coefficients before computing rxn rate coefficients!"
            )

        back_coeffs = ReactionRateCoeffs.BackwardCoeff(nui,
                                                       self.NASA_poly_coefs)
        self.backward_rxn_rate_coeff = back_coeffs.compute_backward_coeffs(
            self.forward_rxn_rate_coeff, self.temperature)
        return self.forward_rxn_rate_coeff, self.backward_rxn_rate_coeff
コード例 #7
0
    def compute_reaction_rate_coeff(self, T=None):
        """Computes reaction rate coefficients of reaction.

        INPUTS:
        -------
        T : float
            temperature of reaction, in K

        RETURNS:
        --------
        k : numeric type (or list of numeric type)
            Reaction rate coefficient
        """
        T = self.temperature
        k = ReactionRateCoeffs.ReactionCoeff(self.rate_coeffs_components,
                                             T=self.temperature).k
        self.rxn_rate_coeff = k
        return k
コード例 #8
0
def test_ReactionCoeff_mod_arrhenius():
    """Test when reaction rate coefficient is modified Arrhenius"""
    k_parameters = {'A': 10**7, 'E': 10**3, 'b': 0.5}
    T = 10**2
    k_test = ReactionRateCoeffs.ReactionCoeff(k_parameters, T).k
    assert numpy.isclose(k_test, 30035490.8896)
コード例 #9
0
def test_ReactionCoeff_arrhenius_invalid_T():
    """Test when reaction rate coefficient is Arrhenius but T is invalid (non-positive)"""
    k_parameters = {'A': 10, 'E': 100}
    T = -10
    with pytest.raises(ValueError):
        k_test = ReactionRateCoeffs.ReactionCoeff(k_parameters, T).k
コード例 #10
0
def test_ReactionCoeff_arrhenius_T_not_set():
    """Test when reaction rate coefficient is Arrhenius but T is not set by user"""
    k_parameters = {'A': 10, 'E': 100}
    with pytest.raises(ValueError):
        k_test = ReactionRateCoeffs.ReactionCoeff(k_parameters).k
コード例 #11
0
def test_ReactionCoeff_invalid_constant():
    """Test when reaction rate coefficient is constant but invalid (non-positive)"""
    k_parameters = {'k': -10}
    with pytest.raises(ValueError):
        k_test = ReactionRateCoeffs.ReactionCoeff(k_parameters).k
コード例 #12
0
def test_ReactionCoeff_constant_with_others():
    """Test when reaction rate coefficient and A', 'b', 'E' all exists"""
    k_parameters = {'k': 10, 'A': 10**7, "q": 8}
    with pytest.raises(ValueError) as excinfo:
        k_test = ReactionRateCoeffs.ReactionCoeff(k_parameters).k
コード例 #13
0
def test_ReactionCoeff_constant():
    """Test when reaction rate coefficient is constant"""
    k_parameters = {'k': 10}
    k_test = ReactionRateCoeffs.ReactionCoeff(k_parameters).k
    assert k_test == 10