forked from AFD-Illinois/igrmonty2d
-
Notifications
You must be signed in to change notification settings - Fork 0
/
tetrads.c
224 lines (178 loc) · 4.64 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
/*
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;
}