Debian Codegraph @

Codes/Rot_star/rotdiff.C

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