Esempio n. 1
0
    def __init__(self, tov_solver_config):

        self.__config = tov_solver_config

        # TODO: File name must be read from config file.
        self.__eos = EoS(
            filename=self.__config.getEoSFileName(),
            central_energy_density=self.__config.getCentralEnergy(),
            verbose=False)
Esempio n. 2
0
    def __init__(self, tov_solver_config):

        self.__config = tov_solver_config

        # TODO: File name must be read from config file.
        self.__eos = EoS(filename=self.__config.getEoSFileName(),
                         central_energy_density=self.__config.getCentralEnergy(),
                         verbose=False)
Esempio n. 3
0
class TOVSolver:
    """ TOV equation solver. """
    def __init__(self, tov_solver_config):

        self.__config = tov_solver_config

        # TODO: File name must be read from config file.
        self.__eos = EoS(
            filename=self.__config.getEoSFileName(),
            central_energy_density=self.__config.getCentralEnergy(),
            verbose=False)

    def evaluate(self, epsilon, pressure):

        eval_epsilon = 0
        eval_pressure = 0

        pressure_0 = self.__eos.pressure_from_energy(1.)
        # pressure_0 = 0

        if epsilon > 0:
            eval_pressure = self.__eos.pressure_from_energy(epsilon)

        if pressure > 0:
            eval_epsilon = self.__eos.energy_from_pressure(pressure)

        self.output_interpolation_header(
            self.__config.getConfigFileName(), self.__config.getEoSFileName(),
            self.__config.getCentralEnergy(),
            pressure_0 * self.__config.getCentralEnergy(),
            eval_epsilon * self.__config.getCentralEnergy(),
            eval_pressure * self.__config.getCentralEnergy())

    def run(self):

        tov_equations = TOVEquations(self.__eos)

        # Initial conditions, all values dimensionless.
        mass_0 = 0
        energy_0 = 1
        pressure_0 = float(self.__eos.pressure_from_energy(energy_0))

        self.output_header(self.__config.getConfigFileName(),
                           self.__config.getEoSFileName(),
                           self.__config.getCentralEnergy(),
                           pressure_0 * self.__config.getCentralEnergy(),
                           self.__config.getTransitionPressure(),
                           self.__config.getCutoffDensity(),
                           self.__config.getRadiusScaleFactor(),
                           self.__config.getMassScaleFactor())

        rk_parameters = RungeKuttaParameters(
            first_element=self.__config.rk_inferior_lim,
            last_element=self.__config.rk_superior_lim,
            rk_steps=self.__config.rk_ode_steps,
            derivatives=[
                tov_equations.delta_m_delta_eta,
                tov_equations.delta_p_delta_eta
            ],
            initial_conditions=[mass_0, pressure_0],
            verbose=False)

        # print("self.__config.getCutoffDensity() = {}".format(type(self.__config.getCutoffDensity())))
        # print("self.__config.getCentralEnergy() = {}".format(type(self.__config.getCentralEnergy())))

        rk4 = TOVRungeKutta(
            rk_parameters=rk_parameters,
            central_energy=self.__config.getCentralEnergy(),
            cutoff_density=self.__config.getCutoffDensity() *
            const.LIGHT_SPEED_SQUARED,
            transition_pressure=self.__config.getTransitionPressure())

        # Debugging purposes
        # self.solve_via_scipy(rk_parameters, tov_equations)

        # TODO: this part can be improved.

        rk4.run()

        results = rk4.get_result()

        star_mass = results.mass * self.__config.getMassScaleFactor(
        ) / const.SUN_MASS

        # The result is dimensionless. It must be converted to km.
        star_radius = results.eta * self.__config.getRadiusScaleFactor(
        ) * const.LENGTH_TO_KM

        radius_phase_transition_bar = results.radius_phase_transition_bar * \
            self.__config.getRadiusScaleFactor() * const.LENGTH_TO_KM

        quark_core_mass = results.mass_quark_core_bar * self.__config.getMassScaleFactor(
        ) / const.SUN_MASS

        self.output_summary(star_mass, quark_core_mass, star_radius, 0,
                            radius_phase_transition_bar, 0, 0, 0)

        # eta = np.linspace(self.__inferior_lim, self.__superior_lim, self.__ode_steps)
        #
        # for solution in tov_solution:
        #     plt.plot(eta, solution, label='Pressure')
        #
        #     # plot results
        #     print("Plotting...")
        #     plt.grid(True)
        #     plt.figure(2)

    def output_header(self, config_file_name, eos_file_name, epsilon_0,
                      pressure_0, transition_pressure, cutoff_density,
                      scale_radius, scale_mass):

        header_format = \
            ("#--------------------------------------------------------------------------------------------#\n"
             "#--------------------------------  TOV Solver - Solver Mode  --------------------------------#\n"
             "#--------------------------------------------------------------------------------------------#\n"
             "#                                         PARAMETERS                                         #\n"
             "#--------------------------------------------------------------------------------------------#\n"
             "# CONFIG FILE            : {}\n"
             "# EOS FILE               : {}\n"
             "# EPSILON_0 (erg/cm3)    : {}\n"
             "# PRESSURE_0             : {}\n"
             "# TRANSITION_PRESSURE    : {}\n"
             "# CUTOFF_DENSITY (g/cm3) : {}\n"
             "# SCALE_RADIUS (cm)      : {:0.05e}\n"
             "# SCALE_MASS (g)         : {:0.05e}")

        print(
            header_format.format(config_file_name, eos_file_name, epsilon_0,
                                 pressure_0, transition_pressure,
                                 cutoff_density, scale_radius, scale_mass))

    def output_summary(self, star_mass, quark_core_mass, star_radius,
                       baryon_number, radius_phase_transition, info_entropy,
                       diseq, complexity):

        summary_format = \
            ("#\n"
             "#--------------------------------------------------------------------------------------------#\n"
             "#                                            SUMMARY                                         #\n"
             "#--------------------------------------------------------------------------------------------#\n"
             "#\n"
             "# Star Radius (km)              : {}\n"
             "# Quark Core Radius (km)        : {}\n"
             "#\n"
             "# Star Mass (Solar Units)       : {}\n"
             "# Quark Core Mass (Solar Units) : {}\n"
             "#\n"
             "# Baryon Number                 : {}\n"
             "#\n"
             "# Information Entropy           : {}\n"
             "# Disequilibrium                : {}\n"
             "# Complexity                    : {}\n"
             "#\n"
             "#--------------------------------------------------------------------------------------------#\n")

        print(
            summary_format.format(
                star_radius,
                radius_phase_transition if radius_phase_transition > 0 else 0,
                star_mass, quark_core_mass if quark_core_mass > 0 else 0,
                baryon_number, info_entropy, diseq, complexity))

    def output_interpolation_header(self, config_file_name, eos_file_name,
                                    epsilon_0, pressure_0, epsilon, pressure):

        header_format = \
            ("#--------------------------------------------------------------------------------------------#\n"
             "#----------------------------  TOV Solver - Interpolation Mode  -----------------------------#\n"
             "#--------------------------------------------------------------------------------------------#\n"
             "# Config File          : {}\n"
             "# EoS File             : {}\n"
             "# RHO_0 (g/cm^3)       : {:10e}\n"
             "# EPSILON_0 (erg/cm^3) : {:10e}\n"
             "# PRESSURE_0           : {:10e}\n"
             "#--------------------------------------------------------------------------------------------#\n"
             "# Epsilon              : {:10e}\n"
             "# Epsilon (adim)       : {:10e}\n"
             "# Pressure             : {:10e}\n"
             "# Pressure (adim)      : {:10e}\n"
             "#--------------------------------------------------------------------------------------------#\n")

        print(
            header_format.format(config_file_name, eos_file_name,
                                 epsilon_0 / const.LIGHT_SPEED**2., epsilon_0,
                                 pressure_0, epsilon, epsilon / epsilon_0,
                                 pressure, pressure / epsilon_0))

    def solve_via_scipy(self, rk_parameters, tov_equations):

        eta = np.linspace(rk_parameters.first_element,
                          rk_parameters.last_element, 1000)

        try:
            parameters = [0, 0]
            solutions = integrate.odeint(tov_equations.vector_field,
                                         rk_parameters.initial_conditions,
                                         eta,
                                         args=(parameters, ))

            mass_sol = solutions[:, 0]
            press_sol = solutions[:, 1]
        except:
            traceback.print_exc()

        plt.figure()
        #plt.plot(eta, mass_sol, label='Massa')
        plt.plot(eta, press_sol, label='Pressao')
        plt.xlabel('eta')
        #plt.ylabel('Massa')
        plt.ylabel('Pressao')
        plt.legend(loc=0)
