Beispiel #1
0
def test_move_r_packet(
    packet_params,
    expected_params,
    packet,
    model,
    estimators,
    ENABLE_FULL_RELATIVITY,
):
    distance = 1.0e13
    packet.nu = packet_params["nu"]
    packet.mu = packet_params["mu"]
    packet.energy = packet_params["energy"]
    packet.r = packet_params["r"]

    numba_config.ENABLE_FULL_RELATIVITY = ENABLE_FULL_RELATIVITY
    r_packet_transport.move_r_packet.recompile(
    )  # This must be done as move_r_packet was jitted with ENABLE_FULL_RELATIVITY
    doppler_factor = frame_transformations.get_doppler_factor(
        packet.r, packet.mu, model.time_explosion)

    r_packet_transport.move_r_packet(packet, distance, model.time_explosion,
                                     estimators)

    assert_almost_equal(packet.mu, expected_params["mu"])
    assert_almost_equal(packet.r, expected_params["r"])

    expected_j = expected_params["j"]
    expected_nubar = expected_params["nubar"]

    if ENABLE_FULL_RELATIVITY:
        expected_j *= doppler_factor
        expected_nubar *= doppler_factor

    numba_config.ENABLE_FULL_RELATIVITY = False
    assert_allclose(estimators.j_estimator[packet.current_shell_id],
                    expected_j,
                    rtol=5e-7)
    assert_allclose(
        estimators.nu_bar_estimator[packet.current_shell_id],
        expected_nubar,
        rtol=5e-7,
    )
Beispiel #2
0
def test_move_packet(packet_params, expected_params, full_relativity):
    distance = 1e13
    r, mu, nu, energy = 7.5e14, 0.3, 0.4, 0.9
    time_explosion = 5.2e7
    packet = r_packet.RPacket(r, mu, nu, energy)
    packet.nu = packet_params["nu"]
    packet.mu = packet_params["mu"]
    packet.energy = packet_params["energy"]
    packet.r = packet_params["r"]
    # model.full_relativity = full_relativity
    mc.full_relativity = full_relativity

    doppler_factor = get_doppler_factor(packet.r, packet.mu, time_explosion)
    numba_estimator = Estimators(packet_params["j"], packet_params["nu_bar"],
                                 0, 0)
    r_packet_transport.move_r_packet(packet, distance, time_explosion,
                                     numba_estimator)

    assert_almost_equal(packet.mu, expected_params["mu"])
    assert_almost_equal(packet.r, expected_params["r"])

    expected_j = expected_params["j"]
    expected_nubar = expected_params["nubar"]
    if full_relativity:
        expected_j *= doppler_factor
        expected_nubar *= doppler_factor

    mc.full_relativity = False

    assert_allclose(
        numba_estimator.j_estimator[packet.current_shell_id],
        expected_j,
        rtol=5e-7,
    )
    assert_allclose(
        numba_estimator.nu_bar_estimator[packet.current_shell_id],
        expected_nubar,
        rtol=5e-7,
    )
Beispiel #3
0
def test_compute_distance2line_relativistic(mu, r, t_exp, nu, nu_line,
                                            full_relativity):
    packet = r_packet.RPacket(r=r, nu=nu, mu=mu, energy=0.9)
    # packet.nu_line = nu_line
    numba_estimator = Estimators(
        runner.j_estimator,
        runner.nu_bar_estimator,
        runner.j_blue_estimator,
        runner.Edotlu_estimator,
    )
    mc.full_relativity = bool(full_relativity)

    doppler_factor = get_doppler_factor(r, mu, t_exp)
    comov_nu = packet.nu * doppler_factor
    distance = r_packet.calculate_distance_line(packet, comov_nu, nu_line,
                                                t_exp)
    r_packet_transport.move_r_packet(packet, distance, t_exp, numba_estimator)

    doppler_factor = get_doppler_factor(r, mu, t_exp)
    comov_nu = packet.nu * doppler_factor
    mc.full_relativity = False

    assert_allclose(comov_nu, nu_line, rtol=1e-14)
