double test_calculate_chi_bf(void){ rpacket_t rp; storage_model_t sm; init_rpacket(&rp); init_storage_model(&sm); rk_state mt_state; irandom(&mt_state); int64_t j_blue_idx = 0; double D_BOUNDARY = compute_distance2boundary(&rp, &sm); rpacket_set_d_boundary(&rp, D_BOUNDARY); double D_LINE; // FIXME MR: return status of compute_distance2line() is ignored compute_distance2line(&rp, &sm, &D_LINE); rpacket_set_d_line(&rp, D_LINE); move_packet(&rp, &sm, 1e13); double d_line = rpacket_get_d_line(&rp); increment_j_blue_estimator(&rp, &sm, d_line, j_blue_idx); double DISTANCE = 1e13; montecarlo_line_scatter(&rp, &sm, DISTANCE, &mt_state); DISTANCE = 0.95e13; // MR: wrong: move_packet_across_shell_boundary() returns void move_packet_across_shell_boundary(&rp, &sm, DISTANCE, &mt_state); montecarlo_one_packet(&sm, &rp, 1, &mt_state); montecarlo_one_packet_loop(&sm, &rp, 1, &mt_state); DISTANCE = 1e13; montecarlo_thomson_scatter(&rp, &sm, DISTANCE, &mt_state); calculate_chi_bf(&rp, &sm); double res = rpacket_doppler_factor (&rp, &sm); dealloc_storage_model(&sm); return res; }
extern inline void montecarlo_compute_distances(rpacket_t *packet, storage_model_t *storage) { // Check if the last line was the same nu as the current line. if (rpacket_get_close_line(packet)) { // If so set the distance to the line to 0.0 rpacket_set_d_line(packet, 0.0); // Reset close_line. rpacket_set_close_line(packet, false); } else { rpacket_set_d_boundary(packet, compute_distance2boundary(packet, storage)); double d_line; compute_distance2line(packet, storage, &d_line); rpacket_set_d_line(packet, d_line); rpacket_set_d_electron(packet, compute_distance2electron(packet, storage)); } }
double test_compute_distance2line(void){ rpacket_t rp; storage_model_t sm; init_rpacket(&rp); init_storage_model(&sm); double D_LINE; // FIXME MR: return status of compute_distance2line() is ignored compute_distance2line(&rp, &sm, &D_LINE); rpacket_set_d_line(&rp, D_LINE); dealloc_storage_model(&sm); return D_LINE; }
static void montecarlo_compute_distances (rpacket_t * packet, storage_model_t * storage) { // Check if the last line was the same nu as the current line. if (rpacket_get_close_line (packet)) { // If so set the distance to the line to 0.0 rpacket_set_d_line (packet, 0.0); // Reset close_line. rpacket_set_close_line (packet, false); } else { compute_distance2boundary(packet, storage); compute_distance2line (packet, storage); // FIXME MR: return status of compute_distance2line() is ignored compute_distance2continuum (packet, storage); } }
double test_increment_j_blue_estimator(void){ rpacket_t rp; storage_model_t sm; init_rpacket(&rp); init_storage_model(&sm); int64_t j_blue_idx = 0; double D_BOUNDARY = compute_distance2boundary(&rp, &sm); rpacket_set_d_boundary(&rp, D_BOUNDARY); double D_LINE; // FIXME MR: return status of compute_distance2line() is ignored compute_distance2line(&rp, &sm, &D_LINE); rpacket_set_d_line(&rp, D_LINE); move_packet(&rp, &sm, 1e13); double d_line = rpacket_get_d_line(&rp); increment_j_blue_estimator(&rp, &sm, d_line, j_blue_idx); double res = sm.line_lists_j_blues[j_blue_idx]; dealloc_storage_model(&sm); return res; }
tardis_error_t compute_distance2line (rpacket_t * packet, const storage_model_t * storage) { if (!rpacket_get_last_line (packet)) { double r = rpacket_get_r (packet); double mu = rpacket_get_mu (packet); double nu = rpacket_get_nu (packet); double nu_line = rpacket_get_nu_line (packet); double distance, nu_diff; double t_exp = storage->time_explosion; double inverse_t_exp = storage->inverse_time_explosion; int64_t cur_zone_id = rpacket_get_current_shell_id (packet); double doppler_factor = 1.0 - mu * r * inverse_t_exp * INVERSE_C; double comov_nu = nu * doppler_factor; if ( (nu_diff = comov_nu - nu_line) >= 0) { distance = (nu_diff / nu) * C * t_exp; rpacket_set_d_line (packet, distance); return TARDIS_ERROR_OK; } else { if (rpacket_get_next_line_id (packet) == storage->no_of_lines - 1) { fprintf (stderr, "last_line = %f\n", storage-> line_list_nu[rpacket_get_next_line_id (packet) - 1]); fprintf (stderr, "Last line in line list reached!"); } else if (rpacket_get_next_line_id (packet) == 0) { fprintf (stderr, "First line in line list!"); fprintf (stderr, "next_line = %f\n", storage-> line_list_nu[rpacket_get_next_line_id (packet) + 1]); } else { fprintf (stderr, "last_line = %f\n", storage-> line_list_nu[rpacket_get_next_line_id (packet) - 1]); fprintf (stderr, "next_line = %f\n", storage-> line_list_nu[rpacket_get_next_line_id (packet) + 1]); } fprintf (stderr, "ERROR: Comoving nu less than nu_line!\n"); fprintf (stderr, "comov_nu = %f\n", comov_nu); fprintf (stderr, "nu_line = %f\n", nu_line); fprintf (stderr, "(comov_nu - nu_line) / nu_line = %f\n", (comov_nu - nu_line) / nu_line); fprintf (stderr, "r = %f\n", r); fprintf (stderr, "mu = %f\n", mu); fprintf (stderr, "nu = %f\n", nu); fprintf (stderr, "doppler_factor = %f\n", doppler_factor); fprintf (stderr, "cur_zone_id = %" PRIi64 "\n", cur_zone_id); return TARDIS_ERROR_COMOV_NU_LESS_THAN_NU_LINE; } } else { rpacket_set_d_line (packet, MISS_DISTANCE); return TARDIS_ERROR_OK; } }
bool test_rpacket_get_d_line(double value) { rpacket_t rp; rpacket_set_d_line(&rp, value); return value==rpacket_get_d_line(&rp); }