Skip to content
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
30 changes: 30 additions & 0 deletions docs/physics_walkthrough/montecarlo/propagation.rst
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,36 @@ 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. The packet retains the next eligible line ID in each frequency direction,
so a processed transition contributes once while frequency drifts monotonically
between line emissions. This history survives electron scattering and continuous
shell crossings when the drift direction agrees. A reversal can make earlier
lines eligible again. Each line emission starts a new outgoing history and
excludes the emitted transition itself. Emission into another transition can
make the absorbed line eligible again even if both rest frequencies are equal.

Transitions with identical frequencies keep their separate optical depths and
estimator contributions. At the start of a trace, eligible lines satisfying
:math:`|\nu_{\mathrm{CMF}}-\nu_{\mathrm{line}}|/\nu_{\mathrm{lab}} < 10^{-14}`
are processed at zero distance, following the homologous close-line convention.
Cursor eligibility excludes the emitting line before this rule is applied.
The rule also approximates sufficiently close distinct frequencies as coincident
at trace entry. Other roots retain the distance solver's existing spatial cutoff;
the frequency convention does not extend that solver's resolution.
Search direction is inferred from the interval endpoint frequencies; monotonic
replay prevention assumes those endpoints resolve the direction of drift.

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

Expand Down
31 changes: 25 additions & 6 deletions tardis/transport/geometry/calculate_distances.py
Original file line number Diff line number Diff line change
Expand Up @@ -439,16 +439,35 @@ def get_line_id_range_nonhomologous(
line_list_nu: npt.NDArray[np.float64],
comov_nu_start: float,
comov_nu_end: float,
minimum_frequency_padding: float,
) -> tuple[int, int, int]:
"""Return directional line-list bounds for one monotonic path interval.
"""Return directional candidate line-list bounds for a monotonic interval.

The transport line list is ordered by descending frequency. The returned
range conservatively includes both interval endpoint frequencies; the
distance bounds reject a resonance at the packet's interval start.
The transport line list is ordered by descending frequency. Both endpoint
frequencies are included, with padding for numerical uncertainty. The
caller excludes previously processed lines and checks resonance distances
against the spatial interval.

Parameters
----------
line_list_nu : numpy.ndarray
Line frequencies in descending order.
comov_nu_start : float
Comoving frequency at the interval start, in Hz.
comov_nu_end : float
Comoving frequency at the interval end, in Hz.
minimum_frequency_padding : float
Minimum padding in Hz, used to admit the starting close-frequency band.

Returns
-------
tuple[int, int, int]
Start line ID, exclusive stop line ID, and directional ID step.
"""
line_count = len(line_list_nu)
frequency_tolerance = CLOSE_LINE_THRESHOLD * max(
abs(comov_nu_start), abs(comov_nu_end)
frequency_tolerance = max(
CLOSE_LINE_THRESHOLD * max(abs(comov_nu_start), abs(comov_nu_end)),
minimum_frequency_padding,
)
minimum_frequency = min(comov_nu_start, comov_nu_end) - frequency_tolerance
maximum_frequency = max(comov_nu_start, comov_nu_end) + frequency_tolerance
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,17 @@
from numba import njit

from tardis import constants as const
from tardis.model.geometry.radial1d import NumbaRadial1DGeometry
from tardis.opacities.opacity_state_numba import OpacityStateNumba
from tardis.transport.frame_transformations import (
get_doppler_factor,
get_inverse_doppler_factor,
)
from tardis.transport.montecarlo import njit_dict_no_parallel
from tardis.transport.montecarlo.packets.radiative_packet import PacketStatus
from tardis.transport.montecarlo.packets.radiative_packet import (
PacketStatus,
RPacket,
)
from tardis.transport.montecarlo.utils import get_random_mu

K_B = const.k_B.cgs.value
Expand Down Expand Up @@ -225,24 +230,28 @@ class LineInteractionType(IntEnum):

@njit(**njit_dict_no_parallel)
def line_emission(
r_packet,
emission_line_id,
geometry,
opacity_state,
enable_full_relativity,
):
r_packet: RPacket,
emission_line_id: int,
geometry: NumbaRadial1DGeometry,
opacity_state: OpacityStateNumba,
enable_full_relativity: bool,
) -> None:
"""
Sets the frequency of the RPacket properly given the emission channel
Set packet frequency and exclude the emitting line in both directions.

