Exemplo n.º 1
0
    def create_q_matrices(self):
        q_sn_ia = matrix.q_sn(constants.CHANDRASEKHAR_LIMIT,
                              feh=self.context["abundances"].feh(),
                              sn_yields=self.context["sn_yields"])
        imf_sn_file = open(f"{self.context['output_dir']}/imf_supernova_rates",
                           "w+")
        matrices_file = open(f"{self.context['output_dir']}/qm-matrices", "w+")
        if self.context["return_fractions"] is True:
            return_fraction_file = open(
                f"{self.context['output_dir']}/return_fractions", "w+")

        for i in range(0, self.total_time_steps):
            m_inf, m_sup = self.mass_intervals[i]
            q = np.zeros((constants.Q_MATRIX_ROWS, constants.Q_MATRIX_COLUMNS))
            phi, supernova_Ia_rates, supernova_II_rates, r = 0.0, 0.0, 0.0, 0.0

            if m_sup > constants.M_MIN and m_sup > m_inf:
                q += newton_cotes(
                    m_inf, m_sup, lambda m: global_imf(
                        m, self.initial_mass_function, self.context[
                            "binary_fraction"]) * matrix.q(m, self.context))

                supernova_Ia_rates = self.sn_Ia_rates[
                    i] * self.initial_mass_function.stars_per_mass_unit * dtd_correction(
                        self.context)
                q += q_sn_ia * supernova_Ia_rates

                phi = newton_cotes(
                    m_inf, m_sup,
                    lambda m: global_imf(m, self.initial_mass_function, self.
                                         context["binary_fraction"]))

                supernova_II_rates = newton_cotes(
                    m_inf, m_sup, lambda m: imf_supernovae_II(
                        m, self.initial_mass_function, self.context[
                            "binary_fraction"]))

                if self.context["return_fractions"] is True:
                    r = return_fraction(m_inf, m_sup, self.context["expelled"],
                                        self.initial_mass_function,
                                        self.context["binary_fraction"])

            np.savetxt(matrices_file,
                       q,
                       fmt="%15.10f",
                       header=self._matrix_header(m_sup, m_inf))
            imf_sn_file.write(
                f"  {phi:.10f}  {supernova_Ia_rates:.10f}  {supernova_II_rates:.10f}  {self.energies[i]:.10f}\n"
            )
            if self.context["return_fractions"] is True:
                return_fraction_file.write(f"{r:.10f}\n")

        matrices_file.close()
        imf_sn_file.close()
        if self.context["return_fractions"] is True:
            return_fraction_file.close()
Exemplo n.º 2
0
def test_cri_lim_exception(mocker):
    test_settings = {
        "z": 0.03,
        "abundances": abundances.select_abundances(np.random.choice(settings.valid_values["sol_ab"]), 0.03),
        "expelled": elements.Expelled(settings.default["expelled_elements_filename"]),
    }
    mocker.spy(abundances.Abundances, "abundance")
    mocker.spy(abundances.Abundances, "corrected_abundance_CRI_LIM")

    q = matrix.q(4, test_settings)

    abundances.Abundances.abundance.assert_called_once()
    abundances.Abundances.corrected_abundance_CRI_LIM.assert_not_called()

    test_settings["expelled"].cri_lim_yields = True

    q = matrix.q(4, test_settings)

    abundances.Abundances.corrected_abundance_CRI_LIM.assert_called_once()
Exemplo n.º 3
0
def test_matrices_are_empty_if_not_enough_mass():
    m = constants.M_MIN - 0.001
    test_settings = {
        "z": 0.03,
        "abundances": abundances.select_abundances(np.random.choice(settings.valid_values["sol_ab"]), 0.03),
        "expelled": elements.Expelled(settings.default["expelled_elements_filename"]),
    }

    assert np.all([i == 0 for i in matrix.q(m, test_settings)])
    assert np.all([i == 0 for i in matrix.q_sn(m)])
Exemplo n.º 4
0
def test_q_with_no_yield_corrections(mocker):
    m = constants.M_MIN + np.random.rand() * 40
    expelled = elements.Expelled(settings.default["expelled_elements_filename"])
    test_settings = {
                "z": 0.02,
                "abundances": abundances.select_abundances(np.random.choice(settings.valid_values["sol_ab"]), 0.02),
                "expelled": expelled,
            }

    mocker.spy(expelled, "for_mass")
    q = matrix.q(m, test_settings)
    expelled.for_mass.assert_called_once_with(m, {})
Exemplo n.º 5
0
def test_q_size():
    for m in [0.8, 1, 2, 4, 6, 8, 10, 40, 90]:
        for z in [0., 0.001, 0.01, 0.02, 0.03, 0.04, 0.05]:
            test_settings = {
                "z": z,
                "abundances": abundances.select_abundances(np.random.choice(settings.valid_values["sol_ab"]), z),
                "expelled": elements.Expelled(settings.default["expelled_elements_filename"]),
            }

            q = matrix.q(m, test_settings)

            assert q.shape == (constants.Q_MATRIX_ROWS, constants.Q_MATRIX_COLUMNS)