Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
S
slab
Manage
Activity
Members
Plan
Wiki
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Package registry
Model registry
Operate
Terraform modules
Analyze
Contributor analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
polarization
slab
Commits
243fca98
Commit
243fca98
authored
2 weeks ago
by
Ruben Farinelli
Browse files
Options
Downloads
Patches
Plain Diff
Corrected bug in the MC routine for high values of the optical depth
parent
7907ceea
No related branches found
No related tags found
No related merge requests found
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
Makefile
+2
-2
2 additions, 2 deletions
Makefile
main_program.c
+48
-16
48 additions, 16 deletions
main_program.c
mc_slab.c
+56
-51
56 additions, 51 deletions
mc_slab.c
with
106 additions
and
69 deletions
Makefile
+
2
−
2
View file @
243fca98
LDFLAGS
=
-L
${
LIB_CFITSIO
}
-L
${
LIB_GSL
}
-L
${
LIB_MPI
}
-lcfitsio
-lm
-lgsl
-lgslcblas
-lmpi
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/
INCLUDE
=
-I
${
PWD
}
-I
${
HEADERS_CFITSIO
}
-I
${
HEADERS_GSL
}
-I
${
HEADERS_MPI
}
-I
${
MC_INSTDIR
}
/../../include/
CFLAGS
=
-g
-O
fast
-Wall
${
INCLUDE
}
CFLAGS
=
-g
-O
3
-Wall
${
INCLUDE
}
LOCAL_DIR
=
${
PWD
}
LOCAL_DIR
=
${
PWD
}
...
@@ -20,7 +20,7 @@ MC_SYNC = ${MC_INSTDIR}/../../gr_code/synchrotron
...
@@ -20,7 +20,7 @@ MC_SYNC = ${MC_INSTDIR}/../../gr_code/synchrotron
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
${
LOCAL_DIR
}
/simul_sync.o
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
${
LOCAL_DIR
}
/simul_sync.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_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_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
...
...
This diff is collapsed.
Click to expand it.
main_program.c
+
48
−
16
View file @
243fca98
#include
"iteration_functions.h"
#include
"globals.h"
#include
"globals.h"
#include
"iteration_functions.h"
#include
<mpi.h>
#include
<mpi.h>
#include
<stdio.h>
#include
<stdio.h>
...
@@ -9,11 +9,9 @@ int seed;
...
@@ -9,11 +9,9 @@ int seed;
double
tau_c
;
double
tau_c
;
double
albedobase
;
double
albedobase
;
char
*
polarization_file
;
char
*
polarization_file
;
char
*
diffusion_file
;
char
*
diffusion_file
;
// int nph;
// int nph;
// int rank;
// int rank;
...
@@ -152,6 +150,16 @@ int main(int argc, char* argv[])
...
@@ -152,6 +150,16 @@ int main(int argc, char* argv[])
ktbb
=
numpar
(
argv
[
t
]);
ktbb
=
numpar
(
argv
[
t
]);
}
}
if
(
strstr
(
argv
[
t
],
"emin="
)
!=
NULL
)
{
emin
=
numpar
(
argv
[
t
]);
}
if
(
strstr
(
argv
[
t
],
"emax="
)
!=
NULL
)
{
emax
=
numpar
(
argv
[
t
]);
}
if
(
strstr
(
argv
[
t
],
"albedobase="
)
!=
NULL
)
if
(
strstr
(
argv
[
t
],
"albedobase="
)
!=
NULL
)
{
{
albedobase
=
numpar
(
argv
[
t
]);
albedobase
=
numpar
(
argv
[
t
]);
...
@@ -180,6 +188,16 @@ int main(int argc, char* argv[])
...
@@ -180,6 +188,16 @@ int main(int argc, char* argv[])
ktbb
=
1
;
ktbb
=
1
;
}
}
if
(
!
emin
)
{
emin
=
0
.
1
;
}
if
(
!
emax
)
{
emax
=
50
.;
}
/*=========================================================*/
/*=========================================================*/
if
(
!
disktau
||
disktau
==
0
)
if
(
!
disktau
||
disktau
==
0
)
...
@@ -274,23 +292,37 @@ int main(int argc, char* argv[])
...
@@ -274,23 +292,37 @@ int main(int argc, char* argv[])
exit
(
1
);
exit
(
1
);
}
}
if
(
diffusion
==
0x0
)
{
diffusion
=
set_filename
(
"diffusion_mc_tau"
,
tau_char
,
seed_char
,
albedo_char
,
"mc"
);
diffusion
=
set_filename
(
"diffusion_mc_tau"
,
tau_char
,
seed_char
,
albedo_char
,
"mc"
);
}
if
(
outspec
==
0x0
)
{
outspec
=
set_filename
(
"spectrum_mc_tau"
,
tau_char
,
seed_char
,
albedo_char
,
"mc"
);
outspec
=
set_filename
(
"spectrum_mc_tau"
,
tau_char
,
seed_char
,
albedo_char
,
"mc"
);
}
if
(
integral
==
0x0
)
{
integral
=
set_filename
(
"integralpolar_mc_tau"
,
tau_char
,
seed_char
,
albedo_char
,
"mc"
);
integral
=
set_filename
(
"integralpolar_mc_tau"
,
tau_char
,
seed_char
,
albedo_char
,
"mc"
);
}
if
(
polarfile
==
0x0
)
{
polarfile
=
set_filename
(
"energypolar_mc_tau"
,
tau_char
,
seed_char
,
albedo_char
,
"mc"
);
polarfile
=
set_filename
(
"energypolar_mc_tau"
,
tau_char
,
seed_char
,
albedo_char
,
"mc"
);
}
status
=
slab_mc
(
nph
,
seed
);
status
=
slab_mc
(
nph
,
seed
);
}
}
else
else
{
{
printf
(
printf
(
"
\n
Please select method=ode (solve ODE) or method=mc (Montecarlo)
\n
"
);
"
\n
Please select method=ode (solve ODE) or method=mc (Montecarlo)
\n
"
);
return
(
1
);
return
(
1
);
}
}
if
(
strcmp
(
method
,
"mc"
)
==
0
)
MPI_Finalize
();
if
(
strcmp
(
method
,
"mc"
)
==
0
)
MPI_Finalize
();
return
(
0
);
return
(
0
);
}
}
...
...
This diff is collapsed.
Click to expand it.
mc_slab.c
+
56
−
51
View file @
243fca98
...
@@ -17,7 +17,6 @@ void comptonization(double E_lab,
...
@@ -17,7 +17,6 @@ void comptonization(double E_lab,
double
*
Efield_lab_new
,
double
*
Efield_lab_new
,
double
*
Magfield_lab_new
);
double
*
Magfield_lab_new
);
double
distance_bottom
(
double
z0
,
double
kz
);
double
distance_bottom
(
double
z0
,
double
kz
);
double
distance_top
(
double
z0
,
double
kz
,
double
H
);
double
distance_top
(
double
z0
,
double
kz
,
double
H
);
...
@@ -28,14 +27,12 @@ double distance_top(double z0, double kz, double H);
...
@@ -28,14 +27,12 @@ double distance_top(double z0, double kz, double H);
// double obsmindeg;
// double obsmindeg;
// double obsmaxdeg;
// double obsmaxdeg;
// double* array_angles;
// double* array_angles;
// double* array_ubounds;
// double* array_ubounds;
// double** array_gb;
// double** array_gb;
// double** ptr_2colfile;
// double** ptr_2colfile;
const
gsl_root_fsolver_type
*
T_phi
;
const
gsl_root_fsolver_type
*
T_phi
;
gsl_root_fsolver
*
s_phi
;
gsl_root_fsolver
*
s_phi
;
...
@@ -59,7 +56,6 @@ int slab_mc(int nphot, int seed)
...
@@ -59,7 +56,6 @@ int slab_mc(int nphot, int seed)
int
photon_diffusion
[
NSC_MAX
];
int
photon_diffusion
[
NSC_MAX
];
int
status
;
int
status
;
double
E_lab
;
double
E_lab
;
double
E_new_lab
;
double
E_new_lab
;
double
k_lab
[
3
];
double
k_lab
[
3
];
...
@@ -105,7 +101,7 @@ int slab_mc(int nphot, int seed)
...
@@ -105,7 +101,7 @@ int slab_mc(int nphot, int seed)
array_gb
=
read_matrix
(
matrix_gb
);
array_gb
=
read_matrix
(
matrix_gb
);
double
array_ene
[
NSTEP_ENE
];
double
array_ene
[
NSTEP_ENE
];
make_array_energy
(
array_ene
,
0
.
01
,
20
,
NSTEP_ENE
);
make_array_energy
(
array_ene
,
emin
,
emax
,
NSTEP_ENE
);
double
**
array_counts
;
double
**
array_counts
;
array_counts
=
dmatrix
(
0
,
NSTEP_ENE
-
1
,
0
,
nstepangles
-
1
);
array_counts
=
dmatrix
(
0
,
NSTEP_ENE
-
1
,
0
,
nstepangles
-
1
);
...
@@ -139,7 +135,6 @@ int slab_mc(int nphot, int seed)
...
@@ -139,7 +135,6 @@ int slab_mc(int nphot, int seed)
setup_gsl_objects
(
radiation_field
,
MC_SLAB
);
setup_gsl_objects
(
radiation_field
,
MC_SLAB
);
}
}
Pdeg
=
0
;
Pdeg
=
0
;
nph_esc
=
0
;
nph_esc
=
0
;
cos_theta
=
0
;
cos_theta
=
0
;
...
@@ -190,7 +185,10 @@ int slab_mc(int nphot, int seed)
...
@@ -190,7 +185,10 @@ int slab_mc(int nphot, int seed)
cos_theta
=
2
*
clock_random
()
-
1
;
cos_theta
=
2
*
clock_random
()
-
1
;
}
}
else
if
(
seed
==
2
)
else
if
(
seed
==
2
)
{
if
(
!
emin
)
{
{
emin
=
0
.
1
;
}
pos
[
2
]
=
clock_random
()
*
Hphot
;
pos
[
2
]
=
clock_random
()
*
Hphot
;
cos_theta
=
2
*
clock_random
()
-
1
;
cos_theta
=
2
*
clock_random
()
-
1
;
}
}
...
@@ -224,7 +222,6 @@ int slab_mc(int nphot, int seed)
...
@@ -224,7 +222,6 @@ int slab_mc(int nphot, int seed)
k_lab
[
1
]
=
sin_theta
*
sin
(
phi
);
k_lab
[
1
]
=
sin_theta
*
sin
(
phi
);
k_lab
[
2
]
=
cos_theta
;
k_lab
[
2
]
=
cos_theta
;
if
(
DiskPolarizationFlag
==
FROMFILE
)
if
(
DiskPolarizationFlag
==
FROMFILE
)
{
{
electricfield_fromfile
(
k_lab
,
Efield_lab
,
Magfield_lab
,
&
Pdeg
);
electricfield_fromfile
(
k_lab
,
Efield_lab
,
Magfield_lab
,
&
Pdeg
);
...
@@ -280,7 +277,6 @@ int slab_mc(int nphot, int seed)
...
@@ -280,7 +277,6 @@ int slab_mc(int nphot, int seed)
Efield_lab
[
jj
]
=
Efield_lab_new
[
jj
];
Efield_lab
[
jj
]
=
Efield_lab_new
[
jj
];
Magfield_lab
[
jj
]
=
Magfield_lab_new
[
jj
];
Magfield_lab
[
jj
]
=
Magfield_lab_new
[
jj
];
}
}
}
}
else
else
...
@@ -290,10 +286,16 @@ int slab_mc(int nphot, int seed)
...
@@ -290,10 +286,16 @@ int slab_mc(int nphot, int seed)
{
{
// printf("Photon %d escaping after %d scattering\n", ii, n_sc);
// printf("Photon %d escaping after %d scattering\n", ii, n_sc);
if
(
n_sc
==
0
)
n_zero_sc
++
;
if
(
n_sc
==
0
)
n_zero_sc
++
;
compute_stokes
(
E_lab
,
k_lab
,
Efield_lab
,
struct_stokes
,
array_ubounds
,
0
);
compute_stokes
(
E_lab
,
k_lab
,
Efield_lab
,
struct_stokes
,
array_ubounds
,
0
);
if
(
n_sc
<
NSC_MAX
)
{
photon_diffusion
[
n_sc
]
++
;
photon_diffusion
[
n_sc
]
++
;
}
collect_photons
(
E_new_lab
,
k_lab
,
array_ene
,
array_counts
,
0
);
collect_photons
(
E_new_lab
,
k_lab
,
array_ene
,
array_counts
,
0
);
nph_esc
++
;
nph_esc
++
;
...
@@ -366,9 +368,10 @@ int slab_mc(int nphot, int seed)
...
@@ -366,9 +368,10 @@ int slab_mc(int nphot, int seed)
MPI_Comm_size
(
MPI_COMM_WORLD
,
&
nproc
);
MPI_Comm_size
(
MPI_COMM_WORLD
,
&
nproc
);
/*==================================================================*/
/*==================================================================*/
// printf("Rank %d si trova qui %d\n", rank, __LINE__);
if
(
rank
==
0
)
if
(
rank
==
0
)
{
{
compute_stokes
(
1
,
k_lab
,
Efield_lab
,
struct_stokes_average
,
array_ubounds
,
1
);
compute_stokes
(
1
,
k_lab
,
Efield_lab
,
struct_stokes_average
,
array_ubounds
,
1
);
...
@@ -396,24 +399,31 @@ int slab_mc(int nphot, int seed)
...
@@ -396,24 +399,31 @@ int slab_mc(int nphot, int seed)
}
}
fclose
(
dat_diffusion
);
fclose
(
dat_diffusion
);
}
collect_photons
(
0
,
k_lab
,
array_ene
,
reduce_array_counts
,
1
);
dat_energy_polar
=
fopen
(
polarfile
,
"w"
);
dat_energy_polar
=
fopen
(
polarfile
,
"w"
);
if
(
dat_energy_polar
==
NULL
)
{
fprintf
(
stderr
,
"Errore: fopen fallita su %s
\n
"
,
polarfile
);
MPI_Abort
(
MPI_COMM_WORLD
,
1
);
}
write_polardata
(
struct_stokes_average
,
ene_bound
,
dat_energy_polar
);
write_polardata
(
struct_stokes_average
,
ene_bound
,
dat_energy_polar
);
fclose
(
dat_energy_polar
);
fclose
(
dat_energy_polar
);
collect_photons
(
0
,
k_lab
,
array_ene
,
reduce_array_counts
,
1
);
}
if
(
s_phi
!=
NULL
)
gsl_root_fsolver_free
(
s_phi
);
gsl_root_fsolver_free
(
s_phi
);
if
(
s_disk
!=
NULL
)
gsl_root_fsolver_free
(
s_disk
);
gsl_root_fsolver_free
(
s_disk
);
return
0
;
return
0
;
}
// End of function
}
// End of function
void
comptonization
(
double
E_lab
,
void
comptonization
(
double
E_lab
,
double
*
k_lab
,
double
*
k_lab
,
double
*
Efield_lab
,
double
*
Efield_lab
,
...
@@ -424,7 +434,6 @@ void comptonization(double E_lab,
...
@@ -424,7 +434,6 @@ void comptonization(double E_lab,
double
*
Magfield_lab_new
)
double
*
Magfield_lab_new
)
{
{
int
jj
;
int
jj
;
int
status
;
int
status
;
int
PolarFlag
;
int
PolarFlag
;
...
@@ -444,7 +453,6 @@ void comptonization(double E_lab,
...
@@ -444,7 +453,6 @@ void comptonization(double E_lab,
double
ElectField_old_erf
[
3
];
double
ElectField_old_erf
[
3
];
double
MagField_Erf
[
3
];
double
MagField_Erf
[
3
];
PolarFlag
=
0
;
PolarFlag
=
0
;
Pdeg
=
0
;
Pdeg
=
0
;
...
@@ -462,7 +470,6 @@ void comptonization(double E_lab,
...
@@ -462,7 +470,6 @@ void comptonization(double E_lab,
E_erf
=
energy_lorentz_boost
(
E_lab
,
el_vel_vect
,
k_lab
,
1
);
E_erf
=
energy_lorentz_boost
(
E_lab
,
el_vel_vect
,
k_lab
,
1
);
csi
=
clock_random
();
csi
=
clock_random
();
costheta_erf
=
(
-
1
+
pow
(
-
2
+
4
*
csi
+
sqrt
(
5
-
16
*
csi
+
16
*
pow
(
csi
,
2
)),
2
/
3
.))
/
costheta_erf
=
(
-
1
+
pow
(
-
2
+
4
*
csi
+
sqrt
(
5
-
16
*
csi
+
16
*
pow
(
csi
,
2
)),
2
/
3
.))
/
...
@@ -476,7 +483,6 @@ void comptonization(double E_lab,
...
@@ -476,7 +483,6 @@ void comptonization(double E_lab,
E_new_erf
=
new_energy_erf
(
E_erf
,
costheta_erf
);
E_new_erf
=
new_energy_erf
(
E_erf
,
costheta_erf
);
phik
=
sample_azim_angle
(
E_erf
,
E_new_erf
,
costheta_erf
,
1
);
phik
=
sample_azim_angle
(
E_erf
,
E_new_erf
,
costheta_erf
,
1
);
//================================================================== */
//================================================================== */
...
@@ -499,7 +505,6 @@ void comptonization(double E_lab,
...
@@ -499,7 +505,6 @@ void comptonization(double E_lab,
PolarFlag
=
1
;
PolarFlag
=
1
;
status
=
depolarization_probability
(
E_erf
,
E_new_erf
,
costheta_erf
,
phik
,
&
Pdeg
,
&
PolarFlag
);
status
=
depolarization_probability
(
E_erf
,
E_new_erf
,
costheta_erf
,
phik
,
&
Pdeg
,
&
PolarFlag
);
if
(
status
==
1
)
if
(
status
==
1
)
{
{
exit
(
1
);
exit
(
1
);
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment