Debian Codegraph @

C++/Source/Bin_ns_ncp/bin_ns_ncp.C

raw
1 /*
2 * Methods of class Bin_ns_ncp.C
3 *
4 */
5
6 /*
7 * Copyright (c) 2002 Francois Limousin
8 *
9 * This file is part of LORENE.
10 *
11 * LORENE is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
15 *
16 * LORENE is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
20 *
21 * You should have received a copy of the GNU General Public License
22 * along with LORENE; if not, write to the Free Software
23 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24 *
25 */
26 char Bin_ns_ncp_C[] = "$Header: /cvsroot/Lorene/C++/Source/Bin_ns_ncp/bin_ns_ncp.C,v 1.10 2014/10/13 08:52:43 j_novak Exp $" ;
27
28 /*
29 * $Id: bin_ns_ncp.C,v 1.10 2014/10/13 08:52:43 j_novak Exp $
30 * $Log: bin_ns_ncp.C,v $
31 * Revision 1.10 2014/10/13 08:52:43 j_novak
32 * Lorene classes and functions now belong to the namespace Lorene.
33 *
34 * Revision 1.9 2014/10/06 15:13:02 j_novak
35 * Modified #include directives to use c++ syntax.
36 *
37 * Revision 1.8 2004/03/25 10:28:58 j_novak
38 * All LORENE's units are now defined in the namespace Unites (in file unites.h).
39 *
40 * Revision 1.7 2003/10/13 10:31:59 f_limousin
41 * *** empty log message ***
42 *
43 * Revision 1.6 2003/06/20 13:49:53 f_limousin
44 * Add a new argument conf_flat in the constructors and a new function fait_decouple().
45 *
46 * Revision 1.5 2003/03/03 19:32:06 f_limousin
47 * Suppression of the member ref_triad.
48 *
49 * Revision 1.4 2003/02/12 18:46:59 f_limousin
50 * Change the arguments of the standard constructor.
51 *
52 * Revision 1.3 2003/01/20 17:13:25 j_novak
53 * Modif des include <math.h> pour eviter les warning sous SGI.
54 *
55 * Revision 1.2 2003/01/20 09:38:17 f_limousin
56 * Modification of the standard constructor
57 *
58 * Revision 1.1 2003/01/14 13:43:38 f_limousin
59 * Methods of class Bin_ns_ncp.
60 *
61 * Revision 1.2 2001/12/11 06:44:41 e_gourgoulhon
62 * template files
63 *
64 *
65 *
66 * $Header: /cvsroot/Lorene/C++/Source/Bin_ns_ncp/bin_ns_ncp.C,v 1.10 2014/10/13 08:52:43 j_novak Exp $
67 *
68 */
69
70 // Headers C
71 #include <cmath>
72
73 // Headers Lorene
74 #include "bin_ns_ncp.h"
75 #include "eos.h"
76 #include "utilitaires.h"
77 #include "graphique.h"
78 #include "param.h"
79 #include "unites.h"
80
81 //--------------//
82 // Constructors //
83 //--------------//
84
85 // Standard constructor
86 // --------------------
87
88 namespace Lorene {
89 Bin_ns_ncp::Bin_ns_ncp(Map& mp1, int nzet1, const Eos& eos1, int irrot1,
90 Map& mp2, int nzet2, const Eos& eos2, int irrot2, int relat,
91 int conf_flat, const Metrique& flat1, const Metrique& flat2,
92 const Tenseur_sym &source1, const Tenseur_sym &source2)
93 : star1(mp1, nzet1, relat, eos1, irrot1, conf_flat,
94 mp1.get_bvect_cart(), flat1, source1),
95 star2(mp2, nzet2, relat, eos2, irrot2, conf_flat,
96 mp2.get_bvect_cart(), flat2, source2)
97 {
98
99 et[0] = &star1 ;
100 et[1] = &star2 ;
101
102 omega = 0 ;
103 x_axe = 0 ;
104
105 // Pointers of derived quantities initialized to zero :
106 set_der_0x0() ;
107 }
108
109 // Copy constructor
110 // ----------------
111 Bin_ns_ncp::Bin_ns_ncp(const Bin_ns_ncp& bibi)
112 : star1(bibi.star1),
113 star2(bibi.star2),
114 omega(bibi.omega),
115 x_axe(bibi.x_axe)
116 {
117 et[0] = &star1 ;
118 et[1] = &star2 ;
119
120 // Pointers of derived quantities initialized to zero :
121 set_der_0x0() ;
122 }
123
124 // Constructor from a file
125 // -----------------------
126 Bin_ns_ncp::Bin_ns_ncp(Map& mp1, const Eos& eos1, Map& mp2, const Eos& eos2,
127 const Metrique& flat1, const Metrique& flat2, FILE* fich)
128 : star1(mp1, eos1, mp1.get_bvect_cart(), flat1, fich),
129 star2(mp2, eos2, mp2.get_bvect_cart(), flat2, fich)
130 {
131 et[0] = &star1 ;
132 et[1] = &star2 ;
133
134 // omega and x_axe are read in the file:
135 fread_be(&omega, sizeof(double), 1, fich) ;
136 fread_be(&x_axe, sizeof(double), 1, fich) ;
137
138 // Pointers of derived quantities initialized to zero :
139 set_der_0x0() ;
140
141 }
142
143 //------------//
144 // Destructor //
145 //------------//
146
147 Bin_ns_ncp::~Bin_ns_ncp(){
148
149 del_deriv() ;
150
151 }
152
153 //----------------------------------//
154 // Management of derived quantities //
155 //----------------------------------//
156
157 void Bin_ns_ncp::del_deriv() const {
158
159 if (p_mass_adm != 0x0) delete p_mass_adm ;
160 if (p_mass_kom != 0x0) delete p_mass_kom ;
161 if (p_angu_mom != 0x0) delete p_angu_mom ;
162 if (p_total_ener != 0x0) delete p_total_ener ;
163 if (p_virial != 0x0) delete p_virial ;
164 if (p_virial_gb != 0x0) delete p_virial_gb ;
165 if (p_virial_fus != 0x0) delete p_virial_fus ;
166 if (p_ham_constr != 0x0) delete p_ham_constr ;
167 if (p_mom_constr != 0x0) delete p_mom_constr ;
168
169 set_der_0x0() ;
170 }
171
172
173
174
175 void Bin_ns_ncp::set_der_0x0() const {
176
177 p_mass_adm = 0x0 ;
178 p_mass_kom = 0x0 ;
179 p_angu_mom = 0x0 ;
180 p_total_ener = 0x0 ;
181 p_virial = 0x0 ;
182 p_virial_gb = 0x0 ;
183 p_virial_fus = 0x0 ;
184 p_ham_constr = 0x0 ;
185 p_mom_constr = 0x0 ;
186
187 }
188
189
190 //--------------//
191 // Assignment //
192 //--------------//
193
194 // Assignment to another Bin_ns_ncp
195 // --------------------------------
196
197 void Bin_ns_ncp::operator=(const Bin_ns_ncp& bibi) {
198
199 star1 = bibi.star1 ;
200 star2 = bibi.star2 ;
201
202 omega = bibi.omega ;
203 x_axe = bibi.x_axe ;
204
205 del_deriv() ; // Deletes all derived quantities
206
207 }
208
209 //--------------//
210 // Outputs //
211 //--------------//
212
213 // Save in a file
214 // --------------
215 void Bin_ns_ncp::sauve(FILE* fich) const {
216
217 star1.sauve(fich) ;
218 star2.sauve(fich) ;
219
220 fwrite_be(&omega, sizeof(double), 1, fich) ;
221 fwrite_be(&x_axe, sizeof(double), 1, fich) ;
222
223 }
224
225 // Printing
226 // --------
227 ostream& operator<<(ostream& ost, const Bin_ns_ncp& bibi) {
228 bibi >> ost ;
229 return ost ;
230 }
231
232
233 ostream& Bin_ns_ncp::operator>>(ostream& ost) const {
234
235 using namespace Unites ;
236
237 ost << endl ;
238 ost << "Binary neutron stars with non comformally flat metric" << endl ;
239 ost << "=============" << endl ;
240 ost << endl <<
241 "Orbital angular velocity : " << omega * f_unit << " rad/s" << endl ;
242 ost << endl <<
243 "Coordinate separation between the two stellar centers : "
244 << separation() / km << " km" << endl ;
245 ost <<
246 "Absolute coordinate X of the rotation axis : " << x_axe / km
247 << " km" << endl ;
248 ost << endl << "Star 1 : " << endl ;
249 ost << "====== " << endl ;
250 ost << star1 << endl ;
251 ost << "Star 2 : " << endl ;
252 ost << "====== " << endl ;
253 ost << star2 << endl ;
254 return ost ;
255 }
256
257 // Display in polytropic units
258 // ---------------------------
259
260 void Bin_ns_ncp::display_poly(ostream& ost) const {
261
262 using namespace Unites ;
263
264 const Eos* p_eos1 = &( star1.get_eos() ) ;
265 const Eos_poly* p_eos_poly = dynamic_cast<const Eos_poly*>( p_eos1 ) ;
266
267 if (p_eos_poly != 0x0) {
268
269 assert( star1.get_eos() == star2.get_eos() ) ;
270
271 double kappa = p_eos_poly->get_kap() ;
272 double gamma = p_eos_poly->get_gam() ; ;
273 double kap_ns2 = pow( kappa, 0.5 /(gamma-1) ) ;
274
275 // Polytropic unit of length in terms of r_unit :
276 double r_poly = kap_ns2 / sqrt(ggrav) ;
277
278 // Polytropic unit of time in terms of t_unit :
279 double t_poly = r_poly ;
280
281 // Polytropic unit of mass in terms of m_unit :
282 double m_poly = r_poly / ggrav ;
283
284 // Polytropic unit of angular momentum in terms of j_unit :
285 // double j_poly = r_poly * r_poly / ggrav ;
286
287 ost.precision(10) ;
288 ost << endl << "Quantities in polytropic units : " << endl ;
289 ost << "==============================" << endl ;
290 ost << " ( r_poly = " << r_poly / km << " km )" << endl ;
291 ost << " d_e_max : " << separation() / r_poly << endl ;
292 ost << " d_G : "
293 << ( star2.xa_barycenter() - star1.xa_barycenter() ) / r_poly
294 << endl ;
295 ost << " Omega : " << omega * t_poly << endl ;
296 // ost << " J : " << angu_mom()(2) / j_poly << endl ;
297 // ost << " M_ADM : " << mass_adm() / m_poly << endl ;
298 // ost << " M_Komar : " << mass_kom() / m_poly << endl ;
299 // ost << " E : " << total_ener() / m_poly << endl ;
300 ost << " M_bar(star 1) : " << star1.mass_b() / m_poly << endl ;
301 ost << " M_bar(star 2) : " << star2.mass_b() / m_poly << endl ;
302 ost << " R_0(star 1) : " <<
303 0.5 * ( star1.ray_eq() + star1.ray_eq_pi() ) / r_poly << endl ;
304 ost << " R_0(star 2) : " <<
305 0.5 * ( star2.ray_eq() + star2.ray_eq_pi() ) / r_poly << endl ;
306
307 }
308
309
310 }
311
312
313 void Bin_ns_ncp::fait_decouple () {
314
315 int nz_un = star1.mp.get_mg()->get_nzone() ;
316 int nz_deux = star2.mp.get_mg()->get_nzone() ;
317
318 // On determine R_limite (pour le moment en tout cas...) :
319 double distance = fabs(star1.mp.get_ori_x() - star2.mp.get_ori_x()) ;
320 double lim_un = -1*distance/2. ;
321 double lim_deux = -1*distance/2. ;
322 double int_un = 0*distance/6. ;
323 double int_deux = 0*distance/6. ;
324
325
326 /*
327 // Les fonctions de base
328 Cmp fonction_f_un (star1.mp) ;
329 // fonction_f_un = (exp(-pow(star1.mp.r/lim_un, 2)) - exp(-1.)) / (1-exp(-1.))/2. + 0.5 ;
330
331 fonction_f_un = 0.5*pow(
332 cos((star1.mp.r-int_un)*M_PI/2./(lim_un-int_un)), 2.)+0.5 ;
333 fonction_f_un.std_base_scal();
334
335 des_coupe_z(fonction_f_un, 0, 2) ;
336 des_profile(fonction_f_un, 0, 10, 0, 0) ;
337 des_coef_xi(fonction_f_un.va, 0, 0, 0) ;
338 des_coef_xi(fonction_f_un.va, 1, 0, 0) ;
339 des_coef_xi(fonction_f_un.va, 2, 0, 0) ;
340
341 Cmp fonction_g_un (star1.mp) ;
342 // fonction_g_un = (1 - exp(-pow(star1.mp.r/lim_un, 2))) /
343 //(1-exp(-1.))/2. ;
344
345 fonction_g_un = 0.5*pow
346 (sin((star1.mp.r-int_un)*M_PI/2./(lim_un-int_un)), 2.) ;
347 fonction_g_un.std_base_scal();
348
349 Cmp fonction_f_deux (star2.mp) ;
350 fonction_f_deux = 0.5*pow(
351 cos((star2.mp.r-int_deux)*M_PI/2./(lim_deux-int_deux)), 2.)+0.5 ;
352 fonction_f_deux.std_base_scal();
353
354 Cmp fonction_g_deux (star2.mp) ;
355 fonction_g_deux = 0.5*pow
356 (sin((star2.mp.r-int_deux)*M_PI/2./(lim_deux-int_deux)), 2.) ;
357 fonction_g_deux.std_base_scal();
358 */
359
360
361 // Les fonctions totales :
362 Cmp decouple_un (star1.mp) ;
363 decouple_un.allocate_all() ;
364 Cmp decouple_deux (star2.mp) ;
365 decouple_deux.allocate_all() ;
366
367 Mtbl xabs_un (star1.mp.xa) ;
368 Mtbl yabs_un (star1.mp.ya) ;
369 Mtbl zabs_un (star1.mp.za) ;
370
371 Mtbl xabs_deux (star2.mp.xa) ;
372 Mtbl yabs_deux (star2.mp.ya) ;
373 Mtbl zabs_deux (star2.mp.za) ;
374
375 double xabs, yabs, zabs, air_un, air_deux, theta, phi ;
376
377 // On boucle sur les autres zones :
378 for (int l=0 ; l<nz_un ; l++) {
379 int nr = star1.mp.get_mg()->get_nr (l) ;
380
381 if (l==nz_un-1)
382 nr -- ;
383
384 int np = star1.mp.get_mg()->get_np (l) ;
385 int nt = star1.mp.get_mg()->get_nt (l) ;
386
387 for (int k=0 ; k<np ; k++)
388 for (int j=0 ; j<nt ; j++)
389 for (int i=0 ; i<nr ; i++) {
390
391 xabs = xabs_un (l, k, j, i) ;
392 yabs = yabs_un (l, k, j, i) ;
393 zabs = zabs_un (l, k, j, i) ;
394
395 // les coordonnees du point :
396 star1.mp.convert_absolute
397 (xabs, yabs, zabs, air_un, theta, phi) ;
398 star2.mp.convert_absolute
399 (xabs, yabs, zabs, air_deux, theta, phi) ;
400
401 if (air_un <= lim_un)
402 if (air_un < int_un)
403 decouple_un.set(l, k, j, i) = 1 ;
404 else
405 // pres de l'etoile une :
406 decouple_un.set(l, k, j, i) = 0.5*pow(
407 cos((air_un-int_un)*M_PI/2./(lim_un-int_un)), 2.)+0.5 ;
408
409 else
410 if (air_deux <= lim_deux)
411 if (air_deux < int_deux)
412 decouple_un.set(l, k, j, i) = 0 ;
413 else
414 // On est pres de l'etoile deux :
415 decouple_un.set(l, k, j, i) = 0.5*pow
416 (sin((air_deux-int_deux)*M_PI/2./(lim_deux-int_deux)), 2.) ;
417
418 else
419 // On est loin des deux etoiles :
420 decouple_un.set(l, k, j, i) = 0.5 ;
421 }
422
423
424 // Cas infini :
425 if (l==nz_un-1)
426 for (int k=0 ; k<np ; k++)
427 for (int j=0 ; j<nt ; j++)
428 decouple_un.set(nz_un-1, k, j, nr) = 0.5 ;
429 }
430
431
432 for (int l=0 ; l<nz_deux ; l++) {
433 int nr = star2.mp.get_mg()->get_nr (l) ;
434
435 if (l==nz_deux-1)
436 nr -- ;
437
438 int np = star2.mp.get_mg()->get_np (l) ;
439 int nt = star2.mp.get_mg()->get_nt (l) ;
440
441 for (int k=0 ; k<np ; k++)
442 for (int j=0 ; j<nt ; j++)
443 for (int i=0 ; i<nr ; i++) {
444
445 xabs = xabs_deux (l, k, j, i) ;
446 yabs = yabs_deux (l, k, j, i) ;
447 zabs = zabs_deux (l, k, j, i) ;
448
449 // les coordonnees du point :
450 star1.mp.convert_absolute
451 (xabs, yabs, zabs, air_un, theta, phi) ;
452 star2.mp.convert_absolute
453 (xabs, yabs, zabs, air_deux, theta, phi) ;
454
455 if (air_deux <= lim_deux)
456 if (air_deux < int_deux)
457 decouple_deux.set(l, k, j, i) = 1 ;
458 else
459 // pres de l'etoile deux :
460 decouple_deux.set(l, k, j, i) = 0.5*pow(
461 cos((air_deux-int_deux)*M_PI/2./(lim_deux-int_deux)), 2.)+0.5 ;
462
463 else
464 if (air_un <= lim_un)
465 if (air_un < int_un)
466 decouple_deux.set(l, k, j, i) = 0 ;
467 else
468 // On est pres de l'etoile une :
469 decouple_deux.set(l, k, j, i)=0.5*pow
470 (sin((air_un-int_un)*M_PI/2./(lim_un-int_un)), 2.) ;
471
472
473 else
474 // On est loin des deux etoiles :
475 decouple_deux.set(l, k, j, i) = 0.5 ;
476 }
477
478 // Cas infini :
479 if (l==nz_deux-1)
480 for (int k=0 ; k<np ; k++)
481 for (int j=0 ; j<nt ; j++)
482 decouple_deux.set(nz_un-1, k, j, nr) = 0.5 ;
483 }
484
485 int nr = star2.mp.get_mg()->get_nr (2) ;
486 int np = star2.mp.get_mg()->get_np (2) ;
487 int nt = star2.mp.get_mg()->get_nt (2) ;
488
489 cout << "decouple_un" << endl << norme(decouple_un/(nr*nt*np)) << endl ;
490 cout << "decouple_deux" << endl << norme(decouple_deux/(nr*nt*np)) << endl ;
491 /*
492 decouple_un.std_base_scal() ;
493
494 des_coef_xi(decouple_un.va, 0, 0, 0) ;
495 des_coef_xi(decouple_un.va, 1, 0, 0) ;
496 des_coef_xi(decouple_un.va, 2, 0, 0) ;
497
498 decouple_deux.std_base_scal() ;
499
500 des_coef_xi(decouple_deux.va, 0, 0, 0) ;
501 des_coef_xi(decouple_deux.va, 1, 0, 0) ;
502 des_coef_xi(decouple_deux.va, 2, 0, 0) ;
503 */
504 star1.decouple = decouple_un ;
505 star2.decouple = decouple_deux ;
506
507
508 }
509
510
511
512
513 //-------------------------------//
514 // Miscellaneous //
515 //-------------------------------//
516
517 double Bin_ns_ncp::separation() const {
518
519 double dx = star1.mp.get_ori_x() - star2.mp.get_ori_x() ;
520 double dy = star1.mp.get_ori_y() - star2.mp.get_ori_y() ;
521 double dz = star1.mp.get_ori_z() - star2.mp.get_ori_z() ;
522
523 return sqrt( dx*dx + dy*dy + dz*dz ) ;
524
525 }
526 }