Debian Codegraph @

Codes/GraVaStar/GraVaStar.C

raw
1 /*
2 * Main code for computing stationary axisymmetric gravastar.
3 *
4 */
5
6 /*
7 * Copyright (c) 2010 Frederic Vincent
8 *
9 * This file is part of LORENE.
10 *
11 * LORENE is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
15 *
16 * LORENE is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
20 *
21 * You should have received a copy of the GNU General Public License
22 * along with LORENE; if not, write to the Free Software
23 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24 *
25 */
26
27 char gravastar_C[] = "$Header: /cvsroot/Lorene/Codes/GraVaStar/GraVaStar.C,v 1.2 2014/10/13 08:53:56 j_novak Exp $" ;
28
29 /*
30 *
31 *
32 * "$Header: /cvsroot/Lorene/Codes/GraVaStar/GraVaStar.C,v 1.2 2014/10/13 08:53:56 j_novak Exp $"
33 *
34 */
35
36 // C headers
37 #include <cstdlib>
38 #include <cmath>
39 #include <cstring>
40
41 // Lorene headers
42 #include "gravastar.h"
43 #include "eos.h"
44 #include "utilitaires.h"
45 #include "graphique.h"
46 #include "nbr_spx.h"
47 #include "unites.h"
48
49 namespace Lorene {
50 // Local prototype (for drawings only)
51 Scalar raccord_c1(const Scalar& uu, int l1) ;
52 /* ***Comment: SERT A QUOI?? */
53 }
54 //******************************************************************************
55
56 using namespace Lorene ;
57
58 int main(){
59
60 using namespace Unites ;
61
62 // Identification of all the subroutines called by the code :
63
64 //system("ident nrotstar > identif.d") ;
65 /* ***Comment: SERT A QUOI?? */
66
67 // For the display :
68 char display_bold[]="x[1m" ; display_bold[0] = 27 ;
69
70 //------------------------------------------------------------------
71 // Parameters of the computation
72 //------------------------------------------------------------------
73
74 int mer_max, mer_rot, mer_change_omega, mer_fix_omega,
75 delta_mer_kep, mermax_poisson, graph, nz, nzet, nzadapt,
76 nt, np;
77 double freq_si, fact_omega, precis, freq_ini_si,
78 thres_adapt, relax, relax_poisson,
79 precis_adapt, rho_core ;
80
81 ifstream fpar("par_grav.d") ;
82 if ( !fpar.good() ) {
83 cerr << "Problem in opening the file par_grav.d ! " << endl ;
84 abort() ;
85 }
86
87
88 fpar.ignore(1000,'\n') ; // skip title
89 fpar >> freq_si ; fpar.ignore(1000,'\n') ;
90 fpar >> fact_omega ; fpar.ignore(1000,'\n') ;
91 fpar >> rho_core ; fpar.ignore(1000,'\n') ;
92 fpar.ignore(1000,'\n') ; // skip title
93 fpar >> mer_max ; fpar.ignore(1000,'\n') ;
94 fpar >> precis ; fpar.ignore(1000,'\n') ;
95 fpar >> mer_rot ; fpar.ignore(1000,'\n') ;
96 fpar >> freq_ini_si ; fpar.ignore(1000,'\n') ;
97 fpar >> mer_change_omega ; fpar.ignore(1000,'\n') ;
98 fpar >> mer_fix_omega ; fpar.ignore(1000,'\n') ;
99 fpar >> delta_mer_kep ; fpar.ignore(1000,'\n') ;
100 fpar >> thres_adapt ; fpar.ignore(1000,'\n') ;
101 fpar >> relax ; fpar.ignore(1000,'\n') ;
102 fpar >> mermax_poisson ; fpar.ignore(1000,'\n') ;
103 fpar >> relax_poisson ; fpar.ignore(1000,'\n') ;
104 fpar >> precis_adapt ; fpar.ignore(1000,'\n') ;
105 fpar >> graph ; fpar.ignore(1000,'\n') ;
106 fpar.ignore(1000,'\n') ; // skip title
107 fpar >> nz ; fpar.ignore(1000,'\n') ;
108 fpar >> nzet; fpar.ignore(1000,'\n') ;
109 fpar >> nzadapt; fpar.ignore(1000,'\n') ;
110 fpar >> nt; fpar.ignore(1000,'\n') ;
111 fpar >> np; fpar.ignore(1000,'\n') ;
112
113 int* nr = new int[nz];
114 int* nt_tab = new int[nz];
115 int* np_tab = new int[nz];
116 double* bornes = new double[nz+1];
117
118 fpar.ignore(1000,'\n'); // skip title
119 for (int l=0; l<nz; l++) {
120 fpar >> nr[l];
121 fpar >> bornes[l]; fpar.ignore(1000,'\n') ;
122 np_tab[l] = np ;
123 nt_tab[l] = nt ;
124 }
125 bornes[nz] = __infinity ;
126
127 fpar.ignore(1000,'\n'); // skip title
128 Tbl ent_limit(nzet) ;
129 ent_limit.set_etat_qcq() ;
130 ent_limit.set(nzet-1) = 0 ; // enthalpy at the gravastar surface = 0
131 for (int l=0; l<nzet-1; l++) {
132 fpar >> ent_limit.set(l) ; fpar.ignore(1000,'\n') ;
133 }
134
135 fpar.close();
136
137 // Particular cases
138 // ----------------
139
140 // Initial frequency = final frequency
141 if ( freq_ini_si < 0 ) {
142 freq_ini_si = freq_si ;
143 mer_change_omega = mer_rot ;
144 mer_fix_omega = mer_rot + 1 ;
145 }
146
147
148 //-----------------------------------------------------------------------
149 // Equation of state of the gravastar crust
150 //-----------------------------------------------------------------------
151
152 fpar.open("par_grav_eos.d") ;
153 if ( !fpar.good() ) {
154 cerr << "Problem in opening the file par_grav_eos.d ! " << endl ;
155 abort() ;
156 }
157
158 Eos* peos = Eos::eos_from_file(fpar) ;
159 Eos& eos = *peos ;
160
161 fpar.close() ;
162
163 //-----------------------------------------------------------------------
164 // Construction of the multi-grid and the mapping
165 //-----------------------------------------------------------------------
166
167 /* Remark:
168 1st domain inside gravastar = vacuum core from bornes[0] to bornes[1]
169 2nd domain = first domain inside the crust from bornes[1] to bornes[2]
170 ...
171 nth domain = last domain inside the crust from bornes[nzet-1] to bornes[nzet]
172 (n+1)th domain = first domain outside the gravastar
173 (n+2)th domain = last domain (compactified) outside the gravastar
174
175 If there are more than one domain inside the crust, there is a need to rescale bornes[2,...,nzet-1] inside the crust, in order to allow enthalpy(r) to be linear there from H(inner crust boundary) to H(outer crust boundry)=0
176 */
177
178
179
180 for (int l=1; l<nzet-1; l++) {
181
182 bornes[l+1] = bornes[nzet] + ent_limit(l)/ent_limit(0)*(bornes[1]-bornes[nzet]) ;
183
184 }
185
186
187 // Type of r sampling :
188 int* type_r = new int[nz];
189 type_r[0] = RARE ;
190 for (int l=1; l<nz-1; l++) {
191 type_r[l] = FIN ;
192 }
193 type_r[nz-1] = UNSURR ;
194
195 // Type of sampling in theta and phi :
196 int type_t = SYM ;
197 int type_p = SYM ;
198
199 Mg3d mg(nz, nr, type_r, nt_tab, type_t, np_tab, type_p) ;
200
201 Map_et mp(mg, bornes) ;
202
203 // Cleaning
204 // --------
205
206 delete [] nr ;
207 delete [] nt_tab ;
208 delete [] np_tab ;
209 delete [] type_r ;
210 delete [] bornes ;
211
212
213
214 cout << endl
215 << "==========================================================" << endl
216 << " Physical parameters " << endl
217 << "=========================================================="
218 << endl ;
219 cout << endl ;
220
221 cout << endl << "Equation of state : "
222 << endl << "================= " << endl ;
223 cout << eos << endl ;
224
225 cout << "Rotation frequency : " << freq_si << " Hz" << endl ;
226
227 cout << endl
228 << "==========================================================" << endl
229 << " Computational parameters " << endl
230 << "=========================================================="
231 << endl << endl ;
232
233 cout << "Maximum number of steps in the main iteration : "
234 << mer_max << endl ;
235 cout << "Relaxation factor in the main iteration : "
236 << relax << endl ;
237 cout << "Threshold on the enthalpy relative change for ending the computation : "
238 << precis << endl ;
239 cout << "Maximum number of steps in Map_et::poisson : "
240 << mermax_poisson << endl ;
241 cout << "Relaxation factor in Map_et::poisson : "
242 << relax_poisson << endl ;
243 cout <<
244 "Threshold on |dH/dr|_eq / |dH/dr|_pole for the adaptation of the mapping"
245 << endl << thres_adapt << endl ;
246
247
248 cout << endl << "Multi-grid : "
249 << endl << "==========" << endl << mg << endl ;
250 cout << "Mapping : "
251 << endl << "=======" << endl << mp << endl ;
252
253
254 //-----------------------------------------------------------------------
255 // Construction of the gravastar
256 //-----------------------------------------------------------------------
257
258 Gravastar gravastar(mp,nzet,eos,rho_core);
259
260 //-----------------------------------------------------------------------
261 // Initialization of the enthalpy field
262 //-----------------------------------------------------------------------
263
264
265 const Coord& r = mp.r ;
266 double ray1 = mp.val_r(0, 1., 0., 0.), ray2 = mp.val_r(nzet-1, 1., 0., 0.) ;
267 Scalar ent0(mp) ;
268 ent0 = ent_limit(0) * (r-ray2)/(ray1-ray2) ; //linear profile of enthropy inside the gravastar
269 for (int l=nzet;l<nz;l++) ent0.annule_domain(l) ; //sets enth to zero outside the gravastar
270 ent0.std_spectral_base() ;
271 gravastar.set_enthalpy(ent0) ;
272
273 // des_profile(ent0,0.,10.,0.,0.,"enthalpy0");
274
275 // Initialization of (n,e,p) from H
276 gravastar.equation_of_state() ;
277
278 // Initialization of (E,S,U,etc...) (quantities relative to the Eulerian obs)
279 gravastar.hydro_euler() ;
280
281 cout << endl << "Initial gravastar : "
282 << endl << "============ " << endl ;
283
284 cout << gravastar << endl ;
285
286 //-----------------------------------------------------------------------
287 // Computation of the rotating equilibrium
288 //-----------------------------------------------------------------------
289
290 double omega = 2 * M_PI * freq_si / f_unit ;
291 double omega_ini = 2 * M_PI * freq_ini_si / f_unit ;
292
293 Itbl icontrol(6) ;
294 icontrol.set_etat_qcq() ;
295 icontrol.set(0) = mer_max ;
296 icontrol.set(1) = mer_rot ;
297 icontrol.set(2) = mer_change_omega ;
298 icontrol.set(3) = mer_fix_omega ;
299 icontrol.set(4) = mermax_poisson ;
300 icontrol.set(5) = delta_mer_kep ;
301
302 Tbl control(6) ;
303 control.set_etat_qcq() ;
304 control.set(0) = precis ;
305 control.set(1) = omega_ini ;
306 control.set(2) = relax ;
307 control.set(3) = relax_poisson ;
308 control.set(4) = thres_adapt ;
309 control.set(5) = precis_adapt ;
310
311 Tbl diff(8) ;
312
313 gravastar.equilibrium(omega, fact_omega, nzadapt, ent_limit, icontrol, control,
314 diff) ;
315
316 cout << endl << "Final gravastar : "
317 << endl << "========== " << endl ;
318
319 cout.precision(10) ;
320 cout << gravastar << endl ;
321
322 double rho_c = gravastar.get_ener().val_grid_point(0,0,0,0) ;
323
324 cout << "r_p/r_eq :" << gravastar.aplat() << endl ;
325 cout << "Omega rho0^{-1/2} : " << gravastar.get_omega_c() /
326 sqrt( ggrav * rho_c ) << endl ;
327
328 /*cout << "M rho0^{1/2} : " << gravastar.mass_g() * pow(ggrav,1.5) *
329 sqrt( rho_c ) << endl ;
330
331 cout << "M_B rho0^{1/2} : " << gravastar.mass_b() * pow(ggrav,1.5) *
332 sqrt( rho_c ) << endl ;
333
334 cout << "R_circ rho0^{1/2} : " << gravastar.r_circ() *
335 sqrt( ggrav * rho_c ) << endl ;*/
336
337 cout << "J rho0 : " << gravastar.angu_mom() * ggrav * ggrav * rho_c << endl ;
338
339 cout << "Z_p : " << gravastar.z_pole() << endl ;
340 cout << "Z_eq^f : " << gravastar.z_eqf() << endl ;
341 cout << "Z_eq^b : " << gravastar.z_eqb() << endl ;
342
343 cout << "GRV2: " << gravastar.grv2() << endl ;
344 cout << "GRV3: " << gravastar.grv3() << endl ;
345
346 // double vit_triax = diff(7) ;
347
348 //-----------------------------------------------
349 // General features of the final configuration
350 // saved in a file
351 //-----------------------------------------------
352
353 ofstream fichfinal("result.txt") ;
354 fichfinal.precision(10) ;
355
356 /* //n'a plus de sens pour le gravastar
357 if ( star.is_relativistic() ) {
358 fichfinal << "Relativistic computation" << endl ;
359 }
360 else {
361 fichfinal << "Newtonian computation" << endl ;
362 }*/
363
364 fichfinal << gravastar.get_eos() << endl ;
365
366 fichfinal << endl << "Total CPU time : " << endl ;
367 fichfinal << "Memory size : " << endl << endl ;
368
369 fichfinal << endl << endl ;
370 fichfinal << "Grid : " << endl ;
371 fichfinal << "------ " << endl ;
372 fichfinal << *(gravastar.get_mp().get_mg()) << endl ;
373 fichfinal << endl << "Physical characteristics : " << endl ;
374 fichfinal << "-------------------------" << endl ;
375 fichfinal << gravastar << endl ;
376 // fichfinal << "Growing rate of triaxial perturbation: " << vit_triax
377 // << endl ;
378
379 fichfinal << endl <<
380 "==================================================================="
381 << endl ;
382 fichfinal << "Diff_ent : " << diff(0) << endl ;
383 fichfinal << "Relative error on the virial theorem GRV2 : "
384 << gravastar.grv2() << endl ;
385 fichfinal << "Relative error on the virial theorem GRV3 : "
386 << gravastar.grv3() << endl ;
387
388 fichfinal << endl <<
389 "================================================================" << endl ;
390 fichfinal <<
391 " PARAMETERS USED FOR THE COMPUTATION (file par_grav.d) : " << endl ;
392 fichfinal <<
393 "================================================================" << endl ;
394 fichfinal.close() ;
395 system("cat par_grav.d >> result.txt") ;
396
397 fichfinal.open("result.txt", ios::app) ;
398 fichfinal << endl <<
399 "================================================================" << endl ;
400 fichfinal <<
401 " EOS PARAMETERS (file par_grav_eos.d) : " << endl ;
402 fichfinal <<
403 "================================================================" << endl ;
404 fichfinal.close() ;
405 system("cat par_grav_eos.d >> result.txt") ;
406
407 // Identification du code et de ses sous-routines (no. de version RCS) :
408 fichfinal.open("result.txt", ios::app) ;
409 fichfinal << endl <<
410 "================================================================" << endl ;
411 fichfinal << " IDENTIFICATION OF THE CODE : " << endl ;
412 fichfinal <<
413 "================================================================" << endl ;
414 fichfinal.close() ;
415 // system("ident nrotstar >> result.txt") ;
416 /* ***Comment: SERT A QUOI?? */
417
418 // Saveguard of the whole configuration
419 // ------------------------------------
420
421 FILE* fresu = fopen("resu.d", "w") ;
422
423 gravastar.get_mp().get_mg()->sauve(fresu) ; // writing of the grid
424 gravastar.get_mp().sauve(fresu) ; // writing of the mapping
425 gravastar.get_eos().sauve(fresu) ; // writing of the EOS
426 gravastar.sauve(fresu) ; // writing of the gravastar
427
428 fclose(fresu) ;
429
430 // Drawings
431 // --------
432
433 ofstream fichdes("prof_n.d") ;
434 fichdes.precision(10) ;
435 fichdes << "# r [km] N(theta=0) N(theta=pi/2)" << endl ;
436 int npd = 300 ;
437 double r_max = 3 ;
438 double h = r_max/double(npd-1) ;
439 for (int i=0; i<npd; i++) {
440 double rr = h * i ;
441 fichdes << rr*10 << " "
442 << gravastar.get_nn().val_point(rr,0.,0.) << " "
443 << gravastar.get_nn().val_point(rr, M_PI/2.,0.) << endl ;
444 }
445 fichdes.close() ;
446
447 fichdes.open("prof_omega.d") ;
448 fichdes.precision(10) ;
449 fichdes << "# r [km] omega(theta=0) omega(theta=pi/2)" << endl ;
450 for (int i=0; i<npd; i++) {
451 double rr = h * i ;
452 fichdes << rr*10 << " "
453 << gravastar.get_nphi().val_point(rr,0.,0.) << " "
454 << gravastar.get_nphi().val_point(rr, M_PI/2.,0.) << endl ;
455 }
456 fichdes.close() ;
457
458 fichdes.open("prof_omega.d") ;
459 fichdes.precision(10) ;
460 fichdes << "# r [km] omega(theta=0)/Omega omega(theta=pi/2)/Omega" << endl ;
461 double omega_rot = gravastar.get_omega_c() ;
462 if (omega_rot == double(0)) omega_rot = 1 ;
463 for (int i=0; i<npd; i++) {
464 double rr = h * i ;
465 fichdes << rr*10 << " "
466 << gravastar.get_nphi().val_point(rr,0.,0.) / omega_rot << " "
467 << gravastar.get_nphi().val_point(rr, M_PI/2.,0.) / omega_rot << endl ;
468 }
469 fichdes.close() ;
470
471 fichdes.open("prof_a.d") ;
472 fichdes.precision(10) ;
473 fichdes << "# r [km] A(theta=0) A(theta=pi/2)" << endl ;
474 for (int i=0; i<npd; i++) {
475 double rr = h * i ;
476 fichdes << rr*10 << " "
477 << sqrt( gravastar.get_a_car().val_point(rr,0.,0.) ) << " "
478 << sqrt( gravastar.get_a_car().val_point(rr, M_PI/2.,0.) ) << endl ;
479 }
480 fichdes.close() ;
481
482 fichdes.open("prof_bma.d") ;
483 fichdes.precision(10) ;
484 fichdes << "# r [km] B-A(theta=0) B-A(theta=pi/2)" << endl ;
485 for (int i=0; i<npd; i++) {
486 double rr = h * i ;
487 fichdes << rr*10 << " "
488 << sqrt( gravastar.get_b_car().val_point(rr,0.,0.) )
489 - sqrt( gravastar.get_a_car().val_point(rr,0.,0.) ) << " "
490 << sqrt( gravastar.get_b_car().val_point(rr, M_PI/2.,0.) )
491 - sqrt( gravastar.get_a_car().val_point(rr, M_PI/2.,0.) ) << endl ;
492 }
493 fichdes.close() ;
494
495 fichdes.open("prof_ener.d") ;
496 fichdes.precision(10) ;
497 fichdes << "# r [km] ener(theta=0) ener(theta=pi/2)" << endl ;
498 for (int i=0; i<npd; i++) {
499 double rr = h * i ;
500 fichdes << rr*10 << " "
501 << gravastar.get_ener().val_point(rr,0.,0.) << " "
502 << gravastar.get_ener().val_point(rr, M_PI/2.,0.) << endl ;
503 }
504 fichdes.close() ;
505
506 fichdes.open("prof_h.d") ;
507 fichdes.precision(10) ;
508 fichdes << "# r [km] H(theta=0) H(theta=pi/2)" << endl ;
509 for (int i=0; i<npd; i++) {
510 double rr = h * i ;
511 fichdes << rr*10 << " "
512 << gravastar.get_ent().val_point(rr,0.,0.) << " "
513 << gravastar.get_ent().val_point(rr, M_PI/2.,0.) << endl ;
514 }
515 fichdes.close() ;
516
517 fichdes.open("prof_u.d") ;
518 fichdes.precision(10) ;
519 fichdes << "# r [km] U(theta=0)/c U(theta=pi/2)/c" << endl ;
520 for (int i=0; i<npd; i++) {
521 double rr = h * i ;
522 fichdes << rr*10 << " "
523 << gravastar.get_uuu().val_point(rr,0.,0.) << " "
524 << gravastar.get_uuu().val_point(rr, M_PI/2.,0.) << endl ;
525 }
526 fichdes.close() ;
527
528
529 if (graph == 1) {
530
531 char title[80] ;
532 char bslash[2] = {92, '\0'} ; // 92 is the ASCII code for backslash
533
534 // Scalar defining the surface of the gravastar (via the enthalpy field)
535 Scalar surf( gravastar.get_ent() );
536 Scalar surf_ext(mp) ;
537 surf_ext = - 0.2 * surf.val_grid_point(0, 0, 0, 0) ;
538 surf_ext.annule(0, gravastar.get_nzet()-1) ;
539 surf.annule(gravastar.get_nzet(), mg.get_nzone()-1) ;
540 surf = surf + surf_ext ;
541 surf = raccord_c1(surf, gravastar.get_nzet()) ;
542
543 int nzdes = gravastar.get_nzet() ;
544
545 des_coupe_y(gravastar.get_ent(), 0., nzdes, "Log-enthalpy", &surf) ;
546
547 cout << endl << "Plot of the coefficients of the cos(j theta) expansion of the function G(theta) defining the stellar surface:" << endl ;
548 des_map_et(mp, gravastar.get_nzet()-1) ;
549
550 des_coupe_y(gravastar.get_ener(), 0., nzdes, "Fluid Proper energy density", &surf) ;
551
552 /*if (mer_triax < mer_max) {
553 des_coupe_z(gravastar.get_ent(), 0., nzdes, "Log-enthalpy (equatorial plane)",
554 &surf) ;
555 }*/
556
557 char partit[] = {92, 'g', 'n', '\0'} ;
558 strcpy(title, "Gravitational potential ") ;
559 strcat(title, partit) ;
560
561 des_coupe_y(gravastar.get_logn(), 0., nzdes, title, &surf) ;
562
563
564 strcpy(title, "Azimuthal shift N") ;
565 strcat(title, bslash) ;
566 strcat(title, "u") ;
567 strcat(title, bslash) ;
568 strcat(title, "gf") ;
569 des_coupe_y(gravastar.get_nphi(), 0., nzdes, title, &surf) ;
570
571 strcpy(title, "Metric potential ") ;
572 strcat(title, bslash) ;
573 strcat(title, "gz") ;
574 des_coupe_y(gravastar.get_dzeta(), 0., nzdes, title, &surf) ;
575
576 strcpy(title, "Metric potential (NB-1) r sin") ;
577 strcat(title, bslash) ;
578 strcat(title, "gh") ;
579 des_coupe_y(gravastar.get_tggg(), 0., nzdes, title, &surf) ;
580
581 char debtit[] = {'A', 92, 'u', '2', 92, 'd', ' ', 'K', 92, 'u', '\0'} ;
582 strcpy(title, debtit) ;
583 strcat(title, "ij") ;
584 strcat(title, bslash) ;
585 strcat(title, "d K") ;
586 strcat(title, bslash) ;
587 strcat(title, "dij") ;
588 strcat(title, bslash) ;
589 strcat(title, "u") ;
590
591 des_coupe_y(gravastar.get_ak_car(), 0., nzdes, title, &surf) ;
592
593 }
594
595 /* ofstream seq("seq.d", ios::app) ;
596 seq << gravastar.get_ent().val_grid_point(0,0,0,0) << " " << gravastar.mass_g() / msol
597 << " " << qpig/(4.*M_PI) * gravastar.mass_g() / gravastar.r_circ() << endl ;
598
599 seq.close() ; */
600
601 // Cleaning
602 // --------
603
604 delete peos ;
605
606 exit(EXIT_SUCCESS) ;
607
608 return EXIT_SUCCESS ;
609
610 }