Loading Makefile 0 → 100644 +54 −0 Original line number Diff line number Diff line LDFLAGS = -L ${LIB_CFITSIO} -L ${LIB_GSL} -L ${LIB_MPI} -lcfitsio -lm -lgsl -lgslcblas -lmpi INCLUDE = -I ${PWD} -I ${HEADERS_CFITSIO} -I ${HEADERS_GSL} -I ${HEADERS_MPI} -I ${MC_INSTDIR}/../../include/ CFLAGS = -g -Ofast -Wall ${INCLUDE} LOCAL_DIR = ${PWD} MC_SLAB = ${MC_INSTDIR}/../../gr_code/slab_rte MC_POLARIZATION = ${MC_INSTDIR}/polarization MC_ELE_DISTRIBUTION = ${MC_INSTDIR}/electron_distributions MC_GENERAL = ${MC_INSTDIR}/general_routines/ MC_COORD = ${MC_INSTDIR}/coordinates_systems MC_SEED = ${MC_INSTDIR}/seed_photons/ MC_HYDRO = ${MC_INSTDIR}/../../gr_code/hydrodynamics #======================================================================== LOCAL_DIR_OBJ= ${LOCAL_DIR}/main_program.o ${LOCAL_DIR}/check_results.o ${LOCAL_DIR}/compute_results.o ${LOCAL_DIR}/function_integrals.o ${LOCAL_DIR}/legendre_integration.o ${LOCAL_DIR}/set_deltatau.o ${LOCAL_DIR}/slab_polarization.o ${LOCAL_DIR}/solve_rte.o ${LOCAL_DIR}/mc_slab.o ${LOCAL_DIR}/compute_stokes.o ${LOCAL_DIR}/collect_photons.o MC_POLARIZATION_OBJ=${MC_POLARIZATION}/ortonormal_axes.o ${MC_POLARIZATION}/unpolarized_seedphot.o ${MC_POLARIZATION}/polarization_probability.o ${MC_POLARIZATION}/depolarization_probability.o ${MC_POLARIZATION}/electfield_as_new.o ${MC_POLARIZATION}/sample_azim_angle.o ${MC_POLARIZATION}/allocate_stokes_pointer.o ${MC_POLARIZATION}/disk_polarizationelectricfield.o ${MC_POLARIZATION}/pdeg_atmosphere.o ${MC_POLARIZATION}/write_polardata.o ${MC_POLARIZATION}/select_quadrant.o $ ${MC_POLARIZATION}/detector_axis.o MC_ELE_DISTRIBUTION_OBJ=${MC_ELE_DISTRIBUTION}/hybrid/eledist_hybrid.o ${MC_ELE_DISTRIBUTION}/hybrid/integrate_maxwgamma.o ${MC_ELE_DISTRIBUTION}/sample_electron.o ${MC_ELE_DISTRIBUTION}/powerlaw/eledist_nth.o ${MC_ELE_DISTRIBUTION}/maxwellian/subrel_maxwellian.o MC_COORD_OBJ=${MC_COORD}/versor_boost.o ${MC_COORD}/elmag_lorentztransform.o MC_GENERAL_OBJ=${MC_INSTDIR}/../../gr_code/clock_random.o ${MC_INSTDIR}/../../gr_code/dmatrix.o ${MC_INSTDIR}/../../gr_code/round_to_digits.o ${MC_INSTDIR}/general_routines/gauleg.o ${MC_INSTDIR}/general_routines/numpar.o ${MC_INSTDIR}/general_routines/stringpar.o ${MC_INSTDIR}/general_routines/strrev.o ${MC_INSTDIR}/general_routines/stringconcat.o ${MC_INSTDIR}/general_routines/interpolate_kn.o ${MC_INSTDIR}/../../gr_code/dot_prod.o ${MC_GENERAL}/read_array.o ${MC_INSTDIR}/../../gr_code/vect_prod.o ${MC_GENERAL}/read_matrix.o ${MC_GENERAL}/energy_lorentz_boost.o ${MC_GENERAL}/new_energy_erf.o ${MC_GENERAL}/make_array_angles.o ${MC_INSTDIR}/../../gr_code/init_mpi.o ${MC_INSTDIR}/../../gr_code/abs_val.o ${MC_GENERAL}/make_array_energy.o MC_SEED_OBJ=${MC_SEED}/bb_spec.o MC_HYDRO_OBJ=${MC_HYDRO}/reverse_array.o MC_SLAB_OBJ=${MC_SLAB}/electricfield_fromfile.o ${MC_SLAB}/read_resultsfile.o ${MC_SLAB}/setup_gsl_objects.o ${MC_SLAB}/compute_cumulative_angdist.o all: start_iteration %.o: %.c $(DEPS) $(CC) -c -o $@ $< $(CFLAGS) start_iteration: ${LOCAL_DIR_OBJ} ${MC_GENERAL_OBJ} ${MC_POLARIZATION_OBJ} ${MC_ELE_DISTRIBUTION_OBJ} ${MC_COORD_OBJ} ${MC_SEED_OBJ} ${MC_HYDRO_OBJ} ${MC_SLAB_OBJ} ${CC} $^ -o $@ ${LDFLAGS} clean: rm -f main_program.o ${LOCAL_DIR_OBJ} ${MC_GENERAL_OBJ} ${MC_POLARIZATION_OBJ} ${MC_ELE_DISTRIBUTION_OBJ} ${MC_COORD_OBJ} ${MC_SEED_OBJ} ${MC_HYDRO_OBJ} ${MC_SLAB_OBJ} ciao: echo ${MC_SLAB_OBJ} README.txt 0 → 100644 +3 −0 Original line number Diff line number Diff line The code computes the polarization degree of radiation from a plane-parallel slab in the diffusion approximation for a pure scattering atmosphere. check_results.c 0 → 100644 +50 −0 Original line number Diff line number Diff line #include "iteration_functions.h" void check_results(gsl_spline* Spline_sample_Iu, gsl_spline* Spline_eval_pdeg, gsl_spline* Spline_eval_limbdark) { double u_test = 0, P = 0, Itot = 0; /*double Ir, Il;*/ double csi; int ii, status; for (ii = 0; ii < 2500; ii++) { csi = clock_random(); status = gsl_spline_eval_e(Spline_sample_Iu, csi, xacc_1d, &u_test); if (status) { printf("File %s\n", __FILE__); printf("csi=%lf \n", csi); printf("Error at line %d: %s\n", __LINE__, gsl_strerror(status)); exit(1); } status = gsl_spline_eval_e(Spline_eval_pdeg, u_test, xacc_1d, &P); if (status) { printf("File %s\n", __FILE__); printf("csi=%lf u_test=%lf\n", csi, u_test); printf("Error at line %d: %s\n", __LINE__, gsl_strerror(status)); exit(1); } status = gsl_spline_eval_e(Spline_eval_limbdark, u_test, xacc_1d, &Itot); if (status) { printf("File %s\n", __FILE__); printf("Error at line %d: %s\n", __LINE__, gsl_strerror(status)); exit(1); } if (P > 1) { printf("%lf %lf %5.4e\n", u_test, P, Itot); } /* Ir = 1 / 2. * Itot * (1 + P); Il = 1 / 2. * Itot * (1 - P); */ } } No newline at end of file collect_photons.c 0 → 100644 +153 −0 Original line number Diff line number Diff line #include "iteration_functions.h" #define size 100 int good_j, good_k, n; /*==================================================================================*/ void collect_photons(double ene, double* k, double* array_ene, double** array_counts, int flag) { double center_ene; double delta_ene; double total_counts; double counts; int i, j; double kz; if (k[2] < 0) { kz = -k[2]; } else { kz = k[2]; } // =====================================================================# // Define the array of the total counts // =====================================================================# static int array_total_counts[NSTEP_ENE]; // =====================================================================# // Loop on energies // =====================================================================# for (i = 0; i < nstepangles; i++) { if (array_ubounds[i] < -1 || array_ubounds[i] > 1) { printf("Error bounds %d %lf \n", i, array_ubounds[i]); } } for (i = 0; i < NSTEP_ENE; i++) { if ((ene >= array_ene[i]) && (ene < array_ene[i + 1])) { // =====================================================================# // If the parameter nstepangles is not set, then the total // spectrum is collected and exit from the loop over energy // Otherwise make additional loop over the polar angle defined // by array_u // =====================================================================# if (nstepangles < 2) { break; } else { for (j = 0; j < nstepangles; j++) { if (kz <= array_ubounds[j] && kz > array_ubounds[j + 1]) { good_j = j; array_counts[i][good_j]++; break; } } } // Else condition for photon energy within the boundaries defined by array_ene } else { continue; } // End of loop over energy } if (flag == 1) { dat_spectrum = fopen(outspec, "w"); if (dat_spectrum == NULL) { printf("Error opening file %s\n", outspec); exit(1); } // =========================================================================== /*Compute the total spectrum summed over all angles*/ // =========================================================================== for (i = 0; i < NSTEP_ENE; i++) { for (j = 0; j < nstepangles; j++) { array_total_counts[i] = array_total_counts[i] + array_counts[i][j]; } } // ==================================================================================== // Print spectra values, both total and, if set, also angle-dependent // ==================================================================================== for (i = 0; i < NSTEP_ENE - 1; i++) { center_ene = 0.5 * (array_ene[i + 1] + array_ene[i]); delta_ene = 0.5 * (array_ene[i + 1] - array_ene[i]); // ==================================================================================== // Total counts per keV // ==================================================================================== total_counts = array_total_counts[i] / (array_ene[i + 1] - array_ene[i]); fprintf(dat_spectrum, "%5.3e %5.3e %5.3e ", center_ene, delta_ene, total_counts * center_ene); for (j = 0; j < nstepangles; j++) { nph = 0; // ====================================================================================## // Print the columns with angle-dependent spectra spectrum in the file // ====================================================================================## counts = array_counts[i][j] / (array_ene[i + 1] - array_ene[i]); nph = nph + array_counts[i][j]; if (j < nstepangles - 1) { fprintf(dat_spectrum, " %5.4e ", counts * center_ene); } else { fprintf(dat_spectrum, " %5.4e\n", counts * center_ene); } } } fclose(dat_spectrum); } // End of flag condition for actually producing the qdp file // End of program } compute_results.c 0 → 100644 +201 −0 Original line number Diff line number Diff line #include "iteration_functions.h" double sum_kiter(int k_min, int k_max, int jj, Iklr_intensity* ptr_Iklr, Ikl_intensity* ptr_Ikl, Ikr_intensity* ptr_Ikr, int method); void compute_results(int method, int k_iter, int Nstep_tau, int Nstep_mu, double* array_mu, double* weights_u, Iklr_intensity* ptr_Iklr, Ikl_intensity* ptr_Ikl, Ikr_intensity* ptr_Ikr) { int jj, kk; double* Pdeg = malloc(Nstep_mu * sizeof(double)); double* Pdeg_Band1 = malloc(Nstep_mu * sizeof(double)); double* Pdeg_Band2 = malloc(Nstep_mu * sizeof(double)); double* Pdeg_Band3 = malloc(Nstep_mu * sizeof(double)); double* Pdeg_Band4 = malloc(Nstep_mu * sizeof(double)); double* Pdeg_Band5 = malloc(Nstep_mu * sizeof(double)); double* Itot_upstream = malloc(Nstep_mu * sizeof(double)); double* Itot_downstream = malloc(Nstep_mu * sizeof(double)); double sum_Il, sum_Ir; double sum_Il_downstream, sum_Ir_downstream; FILE* dat; dat = fopen(polarization_file, "w"); for (jj = 0; jj < Nstep_mu; jj++) { sum_Il = 0; sum_Ir = 0; sum_Il_downstream = 0; sum_Ir_downstream = 0; for (kk = 0; kk < k_iter; kk++) { if (method == 1) { sum_Il = sum_Il + ptr_Iklr[kk].Il_matrix_upstream[Nstep_tau - 1][jj]; sum_Ir = sum_Ir + ptr_Iklr[kk].Ir_matrix_upstream[Nstep_tau - 1][jj]; sum_Il_downstream = sum_Il_downstream + ptr_Iklr[kk].Il_matrix_downstream[Nstep_tau - 1][jj]; sum_Ir_downstream = sum_Ir_downstream + ptr_Iklr[kk].Ir_matrix_downstream[Nstep_tau - 1][jj]; } else { sum_Il = sum_Il + ptr_Ikl[kk].matrix[0][jj]; sum_Ir = sum_Ir + ptr_Ikr[kk].matrix[0][jj]; } } if (disktau >= 4 && k_iter > 40) { Pdeg_Band1[jj] = sum_kiter(0, 10, jj, ptr_Iklr, ptr_Ikl, ptr_Ikr, method); Pdeg_Band2[jj] = sum_kiter(10, 20, jj, ptr_Iklr, ptr_Ikl, ptr_Ikr, method); Pdeg_Band3[jj] = sum_kiter(20, 30, jj, ptr_Iklr, ptr_Ikl, ptr_Ikr, method); Pdeg_Band4[jj] = sum_kiter(30, 40, jj, ptr_Iklr, ptr_Ikl, ptr_Ikr, method); Pdeg_Band5[jj] = sum_kiter(40, k_iter, jj, ptr_Iklr, ptr_Ikl, ptr_Ikr, method); } Pdeg[jj] = (sum_Ir - sum_Il) / (sum_Ir + sum_Il); if (isnan(Pdeg[jj])) { printf("Error: Pdeg is NaN at u=%lf sum_Ir=%4.3e sum_Il=%4.3e\n", array_mu[jj], sum_Ir, sum_Il); } Itot_upstream[jj] = (sum_Ir + sum_Il); Itot_downstream[jj] = sum_Ir_downstream + sum_Il_downstream; } /*===========================================================================*/ /*Print I(u) normalized at the value u=1*/ /*===========================================================================*/ if (disktau < 4) { for (jj = 0; jj < Nstep_mu; jj++) { fprintf(dat, "%lf %5.4e %5.4e\n", array_mu[jj], Pdeg[jj], Itot_upstream[jj] / Itot_upstream[Nstep_mu - 1]); } } else { for (jj = 0; jj < Nstep_mu; jj++) { fprintf(dat, "%lf %5.4e %5.4e %5.4e %5.4e %5.4e %5.4e %5.4e \n", array_mu[jj], Pdeg[jj], Itot_upstream[jj] / Itot_upstream[Nstep_mu - 1], Pdeg_Band1[jj], Pdeg_Band2[jj], Pdeg_Band3[jj], Pdeg_Band4[jj], Pdeg_Band5[jj]); } } fclose(dat); /*===========================================================================*/ double TotalFlux = 0; double TotalFlux_downstream = 0; for (jj = 0; jj < Nstep_mu; jj++) { TotalFlux = TotalFlux + Itot_upstream[jj] * array_mu[jj] * weights_u[jj]; TotalFlux_downstream = TotalFlux_downstream + Itot_downstream[jj] * array_mu[jj] * weights_u[jj]; } printf("Total flux at the top (u>0) %lf\n", TotalFlux); printf("Total flux at the bottom (u<0) %lf\n", TotalFlux_downstream); printf("Percenatge of flux at the top %5.4f\n", TotalFlux / (TotalFlux + TotalFlux_downstream)); /*===========================================================================*/ dat = fopen(diffusion_file, "w"); fprintf(dat, "!Total flux at the top (u>0) %lf\n", TotalFlux); fprintf(dat, "!Total flux at the bottom (u<0) %lf\n", TotalFlux_downstream); fprintf(dat, "!Percenatge of flux at the top %5.4f\n", TotalFlux / (TotalFlux + TotalFlux_downstream)); double* diffusion = malloc(k_iter * sizeof(double)); double sum_k; for (kk = 0; kk < k_iter; kk++) { sum_k = 0; for (jj = 0; jj < Nstep_mu; jj++) { if (method == 1) { sum_k = sum_k + ptr_Iklr[kk].Il_matrix_upstream[Nstep_tau - 1][jj] * weights_u[jj] * array_mu[jj] + ptr_Iklr[kk].Ir_matrix_upstream[Nstep_tau - 1][jj] * weights_u[jj] * array_mu[jj]; } else { sum_k = sum_k + ptr_Ikl[kk].matrix[0][jj] + ptr_Ikr[kk].matrix[0][jj]; } } diffusion[kk] = sum_k; fprintf(dat, "%d %5.4e\n", kk, diffusion[kk]); } fclose(dat); /*===================================================================================*/ radiation_field_t* radiation_field = (radiation_field_t*)malloc(sizeof(radiation_field_t)); radiation_field->u_min = array_mu[0]; radiation_field->u_max = array_mu[Nstep_mu - 1]; read_resultsfile(polarization_file, radiation_field, RTE); setup_gsl_objects(radiation_field, RTE); check_results(Spline_sample_Iu, Spline_eval_pdeg, Spline_eval_limbdark); } /*========================================================================*/ double sum_kiter(int k_min, int k_max, int jj, Iklr_intensity* ptr_Iklr, Ikl_intensity* ptr_Ikl, Ikr_intensity* ptr_Ikr, int method) { int kk; double Pdeg; double sum_Il; double sum_Ir; double sum_Il_downstream; double sum_Ir_downstream; sum_Il = 0; sum_Ir = 0; sum_Il_downstream = 0; sum_Ir_downstream = 0; for (kk = k_min; kk < k_max; kk++) { if (method == 1) { sum_Il = sum_Il + ptr_Iklr[kk].Il_matrix_upstream[Nstep_tau - 1][jj]; sum_Ir = sum_Ir + ptr_Iklr[kk].Ir_matrix_upstream[Nstep_tau - 1][jj]; sum_Il_downstream = sum_Il_downstream + ptr_Iklr[kk].Il_matrix_downstream[Nstep_tau - 1][jj]; sum_Ir_downstream = sum_Ir_downstream + ptr_Iklr[kk].Ir_matrix_downstream[Nstep_tau - 1][jj]; } else { sum_Il = sum_Il + ptr_Ikl[kk].matrix[0][jj]; sum_Ir = sum_Ir + ptr_Ikr[kk].matrix[0][jj]; } } Pdeg = (sum_Ir - sum_Il) / (sum_Ir + sum_Il); return Pdeg; } Loading
Makefile 0 → 100644 +54 −0 Original line number Diff line number Diff line LDFLAGS = -L ${LIB_CFITSIO} -L ${LIB_GSL} -L ${LIB_MPI} -lcfitsio -lm -lgsl -lgslcblas -lmpi INCLUDE = -I ${PWD} -I ${HEADERS_CFITSIO} -I ${HEADERS_GSL} -I ${HEADERS_MPI} -I ${MC_INSTDIR}/../../include/ CFLAGS = -g -Ofast -Wall ${INCLUDE} LOCAL_DIR = ${PWD} MC_SLAB = ${MC_INSTDIR}/../../gr_code/slab_rte MC_POLARIZATION = ${MC_INSTDIR}/polarization MC_ELE_DISTRIBUTION = ${MC_INSTDIR}/electron_distributions MC_GENERAL = ${MC_INSTDIR}/general_routines/ MC_COORD = ${MC_INSTDIR}/coordinates_systems MC_SEED = ${MC_INSTDIR}/seed_photons/ MC_HYDRO = ${MC_INSTDIR}/../../gr_code/hydrodynamics #======================================================================== LOCAL_DIR_OBJ= ${LOCAL_DIR}/main_program.o ${LOCAL_DIR}/check_results.o ${LOCAL_DIR}/compute_results.o ${LOCAL_DIR}/function_integrals.o ${LOCAL_DIR}/legendre_integration.o ${LOCAL_DIR}/set_deltatau.o ${LOCAL_DIR}/slab_polarization.o ${LOCAL_DIR}/solve_rte.o ${LOCAL_DIR}/mc_slab.o ${LOCAL_DIR}/compute_stokes.o ${LOCAL_DIR}/collect_photons.o MC_POLARIZATION_OBJ=${MC_POLARIZATION}/ortonormal_axes.o ${MC_POLARIZATION}/unpolarized_seedphot.o ${MC_POLARIZATION}/polarization_probability.o ${MC_POLARIZATION}/depolarization_probability.o ${MC_POLARIZATION}/electfield_as_new.o ${MC_POLARIZATION}/sample_azim_angle.o ${MC_POLARIZATION}/allocate_stokes_pointer.o ${MC_POLARIZATION}/disk_polarizationelectricfield.o ${MC_POLARIZATION}/pdeg_atmosphere.o ${MC_POLARIZATION}/write_polardata.o ${MC_POLARIZATION}/select_quadrant.o $ ${MC_POLARIZATION}/detector_axis.o MC_ELE_DISTRIBUTION_OBJ=${MC_ELE_DISTRIBUTION}/hybrid/eledist_hybrid.o ${MC_ELE_DISTRIBUTION}/hybrid/integrate_maxwgamma.o ${MC_ELE_DISTRIBUTION}/sample_electron.o ${MC_ELE_DISTRIBUTION}/powerlaw/eledist_nth.o ${MC_ELE_DISTRIBUTION}/maxwellian/subrel_maxwellian.o MC_COORD_OBJ=${MC_COORD}/versor_boost.o ${MC_COORD}/elmag_lorentztransform.o MC_GENERAL_OBJ=${MC_INSTDIR}/../../gr_code/clock_random.o ${MC_INSTDIR}/../../gr_code/dmatrix.o ${MC_INSTDIR}/../../gr_code/round_to_digits.o ${MC_INSTDIR}/general_routines/gauleg.o ${MC_INSTDIR}/general_routines/numpar.o ${MC_INSTDIR}/general_routines/stringpar.o ${MC_INSTDIR}/general_routines/strrev.o ${MC_INSTDIR}/general_routines/stringconcat.o ${MC_INSTDIR}/general_routines/interpolate_kn.o ${MC_INSTDIR}/../../gr_code/dot_prod.o ${MC_GENERAL}/read_array.o ${MC_INSTDIR}/../../gr_code/vect_prod.o ${MC_GENERAL}/read_matrix.o ${MC_GENERAL}/energy_lorentz_boost.o ${MC_GENERAL}/new_energy_erf.o ${MC_GENERAL}/make_array_angles.o ${MC_INSTDIR}/../../gr_code/init_mpi.o ${MC_INSTDIR}/../../gr_code/abs_val.o ${MC_GENERAL}/make_array_energy.o MC_SEED_OBJ=${MC_SEED}/bb_spec.o MC_HYDRO_OBJ=${MC_HYDRO}/reverse_array.o MC_SLAB_OBJ=${MC_SLAB}/electricfield_fromfile.o ${MC_SLAB}/read_resultsfile.o ${MC_SLAB}/setup_gsl_objects.o ${MC_SLAB}/compute_cumulative_angdist.o all: start_iteration %.o: %.c $(DEPS) $(CC) -c -o $@ $< $(CFLAGS) start_iteration: ${LOCAL_DIR_OBJ} ${MC_GENERAL_OBJ} ${MC_POLARIZATION_OBJ} ${MC_ELE_DISTRIBUTION_OBJ} ${MC_COORD_OBJ} ${MC_SEED_OBJ} ${MC_HYDRO_OBJ} ${MC_SLAB_OBJ} ${CC} $^ -o $@ ${LDFLAGS} clean: rm -f main_program.o ${LOCAL_DIR_OBJ} ${MC_GENERAL_OBJ} ${MC_POLARIZATION_OBJ} ${MC_ELE_DISTRIBUTION_OBJ} ${MC_COORD_OBJ} ${MC_SEED_OBJ} ${MC_HYDRO_OBJ} ${MC_SLAB_OBJ} ciao: echo ${MC_SLAB_OBJ}
README.txt 0 → 100644 +3 −0 Original line number Diff line number Diff line The code computes the polarization degree of radiation from a plane-parallel slab in the diffusion approximation for a pure scattering atmosphere.
check_results.c 0 → 100644 +50 −0 Original line number Diff line number Diff line #include "iteration_functions.h" void check_results(gsl_spline* Spline_sample_Iu, gsl_spline* Spline_eval_pdeg, gsl_spline* Spline_eval_limbdark) { double u_test = 0, P = 0, Itot = 0; /*double Ir, Il;*/ double csi; int ii, status; for (ii = 0; ii < 2500; ii++) { csi = clock_random(); status = gsl_spline_eval_e(Spline_sample_Iu, csi, xacc_1d, &u_test); if (status) { printf("File %s\n", __FILE__); printf("csi=%lf \n", csi); printf("Error at line %d: %s\n", __LINE__, gsl_strerror(status)); exit(1); } status = gsl_spline_eval_e(Spline_eval_pdeg, u_test, xacc_1d, &P); if (status) { printf("File %s\n", __FILE__); printf("csi=%lf u_test=%lf\n", csi, u_test); printf("Error at line %d: %s\n", __LINE__, gsl_strerror(status)); exit(1); } status = gsl_spline_eval_e(Spline_eval_limbdark, u_test, xacc_1d, &Itot); if (status) { printf("File %s\n", __FILE__); printf("Error at line %d: %s\n", __LINE__, gsl_strerror(status)); exit(1); } if (P > 1) { printf("%lf %lf %5.4e\n", u_test, P, Itot); } /* Ir = 1 / 2. * Itot * (1 + P); Il = 1 / 2. * Itot * (1 - P); */ } } No newline at end of file
collect_photons.c 0 → 100644 +153 −0 Original line number Diff line number Diff line #include "iteration_functions.h" #define size 100 int good_j, good_k, n; /*==================================================================================*/ void collect_photons(double ene, double* k, double* array_ene, double** array_counts, int flag) { double center_ene; double delta_ene; double total_counts; double counts; int i, j; double kz; if (k[2] < 0) { kz = -k[2]; } else { kz = k[2]; } // =====================================================================# // Define the array of the total counts // =====================================================================# static int array_total_counts[NSTEP_ENE]; // =====================================================================# // Loop on energies // =====================================================================# for (i = 0; i < nstepangles; i++) { if (array_ubounds[i] < -1 || array_ubounds[i] > 1) { printf("Error bounds %d %lf \n", i, array_ubounds[i]); } } for (i = 0; i < NSTEP_ENE; i++) { if ((ene >= array_ene[i]) && (ene < array_ene[i + 1])) { // =====================================================================# // If the parameter nstepangles is not set, then the total // spectrum is collected and exit from the loop over energy // Otherwise make additional loop over the polar angle defined // by array_u // =====================================================================# if (nstepangles < 2) { break; } else { for (j = 0; j < nstepangles; j++) { if (kz <= array_ubounds[j] && kz > array_ubounds[j + 1]) { good_j = j; array_counts[i][good_j]++; break; } } } // Else condition for photon energy within the boundaries defined by array_ene } else { continue; } // End of loop over energy } if (flag == 1) { dat_spectrum = fopen(outspec, "w"); if (dat_spectrum == NULL) { printf("Error opening file %s\n", outspec); exit(1); } // =========================================================================== /*Compute the total spectrum summed over all angles*/ // =========================================================================== for (i = 0; i < NSTEP_ENE; i++) { for (j = 0; j < nstepangles; j++) { array_total_counts[i] = array_total_counts[i] + array_counts[i][j]; } } // ==================================================================================== // Print spectra values, both total and, if set, also angle-dependent // ==================================================================================== for (i = 0; i < NSTEP_ENE - 1; i++) { center_ene = 0.5 * (array_ene[i + 1] + array_ene[i]); delta_ene = 0.5 * (array_ene[i + 1] - array_ene[i]); // ==================================================================================== // Total counts per keV // ==================================================================================== total_counts = array_total_counts[i] / (array_ene[i + 1] - array_ene[i]); fprintf(dat_spectrum, "%5.3e %5.3e %5.3e ", center_ene, delta_ene, total_counts * center_ene); for (j = 0; j < nstepangles; j++) { nph = 0; // ====================================================================================## // Print the columns with angle-dependent spectra spectrum in the file // ====================================================================================## counts = array_counts[i][j] / (array_ene[i + 1] - array_ene[i]); nph = nph + array_counts[i][j]; if (j < nstepangles - 1) { fprintf(dat_spectrum, " %5.4e ", counts * center_ene); } else { fprintf(dat_spectrum, " %5.4e\n", counts * center_ene); } } } fclose(dat_spectrum); } // End of flag condition for actually producing the qdp file // End of program }
compute_results.c 0 → 100644 +201 −0 Original line number Diff line number Diff line #include "iteration_functions.h" double sum_kiter(int k_min, int k_max, int jj, Iklr_intensity* ptr_Iklr, Ikl_intensity* ptr_Ikl, Ikr_intensity* ptr_Ikr, int method); void compute_results(int method, int k_iter, int Nstep_tau, int Nstep_mu, double* array_mu, double* weights_u, Iklr_intensity* ptr_Iklr, Ikl_intensity* ptr_Ikl, Ikr_intensity* ptr_Ikr) { int jj, kk; double* Pdeg = malloc(Nstep_mu * sizeof(double)); double* Pdeg_Band1 = malloc(Nstep_mu * sizeof(double)); double* Pdeg_Band2 = malloc(Nstep_mu * sizeof(double)); double* Pdeg_Band3 = malloc(Nstep_mu * sizeof(double)); double* Pdeg_Band4 = malloc(Nstep_mu * sizeof(double)); double* Pdeg_Band5 = malloc(Nstep_mu * sizeof(double)); double* Itot_upstream = malloc(Nstep_mu * sizeof(double)); double* Itot_downstream = malloc(Nstep_mu * sizeof(double)); double sum_Il, sum_Ir; double sum_Il_downstream, sum_Ir_downstream; FILE* dat; dat = fopen(polarization_file, "w"); for (jj = 0; jj < Nstep_mu; jj++) { sum_Il = 0; sum_Ir = 0; sum_Il_downstream = 0; sum_Ir_downstream = 0; for (kk = 0; kk < k_iter; kk++) { if (method == 1) { sum_Il = sum_Il + ptr_Iklr[kk].Il_matrix_upstream[Nstep_tau - 1][jj]; sum_Ir = sum_Ir + ptr_Iklr[kk].Ir_matrix_upstream[Nstep_tau - 1][jj]; sum_Il_downstream = sum_Il_downstream + ptr_Iklr[kk].Il_matrix_downstream[Nstep_tau - 1][jj]; sum_Ir_downstream = sum_Ir_downstream + ptr_Iklr[kk].Ir_matrix_downstream[Nstep_tau - 1][jj]; } else { sum_Il = sum_Il + ptr_Ikl[kk].matrix[0][jj]; sum_Ir = sum_Ir + ptr_Ikr[kk].matrix[0][jj]; } } if (disktau >= 4 && k_iter > 40) { Pdeg_Band1[jj] = sum_kiter(0, 10, jj, ptr_Iklr, ptr_Ikl, ptr_Ikr, method); Pdeg_Band2[jj] = sum_kiter(10, 20, jj, ptr_Iklr, ptr_Ikl, ptr_Ikr, method); Pdeg_Band3[jj] = sum_kiter(20, 30, jj, ptr_Iklr, ptr_Ikl, ptr_Ikr, method); Pdeg_Band4[jj] = sum_kiter(30, 40, jj, ptr_Iklr, ptr_Ikl, ptr_Ikr, method); Pdeg_Band5[jj] = sum_kiter(40, k_iter, jj, ptr_Iklr, ptr_Ikl, ptr_Ikr, method); } Pdeg[jj] = (sum_Ir - sum_Il) / (sum_Ir + sum_Il); if (isnan(Pdeg[jj])) { printf("Error: Pdeg is NaN at u=%lf sum_Ir=%4.3e sum_Il=%4.3e\n", array_mu[jj], sum_Ir, sum_Il); } Itot_upstream[jj] = (sum_Ir + sum_Il); Itot_downstream[jj] = sum_Ir_downstream + sum_Il_downstream; } /*===========================================================================*/ /*Print I(u) normalized at the value u=1*/ /*===========================================================================*/ if (disktau < 4) { for (jj = 0; jj < Nstep_mu; jj++) { fprintf(dat, "%lf %5.4e %5.4e\n", array_mu[jj], Pdeg[jj], Itot_upstream[jj] / Itot_upstream[Nstep_mu - 1]); } } else { for (jj = 0; jj < Nstep_mu; jj++) { fprintf(dat, "%lf %5.4e %5.4e %5.4e %5.4e %5.4e %5.4e %5.4e \n", array_mu[jj], Pdeg[jj], Itot_upstream[jj] / Itot_upstream[Nstep_mu - 1], Pdeg_Band1[jj], Pdeg_Band2[jj], Pdeg_Band3[jj], Pdeg_Band4[jj], Pdeg_Band5[jj]); } } fclose(dat); /*===========================================================================*/ double TotalFlux = 0; double TotalFlux_downstream = 0; for (jj = 0; jj < Nstep_mu; jj++) { TotalFlux = TotalFlux + Itot_upstream[jj] * array_mu[jj] * weights_u[jj]; TotalFlux_downstream = TotalFlux_downstream + Itot_downstream[jj] * array_mu[jj] * weights_u[jj]; } printf("Total flux at the top (u>0) %lf\n", TotalFlux); printf("Total flux at the bottom (u<0) %lf\n", TotalFlux_downstream); printf("Percenatge of flux at the top %5.4f\n", TotalFlux / (TotalFlux + TotalFlux_downstream)); /*===========================================================================*/ dat = fopen(diffusion_file, "w"); fprintf(dat, "!Total flux at the top (u>0) %lf\n", TotalFlux); fprintf(dat, "!Total flux at the bottom (u<0) %lf\n", TotalFlux_downstream); fprintf(dat, "!Percenatge of flux at the top %5.4f\n", TotalFlux / (TotalFlux + TotalFlux_downstream)); double* diffusion = malloc(k_iter * sizeof(double)); double sum_k; for (kk = 0; kk < k_iter; kk++) { sum_k = 0; for (jj = 0; jj < Nstep_mu; jj++) { if (method == 1) { sum_k = sum_k + ptr_Iklr[kk].Il_matrix_upstream[Nstep_tau - 1][jj] * weights_u[jj] * array_mu[jj] + ptr_Iklr[kk].Ir_matrix_upstream[Nstep_tau - 1][jj] * weights_u[jj] * array_mu[jj]; } else { sum_k = sum_k + ptr_Ikl[kk].matrix[0][jj] + ptr_Ikr[kk].matrix[0][jj]; } } diffusion[kk] = sum_k; fprintf(dat, "%d %5.4e\n", kk, diffusion[kk]); } fclose(dat); /*===================================================================================*/ radiation_field_t* radiation_field = (radiation_field_t*)malloc(sizeof(radiation_field_t)); radiation_field->u_min = array_mu[0]; radiation_field->u_max = array_mu[Nstep_mu - 1]; read_resultsfile(polarization_file, radiation_field, RTE); setup_gsl_objects(radiation_field, RTE); check_results(Spline_sample_Iu, Spline_eval_pdeg, Spline_eval_limbdark); } /*========================================================================*/ double sum_kiter(int k_min, int k_max, int jj, Iklr_intensity* ptr_Iklr, Ikl_intensity* ptr_Ikl, Ikr_intensity* ptr_Ikr, int method) { int kk; double Pdeg; double sum_Il; double sum_Ir; double sum_Il_downstream; double sum_Ir_downstream; sum_Il = 0; sum_Ir = 0; sum_Il_downstream = 0; sum_Ir_downstream = 0; for (kk = k_min; kk < k_max; kk++) { if (method == 1) { sum_Il = sum_Il + ptr_Iklr[kk].Il_matrix_upstream[Nstep_tau - 1][jj]; sum_Ir = sum_Ir + ptr_Iklr[kk].Ir_matrix_upstream[Nstep_tau - 1][jj]; sum_Il_downstream = sum_Il_downstream + ptr_Iklr[kk].Il_matrix_downstream[Nstep_tau - 1][jj]; sum_Ir_downstream = sum_Ir_downstream + ptr_Iklr[kk].Ir_matrix_downstream[Nstep_tau - 1][jj]; } else { sum_Il = sum_Il + ptr_Ikl[kk].matrix[0][jj]; sum_Ir = sum_Ir + ptr_Ikr[kk].matrix[0][jj]; } } Pdeg = (sum_Ir - sum_Il) / (sum_Ir + sum_Il); return Pdeg; }