Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

integrate new packetsource #2367

Merged
merged 4 commits into from
Jul 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 21 additions & 15 deletions tardis/model/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__)

Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
17 changes: 17 additions & 0 deletions tardis/montecarlo/packet_source.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
montecarlo_configuration as montecarlo_configuration,
)

from astropy import units as u


class BasePacketSource(abc.ABC):
"""
Expand Down Expand Up @@ -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):
"""
Expand Down
2 changes: 1 addition & 1 deletion tardis/simulation/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down