Skip to content

Commit

Permalink
Reverting Back to Commit where only RPacketTracker is moved to a new …
Browse files Browse the repository at this point in the history
…file
  • Loading branch information
Sumit112192 committed Jun 6, 2024
1 parent b77f212 commit fd38d0a
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 75 deletions.
4 changes: 0 additions & 4 deletions tardis/transport/montecarlo/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,6 @@ def run(
(
v_packets_energy_hist,
last_interaction_tracker,
last_interaction_tracker_check,
vpacket_tracker,
rpacket_trackers,
) = montecarlo_main_loop(
Expand Down Expand Up @@ -216,9 +215,6 @@ def run(
transport_state.last_line_interaction_shell_id = (
last_interaction_tracker.shell_ids
)
transport_state.last_interaction_tracker = (
last_interaction_tracker_check
)

if self.montecarlo_configuration.ENABLE_VPACKET_TRACKING and (
number_of_vpackets > 0
Expand Down
13 changes: 3 additions & 10 deletions tardis/transport/montecarlo/montecarlo_main_loop.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,7 @@

from tardis.transport.montecarlo import njit_dict
from tardis.transport.montecarlo.numba_interface import NumbaModel
from tardis.transport.montecarlo.packet_trackers import (
RPacketTracker,
RPacketLastInteractionTracker,
)
from tardis.transport.montecarlo.packet_trackers import RPacketTracker
from tardis.transport.montecarlo.packet_collections import (
VPacketCollection,
consolidate_vpacket_tracker,
Expand Down Expand Up @@ -71,10 +68,6 @@ def montecarlo_main_loop(
no_of_packets
)

last_interaction_tracker_check = RPacketLastInteractionTracker(
no_of_packets
)

v_packets_energy_hist = np.zeros_like(spectrum_frequency)
delta_nu = spectrum_frequency[1] - spectrum_frequency[0]

Expand Down Expand Up @@ -154,12 +147,13 @@ def montecarlo_main_loop(
packet_collection.output_nus[i] = r_packet.nu

last_interaction_tracker.update_last_interaction(r_packet, i)
last_interaction_tracker_check.update_last_interaction(r_packet, i)

if r_packet.status == PacketStatus.REABSORBED:
packet_collection.output_energies[i] = -r_packet.energy
last_interaction_tracker.types[i] = r_packet.last_interaction_type
elif r_packet.status == PacketStatus.EMITTED:
packet_collection.output_energies[i] = r_packet.energy
last_interaction_tracker.types[i] = r_packet.last_interaction_type

vpacket_collection.finalize_arrays()

Expand Down Expand Up @@ -201,7 +195,6 @@ def montecarlo_main_loop(
return (
v_packets_energy_hist,
last_interaction_tracker,
last_interaction_tracker_check,
vpacket_tracker,
rpacket_trackers,
)
61 changes: 0 additions & 61 deletions tardis/transport/montecarlo/packet_trackers.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,64 +110,3 @@ def finalize_array(self):
self.energy = self.energy[: self.num_interactions]
self.shell_id = self.shell_id[: self.num_interactions]
self.interaction_type = self.interaction_type[: self.num_interactions]


last_interaction_tracker_spec = [
("radius", float64[:]),
("shell_id", int64[:]),
("interaction_type", int64[:]),
("energy", float64[:]),
("in_id", int64[:]),
("in_nu", float64[:]),
("out_id", int64[:]),
("nu", float64[:]),
]


@jitclass(last_interaction_tracker_spec)
class RPacketLastInteractionTracker:
"""
Numba JITCLASS for storing the last interaction info a RPacket
Parameters
----------
radius : float
Radius from the center where last interaction happened
shell_id : int
The id of the shell where the last interaction happened
interaction_type : int
The id of the last interaction that the r_packet went
LINE : 2
ESCATTERING : 4
CONTINUUM_PROCESS : 8
energy : float
The energy of the r_packet
in_id : int
in_nu : float
out_id : int
nu : float
"""

def __init__(self, no_of_packets):
self.radius = -1 * np.ones(no_of_packets, dtype=np.float64)
self.shell_id = -1 * np.ones(no_of_packets, dtype=np.int64)
self.nu = np.zeros(no_of_packets, dtype=np.float64)
self.energy = np.zeros(no_of_packets, dtype=np.float64)
self.interaction_type = -1 * np.ones(no_of_packets, dtype=np.int64)
self.in_id = -1 * np.ones(no_of_packets, dtype=np.int64)
self.in_nu = np.zeros(no_of_packets, dtype=np.float64)
self.out_id = -1 * np.ones(no_of_packets, dtype=np.int64)

def update_last_interaction(self, r_packet, index):
self.radius[index] = r_packet.r
self.shell_id[index] = r_packet.current_shell_id
self.nu[index] = r_packet.nu
self.energy[index] = r_packet.energy
self.interaction_type[index] = r_packet.last_interaction_type
self.in_id[index] = r_packet.last_line_interaction_in_id
self.in_nu[index] = r_packet.last_interaction_in_nu
self.out_id[index] = r_packet.last_line_interaction_out_id

0 comments on commit fd38d0a

Please sign in to comment.