Debian Codegraph @

Codes/Rot_star/rotstar.C

raw
1 /*
2 * Main code for computing stationary axisymmetric rotating stars.
3 *
4 */
5
6 /*
7 * Copyright (c) 2000-2001 Eric Gourgoulhon
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 rotstar_C[] = "$Header: /cvsroot/Lorene/Codes/Rot_star/rotstar.C,v 1.7 2014/10/13 08:53:58 j_novak Exp $" ;
28
29 /*
30 * $Id: rotstar.C,v 1.7 2014/10/13 08:53:58 j_novak Exp $
31 * $Log: rotstar.C,v $
32 * Revision 1.7 2014/10/13 08:53:58 j_novak
33 * Lorene classes and functions now belong to the namespace Lorene.
34 *
35 * Revision 1.6 2014/10/06 15:09:45 j_novak
36 * Modified #include directives to use c++ syntax.
37 *
38 * Revision 1.5 2004/03/25 12:35:44 j_novak
39 * now using namespace Unites
40 *
41 * Revision 1.4 2003/05/14 20:06:09 e_gourgoulhon
42 * Suppressed the qualifier ios::nocreate in call to fstream::open
43 * (not supported by gcc 3.2).
44 *
45 * Revision 1.3 2003/01/09 11:07:51 j_novak
46 * headcpp.h is now compliant with C++ norm.
47 * The include files have been ordered, as well as the local_settings_linux
48 *
49 * Revision 1.2 2002/03/28 08:58:33 e_gourgoulhon
50 * New Makefile, to produce any of the man codes
51 * Updated README file
52 * Template parameter files for rotseq
53 *
54 * Revision 1.1.1.1 2001/11/20 15:19:31 e_gourgoulhon
55 * LORENE
56 *
57 * Revision 1.16 2001/10/10 13:58:04 eric
58 * Modif Joachim: traitement des legendes graphiques
59 *
60 * Revision 1.14 2000/11/29 13:47:41 eric
61 * Correction erreur initialisation du Tbl ent_limit.
62 *
63 * Revision 1.13 2000/11/24 13:28:57 eric
64 * Initialisation de bornes dans le cas nzet >= 2.
65 *
66 * Revision 1.12 2000/11/23 15:44:41 eric
67 * Version pour calcul avec 2 zones ou plus dans l'etoile
68 * --> Ajout de l'argument ent_limit a Etoile_rot::equilibrium
69 *
70 * Revision 1.11 2000/11/19 22:35:12 eric
71 * Sauvegarde configuration complete a la fin
72 * Ecriture parametres EOS dans calcul.d
73 *
74 * Revision 1.10 2000/11/10 15:22:57 eric
75 * Ajout des parametres de calcul delta_mer_kep et precis_adapt
76 * (lus dans le fichier parrot.d)
77 * Ajout de graphiques a la fin.
78 *
79 * Revision 1.9 2000/11/08 15:27:43 eric
80 * Ajout de cout.precision(10) avant l'affichage final.
81 *
82 * Revision 1.8 2000/10/25 15:43:27 eric
83 * Creation du fichier calcul.d a la fin.
84 *
85 * Revision 1.7 2000/10/23 13:50:17 dorota
86 * Sortie de vit_triax.
87 *
88 * Revision 1.6 2000/10/20 13:58:07 eric
89 * Ajout de l'argument nzadapt a Etoile_rot::equilibrium
90 * Divers dessins.
91 *
92 * Revision 1.5 2000/10/17 16:01:26 eric
93 * Ajout de la perturbation triaxiale.
94 *
95 * Revision 1.4 2000/10/16 09:25:01 eric
96 * *** empty log message ***
97 *
98 * Revision 1.3 2000/08/25 12:29:12 eric
99 * Dessins a la fin.
100 *
101 * Revision 1.2 2000/08/18 14:02:39 eric
102 * *** empty log message ***
103 *
104 * Revision 1.1 2000/07/21 16:33:09 eric
105 * Initial revision
106 *
107 *
108 * $Header: /cvsroot/Lorene/Codes/Rot_star/rotstar.C,v 1.7 2014/10/13 08:53:58 j_novak Exp $
109 *
110 */
111
112 // headers C
113 #include <cstdlib>
114 #include <cmath>
115 #include <cstring>
116
117 // headers Lorene
118 #include "etoile.h"
119 #include "eos.h"
120 #include "utilitaires.h"
121 #include "graphique.h"
122 #include "nbr_spx.h"
123 #include "unites.h"
124
125 namespace Lorene {
126 // Local prototype (for drawings only)
127 Cmp raccord_c1(const Cmp& uu, int l1) ;
128 }
129 //******************************************************************************
130
131 using namespace Lorene ;
132
133 int main(){
134
135 using namespace Unites ;
136
137 // Identification of all the subroutines called by the code :
138
139 system("ident rotstar > identif.d") ;
140
141 // For the display :
142 char display_bold[]="x[1m" ; display_bold[0] = 27 ;
143
144 //------------------------------------------------------------------
145 // Parameters of the computation
146 //------------------------------------------------------------------
147
148 char blabla[120] ;
149
150 int relat_i, mer_max, mer_rot, mer_change_omega, mer_fix_omega,
151 delta_mer_kep, mer_mass, mermax_poisson, graph, nz, nzet, nzadapt,
152 nt, np, mer_triax ;
153 double ent_c, freq_si, fact_omega, mbar_wanted, precis, freq_ini_si,
154 thres_adapt, aexp_mass, relax, relax_poisson, ampli_triax,
155 precis_adapt ;
156
157 ifstream fich("parrot.d") ;
158 fich.getline(blabla, 120) ;
159 fich >> relat_i ; fich.getline(blabla, 120) ;
160 bool relat = (relat_i == 1) ;
161 fich >> ent_c ; fich.getline(blabla, 120) ;
162 fich >> freq_si ; fich.getline(blabla, 120) ;
163 fich >> fact_omega ; fich.getline(blabla, 120) ;
164 fich >> mbar_wanted ; fich.getline(blabla, 120) ;
165 mbar_wanted *= msol ;
166 fich.getline(blabla, 120) ;
167 fich >> mer_max ; fich.getline(blabla, 120) ;
168 fich >> precis ; fich.getline(blabla, 120) ;
169 fich >> mer_rot ; fich.getline(blabla, 120) ;
170 fich >> freq_ini_si ; fich.getline(blabla, 120) ;
171 fich >> mer_change_omega ; fich.getline(blabla, 120) ;
172 fich >> mer_fix_omega ; fich.getline(blabla, 120) ;
173 fich >> delta_mer_kep ; fich.getline(blabla, 120) ;
174 fich >> thres_adapt ; fich.getline(blabla, 120) ;
175 fich >> mer_triax ; fich.getline(blabla, 120) ;
176 fich >> ampli_triax ; fich.getline(blabla, 120) ;
177 fich >> mer_mass ; fich.getline(blabla, 120) ;
178 fich >> aexp_mass ; fich.getline(blabla, 120) ;
179 fich >> relax ; fich.getline(blabla, 120) ;
180 fich >> mermax_poisson ; fich.getline(blabla, 120) ;
181 fich >> relax_poisson ; fich.getline(blabla, 120) ;
182 fich >> precis_adapt ; fich.getline(blabla, 120) ;
183 fich >> graph ; fich.getline(blabla, 120) ;
184 fich.getline(blabla, 120) ;
185 fich >> nz ; fich.getline(blabla, 120) ;
186 fich >> nzet; fich.getline(blabla, 120) ;
187 fich >> nzadapt; fich.getline(blabla, 120) ;
188 fich >> nt; fich.getline(blabla, 120) ;
189 fich >> np; fich.getline(blabla, 120) ;
190
191 int* nr = new int[nz];
192 int* nt_tab = new int[nz];
193 int* np_tab = new int[nz];
194 double* bornes = new double[nz+1];
195
196 fich.getline(blabla, 120);
197 for (int l=0; l<nz; l++) {
198 fich >> nr[l];
199 fich >> bornes[l]; fich.getline(blabla, 120) ;
200 np_tab[l] = np ;
201 nt_tab[l] = nt ;
202 }
203 bornes[nz] = __infinity ;
204
205 Tbl ent_limit(nzet) ;
206 ent_limit.set_etat_qcq() ;
207 ent_limit.set(nzet-1) = 0 ; // enthalpy at the stellar surface
208 for (int l=0; l<nzet-1; l++) {
209 fich >> ent_limit.set(l) ; fich.getline(blabla, 120) ;
210 }
211
212
213 fich.close();
214
215 // Particular cases
216 // ----------------
217
218 // Initial frequency = final frequency
219 if ( freq_ini_si < 0 ) {
220 freq_ini_si = freq_si ;
221 mer_change_omega = mer_rot ;
222 mer_fix_omega = mer_rot + 1 ;
223 }
224
225
226 //-----------------------------------------------------------------------
227 // Equation of state
228 //-----------------------------------------------------------------------
229
230 fich.open("par_eos.d") ;
231
232 Eos* peos = Eos::eos_from_file(fich) ;
233 Eos& eos = *peos ;
234
235 fich.close() ;
236
237
238 // Special treatment of crust - liquid core boundary in the case
239 // of Eos_strange
240 if (eos.identify() == 6) {
241 assert( nzet == 2 ) ;
242 const Eos_strange_cr* peos_cr = dynamic_cast<const Eos_strange_cr*>(peos) ;
243 if (peos_cr == 0x0) {
244 cout << "rotstar: problem : peos is not of type Eos_strange_cr !" << endl ;
245 abort() ;
246 }
247
248 ent_limit.set(0) = peos_cr->get_ent_nd() ; // enthalpy at core/crust transition
249
250 }
251
252 //-----------------------------------------------------------------------
253 // Construction of the multi-grid and the mapping
254 //-----------------------------------------------------------------------
255
256 // Rescale of bornes in the case where there more than 1 domain inside
257 // the star
258
259 for (int l=0; l<nzet-1; l++) {
260
261 bornes[l+1] = bornes[nzet] * sqrt(1 - ent_limit(l) / ent_c) ;
262
263 }
264
265 // Type of r sampling :
266 int* type_r = new int[nz];
267 type_r[0] = RARE ;
268 for (int l=1; l<nz-1; l++) {
269 type_r[l] = FIN ;
270 }
271 type_r[nz-1] = UNSURR ;
272
273 // Type of sampling in theta and phi :
274 int type_t = SYM ;
275 int type_p = SYM ;
276
277 Mg3d mg(nz, nr, type_r, nt_tab, type_t, np_tab, type_p) ;
278
279 Map_et mp(mg, bornes) ;
280
281 // Cleaning
282 // --------
283
284 delete [] nr ;
285 delete [] nt_tab ;
286 delete [] np_tab ;
287 delete [] type_r ;
288 delete [] bornes ;
289
290
291
292 cout << endl
293 << "==========================================================" << endl
294 << " Physical parameters " << endl
295 << "=========================================================="
296 << endl ;
297 cout << endl ;
298
299 cout << endl << "Equation of state : "
300 << endl << "================= " << endl ;
301 cout << eos << endl ;
302
303 cout << "Central enthalpy : " << ent_c << " c^2" << endl ;
304 cout << "Rotation frequency : " << freq_si << " Hz" << endl ;
305 if ( abs(mer_mass) < mer_max ) {
306 cout << "Required Baryon mass [M_sol] : "
307 << mbar_wanted / msol << endl ;
308 }
309
310 cout << endl
311 << "==========================================================" << endl
312 << " Computational parameters " << endl
313 << "=========================================================="
314 << endl << endl ;
315
316 cout << "Maximum number of steps in the main iteration : "
317 << mer_max << endl ;
318 cout << "Relaxation factor in the main iteration : "
319 << relax << endl ;
320 cout << "Threshold on the enthalpy relative change for ending the computation : "
321 << precis << endl ;
322 cout << "Maximum number of steps in Map_et::poisson : "
323 << mermax_poisson << endl ;
324 cout << "Relaxation factor in Map_et::poisson : "
325 << relax_poisson << endl ;
326 cout << "Step from which the baryon mass is forced to converge : "
327 << mer_mass << endl ;
328 cout << "Exponent for the increase factor of the central enthalpy : "
329 << aexp_mass << endl ;
330 cout <<
331 "Threshold on |dH/dr|_eq / |dH/dr|_pole for the adaptation of the mapping"
332 << endl << thres_adapt << endl ;
333
334
335 cout << endl << "Multi-grid : "
336 << endl << "==========" << endl << mg << endl ;
337 cout << "Mapping : "
338 << endl << "=======" << endl << mp << endl ;
339
340
341 //-----------------------------------------------------------------------
342 // Construction of the star
343 //-----------------------------------------------------------------------
344
345 Etoile_rot star(mp, nzet, relat, eos) ;
346
347 if ( star.is_relativistic() ) {
348 cout << "========================" << endl ;
349 cout << "Relativistic computation" << endl ;
350 cout << "========================" << endl ;
351 }
352 else {
353 cout << "=====================" << endl ;
354 cout << "Newtonian computation" << endl ;
355 cout << "=====================" << endl ;
356 }
357
358 //-----------------------------------------------------------------------
359 // Initialization of the enthalpy field
360 //-----------------------------------------------------------------------
361
362
363 const Coord& r = mp.r ;
364 double ray0 = mp.val_r(nzet-1, 1., 0., 0.) ;
365 Cmp ent0(mp) ;
366 ent0 = ent_c * ( 1 - r*r / (ray0*ray0) ) ;
367 ent0.annule(nz-1) ;
368 ent0.std_base_scal() ;
369 star.set_enthalpy(ent0) ;
370
371 // Initialization of (n,e,p) from H
372 star.equation_of_state() ;
373
374 // Initialization of (E,S,U,etc...) (quantities relative to the Eulerian obs)
375 star.hydro_euler() ;
376
377 cout << endl << "Initial star : "
378 << endl << "============ " << endl ;
379
380 cout << star << endl ;
381
382 //-----------------------------------------------------------------------
383 // Computation of the rotating equilibrium
384 //-----------------------------------------------------------------------
385
386 double omega = 2 * M_PI * freq_si / f_unit ;
387 double omega_ini = 2 * M_PI * freq_ini_si / f_unit ;
388
389 Itbl icontrol(8) ;
390 icontrol.set_etat_qcq() ;
391 icontrol.set(0) = mer_max ;
392 icontrol.set(1) = mer_rot ;
393 icontrol.set(2) = mer_change_omega ;
394 icontrol.set(3) = mer_fix_omega ;
395 icontrol.set(4) = mer_mass ;
396 icontrol.set(5) = mermax_poisson ;
397 icontrol.set(6) = mer_triax ;
398 icontrol.set(7) = delta_mer_kep ;
399
400 Tbl control(7) ;
401 control.set_etat_qcq() ;
402 control.set(0) = precis ;
403 control.set(1) = omega_ini ;
404 control.set(2) = relax ;
405 control.set(3) = relax_poisson ;
406 control.set(4) = thres_adapt ;
407 control.set(5) = ampli_triax ;
408 control.set(6) = precis_adapt ;
409
410 Tbl diff(8) ;
411
412 star.equilibrium(ent_c, omega, fact_omega, nzadapt, ent_limit, icontrol, control,
413 mbar_wanted, aexp_mass, diff) ;
414
415
416 cout << endl << "Final star : "
417 << endl << "========== " << endl ;
418
419 cout.precision(10) ;
420 cout << star << endl ;
421
422 double rho_c = star.get_ener()()(0,0,0,0) ;
423
424 cout << "r_p/r_eq :" << star.aplat() << endl ;
425 cout << "Omega rho0^{-1/2} : " << star.get_omega_c() /
426 sqrt( ggrav * rho_c ) << endl ;
427
428 cout << "M rho0^{1/2} : " << star.mass_g() * pow(ggrav,1.5) *
429 sqrt( rho_c ) << endl ;
430
431 cout << "M_B rho0^{1/2} : " << star.mass_b() * pow(ggrav,1.5) *
432 sqrt( rho_c ) << endl ;
433
434 cout << "R_circ rho0^{1/2} : " << star.r_circ() *
435 sqrt( ggrav * rho_c ) << endl ;
436
437 cout << "J rho0 : " << star.angu_mom() * ggrav * ggrav * rho_c << endl ;
438
439 cout << "Z_p : " << star.z_pole() << endl ;
440 cout << "Z_eq^f : " << star.z_eqf() << endl ;
441 cout << "Z_eq^b : " << star.z_eqb() << endl ;
442
443 cout << "GRV2: " << star.grv2() << endl ;
444 cout << "GRV3: " << star.grv3() << endl ;
445
446 double vit_triax = diff(7) ;
447
448 //-----------------------------------------------
449 // General features of the final configuration
450 // saved in a file
451 //-----------------------------------------------
452
453 ofstream fichfinal("calcul.d") ;
454 fichfinal.precision(10) ;
455
456 if ( star.is_relativistic() ) {
457 fichfinal << "Relativistic computation" << endl ;
458 }
459 else {
460 fichfinal << "Newtonian computation" << endl ;
461 }
462
463 fichfinal << star.get_eos() << endl ;
464
465 fichfinal << endl << "Total CPU time : " << endl ;
466 fichfinal << "Memory size : " << endl << endl ;
467
468 fichfinal << endl << endl ;
469 fichfinal << "Grid : " << endl ;
470 fichfinal << "------ " << endl ;
471 fichfinal << *(star.get_mp().get_mg()) << endl ;
472 fichfinal << endl << "Physical characteristics : " << endl ;
473 fichfinal << "-------------------------" << endl ;
474 fichfinal << star << endl ;
475 fichfinal << "Growing rate of triaxial perturbation: " << vit_triax
476 << endl ;
477
478 fichfinal << endl <<
479 "==================================================================="
480 << endl ;
481 fichfinal << "Diff_ent : " << diff(0) << endl ;
482 fichfinal << "Relative error on the virial theorem GRV2 : "
483 << star.grv2() << endl ;
484 fichfinal << "Relative error on the virial theorem GRV3 : "
485 << star.grv3() << endl ;
486
487 fichfinal << endl <<
488 "================================================================" << endl ;
489 fichfinal <<
490 " PARAMETERS USED FOR THE COMPUTATION (file parrot.d) : " << endl ;
491 fichfinal <<
492 "================================================================" << endl ;
493 fichfinal.close() ;
494 system("cat parrot.d >> calcul.d") ;
495
496 fichfinal.open("calcul.d", ios::app) ;
497 fichfinal << endl <<
498 "================================================================" << endl ;
499 fichfinal <<
500 " EOS PARAMETERS (file par_eos.d) : " << endl ;
501 fichfinal <<
502 "================================================================" << endl ;
503 fichfinal.close() ;
504 system("cat par_eos.d >> calcul.d") ;
505
506 // Identification du code et de ses sous-routines (no. de version RCS) :
507 fichfinal.open("calcul.d", ios::app) ;
508 fichfinal << endl <<
509 "================================================================" << endl ;
510 fichfinal << " IDENTIFICATION OF THE CODE : " << endl ;
511 fichfinal <<
512 "================================================================" << endl ;
513 fichfinal.close() ;
514 system("ident rotstar >> calcul.d") ;
515
516
517 // Saveguard of the whole configuration
518 // ------------------------------------
519
520 FILE* fresu = fopen("resu.d", "w") ;
521
522 star.get_mp().get_mg()->sauve(fresu) ; // writing of the grid
523 star.get_mp().sauve(fresu) ; // writing of the mapping
524 star.get_eos().sauve(fresu) ; // writing of the EOS
525 star.sauve(fresu) ; // writing of the star
526
527 fclose(fresu) ;
528
529
530
531 // Drawings
532 // --------
533
534 if (graph == 1) {
535
536 des_map_et(mp, 0) ;
537
538
539 char title[80] ;
540 char bslash[2] = {92, '\0'} ; // 92 is the ASCII code for backslash
541
542 // Cmp defining the surface of the star (via the enthalpy field)
543 Cmp surf = star.get_ent()() ;
544 Cmp surf_ext(mp) ;
545 surf_ext = - 0.2 * surf(0, 0, 0, 0) ;
546 surf_ext.annule(0, star.get_nzet()-1) ;
547 surf.annule(star.get_nzet(), mg.get_nzone()-1) ;
548 surf = surf + surf_ext ;
549 surf = raccord_c1(surf, star.get_nzet()) ;
550
551 int nzdes = star.get_nzet() ;
552
553 des_coupe_y(star.get_ent()(), 0., nzdes, "Enthalpy", &surf) ;
554
555 if (mer_triax < mer_max) {
556 des_coupe_z(star.get_ent()(), 0., nzdes, "Enthalpy (equatorial plane)",
557 &surf) ;
558 }
559
560 char partit[] = {92, 'g', 'n', '\0'} ;
561 strcpy(title, "Gravitational potential ") ;
562 strcat(title, partit) ;
563
564 des_coupe_y(star.get_logn()(), 0., nzdes, title, &surf) ;
565
566
567 strcpy(title, "Azimuthal shift N") ;
568 strcat(title, bslash) ;
569 strcat(title, "u") ;
570 strcat(title, bslash) ;
571 strcat(title, "gf") ;
572 des_coupe_y(star.get_nphi()(), 0., nzdes, title, &surf) ;
573
574 strcpy(title, "Metric potential ") ;
575 strcat(title, bslash) ;
576 strcat(title, "gz") ;
577 des_coupe_y(star.get_dzeta()(), 0., nzdes, title, &surf) ;
578
579 strcpy(title, "Metric potential (NB-1) r sin") ;
580 strcat(title, bslash) ;
581 strcat(title, "gh") ;
582 des_coupe_y(star.get_tggg()(), 0., nzdes, title, &surf) ;
583
584
585 char debtit[] = {'A', 92, 'u', '2', 92, 'd', ' ', 'K', 92, 'u', '\0'} ;
586 strcpy(title, debtit) ;
587 strcat(title, "ij") ;
588 strcat(title, bslash) ;
589 strcat(title, "d K") ;
590 strcat(title, bslash) ;
591 strcat(title, "dij") ;
592 strcat(title, bslash) ;
593 strcat(title, "u") ;
594
595 des_coupe_y(star.get_ak_car()(), 0., nzdes, title, &surf) ;
596
597 }
598
599
600 // Cleaning
601 // --------
602
603 delete peos ;
604
605 exit(EXIT_SUCCESS) ;
606
607 return EXIT_SUCCESS ;
608
609 }