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.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.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, )
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.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, )
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)
def single_packet_loop(r_packet, numba_model, numba_plasma, estimators, vpacket_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 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 mc_logger.DEBUG_MODE: r_packet_track_nu = [r_packet.nu] r_packet_track_mu = [r_packet.mu] r_packet_track_r = [r_packet.r] r_packet_track_interaction = [InteractionType.BOUNDARY] r_packet_track_distance = [0.0] 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 mc_logger.DEBUG_MODE: r_packet_track_nu.append(r_packet.nu) r_packet_track_mu.append(r_packet.mu) r_packet_track_r.append(r_packet.r) r_packet_track_interaction.append(interaction_type) r_packet_track_distance.append(distance) if mc_logger.DEBUG_MODE: return ( r_packet_track_nu, r_packet_track_mu, r_packet_track_r, r_packet_track_interaction, r_packet_track_distance, )