Debian Codegraph @

Codes/Bin_star_ncp/coal_ncp.C

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