Debian Codegraph @

Codes/Rot_star/rotstar_dirac_diff.C

raw
1 /*
2 * Main code for computing stationary axisymmetric differentially rotating
3 * stars in Dirac gauge and maximal slicing.
4 * (*** Under development ***)
5 *
6 */
7
8 /*
9 * Copyright (c) 2005 Motoyuki Saijo
10 *
11 * This file is part of LORENE.
12 *
13 * LORENE is free software; you can redistribute it and/or modify
14 * it under the terms of the GNU General Public License as published by
15 * the Free Software Foundation; either version 2 of the License, or
16 * (at your option) any later version.
17 *
18 * LORENE is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU General Public License for more details.
22 *
23 * You should have received a copy of the GNU General Public License
24 * along with LORENE; if not, write to the Free Software
25 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
26 *
27 */
28
29 char rotstar_dirac_C[] = "$Header: /cvsroot/Lorene/Codes/Rot_star/rotstar_dirac_diff.C,v 1.3 2014/10/13 08:53:59 j_novak Exp $" ;
30
31 /*
32 *
33 * $Header: /cvsroot/Lorene/Codes/Rot_star/rotstar_dirac_diff.C,v 1.3 2014/10/13 08:53:59 j_novak Exp $
34 *
35 */
36
37 // headers C
38 #include <cstdlib>
39
40 // headers Lorene
41 #include "star_rot_dirac_diff.h"
42 #include "eos.h"
43 #include "utilitaires.h"
44 #include "graphique.h"
45 #include "nbr_spx.h"
46 #include "unites.h"
47 #include "cmp.h"
48
49 // Function defining the rotation profile
50 double frotlin(double omega, const Lorene::Tbl& par) ;
51 double primfrotlin(double omega, const Lorene::Tbl& par) ;
52
53 namespace Lorene {
54 // Local prototype (for drawings only)
55 //Scalar raccord_c1(const Scalar& uu, int l1) ;
56 Cmp raccord_c1(const Cmp& uu, int l1) ;
57 }
58
59
60 //******************************************************************************
61
62 using namespace Lorene ;
63
64 int main(){
65
66 using namespace Unites ;
67
68 // Identification of all the subroutines called by the code :
69
70 system("ident rotstar_dirac_diff > identif.d") ;
71
72 //------------------------------------------------------------------
73 // Parameters of the computation
74 //------------------------------------------------------------------
75
76 char blabla[120] ;
77
78 int mer_max, mer_rot, mer_change_omega, mer_fix_omega,
79 delta_mer_kep, mer_mass, mermax_poisson, graph, nz, nzet, nzadapt,
80 nt, np, mer_triax, type_rot ;
81 double ent_c, freq_si, fact_omega, mbar_wanted, precis, freq_ini_si,
82 thres_adapt, aexp_mass, relax, relax_poisson, ampli_triax,
83 precis_adapt, rrot_si, arot ;
84
85 ifstream fich("parrotdiff.d") ;
86 if ( !(fich.is_open()) ) {
87 cerr << "Problem in openning the file parrotdiff.d !" << '\n' ;
88 abort() ;
89 }
90 fich.getline(blabla, 120) ;
91 fich.getline(blabla, 120) ;
92 fich >> ent_c ; fich.getline(blabla, 120) ;
93 fich >> freq_si ; fich.getline(blabla, 120) ;
94 fich >> type_rot ; fich.getline(blabla, 120) ;
95 if (type_rot == 0) {
96 fich >> rrot_si ; fich.getline(blabla, 120) ;
97 arot = 0 ;
98 }
99 else {
100 assert (type_rot == 1) ;
101 fich >> arot ; fich.getline(blabla, 120) ;
102 rrot_si = 0 ;
103 }
104 fich >> fact_omega ; fich.getline(blabla, 120) ;
105 fich >> mbar_wanted ; fich.getline(blabla, 120) ;
106 mbar_wanted *= msol ;
107 fich.getline(blabla, 120) ;
108 fich >> mer_max ; fich.getline(blabla, 120) ;
109 fich >> precis ; fich.getline(blabla, 120) ;
110 fich >> mer_rot ; fich.getline(blabla, 120) ;
111 fich >> freq_ini_si ; fich.getline(blabla, 120) ;
112 fich >> mer_change_omega ; fich.getline(blabla, 120) ;
113 fich >> mer_fix_omega ; fich.getline(blabla, 120) ;
114 fich >> delta_mer_kep ; fich.getline(blabla, 120) ;
115 fich >> thres_adapt ; fich.getline(blabla, 120) ;
116 fich >> mer_triax ; fich.getline(blabla, 120) ;
117 fich >> ampli_triax ; fich.getline(blabla, 120) ;
118 fich >> mer_mass ; fich.getline(blabla, 120) ;
119 fich >> aexp_mass ; fich.getline(blabla, 120) ;
120 fich >> relax ; fich.getline(blabla, 120) ;
121 fich >> mermax_poisson ; fich.getline(blabla, 120) ;
122 fich >> relax_poisson ; fich.getline(blabla, 120) ;
123 fich >> precis_adapt ; fich.getline(blabla, 120) ;
124 fich >> graph ; fich.getline(blabla, 120) ;
125 fich.getline(blabla, 120) ;
126 fich >> nz ; fich.getline(blabla, 120) ;
127 fich >> nzet; fich.getline(blabla, 120) ;
128 fich >> nzadapt; fich.getline(blabla, 120) ;
129 fich >> nt; fich.getline(blabla, 120) ;
130 fich >> np; fich.getline(blabla, 120) ;
131
132 int* nr = new int[nz];
133 int* nt_tab = new int[nz];
134 int* np_tab = new int[nz];
135 double* bornes = new double[nz+1];
136
137 fich.getline(blabla, 120);
138 for (int l=0; l<nz; l++) {
139 fich >> nr[l];
140 fich >> bornes[l]; fich.getline(blabla, 120) ;
141 np_tab[l] = np ;
142 nt_tab[l] = nt ;
143 }
144 bornes[nz] = __infinity ;
145
146 Tbl ent_limit(nzet) ;
147 ent_limit.set_etat_qcq() ;
148 ent_limit.set(nzet-1) = 0 ; // enthalpy at the stellar surface
149 for (int l=0; l<nzet-1; l++) {
150 fich >> ent_limit.set(l) ; fich.getline(blabla, 120) ;
151 }
152
153
154 fich.close();
155
156 // Particular cases
157 // ----------------
158
159 // Initial frequency = final frequency
160 if ( freq_ini_si < 0 ) {
161 freq_ini_si = freq_si ;
162 mer_change_omega = mer_rot ;
163 mer_fix_omega = mer_rot + 1 ;
164 }
165
166
167 //-----------------------------------------------------------------------
168 // Equation of state
169 //-----------------------------------------------------------------------
170
171 fich.open("par_eos.d") ;
172
173 Eos* peos = Eos::eos_from_file(fich) ;
174 Eos& eos = *peos ;
175
176 fich.close() ;
177
178 //-----------------------------------------------------------------------
179 // Construction of the multi-grid and the mapping
180 //-----------------------------------------------------------------------
181
182 // Rescale of bornes in the case where there more than 1 domain inside
183 // the star
184
185 for (int l=0; l<nzet-1; l++) {
186
187 bornes[l+1] = bornes[nzet] * sqrt(1 - ent_limit(l) / ent_c) ;
188
189 }
190
191 // Type of r sampling :
192 int* type_r = new int[nz];
193 type_r[0] = RARE ;
194 for (int l=1; l<nz-1; l++) {
195 type_r[l] = FIN ;
196 }
197 type_r[nz-1] = UNSURR ;
198
199 // Type of sampling in theta and phi :
200 int type_t = SYM ;
201 int type_p = SYM ;
202
203 Mg3d mg(nz, nr, type_r, nt_tab, type_t, np_tab, type_p) ;
204
205 Map_af mp(mg, bornes) ;
206
207 // Cleaning
208 // --------
209
210 delete [] nr ;
211 delete [] nt_tab ;
212 delete [] np_tab ;
213 delete [] type_r ;
214 delete [] bornes ;
215
216
217
218 cout << '\n'
219 << "==========================================================" << '\n'
220 << " Physical parameters " << '\n'
221 << "=========================================================="
222 << '\n';
223 cout << '\n';
224
225 cout << '\n'<< "Equation of state : "
226 << '\n'<< "================= " << '\n';
227 cout << eos << '\n';
228
229 cout << "Central enthalpy : " << ent_c << " c^2" << '\n';
230 cout << "Rotation frequency : " << freq_si << " Hz" << '\n';
231 if ( abs(mer_mass) < mer_max ) {
232 cout << "Required Baryon mass [M_sol] : "
233 << mbar_wanted / msol << '\n';
234 }
235
236 cout << '\n'
237 << "==========================================================" << '\n'
238 << " Computational parameters " << '\n'
239 << "=========================================================="
240 << '\n'<< '\n';
241
242 cout << "Maximum number of steps in the main iteration : "
243 << mer_max << '\n';
244 cout << "Relaxation factor in the main iteration : "
245 << relax << '\n';
246 cout << "Threshold on the enthalpy relative change for ending the computation : "
247 << precis << '\n';
248 cout << "Maximum number of steps in Map_et::poisson : "
249 << mermax_poisson << '\n';
250 cout << "Relaxation factor in Map_et::poisson : "
251 << relax_poisson << '\n';
252 cout << "Step from which the baryon mass is forced to converge : "
253 << mer_mass << '\n';
254 cout << "Exponent for the increase factor of the central enthalpy : "
255 << aexp_mass << '\n';
256 cout <<
257 "Threshold on |dH/dr|_eq / |dH/dr|_pole for the adaptation of the mapping"
258 << '\n'<< thres_adapt << '\n';
259
260
261 cout << '\n'<< "Multi-grid : "
262 << '\n'<< "==========" << '\n'<< mg << '\n';
263 cout << "Mapping : "
264 << '\n'<< "=======" << '\n'<< mp << '\n';
265
266 //-----------------------------------------------------------------------
267 // Parameters for the function defining the differential rotation
268 //-----------------------------------------------------------------------
269
270 double omega_c = 2 * M_PI * freq_si / f_unit ;
271 double omega_c_ini = 2 * M_PI * freq_ini_si / f_unit ;
272 double rrot = rrot_si * km ;
273
274 Tbl parfrot(3) ;
275 parfrot.set_etat_qcq() ;
276 parfrot.set(0) = omega_c_ini ;
277 parfrot.set(1) = rrot ;
278 parfrot.set(2) = arot ;
279
280 //-----------------------------------------------------------------------
281 // Construction of the star
282 //-----------------------------------------------------------------------
283
284 Star_rot_Dirac_diff star(mp, nzet, eos, frotlin, primfrotlin, parfrot) ;
285
286
287 //-----------------------------------------------------------------------
288 // Initialization of the enthalpy field
289 //-----------------------------------------------------------------------
290
291
292 const Coord& r = mp.r ;
293 double ray0 = mp.val_r(nzet-1, 1., 0., 0.) ;
294 Scalar ent0(mp) ;
295 ent0 = ent_c * ( 1 - r*r / (ray0*ray0) ) ;
296 ent0.annule_domain(nz-1) ;
297 ent0.std_spectral_base() ;
298 star.set_enthalpy(ent0) ;
299
300 // Initialization of (n,e,p) from H
301 star.equation_of_state() ;
302
303 // Initialization of (E,S,U,etc...) (quantities relative to the Eulerian obs)
304 star.hydro_euler() ;
305
306 cout << '\n'<< "Initial star : "
307 << '\n'<< "============ " << '\n';
308
309 cout << star.get_gamma() ;
310
311 cout << star << '\n';
312
313 //-----------------------------------------------------------------------
314 // Computation of the rotating equilibrium
315 //-----------------------------------------------------------------------
316
317 // double omega = 2 * M_PI * freq_si / f_unit ;
318 // double omega_ini = 2 * M_PI * freq_ini_si / f_unit ;
319
320 Itbl icontrol(6) ;
321 icontrol.set_etat_qcq() ;
322 icontrol.set(0) = mer_max ;
323 icontrol.set(1) = mer_rot ;
324 icontrol.set(2) = mer_change_omega ;
325 icontrol.set(3) = mer_fix_omega ;
326 icontrol.set(4) = mer_mass ;
327 icontrol.set(5) = delta_mer_kep ;
328
329 Tbl control(3) ;
330 control.set_etat_qcq() ;
331 control.set(0) = precis ;
332 control.set(1) = omega_c_ini ;
333 control.set(2) = relax ;
334 // control.set(3) = relax_poisson ;
335 // control.set(4) = thres_adapt ;
336 // control.set(5) = ampli_triax ;
337 // control.set(6) = precis_adapt ;
338
339 Tbl diff(8) ;
340
341 star.equilibrium(ent_c, omega_c, fact_omega, nzadapt, ent_limit, icontrol, control,
342 mbar_wanted, aexp_mass, diff) ;
343
344
345 cout << '\n'<< "Final star : "
346 << '\n'<< "========== " << '\n';
347
348 cout.precision(10) ;
349
350 cout << star << '\n';
351
352 double rho_c = star.get_ener().val_grid_point(0,0,0,0) ;
353
354 cout << "r_p/r_eq :" << star.aplat() << '\n';
355
356 cout << "Omega rho0^{-1/2} : " << star.get_omega() /
357 sqrt( ggrav * rho_c ) << '\n';
358
359 cout << "M rho0^{1/2} : " << star.mass_g() * pow(ggrav,1.5) *
360 sqrt( rho_c ) << '\n';
361
362 cout << "M_B rho0^{1/2} : " << star.mass_b() * pow(ggrav,1.5) *
363 sqrt( rho_c ) << '\n';
364
365 cout << "R_circ rho0^{1/2} : " << star.r_circ() *
366 sqrt( ggrav * rho_c ) << '\n';
367
368 cout << "J rho0 : " << star.angu_mom() * ggrav * ggrav * rho_c
369 << '\n';
370
371 cout << "GRV2: " << star.grv2() << '\n';
372 cout << "GRV3: " << star.grv3() << '\n';
373
374 double vit_triax = diff(6) ;
375
376 //-----------------------------------------------
377 // General features of the final configuration
378 // saved in a file
379 //-----------------------------------------------
380
381 ofstream fichfinal("calcul.d") ;
382 fichfinal.precision(10) ;
383
384
385 fichfinal << star.get_eos() << '\n';
386
387 fichfinal << '\n'<< "Total CPU time : " << '\n';
388 fichfinal << "Memory size : " << '\n'<< '\n';
389
390 fichfinal << '\n'<< '\n';
391 fichfinal << "Grid : " << '\n';
392 fichfinal << "------ " << '\n';
393 fichfinal << *(star.get_mp().get_mg()) << '\n';
394 fichfinal << '\n'<< "Physical characteristics : " << '\n';
395 fichfinal << "-------------------------" << '\n';
396 fichfinal << star << '\n';
397 fichfinal << "Growing rate of triaxial perturbation: " << vit_triax
398 << '\n';
399
400 fichfinal << '\n'<<
401 "==================================================================="
402 << '\n';
403 fichfinal << "Diff_ent : " << diff(0) << '\n';
404 fichfinal << "Relative error on the virial theorem GRV2 : "
405 << star.grv2() << '\n';
406 fichfinal << "Relative error on the virial theorem GRV3 : "
407 << star.grv3() << '\n';
408
409 fichfinal << '\n'<<
410 "================================================================" << '\n';
411 fichfinal <<
412 " PARAMETERS USED FOR THE COMPUTATION (file parrotdiff.d) : " << '\n';
413 fichfinal <<
414 "================================================================" << '\n';
415 fichfinal.close() ;
416 system("cat parrotdiff.d >> calcul.d") ;
417
418 fichfinal.open("calcul.d", ios::app) ;
419 fichfinal << '\n'<<
420 "================================================================" << '\n';
421 fichfinal <<
422 " EOS PARAMETERS (file par_eos.d) : " << '\n';
423 fichfinal <<
424 "================================================================" << '\n';
425 fichfinal.close() ;
426 system("cat par_eos.d >> calcul.d") ;
427
428 // Identification du code et de ses sous-routines (no. de version RCS) :
429 fichfinal.open("calcul.d", ios::app) ;
430 fichfinal << '\n'<<
431 "================================================================" << '\n';
432 fichfinal << " IDENTIFICATION OF THE CODE : " << '\n';
433 fichfinal <<
434 "================================================================" << '\n';
435 fichfinal.close() ;
436 system("ident rotstar_dirac_diff >> calcul.d") ;
437
438
439 // Saveguard of the whole configuration
440 // ------------------------------------
441
442 FILE* fresu = fopen("resu.d", "w") ;
443
444 star.get_mp().get_mg()->sauve(fresu) ; // writing of the grid
445 star.get_mp().sauve(fresu) ; // writing of the mapping
446 star.get_eos().sauve(fresu) ; // writing of the EOS
447 star.sauve(fresu) ; // writing of the star
448
449 fclose(fresu) ;
450
451
452
453 // Drawings
454 // --------
455
456 if (graph == 1) {
457
458 // for (int i=1; i<=3; i++)
459 // for (int j=i; j<=3; j++) {
460 // des_profile(star.get_hh()(i,j), 0., 3*rr, 1, 1) ;
461 // }
462
463 // Cmp defining the surface of the star (via the enthalpy field)
464 Cmp surf(star.get_ent()) ;
465 Cmp surf_ext(mp) ;
466 surf_ext = - 0.2 * surf(0, 0, 0, 0) ;
467 surf_ext.annule(0, star.get_nzet()-1) ;
468 surf.annule(star.get_nzet(), mg.get_nzone()-1) ;
469 surf = surf + surf_ext ;
470 surf = raccord_c1(surf, star.get_nzet()) ;
471
472 int nzdes = star.get_nzet() ;
473
474 des_coupe_y(star.get_ent(), 0., nzdes, "Enthalpy", &surf) ;
475
476 Cmp tmpdes = star.get_omega_field() / (2*M_PI) * f_unit ;
477 des_profile(tmpdes, 0., star.ray_eq(),
478 M_PI/2., 0., "\\gW/2\\gp [Hz]",
479 "Angular velocity in equatorial plane") ;
480
481 des_coupe_y(star.get_omega_field(), 0., nzdes, "\\gW", &surf) ;
482
483 des_coupe_y(star.get_logn(), 0., nzdes, "Gravitational potential \\gn", &surf) ;
484 des_coupe_y(star.get_beta()(3), 0., nzdes, "Azimuthal shift \\gb\\u\\gf",
485 &surf) ;
486 des_coupe_y(star.get_lnq(), 0., nzdes, "Potential ln(Q)", &surf) ;
487
488 des_coupe_y(star.get_hh()(1,1), 0., nzdes, "Metric potential h\\urr", &surf) ;
489
490 }
491
492
493 // Cleaning
494 // --------
495
496 delete peos ;
497
498 exit(EXIT_SUCCESS) ;
499
500 return EXIT_SUCCESS ;
501
502 }
503
504 //------------------------------//
505 // Function F(Omega) //
506 //------------------------------//
507
508 double frotlin(double omega, const Tbl& par){
509
510 double omega_c = par(0) ;
511 double rrot = par(1) ;
512
513 return rrot*rrot* (omega_c - omega) ;
514
515 }
516
517 //------------------------------//
518 // Primitive of F(Omega) //
519 //------------------------------//
520
521 double primfrotlin(double omega, const Tbl& par){
522
523 double omega_c = par(0) ;
524 double rrot = par(1) ;
525
526 return - 0.5 * rrot*rrot* (omega_c - omega)*(omega_c - omega) ;
527
528 }