forked from AFD-Illinois/igrmonty2d
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.c
150 lines (114 loc) · 3.68 KB
/
main.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
/*
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 */
Params params = { 0 };
struct of_geom **geom;
int nthreads;
int N1, N2, N3, n_within_horizon;
double F[N_ESAMP + 1], wgt[N_ESAMP + 1];
int Ns, N_superph_recorded, N_scatt;
struct of_spectrum spect[N_THBINS][N_EBINS] = { };
double t;
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;
int main(int argc, char *argv[])
{
//omp_set_num_threads(1);
double N_superph_made;
time_t currtime, starttime;
// Spectral bin parameters
dlE = 0.25; // bin width
lE0 = log(1.e-12); // location of first bin, in electron rest-mass units
// Load parameters
for (int i=0; i<argc-1; ++i) {
if ( strcmp(argv[i], "-par") == 0 ) {
load_par(argv[i+1], ¶ms);
}
}
init_model(argc, argv, ¶ms);
N_superph_made = 0;
N_superph_recorded = 0;
N_scatt = 0;
starttime = time(NULL);
printf("SYNCH: %i\n", SYNCHROTRON);
printf("BREMS: %i\n", BREMSSTRAHLUNG);
printf("COMPT: %i\n", COMPTON);
fprintf(stderr, "Entering main loop...\n");
// Get number of superphotons for each zone
/*void init_zone(int i, int j, int k, double *nz, double *dnmax);
ZLOOP {
double nz, dnmax;
init_zone(i, j, k, &nz, &dnmax);
if (j == N2/2)
printf("[%i %i %i] nz = %e dnmax = %e\n", i,j,k,nz,dnmax);
}*/
int quit_flag = 0;
#pragma omp parallel
{
struct of_photon 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));
omp_reduce_spect();
report_spectrum((int) N_superph_made, ¶ms);
return 0;
}