Пример #1
0
    def run(self, model, no_of_packets, no_of_virtual_packets=0, nthreads=1,last_run=False):
        """
        Running the TARDIS simulation

        Parameters
        ----------

        :param model:
        :param no_of_virtual_packets:
        :param nthreads:
        :return:
        """
        self.time_of_simulation = model.time_of_simulation
        self.volume = model.tardis_config.structure.volumes
        self._initialize_estimator_arrays(self.volume.shape[0],
                                          model.plasma.tau_sobolevs.shape)
        self._initialize_geometry_arrays(model.tardis_config.structure)

        self._initialize_packets(model.t_inner.value,
                                 no_of_packets)

        montecarlo.montecarlo_radial1d(
            model, self, virtual_packet_flag=no_of_virtual_packets,
            nthreads=nthreads,last_run=last_run)
        # Workaround so that j_blue_estimator is in the right ordering
        # They are written as an array of dimension (no_of_shells, no_of_lines)
        # but python expects (no_of_lines, no_of_shells)
        self.j_blue_estimator = np.ascontiguousarray(
                self.j_blue_estimator.flatten().reshape(
                self.j_blue_estimator.shape, order='F')
                )
        self.Edotlu_estimator = self.Edotlu_estimator.flatten().reshape(
                self.Edotlu_estimator.shape, order='F')
Пример #2
0
    def run(self, model, no_of_virtual_packets, nthreads=1):
        self.time_of_simulation = model.time_of_simulation
        self.volume = model.tardis_config.structure.volumes

        montecarlo.montecarlo_radial1d(
            model, self, virtual_packet_flag=no_of_virtual_packets,
            nthreads=nthreads)
Пример #3
0
    def run(self, model, no_of_packets, no_of_virtual_packets=0, nthreads=1):
        """
        Running the TARDIS simulation

        Parameters
        ----------

        :param model:
        :param no_of_virtual_packets:
        :param nthreads:
        :return:
        """
        self.time_of_simulation = model.time_of_simulation
        self.volume = model.tardis_config.structure.volumes
        self._initialize_estimator_arrays(
            self.volume.shape[0], model.plasma_array.tau_sobolevs.shape)
        self._initialize_geometry_arrays(model.tardis_config.structure)

        self._initialize_packets(model.t_inner.value, no_of_packets)

        montecarlo.montecarlo_radial1d(
            model,
            self,
            virtual_packet_flag=no_of_virtual_packets,
            nthreads=nthreads)
Пример #4
0
    def run(self, model, no_of_virtual_packets, nthreads=1):
        self.time_of_simulation = model.time_of_simulation
        self.volume = model.tardis_config.structure.volumes

        montecarlo.montecarlo_radial1d(
            model,
            self,
            virtual_packet_flag=no_of_virtual_packets,
            nthreads=nthreads)
Пример #5
0
 def run(self, model, no_of_virtual_packets, nthreads=1):
     self.time_of_simulation = model.time_of_simulation
     self.volume = model.tardis_config.structure.volumes
     self._initialize_montecarlo_arrays(model)
     self._initialize_geometry_arrays(model.tardis_config.structure)
     #1/0
     montecarlo.montecarlo_radial1d(
         model, self, virtual_packet_flag=no_of_virtual_packets,
         nthreads=nthreads)
Пример #6
0
    def run(self,
            model,
            plasma,
            no_of_packets,
            no_of_virtual_packets=0,
            nthreads=1,
            last_run=False):
        """
        Run the montecarlo calculation

        Parameters
        ----------
        model : tardis.model.Radial1DModel
        plasma : tardis.plasma.BasePlasma
        no_of_packets : int
        no_of_virtual_packets : int
        nthreads : int
        last_run : bool

        Returns
        -------
        None
        """
        self._integrator = FormalIntegrator(model, plasma, self)
        self.time_of_simulation = self.calculate_time_of_simulation(model)
        self.volume = model.volume
        self._initialize_estimator_arrays(self.volume.shape[0],
                                          plasma.tau_sobolevs.shape)
        self._initialize_geometry_arrays(model)

        self._initialize_packets(model.t_inner.value, no_of_packets)

        montecarlo.montecarlo_radial1d(
            model,
            plasma,
            self,
            virtual_packet_flag=no_of_virtual_packets,
            nthreads=nthreads,
            last_run=last_run)
        # Workaround so that j_blue_estimator is in the right ordering
        # They are written as an array of dimension (no_of_shells, no_of_lines)
        # but python expects (no_of_lines, no_of_shells)
        self.j_blue_estimator = np.ascontiguousarray(
            self.j_blue_estimator.flatten().reshape(
                self.j_blue_estimator.shape, order='F'))
        self.Edotlu_estimator = np.ascontiguousarray(
            self.Edotlu_estimator.flatten().reshape(
                self.Edotlu_estimator.shape, order='F'))