Beispiel #4
0
def single_packet_loop(
    r_packet,
    numba_model,
    numba_plasma,
    estimators,
    vpacket_collection,
    rpacket_collection,
):
    """
    Parameters
    ----------
    r_packet : tardis.montecarlo.montecarlo_numba.r_packet.RPacket
    numba_model : tardis.montecarlo.montecarlo_numba.numba_interface.NumbaModel
    numba_plasma : tardis.montecarlo.montecarlo_numba.numba_interface.NumbaPlasma
    estimators : tardis.montecarlo.montecarlo_numba.numba_interface.Estimators
    vpacket_collection : tardis.montecarlo.montecarlo_numba.numba_interface.VPacketCollection
    rpacket_collection : tardis.montecarlo.montecarlo_numba.numba_interface.RPacketCollection

    Returns
    -------
    None
        This function does not return anything but changes the r_packet object
        and if virtual packets are requested - also updates the vpacket_collection
    """

    line_interaction_type = montecarlo_configuration.line_interaction_type

    if montecarlo_configuration.full_relativity:
        set_packet_props_full_relativity(r_packet, numba_model)
    else:
        set_packet_props_partial_relativity(r_packet, numba_model)
    r_packet.initialize_line_id(numba_plasma, numba_model)

    trace_vpacket_volley(r_packet, vpacket_collection, numba_model,
                         numba_plasma)

    if montecarlo_configuration.RPACKET_TRACKING:
        rpacket_collection.track(r_packet)

    while r_packet.status == PacketStatus.IN_PROCESS:
        distance, interaction_type, delta_shell = trace_packet(
            r_packet, numba_model, numba_plasma, estimators)

        if interaction_type == InteractionType.BOUNDARY:
            move_r_packet(r_packet, distance, numba_model.time_explosion,
                          estimators)
            move_packet_across_shell_boundary(r_packet, delta_shell,
                                              len(numba_model.r_inner))

        elif interaction_type == InteractionType.LINE:
            r_packet.last_interaction_type = 2

            move_r_packet(r_packet, distance, numba_model.time_explosion,
                          estimators)
            line_scatter(
                r_packet,
                numba_model.time_explosion,
                line_interaction_type,
                numba_plasma,
            )
            trace_vpacket_volley(r_packet, vpacket_collection, numba_model,
                                 numba_plasma)

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

            move_r_packet(r_packet, distance, numba_model.time_explosion,
                          estimators)
            thomson_scatter(r_packet, numba_model.time_explosion)

            trace_vpacket_volley(r_packet, vpacket_collection, numba_model,
                                 numba_plasma)

        if montecarlo_configuration.RPACKET_TRACKING:
            rpacket_collection.track(r_packet)
