Debian Codegraph @

Codes/Kerr2/kerr_BL.C

raw
1 /*
2 * Kerr metric in Boyer-Lindquist coordinates
3 */
4
5 /*
6 * Copyright (c) 2011 Eric Gourgoulhon
7 *
8 * This file is part of LORENE.
9 *
10 * LORENE is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License version 2
12 * as published by the Free Software Foundation.
13 *
14 * LORENE is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with LORENE; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 *
23 */
24
25 char kerr_BL_C[] = "$Header: /cvsroot/Lorene/Codes/Kerr2/kerr_BL.C,v 1.6 2014/10/13 08:53:57 j_novak Exp $" ;
26
27 /*
28 * $Id: kerr_BL.C,v 1.6 2014/10/13 08:53:57 j_novak Exp $
29 * $Log: kerr_BL.C,v $
30 * Revision 1.6 2014/10/13 08:53:57 j_novak
31 * Lorene classes and functions now belong to the namespace Lorene.
32 *
33 * Revision 1.5 2013/02/28 15:36:59 o_straub
34 * Output file: added spin output
35 *
36 * Revision 1.4 2013/02/20 13:51:46 e_gourgoulhon
37 * Added output of the grid points to a file
38 *
39 * Revision 1.3 2012/01/17 22:05:42 e_gourgoulhon
40 * Corrected an error in the spectral basis for beta.
41 *
42 * Revision 1.2 2011/11/27 14:45:54 e_gourgoulhon
43 * grid declared SYM in phi
44 * 1 point in phi allowed
45 * suppressed inc_dzpuis on K_23
46 *
47 * Revision 1.1 2011/11/25 16:44:42 e_gourgoulhon
48 * First version; not fully checked yet
49 *
50 *
51 * $Header: /cvsroot/Lorene/Codes/Kerr2/kerr_BL.C,v 1.6 2014/10/13 08:53:57 j_novak Exp $
52 *
53 */
54
55 // C++ headers
56 #include "headcpp.h"
57
58 // C headers
59 #include <cstdlib>
60 #include <cmath>
61
62 // Lorene headers
63 #include "metric.h"
64 #include "nbr_spx.h"
65 #include "utilitaires.h"
66 #include "cmp.h"
67 #include "proto.h"
68 #include "graphique.h"
69
70 // local:
71 double beta3(double, double, double) ;
72
73
74 using namespace Lorene ;
75
76 int main() {
77
78 // Parameters of the computation
79 // -----------------------------
80
81 ifstream fpar("par_kerr_BL.d") ;
82 if ( !fpar.good() ) {
83 cerr << "Problem in opening the file par_kerr_BL.d ! " << endl ;
84 abort() ;
85 }
86
87 double aa ; // Kerr parameter a/M
88 fpar >> aa ; fpar.ignore(1000,'\n') ;
89 double aa2 = aa*aa ;
90
91 int graphic_out ; // flag for graphical outputs
92 fpar >> graphic_out ; fpar.ignore(1000,'\n') ;
93
94 int nr ; // Number of collocation points in r in each domain
95 fpar >> nr; fpar.ignore(1000,'\n') ;
96
97 int nt ; // Number of collocation points in theta in each domain
98 fpar >> nt; fpar.ignore(1000,'\n') ;
99
100 int np ; // Number of collocation points in phi in each domain
101 fpar >> np; fpar.ignore(1000,'\n') ;
102
103 int nz ; // Number of domains
104 fpar >> nz ; fpar.ignore(1000,'\n') ;
105 int nzm1 = nz - 1 ; // Index of outermost domain
106
107 fpar.ignore(1000,'\n') ; // skip title
108 double* r_limits = new double[nz+1]; // radial boundaries of each domain in units of M
109 for (int l=0; l<nz; l++) {
110 fpar >> r_limits[l];
111 }
112 r_limits[nz] = __infinity ;
113
114 fpar.close();
115
116 //## check
117 cout << "r_limits (units of M) : " ;
118 for (int l=0; l<nz+1; l++) {
119 cout << r_limits[l] << " " ;
120 }
121 cout << endl ;
122
123 // value of coordinate r at the event horizon:
124 double r_hor = 1 + sqrt(1 - aa2) ;
125 cout << "Value of coordinate r at the event horizon : " << r_hor << " M" << endl << endl ;
126
127 if (r_limits[1] <= r_hor) {
128 cerr << "Inner boundary of domain no. 1 below the horizon : " << endl ;
129 cerr << " r_limits[1] : " << r_limits[1] << endl ;
130 cerr << " r_hor : " << r_hor << endl ;
131 abort() ;
132 }
133
134 // Setup of a multi-domain grid (Lorene class Mg3d)
135 // ------------------------------------------------
136
137 int symmetry_theta = SYM ; // symmetry with respect to the equatorial plane
138 int symmetry_phi = SYM ; // symmetry with respect to phi --> phi + pi
139 bool compact = true ; // external domain is compactified
140
141 Mg3d mgrid(nz, nr, nt, np, symmetry_theta, symmetry_phi, compact) ;
142
143 cout << mgrid << endl ;
144
145
146 // Setup of an affine mapping : grid --> physical space (Lorene class Map_af)
147 // --------------------------------------------------------------------------
148
149 Map_af map(mgrid, r_limits) ;
150
151 // cout << map << endl ;
152
153 // Denomination of various coordinates associated with the mapping
154 // ---------------------------------------------------------------
155
156 const Coord& r = map.r ; // r field
157 const Coord& cost = map.cost ; // cos(theta) field
158 const Coord& sint = map.sint ; // sin(theta) field
159 Mtbl r2 = r*r ;
160 Mtbl cost2 = cost*cost ;
161 Mtbl sint2 = sint*sint ;
162
163 // rho^2
164 Scalar rho2(map) ;
165 rho2 = r2 + aa2 * cost2 ;
166 rho2.std_spectral_base() ;
167
168 // rho^2 / r^2
169 Scalar rho2_ovr2(map) ;
170 rho2_ovr2 = 1 + aa2 * cost2 / r2 ;
171 rho2_ovr2.std_spectral_base() ;
172
173 // Delta / r^2
174 Scalar delta_ovr2(map) ;
175 delta_ovr2 = 1 - 2/r + aa2/r2 ;
176 delta_ovr2.std_spectral_base() ;
177
178 // B^2 = Sigma^2 / (r*rho)^2
179 Scalar bb2(map) ;
180 bb2 = 1 + aa2/r2 + 2*aa2*sint2 / (r*rho2) ;
181 bb2.std_spectral_base() ;
182
183 // Lapse
184 Scalar nn = sqrt( delta_ovr2 / bb2 ) ;
185 nn.set_domain(0) = 1 ;
186 nn.std_spectral_base() ;
187
188 // Shift vector
189 Vector beta(map, CON, map.get_bvect_spher()) ;
190 beta.set(1) = 0 ;
191 beta.set(2) = 0 ;
192 beta.set(3) = - 2 *aa * sint / (rho2*(1 + aa2/r2) + 2*aa2*sint2/r) ;
193 beta.set(3).annule_domain(0) ;
194 beta.std_spectral_base() ;
195
196 // 3-metric
197 Sym_tensor gamma(map, COV, map.get_bvect_spher()) ;
198 gamma.set(1,1) = rho2_ovr2 / delta_ovr2 ;
199 gamma.set(1,1).set_domain(0) = 1 ;
200 gamma.set(1,2) = 0 ;
201 gamma.set(1,3) = 0 ;
202 gamma.set(2,2) = rho2_ovr2 ;
203 gamma.set(2,2).set_domain(0) = 1 ;
204 gamma.set(2,3) = 0 ;
205 gamma.set(3,3) = bb2 ;
206 gamma.set(3,3).set_domain(0) = 1 ;
207
208 Sym_tensor inv_gamma(map, CON, map.get_bvect_spher()) ;
209 inv_gamma.set(1,1) = 1 / gamma(1,1) ;
210 inv_gamma.set(1,2) = 0 ;
211 inv_gamma.set(1,3) = 0 ;
212 inv_gamma.set(2,2) = 1 / gamma(2,2) ;
213 inv_gamma.set(2,3) = 0 ;
214 inv_gamma.set(3,3) = 1 / gamma(3,3) ;
215
216 // Extrinsic curvature
217 Scalar beta_phi(map) ;
218 beta_phi = - 2*aa / (r*rho2*(1 + aa2/r2) + 2*aa2*sint2) ;
219 beta_phi.annule_domain(0) ;
220 beta_phi.std_spectral_base() ;
221 Sym_tensor kk(map, COV, map.get_bvect_spher()) ;
222 kk.set(1,1) = 0 ;
223 kk.set(1,2) = 0 ;
224 Scalar tmp = 0.5 * bb2 * beta_phi.dsdr() / nn ;
225 tmp.mult_rsint() ;
226 kk.set(1,3) = tmp ;
227 kk.set(2,2) = 0 ;
228 tmp = 0.5 * bb2 * beta_phi.dsdt() / nn ;
229 tmp.mult_sint() ;
230 kk.set(2,3) = tmp ;
231 kk.set(3,3) = 0 ;
232
233 // Value of (r,theta) at the grid points:
234 // cout.precision(16) ;
235 ofstream file_grid("grid.d") ;
236 file_grid.precision(16) ;
237 for (int l=1; l<nz; l++) {
238 // cout << "Domain no. " << l << endl ;
239 file_grid << "Domain no. " << l << endl ;
240 for (int j=0; j<nt; j++) {
241 for (int i=0; i<nr; i++) {
242 double xi = mgrid.get_grille3d(l)->x[i] ;
243 double theta = mgrid.get_grille3d(l)->tet[j] ;
244 double phi = 0 ; // axisymmetry
245 double rg = map.val_r(l, xi, theta, phi) ;
246 // cout << "j, i = " << j << ", " << i << " : r, theta : " << rg << ", " << theta << endl ;
247 file_grid << rg << " " << theta << endl ;
248 }
249 }
250 }
251 file_grid.close() ;
252
253
254
255 // Drawings
256 if (graphic_out == 1) {
257 des_meridian(nn, 0, 1.5*r_limits[nzm1], "N", 1) ;
258
259 des_meridian(beta_phi, 0, 1.5*r_limits[nzm1], "beta\\uphi\\d", 2) ;
260 des_meridian(beta(3), 0, 1.5*r_limits[nzm1], "beta\\u3\\d (ortho. comp.)", 3) ;
261
262 des_meridian(gamma(1,1), 0, 1.5*r_limits[nzm1], "gamma_11", 4) ;
263 des_meridian(gamma(2,2), 0, 1.5*r_limits[nzm1], "gamma_22", 5) ;
264 des_meridian(gamma(3,3), 0, 1.5*r_limits[nzm1], "gamma_33", 6) ;
265
266 des_meridian(kk(1,3), 0, 1.5*r_limits[nzm1], "K_13", 7) ;
267 des_meridian(kk(2,3), 0, 1.5*r_limits[nzm1], "K_23", 8) ;
268
269 arrete() ;
270 }
271
272 // Output file
273 //------------
274 FILE* file_out = fopen("gyoto_kerr_BL.d", "w") ;
275 double total_time = 0. ; // for compatibility
276
277 fwrite_be(&total_time, sizeof(double), 1, file_out) ;
278 mgrid.sauve(file_out) ;
279 map.sauve(file_out) ;
280 nn.sauve(file_out) ;
281 beta.sauve(file_out) ;
282 gamma.sauve(file_out) ;
283 inv_gamma.sauve(file_out) ;
284 kk.sauve(file_out) ;
285 fwrite_be(&aa, sizeof(double), 1, file_out) ;
286
287 fclose(file_out) ;
288
289 // Test
290 //-----
291
292 /* double theta0 = 1. ;
293 double rmin = 1.1* r_limits[1] ;
294 double rmax = r_limits[nz-1] ;
295 cout << "rmin, rmax : " << rmin << ", " << rmax << endl ;
296 int npt = 100 ;
297 double h = (rmax - rmin) / double(npt -1) ;
298 for (int i=0; i<npt; i++) {
299 double rr = rmin + h *i ;
300 double bet = beta(3).val_point(rr,theta0,0) ;
301 double bet0 = beta3(rr,theta0,aa) ;
302 double err = bet - bet0 ;
303 double err_rel = err / bet0 ;
304 cout << "rr, bet, bet0, err, err_rel : " << rr << " " << bet << " " << bet0 << " " << err << " " << err_rel << endl ;
305 }
306 */
307
308 return EXIT_SUCCESS ;
309
310 }
311
312 double beta3(double r, double th, double a) {
313 double a2 = a*a ;
314 double r2 = r*r ;
315 return - 2*a*sin(th) / ( (r2+a2*cos(th)*cos(th))*(1+a2/r2) + 2*a2*sin(th)*sin(th)/r ) ;
316 }
317
318
319
320
321
322
323
324
325
326
327
328
329