Debian Codegraph @

Codes/Binary_star/coal.C

raw
1 /*
2 * Computes the equilibrium configuration of a binary system.
3 *
4 */
5
6 /*
7 * Copyright (c) 2004 francois Limousin
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 coal_C[] = "$Header: /cvsroot/Lorene/Codes/Binary_star/coal.C,v 1.10 2014/10/13 08:53:55 j_novak Exp $" ;
28
29 /*
30 * $Id: coal.C,v 1.10 2014/10/13 08:53:55 j_novak Exp $
31 * $Log: coal.C,v $
32 * Revision 1.10 2014/10/13 08:53:55 j_novak
33 * Lorene classes and functions now belong to the namespace Lorene.
34 *
35 * Revision 1.9 2014/10/06 15:09:40 j_novak
36 * Modified #include directives to use c++ syntax.
37 *
38 * Revision 1.8 2006/05/31 09:26:33 f_limousin
39 * Modif. of the size of the different domains
40 *
41 * Revision 1.7 2006/04/11 14:26:30 f_limousin
42 * New version of the code : improvement of the computation of some
43 * critical sources, estimation of the dirac gauge, helical symmetry...
44 *
45 * Revision 1.6 2005/11/08 20:19:32 f_limousin
46 * Add a call to Binary::dirac_gauge().
47 *
48 * Revision 1.5 2005/09/13 19:47:28 f_limousin
49 * Reintroduction of the resolution of the equations in cartesian coordinates.
50 *
51 * Revision 1.4 2004/09/16 12:14:23 f_limousin
52 * *** empty log message ***
53 *
54 * Revision 1.2 2004/01/22 10:15:20 f_limousin
55 * First version
56 *
57 * $Header: /cvsroot/Lorene/Codes/Binary_star/coal.C,v 1.10 2014/10/13 08:53:55 j_novak Exp $
58 *
59 */
60
61 // headers C
62 #include <cstdlib>
63 #include <cmath>
64 #include <ctime>
65
66 // headers Lorene
67 #include "unites.h"
68 #include "cmp.h"
69 #include "tenseur.h"
70 #include "binary.h"
71 #include "eos.h"
72 #include "utilitaires.h"
73 #include "graphique.h"
74 #include "param.h"
75 #include "nbr_spx.h"
76
77
78 namespace Lorene {
79 // Local prototype
80 Cmp raccord_c1(const Cmp& uu, int l1) ;
81 }
82 using namespace Lorene ;
83
84 int main(){
85
86 // Identification of all the subroutines called by the code :
87
88 system("ident coal > identif.d") ;
89
90 // For the display :
91 char display_bold[]="x[1m" ; display_bold[0] = 27 ;
92 char display_normal[] = "x[0m" ; display_normal[0] = 27 ;
93
94 using namespace Unites ;
95
96 //------------------------------------------------------------------
97 // Parameters of the computation
98 //------------------------------------------------------------------
99
100 char nomini[80] ;
101 int mermax, mermax_eqb, prompt, graph, fmer_stop, fmer_save, mermax_poisson ;
102 int mermax_potvit, mer_masse, fmer_upd_met, ind_rel_met ;
103 double seuil, relax_poisson, relax_potvit, relax, aexp_masse ;
104 double mbar_voulue[2], fact_separ, relax_met, relax_omeg ;
105 double fact_omeg_min, fact_omeg_max, thres_adapt[2], reduce_shift ;
106
107 ifstream fpar("parcoal.d") ;
108 if ( !fpar.good() ) {
109 cout << "Problem with opening the file parcoal.d ! " << endl ;
110 abort() ;
111 }
112 fpar.ignore(1000, '\n') ;
113 fpar.ignore(1000, '\n') ;
114 fpar.getline(nomini, 80) ;
115 fpar >> fact_separ ; fpar.ignore(1000, '\n');
116 fpar >> mbar_voulue[0] ; fpar.ignore(1000, '\n') ;
117 fpar >> mbar_voulue[1] ; fpar.ignore(1000, '\n') ;
118 mbar_voulue[0] *= msol ;
119 mbar_voulue[1] *= msol ;
120 fpar.ignore(1000, '\n') ;
121 fpar >> mermax ; fpar.ignore(1000, '\n') ;
122 fpar >> relax ; fpar.ignore(1000, '\n') ;
123 fpar >> mermax_eqb ; fpar.ignore(1000, '\n') ;
124 fpar >> prompt ; fpar.ignore(1000, '\n') ;
125 fpar >> graph ; fpar.ignore(1000, '\n') ;
126 fpar >> seuil ; fpar.ignore(1000, '\n') ;
127 fpar >> fmer_stop ; fpar.ignore(1000, '\n') ;
128 fpar >> fmer_save ; fpar.ignore(1000, '\n') ;
129 fpar >> mermax_poisson ; fpar.ignore(1000, '\n') ;
130 fpar >> relax_poisson ; fpar.ignore(1000, '\n') ;
131 fpar >> mermax_potvit ; fpar.ignore(1000, '\n') ;
132 fpar >> relax_potvit ; fpar.ignore(1000, '\n') ;
133 fpar >> mer_masse ; fpar.ignore(1000, '\n') ;
134 fpar >> aexp_masse ; fpar.ignore(1000, '\n') ;
135 fpar >> fmer_upd_met ; fpar.ignore(1000, '\n');
136 fpar >> ind_rel_met ; fpar.ignore(1000, '\n');
137 fpar >> relax_met ; fpar.ignore(1000, '\n');
138 if (ind_rel_met == 0) relax_met = 1. ;
139 fpar >> relax_omeg ; fpar.ignore(1000, '\n');
140 fpar >> fact_omeg_min ; fpar.ignore(1000, '\n');
141 fpar >> fact_omeg_max ; fpar.ignore(1000, '\n');
142 fpar >> thres_adapt[0] ; fpar.ignore(1000, '\n');
143 fpar >> thres_adapt[1] ; fpar.ignore(1000, '\n');
144 fpar >> reduce_shift ;
145 if ( ! fpar.good() ) { // to ensure compatibility with old
146 reduce_shift = 0.6 ; // parcoal.d files which did not had
147 } // the reduce_shift line
148 fpar.close() ;
149
150
151 cout << endl
152 << "==========================================================" << endl
153 << " Physical parameters " << endl
154 << "=========================================================="
155 << endl ;
156 cout << endl << endl ;
157 cout << "File containing the initial conditions : " << nomini << endl ;
158 cout << "Factor by which the initial separation will be multiplied : "
159 << fact_separ << endl ;
160 if ( abs(mer_masse) < mermax ) {
161 cout << "Baryon mass required for star 1 [M_sol] : "
162 << mbar_voulue[0] / msol << endl ;
163 cout << "Baryon mass required for star 2 [M_sol] : "
164 << mbar_voulue[1] / msol << endl ;
165 }
166 cout << endl
167 << "==========================================================" << endl
168 << " Parameters of the computation " << endl
169 << "=========================================================="
170 << endl ;
171 cout << "Maximum number of steps in the main iteration : "
172 << mermax << endl ;
173 cout << "Relaxation factor in the main iteration : "
174 << relax << endl ;
175 cout << "Maximum number of steps in Star_bin::equilibrium : "
176 << mermax_eqb << endl ;
177 cout << "Threshold on the enthalpy relative change for ending the computation : "
178 << seuil << endl ;
179 cout << "Step interval between safeguards of the whole configuration : "
180 << fmer_save << endl ;
181 cout << "Maximum number of steps in Map_et::poisson : "
182 << mermax_poisson << endl ;
183 cout << "Relaxation factor in Map_et::poisson : "
184 << relax_poisson << endl ;
185 cout << "Maximum number of steps in Map_radial::poisson_compact : "
186 << mermax_potvit << endl ;
187 cout << "Relaxation factor in Map_radial::poisson_compact : "
188 << relax_potvit << endl ;
189 cout << "Step from which the baryon mass is forced to converge : "
190 << mer_masse << endl ;
191 cout << "Exponent for the increase factor of the central enthalpy : "
192 << aexp_masse << endl ;
193 cout << "Step interval between metric updates : "
194 << fmer_upd_met << endl ;
195 if (ind_rel_met == 1) {
196 cout << "Relaxation factor of the metric : "
197 << relax_met << endl ;
198 }
199 else {
200 cout << "No relaxation on the metric" << endl ;
201 }
202 cout << "Relaxation factor on Omega (orbital angular velocity) : "
203 << relax_omeg << endl ;
204 cout << "Relative low bound in the omega search : "
205 << fact_omeg_min << endl ;
206 cout << "Relative high bound in the omega search : "
207 << fact_omeg_max << endl ;
208 cout <<
209 "Threshold on |dH/dr|_eq / |dH/dr|_pole for the adaptation of the mapping for star 1"
210 << endl << thres_adapt[0] << endl ;
211 cout <<
212 "Threshold on |dH/dr|_eq / |dH/dr|_pole for the adaptation of the mapping for star 2"
213 << endl << thres_adapt[1] << endl ;
214 cout << "Factor by which the initial analytical shift is reduced : "
215 << reduce_shift << endl ;
216
217 arrete(prompt) ;
218
219 double distance = 100. * fact_separ ;
220
221 //------------------------------------------------------------------
222 // Read of the initial conditions
223 //------------------------------------------------------------------
224
225 FILE* fich = fopen(nomini, "r") ;
226 if (fich == 0x0) {
227 cout << "Problem in opening the file " << nomini << " ! " << endl ;
228 perror(" reason") ;
229 abort() ;
230 }
231
232 int mer_ini ;
233 fread(&mer_ini, sizeof(int), 1, fich) ;
234
235 Mg3d mg1(fich) ;
236 Map_et mp1(mg1, fich) ;
237 Eos* peos1 = Eos::eos_from_file(fich) ;
238
239 Mg3d mg2(fich) ;
240 Map_et mp2(mg2, fich) ;
241 Eos* peos2 = Eos::eos_from_file(fich) ;
242
243 Binary star(mp1, *peos1, mp2, *peos2, fich) ;
244
245 fclose(fich) ;
246
247 //------------------------------------------------------------------
248 // Modification of the separation between the two stars
249 //------------------------------------------------------------------
250
251 for (int i=1 ; i<=2 ; i++) {
252
253 double ori_x = (star(i).get_mp()).get_ori_x() ;
254 ori_x *= fact_separ ;
255 ((star.set(i)).set_mp()).set_ori(ori_x, 0., 0.) ;
256 }
257
258 //------------------------------------------------------------------
259 // Update of the initial conditions
260 //------------------------------------------------------------------
261
262 // Initialisation of logn, beta, psi4 etc...
263 // ---------------------------------
264
265 star.fait_decouple() ;
266
267 for (int i=1; i<=2; i++) {
268 (star.set(i)).update_metric(star(3-i), star.get_omega()) ;
269 }
270
271 // Initialisation of gradients of companion potentials
272 // ---------------------------------------------------
273
274 for (int i=1; i<=2; i++) {
275 (star.set(i)).update_metric_der_comp(star(3-i), star.get_omega()) ;
276 }
277
278 // Initialisation of hydro quantities
279 // ----------------------------------
280
281 for (int i=1; i<=2; i++) {
282 (star.set(i)).equation_of_state() ;
283 (star.set(i)).kinematics(star.get_omega(), star.get_x_axe()) ;
284 (star.set(i)).fait_d_psi() ;
285 (star.set(i)).hydro_euler() ;
286 }
287
288 // New initial of value Omega (taking into account the fact
289 // that the separation has changed)
290
291 star.analytical_omega() ;
292
293 // If the shift vector has not been set previously, it is set to
294 // some analytical value
295 // -------------------------------------------------------------
296
297 star.analytical_shift() ;
298 for (int i=1; i<=2; i++) {
299 star.set(i).set_beta_auto() = reduce_shift*star(i).get_beta_auto() ;
300 }
301
302 cout << reduce_shift << endl ;
303
304 // A second call to update_metric must be performed to update
305 // beta_comp, tkij_auto and akcar_auto.
306 for (int i=1; i<=2; i++) {
307 (star.set(i)).update_metric(star(3-i), star.get_omega()) ;
308 }
309
310 // Second update of gradients of companion potentials
311
312 for (int i=1; i<=2; i++) {
313 (star.set(i)).update_metric_der_comp(star(3-i), star.get_omega()) ;
314 }
315
316 // Second update of hydro quantities
317
318 for (int i=1; i<=2; i++) {
319 (star.set(i)).equation_of_state() ;
320 (star.set(i)).kinematics(star.get_omega(), star.get_x_axe()) ;
321 (star.set(i)).fait_d_psi() ;
322 (star.set(i)).hydro_euler() ;
323 }
324
325
326 //##
327 char name[40] ;
328 sprintf(name, "resu_%e.d", distance) ;
329 FILE* fresu = fopen(name, "w") ;
330
331 int mer1 = 0 ;
332 fwrite(&mer1, sizeof(int), 1, fresu) ; // mer
333
334 star(1).get_mp().get_mg()->sauve(fresu) ;
335 star(1).get_mp().sauve(fresu) ;
336 star(1).get_eos().sauve(fresu) ;
337
338 star(2).get_mp().get_mg()->sauve(fresu) ;
339 star(2).get_mp().sauve(fresu) ;
340 star(2).get_eos().sauve(fresu) ;
341
342 star.sauve(fresu) ;
343
344 fclose(fresu) ;
345 //##
346
347 cout << endl
348 << "==========================================================" << endl
349 << " Initial conditions " << endl
350 << "=========================================================="
351 << endl ;
352 cout << star << endl ;
353
354 arrete(prompt) ;
355
356
357 //----------------------------------------------------------------
358 // Auxiliary quantities
359 //----------------------------------------------------------------
360
361 double ent_c[2] ; // Central enthalpy in each star
362 double dentdx[2] ; // Central d/dx(enthalpy) in each star
363
364 // Error indicators in each star
365 Tbl differ[] = {Tbl(13), Tbl(13)} ;
366 differ[0].set_etat_qcq() ;
367 differ[1].set_etat_qcq() ;
368
369 for (int i=1 ; i<=2 ; i++) {
370 ent_c[i-1] = star(i).get_ent().val_grid_point(0, 0, 0, 0) ;
371 differ[i-1].set(0) = 1 ; // diff_ent = 1
372 differ[i-1].set(1) = 1 ; // err_psi = 1
373 differ[i-1].set(2) = 1 ; // err_logn = 1
374 differ[i-1].set(3) = 1 ; // err_lnq = 1
375 differ[i-1].set(4) = 1 ; // err_beta_x = 1
376 differ[i-1].set(5) = 1 ; // err_beta_y = 1
377 differ[i-1].set(6) = 1 ; // err_beta_z = 1
378 differ[i-1].set(7) = 1 ; // err_h11 = 1
379 differ[i-1].set(8) = 1 ; // err_h21 = 1
380 differ[i-1].set(9) = 1 ; // err_h31 = 1
381 differ[i-1].set(10) = 1 ; // err_h22 = 1
382 differ[i-1].set(11) = 1 ; // err_h32 = 1
383 differ[i-1].set(12) = 1 ; // err_h33 = 1
384 }
385
386 double relax_jm1 = 1. - relax ;
387 double relax_omeg_jm1 = 1. - relax_omeg ;
388
389 //----------------------------------------------------------------
390 // Binary system at the previous step (for the relaxation)
391 //----------------------------------------------------------------
392
393 Binary star_jm1 = star ;
394
395 double omega_jm1 = star_jm1.get_omega() ;
396
397
398 // logn_comp and pot_centri are initialized to 0 on star_jm1 :
399 // ---------------------------------------------------------
400 for (int i=1 ; i<=2 ; i++) {
401 star_jm1.set(i).set_logn_comp() = 0 ;
402 star_jm1.set(i).set_pot_centri() = 0 ;
403 }
404
405 //----------------------------------------------------------------
406 // Openning of log files
407 //----------------------------------------------------------------
408
409 sprintf(name, "resglob_%e.d", distance) ;
410 ofstream fichresu(name) ;
411 fichresu.precision(16) ;
412
413 sprintf(name, "resrota_%e.d", distance) ;
414 ofstream fichrota(name) ;
415 fichrota.precision(16) ;
416
417 sprintf(name, "resdiffm_%e.d", distance) ;
418 ofstream fichvir("resdiffm.d") ;
419 fichvir.precision(16) ;
420
421 ofstream fichconv[2] ;
422 sprintf(name, "resconv1_%e.d", distance) ;
423 fichconv[0].open(name) ;
424 fichconv[0].precision(16) ;
425 sprintf(name, "resconv2_%e.d", distance) ;
426 fichconv[1].open(name) ;
427 fichconv[1].precision(16) ;
428
429 ofstream fichet[2] ;
430 sprintf(name, "resstar1_%e.d", distance) ;
431 fichet[0].open(name) ;
432 fichet[0].precision(16) ;
433 sprintf(name, "resstar2_%e.d", distance) ;
434 fichet[1].open(name) ;
435 fichet[1].precision(16) ;
436
437 fichrota <<
438 "# Omega [rad/s] x_axe [km] x_g (et 0) [km] x_g (et 1) [km] M_grav [M_sol] J [ G M_sol^2 / c]"
439 << endl ;
440
441 fichvir <<
442 "# diff_mass"
443 << endl ;
444
445 for (int i=1; i<=2; i++) {
446 fichconv[i-1] <<
447 "# diff_ent err_psi err_logn err_lnq err_beta_x err_beta_y err_beta_z"
448 << endl ;
449
450 fichet[i-1] <<
451 "# ori_x [km] ent_c M_bar [M_sol] R(theta=0) [km] R(pi/2, 0) [km] R(pi/2, pi/2) [km] R(pi/2, pi) [km]"
452 << endl ;
453 }
454
455 double omega_kep, diff_mass ;
456 int mer ;
457
458 Scalar ff_1 (star(1).get_mp()) ;
459 Scalar ff_2 (star(2).get_mp()) ;
460
461
462 //============================================================================
463 // Start of iteration
464 //============================================================================
465
466 for (mer=0; (differ[0](0) > seuil) && (mer < mermax); mer++) {
467
468 cout <<
469 "=========================================================================="
470 << endl ;
471 cout << "step = " << mer << " diff_ent (1) (2) (1)<->(2) : "
472 << differ[0](0) << " " << differ[1](0) << " "
473 << differ[0](0) - differ[1](0) << endl ;
474 cout <<
475 "=========================================================================="
476 << endl ;
477
478 fichresu << mer;
479 fichresu << " step" << endl ;
480
481 fichrota << mer ;
482 fichvir << mer ;
483 fichconv[0] << mer ;
484 fichconv[1] << mer ;
485 fichet[0] << mer ;
486 fichet[1] << mer ;
487
488 //------------------------------------------------------------------
489 // Computation of the metric coefficients
490 //------------------------------------------------------------------
491
492 if ( (mer % fmer_upd_met) == 0 || mer == 1) {
493
494 for (int i=1; i<=2; i++) {
495 (star.set(i)).update_metric(star(3-i), star_jm1(i), relax_met,
496 star.get_omega()) ;
497 }
498
499 for (int i=1; i<=2; i++) {
500 (star.set(i)).update_metric_der_comp(star(3-i),
501 star.get_omega()) ;
502 }
503 }
504
505 // -------------------------
506 // Impose Dirac gauge
507 // -------------------------
508
509 // if ( (mer % fmer_upd_met) == 0 )
510 // star.dirac_gauge() ;
511
512
513 //------------------------------------------------------------------
514 // Computation of the orbital angular velocity Omega
515 //------------------------------------------------------------------
516
517 double xgg[2] ;
518
519 star.orbit(fact_omeg_min, fact_omeg_max, xgg[0], xgg[1]) ;
520
521 // Translation of the stars in order to set the origin
522 // of the absolute frame on the rotation axis
523 //-----------------------------------------------------
524
525 double x_rot = star.get_x_axe() ;
526
527 for (int i=1 ; i<=2 ; i++) {
528 double ori_x_old = (star(i).get_mp()).get_ori_x() ;
529 double ori_x_new = ori_x_old - x_rot ;
530 ((star.set(i)).set_mp()).set_ori(ori_x_new, 0., 0.) ;
531 }
532
533 star.set_x_axe() = 0. ;
534
535 // Relaxation on the orbital velocity
536 // ----------------------------------
537
538 double omega_j = star.get_omega() ;
539 omega_j = relax_omeg * omega_j + relax_omeg_jm1 * omega_jm1 ;
540 omega_jm1 = omega_j ;
541
542 star.set_omega() = omega_j ;
543
544 cout << display_bold << "New orbital velocity Omega : "
545 << star.get_omega() * f_unit << " rad/s" << display_normal << endl ;
546
547 // Keplerian velocity (for comparison only)
548 // ----------------------------------------
549 omega_kep = sqrt( g_si/g_unit * (star(1).mass_g() + star(2).mass_g())
550 / pow( star.separation(), 3.) ) ;
551
552 cout << "``Keplerian'' velocity (for comparison only) : "
553 << omega_kep * f_unit << " rad/s" << endl ;
554 cout << "New X coordinate of the rotation axis : "
555 << star.get_x_axe() / km << " km" << endl ;
556
557
558 fichresu << star.get_x_axe() / km ;
559 fichresu << " abscidia of the rotation axis [km] " << endl ;
560
561 fichresu << star.get_omega() * f_unit ;
562 fichresu << " Orbital frequency Omega [rad/s] " << endl ;
563
564 fichresu << xgg[0] / km ;
565 fichresu << " Abscidia ``center of mass'' star 1 [km] " << endl ;
566
567 fichresu << xgg[1] / km ;
568 fichresu << " Abscidia ``center of mass'' star 2 [km] " << endl ;
569
570 fichrota << " " << star.get_omega() * f_unit ;
571 fichrota << " " << star.get_x_axe() / km ;
572 fichrota << " " << xgg[0] / km ;
573 fichrota << " " << xgg[1] / km ;
574
575 //------------------------------------------------------------------
576 // Computation of B^i/N (bsn) and pot_centri in each star
577 //------------------------------------------------------------------
578
579 for (int i=1; i<=2; i++) {
580
581 (star.set(i)).kinematics( star.get_omega(), star.get_x_axe() ) ;
582
583 }
584
585 //------------------------------------------------------------------
586 // Computation of gam_euler, u_euler, ener_euler, s_euler,
587 // wit_w and loggam in each star
588 //------------------------------------------------------------------
589
590 for (int i=1; i<=2; i++) {
591
592 (star.set(i)).fait_d_psi() ;
593 (star.set(i)).hydro_euler() ;
594
595 // Check of the Binaire::orbit computation
596 //----------------------------------------
597
598 Scalar tmp = star(i).get_logn_auto() + star(i).get_logn_comp()
599 + star(i).get_loggam() ;
600 double grad1 = tmp.dsdx().val_grid_point(0, 0, 0, 0) ;
601
602 double grad2 = star(i).get_pot_centri().dsdx()
603 .val_grid_point(0, 0, 0, 0) ;
604
605 dentdx[i-1] = star(i).get_ent().dsdx()
606 .val_grid_point(0, 0, 0, 0) ;
607
608 double grad3 = star(i).get_loggam().dsdx()
609 .val_grid_point(0, 0, 0, 0) ;
610
611 cout << "Star " << i << " : " << endl ;
612 cout << " central dH/dx : " << dentdx[i-1] << endl ;
613 cout << " central d(log(Gam))/dx : " << grad3 << endl ;
614 cout << " central d/dx(nu + log(Gam)) : " << grad1 << endl ;
615 cout << " central d/dx(pot_centri) : " << grad2 << endl ;
616 cout << " central d/dx(nu + log(Gam) + pot_centri) : "
617 << grad1 + grad2 << endl ;
618
619
620 }
621
622 //------------------------------------------------------------------
623 // Computation of the stellar equilibrium configurations
624 //------------------------------------------------------------------
625
626 for (int i=1; i<=2; i++) {
627
628 // Relaxation on logn_comp (only if it has not been done by
629 // update_metric)
630 // --------------------------------------------------------
631 if ( (ind_rel_met == 0) || ( (mer % fmer_upd_met) != 0 ) ) {
632 star.set(i).set_logn_comp() = relax * star(i).get_logn_comp()
633 + relax_jm1 * star_jm1(i).get_logn_comp() ;
634 }
635
636 // Relaxation on pot_centri
637 // ------------------------
638 star.set(i).set_pot_centri() = relax * star(i).get_pot_centri()
639 + relax_jm1 * star_jm1(i).get_pot_centri() ;
640
641
642
643 (star.set(i)).equilibrium(ent_c[i-1], mermax_eqb, mermax_potvit,
644 mermax_poisson, relax_poisson,
645 relax_potvit, thres_adapt[i-1],
646 differ[i-1], star.get_omega()) ;
647 }
648
649 //------------------------------------------------------------------
650 // Relaxations
651 //------------------------------------------------------------------
652
653 for (int i=1; i<=2; i++) {
654
655 star.set(i).relaxation( star_jm1(i), relax, relax_met, mer,
656 fmer_upd_met ) ;
657
658 star.set(i).hydro_euler() ;
659 }
660
661 //------------------------------------------------------------------
662 // Change in the central enthalpy to get a fixed baryon mass
663 //------------------------------------------------------------------
664
665 if (mer >= mer_masse) {
666
667 for (int i=1; i<=2; i++) {
668
669 double xx = star(i).mass_b() / mbar_voulue[i-1] - 1. ;
670
671 cout << "Discrepancy M_b / wanted M_b : " << xx << endl ;
672
673 double xprog = ( mer > 2*mer_masse) ? 1. :
674 double(mer-mer_masse)/double(mer_masse) ;
675 xx *= xprog ;
676 double ax = .5 * ( 2. + xx ) / (1. + xx ) ;
677
678 double fact_ent = pow(ax, aexp_masse) ;
679
680 cout << " xprog, xx, ax, fact : " << xprog << " " <<
681 xx << " " << ax << " " << fact_ent << endl ;
682
683 ent_c[i-1] *= fact_ent ;
684
685 }
686 }
687
688 // Updates for the next step
689 // -------------------------
690
691 star_jm1 = star ;
692
693
694 cout << star << endl ;
695
696
697 //---------------------------------------------------------------------
698 // The whole configuration is saved in a file
699 //---------------------------------------------------------------------
700
701 if ( (mer % fmer_save) == 0 ) {
702
703 sprintf(name, "resu_%e.d", distance) ;
704 FILE* fresu2 = fopen(name, "w") ;
705
706 fwrite(&mer, sizeof(int), 1, fresu2) ; // mer
707
708 star(1).get_mp().get_mg()->sauve(fresu2) ;
709 star(1).get_mp().sauve(fresu2) ;
710 star(1).get_eos().sauve(fresu2) ;
711
712 star(2).get_mp().get_mg()->sauve(fresu2) ;
713 star(2).get_mp().sauve(fresu2) ;
714 star(2).get_eos().sauve(fresu2) ;
715
716 star.sauve(fresu2) ;
717
718 fclose(fresu2) ;
719 }
720
721
722 //--------------------------------------------
723 // Writing of global quantities in log files
724 //--------------------------------------------
725 for (int i=1 ; i<=2 ; i++) {
726 fichresu << star(i).mass_b() / msol ;
727 fichresu << " Baryon mass of star " << i << " [M_sol] " << endl ;
728 fichresu << differ[i-1](0) ;
729 fichresu << " relative variation enth. star " << i << endl ;
730
731 fichresu << star(i).ray_pole() / km ;
732 fichresu << " R(theta=0) [km] " << endl ;
733 fichresu << star(i).ray_eq() / km ;
734 fichresu << " R(theta=pi/2, phi=0) [km] " << endl ;
735 fichresu << star(i).ray_eq_pis2() / km ;
736 fichresu << " R(theta=pi/2, phi=pi/2) [km] " << endl ;
737 fichresu << star(i).ray_eq_pi() / km ;
738 fichresu << " R(theta=pi/2, phi=pi) [km] " << endl ;
739
740 fichconv[i-1] << " " << log10( fabs(differ[i-1](0)) + 1.e-16 ) ;
741 fichconv[i-1] << " " << log10( fabs(differ[i-1](1)) + 1.e-16 ) ;
742 fichconv[i-1] << " " << log10( fabs(differ[i-1](2)) + 1.e-16 ) ;
743 fichconv[i-1] << " " << log10( fabs(differ[i-1](3)) + 1.e-16 ) ;
744 fichconv[i-1] << " " << log10( fabs(differ[i-1](4)) + 1.e-16 ) ;
745 fichconv[i-1] << " " << log10( fabs(differ[i-1](5)) + 1.e-16 ) ;
746 fichconv[i-1] << " " << log10( fabs(differ[i-1](6)) + 1.e-16 ) ;
747
748 fichet[i-1] << " " << star(i).get_mp().get_ori_x() / km ;
749 fichet[i-1] << " " << ent_c[i-1] ;
750 fichet[i-1] << " " << star(i).mass_b() / msol ;
751 fichet[i-1] << " " << star(i).ray_pole() / km ;
752 fichet[i-1] << " " << star(i).ray_eq() / km ;
753 fichet[i-1] << " " << star(i).ray_eq_pis2() / km ;
754 fichet[i-1] << " " << star(i).ray_eq_pi() / km ;
755
756 } // End of loop on the stars
757
758 diff_mass = ( star(2).mass_b() - star(1).mass_b() )
759 / star(1).mass_b() ;
760 cout << "Relative difference between the baryon masses: "
761 << diff_mass << endl ;
762 fichresu << diff_mass ;
763 fichresu << " Relative difference between the baryon masses" << endl ;
764
765 fichvir << " " << log10( fabs(diff_mass) + 1.e-16 ) ;
766
767
768 fichresu << " " << endl ;
769 fichresu.flush() ;
770 fichrota << " " << endl ;
771 fichrota.flush() ;
772 fichvir << " " << endl ;
773 fichvir.flush() ;
774 fichconv[0] << " " << endl ;
775 fichconv[0].flush() ;
776 fichconv[1] << " " << endl ;
777 fichconv[1].flush() ;
778 fichet[0] << " " << endl ;
779 fichet[0].flush() ;
780 fichet[1] << " " << endl ;
781 fichet[1].flush() ;
782
783
784 } // End of the main loop (mer)
785
786 //============================================================================
787 // End of iteration
788 //============================================================================
789
790 fichresu.close() ;
791 fichrota.close() ;
792 fichvir.close() ;
793 fichconv[0].close() ;
794 fichconv[1].close() ;
795 fichet[0].close() ;
796 fichet[1].close() ;
797
798
799 //-----------------------------------------------
800 // General features of the final configuration
801 // saved in a file
802 //-----------------------------------------------
803
804 ofstream fichfinal("calcul.d") ;
805 fichfinal.precision(6) ;
806
807 time_t rawtime = time(0x0) ;
808 fichfinal << "Date: " << asctime( localtime( &rawtime ) ) << endl ;
809 char* hostname = getenv("HOST") ;
810 if (hostname != 0x0) {
811 fichfinal << "Computer: " << hostname << endl ;
812 }
813 fichfinal <<
814 "==================================================================="
815 << endl << endl ;
816
817
818 if ( star(1).is_irrotational() ) {
819 fichfinal << " Irrotational" << endl ;
820 }
821 else {
822 fichfinal << " Co-rotating" << endl ;
823 }
824
825 fichfinal << star(1).get_eos() << endl ;
826
827 fichfinal << "Omega = " << star.get_omega() * f_unit << " rad/s"
828 << " Orbital frequency f = "
829 << star.get_omega() / (2*M_PI) * f_unit << " Hz" << endl ;
830 fichfinal << "Omega_kepler = " << omega_kep * f_unit << " rad/s" << endl ;
831 fichfinal << "Coordinate separation : " << star.separation() / km
832 << " km" << endl ;
833 fichfinal << "1/2 ADM mass : " << 0.5 * star.mass_adm() / msol
834 << " Mo" << endl ;
835 fichfinal << "1/2 ADM mass (vol) : " << 0.5 * star.mass_adm_vol() / msol
836 << " Mo" << endl ;
837 fichfinal << "Total angular momentum : "
838 << star.angu_mom()(2)/ ( qpig / (4* M_PI) * msol*msol)
839 << " G M_sol^2 / c" << endl ;
840
841
842
843 star(1).test_K_Hi() ;
844
845 cout << "1/2 ADM mass : " << 0.5 * star.mass_adm() / msol
846 << " Mo" << endl ;
847 cout << "1/2 ADM mass (vol) : " << 0.5 * star.mass_adm_vol() / msol
848 << " Mo" << endl ;
849 cout << "Total angular momentum : "
850 << star.angu_mom()(2)/ ( qpig / (4* M_PI) * msol*msol)
851 << " G M_sol^2 / c" << endl ;
852
853 fichfinal << endl << "Number of steps : " << mer << endl ;
854
855 for (int i=1 ; i<=2; i++) {
856 fichfinal << endl <<
857 "==================================================================="
858 << endl ;
859 fichfinal << " Star no. " << i << endl ;
860 fichfinal <<
861 "==================================================================="
862 << endl ;
863 fichfinal << "Grid : " << endl ;
864 fichfinal << "------ " << endl ;
865 fichfinal << *(star(i).get_mp().get_mg()) << endl ;
866 fichfinal << endl << "Physical characteristics : " << endl ;
867 fichfinal << "-------------------------" << endl ;
868 fichfinal << star(i) << endl ;
869 }
870 fichfinal << endl ;
871
872 star.display_poly(fichfinal) ; // Reduced quantities for polytropic EOS
873
874 fichfinal << endl <<
875 "==================================================================="
876 << endl ;
877 fichfinal << "Diff_ent : star 1 : " << differ[0](0) << " star 2 : "
878 << differ[1](0) << endl ;
879 fichfinal <<
880 "Relative difference between the baryon masses of the two stars : "
881 << diff_mass << endl ;
882 fichfinal << "dH/dx at r = 0 : star 1 : " << dentdx[0]
883 << " star 2 : " << dentdx[1] << endl ;
884
885 fichfinal << "Relative error on the virial theorem : " << endl ;
886 fichfinal << " VE(M)= " << star.virial() ;
887
888 fichfinal << endl <<
889 "================================================================" << endl ;
890 fichfinal << " PARAMETERS USED FOR THE COMPUTATION : " << endl ;
891 fichfinal <<
892 "================================================================" << endl ;
893 fichfinal.close() ;
894 system("cat parcoal.d >> calcul.d") ;
895
896 // Identification du code et de ses sous-routines (no. de version RCS) :
897 fichfinal.open("calcul.d", ios::app ) ;
898 fichfinal << endl <<
899 "================================================================" << endl ;
900 fichfinal << " IDENTIFICATION OF THE CODE : " << endl ;
901 fichfinal <<
902 "================================================================" << endl ;
903 fichfinal.close() ;
904 system("ident coal >> calcul.d") ;
905
906 // Preparation for CPU infos printing :
907 fichfinal.open("calcul.d", ios::app ) ;
908 fichfinal << endl <<
909 "================================================================" << endl ;
910 fichfinal << " CPU TIME and MEMORY infos : " << endl ;
911 fichfinal <<
912 "================================================================" << endl ;
913 fichfinal << endl ;
914 fichfinal.close() ;
915
916
917 //-----------------------------------------------
918 // General features of the final configuration
919 // saved in a file with scientific notation and
920 // 14 digits for further reading by a code
921 //-----------------------------------------------
922
923 sprintf(name, "resformat_%e.d", distance) ;
924 ofstream seqfich(name) ;
925 if ( !seqfich.good() ) {
926 cout << "coal : problem with opening the file resformat.d !" << endl ;
927 abort() ;
928 }
929 star.write_global(seqfich) ;
930 seqfich.close() ;
931
932
933 // Cleaning
934 // --------
935
936 delete peos1 ;
937 delete peos2 ;
938
939 return EXIT_SUCCESS ;
940
941 }