コード例 #1
0
def test_compute_distance2line(packet_params, expected_params):
    r = 7.5e14
    mu = 0.3
    nu = 0.4
    energy = 0.9
    packet = r_packet.RPacket(r, mu, nu, energy)
    nu_line = packet_params["nu_line"]
    # packet.next_line_id = packet_params['next_line_id']
    # packet.last_line = packet_params['last_line']

    time_explosion = 5.2e7

    doppler_factor = get_doppler_factor(packet.r, packet.mu, time_explosion)
    comov_nu = packet.nu * doppler_factor

    d_line = 0
    obtained_tardis_error = None
    try:
        d_line = r_packet.calculate_distance_line(packet, comov_nu, nu_line,
                                                  time_explosion)
    except utils.MonteCarloException:
        obtained_tardis_error = utils.MonteCarloException

    assert_almost_equal(d_line, expected_params["d_line"])
    assert obtained_tardis_error == expected_params["tardis_error"]
コード例 #2
0
def test_compute_distance2line(packet_params, expected_params, packet, model):
    packet = r_packet.RPacket(packet.r, packet.mu, packet.nu, packet.energy)
    nu_line = packet_params["nu_line"]
    # packet.next_line_id = packet_params['next_line_id']
    # packet.last_line = packet_params['last_line']

    time_explosion = model.time_explosion

    doppler_factor = r_packet.get_doppler_factor(packet.r, packet.mu,
                                                 time_explosion)
    comov_nu = packet.nu * doppler_factor

    d_line = 0
    obtained_tardis_error = None
    try:
        d_line = r_packet.calculate_distance_line(packet, comov_nu, nu_line,
                                                  time_explosion)
    except r_packet.MonteCarloException:
        obtained_tardis_error = r_packet.MonteCarloException

    assert_almost_equal(d_line, expected_params["d_line"])
    assert obtained_tardis_error == expected_params["tardis_error"]
コード例 #3
0
def test_calculate_distance_line(packet_params, expected_params, static_packet,
                                 model):
    nu_line = packet_params["nu_line"]
    is_last_line = packet_params["is_last_line"]

    time_explosion = model.time_explosion

    doppler_factor = r_packet.get_doppler_factor(static_packet.r,
                                                 static_packet.mu,
                                                 time_explosion)
    comov_nu = static_packet.nu * doppler_factor

    d_line = 0
    obtained_tardis_error = None
    try:
        d_line = r_packet.calculate_distance_line(static_packet, comov_nu,
                                                  is_last_line, nu_line,
                                                  time_explosion)
    except r_packet.MonteCarloException:
        obtained_tardis_error = r_packet.MonteCarloException

    assert_almost_equal(d_line, expected_params["d_line"])
    assert obtained_tardis_error == expected_params["tardis_error"]
コード例 #4
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.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)
コード例 #5
0
def trace_vpacket_within_shell(v_packet, numba_model, numba_plasma):
    """
    Trace VPacket within one shell (relatively simple operation)
    """
    r_inner = numba_model.r_inner[v_packet.current_shell_id]
    r_outer = numba_model.r_outer[v_packet.current_shell_id]

    distance_boundary, delta_shell = calculate_distance_boundary(
        v_packet.r, v_packet.mu, r_inner, r_outer
    )
    # defining start for line interaction
    start_line_id = v_packet.next_line_id

    # e scattering initialization

    cur_electron_density = numba_plasma.electron_density[
        v_packet.current_shell_id
    ]
    tau_electron = calculate_tau_electron(
        cur_electron_density, distance_boundary
    )
    tau_trace_combined = tau_electron

    # Calculating doppler factor
    doppler_factor = get_doppler_factor(
        v_packet.r, v_packet.mu, numba_model.time_explosion
    )
    comov_nu = v_packet.nu * doppler_factor
    cur_line_id = start_line_id

    for cur_line_id in range(start_line_id, len(numba_plasma.line_list_nu)):
        # if tau_trace_combined > 10: ### FIXME ?????
        #    break

        nu_line = numba_plasma.line_list_nu[cur_line_id]
        # TODO: Check if this is what the C code does

        tau_trace_line = numba_plasma.tau_sobolev[
            cur_line_id, v_packet.current_shell_id
        ]

        if cur_line_id == len(numba_plasma.line_list_nu) - 1:
            is_last_line = True
        else:
            is_last_line = False

        distance_trace_line = calculate_distance_line(
            v_packet,
            comov_nu,
            is_last_line,
            nu_line,
            numba_model.time_explosion,
        )

        if cur_line_id != (len(numba_plasma.line_list_nu) - 1):
            test_for_close_line(
                v_packet,
                cur_line_id,
                numba_plasma.line_list_nu[cur_line_id - 1],
                numba_plasma,
            )

        if distance_boundary <= distance_trace_line:
            break

        tau_trace_combined += tau_trace_line

    else:
        if cur_line_id == (len(numba_plasma.line_list_nu) - 1):
            cur_line_id += 1
    v_packet.next_line_id = cur_line_id

    return tau_trace_combined, distance_boundary, delta_shell