Пример #7
0
    def run(self, model, plasma, no_of_packets,
            no_of_virtual_packets=0, nthreads=1,
            last_run=False):
        """
        Run the montecarlo calculation

        Parameters
        ----------
        model : tardis.model.Radial1DModel
        plasma : tardis.plasma.BasePlasma
        no_of_packets : int
        no_of_virtual_packets : int
        nthreads : int
        last_run : bool

        Returns
        -------
        None
        """
        self._integrator = FormalIntegrator(
                model,
                plasma,
                self)
        self.time_of_simulation = self.calculate_time_of_simulation(model)
        self.volume = model.volume
        self._initialize_estimator_arrays(self.volume.shape[0],
                                          plasma.tau_sobolevs.shape)
        self._initialize_geometry_arrays(model)

        self._initialize_packets(model.t_inner.value,
                                 no_of_packets)

        montecarlo.montecarlo_radial1d(
            model, plasma, self,
            virtual_packet_flag=no_of_virtual_packets,
            nthreads=nthreads,
            last_run=last_run)
        # Workaround so that j_blue_estimator is in the right ordering
        # They are written as an array of dimension (no_of_shells, no_of_lines)
        # but python expects (no_of_lines, no_of_shells)
        self.j_blue_estimator = np.ascontiguousarray(
                self.j_blue_estimator.flatten().reshape(
                    self.j_blue_estimator.shape, order='F')
                )
        self.Edotlu_estimator = np.ascontiguousarray(
                self.Edotlu_estimator.flatten().reshape(
                    self.Edotlu_estimator.shape, order='F')
                )
Пример #8
0
    def run(self, model, no_of_virtual_packets, nthreads=1):
        """
        Running the TARDIS simulation

        Parameters
        ----------

        :param model:
        :param no_of_virtual_packets:
        :param nthreads:
        :return:
        """
        self.time_of_simulation = model.time_of_simulation
        self.volume = model.tardis_config.structure.volumes
        self._initialize_montecarlo_arrays(model)
        self._initialize_geometry_arrays(model.tardis_config.structure)

        self._initialize_packets(model.t_inner.value,
                                 model.current_no_of_packets)
        montecarlo.montecarlo_radial1d(
            model, self, virtual_packet_flag=no_of_virtual_packets,
            nthreads=nthreads)
Пример #9
0
    def run(self,
            model,
            no_of_packets,
            no_of_virtual_packets=0,
            nthreads=1,
            last_run=False):
        """
        Running the TARDIS simulation

        Parameters
        ----------

        :param model:
        :param no_of_virtual_packets:
        :param nthreads:
        :return:
        """
        self.time_of_simulation = model.time_of_simulation
        self.volume = model.tardis_config.structure.volumes
        self._initialize_estimator_arrays(self.volume.shape[0],
                                          model.plasma.tau_sobolevs.shape)
        self._initialize_geometry_arrays(model.tardis_config.structure)

        self._initialize_packets(model.t_inner.value, no_of_packets)

        montecarlo.montecarlo_radial1d(
            model,
            self,
            virtual_packet_flag=no_of_virtual_packets,
            nthreads=nthreads,
            last_run=last_run)
        # Workaround so that j_blue_estimator is in the right ordering
        # They are written as an array of dimension (no_of_shells, no_of_lines)
        # but python expects (no_of_lines, no_of_shells)
        self.j_blue_estimator = np.ascontiguousarray(
            self.j_blue_estimator.flatten().reshape(
                self.j_blue_estimator.shape, order='F'))
        self.Edotlu_estimator = self.Edotlu_estimator.flatten().reshape(
            self.Edotlu_estimator.shape, order='F')
