diff --git a/tardis/model/base.py b/tardis/model/base.py index 77bbbb78ed2..a0c8920b170 100644 --- a/tardis/model/base.py +++ b/tardis/model/base.py @@ -21,6 +21,7 @@ from tardis.io.util import HDFWriterMixin from tardis.io.decay import IsotopeAbundances from tardis.model.density import HomologousDensity +from tardis.montecarlo.packet_source import BlackBodySimpleSource logger = logging.getLogger(__name__) @@ -270,29 +271,25 @@ def __init__( time_explosion=self.time_explosion, ) + self.blackbody_packet_source = BlackBodySimpleSource( + self.r_inner[0], t_inner + ) if t_inner is None: if luminosity_requested is not None: - self.t_inner = ( - ( - luminosity_requested - / ( - 4 - * np.pi - * self.r_inner[0] ** 2 - * constants.sigma_sb - ) - ) - ** 0.25 - ).to("K") + self.blackbody_packet_source.set_temperature_from_luminosity( + luminosity_requested + ) else: raise ValueError( "Both t_inner and luminosity_requested cannot " "be None." ) else: - self.t_inner = t_inner + self.blackbody_packet_source.temperature = t_inner if t_radiative is None: - lambda_wien_inner = constants.b_wien / self.t_inner + lambda_wien_inner = ( + constants.b_wien / self.blackbody_packet_source.temperature + ) self._t_radiative = constants.b_wien / ( lambda_wien_inner * (1 + (self.v_middle - self.v_boundary_inner) / constants.c) @@ -328,6 +325,14 @@ def t_rad(self): def t_rad(self, value): self.t_radiative = value + @property + def t_inner(self): + return self.blackbody_packet_source.temperature + + @t_inner.setter + def t_inner(self, value): + self.blackbody_packet_source.temperature = value + @property def dilution_factor(self): if len(self._dilution_factor) == self.no_of_shells: @@ -431,7 +436,6 @@ def r_middle(self): @property def velocity(self): - if self._velocity is None: self._velocity = self.raw_velocity[ self.v_boundary_inner_index : self.v_boundary_outer_index + 1 @@ -641,6 +645,8 @@ def from_config(cls, config, atom_data=None): else: t_radiative = None + #### Here starts the packetsource section + if config.plasma.initial_t_inner < 0.0 * u.K: luminosity_requested = config.supernova.luminosity_requested t_inner = None diff --git a/tardis/montecarlo/packet_source.py b/tardis/montecarlo/packet_source.py index f90397515c0..095fca194c4 100644 --- a/tardis/montecarlo/packet_source.py +++ b/tardis/montecarlo/packet_source.py @@ -7,6 +7,8 @@ montecarlo_configuration as montecarlo_configuration, ) +from astropy import units as u + class BasePacketSource(abc.ABC): """ @@ -231,6 +233,21 @@ def create_packet_energies(self, no_of_packets): """ return np.ones(no_of_packets) / no_of_packets + def set_temperature_from_luminosity(self, luminosity: u.Quantity): + """ + Set blackbody packet source temperature from luminosity + + Parameters + ---------- + + luminosity : u.Quantity + + """ + self.temperature = ( + (luminosity / (4 * np.pi * self.radius**2 * const.sigma_sb)) + ** 0.25 + ).to("K") + class BlackBodySimpleSourceRelativistic(BlackBodySimpleSource): """ diff --git a/tardis/simulation/base.py b/tardis/simulation/base.py index 081926544b1..ea2ae90eb32 100644 --- a/tardis/simulation/base.py +++ b/tardis/simulation/base.py @@ -342,7 +342,7 @@ def advance_state(self): ) self.model.t_rad = next_t_rad self.model.w = next_w - self.model.t_inner = next_t_inner + self.model.blackbody_packet_source.temperature = next_t_inner # model.calculate_j_blues() equivalent # model.update_plasmas() equivalent