| 1 |
/* |
| 2 |
* Construction of initial conditions for a binary star computation. |
| 3 |
* |
| 4 |
*/ |
| 5 |
|
| 6 |
/* |
| 7 |
* Copyright (c) 1999-2001 Eric Gourgoulhon |
| 8 |
* |
| 9 |
* This file is part of LORENE. |
| 10 |
* |
| 11 |
* LORENE is free software; you can redistribute it and/or modify |
| 12 |
* it under the terms of the GNU General Public License as published by |
| 13 |
* the Free Software Foundation; either version 2 of the License, or |
| 14 |
* (at your option) any later version. |
| 15 |
* |
| 16 |
* LORENE is distributed in the hope that it will be useful, |
| 17 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 18 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 19 |
* GNU General Public License for more details. |
| 20 |
* |
| 21 |
* You should have received a copy of the GNU General Public License |
| 22 |
* along with LORENE; if not, write to the Free Software |
| 23 |
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 24 |
* |
| 25 |
*/ |
| 26 |
|
| 27 |
char init_bin_C[] = "$Header: /cvsroot/Lorene/Codes/Bin_star/init_bin.C,v 1.7 2014/10/13 08:53:54 j_novak Exp $" ; |
| 28 |
|
| 29 |
/* |
| 30 |
* $Id: init_bin.C,v 1.7 2014/10/13 08:53:54 j_novak Exp $ |
| 31 |
* $Log: init_bin.C,v $ |
| 32 |
* Revision 1.7 2014/10/13 08:53:54 j_novak |
| 33 |
* Lorene classes and functions now belong to the namespace Lorene. |
| 34 |
* |
| 35 |
* Revision 1.6 2014/10/06 15:09:42 j_novak |
| 36 |
* Modified #include directives to use c++ syntax. |
| 37 |
* |
| 38 |
* Revision 1.5 2008/11/14 13:54:53 e_gourgoulhon |
| 39 |
* Reading in input files par_grid*.d the values for the enthalpy at the |
| 40 |
* boundaries between the domains inside the stars. |
| 41 |
* |
| 42 |
* Revision 1.4 2004/03/25 12:35:36 j_novak |
| 43 |
* now using namespace Unites |
| 44 |
* |
| 45 |
* Revision 1.3 2003/01/09 11:07:48 j_novak |
| 46 |
* headcpp.h is now compliant with C++ norm. |
| 47 |
* The include files have been ordered, as well as the local_settings_linux |
| 48 |
* |
| 49 |
* Revision 1.2 2001/12/06 16:18:39 jl_zdunik |
| 50 |
* Return type of main changed from 'void' to 'int'. |
| 51 |
* |
| 52 |
* Revision 1.1.1.1 2001/11/20 15:19:31 e_gourgoulhon |
| 53 |
* LORENE |
| 54 |
* |
| 55 |
* Revision 1.4 2000/03/16 09:47:18 eric |
| 56 |
* Suppression du shift analytique (c'est desormais fait dans coal). |
| 57 |
* |
| 58 |
* Revision 1.3 2000/03/15 13:15:08 eric |
| 59 |
* Utilisation d'une formule analytique pour initialiser le shift a autre |
| 60 |
* chose que zero. |
| 61 |
* |
| 62 |
* Revision 1.2 2000/02/14 14:56:13 eric |
| 63 |
* Construction des EOS par lecture de fichier formate. |
| 64 |
* |
| 65 |
* Revision 1.1 2000/02/03 14:51:35 eric |
| 66 |
* Initial revision |
| 67 |
* |
| 68 |
* |
| 69 |
* $Header: /cvsroot/Lorene/Codes/Bin_star/init_bin.C,v 1.7 2014/10/13 08:53:54 j_novak Exp $ |
| 70 |
* |
| 71 |
*/ |
| 72 |
|
| 73 |
|
| 74 |
// headers C |
| 75 |
#include <cstdlib> |
| 76 |
#include <cmath> |
| 77 |
|
| 78 |
// headers Lorene |
| 79 |
#include "binaire.h" |
| 80 |
#include "eos.h" |
| 81 |
#include "utilitaires.h" |
| 82 |
#include "graphique.h" |
| 83 |
#include "nbr_spx.h" |
| 84 |
#include "unites.h" |
| 85 |
|
| 86 |
using namespace Lorene ; |
| 87 |
|
| 88 |
//****************************************************************************** |
| 89 |
|
| 90 |
int main(){ |
| 91 |
|
| 92 |
using namespace Unites ; |
| 93 |
|
| 94 |
// Identification of all the subroutines called by the code : |
| 95 |
|
| 96 |
// system("ident init_bin") ; |
| 97 |
|
| 98 |
int nt, np, nz ; |
| 99 |
char blabla[80] ; |
| 100 |
|
| 101 |
ifstream fich("par_init.d") ; |
| 102 |
|
| 103 |
//----------------------------------------------------------------------- |
| 104 |
// Physical parameters imput |
| 105 |
//----------------------------------------------------------------------- |
| 106 |
|
| 107 |
fich.getline(blabla, 80) ; |
| 108 |
fich.getline(blabla, 80) ; |
| 109 |
|
| 110 |
int relat_i ; |
| 111 |
fich >> relat_i; fich.getline(blabla, 80) ; |
| 112 |
bool relat = (relat_i == 1) ; |
| 113 |
|
| 114 |
double separ ; |
| 115 |
fich >> separ; fich.getline(blabla, 80) ; |
| 116 |
separ *= km ; // translation in machine units |
| 117 |
|
| 118 |
int irrot1_i, irrot2_i ; |
| 119 |
double ent_c1, ent_c2 ; |
| 120 |
fich >> ent_c1 ; fich.getline(blabla, 80) ; |
| 121 |
fich >> irrot1_i ; fich.getline(blabla, 80) ; |
| 122 |
bool irrot1 = (irrot1_i == 1) ; |
| 123 |
fich >> ent_c2 ; fich.getline(blabla, 80) ; |
| 124 |
fich >> irrot2_i ; fich.getline(blabla, 80) ; |
| 125 |
bool irrot2 = (irrot2_i == 1) ; |
| 126 |
|
| 127 |
fich.close() ; |
| 128 |
|
| 129 |
cout << endl << "Requested orbital separation : " << separ / km |
| 130 |
<< " km" << endl ; |
| 131 |
|
| 132 |
//----------------------------------------------------------------------- |
| 133 |
// Input data for the multi-grid no. 1 |
| 134 |
//----------------------------------------------------------------------- |
| 135 |
|
| 136 |
|
| 137 |
fich.open("par_grid1.d") ; |
| 138 |
fich.getline(blabla, 80); |
| 139 |
fich.getline(blabla, 80); |
| 140 |
fich >> nz; fich.getline(blabla, 80) ; |
| 141 |
int nzet1 ; |
| 142 |
fich >> nzet1; fich.getline(blabla, 80) ; |
| 143 |
fich >> nt; fich.getline(blabla, 80) ; |
| 144 |
fich >> np; fich.getline(blabla, 80) ; |
| 145 |
|
| 146 |
cout << "total number of domains : nz = " << nz << endl ; |
| 147 |
cout << "number of points in phi : np = " << np << endl ; |
| 148 |
cout << "number of points in theta : nt = " << nt << endl ; |
| 149 |
|
| 150 |
int* nr = new int[nz]; |
| 151 |
int* nt_tab = new int[nz]; |
| 152 |
int* np_tab = new int[nz]; |
| 153 |
double* bornes = new double[nz+1]; |
| 154 |
|
| 155 |
fich.getline(blabla, 80); |
| 156 |
for (int l=0; l<nz; l++) { |
| 157 |
fich >> nr[l]; |
| 158 |
fich >> bornes[l]; fich.getline(blabla, 80) ; |
| 159 |
np_tab[l] = np ; |
| 160 |
nt_tab[l] = nt ; |
| 161 |
} |
| 162 |
bornes[nz] = __infinity ; |
| 163 |
|
| 164 |
|
| 165 |
Tbl ent_limit1(nzet1) ; |
| 166 |
Tbl* pent_limit1 ; |
| 167 |
ent_limit1.set_etat_qcq() ; |
| 168 |
ent_limit1.set(nzet1-1) = 0 ; // enthalpy at the stellar surface |
| 169 |
fich >> ent_limit1.set(0) ; |
| 170 |
if ( fich.good() ) { // to ensure backwards compatibility |
| 171 |
for (int l=1; l<nzet1-1; l++) { |
| 172 |
fich >> ent_limit1.set(l) ; fich.getline(blabla, 120) ; |
| 173 |
} |
| 174 |
pent_limit1 = &ent_limit1 ; |
| 175 |
} |
| 176 |
else { |
| 177 |
pent_limit1 = 0x0 ; |
| 178 |
} |
| 179 |
|
| 180 |
fich.close(); |
| 181 |
|
| 182 |
for (int l=0; l<nzet1-1; l++) { |
| 183 |
|
| 184 |
bornes[l+1] = bornes[nzet1] * sqrt(1 - ent_limit1(l) / ent_c1) ; |
| 185 |
|
| 186 |
} |
| 187 |
|
| 188 |
// Type of r sampling : |
| 189 |
int* type_r = new int[nz]; |
| 190 |
type_r[0] = RARE ; |
| 191 |
for (int l=1; l<nz-1; l++) { |
| 192 |
type_r[l] = FIN ; |
| 193 |
} |
| 194 |
type_r[nz-1] = UNSURR ; |
| 195 |
|
| 196 |
// Type of sampling in theta and phi : |
| 197 |
int type_t = SYM ; |
| 198 |
int type_p = NONSYM ; |
| 199 |
|
| 200 |
//----------------------------------------------------------------------- |
| 201 |
// Construction of multi-grid 1 and mapping 1 |
| 202 |
//----------------------------------------------------------------------- |
| 203 |
|
| 204 |
Mg3d mg1(nz, nr, type_r, nt_tab, type_t, np_tab, type_p) ; |
| 205 |
|
| 206 |
Map_et mp1(mg1, bornes) ; |
| 207 |
|
| 208 |
delete [] nr ; |
| 209 |
delete [] nt_tab ; |
| 210 |
delete [] np_tab ; |
| 211 |
delete [] type_r ; |
| 212 |
delete [] bornes ; |
| 213 |
|
| 214 |
//----------------------------------------------------------------------- |
| 215 |
// Input data for the multi-grid no. 2 |
| 216 |
//----------------------------------------------------------------------- |
| 217 |
|
| 218 |
|
| 219 |
fich.open("par_grid2.d") ; |
| 220 |
fich.getline(blabla, 80); |
| 221 |
fich.getline(blabla, 80); |
| 222 |
fich >> nz; fich.getline(blabla, 80) ; |
| 223 |
int nzet2 ; |
| 224 |
fich >> nzet2; fich.getline(blabla, 80) ; |
| 225 |
fich >> nt; fich.getline(blabla, 80) ; |
| 226 |
fich >> np; fich.getline(blabla, 80) ; |
| 227 |
|
| 228 |
cout << "total number of domains : nz = " << nz << endl ; |
| 229 |
cout << "number of points in phi : np = " << np << endl ; |
| 230 |
cout << "number of points in theta : nt = " << nt << endl ; |
| 231 |
|
| 232 |
nr = new int[nz]; |
| 233 |
nt_tab = new int[nz]; |
| 234 |
np_tab = new int[nz]; |
| 235 |
bornes = new double[nz+1]; |
| 236 |
|
| 237 |
fich.getline(blabla, 80); |
| 238 |
for (int l=0; l<nz; l++) { |
| 239 |
fich >> nr[l]; |
| 240 |
fich >> bornes[l]; fich.getline(blabla, 80) ; |
| 241 |
np_tab[l] = np ; |
| 242 |
nt_tab[l] = nt ; |
| 243 |
} |
| 244 |
bornes[nz] = __infinity ; |
| 245 |
|
| 246 |
Tbl ent_limit2(nzet2) ; |
| 247 |
Tbl* pent_limit2 ; |
| 248 |
ent_limit2.set_etat_qcq() ; |
| 249 |
ent_limit2.set(nzet2-1) = 0 ; // enthalpy at the stellar surface |
| 250 |
fich >> ent_limit2.set(0) ; |
| 251 |
if ( fich.good() ) { // to ensure backwards compatibility |
| 252 |
for (int l=1; l<nzet2-1; l++) { |
| 253 |
fich >> ent_limit2.set(l) ; fich.getline(blabla, 120) ; |
| 254 |
} |
| 255 |
pent_limit2 = &ent_limit2 ; |
| 256 |
} |
| 257 |
else { |
| 258 |
pent_limit2 = 0x0 ; |
| 259 |
} |
| 260 |
|
| 261 |
|
| 262 |
for (int l=0; l<nzet2-1; l++) { |
| 263 |
fich >> ent_limit2.set(l) ; fich.getline(blabla, 120) ; |
| 264 |
} |
| 265 |
|
| 266 |
fich.close(); |
| 267 |
|
| 268 |
for (int l=0; l<nzet2-1; l++) { |
| 269 |
|
| 270 |
bornes[l+1] = bornes[nzet2] * sqrt(1 - ent_limit2(l) / ent_c2) ; |
| 271 |
|
| 272 |
} |
| 273 |
|
| 274 |
// Type of r sampling : |
| 275 |
type_r = new int[nz]; |
| 276 |
type_r[0] = RARE ; |
| 277 |
for (int l=1; l<nz-1; l++) { |
| 278 |
type_r[l] = FIN ; |
| 279 |
} |
| 280 |
type_r[nz-1] = UNSURR ; |
| 281 |
|
| 282 |
// Type of sampling in theta and phi : |
| 283 |
type_t = SYM ; |
| 284 |
type_p = NONSYM ; |
| 285 |
|
| 286 |
//----------------------------------------------------------------------- |
| 287 |
// Construction of multi-grid 2 and mapping 2 |
| 288 |
//----------------------------------------------------------------------- |
| 289 |
|
| 290 |
Mg3d mg2(nz, nr, type_r, nt_tab, type_t, np_tab, type_p) ; |
| 291 |
|
| 292 |
Map_et mp2(mg2, bornes) ; |
| 293 |
|
| 294 |
delete [] nr ; |
| 295 |
delete [] nt_tab ; |
| 296 |
delete [] np_tab ; |
| 297 |
delete [] type_r ; |
| 298 |
delete [] bornes ; |
| 299 |
|
| 300 |
cout << endl << "Multi-grid 1 : " |
| 301 |
<< endl << "============ " << endl << mg1 << endl ; |
| 302 |
cout << "Mapping 1 : " |
| 303 |
<< endl << "========= " << endl << mp1 << endl ; |
| 304 |
|
| 305 |
cout << endl << "Multi-grid 2 : " |
| 306 |
<< endl << "============ " << endl << mg2 << endl ; |
| 307 |
cout << "Mapping 2 : " |
| 308 |
<< endl << "========= " << endl << mp2 << endl ; |
| 309 |
|
| 310 |
//----------------------------------------------------------------------- |
| 311 |
// Equation of state for star 1 |
| 312 |
//----------------------------------------------------------------------- |
| 313 |
|
| 314 |
fich.open("par_eos1.d") ; |
| 315 |
|
| 316 |
Eos* peos1 = Eos::eos_from_file(fich) ; |
| 317 |
Eos& eos1 = *peos1 ; |
| 318 |
|
| 319 |
fich.close() ; |
| 320 |
|
| 321 |
//----------------------------------------------------------------------- |
| 322 |
// Equation of state for star 2 |
| 323 |
//----------------------------------------------------------------------- |
| 324 |
|
| 325 |
fich.open("par_eos2.d") ; |
| 326 |
|
| 327 |
Eos* peos2 = Eos::eos_from_file(fich) ; |
| 328 |
Eos& eos2 = *peos2 ; |
| 329 |
|
| 330 |
fich.close() ; |
| 331 |
|
| 332 |
cout << endl << "Equation of state of star 1 : " |
| 333 |
<< endl << "=========================== " << endl << eos1 << endl ; |
| 334 |
cout << endl << "Equation of state of star 2 : " |
| 335 |
<< endl << "=========================== " << endl << eos2 << endl ; |
| 336 |
|
| 337 |
|
| 338 |
//----------------------------------------------------------------------- |
| 339 |
// Construction of a binary system |
| 340 |
//----------------------------------------------------------------------- |
| 341 |
|
| 342 |
Binaire star(mp1, nzet1, eos1, irrot1, |
| 343 |
mp2, nzet2, eos2, irrot2, |
| 344 |
relat) ; |
| 345 |
|
| 346 |
//----------------------------------------------------------------------- |
| 347 |
// Computation of two static configurations |
| 348 |
//----------------------------------------------------------------------- |
| 349 |
|
| 350 |
double precis = 1.e-14 ; |
| 351 |
|
| 352 |
cout << endl << "Computation of a static configuration for star 1" |
| 353 |
<< endl << "================================================" << endl ; |
| 354 |
|
| 355 |
(star.set(1)).equilibrium_spher(ent_c1, precis, pent_limit1) ; |
| 356 |
|
| 357 |
cout << endl << "Computation of a static configuration for star 2" |
| 358 |
<< endl << "================================================" << endl ; |
| 359 |
|
| 360 |
(star.set(2)).equilibrium_spher(ent_c2, precis, pent_limit2) ; |
| 361 |
|
| 362 |
|
| 363 |
//----------------------------------------------------------------------- |
| 364 |
// Sets the stars at Newtonian (Keplerian) position |
| 365 |
//----------------------------------------------------------------------- |
| 366 |
|
| 367 |
// Omega and rotation axis |
| 368 |
// ----------------------- |
| 369 |
|
| 370 |
double total_mass = star(1).mass_g() + star(2).mass_g() ; |
| 371 |
|
| 372 |
star.set_omega() = sqrt( g_si/g_unit * total_mass / pow(separ, 3.) ) ; |
| 373 |
|
| 374 |
star.set_x_axe() = 0 ; |
| 375 |
|
| 376 |
|
| 377 |
// Position of the two stars |
| 378 |
// ------------------------- |
| 379 |
|
| 380 |
for (int i=1 ; i<=2 ; i++) { |
| 381 |
|
| 382 |
double xa_et = (star(3-i).mass_g()) / total_mass * separ ; |
| 383 |
if (i == 1) xa_et = - xa_et ; |
| 384 |
|
| 385 |
((star.set(i)).set_mp()).set_ori(xa_et, 0., 0.) ; |
| 386 |
} |
| 387 |
|
| 388 |
// Orientation of the two stars |
| 389 |
// ---------------------------- |
| 390 |
|
| 391 |
// Star 1 aligned with the absolute frame : |
| 392 |
((star.set(1)).set_mp()).set_rot_phi(0.) ; |
| 393 |
|
| 394 |
// Star 2 anti-aligned with the absolute frame : |
| 395 |
((star.set(2)).set_mp()).set_rot_phi(M_PI) ; |
| 396 |
|
| 397 |
|
| 398 |
cout << endl |
| 399 |
<< "=============================================================" << endl |
| 400 |
<< "=============================================================" << endl ; |
| 401 |
cout << endl << "Final characteristics of the computed system : " << endl ; |
| 402 |
cout.precision(16) ; |
| 403 |
cout << star << endl ; |
| 404 |
|
| 405 |
//----------------------------------------------------------------------- |
| 406 |
// The result is written in a file |
| 407 |
//----------------------------------------------------------------------- |
| 408 |
|
| 409 |
FILE* fresu = fopen("ini.d", "w") ; |
| 410 |
|
| 411 |
int mer = 0 ; |
| 412 |
fwrite(&mer, sizeof(int), 1, fresu) ; // mer |
| 413 |
|
| 414 |
mg1.sauve(fresu) ; |
| 415 |
mp1.sauve(fresu) ; |
| 416 |
eos1.sauve(fresu) ; |
| 417 |
|
| 418 |
mg2.sauve(fresu) ; |
| 419 |
mp2.sauve(fresu) ; |
| 420 |
eos2.sauve(fresu) ; |
| 421 |
|
| 422 |
star.sauve(fresu) ; |
| 423 |
|
| 424 |
fclose(fresu) ; |
| 425 |
|
| 426 |
// Cleaning |
| 427 |
// -------- |
| 428 |
|
| 429 |
delete peos1 ; |
| 430 |
delete peos2 ; |
| 431 |
|
| 432 |
return EXIT_SUCCESS ; |
| 433 |
|
| 434 |
|
| 435 |
} |