Esempio n. 1
0
    def test_row_sums(self):
        """
        Purpose: The sum of the entries in coeffs_temp should equal temp_dot.
        The sum of the entries in each row of coeffs_y should equal
        numpy.asarray([ydot]).transpose().

        Arguments:
        None

        Returns:
        None

        """
        (coeffs_temp,
         coeffs_y,
         rhs_temp,
         rhs_y) = chemReduce.error_constraint_data(self.state,
            self.gas, self.mass_stoich_prod, self.atol, self.rtol)

        # Test identity for temperature
        rhs_temp_test = self.atol[0] + self.rtol[0] * numpy.sum(coeffs_temp)
        self.assertAlmostEqual(numpy.max(abs(rhs_temp_test - rhs_temp)), 0,
                               delta=self.float_tol)

        # Test identity for each species
        rhs_y_test = numpy.zeros(self.gas.nSpecies())
        for j in range(0, self.gas.nSpecies()):
            rhs_y_test[j] = (self.atol[j + 1] + self.rtol[j + 1] *
                             numpy.sum(coeffs_y[j,:]))

        self.assertAlmostEqual(numpy.max(abs(rhs_y_test - rhs_y)), 0,
                               delta=self.float_tol)
Esempio n. 2
0
    def test_naive_summation(self):
        """
        Purpose: Calculate the entries of coeffs_temp, coeffs_y, rhs_temp,
        rhs_y using loops instead of vectorizing. Will be slow, but should
        yield same answer.

        Arguments:
        None

        Returns:
        None
        """

        molarMass = self.gas.molarMasses()
        stoichMatrix = (self.gas.productStoichCoeffs() -
            self.gas.reactantStoichCoeffs())

        coeffs_y_loop = numpy.zeros((self.gas.nSpecies(),
                                    self.gas.nReactions()))
        coeffs_temp_loop = numpy.zeros(self.gas.nReactions())

        for i in range(0, self.gas.nReactions()):
            coeffs_temp_loop[i] = numpy.sum(
                [self.enthalpy_mass[j] * molarMass[j] * stoichMatrix[j,i] *
                 self.rxn_rate[i] / (self.cp_mass * self.rho)
                 for j in range(0, self.gas.nSpecies())])
            for j in range(0, self.gas.nSpecies()):
                coeffs_y_loop[j,i] = (molarMass[j] * stoichMatrix[j,i] *
                    self.rxn_rate[i] / self.rho)

        temp_dot = numpy.sum(coeffs_temp_loop)
        y_dot = numpy.sum(coeffs_y_loop, axis=1)

        rhs_temp_loop = self.atol[0] + self.rtol[0] * abs(temp_dot)
        rhs_y_loop = numpy.zeros(self.gas.nSpecies())
        for j in range(0, self.gas.nSpecies()):
            rhs_y_loop[j] = self.atol[j+1] + self.rtol[j+1] * abs(y_dot[j])

        (coeffs_temp,
         coeffs_y,
         rhs_temp,
         rhs_y) = chemReduce.error_constraint_data(self.state,
            self.gas, self.mass_stoich_prod, self.atol, self.rtol)

        self.assertAlmostEqual(rhs_temp, rhs_temp_loop, delta=self.float_tol)

        self.assertAlmostEqual(numpy.max(abs(rhs_y - rhs_y_loop)), 0,
                               delta=self.float_tol)

        self.assertAlmostEqual(numpy.max(abs(coeffs_temp - coeffs_temp)), 0,
                               delta=self.float_tol)

        self.assertAlmostEqual(numpy.max(abs(coeffs_y - coeffs_y_loop)), 0,
                               delta=self.float_tol)
Esempio n. 3
0
    def test_col_sums(self):
        """
        Purpose: The sum of over each column in coeffs_y, where each row is
        scaled by enthalpy_mass[j] / cp_mass, should equal coeffs_t.

        Arguments:
        None

        Returns:
        None
        """
        (coeffs_temp,
         coeffs_y,
         _,
         _) = chemReduce.error_constraint_data(self.state,
            self.gas, self.mass_stoich_prod, self.atol, self.rtol)

        row_total = numpy.zeros(self.gas.nReactions())
        for j in range(0, self.gas.nSpecies()):
            row_total += self.enthalpy_mass[j] * coeffs_y[j] / self.cp_mass

        self.assertAlmostEqual(numpy.max(abs(row_total - coeffs_temp)), 0,
                               delta = self.float_tol)