Debian Codegraph @

Codes/Rot_star/rotstar_dirac.C

raw
1 /*
2 * Main code for computing stationary axisymmetric rotating stars in Dirac
3 * gauge and maximal slicing.
4 *
5 */
6
7 /*
8 * Copyright (c) 2005 Lap-Ming Lin & Jerome Novak
9 *
10 * This file is part of LORENE.
11 *
12 * LORENE is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation; either version 2 of the License, or
15 * (at your option) any later version.
16 *
17 * LORENE is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
21 *
22 * You should have received a copy of the GNU General Public License
23 * along with LORENE; if not, write to the Free Software
24 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
25 *
26 */
27
28 char rotstar_dirac_C[] = "$Header: /cvsroot/Lorene/Codes/Rot_star/rotstar_dirac.C,v 1.11 2015/01/27 14:22:39 j_novak Exp $" ;
29
30 /*
31 * $Id: rotstar_dirac.C,v 1.11 2015/01/27 14:22:39 j_novak Exp $
32 * $Log: rotstar_dirac.C,v $
33 * Revision 1.11 2015/01/27 14:22:39 j_novak
34 * New methods in Eos_tabul to correct for EoS themro consistency (optional).
35 *
36 * Revision 1.10 2014/10/13 08:53:59 j_novak
37 * Lorene classes and functions now belong to the namespace Lorene.
38 *
39 * Revision 1.9 2014/05/09 14:44:25 j_novak
40 * Tests are now done for the opening of parameter files.
41 *
42 * Revision 1.8 2012/05/10 09:05:30 j_novak
43 * New code examrot_dirac for reading the results of
44 * rotstar_dirac. Simplification of the parrot.d parameter file for
45 * rotstar_dirac.
46 *
47 * Revision 1.7 2009/10/26 10:42:30 j_novak
48 * Changed dzpuis handling in final test.
49 *
50 * Revision 1.6 2008/08/22 06:34:13 j_novak
51 * Now displaying \hat{A}^{ij} and \hat{A}^{ij}_{TT} (see paper by Cordero,
52 * Cerda, Dimmelmeier et al.).
53 *
54 * Revision 1.5 2008/02/25 10:40:54 j_novak
55 * Added the flag mer_hij to control the step from which the equation for h^{ij}
56 * is being solved.
57 *
58 * Revision 1.4 2007/11/06 16:24:00 j_novak
59 * Added the flag spectral_filter giving the order of possible spectral filtering
60 * of the hydro sources of metric equations (some members *_euler). The filtering
61 * is done in strot_dirac_hydro, if this flag is non-zero.
62 *
63 * Revision 1.3 2005/03/25 13:53:34 j_novak
64 * Added drawings of various fields.
65 *
66 * Revision 1.2 2005/03/10 09:38:35 j_novak
67 * *** empty log message ***
68 *
69 * Revision 1.1 2005/01/31 09:10:06 j_novak
70 * Main code for rotating stars in Dirac gauge.
71 *
72 *
73 * $Header: /cvsroot/Lorene/Codes/Rot_star/rotstar_dirac.C,v 1.11 2015/01/27 14:22:39 j_novak Exp $
74 *
75 */
76
77 // headers C
78 #include <cstdlib>
79
80 // headers Lorene
81 #include "star_rot_dirac.h"
82 #include "cmp.h"
83 #include "eos.h"
84 #include "graphique.h"
85 #include "nbr_spx.h"
86 #include "unites.h"
87
88 namespace Lorene {
89
90 // Local prototype (for drawings only)
91 Cmp raccord_c1(const Cmp& uu, int l1) ;
92
93 }
94
95 //******************************************************************************
96
97 using namespace Lorene ;
98
99 int main(){
100
101 using namespace Unites ;
102
103 //------------------------------------------------------------------
104 // Parameters of the computation
105 //------------------------------------------------------------------
106
107 char blabla[120] ;
108
109 int mer_max, mer_rot, mer_change_omega, mer_fix_omega,
110 delta_mer_kep, mer_mass, graph, nz, nzet, nzadapt,
111 nt, np, filter_order, mer_hij ;
112 double ent_c, freq_si, fact_omega, mbar_wanted, precis, freq_ini_si,
113 aexp_mass, relax ;
114
115 ifstream fich("parrot.d") ;
116 if ( !fich.good() ) {
117 cerr << "Problem in opening the file parrot.d ! " << endl ;
118 abort() ;
119 }
120 fich.getline(blabla, 120) ; fich.getline(blabla, 120) ;
121 fich >> ent_c ; fich.getline(blabla, 120) ;
122 fich >> freq_si ; fich.getline(blabla, 120) ;
123 fich >> fact_omega ; fich.getline(blabla, 120) ;
124 fich >> mbar_wanted ; fich.getline(blabla, 120) ;
125 mbar_wanted *= msol ;
126 fich.getline(blabla, 120) ;
127 fich >> mer_max ; fich.getline(blabla, 120) ;
128 fich >> precis ; fich.getline(blabla, 120) ;
129 fich >> mer_rot ; fich.getline(blabla, 120) ;
130 fich >> freq_ini_si ; fich.getline(blabla, 120) ;
131 fich >> mer_change_omega ; fich.getline(blabla, 120) ;
132 fich >> mer_fix_omega ; fich.getline(blabla, 200) ;
133 fich >> delta_mer_kep ; fich.getline(blabla, 120) ;
134 fich >> mer_mass ; fich.getline(blabla, 120) ;
135 fich >> aexp_mass ; fich.getline(blabla, 120) ;
136 fich >> relax ; fich.getline(blabla, 120) ;
137 fich >> graph ; fich.getline(blabla, 120) ;
138 fich.getline(blabla, 120) ;
139 fich >> nz ; fich.getline(blabla, 120) ;
140 fich >> nzet; fich.getline(blabla, 120) ;
141 fich >> nzadapt; fich.getline(blabla, 120) ;
142 fich >> nt; fich.getline(blabla, 120) ;
143 fich >> np; fich.getline(blabla, 120) ;
144
145 int* nr = new int[nz];
146 int* nt_tab = new int[nz];
147 int* np_tab = new int[nz];
148 double* bornes = new double[nz+1];
149
150 fich.getline(blabla, 120);
151 for (int l=0; l<nz; l++) {
152 fich >> nr[l];
153 fich >> bornes[l]; fich.getline(blabla, 120) ;
154 np_tab[l] = np ;
155 nt_tab[l] = nt ;
156 }
157 bornes[nz] = __infinity ;
158
159 Tbl ent_limit(nzet) ;
160 ent_limit.set_etat_qcq() ;
161 ent_limit.set(nzet-1) = 0 ; // enthalpy at the stellar surface
162 for (int l=0; l<nzet-1; l++) {
163 fich >> ent_limit.set(l) ; fich.getline(blabla, 120) ;
164 }
165 fich >> filter_order ; fich.getline(blabla, 120) ;
166 fich >> mer_hij ;fich.getline(blabla, 120) ;
167
168 fich.close();
169
170 // Particular cases
171 // ----------------
172
173 // Initial frequency = final frequency
174 if ( freq_ini_si < 0 ) {
175 freq_ini_si = freq_si ;
176 mer_change_omega = mer_rot ;
177 mer_fix_omega = mer_rot + 1 ;
178 }
179
180
181 //-----------------------------------------------------------------------
182 // Equation of state
183 //-----------------------------------------------------------------------
184
185 fich.open("par_eos.d") ;
186 if ( !fich.good() ) {
187 cerr << "Problem in opening the file par_eos.d ! " << endl ;
188 abort() ;
189 }
190 Eos* peos = Eos::eos_from_file(fich) ;
191 Eos& eos = *peos ;
192
193 fich.close() ;
194
195 //-----------------------------------------------------------------------
196 // Construction of the multi-grid and the mapping
197 //-----------------------------------------------------------------------
198
199 // Rescale of bornes in the case where there more than 1 domain inside
200 // the star
201
202 for (int l=0; l<nzet-1; l++) {
203
204 bornes[l+1] = bornes[nzet] * sqrt(1 - ent_limit(l) / ent_c) ;
205
206 }
207
208 // Type of r sampling :
209 int* type_r = new int[nz];
210 type_r[0] = RARE ;
211 for (int l=1; l<nz-1; l++) {
212 type_r[l] = FIN ;
213 }
214 type_r[nz-1] = UNSURR ;
215
216 // Type of sampling in theta and phi :
217 int type_t = SYM ;
218 int type_p = SYM ;
219
220 Mg3d mg(nz, nr, type_r, nt_tab, type_t, np_tab, type_p) ;
221
222 Map_af mp(mg, bornes) ;
223
224 // Cleaning
225 // --------
226
227 delete [] nr ;
228 delete [] nt_tab ;
229 delete [] np_tab ;
230 delete [] type_r ;
231 delete [] bornes ;
232
233
234
235 cout << endl
236 << "==========================================================" << endl
237 << " Physical parameters " << endl
238 << "=========================================================="
239 << endl ;
240 cout << endl ;
241
242 cout << endl << "Equation of state : "
243 << endl << "================= " << endl ;
244 cout << eos << endl ;
245
246 cout << "Central enthalpy : " << ent_c << " c^2" << endl ;
247 cout << "Rotation frequency : " << freq_si << " Hz" << endl ;
248 if ( abs(mer_mass) < mer_max ) {
249 cout << "Required Baryon mass [M_sol] : "
250 << mbar_wanted / msol << endl ;
251 }
252
253 cout << endl
254 << "==========================================================" << endl
255 << " Computational parameters " << endl
256 << "=========================================================="
257 << endl << endl ;
258
259 cout << "Maximum number of steps in the main iteration : "
260 << mer_max << endl ;
261 cout << "Relaxation factor in the main iteration : "
262 << relax << endl ;
263 cout << "Threshold on the enthalpy relative change for ending the computation : "
264 << precis << endl ;
265 cout << "Step from which the baryon mass is forced to converge : "
266 << mer_mass << endl ;
267 cout << "Exponent for the increase factor of the central enthalpy : "
268 << aexp_mass << endl ;
269
270 cout << endl << "Multi-grid : "
271 << endl << "==========" << endl << mg << endl ;
272 cout << "Mapping : "
273 << endl << "=======" << endl << mp << endl ;
274
275
276 //-----------------------------------------------------------------------
277 // Construction of the star
278 //-----------------------------------------------------------------------
279
280 Star_rot_Dirac star(mp, nzet, eos, filter_order) ;
281
282
283 //-----------------------------------------------------------------------
284 // Initialization of the enthalpy field
285 //-----------------------------------------------------------------------
286
287
288 const Coord& r = mp.r ;
289 double ray0 = mp.val_r(nzet-1, 1., 0., 0.) ;
290 Scalar ent0(mp) ;
291 ent0 = ent_c * ( 1 - r*r / (ray0*ray0) ) ;
292 ent0.annule_domain(nz-1) ;
293 ent0.std_spectral_base() ;
294 star.set_enthalpy(ent0) ;
295
296 // Initialization of (n,e,p) from H
297 star.equation_of_state() ;
298
299 // Initialization of (E,S,U,etc...) (quantities relative to the Eulerian obs)
300 star.hydro_euler() ;
301
302 cout << endl << "Initial star : "
303 << endl << "============ " << endl ;
304
305 cout << star.get_gamma() ;
306
307 cout << star << endl ;
308
309 //-----------------------------------------------------------------------
310 // Computation of the rotating equilibrium
311 //-----------------------------------------------------------------------
312
313 double omega = 2 * M_PI * freq_si / f_unit ;
314 double omega_ini = 2 * M_PI * freq_ini_si / f_unit ;
315
316 Itbl icontrol(7) ;
317 icontrol.set_etat_qcq() ;
318 icontrol.set(0) = mer_max ;
319 icontrol.set(1) = mer_rot ;
320 icontrol.set(2) = mer_change_omega ;
321 icontrol.set(3) = mer_fix_omega ;
322 icontrol.set(4) = mer_mass ;
323 icontrol.set(5) = delta_mer_kep ;
324 icontrol.set(6) = mer_hij ;
325
326 Tbl control(3) ;
327 control.set_etat_qcq() ;
328 control.set(0) = precis ;
329 control.set(1) = omega_ini ;
330 control.set(2) = relax ;
331
332 Tbl diff(8) ;
333
334 star.equilibrium(ent_c, omega, fact_omega, nzadapt, ent_limit, icontrol, control,
335 mbar_wanted, aexp_mass, diff) ;
336
337
338 cout << endl << "Final star : "
339 << endl << "========== " << endl ;
340
341 cout.precision(10) ;
342 cout << star << endl ;
343
344 double rho_c = star.get_ener().val_grid_point(0,0,0,0) ;
345
346 cout << "r_p/r_eq :" << star.aplat() << endl ;
347 cout << "Omega rho0^{-1/2} : " << star.get_omega() /
348 sqrt( ggrav * rho_c ) << endl ;
349
350 cout << "M rho0^{1/2} : " << star.mass_g() * pow(ggrav,1.5) *
351 sqrt( rho_c ) << endl ;
352
353 cout << "M_B rho0^{1/2} : " << star.mass_b() * pow(ggrav,1.5) *
354 sqrt( rho_c ) << endl ;
355
356 cout << "R_circ rho0^{1/2} : " << star.r_circ() *
357 sqrt( ggrav * rho_c ) << endl ;
358
359 cout << "J rho0 : " << star.angu_mom() * ggrav * ggrav * rho_c << endl ;
360
361 cout << "GRV2: " << star.grv2() << endl ;
362 cout << "GRV3: " << star.grv3() << endl ;
363
364 double vit_triax = diff(6) ;
365
366 //-----------------------------------------------
367 // General features of the final configuration
368 // saved in a file
369 //-----------------------------------------------
370
371 ofstream fichfinal("calcul.d") ;
372 fichfinal.precision(10) ;
373
374
375 fichfinal << star.get_eos() << endl ;
376
377 fichfinal << endl << "Total CPU time : " << endl ;
378 fichfinal << "Memory size : " << endl << endl ;
379
380 fichfinal << endl << endl ;
381 fichfinal << "Grid : " << endl ;
382 fichfinal << "------ " << endl ;
383 fichfinal << *(star.get_mp().get_mg()) << endl ;
384 fichfinal << endl << "Physical characteristics : " << endl ;
385 fichfinal << "-------------------------" << endl ;
386 fichfinal << star << endl ;
387 fichfinal << "Growing rate of triaxial perturbation: " << vit_triax
388 << endl ;
389
390 fichfinal << endl <<
391 "==================================================================="
392 << endl ;
393
394 fichfinal << endl <<
395 "================================================================" << endl ;
396 fichfinal <<
397 " PARAMETERS USED FOR THE COMPUTATION (file parrot.d) : " << endl ;
398 fichfinal <<
399 "================================================================" << endl ;
400 fichfinal.close() ;
401 int ret = system("cat parrot.d >> calcul.d") ;
402
403 fichfinal.open("calcul.d", ios::app) ;
404 fichfinal << endl <<
405 "================================================================" << endl ;
406 fichfinal <<
407 " EOS PARAMETERS (file par_eos.d) : " << endl ;
408 fichfinal <<
409 "================================================================" << endl ;
410 fichfinal.close() ;
411 ret = system("cat par_eos.d >> calcul.d") ;
412
413 if (ret == -1) cout << "Warning: problems in identification of the parameters!"
414 << endl ;
415
416 // Saveguard of the whole configuration
417 // ------------------------------------
418
419 FILE* fresu = fopen("resu.d", "w") ;
420
421 star.get_mp().get_mg()->sauve(fresu) ; // writing of the grid
422 star.get_mp().sauve(fresu) ; // writing of the mapping
423 star.get_eos().sauve(fresu) ; // writing of the EOS
424 star.sauve(fresu) ; // writing of the star
425
426 fclose(fresu) ;
427
428 Sym_tensor hat_aij = star.get_psi4()*star.get_psi2()*star.get_aa() ;
429 const Metric_flat& mets = mp.flat_met_spher() ;
430 cout << "Looking at \\hat{A}^{ij} and \\hat{A}^{ij}_{TT}: " << endl ;
431 Vector wwws = hat_aij.divergence(mets) ;
432 wwws.inc_dzpuis() ;
433 Vector www = wwws.poisson(1./3., 6) ;
434 Sym_tensor prueba = hat_aij - www.ope_killing_conf(mets) ;
435 Tbl maxa = maxabs(hat_aij, "Max \\hat{A}^ij") ;
436 Tbl maxb = maxabs(prueba, "Max. \\hat{A}^{ij}_{TT}: ") ;
437 Tbl maxh = maxabs(star.get_hh(), "Max. h^ij: ") ;
438 cout << "Max(A_TT)/Max(A): " << max(maxb)/max(maxa) <<endl ;
439 cout << "Max(h): " << max(maxh) <<endl ;
440
441
442 // Drawings
443 // --------
444
445 if (graph == 1) {
446
447 // for (int i=1; i<=3; i++)
448 // for (int j=i; j<=3; j++) {
449 // des_profile(star.get_hh()(i,j), 0., 3*rr, 1, 1) ;
450 // }
451
452 // Cmp defining the surface of the star (via the enthalpy field)
453 Cmp surf(star.get_ent()) ;
454 Cmp surf_ext(mp) ;
455 surf_ext = - 0.2 * surf(0, 0, 0, 0) ;
456 surf_ext.annule(0, star.get_nzet()-1) ;
457 surf.annule(star.get_nzet(), mg.get_nzone()-1) ;
458 surf = surf + surf_ext ;
459 surf = raccord_c1(surf, star.get_nzet()) ;
460
461 int nzdes = star.get_nzet() ;
462
463 des_coupe_y(star.get_ent(), 0., nzdes, "Enthalpy", &surf) ;
464
465 des_coupe_y(star.get_logn(), 0., nzdes, "Gravitational potential \\gn", &surf) ;
466 des_coupe_y(star.get_beta()(3), 0., nzdes, "Azimuthal shift \\gb\\u\\gf",
467 &surf) ;
468 des_coupe_y(star.get_lnq(), 0., nzdes, "Potential ln(Q)", &surf) ;
469
470 des_coupe_y(star.get_hh()(1,1), 0., nzdes, "Metric potential h\\urr", &surf) ;
471
472 }
473
474
475 // Cleaning
476 // --------
477
478 delete peos ;
479
480 exit(EXIT_SUCCESS) ;
481
482 return EXIT_SUCCESS ;
483
484 }