forked from pseudotensor/grmonty
-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathtetrads.c
283 lines (223 loc) · 6.91 KB
/
tetrads.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
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
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
/***********************************************************************************
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
***********************************************************************************/
/*
all functions related to creation and manipulation of tetrads
*/
#include "decs.h"
/* input and vectors are contravariant (index up) */
void coordinate_to_tetrad(double Ecov[NDIM][NDIM], double K[NDIM],
double K_tetrad[NDIM])
{
int k;
for (k = 0; k < 4; k++) {
K_tetrad[k] =
Ecov[k][0] * K[0] +
Ecov[k][1] * K[1] +
Ecov[k][2] * K[2] + Ecov[k][3] * K[3];
}
}
/* input and vectors are contravariant (index up) */
void tetrad_to_coordinate(double Econ[NDIM][NDIM], double K_tetrad[NDIM],
double K[NDIM])
{
int l;
for (l = 0; l < 4; l++) {
K[l] = Econ[0][l] * K_tetrad[0] +
Econ[1][l] * K_tetrad[1] +
Econ[2][l] * K_tetrad[2] + Econ[3][l] * K_tetrad[3];
}
return;
}
#define SMALL_VECTOR 1.e-30
/* make orthonormal basis
first basis vector || U
second basis vector || B
*/
void make_tetrad(double Ucon[NDIM], double trial[NDIM],
double Gcov[NDIM][NDIM], double Econ[NDIM][NDIM],
double Ecov[NDIM][NDIM])
{
int k, l;
double norm;
void normalize(double *vcon, double Gcov[4][4]);
void project_out(double *vcona, double *vconb, double Gcov[4][4]);
/* econ/ecov index explanation:
Econ[k][l]
k: index attached to tetrad basis
index down
l: index attached to coordinate basis
index up
Ecov[k][l]
k: index attached to tetrad basis
index up
l: index attached to coordinate basis
index down
*/
/* start w/ time component parallel to U */
for (k = 0; k < 4; k++)
Econ[0][k] = Ucon[k];
normalize(Econ[0], Gcov);
/*** done w/ basis vector 0 ***/
/* now use the trial vector in basis vector 1 */
/* cast a suspicious eye on the trial vector... */
norm = 0.;
for (k = 0; k < 4; k++)
for (l = 0; l < 4; l++)
norm += trial[k] * trial[l] * Gcov[k][l];
if (norm <= SMALL_VECTOR) { /* bad trial vector; default to radial direction */
for (k = 0; k < 4; k++) /* trial vector */
trial[k] = delta(k, 1);
}
for (k = 0; k < 4; k++) /* trial vector */
Econ[1][k] = trial[k];
/* project out econ0 */
project_out(Econ[1], Econ[0], Gcov);
normalize(Econ[1], Gcov);
/*** done w/ basis vector 1 ***/
/* repeat for x2 unit basis vector */
for (k = 0; k < 4; k++) /* trial vector */
Econ[2][k] = delta(k, 2);
/* project out econ[0-1] */
project_out(Econ[2], Econ[0], Gcov);
project_out(Econ[2], Econ[1], Gcov);
normalize(Econ[2], Gcov);
/*** done w/ basis vector 2 ***/
/* and repeat for x3 unit basis vector */
for (k = 0; k < 4; k++) /* trial vector */
Econ[3][k] = delta(k, 3);
/* project out econ[0-2] */
project_out(Econ[3], Econ[0], Gcov);
project_out(Econ[3], Econ[1], Gcov);
project_out(Econ[3], Econ[2], Gcov);
normalize(Econ[3], Gcov);
/*** done w/ basis vector 3 ***/
/* now make covariant version */
for (k = 0; k < 4; k++) {
/* lower coordinate basis index */
lower(Econ[k], Gcov, Ecov[k]);
}
/* then raise tetrad basis index */
for (l = 0; l < 4; l++) {
Ecov[0][l] *= -1.;
}
/* paranoia: check orthonormality */
/*
double sum ;
int m ;
fprintf(stderr,"ortho check:\n") ;
for(k=0;k<NDIM;k++)
for(l=0;l<NDIM;l++) {
sum = 0. ;
for(m=0;m<NDIM;m++) {
sum += Econ[k][m]*Ecov[l][m] ;
}
fprintf(stderr,"%d %d %g\n",k,l,sum) ;
}
fprintf(stderr,"\n") ;
for(k=0;k<NDIM;k++)
for(l=0;l<NDIM;l++) {
fprintf(stderr,"%d %d %g\n",k,l,Econ[k][l]) ;
}
fprintf(stderr,"\n") ;
*/
/* done */
}
double delta(int i, int j)
{
if (i == j)
return (1.);
else
return (0.);
}
void lower(double *ucon, double Gcov[NDIM][NDIM], double *ucov)
{
ucov[0] = Gcov[0][0] * ucon[0]
+ Gcov[0][1] * ucon[1]
+ Gcov[0][2] * ucon[2]
+ Gcov[0][3] * ucon[3];
ucov[1] = Gcov[1][0] * ucon[0]
+ Gcov[1][1] * ucon[1]
+ Gcov[1][2] * ucon[2]
+ Gcov[1][3] * ucon[3];
ucov[2] = Gcov[2][0] * ucon[0]
+ Gcov[2][1] * ucon[1]
+ Gcov[2][2] * ucon[2]
+ Gcov[2][3] * ucon[3];
ucov[3] = Gcov[3][0] * ucon[0]
+ Gcov[3][1] * ucon[1]
+ Gcov[3][2] * ucon[2]
+ Gcov[3][3] * ucon[3];
return;
}
void normalize(double *vcon, double Gcov[NDIM][NDIM])
{
int k, l;
double norm;
norm = 0.;
for (k = 0; k < 4; k++)
for (l = 0; l < 4; l++)
norm += vcon[k] * vcon[l] * Gcov[k][l];
norm = sqrt(fabs(norm));
for (k = 0; k < 4; k++)
vcon[k] /= norm;
return;
}
void project_out(double *vcona, double *vconb, double Gcov[NDIM][NDIM])
{
double adotb, vconb_sq;
int k, l;
vconb_sq = 0.;
for (k = 0; k < 4; k++)
for (l = 0; l < 4; l++)
vconb_sq += vconb[k] * vconb[l] * Gcov[k][l];
adotb = 0.;
for (k = 0; k < 4; k++)
for (l = 0; l < 4; l++)
adotb += vcona[k] * vconb[l] * Gcov[k][l];
for (k = 0; k < 4; k++)
vcona[k] -= vconb[k] * adotb / vconb_sq;
return;
}
void normalize_null(double Gcov[NDIM][NDIM], double K[])
{
int k, l;
double A, B, C;
/* pop K back onto the light cone */
A = Gcov[0][0];
B = 0.;
for (k = 1; k < 4; k++)
B += 2. * Gcov[k][0] * K[k];
C = 0.;
for (k = 1; k < 4; k++)
for (l = 1; l < 4; l++)
C += Gcov[k][l] * K[k] * K[l];
K[0] = (-B - sqrt(fabs(B * B - 4. * A * C))) / (2. * A);
return;
}