Parameters
----------
r_packet : tardis.transport.montecarlo.r_packet.RPacket
r_packet : RPacket
Packet whose outgoing frequency and line cursors are updated.
emission_line_id : int
Line selected by the emission channel.
geometry : NumbaRadial1DGeometry
opacity_state : tardis.transport.montecarlo.numba_interface.OpacityState
Geometry supplying the local velocity.
opacity_state : OpacityStateNumba
Opacity state containing the line frequencies.
enable_full_relativity : bool
Whether full relativistic transformations are enabled.
"""
if emission_line_id != r_packet.next_line_id:
pass
v = geometry.get_velocity(r_packet.r, r_packet.current_shell_id)
inverse_doppler_factor = get_inverse_doppler_factor(
v,
Expand All @@ -253,6 +262,7 @@ def line_emission(
opacity_state.line_list_nu[emission_line_id] * inverse_doppler_factor
)
r_packet.next_line_id = emission_line_id + 1
r_packet.prev_line_id = emission_line_id - 1

if enable_full_relativity:
raise NotImplementedError("Full relativity not implemented in non-homologous mode.")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
"""Nonhomologous mode packet transport - line-only without continuum processes."""

import numpy as np
from numba import njit

from tardis import constants as const
Expand Down Expand Up @@ -30,6 +29,7 @@
)
from tardis.transport.montecarlo.modes.nonhomologous.rad_packet_transport import (
trace_packet,
update_line_ids,
)
from tardis.transport.montecarlo.packets.movement import (
move_packet_across_shell_boundary,
Expand Down Expand Up @@ -100,23 +100,14 @@ def packet_propagation(
"Full relativity not supported for non-homology."
)
set_packet_props_partial_relativity(r_packet, geometry)
# Manually perform the function of r_packet.initialize_line_id for now until
# nonhomology is supported
inverse_line_list_nu = opacity_state.line_list_nu[::-1]
v = geometry.get_velocity(r_packet.r, r_packet.current_shell_id)
doppler_factor = get_doppler_factor(
v,
r_packet.mu,
montecarlo_configuration.ENABLE_FULL_RELATIVITY,
)
comov_nu = r_packet.nu * doppler_factor
next_line_id = len(opacity_state.line_list_nu) - np.searchsorted(
inverse_line_list_nu, comov_nu
)
if next_line_id == len(opacity_state.line_list_nu):
next_line_id -= 1
r_packet.next_line_id = next_line_id
r_packet.prev_line_id = next_line_id - 1
update_line_ids(r_packet, opacity_state.line_list_nu, comov_nu)

rpacket_tracker.track_boundary_event(
r_packet, from_shell_id=-1, to_shell_id=0
Expand Down Expand Up @@ -151,6 +142,16 @@ def packet_propagation(
)

if interaction_type == InteractionType.BOUNDARY:
next_shell_id = r_packet.current_shell_id + delta_shell
is_velocity_discontinuous = False
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]
is_velocity_discontinuous = edge_velocity != next_edge_velocity
move_r_packet(
r_packet,
distance,
Expand All @@ -169,6 +170,18 @@ def packet_propagation(
delta_shell,
len(geometry.r_inner),
)
if is_velocity_discontinuous:
incoming_velocity = geometry.get_velocity(
r_packet.r, r_packet.current_shell_id
)
incoming_comov_nu = r_packet.nu * get_doppler_factor(
incoming_velocity,
r_packet.mu,
montecarlo_configuration.ENABLE_FULL_RELATIVITY,
)
update_line_ids(
r_packet, opacity_state.line_list_nu, incoming_comov_nu
)

elif interaction_type == InteractionType.LINE:
move_r_packet(
Expand Down
Loading
Loading