-
Notifications
You must be signed in to change notification settings - Fork 20
Expand file tree
/
Copy pathjnu_mixed.c
More file actions
254 lines (186 loc) · 5.81 KB
/
jnu_mixed.c
File metadata and controls
254 lines (186 loc) · 5.81 KB
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
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
/***********************************************************************************
Copyright 2013 Joshua C. Dolence, Charles F. Gammie, Monika Mo\'scibrodzka,
and Po Kin Leung
GRMONTY version 1.0 (released February 1, 2013)
This file is part of GRMONTY. GRMONTY v1.0 is a program that calculates the
emergent spectrum from a model using a Monte Carlo technique.
This version of GRMONTY is configured to use input files from the HARM code
available on the same site. It assumes that the source is a plasma near a
black hole described by Kerr-Schild coordinates that radiates via thermal
synchrotron and inverse compton scattering.
You are morally obligated to cite the following paper in any
scientific literature that results from use of any part of GRMONTY:
Dolence, J.C., Gammie, C.F., Mo\'scibrodzka, M., \& Leung, P.-K. 2009,
Astrophysical Journal Supplement, 184, 387
Further, we strongly encourage you to obtain the latest version of
GRMONTY directly from our distribution website:
http://rainman.astro.illinois.edu/codelib/
GRMONTY is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
GRMONTY is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with GRMONTY; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
***********************************************************************************/
#include "decs.h"
#pragma omp threadprivate(r)
/*
"mixed" emissivity formula
interpolates between Petrosian limit and
classical thermal synchrotron limit
good for Thetae > 1
*/
#define CST 1.88774862536 /* 2^{11/12} */
double jnu_synch(double nu, double Ne, double Thetae, double B,
double theta)
{
double K2, nuc, nus, x, f, j, sth, xp1, xx;
double K2_eval(double Thetae);
if (Thetae < THETAE_MIN)
return 0.;
K2 = K2_eval(Thetae);
nuc = EE * B / (2. * M_PI * ME * CL);
sth = sin(theta);
nus = (2. / 9.) * nuc * Thetae * Thetae * sth;
if (nu > 1.e12 * nus)
return (0.);
x = nu / nus;
xp1 = pow(x, 1. / 3.);
xx = sqrt(x) + CST * sqrt(xp1);
f = xx * xx;
j = (M_SQRT2 * M_PI * EE * EE * Ne * nus / (3. * CL * K2)) * f *
exp(-xp1);
return (j);
}
#undef CST
#define JCST (M_SQRT2*EE*EE*EE/(27*ME*CL*CL))
double int_jnu(double Ne, double Thetae, double Bmag, double nu)
{
/* Returns energy per unit time at *
* frequency nu in cgs */
double j_fac, K2;
double F_eval(double Thetae, double B, double nu);
double K2_eval(double Thetae);
if (Thetae < THETAE_MIN)
return 0.;
K2 = K2_eval(Thetae);
if (K2 == 0.)
return 0.;
j_fac = Ne * Bmag * Thetae * Thetae / K2;
return JCST * j_fac * F_eval(Thetae, Bmag, nu);
}
#undef JCST
#define CST 1.88774862536 /* 2^{11/12} */
double jnu_integrand(double th, void *params)
{
double K = *(double *) params;
double sth = sin(th);
double x = K / sth;
if (sth < 1.e-150 || x > 2.e8)
return 0.;
return sth * sth * pow(sqrt(x) + CST * pow(x, 1. / 6.),
2.) * exp(-pow(x, 1. / 3.));
}
#undef CST
/* Tables */
double F[N_ESAMP + 1], K2[N_ESAMP + 1];
double lK_min, dlK;
double lT_min, dlT;
#define EPSABS 0.
#define EPSREL 1.e-6
#define KMIN (0.002)
#define KMAX (1.e7)
#define TMIN (THETAE_MIN)
#define TMAX (1.e2)
void init_emiss_tables(void)
{
int k;
double result, err, K, T;
gsl_function func;
gsl_integration_workspace *w;
func.function = &jnu_integrand;
func.params = &K;
lK_min = log(KMIN);
dlK = log(KMAX / KMIN) / (N_ESAMP);
lT_min = log(TMIN);
dlT = log(TMAX / TMIN) / (N_ESAMP);
/* build table for F(K) where F(K) is given by
\int_0^\pi ( (K/\sin\theta)^{1/2} + 2^{11/12}(K/\sin\theta)^{1/6})^2 \exp[-(K/\sin\theta)^{1/3}]
so that J_{\nu} = const.*F(K)
*/
w = gsl_integration_workspace_alloc(1000);
for (k = 0; k <= N_ESAMP; k++) {
K = exp(k * dlK + lK_min);
gsl_integration_qag(&func, 0., M_PI / 2., EPSABS, EPSREL,
1000, GSL_INTEG_GAUSS61, w, &result,
&err);
F[k] = log(4 * M_PI * result);
}
gsl_integration_workspace_free(w);
/* build table for quick evaluation of the bessel function K2 for emissivity */
for (k = 0; k <= N_ESAMP; k++) {
T = exp(k * dlT + lT_min);
K2[k] = log(gsl_sf_bessel_Kn(2, 1. / T));
}
/* Avoid doing divisions later */
dlK = 1. / dlK;
dlT = 1. / dlT;
fprintf(stderr, "done.\n\n");
return;
}
/* rapid evaluation of K_2(1/\Thetae) */
double K2_eval(double Thetae)
{
double linear_interp_K2(double);
if (Thetae < THETAE_MIN)
return 0.;
if (Thetae > TMAX)
return 2. * Thetae * Thetae;
return linear_interp_K2(Thetae);
}
#define KFAC (9*M_PI*ME*CL/EE)
double F_eval(double Thetae, double Bmag, double nu)
{
double K, x;
double linear_interp_F(double);
K = KFAC * nu / (Bmag * Thetae * Thetae);
if (K > KMAX) {
return 0.;
} else if (K < KMIN) {
/* use a good approximation */
x = pow(K, 0.333333333333333333);
return (x * (37.67503800178 + 2.240274341836 * x));
} else {
return linear_interp_F(K);
}
}
#undef KFAC
#undef KMIN
#undef KMAX
#undef EPSABS
#undef EPSREL
double linear_interp_K2(double Thetae)
{
int i;
double di, lT;
lT = log(Thetae);
di = (lT - lT_min) * dlT;
i = (int) di;
di = di - i;
return exp((1. - di) * K2[i] + di * K2[i + 1]);
}
double linear_interp_F(double K)
{
int i;
double di, lK;
lK = log(K);
di = (lK - lK_min) * dlK;
i = (int) di;
di = di - i;
return exp((1. - di) * F[i] + di * F[i + 1]);
}