Esempio n. 4
0
class TOVSolver:
    """ TOV equation solver. """

    def __init__(self, tov_solver_config):

        self.__config = tov_solver_config

        # TODO: File name must be read from config file.
        self.__eos = EoS(filename=self.__config.getEoSFileName(),
                         central_energy_density=self.__config.getCentralEnergy(),
                         verbose=False)

    def evaluate(self, epsilon, pressure):

        eval_epsilon = 0
        eval_pressure = 0

        pressure_0 = self.__eos.pressure_from_energy(1.)
        # pressure_0 = 0

        if epsilon > 0:
            eval_pressure = self.__eos.pressure_from_energy(epsilon)

        if pressure > 0:
            eval_epsilon = self.__eos.energy_from_pressure(pressure)

        self.output_interpolation_header(self.__config.getConfigFileName(),
                                         self.__config.getEoSFileName(),
                                         self.__config.getCentralEnergy(),
                                         pressure_0 * self.__config.getCentralEnergy(),
                                         eval_epsilon * self.__config.getCentralEnergy(),
                                         eval_pressure * self.__config.getCentralEnergy())

    def run(self):
        tovEquations = TOVEquations(self.__eos)

        # Initial conditions, all values dimensionless.
        mass_0 = 0
        energy_0 = 1
        pressure_0 = float(self.__eos.pressure_from_energy(energy_0))

        self.output_header(self.__config.getConfigFileName(),
                           self.__config.getEoSFileName(),
                           self.__config.getCentralEnergy(),
                           pressure_0 * self.__config.getCentralEnergy(),
                           self.__config.getTransitionPressure(),
                           self.__config.getCutoffDensity(),
                           self.__config.getRadiusScaleFactor(),
                           self.__config.getMassScaleFactor())

        rk_parameters = RungeKuttaParameters(
            first_element=self.__config.rk_inferior_lim,
            last_element=self.__config.rk_superior_lim,
            rk_steps=self.__config.rk_ode_steps,
            derivatives=[tovEquations.delta_M_delta_eta, tovEquations.delta_P_delta_eta],
            initial_conditions=[mass_0, pressure_0],
            verbose=False)

        # print("self.__config.getCutoffDensity() = {}".format(type(self.__config.getCutoffDensity())))
        # print("self.__config.getCentralEnergy() = {}".format(type(self.__config.getCentralEnergy())))

        rk4 = TOVRungeKutta(rk_parameters=rk_parameters,
                            central_energy=self.__config.getCentralEnergy(),
                            cutoff_density=self.__config.getCutoffDensity() * const.LIGHT_SPEED ** 2.,
                            transition_pressure=self.__config.getTransitionPressure())

        rk4.run()

        # TODO: this part can be improved.

        results = rk4.getResult()

        star_mass = results.mass * self.__config.getMassScaleFactor() / const.SUN_MASS

        # The result is dimensionless. It must be converted to km.
        star_radius = results.eta * self.__config.getRadiusScaleFactor() * const.LENGTH_TO_KM

        radius_phase_transition_bar = results.radius_phase_transition_bar * \
                                      self.__config.getRadiusScaleFactor() * const.LENGTH_TO_KM

        quark_core_mass = results.mass_quark_core_bar * self.__config.getMassScaleFactor() / const.SUN_MASS

        self.output_summary(star_mass, quark_core_mass, star_radius, 0, radius_phase_transition_bar, 0, 0, 0)

        # eta = np.linspace(self.__inferior_lim, self.__superior_lim, self.__ode_steps)
        #
        # for solution in tov_solution:
        #     plt.plot(eta, solution, label='Pressure')
        #
        #     # plot results
        #     print("Plotting...")
        #     plt.grid(True)
        #     plt.figure(2)

    def output_header(self,
                      config_file_name,
                      eos_file_name,
                      epsilon_0,
                      pressure_0,
                      transition_pressure,
                      cutoff_density,
                      scale_radius,
                      scale_mass):

        header_format = \
            ("#--------------------------------------------------------------------------------------------#\n"
             "#--------------------------------  TOV Solver - Solver Mode  --------------------------------#\n"
             "#--------------------------------------------------------------------------------------------#\n"
             "#                                         PARAMETERS                                         #\n"
             "#--------------------------------------------------------------------------------------------#\n"
             "# CONFIG FILE            : {}\n"
             "# EOS FILE               : {}\n"
             "# EPSILON_0 (g/cm3)      : {}\n"
             "# PRESSURE_0             : {}\n"
             "# TRANSITION_PRESSURE    : {}\n"
             "# CUTOFF_DENSITY (g/cm3) : {}\n"
             "# SCALE_RADIUS (cm)      : {:0.05e}\n"
             "# SCALE_MASS (g)         : {:0.05e}")

        print(header_format.format(config_file_name,
                                   eos_file_name,
                                   epsilon_0,
                                   pressure_0,
                                   transition_pressure,
                                   cutoff_density,
                                   scale_radius,
                                   scale_mass))

    def output_summary(self,
                       star_mass,
                       quark_core_mass,
                       star_radius,
                       baryon_number,
                       radius_phase_transition,
                       info_entropy,
                       diseq,
                       complexity):

        summary_format = \
            ("#\n"
             "#--------------------------------------------------------------------------------------------#\n"
             "#                                            SUMMARY                                         #\n"
             "#--------------------------------------------------------------------------------------------#\n"
             "#\n"
             "# Star Radius (km)              : {}\n"
             "# Quark Core Radius (km)        : {}\n"
             "#\n"
             "# Star Mass (Solar Units)       : {}\n"
             "# Quark Core Mass (Solar Units) : {}\n"
             "#\n"
             "# Baryon Number                 : {}\n"
             "#\n"
             "# Information Entropy           : {}\n"
             "# Disequilibrium                : {}\n"
             "# Complexity                    : {}\n"
             "#\n"
             "#--------------------------------------------------------------------------------------------#\n")

        print(summary_format.format(star_radius,
                                    radius_phase_transition,
                                    star_mass,
                                    quark_core_mass,
                                    baryon_number,
                                    info_entropy,
                                    diseq,
                                    complexity))

    def output_interpolation_header(self,
                                    config_file_name,
                                    eos_file_name,
                                    epsilon_0,
                                    pressure_0,
                                    epsilon,
                                    pressure):

        header_format = \
            ("#--------------------------------------------------------------------------------------------#\n"
             "#----------------------------  TOV Solver - Interpolation Mode  -----------------------------#\n"
             "#--------------------------------------------------------------------------------------------#\n"
             "# Config File          : {}\n"
             "# EoS File             : {}\n"
             "# RHO_0 (g/cm^3)       : {:10e}\n"
             "# EPSILON_0 (erg/cm^3) : {:10e}\n"
             "# PRESSURE_0           : {:10e}\n"
             "#--------------------------------------------------------------------------------------------#\n"
             "# Epsilon              : {:10e}\n"
             "# Epsilon (adim)       : {:10e}\n"
             "# Pressure             : {:10e}\n"
             "# Pressure (adim)      : {:10e}\n"
             "#--------------------------------------------------------------------------------------------#\n")

        print(header_format.format(config_file_name,
                                   eos_file_name,
                                   epsilon_0 / const.LIGHT_SPEED ** 2.,
                                   epsilon_0,
                                   pressure_0,
                                   epsilon,
                                   epsilon / epsilon_0,
                                   pressure,
                                   pressure / epsilon_0))