Beispiel #5
0
def single_packet_loop(
    r_packet,
    numba_model,
    numba_plasma,
    estimators,
    vpacket_collection,
    rpacket_tracker,
):
    """
    Parameters
    ----------
    r_packet : tardis.montecarlo.montecarlo_numba.r_packet.RPacket
    numba_model : tardis.montecarlo.montecarlo_numba.numba_interface.NumbaModel
    numba_plasma : tardis.montecarlo.montecarlo_numba.numba_interface.NumbaPlasma
    estimators : tardis.montecarlo.montecarlo_numba.numba_interface.Estimators
    vpacket_collection : tardis.montecarlo.montecarlo_numba.numba_interface.VPacketCollection
    rpacket_collection : tardis.montecarlo.montecarlo_numba.numba_interface.RPacketCollection

    Returns
    -------
    None
        This function does not return anything but changes the r_packet object
        and if virtual packets are requested - also updates the vpacket_collection
    """
    line_interaction_type = montecarlo_configuration.line_interaction_type

    if montecarlo_configuration.full_relativity:
        set_packet_props_full_relativity(r_packet, numba_model)
    else:
        set_packet_props_partial_relativity(r_packet, numba_model)
    r_packet.initialize_line_id(numba_plasma, numba_model)

    trace_vpacket_volley(
        r_packet, vpacket_collection, numba_model, numba_plasma
    )

    if montecarlo_configuration.RPACKET_TRACKING:
        rpacket_tracker.track(r_packet)

    # this part of the code is temporary and will be better incorporated
    while r_packet.status == PacketStatus.IN_PROCESS:
        # Compute continuum quantities
        # trace packet (takes opacities)
        doppler_factor = get_doppler_factor(
            r_packet.r, r_packet.mu, numba_model.time_explosion
        )
        comov_nu = r_packet.nu * doppler_factor
        chi_e = chi_electron_calculator(
            numba_plasma, comov_nu, r_packet.current_shell_id
        )
        if montecarlo_configuration.CONTINUUM_PROCESSES_ENABLED:
            (
                chi_bf_tot,
                chi_bf_contributions,
                current_continua,
                x_sect_bfs,
                chi_ff,
            ) = chi_continuum_calculator(
                numba_plasma, comov_nu, r_packet.current_shell_id
            )
            chi_continuum = chi_e + chi_bf_tot + chi_ff
            escat_prob = chi_e / chi_continuum  # probability of e-scatter
            distance, interaction_type, delta_shell = trace_packet_continuum(
                r_packet,
                numba_model,
                numba_plasma,
                estimators,
                chi_continuum,
                escat_prob,
            )
            update_bound_free_estimators(
                comov_nu,
                r_packet.energy * doppler_factor,
                r_packet.current_shell_id,
                distance,
                estimators,
                numba_plasma.t_electrons[r_packet.current_shell_id],
                x_sect_bfs,
                current_continua,
                numba_plasma.bf_threshold_list_nu,
            )
        else:
            escat_prob = 1.0
            chi_continuum = chi_e
            distance, interaction_type, delta_shell = trace_packet_continuum(
                r_packet,
                numba_model,
                numba_plasma,
                estimators,
                chi_continuum,
                escat_prob,
            )

        # If continuum processes: update continuum estimators

        if interaction_type == InteractionType.BOUNDARY:
            move_r_packet(
                r_packet, distance, numba_model.time_explosion, estimators
            )
            move_packet_across_shell_boundary(
                r_packet, delta_shell, len(numba_model.r_inner)
            )

        elif interaction_type == InteractionType.LINE:
            r_packet.last_interaction_type = 2
            move_r_packet(
                r_packet, distance, numba_model.time_explosion, estimators
            )
            line_scatter(
                r_packet,
                numba_model.time_explosion,
                line_interaction_type,
                numba_plasma,
            )
            trace_vpacket_volley(
                r_packet, vpacket_collection, numba_model, numba_plasma
            )

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

            move_r_packet(
                r_packet, distance, numba_model.time_explosion, estimators
            )
            thomson_scatter(r_packet, numba_model.time_explosion)

            trace_vpacket_volley(
                r_packet, vpacket_collection, numba_model, numba_plasma
            )
        elif (
            montecarlo_configuration.CONTINUUM_PROCESSES_ENABLED
            and interaction_type == InteractionType.CONTINUUM_PROCESS
        ):
            r_packet.last_interaction_type = InteractionType.CONTINUUM_PROCESS
            move_r_packet(
                r_packet, distance, numba_model.time_explosion, estimators
            )
            continuum_event(
                r_packet,
                numba_model.time_explosion,
                numba_plasma,
                chi_bf_tot,
                chi_ff,
                chi_bf_contributions,
                current_continua,
            )

            trace_vpacket_volley(
                r_packet, vpacket_collection, numba_model, numba_plasma
            )
        else:
            pass
        if montecarlo_configuration.RPACKET_TRACKING:
            rpacket_tracker.track(r_packet)