Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 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
22 changes: 22 additions & 0 deletions docs/physics_walkthrough/montecarlo/propagation.rst
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,28 @@ the plasma properties will be updated, and the accumulation of optical depth wil

.. note:: While it would make physical sense for the accumulation of optical depth to continue between cells until the packet eventually interacts, due to the exponential nature of optical depth and interaction probabilities, both continuing and restarting the accumulation of optical depth between cells can be mathematically shown to yield the same overall statistical results. Restarting the optical depth accumulation is computationally easier, and hence it is the method employed by TARDIS.

For nonhomologous real-packet transport, the radial velocity varies linearly
within each shell. The frequency drift along a straight packet path is set by
the projected velocity gradient

.. math::

G = \mu^2 \frac{dv}{dr} + (1-\mu^2)\frac{v}{r},
\qquad
\frac{d\nu_{\mathrm{CMF}}}{ds} = -\frac{\nu_{\mathrm{lab}}}{c}G.

The line search divides the path at analytic zeros where :math:`G` reverses
sign. Within each interval the comoving frequency moves in one direction, so
a line resonance contributes optical depth and estimators once. The same line
can resonate again after a genuine reversal. The search remembers processed
lines between traces, including crossings that do not cause scattering, so
coherent emission cannot immediately replay the emitted line. Emission into
a different line begins a new frequency history. Across a shell edge, history
is retained when the represented velocity is continuous and the gradient
direction agrees. The resonance solver's existing distance cutoff limits
resolution of very close crossings; this traversal history does not extend
that numerical resolution.

Performing an Interaction
-------------------------

Expand Down
513 changes: 513 additions & 0 deletions docs/workflows/nonhomologous_line_search_implementation_plan.md

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@
get_doppler_factor,
get_inverse_doppler_factor,
)
from tardis.transport.geometry.calculate_distances import (
calculate_projected_velocity_gradient,
)
from tardis.transport.montecarlo.configuration.base import (
MonteCarloConfiguration,
)
Expand Down Expand Up @@ -122,6 +125,9 @@ def packet_propagation(
r_packet, from_shell_id=-1, to_shell_id=0
)

next_untraversed_line_id = 0
line_search_direction = 0

