Debian Codegraph @

Codes/Bin_star_xcts/xinit_bin.C

raw
1 /*
2 * Construction of initial conditions for a binary star computation
3 * in XCTS formalism (see star_xcts.h and binary_xcts.h for details)
4 *
5 */
6
7 /*
8 * Copyright (c) 2010 Michal Bejger
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 version 2
14 * as published by the Free Software Foundation.
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_xcts/xinit_bin.C,v 1.5 2014/10/13 08:53:54 j_novak Exp $" ;
28
29 /*
30 * $Id: xinit_bin.C,v 1.5 2014/10/13 08:53:54 j_novak Exp $
31 * $Log: xinit_bin.C,v $
32 * Revision 1.5 2014/10/13 08:53:54 j_novak
33 * Lorene classes and functions now belong to the namespace Lorene.
34 *
35 * Revision 1.4 2014/10/06 15:09:43 j_novak
36 * Modified #include directives to use c++ syntax.
37 *
38 * Revision 1.3 2011/06/08 07:06:29 m_bejger
39 * star.display_poly() added to the output
40 *
41 * Revision 1.2 2011/03/30 13:22:09 m_bejger
42 * Reading of the third line in par_init.d to assure backwards compatibility with Bin_star/init_bin
43 *
44 * Revision 1.1 2011/03/29 13:49:58 m_bejger
45 * Renaming init_bin.C to xinit_bin.C in order to avoid confusion with previous codes
46 *
47 * Revision 1.5 2010/12/09 10:49:37 m_bejger
48 * *** empty log message ***
49 *
50 * Revision 1.4 2010/10/18 18:14:27 m_bejger
51 * Changed to allow initial data with more than one domain in the star
52 *
53 * Revision 1.3 2010/06/17 15:00:27 m_bejger
54 * Redefinition of initial Psi_auto and chi_auto
55 *
56 * Revision 1.2 2010/05/03 13:39:14 m_bejger
57 * File handler fixed
58 *
59 * Revision 1.1 2010/04/29 15:05:17 m_bejger
60 * Initial version
61 *
62 *
63 * $Header: /cvsroot/Lorene/Codes/Bin_star_xcts/xinit_bin.C,v 1.5 2014/10/13 08:53:54 j_novak Exp $
64 *
65 */
66
67 // headers C
68 #include <cstdlib>
69 #include <cmath>
70
71 // headers Lorene
72 #include "unites.h"
73 #include "binary_xcts.h"
74 #include "eos.h"
75 #include "utilitaires.h"
76 #include "graphique.h"
77 #include "nbr_spx.h"
78
79 using namespace Lorene ;
80
81 int main() {
82
83 //------------------------------------------------------------------
84 // Input data for the multi-grid no. 1
85 //------------------------------------------------------------------
86
87 int nt, np, nz ;
88 char blabla[80] ;
89
90 //------------------------------------------------------------------
91 // Physical parameters imput
92 //------------------------------------------------------------------
93
94 using namespace Unites ;
95
96 ifstream fich("par_init.d") ;
97 fich.getline(blabla, 80) ;
98 fich.getline(blabla, 80) ;
99 fich.getline(blabla, 80) ; // this line added for the backwards
100 // compatibility with the init_bin.C
101 // from Bin_star
102
103 double separ ;
104 fich >> separ; fich.getline(blabla, 80) ;
105 separ *= km ; // translation in machine units
106
107 int irrot1_i, irrot2_i ;
108 double ent_c1, ent_c2 ;
109 fich >> ent_c1 ; fich.getline(blabla, 80) ;
110 fich >> irrot1_i ; fich.getline(blabla, 80) ;
111 bool irrot1 = (irrot1_i == 1) ;
112 fich >> ent_c2 ; fich.getline(blabla, 80) ;
113 fich >> irrot2_i ; fich.getline(blabla, 80) ;
114 bool irrot2 = (irrot2_i == 1) ;
115
116 fich.close() ;
117
118 cout << endl << "Requested orbital separation : " << separ / km
119 << " km" << endl ;
120
121 fich.open("par_grid1.d") ;
122 fich.getline(blabla, 80);
123 fich.getline(blabla, 80);
124 fich >> nz; fich.getline(blabla, 80) ;
125 int nzet1 ;
126 fich >> nzet1; fich.getline(blabla, 80) ;
127 fich >> nt; fich.getline(blabla, 80) ;
128 fich >> np; fich.getline(blabla, 80) ;
129
130 cout << "total number of domains : nz = " << nz << endl ;
131 cout << "number of points in phi : np = " << np << endl ;
132 cout << "number of points in theta : nt = " << nt << endl ;
133
134 int* nr = new int[nz];
135 int* nt_tab = new int[nz];
136 int* np_tab = new int[nz];
137 double* bornes = new double[nz+1];
138
139 fich.getline(blabla, 80);
140 for (int l=0; l<nz; l++) {
141 fich >> nr[l];
142 fich >> bornes[l]; fich.getline(blabla, 80) ;
143 np_tab[l] = np ;
144 nt_tab[l] = nt ;
145 }
146 bornes[nz] = __infinity ;
147
148 Tbl ent_limit1(nzet1) ;
149 Tbl* pent_limit1 ;
150 ent_limit1.set_etat_qcq() ;
151 ent_limit1.set(nzet1-1) = 0 ; // enthalpy at the stellar surface
152 fich >> ent_limit1.set(0) ;
153 if ( fich.good() ) { // to ensure backwards compatibility
154 for (int l=1; l<nzet1-1; l++) {
155 fich >> ent_limit1.set(l) ; fich.getline(blabla, 120) ;
156 }
157 pent_limit1 = &ent_limit1 ;
158 }
159 else {
160 pent_limit1 = 0x0 ;
161 }
162
163 fich.close();
164
165 for (int l=0; l<nzet1-1; l++)
166 bornes[l+1] = bornes[nzet1] * sqrt(1 - ent_limit1(l) / ent_c1) ;
167
168 // Type of r sampling :
169 int* type_r = new int[nz];
170 type_r[0] = RARE ;
171 for (int l=1; l<nz-1; l++) {
172 type_r[l] = FIN ;
173 }
174 type_r[nz-1] = UNSURR ;
175
176 // Type of sampling in theta and phi :
177 int type_t = SYM ;
178 int type_p = NONSYM ;
179
180 //------------------------------------------------------------------
181 // Construction of multi-grid 1 and mapping 1
182 //------------------------------------------------------------------
183
184 Mg3d mg1(nz, nr, type_r, nt_tab, type_t, np_tab, type_p) ;
185
186 Map_et mp1(mg1, bornes) ;
187
188 delete [] nr ;
189 delete [] nt_tab ;
190 delete [] np_tab ;
191 delete [] type_r ;
192 delete [] bornes ;
193
194 //------------------------------------------------------------------
195 // Input data for the multi-grid no. 2
196 //------------------------------------------------------------------
197
198
199 fich.open("par_grid2.d") ;
200 fich.getline(blabla, 80);
201 fich.getline(blabla, 80);
202 fich >> nz; fich.getline(blabla, 80) ;
203 int nzet2 ;
204 fich >> nzet2; fich.getline(blabla, 80) ;
205 fich >> nt; fich.getline(blabla, 80) ;
206 fich >> np; fich.getline(blabla, 80) ;
207
208 cout << "total number of domains : nz = " << nz << endl ;
209 cout << "number of points in phi : np = " << np << endl ;
210 cout << "number of points in theta : nt = " << nt << endl ;
211
212 nr = new int[nz];
213 nt_tab = new int[nz];
214 np_tab = new int[nz];
215 bornes = new double[nz+1];
216
217 fich.getline(blabla, 80);
218 for (int l=0; l<nz; l++) {
219 fich >> nr[l];
220 fich >> bornes[l]; fich.getline(blabla, 80) ;
221 np_tab[l] = np ;
222 nt_tab[l] = nt ;
223 }
224 bornes[nz] = __infinity ;
225
226 Tbl ent_limit2(nzet2) ;
227 Tbl* pent_limit2 ;
228 ent_limit2.set_etat_qcq() ;
229 ent_limit2.set(nzet2-1) = 0 ; // enthalpy at the stellar surface
230 fich >> ent_limit2.set(0) ;
231 if ( fich.good() ) { // to ensure backwards compatibility
232 for (int l=1; l<nzet2-1; l++) {
233 fich >> ent_limit2.set(l) ; fich.getline(blabla, 120) ;
234 }
235 pent_limit2 = &ent_limit2 ;
236 }
237 else {
238 pent_limit2 = 0x0 ;
239 }
240
241
242 for (int l=0; l<nzet2-1; l++) {
243 fich >> ent_limit2.set(l) ; fich.getline(blabla, 120) ;
244 }
245
246 fich.close();
247
248 for (int l=0; l<nzet2-1; l++)
249 bornes[l+1] = bornes[nzet2] * sqrt(1 - ent_limit2(l) / ent_c2) ;
250
251 // Type of r sampling :
252 type_r = new int[nz];
253 type_r[0] = RARE ;
254 for (int l=1; l<nz-1; l++) {
255 type_r[l] = FIN ;
256 }
257 type_r[nz-1] = UNSURR ;
258
259 //------------------------------------------------------------------
260 // Construction of multi-grid 2 and mapping 2
261 //------------------------------------------------------------------
262
263 Mg3d mg2(nz, nr, type_r, nt_tab, type_t, np_tab, type_p) ;
264
265 Map_et mp2(mg2, bornes) ;
266
267 delete [] nr ;
268 delete [] nt_tab ;
269 delete [] np_tab ;
270 delete [] type_r ;
271 delete [] bornes ;
272
273 cout << endl << "Multi-grid 1 : "
274 << endl << "============ " << endl << mg1 << endl ;
275 cout << "Mapping 1 : "
276 << endl << "========= " << endl << mp1 << endl ;
277
278 cout << endl << "Multi-grid 2 : "
279 << endl << "============ " << endl << mg2 << endl ;
280 cout << "Mapping 2 : "
281 << endl << "========= " << endl << mp2 << endl ;
282
283 //------------------------------------------------------------------
284 // Equation of state for star 1
285 //------------------------------------------------------------------
286
287 fich.open("par_eos1.d") ;
288
289 Eos* peos1 = Eos::eos_from_file(fich) ;
290 Eos& eos1 = *peos1 ;
291
292 fich.close() ;
293
294 //------------------------------------------------------------------
295 // Equation of state for star 2
296 //------------------------------------------------------------------
297
298 fich.open("par_eos2.d") ;
299
300 Eos* peos2 = Eos::eos_from_file(fich) ;
301 Eos& eos2 = *peos2 ;
302
303 fich.close() ;
304
305 cout << endl << "Equation of state of star 1 : "
306 << endl << "=========================== " << endl << eos1 << endl ;
307 cout << endl << "Equation of state of star 2 : "
308 << endl << "=========================== " << endl << eos2 << endl ;
309
310 //------------------------------------------------------------------
311 // Construction of a binary system
312 //------------------------------------------------------------------
313
314 Binary_xcts star(mp1, nzet1, eos1, irrot1,
315 mp2, nzet2, eos2, irrot2) ;
316
317 //------------------------------------------------------------------
318 // Computation of two static configurations
319 //------------------------------------------------------------------
320
321 double precis = 1.e-14 ;
322
323 cout << endl << "Computation of a static configuration for star 1"
324 << endl << "================================================" << endl ;
325 (star.set(1)).equilibrium_spher(ent_c1, precis, pent_limit1) ;
326
327 star.set(1).set_Psi_auto() = exp(0.5*(star(1).get_lnq()-star(1).get_logn())) - 1.;
328 star.set(1).set_Psi_auto().std_spectral_base() ;
329
330 star.set(1).set_chi_auto() = exp(0.5*(star(1).get_lnq()+star(1).get_logn())) - 1.;
331 star.set(1).set_chi_auto().std_spectral_base() ;
332
333
334 cout << endl << "Computation of a static configuration for star 2"
335 << endl << "================================================" << endl ;
336
337 (star.set(2)).equilibrium_spher(ent_c2, precis, pent_limit2) ;
338
339 star.set(2).set_Psi_auto() = exp(0.5*(star(2).get_lnq()-star(2).get_logn())) - 1.;
340 star.set(2).set_Psi_auto().std_spectral_base() ;
341
342 star.set(2).set_chi_auto() = exp(0.5*(star(2).get_lnq()+star(2).get_logn())) - 1.;
343 star.set(2).set_chi_auto().std_spectral_base() ;
344
345 //-----------------------------------------------------------------------
346 // Sets the stars at Newtonian (Keplerian) position
347 //-----------------------------------------------------------------------
348
349 // Omega and rotation axis
350 // -----------------------
351
352 double total_mass = star(1).mass_g() + star(2).mass_g() ;
353
354 star.set_omega() = sqrt( g_si/g_unit * total_mass / pow(separ, 3.) ) ;
355
356 star.set_x_axe() = 0 ;
357
358
359 // Position of the two stars
360 // -------------------------
361
362 for (int i=1 ; i<=2 ; i++) {
363
364 double xa_et = (star(3-i).mass_g()) / total_mass * separ ;
365 if (i == 1) xa_et = - xa_et ;
366
367 ((star.set(i)).set_mp()).set_ori(xa_et, 0., 0.) ;
368 }
369
370 // Orientation of the two stars
371 // ----------------------------
372
373 // Star 1 aligned with the absolute frame :
374 ((star.set(1)).set_mp()).set_rot_phi(0.) ;
375
376 // Star 2 anti-aligned with the absolute frame :
377 ((star.set(2)).set_mp()).set_rot_phi(M_PI) ;
378
379
380 cout << endl
381 << "=============================================================" << endl
382 << "=============================================================" << endl ;
383 cout << endl << "Final characteristics of the computed system : " << endl ;
384 cout.precision(16) ;
385 cout << star << endl ;
386
387 star.display_poly(cout) ; // Reduced quantities for polytropic EOS
388 //-----------------------------------------------------------------------
389 // The result is written in a file
390 //-----------------------------------------------------------------------
391
392 FILE* fresu = fopen("ini.d", "w") ;
393
394 int mer = 0 ;
395 fwrite(&mer, sizeof(int), 1, fresu) ; // mer
396
397 mg1.sauve(fresu) ;
398 mp1.sauve(fresu) ;
399 eos1.sauve(fresu) ;
400
401 mg2.sauve(fresu) ;
402 mp2.sauve(fresu) ;
403 eos2.sauve(fresu) ;
404
405 star.sauve(fresu) ;
406
407 fclose(fresu) ;
408
409 // Cleaning
410 // --------
411
412 delete peos1 ;
413 delete peos2 ;
414
415 return EXIT_SUCCESS ;
416
417 }