예제 #1
0
def line_emission(r_packet, emission_line_id, time_explosion, numba_plasma):
    """
    Sets the frequency of the RPacket properly given the emission channel

    Parameters
    -----------

    r_packet: RPacket
    emission_line_id: int
    time_explosion: float
    numba_plasma: NumbaPlasma
    """
    r_packet.last_line_interaction_out_id = emission_line_id

    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)
    r_packet.nu = (numba_plasma.line_list_nu[emission_line_id] *
                   inverse_doppler_factor)
    r_packet.next_line_id = emission_line_id + 1
    nu_line = numba_plasma.line_list_nu[emission_line_id]

    if emission_line_id != (len(numba_plasma.line_list_nu) - 1):
        test_for_close_line(r_packet, emission_line_id + 1, nu_line,
                            numba_plasma)

    if montecarlo_configuration.full_relativity:
        r_packet.mu = angle_aberration_CMF_to_LF(r_packet, time_explosion,
                                                 r_packet.mu)
예제 #2
0
def thomson_scatter(r_packet, time_explosion):
    """
    Thomson scattering — no longer line scattering
    2) get the doppler factor at that position with the old angle
    3) convert the current energy and nu into the comoving
        frame with the old mu
    4) Scatter and draw new mu - update mu
    5) Transform the comoving energy and nu back using the new mu

    Parameters
    ----------
    r_packet : RPacket
    time_explosion: float
        time since explosion in seconds

    """
    old_doppler_factor = get_doppler_factor(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)

    r_packet.nu = comov_nu * inverse_new_doppler_factor
    r_packet.energy = comov_energy * inverse_new_doppler_factor
    if montecarlo_configuration.full_relativity:
        r_packet.mu = angle_aberration_CMF_to_LF(r_packet, time_explosion,
                                                 r_packet.mu)
예제 #3
0
def line_scatter(r_packet, time_explosion, line_interaction_type,
                 numba_plasma):
    """
    Line scatter function that handles the scattering itself, including new angle drawn, and calculating nu out using macro atom
    r_packet: RPacket
    time_explosion: float
    line_interaction_type: enum
    numba_plasma: NumbaPlasma
    """

    old_doppler_factor = get_doppler_factor(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)

    comov_energy = r_packet.energy * old_doppler_factor
    r_packet.energy = comov_energy * inverse_new_doppler_factor

    if line_interaction_type == LineInteractionType.SCATTER:
        line_emission(r_packet, r_packet.next_line_id, time_explosion,
                      numba_plasma)
    else:  # includes both macro atom and downbranch - encoded in the transition probabilities
        emission_line_id = macro_atom(r_packet, numba_plasma)
        line_emission(r_packet, emission_line_id, time_explosion, numba_plasma)
예제 #4
0
def set_packet_props_partial_relativity(r_packet, numba_model):
    inverse_doppler_factor = get_inverse_doppler_factor(
        r_packet.r,
        r_packet.mu,
        numba_model.time_explosion,
    )
    r_packet.nu *= inverse_doppler_factor
    r_packet.energy *= inverse_doppler_factor
예제 #5
0
def test_unphysical_inverse_doppler_factor(mu, r, inv_t_exp):
    # Set the params from test cases here
    # TODO: add relativity tests
    time_explosion = 1 / inv_t_exp

    # Perform any other setups just before this, they can be additional calls
    # to other methods or introduction of some temporary variables
    with pytest.raises(r_packet.SuperluminalError):
        obtained = r_packet.get_inverse_doppler_factor(r, mu, time_explosion)
예제 #6
0
def set_packet_props_full_relativity(r_packet, numba_model):
    beta = (r_packet.r / numba_model.time_explosion) / C_SPEED_OF_LIGHT

    inverse_doppler_factor = get_inverse_doppler_factor(
        r_packet.r,
        r_packet.mu,
        numba_model.time_explosion,
    )

    r_packet.nu *= inverse_doppler_factor
    r_packet.energy *= inverse_doppler_factor
    r_packet.mu = (r_packet.mu + beta) / (1 + beta * r_packet.mu)
예제 #7
0
def test_get_inverse_doppler_factor(mu, r, inv_t_exp, expected):
    # Set the params from test cases here
    # TODO: add relativity tests
    time_explosion = 1 / inv_t_exp

    # Perform any other setups just before this, they can be additional calls
    # to other methods or introduction of some temporary variables

    obtained = r_packet.get_inverse_doppler_factor(r, mu, time_explosion)

    # Perform required assertions
    assert_almost_equal(obtained, expected)
예제 #8
0
def test_frame_transformations(mu, r, inv_t_exp, full_relativity):
    packet = r_packet.RPacket(r=r, mu=mu, energy=0.9, nu=0.4)
    mc.full_relativity = bool(full_relativity)
    mc.full_relativity = full_relativity

    inverse_doppler_factor = r_packet.get_inverse_doppler_factor(
        r, mu, 1 / inv_t_exp)
    r_packet.angle_aberration_CMF_to_LF(packet, 1 / inv_t_exp, packet.mu)

    doppler_factor = get_doppler_factor(r, mu, 1 / inv_t_exp)
    mc.full_relativity = False

    assert_almost_equal(doppler_factor * inverse_doppler_factor, 1.0)