コード例 #1
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

    Parameters
    ----------
    r_packet : tardis.montecarlo.montecarlo_numba.r_packet.RPacket
    time_explosion : float
    line_interaction_type : enum
    numba_plasma : tardis.montecarlo.montecarlo_numba.numba_interface.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
        comov_nu = r_packet.nu * old_doppler_factor  # Is this necessary?
        r_packet.nu = comov_nu * inverse_new_doppler_factor
        activation_level_id = numba_plasma.line2macro_level_upper[
            r_packet.next_line_id]
        macro_atom_event(activation_level_id, r_packet, time_explosion,
                         numba_plasma)
コード例 #2
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 : tardis.montecarlo.montecarlo_numba.r_packet.RPacket
    emission_line_id : int
    time_explosion : float
    numba_plasma : tardis.montecarlo.montecarlo_numba.numba_interface.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 montecarlo_configuration.full_relativity:
        r_packet.mu = angle_aberration_CMF_to_LF(r_packet, time_explosion,
                                                 r_packet.mu)
コード例 #3
0
def thomson_scatter(r_packet, time_explosion):
    """
    Thomson scattering — no longer line scattering
    \n1) get the doppler factor at that position with the old angle
    \n2) convert the current energy and nu into the comoving frame with the old mu
    \n3) Scatter and draw new mu - update mu
    \n4) Transform the comoving energy and nu back using the new mu

    Parameters
    ----------
    r_packet : tardis.montecarlo.montecarlo_numba.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)
    temp_doppler_factor = get_doppler_factor(r_packet.r, r_packet.mu,
                                             time_explosion)
コード例 #4
0
ファイル: single_packet_loop.py プロジェクト: smithis7/tardis
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
ファイル: single_packet_loop.py プロジェクト: smithis7/tardis
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)
コード例 #6
0
def scatter(r_packet, time_explosion):

    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.energy = comov_energy * inverse_new_doppler_factor

    return comov_nu, inverse_new_doppler_factor
コード例 #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 = frame_transformations.get_inverse_doppler_factor(
        r, mu, time_explosion)

    # Perform required assertions
    assert_almost_equal(obtained, expected)
コード例 #8
0
def continuum_event(
    r_packet,
    time_explosion,
    numba_plasma,
    chi_bf_tot,
    chi_ff,
    chi_bf_contributions,
    current_continua,
):
    """
    continuum event handler - activate the macroatom and run the handler

    Parameters
    ----------
    r_packet : tardis.montecarlo.montecarlo_numba.r_packet.RPacket
    time_explosion : float
    numba_plasma : tardis.montecarlo.montecarlo_numba.numba_interface.NumbaPlasma
    continuum : tardis.montecarlo.montecarlo_numba.numba_interface.Continuum
    """
    old_doppler_factor = get_doppler_factor(r_packet.r, r_packet.mu,
                                            time_explosion)

    r_packet.mu = get_random_mu()
    inverse_doppler_factor = get_inverse_doppler_factor(
        r_packet.r, r_packet.mu, time_explosion)
    comov_energy = r_packet.energy * old_doppler_factor
    comov_nu = (r_packet.nu * old_doppler_factor
                )  # make sure frequency should be updated
    r_packet.energy = comov_energy * inverse_doppler_factor
    r_packet.nu = comov_nu * inverse_doppler_factor

    destination_level_idx = determine_continuum_macro_activation_idx(
        numba_plasma,
        comov_nu,
        chi_bf_tot,
        chi_ff,
        chi_bf_contributions,
        current_continua,
    )

    macro_atom_event(destination_level_idx, r_packet, time_explosion,
                     numba_plasma)
コード例 #9
0
def free_free_emission(r_packet, time_explosion, numba_plasma):
    """
    Free-Free emission - set the frequency from electron-ion interaction

    Parameters
    ----------
    r_packet : tardis.montecarlo.montecarlo_numba.r_packet.RPacket
    time_explosion : float
    numba_plasma : tardis.montecarlo.montecarlo_numba.numba_interface.NumbaPlasma
    """

    inverse_doppler_factor = get_inverse_doppler_factor(
        r_packet.r, r_packet.mu, time_explosion)
    comov_nu = sample_nu_free_free(numba_plasma, r_packet.current_shell_id)
    r_packet.nu = comov_nu * inverse_doppler_factor
    current_line_id = get_current_line_id(comov_nu, numba_plasma.line_list_nu)
    r_packet.next_line_id = current_line_id

    if montecarlo_configuration.full_relativity:
        r_packet.mu = angle_aberration_CMF_to_LF(r_packet, time_explosion,
                                                 r_packet.mu)