Debian Codegraph @

Codes/Binary_star/coal_seq.C

raw
1 /*
2 * Computes the equilibrium configuration of a binary system.
3 *
4 */
5
6 /*
7 * Copyright (c) 2005 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_seq_C[] = "$Header: /cvsroot/Lorene/Codes/Binary_star/coal_seq.C,v 1.5 2014/10/13 08:53:55 j_novak Exp $" ;
28
29 /*
30 * $Id: coal_seq.C,v 1.5 2014/10/13 08:53:55 j_novak Exp $
31 * $Log: coal_seq.C,v $
32 * Revision 1.5 2014/10/13 08:53:55 j_novak
33 * Lorene classes and functions now belong to the namespace Lorene.
34 *
35 * Revision 1.4 2014/10/06 15:09:40 j_novak
36 * Modified #include directives to use c++ syntax.
37 *
38 * Revision 1.3 2006/05/31 11:30:28 f_limousin
39 * Modif. of the size of the different domains
40 *
41 * Revision 1.2 2006/04/11 14:45:33 f_limousin
42 * Correction of the char "coal_seq_C".
43 *
44 * Revision 1.1 2006/04/11 14:39:16 f_limousin
45 * First version
46 *
47 *
48 * $Header: /cvsroot/Lorene/Codes/Binary_star/coal_seq.C,v 1.5 2014/10/13 08:53:55 j_novak Exp $
49 *
50 */
51
52 // headers C
53 #include <cstdlib>
54 #include <cmath>
55 #include <ctime>
56
57 // headers Lorene
58 #include "unites.h"
59 #include "cmp.h"
60 #include "tenseur.h"
61 #include "binary.h"
62 #include "eos.h"
63 #include "utilitaires.h"
64 #include "graphique.h"
65 #include "param.h"
66 #include "nbr_spx.h"
67
68
69 namespace Lorene {
70 // Local prototype
71 Cmp raccord_c1(const Cmp& uu, int l1) ;
72 }
73 using namespace Lorene ;
74
75 int main(){
76
77 // Identification of all the subroutines called by the code :
78
79 system("ident coal > identif.d") ;
80
81 // For the display :
82 char display_bold[]="x[1m" ; display_bold[0] = 27 ;
83 char display_normal[] = "x[0m" ; display_normal[0] = 27 ;
84
85 using namespace Unites ;
86
87 //------------------------------------------------------------------
88 // Parameters of the computation
89 //------------------------------------------------------------------
90
91 char nomini[80] ;
92 int mermax, mermax_eqb, prompt, graph, fmer_stop, fmer_save, mermax_poisson ;
93 int mermax_potvit, mer_masse, fmer_upd_met, ind_rel_met ;
94 double seuil, relax_poisson, relax_potvit, relax, aexp_masse ;
95 double mbar_voulue[2], fact_separ, relax_met, relax_omeg ;
96 double fact_omeg_min, fact_omeg_max, thres_adapt[2], reduce_shift ;
97
98 ifstream fpar("parcoal.d") ;
99 if ( !fpar.good() ) {
100 cout << "Problem with opening the file parcoal.d ! " << endl ;
101 abort() ;
102 }
103 fpar.ignore(1000, '\n') ;
104 fpar.ignore(1000, '\n') ;
105 fpar.getline(nomini, 80) ;
106 fpar >> fact_separ ; fpar.ignore(1000, '\n');
107 fpar >> mbar_voulue[0] ; fpar.ignore(1000, '\n') ;
108 fpar >> mbar_voulue[1] ; fpar.ignore(1000, '\n') ;
109 mbar_voulue[0] *= msol ;
110 mbar_voulue[1] *= msol ;
111 fpar.ignore(1000, '\n') ;
112 fpar >> mermax ; fpar.ignore(1000, '\n') ;
113 fpar >> relax ; fpar.ignore(1000, '\n') ;
114 fpar >> mermax_eqb ; fpar.ignore(1000, '\n') ;
115 fpar >> prompt ; fpar.ignore(1000, '\n') ;
116 fpar >> graph ; fpar.ignore(1000, '\n') ;
117 fpar >> seuil ; fpar.ignore(1000, '\n') ;
118 fpar >> fmer_stop ; fpar.ignore(1000, '\n') ;
119 fpar >> fmer_save ; fpar.ignore(1000, '\n') ;
120 fpar >> mermax_poisson ; fpar.ignore(1000, '\n') ;
121 fpar >> relax_poisson ; fpar.ignore(1000, '\n') ;
122 fpar >> mermax_potvit ; fpar.ignore(1000, '\n') ;
123 fpar >> relax_potvit ; fpar.ignore(1000, '\n') ;
124 fpar >> mer_masse ; fpar.ignore(1000, '\n') ;
125 fpar >> aexp_masse ; fpar.ignore(1000, '\n') ;
126 fpar >> fmer_upd_met ; fpar.ignore(1000, '\n');
127 fpar >> ind_rel_met ; fpar.ignore(1000, '\n');
128 fpar >> relax_met ; fpar.ignore(1000, '\n');
129 if (ind_rel_met == 0) relax_met = 1. ;
130 fpar >> relax_omeg ; fpar.ignore(1000, '\n');
131 fpar >> fact_omeg_min ; fpar.ignore(1000, '\n');
132 fpar >> fact_omeg_max ; fpar.ignore(1000, '\n');
133 fpar >> thres_adapt[0] ; fpar.ignore(1000, '\n');
134 fpar >> thres_adapt[1] ; fpar.ignore(1000, '\n');
135 fpar >> reduce_shift ;
136 if ( ! fpar.good() ) { // to ensure compatibility with old
137 reduce_shift = 0.6 ; // parcoal.d files which did not had
138 } // the reduce_shift line
139 fpar.close() ;
140
141
142 cout << endl
143 << "==========================================================" << endl
144 << " Physical parameters " << endl
145 << "=========================================================="
146 << endl ;
147 cout << endl << endl ;
148 cout << "File containing the initial conditions : " << nomini << endl ;
149 cout << "Factor by which the initial separation will be multiplied : "
150 << fact_separ << endl ;
151 if ( abs(mer_masse) < mermax ) {
152 cout << "Baryon mass required for star 1 [M_sol] : "
153 << mbar_voulue[0] / msol << endl ;
154 cout << "Baryon mass required for star 2 [M_sol] : "
155 << mbar_voulue[1] / msol << endl ;
156 }
157 cout << endl
158 << "==========================================================" << endl
159 << " Parameters of the computation " << endl
160 << "=========================================================="
161 << endl ;
162 cout << "Maximum number of steps in the main iteration : "
163 << mermax << endl ;
164 cout << "Relaxation factor in the main iteration : "
165 << relax << endl ;
166 cout << "Maximum number of steps in Star_bin::equilibrium : "
167 << mermax_eqb << endl ;
168 cout << "Threshold on the enthalpy relative change for ending the computation : "
169 << seuil << endl ;
170 cout << "Step interval between safeguards of the whole configuration : "
171 << fmer_save << endl ;
172 cout << "Maximum number of steps in Map_et::poisson : "
173 << mermax_poisson << endl ;
174 cout << "Relaxation factor in Map_et::poisson : "
175 << relax_poisson << endl ;
176 cout << "Maximum number of steps in Map_radial::poisson_compact : "
177 << mermax_potvit << endl ;
178 cout << "Relaxation factor in Map_radial::poisson_compact : "
179 << relax_potvit << endl ;
180 cout << "Step from which the baryon mass is forced to converge : "
181 << mer_masse << endl ;
182 cout << "Exponent for the increase factor of the central enthalpy : "
183 << aexp_masse << endl ;
184 cout << "Step interval between metric updates : "
185 << fmer_upd_met << endl ;
186 if (ind_rel_met == 1) {
187 cout << "Relaxation factor of the metric : "
188 << relax_met << endl ;
189 }
190 else {
191 cout << "No relaxation on the metric" << endl ;
192 }
193 cout << "Relaxation factor on Omega (orbital angular velocity) : "
194 << relax_omeg << endl ;
195 cout << "Relative low bound in the omega search : "
196 << fact_omeg_min << endl ;
197 cout << "Relative high bound in the omega search : "
198 << fact_omeg_max << endl ;
199 cout <<
200 "Threshold on |dH/dr|_eq / |dH/dr|_pole for the adaptation of the mapping for star 1"
201 << endl << thres_adapt[0] << endl ;
202 cout <<
203 "Threshold on |dH/dr|_eq / |dH/dr|_pole for the adaptation of the mapping for star 2"
204 << endl << thres_adapt[1] << endl ;
205 cout << "Factor by which the initial analytical shift is reduced : "
206 << reduce_shift << endl ;
207
208 arrete(prompt) ;
209
210 //------------------------------------------------------------------
211 // Computation of the distances for the sequence
212 //------------------------------------------------------------------
213
214 for(int dist = 0; dist < 8; dist++){
215 fact_separ = 0.65 - dist*0.05 ;
216 double distance = 100 * fact_separ ;
217 cout << "new distance = " << distance << endl ;
218
219
220 //------------------------------------------------------------------
221 // Read of the initial conditions
222 //------------------------------------------------------------------
223
224 FILE* fich = fopen(nomini, "r") ;
225 if (fich == 0x0) {
226 cout << "Problem in opening the file " << nomini << " ! " << endl ;
227 perror(" reason") ;
228 abort() ;
229 }
230
231 int mer_ini ;
232 fread(&mer_ini, sizeof(int), 1, fich) ;
233
234 Mg3d mg1(fich) ;
235 Map_et mp1(mg1, fich) ;
236 Eos* peos1 = Eos::eos_from_file(fich) ;
237
238 Mg3d mg2(fich) ;
239 Map_et mp2(mg2, fich) ;
240 Eos* peos2 = Eos::eos_from_file(fich) ;
241
242 Binary star(mp1, *peos1, mp2, *peos2, fich) ;
243
244 fclose(fich) ;
245
246 //------------------------------------------------------------------
247 // Modification of the separation between the two stars
248 //------------------------------------------------------------------
249
250 for (int i=1 ; i<=2 ; i++) {
251
252 double ori_x = (star(i).get_mp()).get_ori_x() ;
253 ori_x *= fact_separ ;
254 ((star.set(i)).set_mp()).set_ori(ori_x, 0., 0.) ;
255 }
256
257 //------------------------------------------------------------------
258 // Update of the initial conditions
259 //------------------------------------------------------------------
260
261 // Initialisation of logn, beta, psi4 etc...
262 // ---------------------------------
263
264 star.fait_decouple() ;
265
266 for (int i=1; i<=2; i++) {
267 (star.set(i)).update_metric(star(3-i), star.get_omega()) ;
268 }
269
270 // Initialisation of gradients of companion potentials
271 // ---------------------------------------------------
272
273 for (int i=1; i<=2; i++) {
274 (star.set(i)).update_metric_der_comp(star(3-i), star.get_omega()) ;
275 }
276
277 // Initialisation of hydro quantities
278 // ----------------------------------
279
280 for (int i=1; i<=2; i++) {
281 (star.set(i)).equation_of_state() ;
282 (star.set(i)).kinematics(star.get_omega(), star.get_x_axe()) ;
283 (star.set(i)).fait_d_psi() ;
284 (star.set(i)).hydro_euler() ;
285 }
286
287 // New initial of value Omega (taking into account the fact
288 // that the separation has changed)
289
290 star.analytical_omega() ;
291
292 // If the shift vector has not been set previously, it is set to
293 // some analytical value
294 // -------------------------------------------------------------
295
296 star.analytical_shift() ;
297 for (int i=1; i<=2; i++) {
298 star.set(i).set_beta_auto() = reduce_shift*star(i).get_beta_auto() ;
299 }
300
301 cout << reduce_shift << endl ;
302
303 // A second call to update_metric must be performed to update
304 // beta_comp, tkij_auto and akcar_auto.
305 for (int i=1; i<=2; i++) {
306 (star.set(i)).update_metric(star(3-i), star.get_omega()) ;
307 }
308
309 // Second update of gradients of companion potentials
310
311 for (int i=1; i<=2; i++) {
312 (star.set(i)).update_metric_der_comp(star(3-i), star.get_omega()) ;
313 }
314
315 // Second update of hydro quantities
316
317 for (int i=1; i<=2; i++) {
318 (star.set(i)).equation_of_state() ;
319 (star.set(i)).kinematics(star.get_omega(), star.get_x_axe()) ;
320 (star.set(i)).fait_d_psi() ;
321 (star.set(i)).hydro_euler() ;
322 }
323
324
325 //##
326 char name[40] ;
327 sprintf(name, "resu_%e.d", distance) ;
328 FILE* fresu = fopen(name, "w") ;
329
330 int mer1 = 0 ;
331 fwrite(&mer1, sizeof(int), 1, fresu) ; // mer
332
333 star(1).get_mp().get_mg()->sauve(fresu) ;
334 star(1).get_mp().sauve(fresu) ;
335 star(1).get_eos().sauve(fresu) ;
336
337 star(2).get_mp().get_mg()->sauve(fresu) ;
338 star(2).get_mp().sauve(fresu) ;
339 star(2).get_eos().sauve(fresu) ;
340
341 star.sauve(fresu) ;
342
343 fclose(fresu) ;
344 //##
345
346 cout << endl
347 << "==========================================================" << endl
348 << " Initial conditions " << endl
349 << "=========================================================="
350 << endl ;
351 cout << star << endl ;
352
353 arrete(prompt) ;
354
355
356 //----------------------------------------------------------------
357 // Auxiliary quantities
358 //----------------------------------------------------------------
359
360 double ent_c[2] ; // Central enthalpy in each star
361 double dentdx[2] ; // Central d/dx(enthalpy) in each star
362
363 // Error indicators in each star
364 Tbl differ[] = {Tbl(13), Tbl(13)} ;
365 differ[0].set_etat_qcq() ;
366 differ[1].set_etat_qcq() ;
367
368 for (int i=1 ; i<=2 ; i++) {
369 ent_c[i-1] = star(i).get_ent().val_grid_point(0, 0, 0, 0) ;
370 differ[i-1].set(0) = 1 ; // diff_ent = 1
371 differ[i-1].set(1) = 1 ; // err_psi = 1
372 differ[i-1].set(2) = 1 ; // err_logn = 1
373 differ[i-1].set(3) = 1 ; // err_lnq = 1
374 differ[i-1].set(4) = 1 ; // err_beta_x = 1
375 differ[i-1].set(5) = 1 ; // err_beta_y = 1
376 differ[i-1].set(6) = 1 ; // err_beta_z = 1
377 differ[i-1].set(7) = 1 ; // err_h11 = 1
378 differ[i-1].set(8) = 1 ; // err_h21 = 1
379 differ[i-1].set(9) = 1 ; // err_h31 = 1
380 differ[i-1].set(10) = 1 ; // err_h22 = 1
381 differ[i-1].set(11) = 1 ; // err_h32 = 1
382 differ[i-1].set(12) = 1 ; // err_h33 = 1
383 }
384
385 double relax_jm1 = 1. - relax ;
386 double relax_omeg_jm1 = 1. - relax_omeg ;
387
388 //----------------------------------------------------------------
389 // Binary system at the previous step (for the relaxation)
390 //----------------------------------------------------------------
391
392 Binary star_jm1 = star ;
393
394 double omega_jm1 = star_jm1.get_omega() ;
395
396
397 // logn_comp and pot_centri are initialized to 0 on star_jm1 :
398 // ---------------------------------------------------------
399 for (int i=1 ; i<=2 ; i++) {
400 star_jm1.set(i).set_logn_comp() = 0 ;
401 star_jm1.set(i).set_pot_centri() = 0 ;
402 }
403
404 //----------------------------------------------------------------
405 // Openning of log files
406 //----------------------------------------------------------------
407
408 sprintf(name, "resglob_%e.d", distance) ;
409 ofstream fichresu(name) ;
410 fichresu.precision(16) ;
411
412 sprintf(name, "resrota_%e.d", distance) ;
413 ofstream fichrota(name) ;
414 fichrota.precision(16) ;
415
416 sprintf(name, "resdiffm_%e.d", distance) ;
417 ofstream fichvir("resdiffm.d") ;
418 fichvir.precision(16) ;
419
420 ofstream fichconv[2] ;
421 sprintf(name, "resconv1_%e.d", distance) ;
422 fichconv[0].open(name) ;
423 fichconv[0].precision(16) ;
424 sprintf(name, "resconv2_%e.d", distance) ;
425 fichconv[1].open(name) ;
426 fichconv[1].precision(16) ;
427
428 ofstream fichet[2] ;
429 sprintf(name, "resstar1_%e.d", distance) ;
430 fichet[0].open(name) ;
431 fichet[0].precision(16) ;
432 sprintf(name, "resstar2_%e.d", distance) ;
433 fichet[1].open(name) ;
434 fichet[1].precision(16) ;
435
436 fichrota <<
437 "# 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]"
438 << endl ;
439
440 fichvir <<
441 "# diff_mass"
442 << endl ;
443
444 for (int i=1; i<=2; i++) {
445 fichconv[i-1] <<
446 "# diff_ent err_psi err_logn err_lnq err_beta_x err_beta_y err_beta_z"
447 << endl ;
448
449 fichet[i-1] <<
450 "# 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]"
451 << endl ;
452 }
453
454 double omega_kep, diff_mass ;
455 int mer ;
456
457 Scalar ff_1 (star(1).get_mp()) ;
458 Scalar ff_2 (star(2).get_mp()) ;
459
460
461 //============================================================================
462 // Start of iteration
463 //============================================================================
464
465 for (mer=0; (differ[0](0) > seuil) && (mer < mermax); mer++) {
466
467 cout <<
468 "=========================================================================="
469 << endl ;
470 cout << "step = " << mer << " diff_ent (1) (2) (1)<->(2) : "
471 << differ[0](0) << " " << differ[1](0) << " "
472 << differ[0](0) - differ[1](0) << endl ;
473 cout <<
474 "=========================================================================="
475 << endl ;
476
477 fichresu << mer;
478 fichresu << " step" << endl ;
479
480 fichrota << mer ;
481 fichvir << mer ;
482 fichconv[0] << mer ;
483 fichconv[1] << mer ;
484 fichet[0] << mer ;
485 fichet[1] << mer ;
486
487 //------------------------------------------------------------------
488 // Computation of the metric coefficients
489 //------------------------------------------------------------------
490
491 if ( (mer % fmer_upd_met) == 0 || mer == 1) {
492
493 for (int i=1; i<=2; i++) {
494 (star.set(i)).update_metric(star(3-i), star_jm1(i), relax_met,
495 star.get_omega()) ;
496 }
497
498 for (int i=1; i<=2; i++) {
499 (star.set(i)).update_metric_der_comp(star(3-i),
500 star.get_omega()) ;
501 }
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
940 return EXIT_SUCCESS ;
941
942 }