# this part of the code is temporary and will be better incorporated
while r_packet.status == PacketStatus.IN_PROCESS:
# Compute electron scattering opacity
Expand All @@ -140,17 +146,35 @@ def packet_propagation(
if montecarlo_configuration.ENABLE_FULL_RELATIVITY:
opacity_electron *= doppler_factor

distance, interaction_type, delta_shell = trace_packet(
(
distance,
interaction_type,
delta_shell,
next_untraversed_line_id,
line_search_direction,
) = trace_packet(
r_packet,
geometry,
opacity_state,
estimators_line,
opacity_electron,
montecarlo_configuration.ENABLE_FULL_RELATIVITY,
montecarlo_configuration.DISABLE_LINE_SCATTERING,
next_untraversed_line_id,
line_search_direction,
)

if interaction_type == InteractionType.BOUNDARY:
next_shell_id = r_packet.current_shell_id + delta_shell
if 0 <= next_shell_id < len(geometry.r_inner):
if delta_shell == 1:
edge_velocity = geometry.v_outer[r_packet.current_shell_id]
next_edge_velocity = geometry.v_inner[next_shell_id]
else:
edge_velocity = geometry.v_inner[r_packet.current_shell_id]
next_edge_velocity = geometry.v_outer[next_shell_id]
if edge_velocity != next_edge_velocity:
line_search_direction = 0
move_r_packet(
r_packet,
distance,
Expand Down Expand Up @@ -188,6 +212,19 @@ def packet_propagation(
opacity_state,
montecarlo_configuration.ENABLE_FULL_RELATIVITY,
)
emitted_line_id = r_packet.next_line_id - 1
outgoing_velocity = geometry.get_velocity(
r_packet.r, r_packet.current_shell_id
)
outgoing_gradient = calculate_projected_velocity_gradient(
r_packet.r,
r_packet.mu,
outgoing_velocity,
geometry.velocity_gradient[r_packet.current_shell_id],
)
outgoing_direction = 1 if outgoing_gradient >= 0.0 else -1
Comment thread
connor-mcclellan marked this conversation as resolved.
Resolved
next_untraversed_line_id = emitted_line_id + outgoing_direction
line_search_direction = outgoing_direction
rpacket_tracker.track_line_interaction_after(r_packet)
elif interaction_type == InteractionType.ESCATTERING:
move_r_packet(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,9 @@ def trace_packet(
opacity_electron: float,
enable_full_relativity: bool,
disable_line_scattering: bool,
) -> tuple[float, InteractionType, int]:
next_untraversed_line_id: int,
line_search_direction: int,
) -> tuple[float, InteractionType, int, int, int]:
"""
Traces the RPacket through the ejecta and stops when an interaction happens.

Expand All @@ -84,11 +86,16 @@ def trace_packet(
Flag to enable full relativistic calculations
disable_line_scattering : bool
Flag to disable line scattering
next_untraversed_line_id : int
First line ID not yet processed in the active search direction.
line_search_direction : int
Active line-ID step, or zero when no frontier is active.

Returns
-------
tuple[float, InteractionType, int]
(distance, interaction_type, delta_shell)
tuple[float, InteractionType, int, int, int]
Distance, interaction type, shell step, next untraversed line ID,
and active line-search direction.
"""
r_inner = numba_radial_1d_geometry.r_inner[r_packet.current_shell_id]
r_outer = numba_radial_1d_geometry.r_outer[r_packet.current_shell_id]
Expand Down Expand Up @@ -135,6 +142,14 @@ def trace_packet(
comov_nu_start,
comov_nu_end,
)
if line_search_direction == line_id_step:
if line_id_step == 1:
start_line_id = max(start_line_id, next_untraversed_line_id)
else:
start_line_id = min(start_line_id, next_untraversed_line_id)
else:
line_search_direction = line_id_step
next_untraversed_line_id = start_line_id
Comment thread
connor-mcclellan marked this conversation as resolved.
Resolved

for cur_line_id in range(start_line_id, stop_line_id, line_id_step):
distance_trace = calculate_distance_line_nonhomologous(
Expand Down Expand Up @@ -162,6 +177,8 @@ def trace_packet(
distance_electron,
InteractionType.ESCATTERING,
delta_shell,
next_untraversed_line_id,
line_search_direction,
)
if distance_boundary <= distance_trace:
update_line_ids(
Expand All @@ -173,6 +190,8 @@ def trace_packet(
distance_boundary,
InteractionType.BOUNDARY,
delta_shell,
next_untraversed_line_id,
line_search_direction,
)

# Line interaction
Expand Down Expand Up @@ -228,11 +247,18 @@ def trace_packet(
estimators_line.energy_deposition_line_rate[
cur_line_id, r_packet.current_shell_id
] += energy
next_untraversed_line_id = cur_line_id + line_id_step

if tau_trace_combined > tau_event and not disable_line_scattering:
r_packet.next_line_id = cur_line_id
r_packet.prev_line_id = cur_line_id - 1
return distance_trace, InteractionType.LINE, delta_shell
return (
distance_trace,
InteractionType.LINE,
delta_shell,
next_untraversed_line_id,
line_search_direction,
)

tau_trace_line_combined += tau_trace_line
distance_electron = (
Expand All @@ -254,6 +280,8 @@ def trace_packet(
distance_electron,
InteractionType.ESCATTERING,
delta_shell,
next_untraversed_line_id,
line_search_direction,
)
interval_start = interval_end

Expand All @@ -262,4 +290,10 @@ def trace_packet(
opacity_state.line_list_nu,
comov_nu_end,
)
return distance_boundary, InteractionType.BOUNDARY, delta_shell
return (
distance_boundary,
InteractionType.BOUNDARY,
delta_shell,
next_untraversed_line_id,
line_search_direction,
)
Loading
Loading