Пример #10
0
    def run(self, model, no_of_packets, no_of_virtual_packets=0, nthreads=1):
        """
        Running the TARDIS simulation

        Parameters
        ----------

        :param model:
        :param no_of_virtual_packets:
        :param nthreads:
        :return:
        """
        self.time_of_simulation = model.time_of_simulation
        self.volume = model.tardis_config.structure.volumes
        self._initialize_estimator_arrays(self.volume.shape[0],
                                          model.plasma_array.tau_sobolevs.shape)
        self._initialize_geometry_arrays(model.tardis_config.structure)

        self._initialize_packets(model.t_inner.value,
                                 no_of_packets)

        montecarlo.montecarlo_radial1d(
            model, self, virtual_packet_flag=no_of_virtual_packets,
            nthreads=nthreads)
Пример #11
0
    def simulate(self,
                 update_radiation_field=True,
                 enable_virtual=False,
                 initialize_j_blues=False,
                 initialize_nlte=False):
        """
        Run a simulation
        """

        if update_radiation_field:
            t_inner_new = self.update_radiationfield()
        else:
            t_inner_new = self.t_inner

        self.calculate_j_blues(init_detailed_j_blues=initialize_j_blues)
        self.update_plasmas(initialize_nlte=initialize_nlte)

        self.t_inner = t_inner_new

        self.packet_src.create_packets(self.current_no_of_packets,
                                       self.t_inner.value)

        if enable_virtual:
            no_of_virtual_packets = self.tardis_config.montecarlo.no_of_virtual_packets
        else:
            no_of_virtual_packets = 0
        if np.any(np.isnan(self.plasma_array.tau_sobolevs.values)) or np.any(np.isinf(self.plasma_array.tau_sobolevs.values)) \
            or np.any(np.isneginf(self.plasma_array.tau_sobolevs.values)):
            raise ValueError(
                'Some tau_sobolevs are nan, inf, -inf in tau_sobolevs. Something went wrong!'
            )

        self.j_blue_estimators = np.zeros(
            (len(self.t_rads), len(self.atom_data.lines)))
        self.montecarlo_virtual_luminosity = np.zeros_like(
            self.spectrum.frequency.value)

        montecarlo_nu, montecarlo_energies, self.j_estimators, self.nubar_estimators, \
        last_line_interaction_in_id, last_line_interaction_out_id, \
        self.last_interaction_type, self.last_line_interaction_shell_id = \
            montecarlo.montecarlo_radial1d(self,
                                                     virtual_packet_flag=no_of_virtual_packets)

        if np.sum(montecarlo_energies < 0) == len(montecarlo_energies):
            logger.critical("No r-packet escaped through the outer boundary.")

        self.montecarlo_nu = montecarlo_nu * u.Hz
        self.montecarlo_luminosity = montecarlo_energies * 1 * u.erg / self.time_of_simulation


        montecarlo_reabsorbed_luminosity = -np.histogram(self.montecarlo_nu.value[self.montecarlo_luminosity.value < 0],
                                         weights=self.montecarlo_luminosity.value[self.montecarlo_luminosity.value < 0],
                                         bins=self.tardis_config.spectrum.frequency.value)[0] \
                                      * self.montecarlo_luminosity.unit

        montecarlo_emitted_luminosity = np.histogram(self.montecarlo_nu.value[self.montecarlo_luminosity.value >= 0],
                                         weights=self.montecarlo_luminosity.value[self.montecarlo_luminosity.value >= 0],
                                         bins=self.tardis_config.spectrum.frequency.value)[0] \
                                   * self.montecarlo_luminosity.unit

        self.spectrum.update_luminosity(montecarlo_emitted_luminosity)
        self.spectrum_reabsorbed.update_luminosity(
            montecarlo_reabsorbed_luminosity)

        if no_of_virtual_packets > 0:
            self.montecarlo_virtual_luminosity = self.montecarlo_virtual_luminosity \
                                                 * 1 * u.erg / self.time_of_simulation
            self.spectrum_virtual.update_luminosity(
                self.montecarlo_virtual_luminosity)

        self.last_line_interaction_in_id = self.atom_data.lines_index.index.values[
            last_line_interaction_in_id]
        self.last_line_interaction_in_id = self.last_line_interaction_in_id[
            last_line_interaction_in_id != -1]
        self.last_line_interaction_out_id = self.atom_data.lines_index.index.values[
            last_line_interaction_out_id]
        self.last_line_interaction_out_id = self.last_line_interaction_out_id[
            last_line_interaction_out_id != -1]
        self.last_line_interaction_angstrom = self.montecarlo_nu[
            last_line_interaction_in_id != -1].to('angstrom', u.spectral())

        self.iterations_executed += 1
        self.iterations_remaining -= 1

        if self.gui is not None:
            self.gui.update_data(self)
            self.gui.show()
