Skip to content

Commit

Permalink
Add Track Line Interaction
Browse files Browse the repository at this point in the history
  • Loading branch information
Sumit112192 committed Jul 30, 2024
1 parent edd7f43 commit 802248e
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 1 deletion.
65 changes: 64 additions & 1 deletion tardis/transport/montecarlo/packet_trackers.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,23 @@
("next_shell_id", "int64"),
]
)


line_interaction_dtype = np.dtype(
[
("interaction_id", "int64"),
("shell_id", "int64"),
("r", "float64"),
("in_nu", "float64"),
("in_id", "int64"),
("out_id", "int64"),
]
)

rpacket_tracker_spec = [
("length", int64),
("boundary_interaction_array_length", int64),
("line_interaction_array_length", int64),
("seed", int64),
("index", int64),
("status", int64[:]),
Expand All @@ -25,8 +39,11 @@
("shell_id", int64[:]),
("interaction_type", int64[:]),
("boundary_interaction", from_dtype(boundary_interaction_dtype)[:]),
("line_interaction", from_dtype(line_interaction_dtype)[:]),
("num_interactions", int64),
("num_boundary_interactions", int64),
("num_line_interactions", int64),
("interaction_id", int64),
]


Expand Down Expand Up @@ -76,8 +93,14 @@ def __init__(self, length):
self.boundary_interaction_array_length,
dtype=boundary_interaction_dtype,
)
self.line_interaction = np.empty(
self.line_interaction_array_length,
dtype=line_interaction_dtype,
)
self.num_interactions = 0
self.num_boundary_interactions = 0
self.num_line_interactions = 0
self.interaction_id = 1

def track(self, r_packet):
if self.num_interactions >= self.length:
Expand Down Expand Up @@ -139,14 +162,48 @@ def track_boundary_interaction(self, current_shell_id, next_shell_id):

self.boundary_interaction[self.num_boundary_interactions][
"interaction_id"
] = (self.num_boundary_interactions + 1)
] = self.interaction_id
self.boundary_interaction[self.num_boundary_interactions][
"current_shell_id"
] = current_shell_id
self.boundary_interaction[self.num_boundary_interactions][
"next_shell_id"
] = next_shell_id
self.num_boundary_interactions += 1
self.interaction_id += 1

def track_line_interaction(self, r_packet):
if self.num_line_interactions >= self.line_interaction_array_length:
temp_length = self.line_interaction_array_length * 2

temp_line_interaction = np.empty(
temp_length, dtype=line_interaction_dtype
)
temp_line_interaction[
: self.line_interaction_array_length
] = self.line_interaction

self.line_interaction = temp_line_interaction
self.line_interaction_array_length = temp_length

self.line_interaction[self.num_line_interactions][
"interaction_id"
] = self.interaction_id
self.line_interaction[self.num_line_interactions][
"shell_id"
] = r_packet.current_shell_id
self.line_interaction[self.num_line_interactions]["r"] = r_packet.r
self.line_interaction[self.num_line_interactions][
"in_nu"
] = r_packet.last_interaction_in_nu
self.line_interaction[self.num_line_interactions][
"in_id"
] = r_packet.last_interaction_in_id
self.line_interaction[self.num_line_interactions][
"out_id"
] = r_packet.last_interaction_out_id
self.num_line_interactions += 1
self.interaction_id += 1

def finalize_array(self):
self.status = self.status[: self.num_interactions]
Expand All @@ -159,6 +216,9 @@ def finalize_array(self):
self.boundary_interaction = self.boundary_interaction[
: self.num_boundary_interactions
]
self.line_interaction = self.line_interaction[
: self.num_line_interactions
]


def rpacket_trackers_to_dataframe(rpacket_trackers):
Expand Down Expand Up @@ -261,6 +321,9 @@ def finalize_array(self):
def track_boundary_interaction(self, current_shell_id, next_shell_id):
pass

def track_line_interaction(self, r_packet):
pass


@njit
def generate_rpacket_tracker_list(no_of_packets, length):
Expand Down
1 change: 1 addition & 0 deletions tardis/transport/montecarlo/single_packet_loop.py
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,7 @@ def single_packet_loop(
montecarlo_configuration.VPACKET_TAU_RUSSIAN,
montecarlo_configuration.SURVIVAL_PROBABILITY,
)
rpacket_tracker.track_line_interaction(r_packet)

elif interaction_type == InteractionType.ESCATTERING:
r_packet.last_interaction_type = 1
Expand Down

0 comments on commit 802248e

Please sign in to comment.