Debian Codegraph @

Codes/Kerr/kerr.C

raw
1 /* Computes the Kerr metric in Dirac gauge.
2 *
3 */
4
5 /*
6 * Copyright (c) 2004 Francois Limousin
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 as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
14 *
15 * LORENE is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License
21 * along with LORENE; if not, write to the Free Software
22 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 *
24 */
25
26
27 char kerr_C[] = "$Header: /cvsroot/Lorene/Codes/Kerr/kerr.C,v 1.6 2014/10/13 08:53:57 j_novak Exp $" ;
28
29 /*
30 * $Id: kerr.C,v 1.6 2014/10/13 08:53:57 j_novak Exp $
31 * $Log: kerr.C,v $
32 * Revision 1.6 2014/10/13 08:53:57 j_novak
33 * Lorene classes and functions now belong to the namespace Lorene.
34 *
35 * Revision 1.5 2014/10/06 15:09:45 j_novak
36 * Modified #include directives to use c++ syntax.
37 *
38 * Revision 1.4 2006/01/24 16:01:33 f_limousin
39 * Version ok for lambda = 0 and lambda = 1/3
40 *
41 * Revision 1.3 2005/11/10 16:35:30 f_limousin
42 * Improve the convergence and the accuracy of the solution
43 *
44 * Revision 1.2 2005/11/08 14:18:57 f_limousin
45 * First version
46 *
47 *
48 * $Header: /cvsroot/Lorene/Codes/Kerr/kerr.C,v 1.6 2014/10/13 08:53:57 j_novak Exp $
49 *
50 */
51
52 // headers C++
53 #include "headcpp.h"
54
55 // headers C
56 #include <cstdlib>
57 #include <cmath>
58
59 // headers Lorene
60 #include "tenseur.h"
61 #include "tensor.h"
62 #include "graphique.h"
63 #include "nbr_spx.h"
64 #include "metric.h"
65 #include "proto.h"
66 #include "utilitaires.h"
67
68 using namespace Lorene ;
69
70 int main(){
71
72 //------------------------------------------------------------------
73 // Parameters of the computation
74 //------------------------------------------------------------------
75
76 int nt, np, nz, nr1, nrp1 ;
77 double aa, hh, mm ;
78
79 ifstream fpar("parkerr.d") ;
80 fpar.ignore(1000, '\n') ;
81 fpar.ignore(1000, '\n') ;
82 fpar >> nz; fpar.ignore(1000, '\n');
83 fpar >> nt; fpar.ignore(1000, '\n');
84 fpar >> np; fpar.ignore(1000, '\n');
85 fpar >> nr1; fpar.ignore(1000, '\n');
86 fpar >> nrp1; fpar.ignore(1000, '\n');
87
88 // Type of sampling in theta and phi :
89 int type_t = SYM ;
90 int type_p = NONSYM ;
91
92 cout << "total number of domains : nz = " << nz << endl ;
93 cout << "number of points in phi : np = " << np << endl ;
94 cout << "number of points in theta : nt = " << nt << endl ;
95
96 double relax, seuil ;
97 int niter ;
98 fpar >> relax; fpar.ignore(1000, '\n');
99 fpar >> seuil; fpar.ignore(1000, '\n');
100 fpar >> niter; fpar.ignore(1000, '\n');
101
102 int* nr_tab = new int[nz];
103 int* nt_tab = new int[nz];
104 int* np_tab = new int[nz];
105 double* bornes = new double[nz+1];
106
107 for (int l=0; l<nz; l++) {
108 if (l==1) nr_tab[1] = nr1 ;
109 else nr_tab[l] = nrp1 ;
110 np_tab[l] = np ;
111 nt_tab[l] = nt ;
112 bornes[l] = pow(2., l-1) ;
113 }
114 bornes[0] = 0. ;
115 bornes[nz] = __infinity ;
116
117 fpar >> hh ; fpar.ignore(1000, '\n') ;
118 fpar >> mm ; fpar.ignore(1000, '\n') ;
119 fpar >> seuil ; fpar.ignore(1000, '\n') ;
120
121 for (int l=0; l<nz; l++)
122 bornes[l] = bornes[l] * hh * 0.5 ;
123
124 cout << "h = " << hh << endl ;
125 cout << "M = " << mm << endl ;
126 cout << "seuil = " << seuil << endl ;
127
128 fpar.close();
129
130
131 // Type of r sampling :
132 int* type_r = new int[nz];
133 type_r[0] = RARE ;
134 for (int l=1; l<nz-1; l++) {
135 type_r[l] = FIN ;
136 }
137 type_r[nz-1] = UNSURR ;
138
139
140 //-----------------------------------------------------------------------
141 // Construction of multi-grid and mapping
142 //-----------------------------------------------------------------------
143
144 Mg3d mg(nz, nr_tab, type_r, nt_tab, type_t, np_tab, type_p) ;
145
146 Map_af mp(mg, bornes) ;
147
148 //-------------------------------
149 // Initialisation of h_uu and xi
150 //-------------------------------
151
152 Scalar a2(mp) ;
153 Scalar b2(mp) ;
154
155 // We parametrize Kerr with M and h.
156 aa = sqrt (mm*mm - hh*hh) ;
157
158 const Coord& rr = mp.r ;
159 const Coord& theta = mp.tet ;
160
161 a2 = 1. + 2.*mm/rr + (3.*mm*mm + aa*aa*cos(2.*theta))/(2.*rr*rr)
162 + (hh*hh*mm)/(2.*pow(rr, 3.)) + pow(hh,4.)/(16.*pow(rr,4.)) ;
163
164 b2 = ( pow(rr,8.) + 4.*mm*pow(rr,7.) + (7.*mm*mm +
165 aa*aa*cos(theta)*cos(theta))*pow(rr,6.) + mm*(7.*mm*mm+aa*aa)
166 *pow(rr,5.) + (4.*pow(mm,4.) + hh*hh*(3.*hh*hh/4.+aa*aa*sin(theta)
167 *sin(theta))/2.)*pow(rr,4.) + hh*hh*mm*(2.*mm*mm-hh*hh/4.)
168 *pow(rr,3.) + pow(hh,4.)/16.*(7.*mm*mm + aa*aa*cos(theta)
169 *cos(theta))*rr*rr + pow(hh,6.)*mm/16.*rr + pow(hh,8.)/256. )
170 / ( pow(rr,8.) + 2.*mm*pow(rr,7.) + (3.*mm*mm + aa*aa
171 *cos(2.*theta))/2.*pow(rr,6.) + hh*hh*mm/2.*pow(rr,5.)
172 + pow(hh,4.)/16.*pow(rr,4.)) ;
173
174 b2.set_outer_boundary(nz-1 ,1.) ;
175 b2.std_spectral_base() ;
176 b2.set_domain(0) = 1. ;
177
178 Sym_tensor h_uu(mp, CON, mp.get_bvect_cart()) ;
179 h_uu.set(1,1) = pow(b2/a2, 1./3.) - 1 ;
180 h_uu.set(2,2) = pow(b2/a2, 1./3.) - 1 ;
181 h_uu.set(3,3) = pow(a2/b2, 2./3.) - 1 ;
182 h_uu.set(1,2) = 0. ;
183 h_uu.set(1,3) = 0. ;
184 h_uu.set(2,3) = 0. ;
185 h_uu.annule_domain(0) ;
186 h_uu.std_spectral_base() ;
187
188 Sym_tensor g_uu(mp, CON, mp.get_bvect_cart()) ;
189 g_uu.set(1,1) = 1 / a2 ;
190 g_uu.set(2,2) = 1 / a2 ;
191 g_uu.set(3,3) = 1 / b2 ;
192 g_uu.set(1,2).annule_hard() ;
193 g_uu.set(1,3).annule_hard() ;
194 g_uu.set(2,3).annule_hard() ;
195
196 for (int i=1; i<=3; i++)
197 for (int j=1; j<=i; j++)
198 g_uu.set(i,j).set_domain(0) = 1. ;
199 g_uu.std_spectral_base() ;
200
201 Metric_flat flat(mp.flat_met_cart()) ;
202 Metric gamma (g_uu) ;
203 Sym_tensor gt_uu(mp, CON, mp.get_bvect_cart()) ;
204 for(int i=1; i<=3; i++)
205 for(int j=1; j<=i; j++){
206 gt_uu.set(i,j) = flat.con()(i,j) + h_uu(i,j) ;
207 }
208 gt_uu.std_spectral_base() ;
209
210 // Save initial metric
211 Sym_tensor huu_save (h_uu) ;
212 Sym_tensor guu_save (g_uu) ;
213
214 Vector xi(mp, CON, mp.get_bvect_cart()) ;
215 xi.set(1) = 0. ;
216 xi.set(2) = 0. ;
217 xi.set(3) = 0. ;
218 xi.std_spectral_base() ;
219
220 //----------------------------------------------------
221 // Resolution of the vectorial Poisson equation for xi
222 //----------------------------------------------------
223
224 Vector source(mp, CON, mp.get_bvect_cart()) ;
225
226 Vector xi_jm1(mp, CON, mp.get_bvect_cart()) ;
227 for(int i=1; i<=3; i++)
228 xi_jm1.set(i) = 0. ;
229 double diff_xi = 1. ;
230
231
232
233 for(int mer=0; mer<niter; mer++){
234
235 cout <<
236 "========================================================================"
237 << endl ;
238 cout << "step = " << mer << " diff_xi = "<< diff_xi << endl ;
239 cout <<
240 "========================================================================"
241 << endl ;
242
243 // Function exp(-(r-r_0)^2/sigma^2)
244 // --------------------------------
245
246 double r0 = mp.val_r(nz-2, 1, 0, 0) ;
247 double sigma = 1.*r0 ;
248
249 Scalar rrr (mp) ;
250 rrr = mp.r ;
251
252 Scalar ff (mp) ;
253 ff = exp( -(rrr - r0)*(rrr - r0)/sigma/sigma ) ;
254 for (int ii=0; ii<nz-1; ii++)
255 ff.set_domain(ii) = 1. ;
256 ff.set_outer_boundary(nz-1, 0) ;
257 ff.std_spectral_base() ;
258
259
260 // Source
261 source = h_uu.divergence(flat) ;
262 source = source * ff ;
263 source.inc_dzpuis(2) ;
264
265 source.annule_domain(0) ;
266
267 // Printing
268 //-----------
269
270 cout << "moyenne de la source pour xi :" << endl ;
271 for (int i=1; i<=3; i++){
272 cout << " Comp. " << i << " : " ;
273 for (int l=0; l<nz; l++){
274 cout << norme(source(i)/(nr_tab[0]*nt*np))(l) << " " ;
275 }
276 cout << endl ;
277 }
278 /*
279 des_meridian(source(1), 0, 20, "source", 0) ;
280 des_meridian(source(2), 0, 20, "source", 1) ;
281 des_meridian(source(3), 0, 20, "source", 2) ;
282 arrete() ;
283 */
284 // Resolution of the Poisson equation
285 // ----------------------------------
286
287 double lambda = 1./3. ;
288 Vector source_reg = - (1./3. - lambda) *
289 xi.divergence(flat).derive_con(flat) ;
290 source_reg = source_reg * ff ;
291 source_reg.inc_dzpuis() ;
292 source += source_reg ;
293
294 /*
295 des_profile(ff, 0, 20, 0, 0) ;
296 des_meridian(source(1), 0, 20, "source", 3) ;
297 des_meridian(source(2), 0, 20, "source", 4) ;
298 des_meridian(source(3), 0, 20, "source", 5) ;
299 arrete() ;
300 */
301
302 for (int i=1; i<=3; i++)
303 source.set(i).set_domain(nz-1) = 1.e-15 ; // Because of the dzpuis
304
305 double precision = 1.e-12 ;
306 int num_front = 0 ; // index of the intern boundary
307 int itermax = 20 ;
308
309 Vector limite (mp, CON, mp.get_bvect_cart()) ;
310 limite.std_spectral_base() ;
311 Valeur lim_x (mg.get_angu()) ;
312 Valeur lim_y (mg.get_angu()) ;
313 Valeur lim_z (mg.get_angu()) ;
314 lim_x = 0. ;
315 lim_y = 0. ;
316 lim_z = 0. ;
317 lim_x.set_base(limite(1).get_spectral_va().get_base()) ;
318 lim_y.set_base(limite(2).get_spectral_va().get_base()) ;
319 lim_z.set_base(limite(3).get_spectral_va().get_base()) ;
320
321
322 cout << "Resolution of equation for xi : poisson_vect_frontiere "
323 << endl << "----------------------------------------------------"
324 << endl ;
325
326
327 Tenseur source_p(mp, 1, CON, mp.get_bvect_cart() ) ;
328 source_p.set_etat_qcq() ;
329 for (int i=0; i<3; i++)
330 source_p.set(i) = Cmp(source(i+1)) ;
331
332 Tenseur resu_p(mp, 1, CON, mp.get_bvect_cart() ) ;
333 resu_p.set_etat_qcq() ;
334 for (int i=0; i<3; i++)
335 resu_p.set(i).annule_hard() ;
336 resu_p.set_std_base() ;
337
338 poisson_vect_frontiere(lambda, source_p, resu_p, lim_x,
339
340 lim_y, lim_z, num_front, precision, itermax) ;
341
342 for (int i=1; i<=3; i++)
343 xi.set(i) = resu_p(i-1) ;
344
345 // Test
346 // ---------
347
348 source.dec_dzpuis() ;
349 Vector lap_xi = (xi.derive_con(flat)).divergence(flat)
350 + lambda* xi.divergence(flat).derive_con(flat) ;
351
352 maxabs(lap_xi - source,
353 "Absolute error in the resolution of the equation for beta") ;
354 cout << endl ;
355
356 Tbl tdiff_xi_x = diffrel(lap_xi(1), source(1)) ;
357 Tbl tdiff_xi_y = diffrel(lap_xi(2), source(2)) ;
358 Tbl tdiff_xi_z = diffrel(lap_xi(3), source(3)) ;
359
360 cout <<
361 "Relative error in the resolution of the equation for xi1 : "
362 << endl ;
363 cout << "x component : " ;
364 for (int l=0; l<nz; l++) {
365 cout << tdiff_xi_x(l) << " " ;
366 }
367 cout << endl ;
368 cout << "y component : " ;
369 for (int l=0; l<nz; l++) {
370 cout << tdiff_xi_y(l) << " " ;
371 }
372 cout << endl ;
373 cout << "z component : " ;
374 for (int l=0; l<nz; l++) {
375 cout << tdiff_xi_z(l) << " " ;
376 }
377 cout << endl ;
378
379 // Xi
380 cout << "xi :" << endl ;
381 for (int i=1; i<=3; i++){
382 cout << " Comp. " << i << " : " ;
383 for (int l=0; l<nz; l++){
384 cout << norme(xi(i)/(nr_tab[0]*nt*np))(l) << " " ;
385 }
386 cout << endl ;
387 }
388 cout << endl ;
389
390
391 // Construction of the new metric quantities :
392 //--------------------------------------------
393
394 Sym_tensor temp_guu (g_uu.derive_lie(xi)) ;
395 temp_guu.dec_dzpuis(2) ;
396 g_uu = g_uu + temp_guu ;
397
398 for (int i=1; i<=3; i++)
399 for (int j=1; j<=i; j++)
400 g_uu.set(i,j).set_domain(0) = 1. ;
401
402 gamma = g_uu ;
403 gt_uu = pow(gamma.determinant(), 1./3.) * g_uu ;
404 gt_uu.std_spectral_base() ;
405
406 for(int i=1; i<=3; i++)
407 for(int j=1; j<=i; j++)
408 h_uu.set(i,j) = gt_uu(i,j) - flat.con()(i,j) ;
409
410
411 // End of the iteration ?
412
413 diff_xi = 0. ;
414 Tbl diff (max(abs(xi(1)))) ;
415 for (int i=1 ; i<nz ; i++)
416 if (diff(i) > diff_xi)
417 diff_xi = diff(i) ;
418
419
420 if(diff_xi < seuil) {
421 cout <<
422 "========================================================================"
423 << endl ;
424 cout << "step = " << mer << " diff_xi = "<< diff_xi << endl ;
425 cout <<
426 "========================================================================"
427 << endl ;
428 mer = niter ;
429 }
430
431 xi = relax * xi + (1-relax) * xi_jm1 ;
432 for (int i=1; i<=3; i++) {
433 xi_jm1.set(i) = xi(i) ;
434 }
435
436 } // End of the main iteration
437
438 cout <<
439 "========================================================================"
440 << endl ;
441
442
443 // Compute h_uu in dirac gauge :
444 //-----------------------------
445
446 Sym_tensor guu_dirac (mp, CON, mp.get_bvect_cart()) ;
447
448 guu_dirac = g_uu.derive_lie(xi) ;
449 guu_dirac.dec_dzpuis(2) ;
450 guu_dirac = guu_dirac + g_uu ;
451
452
453 cout << "Relative difference between g_uu in dirac gauge and in isotropic gauge "
454 << endl ;
455 cout << " Comp 1 1 : " ;
456 for (int l=0; l<nz; l++) {
457 cout << diffrel(guu_dirac(1,1), guu_save(1,1))(l) << " " ;
458 }
459 cout << endl ;
460 cout << " Comp 2 2 : " ;
461 for (int l=0; l<nz; l++) {
462 cout << diffrel(guu_dirac(2,2), guu_save(2,2))(l) << " " ;
463 }
464 cout << endl ;
465 cout << " Comp 3 3 : " ;
466 for (int l=0; l<nz; l++) {
467 cout << diffrel(guu_dirac(3,3), guu_save(3,3))(l) << " " ;
468 }
469 cout << endl << endl ;
470
471
472
473 cout << "norme de g_uu en jauge de dirac :" << endl ;
474 for (int i=1; i<=3; i++)
475 for (int j=1; j<=i; j++) {
476 cout << " Comp. " << i << " " << j << " : " ;
477 for (int l=0; l<nz; l++){
478 cout << norme(guu_dirac(i,j)/(nr_tab[0]*nt*np))(l) << " " ;
479 }
480 cout << endl ;
481 }
482 cout << endl ;
483
484 // Check of the Dirac gauge
485 // ------------------------
486
487 for (int i=1; i<=3; i++)
488 for (int j=1; j<=i; j++)
489 guu_dirac.set(i,j).set_domain(0) = 1. ;
490
491 Metric g_dirac (guu_dirac) ;
492 Sym_tensor gtuu_dirac (mp, CON, mp.get_bvect_cart()) ;
493 gtuu_dirac = pow(g_dirac.determinant(), 1./3.) * guu_dirac ;
494 gtuu_dirac.std_spectral_base() ;
495
496 cout << "norme de gt_uu en jauge de dirac :" << endl ;
497 for (int i=1; i<=3; i++)
498 for (int j=1; j<=i; j++) {
499 cout << " Comp. " << i << " " << j << " : " ;
500 for (int l=0; l<nz; l++){
501 cout << norme(gtuu_dirac(i,j)/(nr_tab[0]*nt*np))(l) <<" " ;
502 }
503 cout << endl ;
504 }
505 cout << endl ;
506
507
508 Vector d_gtuu_dirac (gtuu_dirac.divergence(flat)) ;
509 d_gtuu_dirac.dec_dzpuis(2) ;
510
511 cout << "Is Dirac gauge really satisfied ?" << endl ;
512 cout << "Vector H^i" << endl ;
513 for (int i=1; i<=3; i++){
514 cout << " Comp. " << i << " : " << norme(d_gtuu_dirac(i)
515 /(nr_tab[0]*nt*np)) << endl ;
516 }
517
518 cout << "For comparaison value norme(h^11_dirac)/dist = " << endl
519 << norme(gtuu_dirac(1,1)-1)/(nr_tab[0]*nt*np) * 2 / hh ;
520
521 Vector hh_dirac (huu_save.divergence(flat)) ;
522 cout << "For comparaison H^i before computation = " << endl
523 << norme(hh_dirac(1))/(nr_tab[0]*nt*np)
524 << endl
525 << norme(hh_dirac(2))/(nr_tab[0]*nt*np)
526 << endl
527 << norme(hh_dirac(3))/(nr_tab[0]*nt*np)
528 << endl ;
529
530 // Another computation (test)
531 // --------------------------
532
533 Sym_tensor gtuu_dirac2 (mp, CON, mp.get_bvect_cart()) ;
534 Scalar psi4 = pow(a2, 2./3.) * pow(b2, 1./3.) ;
535 psi4.std_spectral_base() ;
536 gtuu_dirac2 = g_uu.derive_lie(xi) * psi4 + 0.666666666666666 *
537 xi.divergence(gamma) * gt_uu ; // xi = 0 donc... pas si top !
538 gtuu_dirac2.dec_dzpuis(2) ;
539 gtuu_dirac2 += gt_uu ;
540
541 d_gtuu_dirac = gtuu_dirac2.divergence(flat) ;
542 d_gtuu_dirac.dec_dzpuis(2) ;
543 cout << "second computation" << endl ;
544 cout << "Vector H^i" << endl ;
545 for (int i=1; i<=3; i++){
546 cout << " Comp. " << i << " : " << norme(d_gtuu_dirac(i)
547 /(nr_tab[0]*nt*np)) << endl ;
548 }
549
550 cout << "Relative difference between the two computation of h_uu dirac"
551 << endl ;
552 cout << " Comp 1 1 : " ;
553 for (int l=0; l<nz; l++) {
554 cout << diffrel(gtuu_dirac(1,1)-1, gtuu_dirac2(1,1)-1)(l) <<" " ;
555 }
556 cout << endl ;
557 cout << " Comp 2 2 : " ;
558 for (int l=0; l<nz; l++) {
559 cout << diffrel(gtuu_dirac(2,2)-1, gtuu_dirac2(2,2)-1)(l) <<" " ;
560 }
561 cout << endl ;
562 cout << " Comp 3 3 : " ;
563 for (int l=0; l<nz; l++) {
564 cout << diffrel(gtuu_dirac(3,3)-1, gtuu_dirac2(3,3)-1)(l) <<" " ;
565 }
566 cout << endl ;
567
568
569 delete [] nr_tab ;
570 delete [] nt_tab ;
571 delete [] np_tab ;
572 delete [] type_r ;
573 delete [] bornes ;
574
575 return EXIT_SUCCESS ;
576
577 }
578
579