Пример #12
0
    def simulate(self, update_radiation_field=True, enable_virtual=False, initialize_j_blues=False,
                 initialize_nlte=False):
        """
        Run a simulation
        """

        if update_radiation_field:
            t_inner_new = self.update_radiationfield()
        else:
            t_inner_new = self.t_inner

        self.calculate_j_blues(init_detailed_j_blues=initialize_j_blues)
        self.update_plasmas(initialize_nlte=initialize_nlte)


        self.t_inner = t_inner_new

        self.packet_src.create_packets(self.current_no_of_packets, self.t_inner.value)

        if enable_virtual:
            no_of_virtual_packets = self.tardis_config.montecarlo.no_of_virtual_packets
        else:
            no_of_virtual_packets = 0
        if np.any(np.isnan(self.plasma_array.tau_sobolevs.values)) or np.any(np.isinf(self.plasma_array.tau_sobolevs.values)) \
            or np.any(np.isneginf(self.plasma_array.tau_sobolevs.values)):
            raise ValueError('Some tau_sobolevs are nan, inf, -inf in tau_sobolevs. Something went wrong!')

        self.j_blue_estimators = np.zeros((len(self.t_rads), len(self.atom_data.lines)))
        self.montecarlo_virtual_luminosity = np.zeros_like(self.spectrum.frequency.value)

        montecarlo_nu, montecarlo_energies, self.j_estimators, self.nubar_estimators, \
        last_line_interaction_in_id, last_line_interaction_out_id, \
        self.last_interaction_type, self.last_line_interaction_shell_id = \
            montecarlo.montecarlo_radial1d(self,
                                                     virtual_packet_flag=no_of_virtual_packets)

        if np.sum(montecarlo_energies < 0) == len(montecarlo_energies):
            logger.critical("No r-packet escaped through the outer boundary.")

        self.montecarlo_nu = montecarlo_nu * u.Hz
        self.montecarlo_luminosity = montecarlo_energies *  1 * u.erg / self.time_of_simulation


        montecarlo_reabsorbed_luminosity = -np.histogram(self.montecarlo_nu.value[self.montecarlo_luminosity.value < 0],
                                         weights=self.montecarlo_luminosity.value[self.montecarlo_luminosity.value < 0],
                                         bins=self.tardis_config.spectrum.frequency.value)[0] \
                                      * self.montecarlo_luminosity.unit

        montecarlo_emitted_luminosity = np.histogram(self.montecarlo_nu.value[self.montecarlo_luminosity.value >= 0],
                                         weights=self.montecarlo_luminosity.value[self.montecarlo_luminosity.value >= 0],
                                         bins=self.tardis_config.spectrum.frequency.value)[0] \
                                   * self.montecarlo_luminosity.unit



        self.spectrum.update_luminosity(montecarlo_emitted_luminosity)
        self.spectrum_reabsorbed.update_luminosity(montecarlo_reabsorbed_luminosity)


        if no_of_virtual_packets > 0:
            self.montecarlo_virtual_luminosity = self.montecarlo_virtual_luminosity \
                                                 * 1 * u.erg / self.time_of_simulation
            self.spectrum_virtual.update_luminosity(self.montecarlo_virtual_luminosity)



        self.last_line_interaction_in_id = self.atom_data.lines_index.index.values[last_line_interaction_in_id]
        self.last_line_interaction_in_id = self.last_line_interaction_in_id[last_line_interaction_in_id != -1]
        self.last_line_interaction_out_id = self.atom_data.lines_index.index.values[last_line_interaction_out_id]
        self.last_line_interaction_out_id = self.last_line_interaction_out_id[last_line_interaction_out_id != -1]
        self.last_line_interaction_angstrom = self.montecarlo_nu[last_line_interaction_in_id != -1].to('angstrom',
                                                                                                       u.spectral())


        self.iterations_executed += 1
        self.iterations_remaining -= 1

        if self.gui is not None:
            self.gui.update_data(self)
            self.gui.show()