Debian Codegraph @

Codes/Bin_star/coal_regu.C

raw
1 /*
2 * Computes the equilibrium configuration of a binary system
3 * by using regularized source.
4 *
5 */
6
7 /*
8 * Copyright (c) 2001-2003 Keisuke Taniguchi
9 *
10 * This file is part of LORENE.
11 *
12 * LORENE is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation; either version 2 of the License, or
15 * (at your option) any later version.
16 *
17 * LORENE is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
21 *
22 * You should have received a copy of the GNU General Public License
23 * along with LORENE; if not, write to the Free Software
24 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
25 *
26 */
27
28 char coal_regu_C[] = "$Header: /cvsroot/Lorene/Codes/Bin_star/coal_regu.C,v 1.12 2014/10/13 08:53:54 j_novak Exp $" ;
29
30 /*
31 * $Id: coal_regu.C,v 1.12 2014/10/13 08:53:54 j_novak Exp $
32 * $Log: coal_regu.C,v $
33 * Revision 1.12 2014/10/13 08:53:54 j_novak
34 * Lorene classes and functions now belong to the namespace Lorene.
35 *
36 * Revision 1.11 2014/10/06 15:09:42 j_novak
37 * Modified #include directives to use c++ syntax.
38 *
39 * Revision 1.10 2004/03/25 12:35:36 j_novak
40 * now using namespace Unites
41 *
42 * Revision 1.9 2003/09/18 15:22:49 e_gourgoulhon
43 * Added #include <time.h> which had been forgotten in previous commit.
44 *
45 * Revision 1.8 2003/09/18 15:06:59 e_gourgoulhon
46 * Added printing of date and host name in the header of the file calcul.d.
47 *
48 * Revision 1.7 2003/09/17 15:43:53 e_gourgoulhon
49 * Test of good opening of the initial data file.
50 *
51 * Revision 1.6 2003/09/16 13:36:50 e_gourgoulhon
52 * -- initial analytical shift decreased by a factor reduce_shift which
53 * can be specified in the parcoal.d file (default value = 0.6)
54 * -- replaced the fpar.getline(blabla, 120) by fpar.ignore(1000,'\n')
55 * -- new output file "resformat.d" at the end of the computation for
56 * formatted output of global quantities (to be read by external code)
57 *
58 * Revision 1.5 2003/09/08 15:32:10 e_gourgoulhon
59 * Added the printing of the virial errors in the output file "calcul.d".
60 *
61 * Revision 1.4 2003/05/14 20:06:09 e_gourgoulhon
62 * Suppressed the qualifier ios::nocreate in call to fstream::open
63 * (not supported by gcc 3.2).
64 *
65 * Revision 1.3 2003/01/09 11:07:48 j_novak
66 * headcpp.h is now compliant with C++ norm.
67 * The include files have been ordered, as well as the local_settings_linux
68 *
69 * Revision 1.2 2002/12/11 14:16:14 k_taniguchi
70 * Return type of main changed from 'void' to 'int'.
71 * Add "thres_adapt" to star 2
72 * and modify the part of "resize".
73 *
74 * Revision 1.1.1.1 2001/11/20 15:19:31 e_gourgoulhon
75 * LORENE
76 *
77 * Revision 2.3 2001/08/07 09:54:27 keisuke
78 * Change of the argument in Etoile_bin::equil_regular.
79 * Addition of the procedure to calculate a factor for "resize".
80 *
81 * Revision 2.2 2001/03/20 16:05:50 keisuke
82 * Translation of the origin of the absolute frame.
83 *
84 * Revision 2.1 2001/01/18 12:38:11 keisuke
85 * Input the identification of the codes in calcul.d.
86 *
87 * Revision 2.0 2001/01/17 14:17:19 keisuke
88 * *** empty log message ***
89 *
90 *
91 * $Header: /cvsroot/Lorene/Codes/Bin_star/coal_regu.C,v 1.12 2014/10/13 08:53:54 j_novak Exp $
92 *
93 */
94
95 // headers C
96 #include <cstdlib>
97 #include <cmath>
98 #include <ctime>
99
100 // headers Lorene
101 #include "binaire.h"
102 #include "eos.h"
103 #include "utilitaires.h"
104 #include "graphique.h"
105 #include "unites.h"
106
107 namespace Lorene {
108 // Local prototype
109 Cmp raccord_c1(const Cmp& uu, int l1) ;
110 }
111 //******************************************************************************
112
113 using namespace Lorene ;
114
115 int main(){
116
117 using namespace Unites ;
118
119 // Identification of all the subroutines called by the code :
120
121 system("ident coal_regu > identif.d") ;
122
123 // For the display :
124 char display_bold[]="x[1m" ; display_bold[0] = 27 ;
125 char display_normal[] = "x[0m" ; display_normal[0] = 27 ;
126
127 //------------------------------------------------------------------
128 // Parameters of the computation
129 //------------------------------------------------------------------
130
131 char nomini[80] ;
132 int mermax, mermax_eqb, prompt, graph, fmer_stop, fmer_save, mermax_poisson ;
133 int mermax_potvit, mer_masse, fmer_upd_met, ind_rel_met ;
134 double seuil, relax_poisson, relax_potvit, relax, aexp_masse ;
135 double mbar_voulue[2], fact_separ, relax_met, relax_omeg ;
136 double fact_omeg_min, fact_omeg_max, thres_adapt[2], reduce_shift ;
137
138 ifstream fpar("parcoal.d") ;
139 if ( !fpar.good() ) {
140 cout << "Problem with opening the file parcoal.d ! " << endl ;
141 abort() ;
142 }
143 fpar.ignore(1000, '\n') ;
144 fpar.ignore(1000, '\n') ;
145 fpar.getline(nomini, 80) ;
146 fpar >> fact_separ ; fpar.ignore(1000, '\n');
147 fpar >> mbar_voulue[0] ; fpar.ignore(1000, '\n') ;
148 fpar >> mbar_voulue[1] ; fpar.ignore(1000, '\n') ;
149 mbar_voulue[0] *= msol ;
150 mbar_voulue[1] *= msol ;
151 fpar.ignore(1000, '\n') ;
152 fpar >> mermax ; fpar.ignore(1000, '\n') ;
153 fpar >> relax ; fpar.ignore(1000, '\n') ;
154 fpar >> mermax_eqb ; fpar.ignore(1000, '\n') ;
155 fpar >> prompt ; fpar.ignore(1000, '\n') ;
156 fpar >> graph ; fpar.ignore(1000, '\n') ;
157 fpar >> seuil ; fpar.ignore(1000, '\n') ;
158 fpar >> fmer_stop ; fpar.ignore(1000, '\n') ;
159 fpar >> fmer_save ; fpar.ignore(1000, '\n') ;
160 fpar >> mermax_poisson ; fpar.ignore(1000, '\n') ;
161 fpar >> relax_poisson ; fpar.ignore(1000, '\n') ;
162 fpar >> mermax_potvit ; fpar.ignore(1000, '\n') ;
163 fpar >> relax_potvit ; fpar.ignore(1000, '\n') ;
164 fpar >> mer_masse ; fpar.ignore(1000, '\n') ;
165 fpar >> aexp_masse ; fpar.ignore(1000, '\n') ;
166 fpar >> fmer_upd_met ; fpar.ignore(1000, '\n');
167 fpar >> ind_rel_met ; fpar.ignore(1000, '\n');
168 fpar >> relax_met ; fpar.ignore(1000, '\n');
169 if (ind_rel_met == 0) relax_met = 1. ;
170 fpar >> relax_omeg ; fpar.ignore(1000, '\n');
171 fpar >> fact_omeg_min ; fpar.ignore(1000, '\n');
172 fpar >> fact_omeg_max ; fpar.ignore(1000, '\n');
173 fpar >> thres_adapt[0] ; fpar.ignore(1000, '\n');
174 fpar >> thres_adapt[1] ; fpar.ignore(1000, '\n');
175 fpar >> reduce_shift ;
176 if ( ! fpar.good() ) { // to ensure compatibility with old
177 reduce_shift = 0.6 ; // parcoal.d files which did not had
178 } // the reduce_shift line
179 fpar.close() ;
180
181 cout << endl
182 << "==========================================================" << endl
183 << " Physical parameters " << endl
184 << "=========================================================="
185 << endl ;
186 cout << endl << endl ;
187 cout << "File containing the initial conditions : " << nomini << endl ;
188 cout << "Factor by which the initial separation will be multiplied : "
189 << fact_separ << endl ;
190 if ( abs(mer_masse) < mermax ) {
191 cout << "Baryon mass required for star 1 [M_sol] : "
192 << mbar_voulue[0] / msol << endl ;
193 cout << "Baryon mass required for star 2 [M_sol] : "
194 << mbar_voulue[1] / msol << endl ;
195 }
196 cout << endl
197 << "==========================================================" << endl
198 << " Parameters of the computation " << endl
199 << "=========================================================="
200 << endl ;
201 cout << "Maximum number of steps in the main iteration : "
202 << mermax << endl ;
203 cout << "Relaxation factor in the main iteration : "
204 << relax << endl ;
205 cout << "Maximum number of steps in Etoile_bin::equil_regular : "
206 << mermax_eqb << endl ;
207 cout << "Threshold on the enthalpy relative change for ending the computation : "
208 << seuil << endl ;
209 cout << "Step interval between safeguards of the whole configuration : "
210 << fmer_save << endl ;
211 cout << "Maximum number of steps in Map_et::poisson : "
212 << mermax_poisson << endl ;
213 cout << "Relaxation factor in Map_et::poisson : "
214 << relax_poisson << endl ;
215 cout << "Maximum number of steps in Map_radial::poisson_compact : "
216 << mermax_potvit << endl ;
217 cout << "Relaxation factor in Map_radial::poisson_compact : "
218 << relax_potvit << endl ;
219 cout << "Step from which the baryon mass is forced to converge : "
220 << mer_masse << endl ;
221 cout << "Exponent for the increase factor of the central enthalpy : "
222 << aexp_masse << endl ;
223 cout << "Step interval between metric updates : "
224 << fmer_upd_met << endl ;
225 if (ind_rel_met == 1) {
226 cout << "Relaxation factor of the metric : "
227 << relax_met << endl ;
228 }
229 else {
230 cout << "No relaxation on the metric" << endl ;
231 }
232 cout << "Relaxation factor on Omega (orbital angular velocity) : "
233 << relax_omeg << endl ;
234 cout << "Relative low bound in the omega search : "
235 << fact_omeg_min << endl ;
236 cout << "Relative high bound in the omega search : "
237 << fact_omeg_max << endl ;
238 cout <<
239 "Threshold on |dH/dr|_eq / |dH/dr|_pole for the adaptation of the mapping for star 1"
240 << endl << thres_adapt[0] << endl ;
241 cout <<
242 "Threshold on |dH/dr|_eq / |dH/dr|_pole for the adaptation of the mapping for star 2"
243 << endl << thres_adapt[1] << endl ;
244 cout << "Factor by which the initial analytical shift is reduced : "
245 << reduce_shift << endl ;
246
247 arrete(prompt) ;
248
249 //------------------------------------------------------------------
250 // Read of the initial conditions
251 //------------------------------------------------------------------
252
253 FILE* fich = fopen(nomini, "r") ;
254 if (fich == 0x0) {
255 cout << "Problem in opening the file " << nomini << " ! " << endl ;
256 perror(" reason") ;
257 abort() ;
258 }
259
260 int mer_ini ;
261 fread(&mer_ini, sizeof(int), 1, fich) ;
262
263 Mg3d mg1(fich) ;
264 Map_et mp1(mg1, fich) ;
265 Eos* peos1 = Eos::eos_from_file(fich) ;
266
267 Mg3d mg2(fich) ;
268 Map_et mp2(mg2, fich) ;
269 Eos* peos2 = Eos::eos_from_file(fich) ;
270
271 Binaire star(mp1, *peos1, mp2, *peos2, fich) ;
272
273 fclose(fich) ;
274
275 //------------------------------------------------------------------
276 // Modification of the separation between the two stars
277 //------------------------------------------------------------------
278
279 for (int i=1 ; i<=2 ; i++) {
280
281 double ori_x = (star(i).get_mp()).get_ori_x() ;
282 ori_x *= fact_separ ;
283 ((star.set(i)).set_mp()).set_ori(ori_x, 0., 0.) ;
284 }
285
286 //------------------------------------------------------------------
287 // Update of the initial conditions
288 //------------------------------------------------------------------
289
290 // Initialisation of A^2, N, etc...
291 // ---------------------------------
292 for (int i=1; i<=2; i++) {
293 (star.set(i)).update_metric(star(3-i)) ;
294 }
295
296 // Initialisation of gradients of companion potentials
297 // ---------------------------------------------------
298
299 for (int i=1; i<=2; i++) {
300 (star.set(i)).update_metric_der_comp(star(3-i)) ;
301 }
302
303 // Initialisation of hydro quantities
304 // ----------------------------------
305
306 for (int i=1; i<=2; i++) {
307 (star.set(i)).equation_of_state() ;
308 (star.set(i)).kinematics(star.get_omega(), star.get_x_axe()) ;
309 (star.set(i)).fait_d_psi() ;
310 (star.set(i)).hydro_euler() ;
311 }
312
313 // If the shift vector has not been set previously, it is set to
314 // some analytical value
315 // -------------------------------------------------------------
316
317 if (star(1).get_w_shift()(1).get_etat() == ETATZERO) {
318
319 assert( star(1).get_w_shift()(0).get_etat() == ETATZERO ) ;
320 assert( star(1).get_w_shift()(2).get_etat() == ETATZERO ) ;
321
322 assert( star(2).get_w_shift()(0).get_etat() == ETATZERO ) ;
323 assert( star(2).get_w_shift()(1).get_etat() == ETATZERO ) ;
324 assert( star(2).get_w_shift()(2).get_etat() == ETATZERO ) ;
325
326
327 // New initial of value Omega (taking into account the fact
328 // that the separation has changed)
329
330 star.analytical_omega() ;
331
332 // Sets some value to w_shift and khi_shift corresponding to the
333 // new values of Omega and separation
334
335 star.analytical_shift() ;
336
337 // Initial shift decreased by a factor reduce_shift
338 for (int i=1; i<=2; i++) {
339 star.set(i).set_w_shift() = reduce_shift * star(i).get_w_shift() ;
340 star.set(i).set_khi_shift() = reduce_shift * star(i).get_khi_shift() ;
341 }
342
343
344 // Computes shift_auto from w_shift and khi_shift
345 for (int i=1; i<=2; i++) {
346 (star.set(i)).fait_shift_auto() ;
347 }
348
349 // A second call to update_metric must be performed to update
350 // shift_comp, tkij_auto and akcar_auto.
351 for (int i=1; i<=2; i++) {
352 (star.set(i)).update_metric(star(3-i)) ;
353 }
354
355 // Second update of gradients of companion potentials
356
357 for (int i=1; i<=2; i++) {
358 (star.set(i)).update_metric_der_comp(star(3-i)) ;
359 }
360
361 // Second update of hydro quantities
362
363 for (int i=1; i<=2; i++) {
364 (star.set(i)).equation_of_state() ;
365 (star.set(i)).kinematics(star.get_omega(), star.get_x_axe()) ;
366 (star.set(i)).fait_d_psi() ;
367 (star.set(i)).hydro_euler() ;
368 }
369
370
371 } // End of the setting of an analytical shift
372
373
374 //##
375 FILE* fresu = fopen("resu.d", "w") ;
376
377 int mer1 = 0 ;
378 fwrite(&mer1, sizeof(int), 1, fresu) ; // mer
379
380 star(1).get_mp().get_mg()->sauve(fresu) ;
381 star(1).get_mp().sauve(fresu) ;
382 star(1).get_eos().sauve(fresu) ;
383
384 star(2).get_mp().get_mg()->sauve(fresu) ;
385 star(2).get_mp().sauve(fresu) ;
386 star(2).get_eos().sauve(fresu) ;
387
388 star.sauve(fresu) ;
389
390 fclose(fresu) ;
391 //##
392
393 cout << endl
394 << "==========================================================" << endl
395 << " Initial conditions " << endl
396 << "=========================================================="
397 << endl ;
398 cout << star << endl ;
399
400 if ( star(1).is_relativistic() ) {
401 cout << "========================" << endl ;
402 cout << "Relativistic computation" << endl ;
403 cout << "========================" << endl ;
404 }
405 else {
406 cout << "=====================" << endl ;
407 cout << "Newtonian computation" << endl ;
408 cout << "=====================" << endl ;
409 }
410
411 arrete(prompt) ;
412
413
414 //----------------------------------------------------------------
415 // Auxiliary quantities
416 //----------------------------------------------------------------
417
418 double ent_c[2] ; // Central enthalpy in each star
419 double dentdx[2] ; // Central d/dx(enthalpy) in each star
420
421 // Resizing factor of the first shell
422 // Computation is shown just befor "equilibrium"
423 Tbl fact_resize[] = {Tbl(1), Tbl(1)} ;
424 fact_resize[0].set_etat_qcq() ;
425 fact_resize[1].set_etat_qcq() ;
426
427 // Error indicators in each star
428 Tbl differ[] = {Tbl(7), Tbl(7)} ;
429 differ[0].set_etat_qcq() ;
430 differ[1].set_etat_qcq() ;
431
432 for (int i=1 ; i<=2 ; i++) {
433 ent_c[i-1] = star(i).get_ent()()(0, 0, 0, 0) ;
434 differ[i-1].set(0) = 1 ; // diff_ent = 1
435 differ[i-1].set(1) = 1 ; // err_psi = 1
436 differ[i-1].set(2) = 1 ; // err_logn = 1
437 differ[i-1].set(3) = 1 ; // err_beta = 1
438 differ[i-1].set(4) = 1 ; // err_shift_x = 1
439 differ[i-1].set(5) = 1 ; // err_shift_y = 1
440 differ[i-1].set(6) = 1 ; // err_shift_z = 1
441 }
442
443 double relax_jm1 = 1. - relax ;
444 double relax_omeg_jm1 = 1. - relax_omeg ;
445
446 //----------------------------------------------------------------
447 // Binary system at the previous step (for the relaxation)
448 //----------------------------------------------------------------
449
450 Binaire star_jm1 = star ;
451
452 double omega_jm1 = star_jm1.get_omega() ;
453
454
455 // logn_comp and pot_centri are initialized to 0 on star_jm1 :
456 // ---------------------------------------------------------
457 for (int i=1 ; i<=2 ; i++) {
458 star_jm1.set(i).set_logn_comp() = 0 ;
459 star_jm1.set(i).set_pot_centri() = 0 ;
460 }
461
462 //----------------------------------------------------------------
463 // Openning of log files
464 //----------------------------------------------------------------
465
466 ofstream fichresu("resglob.d") ;
467 fichresu.precision(16) ;
468
469 ofstream fichrota("resrota.d") ;
470 fichrota.precision(16) ;
471
472 ofstream fichvir("resdiffm.d") ;
473 fichvir.precision(16) ;
474
475 ofstream fichconv[2] ;
476 fichconv[0].open("resconv1.d") ;
477 fichconv[0].precision(16) ;
478 fichconv[1].open("resconv2.d") ;
479 fichconv[1].precision(16) ;
480
481 ofstream fichet[2] ;
482 fichet[0].open("resstar1.d") ;
483 fichet[0].precision(16) ;
484 fichet[1].open("resstar2.d") ;
485 fichet[1].precision(16) ;
486
487 fichrota <<
488 "# 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]"
489 << endl ;
490
491 fichvir <<
492 "# diff_mass"
493 << endl ;
494
495 for (int i=1; i<=2; i++) {
496 fichconv[i-1] <<
497 "# diff_ent err_psi err_logn err_beta err_shift_x err_shift_y err_shift_z"
498 << endl ;
499
500 fichet[i-1] <<
501 "# 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]"
502 << endl ;
503 }
504
505 double omega_kep, diff_mass ;
506 int mer ;
507
508 //============================================================================
509 // Start of iteration
510 //============================================================================
511
512 for (mer=0; (differ[0](0) > seuil) && (mer < mermax); mer++) {
513
514 cout <<
515 "=========================================================================="
516 << endl ;
517 cout << "step = " << mer << " diff_ent (1) (2) (1)<->(2) : "
518 << differ[0](0) << " " << differ[1](0) << " "
519 << differ[0](0) - differ[1](0) << endl ;
520 cout <<
521 "=========================================================================="
522 << endl ;
523
524 fichresu << mer;
525 fichresu << " step" << endl ;
526
527 fichrota << mer ;
528 fichvir << mer ;
529 fichconv[0] << mer ;
530 fichconv[1] << mer ;
531 fichet[0] << mer ;
532 fichet[1] << mer ;
533
534
535 //------------------------------------------------------------------
536 // Computation of the metric coefficients
537 //------------------------------------------------------------------
538
539 if ( (mer % fmer_upd_met) == 0 ) {
540
541 for (int i=1; i<=2; i++) {
542 (star.set(i)).update_metric(star(3-i), star_jm1(i), relax_met) ;
543 }
544
545 for (int i=1; i<=2; i++) {
546 (star.set(i)).update_metric_der_comp(star(3-i)) ;
547 }
548
549 }
550
551
552 //------------------------------------------------------------------
553 // Computation of the orbital angular velocity Omega
554 //------------------------------------------------------------------
555
556 double xgg[2] ;
557
558 star.orbit(fact_omeg_min, fact_omeg_max, xgg[0], xgg[1]) ;
559
560 // Translation of the stars in order to set the origin
561 // of the absolute frame on the rotation axis
562 //-----------------------------------------------------
563
564 double x_rot = star.get_x_axe() ;
565
566 for (int i=1 ; i<=2 ; i++) {
567 double ori_x_old = (star(i).get_mp()).get_ori_x() ;
568 double ori_x_new = ori_x_old - x_rot ;
569 ((star.set(i)).set_mp()).set_ori(ori_x_new, 0., 0.) ;
570 }
571
572 star.set_x_axe() = 0. ;
573
574 // Relaxation on the orbital velocity
575 // ----------------------------------
576
577 double omega_j = star.get_omega() ;
578 omega_j = relax_omeg * omega_j + relax_omeg_jm1 * omega_jm1 ;
579 omega_jm1 = omega_j ;
580
581 star.set_omega() = omega_j ;
582
583 cout << display_bold << "New orbital velocity Omega : "
584 << star.get_omega() * f_unit << " rad/s" << display_normal << endl ;
585
586 // Keplerian velocity (for comparison only)
587 // ----------------------------------------
588 omega_kep = sqrt( g_si/g_unit * (star(1).mass_g() + star(2).mass_g())
589 / pow( star.separation(), 3.) ) ;
590
591 cout << "``Keplerian'' velocity (for comparison only) : "
592 << omega_kep * f_unit << " rad/s" << endl ;
593 cout << "New X coordinate of the rotation axis : "
594 << star.get_x_axe() / km << " km" << endl ;
595
596 arrete(prompt) ;
597
598 fichresu << star.get_x_axe() / km ;
599 fichresu << " abscidia of the rotation axis [km] " << endl ;
600
601 fichresu << star.get_omega() * f_unit ;
602 fichresu << " Orbital frequency Omega [rad/s] " << endl ;
603
604 fichresu << xgg[0] / km ;
605 fichresu << " Abscidia ``center of mass'' star 1 [km] " << endl ;
606
607 fichresu << xgg[1] / km ;
608 fichresu << " Abscidia ``center of mass'' star 2 [km] " << endl ;
609
610 fichrota << " " << star.get_omega() * f_unit ;
611 fichrota << " " << star.get_x_axe() / km ;
612 fichrota << " " << xgg[0] / km ;
613 fichrota << " " << xgg[1] / km ;
614
615 //------------------------------------------------------------------
616 // Computation of B^i/N (bsn) and pot_centri in each star
617 //------------------------------------------------------------------
618
619 for (int i=1; i<=2; i++) {
620
621 (star.set(i)).kinematics( star.get_omega(), star.get_x_axe() ) ;
622
623 }
624
625 //------------------------------------------------------------------
626 // Computation of gam_euler, u_euler, ener_euler, s_euler,
627 // wit_w and loggam in each star
628 //------------------------------------------------------------------
629
630 for (int i=1; i<=2; i++) {
631
632 (star.set(i)).fait_d_psi() ;
633 (star.set(i)).hydro_euler() ;
634
635 // Check of the Binaire::orbit computation
636 //----------------------------------------
637
638 Cmp tmp = star(i).get_logn_auto()() + star(i).get_logn_comp()()
639 + star(i).get_loggam()() ;
640 double grad1 = tmp.dsdx()(0, 0, 0, 0) ;
641
642 double grad2 = star(i).get_pot_centri()().dsdx()(0, 0, 0, 0) ;
643
644 dentdx[i-1] = star(i).get_ent()().dsdx()(0, 0, 0, 0) ;
645
646 double grad3 = star(i).get_loggam()().dsdx()(0, 0, 0, 0) ;
647
648 cout << "Star " << i << " : " << endl ;
649 cout << " central dH/dx : " << dentdx[i-1] << endl ;
650 cout << " central d(log(Gam))/dx : " << grad3 << endl ;
651 cout << " central d/dx(nu + log(Gam)) : " << grad1 << endl ;
652 cout << " central d/dx(pot_centri) : " << grad2 << endl ;
653 cout << " central d/dx(nu + log(Gam) + pot_centri) : "
654 << grad1 + grad2 << endl ;
655
656 }
657
658 // Check the accuracy of d_logn_auto
659
660 /*
661 for (int i=1; i<=2; i++) {
662 Tenseur dlna_ana = star(i).get_d_logn_auto() ;
663 Tenseur dlna_num = (star(i).get_logn_auto()).gradient() ;
664 dlna_num.change_triad( *(dlna_ana.get_triad()) ) ;
665
666 for (int j=0; j<=2; j++) {
667
668 Cmp dlnaana = dlna_ana(j) ;
669 Cmp dlnanum = dlna_num(j) ;
670 Cmp ddiff = dlna_ana(j) - dlna_num(j) ;
671 Cmp diverg = star(i).get_d_logn_auto_div()(j) ;
672 Cmp regu = star(i).get_d_logn_auto_regu()(j) ;
673
674 cout << "max(dlnaana) : " << max(dlnaana) << endl ;
675 cout << "max(dlnanum) : " << max(dlnanum) << endl ;
676
677 cout << "max(diff) : " << max(ddiff) << endl ;
678 cout << "max(diverg) : " << max(diverg) << endl ;
679 cout << "max(regu) : " << max(regu) << endl ;
680
681 Tbl tdiff = diffrel(dlna_ana(j), dlna_num(j)) ;
682 cout <<
683 "Relative error in the resolution of d_logn_auto(" << j << ") : "
684 << endl ;
685 for (int l=0; l<3; l++) {
686 cout << tdiff(l) << " " ;
687 }
688 cout << endl ;
689 }
690
691 // arrete() ;
692 }
693 */
694
695 //------------------------------------------------------------------
696 // Computation of the stellar equilibrium configurations
697 //------------------------------------------------------------------
698
699 for (int i=1; i<=2; i++) {
700
701 // Computation of the resizing factor
702 double ray_eq_auto = star(i).ray_eq() ;
703 double ray_eq_comp = star(3-i).ray_eq() ;
704
705 int num_resize ;
706
707 if (mg1.get_nzone() > 3) {
708 assert( mg2.get_nzone() == mg1.get_nzone() ) ;
709 num_resize = mg1.get_nzone() -3 ;
710 }
711 else {
712 num_resize = star(i).get_nzet() ;
713 }
714
715 double lambda_resize = 0.95 *
716 (star.separation() - ray_eq_comp)/ray_eq_auto ;
717 fact_resize[i-1].set(0) =
718 (lambda_resize < 2.*num_resize) ? lambda_resize : 2.*num_resize ;
719
720 }
721
722 for (int i=1; i<=2; i++) {
723
724 // Relaxation on logn_comp (only if it has not been done by
725 // update_metric)
726 // --------------------------------------------------------
727 if ( (ind_rel_met == 0) || ( (mer % fmer_upd_met) != 0 ) ) {
728 star.set(i).set_logn_comp() = relax * star(i).get_logn_comp()
729 + relax_jm1 * star_jm1(i).get_logn_comp() ;
730 }
731
732 // Relaxation on pot_centri
733 // ------------------------
734 star.set(i).set_pot_centri() = relax * star(i).get_pot_centri()
735 + relax_jm1 * star_jm1(i).get_pot_centri() ;
736
737
738 // Call to Etoile_bin::equil_regular
739 // ---------------------------------
740
741 (star.set(i)).equil_regular(ent_c[i-1], mermax_eqb, mermax_poisson,
742 relax_poisson, mermax_potvit,
743 relax_potvit, thres_adapt[i-1],
744 fact_resize[i-1], differ[i-1]) ;
745
746 }
747
748
749 //------------------------------------------------------------------
750 // Relaxations
751 //------------------------------------------------------------------
752
753 for (int i=1; i<=2; i++) {
754
755 star.set(i).relaxation( star_jm1(i), relax, relax_met, mer,
756 fmer_upd_met ) ;
757
758 star.set(i).hydro_euler() ;
759 }
760
761 //------------------------------------------------------------------
762 // Change in the central enthalpy to get a fixed baryon mass
763 //------------------------------------------------------------------
764
765 if (mer >= mer_masse) {
766
767 for (int i=1; i<=2; i++) {
768
769 double xx = star(i).mass_b() / mbar_voulue[i-1] - 1. ;
770
771 cout << "Discrepancy M_b / wanted M_b : " << xx << endl ;
772
773 double xprog = ( mer > 2*mer_masse) ? 1. :
774 double(mer-mer_masse)/double(mer_masse) ;
775 xx *= xprog ;
776 double ax = .5 * ( 2. + xx ) / (1. + xx ) ;
777
778 double fact_ent = pow(ax, aexp_masse) ;
779
780 cout << " xprog, xx, ax, fact : " << xprog << " " <<
781 xx << " " << ax << " " << fact_ent << endl ;
782
783 ent_c[i-1] *= fact_ent ;
784
785 }
786 }
787
788 // Updates for the next step
789 // -------------------------
790
791 star_jm1 = star ;
792
793
794 cout << star << endl ;
795
796
797 // Graphical output
798 // ----------------
799
800 if ( (graph==1) && (mer % 5 == 0) ) {
801 double xdes_min = - star(1).ray_eq_pi() + star(1).get_mp().get_ori_x() ;
802 xdes_min *= 1.5 ;
803 double xdes_max = star(2).ray_eq_pi() + star(2).get_mp().get_ori_x() ;
804 xdes_max *= 1.5 ;
805 double ydes_min = - 2.5 * star(1).ray_eq_pis2() ;
806 double ydes_max = 2.5 * star(2).ray_eq_pis2() ;
807
808 Cmp surf1 = star(1).get_ent()() ;
809 Cmp surf1_ext(mp1) ;
810 surf1_ext = - 0.2 * surf1(0, 0, 0, 0) ;
811 surf1_ext.annule(0, star(1).get_nzet()-1) ;
812 surf1.annule(star(1).get_nzet(), mg1.get_nzone()-1) ;
813 surf1 = surf1 + surf1_ext ;
814
815 surf1 = raccord_c1(surf1, star(1).get_nzet()) ;
816
817 Cmp surf2 = star(2).get_ent()() ;
818 Cmp surf2_ext(mp2) ;
819 surf2_ext = - 0.2 * surf2(0, 0, 0, 0) ;
820 surf2_ext.annule(0, star(2).get_nzet()-1) ;
821 surf2.annule(star(2).get_nzet(), mg2.get_nzone()-1) ;
822 surf2 = surf2 + surf2_ext ;
823
824 surf2 = raccord_c1(surf2, star(2).get_nzet()) ;
825
826 des_coupe_bin_z(star(1).get_nbar()(), star(2).get_nbar()(), 0.,
827 xdes_min, xdes_max, ydes_min, ydes_max,
828 "Baryon density (z=0)", &surf1, &surf2 ) ;
829
830 des_coupe_bin_y(star(1).get_nbar()(), star(2).get_nbar()(), 0.,
831 xdes_min, xdes_max, ydes_min, ydes_max,
832 "Baryon density (y=0)", &surf1, &surf2 ) ;
833 }
834
835
836
837 //-----------------------------------------------------------------------
838 // The whole configuration is saved in a file
839 //-----------------------------------------------------------------------
840
841 if ( (mer % fmer_save) == 0 ) {
842
843 FILE* fresu = fopen("resu.d", "w") ;
844
845 fwrite(&mer, sizeof(int), 1, fresu) ; // mer
846
847 star(1).get_mp().get_mg()->sauve(fresu) ;
848 star(1).get_mp().sauve(fresu) ;
849 star(1).get_eos().sauve(fresu) ;
850
851 star(2).get_mp().get_mg()->sauve(fresu) ;
852 star(2).get_mp().sauve(fresu) ;
853 star(2).get_eos().sauve(fresu) ;
854
855 star.sauve(fresu) ;
856
857 fclose(fresu) ;
858 }
859
860 //--------------------------------------------
861 // Writing of global quantities in log files
862 //--------------------------------------------
863 for (int i=1 ; i<=2 ; i++) {
864 fichresu << star(i).mass_b() / msol ;
865 fichresu << " Baryon mass of star " << i << " [M_sol] " << endl ;
866 fichresu << differ[i-1](0) ;
867 fichresu << " relative variation enth. star " << i << endl ;
868
869 fichresu << star(i).ray_pole() / km ;
870 fichresu << " R(theta=0) [km] " << endl ;
871 fichresu << star(i).ray_eq() / km ;
872 fichresu << " R(theta=pi/2, phi=0) [km] " << endl ;
873 fichresu << star(i).ray_eq_pis2() / km ;
874 fichresu << " R(theta=pi/2, phi=pi/2) [km] " << endl ;
875 fichresu << star(i).ray_eq_pi() / km ;
876 fichresu << " R(theta=pi/2, phi=pi) [km] " << endl ;
877
878 fichconv[i-1] << " " << log10( fabs(differ[i-1](0)) + 1.e-16 ) ;
879 fichconv[i-1] << " " << log10( fabs(differ[i-1](1)) + 1.e-16 ) ;
880 fichconv[i-1] << " " << log10( fabs(differ[i-1](2)) + 1.e-16 ) ;
881 fichconv[i-1] << " " << log10( fabs(differ[i-1](3)) + 1.e-16 ) ;
882 fichconv[i-1] << " " << log10( fabs(differ[i-1](4)) + 1.e-16 ) ;
883 fichconv[i-1] << " " << log10( fabs(differ[i-1](5)) + 1.e-16 ) ;
884 fichconv[i-1] << " " << log10( fabs(differ[i-1](6)) + 1.e-16 ) ;
885
886 fichet[i-1] << " " << star(i).get_mp().get_ori_x() / km ;
887 fichet[i-1] << " " << ent_c[i-1] ;
888 fichet[i-1] << " " << star(i).mass_b() / msol ;
889 fichet[i-1] << " " << star(i).ray_pole() / km ;
890 fichet[i-1] << " " << star(i).ray_eq() / km ;
891 fichet[i-1] << " " << star(i).ray_eq_pis2() / km ;
892 fichet[i-1] << " " << star(i).ray_eq_pi() / km ;
893
894 } // End of loop on the stars
895
896 diff_mass = ( star(2).mass_b() - star(1).mass_b() )
897 / star(1).mass_b() ;
898 cout << "Relative difference between the baryon masses: "
899 << diff_mass << endl ;
900 fichresu << diff_mass ;
901 fichresu << " Relative difference between the baryon masses" << endl ;
902
903 fichvir << " " << log10( fabs(diff_mass) + 1.e-16 ) ;
904
905
906 fichresu << " " << endl ;
907 fichresu.flush() ;
908 fichrota << " " << endl ;
909 fichrota.flush() ;
910 fichvir << " " << endl ;
911 fichvir.flush() ;
912 fichconv[0] << " " << endl ;
913 fichconv[0].flush() ;
914 fichconv[1] << " " << endl ;
915 fichconv[1].flush() ;
916 fichet[0] << " " << endl ;
917 fichet[0].flush() ;
918 fichet[1] << " " << endl ;
919 fichet[1].flush() ;
920
921 } // End of the main loop (mer)
922
923 //============================================================================
924 // End of iteration
925 //============================================================================
926
927 fichresu.close() ;
928 fichrota.close() ;
929 fichvir.close() ;
930 fichconv[0].close() ;
931 fichconv[1].close() ;
932 fichet[0].close() ;
933 fichet[1].close() ;
934
935
936 //-----------------------------------------------
937 // General features of the final configuration
938 // saved in a file
939 //-----------------------------------------------
940
941 ofstream fichfinal("calcul.d") ;
942 fichfinal.precision(6) ;
943
944 time_t rawtime = time(0x0) ;
945 fichfinal << "Date: " << asctime( localtime( &rawtime ) ) << endl ;
946 char* hostname = getenv("HOST") ;
947 if (hostname != 0x0) {
948 fichfinal << "Computer: " << hostname << endl ;
949 }
950 fichfinal <<
951 "==================================================================="
952 << endl << endl ;
953
954 if ( star(1).is_relativistic() ) {
955 fichfinal << "Relativistic computation" ;
956 }
957 else {
958 fichfinal << "Newtonian computation" ;
959 }
960
961 if ( star(1).is_irrotational() ) {
962 fichfinal << " Irrotational" << endl ;
963 }
964 else {
965 fichfinal << " Co-rotating" << endl ;
966 }
967
968 fichfinal << star(1).get_eos() << endl ;
969
970 fichfinal << "Omega = " << star.get_omega() * f_unit << " rad/s"
971 << " Orbital frequency f = "
972 << star.get_omega() / (2*M_PI) * f_unit << " Hz" << endl ;
973 fichfinal << "Omega_kepler = " << omega_kep * f_unit << " rad/s" << endl ;
974 fichfinal << "Coordinate separation : " << star.separation() / km
975 << " km" << endl ;
976 fichfinal << "1/2 ADM mass : " << 0.5 * star.mass_adm() / msol
977 << " Mo" << endl ;
978 fichfinal << "Total angular momentum : "
979 << star.angu_mom()(2)/ ( qpig / (4* M_PI) * msol*msol)
980 << " G M_sol^2 / c" << endl ;
981
982 fichfinal << endl << "Number of steps : " << mer << endl ;
983
984 for (int i=1 ; i<=2; i++) {
985 fichfinal << endl <<
986 "==================================================================="
987 << endl ;
988 fichfinal << " Star no. " << i << endl ;
989 fichfinal <<
990 "==================================================================="
991 << endl ;
992 fichfinal << "Grid : " << endl ;
993 fichfinal << "------ " << endl ;
994 fichfinal << *(star(i).get_mp().get_mg()) << endl ;
995 fichfinal << endl << "Physical characteristics : " << endl ;
996 fichfinal << "-------------------------" << endl ;
997 fichfinal << star(i) << endl ;
998 }
999 fichfinal << endl ;
1000
1001 star.display_poly(fichfinal) ; // Reduced quantities for polytropic EOS
1002
1003 fichfinal << endl <<
1004 "==================================================================="
1005 << endl ;
1006 fichfinal << "Diff_ent : star 1 : " << differ[0](0) << " star 2 : "
1007 << differ[1](0) << endl ;
1008 fichfinal <<
1009 "Relative difference between the baryon masses of the two stars : "
1010 << diff_mass << endl ;
1011 fichfinal << "dH/dx at r = 0 : star 1 : " << dentdx[0]
1012 << " star 2 : " << dentdx[1] << endl ;
1013
1014 if ( star(1).is_relativistic() ) {
1015 fichfinal << "Relative error on the virial theorem : " << endl ;
1016 fichfinal << " VE(M)= " << star.virial()
1017 << " VE(GB)= "<< star.virial_gb()
1018 << " VE(FUS)= " << star.virial_fus() << endl ;
1019 }
1020 else {
1021 fichfinal << "Relative error on the virial theorem : "
1022 << star.virial() << endl ;
1023 }
1024
1025 fichfinal << endl <<
1026 "================================================================" << endl ;
1027 fichfinal << " PARAMETERS USED FOR THE COMPUTATION : " << endl ;
1028 fichfinal <<
1029 "================================================================" << endl ;
1030 fichfinal.close() ;
1031 system("cat parcoal.d >> calcul.d") ;
1032
1033 // Identification du code et de ses sous-routines (no. de version RCS) :
1034 fichfinal.open("calcul.d", ios::app) ;
1035 fichfinal << endl <<
1036 "================================================================" << endl ;
1037 fichfinal << " IDENTIFICATION OF THE CODE : " << endl ;
1038 fichfinal <<
1039 "================================================================" << endl ;
1040 fichfinal.close() ;
1041 system("ident coal_regu >> calcul.d") ;
1042
1043 // Preparation for CPU infos printing :
1044 fichfinal.open("calcul.d", ios::app ) ;
1045 fichfinal << endl <<
1046 "================================================================" << endl ;
1047 fichfinal << " CPU TIME and MEMORY infos : " << endl ;
1048 fichfinal <<
1049 "================================================================" << endl ;
1050 fichfinal << endl ;
1051 fichfinal.close() ;
1052
1053 //-----------------------------------------------
1054 // General features of the final configuration
1055 // saved in a file with scientific notation and
1056 // 14 digits for further reading by a code
1057 //-----------------------------------------------
1058
1059 ofstream seqfich("resformat.d") ;
1060 if ( !seqfich.good() ) {
1061 cout << "coal_regu : problem with opening the file resformat.d !" << endl ;
1062 abort() ;
1063 }
1064 star.write_global(seqfich) ;
1065 seqfich.close() ;
1066
1067
1068 if (graph == 1) {
1069
1070 // des_explorer(star, "latbin") ;
1071
1072 //## double xdes_min = - star(1).ray_eq_pi() + star(1).get_mp().get_ori_x() ;
1073 // xdes_min *= 1.5 ;
1074 // double xdes_max = star(2).ray_eq_pi() + star(2).get_mp().get_ori_x() ;
1075 // xdes_max *= 1.5 ;
1076 // double ydes_min = - 2.5 * star(1).ray_eq_pis2() ;
1077 // double ydes_max = 2.5 * star(2).ray_eq_pis2() ;
1078 //
1079 // des_coupe_bin_z(star(1).get_nbar()(), star(2).get_nbar()(), 0,
1080 // xdes_min, xdes_max, ydes_min, ydes_max, "density (z=0)",
1081 // &(star(1).get_ent()()), &(star(2).get_ent()()) ) ;
1082 //
1083 // des_coupe_bin_z(star(1).get_logn_auto()(), star(2).get_logn_auto()(), 0,
1084 // xdes_min, xdes_max, ydes_min, ydes_max, "ln(N) (z=0)",
1085 // &(star(1).get_ent()()), &(star(2).get_ent()()) ) ;
1086 //
1087 // des_coupe_z(star(1).get_logn_comp()(), 0., 1, "logn_comp (z=0)",
1088 //## &(star(1).get_ent()()) ) ;
1089
1090 }
1091
1092 // Cleaning
1093 // --------
1094
1095 delete peos1 ;
1096 delete peos2 ;
1097
1098 return EXIT_SUCCESS ;
1099
1100 }