Debian Codegraph @

Codes/Bin_star/test_darwin.C

raw
1 /*
2 * Test program for solving Darwin-like binaries
3 * Fixing the orbital separation and the central value of the star
4 * The case of the identical star binary
5 */
6
7 /*
8 * Copyright (c) 1999-2001 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 test_darwin_C[] = "$Header: /cvsroot/Lorene/Codes/Bin_star/test_darwin.C,v 1.3 2014/10/06 15:09:43 j_novak Exp $" ;
29
30 /*
31 * $Id: test_darwin.C,v 1.3 2014/10/06 15:09:43 j_novak Exp $
32 * $Log: test_darwin.C,v $
33 * Revision 1.3 2014/10/06 15:09:43 j_novak
34 * Modified #include directives to use c++ syntax.
35 *
36 * Revision 1.2 2003/01/09 11:07:49 j_novak
37 * headcpp.h is now compliant with C++ norm.
38 * The include files have been ordered, as well as the local_settings_linux
39 *
40 * Revision 1.1.1.1 2001/11/20 15:19:31 e_gourgoulhon
41 * LORENE
42 *
43 * Revision 1.3 1999/12/24 12:15:51 keisuke
44 * Minor changes.
45 *
46 * Revision 1.2 1999/12/23 16:41:11 keisuke
47 * Change of the criterion for the convergence.
48 *
49 * Revision 1.1 1999/12/23 13:44:55 keisuke
50 * Initial revision
51 *
52 *
53 * $Header: /cvsroot/Lorene/Codes/Bin_star/test_darwin.C,v 1.3 2014/10/06 15:09:43 j_novak Exp $
54 *
55 */
56
57 // version of 09.12.1999
58 // version of 16.12.1999
59 // version of 22.12.1999
60 // version of 23.12.1999
61
62 // headers C
63 #include <cstdlib>
64 #include <cmath>
65
66 // headers Lorene
67 #include "type_parite.h"
68 #include "cmp.h"
69 #include "utilitaires.h"
70 #include "graphique.h"
71 #include "param.h"
72
73 // Local prototypes:
74 Cmp eos1_local(const Cmp& ent, int nzet, double n_index) ;
75 Cmp eos2_local(const Cmp& ent, int nzet, double n_index) ;
76 double funct_zero_ent(double r, const Param& par) ;
77
78 //**********************************************************************
79
80 void main(){
81
82 // Identification of all the subroutines called by the code :
83
84 system("ident test_darwin > identif_darwin.d") ;
85
86 //-----------------------------------------------------------------------
87 // Input from file "part.d"
88 //-----------------------------------------------------------------------
89
90 int type_t, type_p, nt, np, nz, l;
91 char blabla[80];
92 double n_index, R_sep ;
93
94 //----------------------------------------------------
95 // Declear the polytropic index
96 //----------------------------------------------------
97 cout << "Input the polytropic index: " ;
98 cin >> n_index ;
99 cout << "Input the orbital separation: " ;
100 cin >> R_sep ;
101
102 ifstream fich("part.d") ;
103 fich >> nt; fich.getline(blabla, 80);
104 fich >> np; fich.getline(blabla, 80);
105 fich >> nz; fich.getline(blabla, 80);
106
107 cout << "nb de points en phi : np = " << np << endl;
108 cout << "nb de points en theta : nt = " << nt << endl;
109 cout << "nb de zones : nz = " << nz << endl;
110
111 // initialisation des tableaux decrivant chaque zone
112
113 int* nr = new int[nz];
114 int* nt_tab = new int[nz];
115 int* np_tab = new int[nz];
116 double* bornes = new double[nz+1];
117 int* type_r = new int[nz];
118
119 fich >> bornes[nz] ; fich.getline(blabla, 80) ;
120 for (l=0; l<nz; l++) {
121 fich >> nr[l];
122 fich >> bornes[l];
123 fich >> type_r[l]; fich.getline(blabla, 80);
124 np_tab[l] = np ;
125 nt_tab[l] = nt ;
126 }
127 if (type_r[nz-1]==UNSURR) bornes[nz] = 1./bornes[nz] ;
128
129 fich.close();
130
131
132 //-----------------------------------------------------------------------
133 // Construction of 2 multi-grids
134 //-----------------------------------------------------------------------
135
136 type_t = SYM ;
137 type_p = NONSYM ;
138
139 const Mg3d mg1(nz, nr, type_r, nt_tab, type_t, np_tab, type_p) ;
140 const Mg3d mg2(nz, nr, type_r, nt_tab, type_t, np_tab, type_p) ;
141
142 //-----------------------------------------------------------------------
143 // Construction of 2 mappings
144 //-----------------------------------------------------------------------
145
146 Map_af mp1(mg1, bornes) ;
147 double xo1 = - R_sep/2 ;
148 mp1.set_ori(xo1, 0, 0) ;
149
150 Map_af mp2(mg2, bornes) ;
151 double xo2 = R_sep/2 ;
152 mp2.set_ori(xo2, 0, 0) ;
153 mp2.set_rot_phi(M_PI) ;
154
155
156 cout << "Mapping mp1 : " << mp1 << endl ;
157 cout << "Mapping mp2 : " << mp2 << endl ;
158
159 //-----------------------------------------------------------------------
160 // Construction of Cmp's
161 //-----------------------------------------------------------------------
162
163 //-------------------------------------
164 // Construction of two spherical stars
165 //-------------------------------------
166
167 Cmp rho1(mp1) ;
168 const Coord& x1 = mp1.x ;
169 const Coord& y1 = mp1.y ;
170
171 rho1 = 1 ;
172 rho1.annule(nz-1) ;
173 rho1.set_dzpuis(4) ;
174 rho1.std_base_scal() ;
175
176 Cmp rho2(mp2) ;
177 const Coord& x2 = mp2.x ;
178 const Coord& y2 = mp2.y ;
179
180 rho2 = 1 ;
181 rho2.annule(nz-1) ;
182 rho2.set_dzpuis(4) ;
183 rho2.std_base_scal() ;
184
185 Cmp pot_star1(mp1) ;
186 Cmp rho_prev_star1(mp1) ;
187 Cmp ent_star1(mp1) ;
188 double ent_star1_c = 1 ;
189 double ent_star1_s = 0 ;
190
191 Cmp pot_star2(mp2) ;
192 Cmp rho_prev_star2(mp2) ;
193 Cmp ent_star2(mp2) ;
194 double ent_star2_c = 1 ;
195 double ent_star2_s = 0 ;
196
197 int nr_star1 = mg1.get_nr(nz-2) ;
198 int nr_star2 = mg2.get_nr(nz-2) ;
199
200 // Start the do loop for constructing spherical stars
201 //----------------------------------------------------
202
203 // For star 1
204 //------------
205 do {
206
207 // Solving the Poisson equation
208 //------------------------------
209 pot_star1 = - rho1.poisson() ;
210
211 // Obtaining "lambda" in order to rescale the mapping
212 //----------------------------------------------------
213 double pot_star1_c = pot_star1(0,0,0,0) ;
214 double pot_star1_s = pot_star1(nz-2,0,0,nr_star1-1) ;
215
216 double lambda2_star1 = (ent_star1_s - ent_star1_c) /
217 (pot_star1_s - pot_star1_c) ;
218 cout << "lambda2_star1 : " << lambda2_star1 << endl ;
219
220 // New potential after rescaling
221 //-------------------------------
222 pot_star1 = lambda2_star1 * pot_star1 ;
223 pot_star1_c *= lambda2_star1 ;
224
225 // First integral of motion
226 // -------------------------
227 ent_star1 = ent_star1_c + pot_star1 - pot_star1_c ;
228 // enthalpy is just the same as the Lane-Emden function Theta
229
230 // Rescale of the mapping
231 //------------------------
232 mp1.homothetie( sqrt(lambda2_star1) ) ;
233
234 // EOS : rho = rho(H)
235 //--------------------
236 rho_prev_star1 = rho1 ;
237 rho1 = pow(abs(ent_star1), n_index) ;
238
239 rho1.annule(nz-1) ;
240 rho1.set_dzpuis(4) ;
241 rho1.std_base_scal() ;
242
243 cout << max(abs(rho1 - rho_prev_star1)) << endl;
244 cout << "Maximum difference between rho1 and rho1_prev : "
245 << max(diffrel(rho1, rho_prev_star1)) << endl ;
246
247 } while(max(diffrel(rho1, rho_prev_star1)) > 1.e-6) ;
248
249 // For star 2
250 //------------
251
252 do {
253
254 // Solving the Poisson equation
255 //------------------------------
256 pot_star2 = - rho2.poisson() ;
257
258 // Obtaining "lambda" in order to rescale the mapping
259 //----------------------------------------------------
260 double pot_star2_c = pot_star2(0,0,0,0) ;
261 double pot_star2_s = pot_star2(nz-2,0,0,nr_star2-1) ;
262
263 double lambda2_star2 = (ent_star2_s - ent_star2_c) /
264 (pot_star2_s - pot_star2_c) ;
265 cout << "lambda2_star2 : " << lambda2_star2 << endl ;
266
267 // New potential after rescaling
268 //-------------------------------
269 pot_star2 = lambda2_star2 * pot_star2 ;
270 pot_star2_c *= lambda2_star2 ;
271
272 // First integral of motion
273 // -------------------------
274 ent_star2 = ent_star2_c + pot_star2 - pot_star2_c ;
275 // enthalpy is just the same as the Lane-Emden function Theta
276
277 // Rescale of the mapping
278 //------------------------
279 mp2.homothetie( sqrt(lambda2_star2) ) ;
280
281 // EOS : rho = rho(H)
282 //--------------------
283 rho_prev_star2 = rho2 ;
284 rho2 = pow(abs(ent_star2), n_index) ;
285
286 rho2.annule(nz-1) ;
287 rho2.set_dzpuis(4) ;
288 rho2.std_base_scal() ;
289
290 cout << max(abs(rho2 - rho_prev_star2)) << endl;
291 cout << "Maximum difference between rho2 and rho2_prev : "
292 << max(diffrel(rho2, rho_prev_star2)) << endl ;
293
294 } while(max(diffrel(rho2, rho_prev_star2)) > 1.e-6) ;
295
296 arrete() ;
297
298 // Masses of stars
299 //-----------------
300 double mass1 = rho1.integrale() ;
301 double mass2 = rho2.integrale() ;
302
303
304 //-----------------------------------------------
305 // Construction of the Darwin-like binary system
306 //-----------------------------------------------
307
308 int nr1_s = mg1.get_nr(nz-2) ;
309 int nr2_s = mg2.get_nr(nz-2) ;
310
311 Cmp pot11(mp1) ;
312 Cmp pot12(mp2) ;
313 Cmp pot22(mp2) ;
314 Cmp pot21(mp1) ;
315 pot11.std_base_scal() ;
316 pot22.std_base_scal() ;
317 pot12.std_base_scal() ;
318 pot21.std_base_scal() ;
319
320 Cmp rho1_prev(mp1) ;
321 Cmp rho2_prev(mp2) ;
322 Cmp rot1(mp1) ;
323 Cmp rot2(mp2) ;
324
325 Cmp ent1(mp1) ;
326 Cmp ent2(mp2) ;
327 double ent1_c = 1 ;
328 double ent1_s = 0 ;
329 double ent2_c = 1 ;
330 double ent2_s = 0 ;
331
332 Cmp dpot21(mp1) ; // x derivative of pot21
333 Cmp disp1(mp1) ; // Cmp description of x
334 Cmp rho1_dpot21(mp1) ; // multiply rho1 by dpot21
335 Cmp rho1_disp1(mp1) ; // multiply rho1 by disp1
336
337 Cmp dpot12(mp2) ;
338 Cmp disp2(mp2) ;
339 Cmp rho2_dpot12(mp2) ;
340 Cmp rho2_disp2(mp2) ;
341
342 cout << "Mass of star 1 = " << mass1 << endl ;
343 cout << "Mass of star 2 = " << mass2 << endl ;
344
345 double mass1_prev ;
346 double rel_mass1 ;
347 double mass2_prev ;
348 double rel_mass2 ;
349
350 double omega2_1 ;
351 double omega2_prev1 ;
352 double rel_omega1 ;
353 omega2_1 = (mass1 + mass2) / (M_PI * R_sep * R_sep * R_sep) ;
354
355 double omega2_2 ;
356 double omega2_prev2 ;
357 double rel_omega2 ;
358 omega2_2 = (mass1 + mass2) / (M_PI * R_sep * R_sep * R_sep) ;
359
360 cout << "omega^2 = " << omega2_1 << endl ;
361
362 double cc1 ;
363 double cc1_prev ;
364 double rel_cc1 ;
365 cc1 = 0 ;
366
367 double cc2 ;
368 double cc2_prev ;
369 double rel_cc2 ;
370 cc2 = 0 ;
371
372 double r1_x ;
373 double r2_x ;
374
375 arrete() ;
376
377 do {
378
379 // Solving the Poisson equation
380 //------------------------------
381 pot11 = - rho1.poisson() ;
382 pot22 = - rho2.poisson() ;
383
384 pot12.import(nz-1, pot11) ;
385 pot21.import(nz-1, pot22) ;
386
387 // Angular velocity
388 //------------------
389
390 // For star 1
391 omega2_prev1 = omega2_1 ;
392 dpot21 = pot21.dsdx() ;
393 disp1 = x1 ;
394
395 rho1_dpot21 = rho1 * dpot21 ;
396 rho1_dpot21.annule(nz-1) ;
397 rho1_dpot21.set_dzpuis(4) ;
398 rho1_dpot21.std_base_scal() ;
399
400 rho1_disp1 = rho1 * disp1 ;
401 rho1_disp1.annule(nz-1) ;
402 rho1_disp1.set_dzpuis(4) ;
403 rho1_disp1.std_base_scal() ;
404
405 double integ_r1_dp21 = rho1_dpot21.integrale() ;
406 double integ_r1_dis1 = rho1_disp1.integrale() ;
407
408 omega2_1 = 8. * integ_r1_dp21 / (mass1 * R_sep - 2. * integ_r1_dis1) ;
409
410 cout << "Omega^2/(pi G rho_c) for star 1 : " << omega2_1 << endl ;
411
412 rel_omega1 = fabs(1. - omega2_prev1 / omega2_1) ;
413 cout << "Relative error in Omega^2 for star 1 : " << rel_omega1
414 << endl ;
415
416
417 // For star 2
418 omega2_prev2 = omega2_2 ;
419 dpot12 = pot12.dsdx() ;
420 disp2 = x2 ;
421
422 rho2_dpot12 = rho2 * dpot12 ;
423 rho2_dpot12.annule(nz-1) ;
424 rho2_dpot12.set_dzpuis(4) ;
425 rho2_dpot12.std_base_scal() ;
426
427 rho2_disp2 = rho2 * disp2 ;
428 rho2_disp2.annule(nz-1) ;
429 rho2_disp2.set_dzpuis(4) ;
430 rho2_disp2.std_base_scal() ;
431
432 double integ_r2_dp12 = rho2_dpot12.integrale() ;
433 double integ_r2_dis2 = rho2_disp2.integrale() ;
434
435 omega2_2 = 8. * integ_r2_dp12 / (mass2 * R_sep - 2. * integ_r2_dis2) ;
436
437 cout << "Omega^2/(pi G rho_c) for star 2 : " << omega2_2 << endl ;
438
439 rel_omega2 = fabs(1. - omega2_prev2 / omega2_2) ;
440 cout << "Relative error in Omega^2 for star 2 : " << rel_omega2
441 << endl ;
442
443 // arrete() ;
444
445 // Obtaining "lambda" for each star in order to rescale mappings
446 //---------------------------------------------------------------
447 double pot11_c = pot11(0,0,0,0) ;
448 double pot22_c = pot22(0,0,0,0) ;
449 double pot21_c = pot21(0,0,0,0) ;
450 double pot12_c = pot12(0,0,0,0) ;
451
452 r1_x = mp1.val_r(nz-2,1.,M_PI/2,0) ;
453 r2_x = mp2.val_r(nz-2,1.,M_PI/2,0) ;
454
455 cout << "Radius x of star 1 : " << r1_x << endl
456 << "Radius x of star 2 : " << r2_x << endl ;
457
458 double pot11_sx = pot11.val_point(r1_x,M_PI/2,0) ;
459 double pot21_sx = pot21.val_point(r1_x,M_PI/2,0) ;
460 double pot22_sx = pot22.val_point(r2_x,M_PI/2,0) ;
461 double pot12_sx = pot12.val_point(r2_x,M_PI/2,0) ;
462
463 // lambda2
464 //---------
465 double lambda2_1 = (ent1_c - ent1_s - pot21_c + pot21_sx +
466 0.125 * omega2_1 * r1_x * (r1_x - R_sep)) /
467 (pot11_c - pot11_sx) ;
468
469 double lambda2_2 = (ent2_c - ent2_s - pot12_c + pot12_sx +
470 0.125 * omega2_2 * r2_x * (r2_x - R_sep)) /
471 (pot22_c - pot22_sx) ;
472
473 cout << "lambda2 for star 1 : " << lambda2_1 << endl
474 << "lambda2 for star 2 : " << lambda2_2 << endl ;
475
476 // New potentials after rescaling
477 //--------------------------------
478 pot11 = lambda2_1 * pot11 ;
479 pot11_c = lambda2_1 * pot11_c ;
480 pot11_sx = lambda2_1 * pot11_sx ;
481
482 pot22 = lambda2_2 * pot22 ;
483 pot22_c = lambda2_2 * pot22_c ;
484 pot22_sx = lambda2_2 * pot22_sx ;
485
486 // Integration constant
487 //----------------------
488 cc1_prev = cc1 ;
489 cc1 = ent1_c - pot11_c - pot21_c - omega2_1 * R_sep * R_sep /32. ;
490 cc2_prev = cc2 ;
491 cc2 = ent2_c - pot22_c - pot12_c - omega2_2 * R_sep * R_sep /32. ;
492
493 cout << "Integration constant for star 1 : " << cc1 << endl
494 << "Integration constant for star 2 : " << cc2 << endl ;
495
496 rel_cc1 = fabs(1. - cc1_prev / cc1) ;
497 rel_cc2 = fabs(1. - cc2_prev / cc2) ;
498 cout << "Relative error in cc1 : " << rel_cc1 << endl
499 << "Relative error in cc2 : " << rel_cc2 << endl ;
500
501 // arrete() ;
502
503
504 // First integration of motion
505 //-----------------------------
506 rot1 = 0.125 * omega2_1 * (0.25 * R_sep * R_sep - R_sep * x1 +
507 x1 * x1 + y1 * y1) ;
508 rot1.annule(nz-1) ;
509
510 rot2 = 0.125 * omega2_2 * (0.25 * R_sep * R_sep - R_sep * x2 +
511 x2 * x2 + y2 * y2) ;
512 rot2.annule(nz-1) ;
513
514 ent1 = pot11 + pot21 + rot1 + cc1 ;
515 ent1.annule(nz-1) ;
516
517 ent2 = pot22 + pot12 + rot2 + cc2 ;
518 ent2.annule(nz-1) ;
519
520 // Rescaling of mappings
521 //-----------------------
522 mp1.homothetie( sqrt(lambda2_1) ) ;
523 mp2.homothetie( sqrt(lambda2_2) ) ;
524
525 rho1_prev = rho1 ;
526 rho2_prev = rho2 ;
527
528 // EOS : rho = rho(H)
529 //--------------------
530 rho1 = eos1_local(ent1, nz-1, n_index) ;
531 rho2 = eos2_local(ent2, nz-1, n_index) ;
532
533 rho1.set_dzpuis(4) ;
534 rho2.set_dzpuis(4) ;
535 rho1.std_base_scal() ;
536 rho2.std_base_scal() ;
537
538 cout << max(abs(rho1 - rho1_prev)) << endl
539 << max(abs(rho2 - rho2_prev)) << endl ;
540
541 // Masses of stars
542 //-----------------
543
544 // For star 1
545 mass1_prev = mass1 ;
546 mass1 = rho1.integrale() ;
547 cout << "Mass/rho_c for star 1 : " << mass1 << endl ;
548
549 rel_mass1 = fabs(1. - mass1_prev / mass1) ;
550 cout << "Relative error in Mass for star 1 : " << rel_mass1 << endl ;
551
552 // For star 2
553 mass2_prev = mass2 ;
554 mass2 = rho2.integrale() ;
555 cout << "Mass/rho_c for star 2 : " << mass2 << endl ;
556
557 rel_mass2 = fabs(1. - mass2_prev / mass2) ;
558 cout << "Relative error in Mass for star 2 : " << rel_mass2 << endl ;
559
560 cout << "Maximum difference between rho1 and rho1_prev : "
561 << max(diffrel(rho1, rho1_prev)) << endl
562 << "Maximum difference between rho2 and rho2_prev : "
563 << max(diffrel(rho2, rho2_prev)) << endl ;
564
565 // arrete() ;
566
567 } while(max(diffrel(rho1, rho1_prev)) > 1.e-4) ;
568
569 cout << "Coef of rho1 : " << endl ;
570 rho1.affiche_seuil(cout) ;
571
572 cout << "Coef of pot11 : " << endl ;
573 pot11.affiche_seuil(cout) ;
574
575 cout << "Value of pot11 at the origin : " << pot11(0,0,0,0) << endl ;
576 cout << "Value of pot11 at the surface (r=ray) : "
577 << pot11(nz-1,0,0,0) << endl ;
578 cout << "Value of pot11 at the surface (r=ray) : "
579 << pot11(nz-2,0,0,nr1_s-1) << endl ;
580 arrete() ;
581
582 cout << "Coef of rho2 : " << endl ;
583 rho2.affiche_seuil(cout) ;
584
585 cout << "Coef of pot22 : " << endl ;
586 pot22.affiche_seuil(cout) ;
587
588 cout << "Value of pot22 at the origin : " << pot22(0,0,0,0) << endl ;
589 cout << "Value of pot22 at the surface (r=ray) : "
590 << pot22(nz-1,0,0,0) << endl ;
591 cout << "Value of pot22 at the surface (r=ray) : "
592 << pot22(nz-2,0,0,nr2_s-1) << endl ;
593 arrete() ;
594
595 // Checking whether or not the potentials satisfy their Poisson equations
596 //------------------------------------------------------------------------
597 Cmp lap1 = - pot11.laplacien() ;
598 cout << "max( |lap(pot11) - rho1| ) " << max(abs(lap1 - rho1)) << endl ;
599 cout << "relative error for star 1 : " << diffrel(lap1, rho1) << endl ;
600
601 Cmp lap2 = - pot22.laplacien() ;
602 cout << "max( |lap(pot22) - rho2| ) " << max(abs(lap2 - rho2)) << endl ;
603 cout << "relative error for star 2: " << diffrel(lap2, rho2) << endl ;
604
605 // Searching the radius to the x-axis direction for star 1
606 //---------------------------------------------------------
607 Param par_funct_zero_x ;
608 par_funct_zero_x.add_cmp(ent1) ;
609 double phi_search_x = 0 ;
610 double theta_search_x = M_PI/2 ;
611 par_funct_zero_x.add_double(theta_search_x, 0) ;
612 par_funct_zero_x.add_double(phi_search_x, 1) ;
613
614 double r_min_search_x = 0 ;
615 double r_max_search_x = r1_x ;
616 double precis_x = 1e-10 ;
617 int nitermax_x = 100 ;
618 int niter_x ;
619
620 double radius_x = zerosec(funct_zero_ent, par_funct_zero_x,
621 r_min_search_x, r_max_search_x, precis_x,
622 nitermax_x, niter_x) ;
623
624 cout << "Radius of star 1 in the x-axis direction : " << radius_x
625 << endl ;
626
627 // Searching the radius opposite to the x-axis direction for star 1
628 //------------------------------------------------------------------
629 Param par_funct_zero_xopp ;
630 par_funct_zero_xopp.add_cmp(ent1) ;
631 double phi_search_xopp = - M_PI ;
632 double theta_search_xopp = M_PI/2 ;
633 par_funct_zero_xopp.add_double(theta_search_xopp, 0) ;
634 par_funct_zero_xopp.add_double(phi_search_xopp, 1) ;
635
636 double r_min_search_xopp = 0 ;
637 double r_max_search_xopp = r1_x ;
638 double precis_xopp = 1e-10 ;
639 int nitermax_xopp = 100 ;
640 int niter_xopp ;
641
642 double radius_xopp = zerosec(funct_zero_ent, par_funct_zero_xopp,
643 r_min_search_xopp, r_max_search_xopp, precis_xopp,
644 nitermax_xopp, niter_xopp) ;
645
646 cout << "Radius of star 1 opposite to the x-axis direction : "
647 << radius_xopp << endl ;
648
649 // Searching the radius to the y-axis direction for star 1
650 //---------------------------------------------------------
651 Param par_funct_zero_y ;
652 par_funct_zero_y.add_cmp(ent1) ;
653 double phi_search_y = M_PI/2 ;
654 double theta_search_y = M_PI/2 ;
655 par_funct_zero_y.add_double(theta_search_y, 0) ;
656 par_funct_zero_y.add_double(phi_search_y, 1) ;
657
658 double r_min_search_y = 0 ;
659 double r_max_search_y = r1_x ;
660 double precis_y = 1e-10 ;
661 int nitermax_y = 100 ;
662 int niter_y ;
663
664 double radius_y = zerosec(funct_zero_ent, par_funct_zero_y,
665 r_min_search_y, r_max_search_y, precis_y,
666 nitermax_y, niter_y) ;
667
668 cout << "Radius of star 1 in the y-axis direction : " << radius_y
669 << endl ;
670
671 // Searching the radius to the north pole for star 1
672 //---------------------------------------------------
673 Param par_funct_zero_z ;
674 par_funct_zero_z.add_cmp(ent1) ;
675 double phi_search_z = 0 ;
676 double theta_search_z = 0 ;
677 par_funct_zero_z.add_double(theta_search_z, 0) ;
678 par_funct_zero_z.add_double(phi_search_z, 1) ;
679
680 double r_min_search_z = 0 ;
681 double r_max_search_z = r1_x ;
682 double precis_z = 1e-10 ;
683 int nitermax_z = 100 ;
684 int niter_z ;
685
686 double radius_z = zerosec(funct_zero_ent, par_funct_zero_z,
687 r_min_search_z, r_max_search_z, precis_z,
688 nitermax_z, niter_z) ;
689
690 cout << "Radius of star 1 in the z-axis direction : " << radius_z
691 << endl ;
692
693 // Radius of star 1
694 //------------------
695 double ray1 = mp1.val_r(nz-2,1.,M_PI/2,0) ;
696 cout << "Radius of star 1 in the x-axis direction : " << ray1 << endl ;
697
698 cout << "The ratios of the axes : " << endl
699 << "a_2/a_1 : " << radius_y/radius_x << endl
700 << "a_3/a_1 : " << radius_z/radius_x << endl ;
701
702 // Radius of star 1
703 //------------------
704 double ray2 = mp2.val_r(nz-2,1.,M_PI/2,0) ;
705 cout << "Radius of star 2 in the x-axis direction : " << ray2 << endl ;
706
707 // Angular velocity
708 //------------------
709 double omega1 = sqrt(omega2_1) ;
710 double omega2 = sqrt(omega2_2) ;
711
712 cout << "Angular velocity of the star Omega/(pi G rho_c)^{1/2} : "
713 << omega1 << endl ;
714 cout << "Angular velocity Omega^2/(pi G rho_c) : " << omega2_1 << endl ;
715
716 arrete() ;
717
718 // Total energy of the binary system
719 //-----------------------------------
720
721 // Internal energy
722 //-----------------
723
724 // For star 1
725 Cmp rho1_n(mp1) ;
726
727 rho1_n = pow(abs(rho1), 1 + 1/n_index) ;
728 rho1_n.annule(nz-1) ;
729 rho1_n.set_dzpuis(4) ;
730 rho1_n.std_base_scal() ;
731
732 double energy1_internal = 4. * M_PI *
733 (1 / (1 + n_index)) * rho1_n.integrale() * ray1 / (mass1 * mass1) ;
734
735 cout << "Internal energy of star 1 : "
736 << n_index * energy1_internal << endl ;
737
738 // For star 2
739 Cmp rho2_n(mp2) ;
740
741 rho2_n = pow(abs(rho2), 1 + 1/n_index) ;
742 rho2_n.annule(nz-1) ;
743 rho2_n.set_dzpuis(4) ;
744 rho2_n.std_base_scal() ;
745
746 double energy2_internal = 4. * M_PI *
747 (1 / (1 + n_index)) * rho2_n.integrale() * ray2 / (mass2 * mass2) ;
748
749 cout << "Internal energy of star 2 : "
750 << n_index * energy2_internal << endl ;
751
752 cout << "Internal energy of the Darwin binary system : E_int/(GM^2/ray) : "
753 << n_index * energy1_internal + n_index * energy2_internal << endl ;
754
755 // Self-gravity energy
756 //---------------------
757
758 // For star 1
759 Cmp rho1_pot11(mp1) ;
760 rho1_pot11 = rho1 * pot11 ;
761 rho1_pot11.annule(nz-1) ;
762 rho1_pot11.set_dzpuis(4) ;
763 rho1_pot11.std_base_scal() ;
764 double energy1_selfgrav = -2. * M_PI * rho1_pot11.integrale() * ray1 /
765 (mass1 * mass1) ;
766
767 cout << "Self-gravity energy of star 1 : " << energy1_selfgrav << endl ;
768
769 // For star 2
770 Cmp rho2_pot22(mp2) ;
771 rho2_pot22 = rho2 * pot22 ;
772 rho2_pot22.annule(nz-1) ;
773 rho2_pot22.set_dzpuis(4) ;
774 rho2_pot22.std_base_scal() ;
775 double energy2_selfgrav = -2. * M_PI * rho2_pot22.integrale() * ray2 /
776 (mass2 * mass2) ;
777
778 cout << "Self-gravity energy of star 2 : " << energy2_selfgrav << endl ;
779
780 cout <<
781 "Self-gravity energy of the Darwin binary system : E_self/(GM^2/ray) : "
782 << energy1_selfgrav + energy2_selfgrav << endl ;
783
784 // Interaction energy
785 //--------------------
786
787 // For star 1
788 Cmp rho1_pot21(mp1) ;
789 rho1_pot21 = rho1 * pot21 ;
790 rho1_pot21.annule(nz-1) ;
791 rho1_pot21.set_dzpuis(4) ;
792 rho1_pot21.std_base_scal() ;
793 double energy1_interact = -2. * M_PI * rho1_pot21.integrale() * ray1 /
794 (mass1 * mass1) ;
795
796 cout << "Interaction energy for star 1 : " << energy1_interact << endl ;
797
798 // For star 2
799 Cmp rho2_pot12(mp2) ;
800 rho2_pot12 = rho2 * pot12 ;
801 rho2_pot12.annule(nz-1) ;
802 rho2_pot12.set_dzpuis(4) ;
803 rho2_pot12.std_base_scal() ;
804 double energy2_interact = -2. * M_PI * rho2_pot12.integrale() * ray2 /
805 (mass2 * mass2) ;
806
807 cout << "Interaction energy for star 2 : " << energy2_interact << endl ;
808
809 cout <<
810 "Interaction energy of the Darwin binary system : E_ext/(GM^2/ray) : "
811 << energy1_interact + energy2_interact << endl ;
812
813 // Kinetic energy
814 //----------------
815
816 // For star 1
817 Cmp rr1(mp1) ;
818 Cmp rho1_quad1(mp1) ;
819 rr1 = x1 * x1 + y1 * y1 - R_sep * x1 ;
820 rho1_quad1 = rho1 * rr1 ;
821 rho1_quad1.annule(nz-1) ;
822 rho1_quad1.set_dzpuis(4) ;
823 rho1_quad1.std_base_scal() ;
824 double energy1_kinetic = 0.5 * M_PI * omega2_1 *
825 (0.25 * R_sep * R_sep + rho1_quad1.integrale() / mass1 ) *
826 ray1 / mass1 ;
827
828 cout << "Kinetic energy for star 1 : " << energy1_kinetic << endl ;
829
830 // For star 2
831 Cmp rr2(mp2) ;
832 Cmp rho2_quad2(mp2) ;
833 rr2 = x2 * x2 + y2 * y2 - R_sep * x2 ;
834 rho2_quad2 = rho2 * rr2 ;
835 rho2_quad2.annule(nz-1) ;
836 rho2_quad2.set_dzpuis(4) ;
837 rho2_quad2.std_base_scal() ;
838 double energy2_kinetic = 0.5 * M_PI * omega2_2 *
839 (0.25 * R_sep * R_sep + rho2_quad2.integrale() / mass2 ) *
840 ray2 / mass2 ;
841
842 cout << "Kinetic energy for star 2 : " << energy2_kinetic << endl ;
843
844 cout << "Kinetic energy of the Darwin binary system : "
845 << "E_kinet/(GM^2/ray) : "
846 << energy1_kinetic + energy2_kinetic << endl ;
847
848 // Total energy
849 //--------------
850
851 // For star 1
852 double energy1_total = n_index * energy1_internal + energy1_selfgrav
853 + energy1_kinetic + energy1_interact ;
854
855 cout << "Total energy for star 1 : E_1/(GM_1^2/ray1) : "
856 << energy1_total << endl ;
857
858 // For star 2
859 double energy2_total = n_index * energy2_internal + energy2_selfgrav
860 + energy2_kinetic + energy2_interact ;
861
862 cout << "Total energy for star 2 : E_2/(GM_2^2/ray) : "
863 << energy2_total << endl ;
864
865 // For binary system
866 cout << "Total energy of the Darwin binary system : E/(GM^2/ray) : "
867 << energy1_total + energy2_total << endl ;
868
869 // Angular momentum
870 //------------------
871
872 // For star 1
873 double angmom1 = sqrt(M_PI) * omega1 *
874 ( 0.25 * mass1 * R_sep * R_sep + rho1_quad1.integrale() ) /
875 sqrt( mass1 * mass1 * mass1 * ray1 ) ;
876
877 cout << "Angular momentum for star 1 : " << angmom1 << endl ;
878
879 // For star 2
880 double angmom2 = sqrt(M_PI) * omega2 *
881 ( 0.25 * mass2 * R_sep * R_sep + rho2_quad2.integrale() ) /
882 sqrt( mass2 * mass2 * mass2 * ray2 ) ;
883
884 cout << "Angular momentum for star 2 : " << angmom2 << endl ;
885
886 cout <<
887 "Angular momentum of the Darwin binary system : J/(GM^3 ray)^{1/2} : "
888 << angmom1 + angmom2 << endl ;
889
890 // Virial relation
891 //-----------------
892
893 // For star 1
894 double virial1 = 3. * energy1_internal + energy1_selfgrav
895 + 2. * energy1_kinetic + energy1_interact ;
896
897 cout << "Virial relation for star 1 : " << virial1 << endl ;
898
899 // For star 2
900 double virial2 = 3. * energy2_internal + energy2_selfgrav
901 + 2. * energy2_kinetic + energy2_interact ;
902
903 cout << "Virial relation for star 2 : " << virial2 << endl ;
904
905 cout << "Virial relation of the Darwin binary system : "
906 << virial1 + virial2 << endl ;
907
908 arrete() ;
909
910 //------------------------------------------
911 // Plot the figures
912 //------------------------------------------
913 double rmax = R_sep/2 ;
914 // cout << "r_max ?" << endl ;
915 // cin >> rmax ;
916
917 des_profile(rho1,0.,rmax,M_PI/2,0.,"rho1/rho_c","rho1 (x direction)") ;
918 des_profile(rho1,0.,rmax,M_PI/2,M_PI/2,"rho1/rho_c","rho1 (y direction)") ;
919 des_profile(rho1,0.,rmax,0.,0.,"rho1/rho_c","rho1 (z direction)") ;
920
921 // des_coupe_x(rho1, 0., -rmax, rmax, -rmax, rmax, "rho1 (y-z plane)") ;
922 des_coupe_x(rho1, 0., -rmax, rmax, -rmax, rmax, "rho1 (y-z plane)",&ent1) ;
923 des_coupe_y(rho1, 0., -rmax, rmax, -rmax, rmax, "rho1 (z-x plane)",&ent1) ;
924 des_coupe_z(rho1, 0., -rmax, rmax, -rmax, rmax, "rho1 (x-y plane)",&ent1) ;
925
926 des_coef_xi(rho1.va, 0, 0, 0, 1.e-14, "log|c_i|", "domain no. 0") ;
927 des_coef_theta(rho1.va, 0, 0, 0) ;
928 des_coef_phi(rho1.va, 0, 0, 0) ;
929
930 des_coef_xi(rho1.va, 1, 0, 0, 1.e-14, "log|c_i|", "domain no. 1") ;
931 des_coef_theta(rho1.va, 0, 0, 0) ;
932 des_coef_phi(rho1.va, 0, 0, 0) ;
933
934 exit(-1) ;
935
936 }
937