-
Notifications
You must be signed in to change notification settings - Fork 1
/
grmonty.c
155 lines (119 loc) · 3.56 KB
/
grmonty.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
/*
grmonty Nph
Using monte carlo method, estimate spectrum of an appropriately
scaled axisymmetric GRMHD simulation as a function of
latitudinal viewing angle.
Input simulation data is assumed to be in dump format provided by
HARM code. Location of input file is, at present, hard coded
(see init_sim_data.c).
Nph super-photons are generated in total and then allowed
to propagate. They are weighted according to the emissivity.
The photons are pushed by the geodesic equation.
Their weight decays according to the local absorption coefficient.
The photons also scatter with probability related to the local
scattering opacity.
The electrons are assumed to have a thermal distribution
function, and to be at the same temperature as the protons.
CFG 8-17-06
Implemented synchrotron sampling, 22 Jan 07
fixed bugs in tetrad/compton scattering routines, 31 Jan 07
Implemented normalization for output, 6 Feb 07
Separated out different synchrotron sampling routines
into separate files, 8 Mar 07
fixed bug in energy recording; bug used Kcon[0] rather than
Kcov[0] as energy, 18 Mar 07
major reorganization to encapsulate problem-dependent parts 5-6 Nov 07
*/
#include "decs.h"
/* defining declarations for global variables */
struct of_geom **geom;
int N1, N2, N3, n_within_horizon;
double F[N_ESAMP + 1], wgt[N_ESAMP + 1];
int Ns, N_superph_recorded, N_scatt;
/* some coordinate parameters */
double a;
double R0, Rin, Rh, Rout, Rms;
double hslope;
double startx[NDIM], stopx[NDIM], dx[NDIM];
double dlE, lE0;
double gam;
double dMsim;
double M_unit, L_unit, T_unit;
double RHO_unit, U_unit, B_unit, Ne_unit, Thetae_unit;
double max_tau_scatt, Ladv, dMact, bias_norm;
gsl_rng *r;
gsl_integration_workspace *w;
#pragma omp threadprivate(r)
#include <time.h>
int main(int argc, char *argv[])
{
double Ntot, N_superph_made;
int quit_flag, myid;
struct of_photon ph;
time_t currtime, starttime;
if (argc < 4) {
fprintf(stderr, "usage: grmonty Ns infilename M_unit\n");
exit(0);
}
sscanf(argv[1], "%lf", &Ntot);
Ns = (int) Ntot;
/* initialize random number generator */
#pragma omp parallel private(myid)
{
myid = omp_get_thread_num();
init_monty_rand(139 * myid + time(NULL)); /* Arbitrarily picked initial seed */
}
/* spectral bin parameters */
dlE = 0.25; /* bin width */
lE0 = log(1.e-12); /* location of first bin, in electron rest-mass units */
/* initialize model data, auxiliary variables */
init_model(argv);
/** main loop **/
N_superph_made = 0;
N_superph_recorded = 0;
N_scatt = 0;
starttime = time(NULL);
quit_flag = 0;
fprintf(stderr, "Entering main loop...\n");
fflush(stderr);
#pragma omp parallel private(ph)
{
while (1) {
/* get pseudo-quanta */
#pragma omp critical (MAKE_SPHOT)
{
if (!quit_flag)
make_super_photon(&ph, &quit_flag);
}
if (quit_flag)
break;
/* push them around */
track_super_photon(&ph);
/* step */
#pragma omp atomic
N_superph_made += 1;
/* give interim reports on rates */
if (((int) (N_superph_made)) % 100000 == 0
&& N_superph_made > 0) {
currtime = time(NULL);
fprintf(stderr, "time %g, rate %g ph/s\n",
(double) (currtime - starttime),
N_superph_made / (currtime -
starttime));
}
}
}
currtime = time(NULL);
fprintf(stderr, "Final time %g, rate %g ph/s\n",
(double) (currtime - starttime),
N_superph_made / (currtime - starttime));
#ifdef _OPENMP
#pragma omp parallel
{
omp_reduce_spect();
}
#endif
report_spectrum((int) N_superph_made);
/* done! */
return (0);
}