Skip to content

Commit

Permalink
Fixes a lot of globals
Browse files Browse the repository at this point in the history
Co-authored-by: Joshua Shields <[email protected]>
  • Loading branch information
andrewfullard and jvshields committed Jul 12, 2024
1 parent ff4b045 commit dc7abbc
Show file tree
Hide file tree
Showing 9 changed files with 125 additions and 122 deletions.
4 changes: 1 addition & 3 deletions tardis/io/model/parse_packet_source_configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def initialize_packet_source(packet_source, config, geometry):
return packet_source


def parse_packet_source_from_config(config, geometry, legacy_mode_enabled):
def parse_packet_source_from_config(config, geometry):
"""
Parse the packet source based on the given configuration and geometry.
Expand All @@ -66,12 +66,10 @@ def parse_packet_source_from_config(config, geometry, legacy_mode_enabled):
packet_source = BlackBodySimpleSourceRelativistic(
base_seed=config.montecarlo.seed,
time_explosion=config.supernova.time_explosion,
legacy_mode_enabled=legacy_mode_enabled,
)
else:
packet_source = BlackBodySimpleSource(
base_seed=config.montecarlo.seed,
legacy_mode_enabled=legacy_mode_enabled,
)

return initialize_packet_source(packet_source, config, geometry)
8 changes: 2 additions & 6 deletions tardis/model/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -295,9 +295,7 @@ def from_config(cls, config, atom_data, legacy_mode_enabled=False):
atom_data, config, time_explosion, geometry
)

packet_source = parse_packet_source_from_config(
config, geometry, legacy_mode_enabled
)
packet_source = parse_packet_source_from_config(config, geometry)

radiation_field_state = parse_radiation_field_state_from_config(
config,
Expand Down Expand Up @@ -394,9 +392,7 @@ def from_csvy(cls, config, atom_data=None, legacy_mode_enabled=False):
geometry,
)

packet_source = parse_packet_source_from_config(
config, geometry, legacy_mode_enabled
)
packet_source = parse_packet_source_from_config(config, geometry)

radiation_field_state = parse_radiation_field_state_from_csvy(
config, csvy_model_config, csvy_model_data, geometry, packet_source
Expand Down
97 changes: 58 additions & 39 deletions tardis/transport/montecarlo/interaction.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@
from tardis.transport.montecarlo.configuration.constants import (
LineInteractionType,
)
from tardis.transport.montecarlo.configuration.montecarlo_globals import (
CONTINUUM_PROCESSES_ENABLED,
ENABLE_FULL_RELATIVITY,
)
from tardis.transport.montecarlo.r_packet import (
PacketStatus,
)
Expand Down Expand Up @@ -148,8 +152,6 @@ def continuum_event(
chi_ff,
chi_bf_contributions,
current_continua,
continuum_processes_enabled,
enable_full_relativity,
):
"""
continuum event handler - activate the macroatom and run the handler
Expand All @@ -162,12 +164,16 @@ def continuum_event(
continuum : tardis.transport.montecarlo.numba_interface.Continuum
"""
old_doppler_factor = get_doppler_factor(
r_packet.r, r_packet.mu, time_explosion, enable_full_relativity
r_packet.r,
r_packet.mu,
time_explosion,
)

r_packet.mu = get_random_mu()
inverse_doppler_factor = get_inverse_doppler_factor(
r_packet.r, r_packet.mu, time_explosion, enable_full_relativity
r_packet.r,
r_packet.mu,
time_explosion,
)
comov_energy = r_packet.energy * old_doppler_factor
comov_nu = (
Expand All @@ -190,8 +196,6 @@ def continuum_event(
r_packet,
time_explosion,
opacity_state,
continuum_processes_enabled,
enable_full_relativity,
)


Expand All @@ -201,8 +205,6 @@ def macro_atom_event(
r_packet,
time_explosion,
opacity_state,
continuum_processes_enabled,
enable_full_relativity,
):
"""
Macroatom event handler - run the macroatom and handle the result
Expand All @@ -219,34 +221,37 @@ def macro_atom_event(
)

if (
continuum_processes_enabled
CONTINUUM_PROCESSES_ENABLED
and transition_type == MacroAtomTransitionType.FF_EMISSION
):
free_free_emission(
r_packet, time_explosion, opacity_state, enable_full_relativity
r_packet,
time_explosion,
opacity_state,
)

elif (
continuum_processes_enabled
CONTINUUM_PROCESSES_ENABLED
and transition_type == MacroAtomTransitionType.BF_EMISSION
):
bound_free_emission(
r_packet,
time_explosion,
opacity_state,
transition_id,
enable_full_relativity,
)
elif (
continuum_processes_enabled
CONTINUUM_PROCESSES_ENABLED
and transition_type == MacroAtomTransitionType.BF_COOLING
):
bf_cooling(
r_packet, time_explosion, opacity_state, enable_full_relativity
r_packet,
time_explosion,
opacity_state,
)

elif (
continuum_processes_enabled
CONTINUUM_PROCESSES_ENABLED
and transition_type == MacroAtomTransitionType.ADIABATIC_COOLING
):
adiabatic_cooling(r_packet)
Expand All @@ -257,14 +262,17 @@ def macro_atom_event(
transition_id,
time_explosion,
opacity_state,
enable_full_relativity,
)
else:
raise Exception("No Interaction Found!")


@njit(**njit_dict_no_parallel)
def bf_cooling(r_packet, time_explosion, opacity_state, enable_full_relativity):
def bf_cooling(
r_packet,
time_explosion,
opacity_state,
):
"""
Bound-Free Cooling - Determine and run bf emission from cooling
Expand All @@ -289,7 +297,6 @@ def bf_cooling(r_packet, time_explosion, opacity_state, enable_full_relativity):
time_explosion,
opacity_state,
continuum_idx,
enable_full_relativity,
)


Expand Down Expand Up @@ -326,7 +333,9 @@ def get_current_line_id(nu, line_list):

@njit(**njit_dict_no_parallel)
def free_free_emission(
r_packet, time_explosion, opacity_state, enable_full_relativity
r_packet,
time_explosion,
opacity_state,
):
"""
Free-Free emission - set the frequency from electron-ion interaction
Expand All @@ -338,14 +347,16 @@ def free_free_emission(
opacity_state : tardis.transport.montecarlo.numba_interface.OpacityState
"""
inverse_doppler_factor = get_inverse_doppler_factor(
r_packet.r, r_packet.mu, time_explosion, enable_full_relativity
r_packet.r,
r_packet.mu,
time_explosion,
)
comov_nu = sample_nu_free_free(opacity_state, r_packet.current_shell_id)
r_packet.nu = comov_nu * inverse_doppler_factor
current_line_id = get_current_line_id(comov_nu, opacity_state.line_list_nu)
r_packet.next_line_id = current_line_id

if enable_full_relativity:
if ENABLE_FULL_RELATIVITY:
r_packet.mu = angle_aberration_CMF_to_LF(
r_packet, time_explosion, r_packet.mu
)
Expand All @@ -357,7 +368,6 @@ def bound_free_emission(
time_explosion,
opacity_state,
continuum_id,
enable_full_relativity,
):
"""
Bound-Free emission - set the frequency from photo-ionization
Expand All @@ -370,7 +380,9 @@ def bound_free_emission(
continuum_id : int
"""
inverse_doppler_factor = get_inverse_doppler_factor(
r_packet.r, r_packet.mu, time_explosion, enable_full_relativity
r_packet.r,
r_packet.mu,
time_explosion,
)

comov_nu = sample_nu_free_bound(
Expand All @@ -380,14 +392,17 @@ def bound_free_emission(
current_line_id = get_current_line_id(comov_nu, opacity_state.line_list_nu)
r_packet.next_line_id = current_line_id

if enable_full_relativity:
if ENABLE_FULL_RELATIVITY:
r_packet.mu = angle_aberration_CMF_to_LF(
r_packet, time_explosion, r_packet.mu
)


@njit(**njit_dict_no_parallel)
def thomson_scatter(r_packet, time_explosion, enable_full_relativity):
def thomson_scatter(
r_packet,
time_explosion,
):
"""
Thomson scattering — no longer line scattering
\n1) get the doppler factor at that position with the old angle
Expand All @@ -402,23 +417,29 @@ def thomson_scatter(r_packet, time_explosion, enable_full_relativity):
time since explosion in seconds
"""
old_doppler_factor = get_doppler_factor(
r_packet.r, r_packet.mu, time_explosion, enable_full_relativity
r_packet.r,
r_packet.mu,
time_explosion,
)
comov_nu = r_packet.nu * old_doppler_factor
comov_energy = r_packet.energy * old_doppler_factor
r_packet.mu = get_random_mu()
inverse_new_doppler_factor = get_inverse_doppler_factor(
r_packet.r, r_packet.mu, time_explosion, enable_full_relativity
r_packet.r,
r_packet.mu,
time_explosion,
)

r_packet.nu = comov_nu * inverse_new_doppler_factor
r_packet.energy = comov_energy * inverse_new_doppler_factor
if enable_full_relativity:
if ENABLE_FULL_RELATIVITY:
r_packet.mu = angle_aberration_CMF_to_LF(
r_packet, time_explosion, r_packet.mu
)
temp_doppler_factor = get_doppler_factor(
r_packet.r, r_packet.mu, time_explosion, enable_full_relativity
r_packet.r,
r_packet.mu,
time_explosion,
)


Expand All @@ -428,8 +449,6 @@ def line_scatter(
time_explosion,
line_interaction_type,
opacity_state,
continuum_processes_enabled,
enable_full_relativity,
):
"""
Line scatter function that handles the scattering itself, including new angle drawn, and calculating nu out using macro atom
Expand All @@ -442,12 +461,16 @@ def line_scatter(
opacity_state : tardis.transport.montecarlo.numba_interface.OpacityState
"""
old_doppler_factor = get_doppler_factor(
r_packet.r, r_packet.mu, time_explosion, enable_full_relativity
r_packet.r,
r_packet.mu,
time_explosion,
)
r_packet.mu = get_random_mu()

inverse_new_doppler_factor = get_inverse_doppler_factor(
r_packet.r, r_packet.mu, time_explosion, enable_full_relativity
r_packet.r,
r_packet.mu,
time_explosion,
)

comov_energy = r_packet.energy * old_doppler_factor
Expand All @@ -459,7 +482,6 @@ def line_scatter(
r_packet.next_line_id,
time_explosion,
opacity_state,
enable_full_relativity,
)
else: # includes both macro atom and downbranch - encoded in the transition probabilities
comov_nu = r_packet.nu * old_doppler_factor # Is this necessary?
Expand All @@ -472,8 +494,6 @@ def line_scatter(
r_packet,
time_explosion,
opacity_state,
continuum_processes_enabled,
enable_full_relativity,
)


Expand All @@ -483,7 +503,6 @@ def line_emission(
emission_line_id,
time_explosion,
opacity_state,
enable_full_relativity,
):
"""
Sets the frequency of the RPacket properly given the emission channel
Expand All @@ -501,15 +520,15 @@ def line_emission(
if emission_line_id != r_packet.next_line_id:
pass
inverse_doppler_factor = get_inverse_doppler_factor(
r_packet.r, r_packet.mu, time_explosion, enable_full_relativity
r_packet.r, r_packet.mu, time_explosion
)
r_packet.nu = (
opacity_state.line_list_nu[emission_line_id] * inverse_doppler_factor
)
r_packet.next_line_id = emission_line_id + 1
nu_line = opacity_state.line_list_nu[emission_line_id]

if enable_full_relativity:
if ENABLE_FULL_RELATIVITY:
r_packet.mu = angle_aberration_CMF_to_LF(
r_packet, time_explosion, r_packet.mu
)
Loading

0 comments on commit dc7abbc

Please sign in to comment.