Debian Codegraph @

Codes/Binary_star/init_bin.C

raw
1 /*
2 * Construction of initial conditions for a binary star computation.
3 *
4 */
5
6 /*
7 * Copyright (c) 2004 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
27 char init_bin_C[] = "$Header: /cvsroot/Lorene/Codes/Binary_star/init_bin.C,v 1.7 2014/10/13 08:53:55 j_novak Exp $" ;
28
29 /*
30 * $Id: init_bin.C,v 1.7 2014/10/13 08:53:55 j_novak Exp $
31 * $Log: init_bin.C,v $
32 * Revision 1.7 2014/10/13 08:53:55 j_novak
33 * Lorene classes and functions now belong to the namespace Lorene.
34 *
35 * Revision 1.6 2014/10/06 15:09:40 j_novak
36 * Modified #include directives to use c++ syntax.
37 *
38 * Revision 1.5 2005/09/13 19:47:28 f_limousin
39 * Reintroduction of the resolution of the equations in cartesian coordinates.
40 *
41 * Revision 1.4 2004/09/16 12:14:30 f_limousin
42 * *** empty log message ***
43 *
44 * Revision 1.2 2004/01/22 10:12:50 f_limousin
45 * First version
46 *
47 * $Header: /cvsroot/Lorene/Codes/Binary_star/init_bin.C,v 1.7 2014/10/13 08:53:55 j_novak Exp $
48 *
49 */
50
51
52
53 // headers C
54 #include <cstdlib>
55 #include <cmath>
56
57 // headers Lorene
58 #include "unites.h"
59 #include "binary.h"
60 #include "eos.h"
61 #include "utilitaires.h"
62 #include "graphique.h"
63 #include "nbr_spx.h"
64
65 using namespace Lorene ;
66
67 //******************************************************************************
68
69 int main(){
70
71
72 // Identification of all the subroutines called by the code :
73
74 // system("ident init_bin") ;
75
76
77 //-----------------------------------------------------------------------
78 // Input data for the multi-grid no. 1
79 //-----------------------------------------------------------------------
80
81 int nt, np, nz ;
82 char blabla[80] ;
83
84 ifstream fich("par_grid1.d") ;
85 fich.getline(blabla, 80);
86 fich.getline(blabla, 80);
87 fich >> nz; fich.getline(blabla, 80) ;
88 int nzet1 ;
89 fich >> nzet1; fich.getline(blabla, 80) ;
90 fich >> nt; fich.getline(blabla, 80) ;
91 fich >> np; fich.getline(blabla, 80) ;
92
93 cout << "total number of domains : nz = " << nz << endl ;
94 cout << "number of points in phi : np = " << np << endl ;
95 cout << "number of points in theta : nt = " << nt << endl ;
96
97 int* nr = new int[nz];
98 int* nt_tab = new int[nz];
99 int* np_tab = new int[nz];
100 double* bornes = new double[nz+1];
101
102 fich.getline(blabla, 80);
103 for (int l=0; l<nz; l++) {
104 fich >> nr[l];
105 fich >> bornes[l]; fich.getline(blabla, 80) ;
106 np_tab[l] = np ;
107 nt_tab[l] = nt ;
108 }
109 bornes[nz] = __infinity ;
110
111 fich.close();
112
113
114 // Type of r sampling :
115 int* type_r = new int[nz];
116 type_r[0] = RARE ;
117 for (int l=1; l<nz-1; l++) {
118 type_r[l] = FIN ;
119 }
120 type_r[nz-1] = UNSURR ;
121
122 // Type of sampling in theta and phi :
123 int type_t = SYM ;
124 int type_p = NONSYM ;
125
126 //-----------------------------------------------------------------------
127 // Construction of multi-grid 1 and mapping 1
128 //-----------------------------------------------------------------------
129
130 Mg3d mg1(nz, nr, type_r, nt_tab, type_t, np_tab, type_p) ;
131
132 Map_et mp1(mg1, bornes) ;
133
134 delete [] nr ;
135 delete [] nt_tab ;
136 delete [] np_tab ;
137 delete [] type_r ;
138 delete [] bornes ;
139
140 //-----------------------------------------------------------------------
141 // Input data for the multi-grid no. 2
142 //-----------------------------------------------------------------------
143
144
145 fich.open("par_grid2.d") ;
146 fich.getline(blabla, 80);
147 fich.getline(blabla, 80);
148 fich >> nz; fich.getline(blabla, 80) ;
149 int nzet2 ;
150 fich >> nzet2; fich.getline(blabla, 80) ;
151 fich >> nt; fich.getline(blabla, 80) ;
152 fich >> np; fich.getline(blabla, 80) ;
153
154 cout << "total number of domains : nz = " << nz << endl ;
155 cout << "number of points in phi : np = " << np << endl ;
156 cout << "number of points in theta : nt = " << nt << endl ;
157
158 nr = new int[nz];
159 nt_tab = new int[nz];
160 np_tab = new int[nz];
161 bornes = new double[nz+1];
162
163 fich.getline(blabla, 80);
164 for (int l=0; l<nz; l++) {
165 fich >> nr[l];
166 fich >> bornes[l]; fich.getline(blabla, 80) ;
167 np_tab[l] = np ;
168 nt_tab[l] = nt ;
169 }
170 bornes[nz] = __infinity ;
171
172 fich.close();
173
174
175 // Type of r sampling :
176 type_r = new int[nz];
177 type_r[0] = RARE ;
178 for (int l=1; l<nz-1; l++) {
179 type_r[l] = FIN ;
180 }
181 type_r[nz-1] = UNSURR ;
182
183 //-----------------------------------------------------------------------
184 // Construction of multi-grid 2 and mapping 2
185 //-----------------------------------------------------------------------
186
187 Mg3d mg2(nz, nr, type_r, nt_tab, type_t, np_tab, type_p) ;
188
189 Map_et mp2(mg2, bornes) ;
190
191 delete [] nr ;
192 delete [] nt_tab ;
193 delete [] np_tab ;
194 delete [] type_r ;
195 delete [] bornes ;
196
197 cout << endl << "Multi-grid 1 : "
198 << endl << "============ " << endl << mg1 << endl ;
199 cout << "Mapping 1 : "
200 << endl << "========= " << endl << mp1 << endl ;
201
202 cout << endl << "Multi-grid 2 : "
203 << endl << "============ " << endl << mg2 << endl ;
204 cout << "Mapping 2 : "
205 << endl << "========= " << endl << mp2 << endl ;
206
207 //-----------------------------------------------------------------------
208 // Equation of state for star 1
209 //-----------------------------------------------------------------------
210
211 fich.open("par_eos1.d") ;
212
213 Eos* peos1 = Eos::eos_from_file(fich) ;
214 Eos& eos1 = *peos1 ;
215
216 fich.close() ;
217
218 //-----------------------------------------------------------------------
219 // Equation of state for star 2
220 //-----------------------------------------------------------------------
221
222 fich.open("par_eos2.d") ;
223
224 Eos* peos2 = Eos::eos_from_file(fich) ;
225 Eos& eos2 = *peos2 ;
226
227 fich.close() ;
228
229 cout << endl << "Equation of state of star 1 : "
230 << endl << "=========================== " << endl << eos1 << endl ;
231 cout << endl << "Equation of state of star 2 : "
232 << endl << "=========================== " << endl << eos2 << endl ;
233
234
235 //-----------------------------------------------------------------------
236 // Physical parameters imput
237 //-----------------------------------------------------------------------
238
239 using namespace Unites ;
240
241 fich.open("par_init.d") ;
242 fich.getline(blabla, 80) ;
243 fich.getline(blabla, 80) ;
244
245 double separ ;
246 fich >> separ; fich.getline(blabla, 80) ;
247 separ *= km ; // translation in machine units
248
249 int irrot1_i, irrot2_i ;
250 double ent_c1, ent_c2 ;
251 fich >> ent_c1 ; fich.getline(blabla, 80) ;
252 fich >> irrot1_i ; fich.getline(blabla, 80) ;
253 bool irrot1 = (irrot1_i == 1) ;
254 fich >> ent_c2 ; fich.getline(blabla, 80) ;
255 fich >> irrot2_i ; fich.getline(blabla, 80) ;
256 bool irrot2 = (irrot2_i == 1) ;
257
258 int conf_flat_i ;
259 fich >> conf_flat_i; fich.getline(blabla, 80) ;
260 bool conf_flat = (conf_flat_i == 1) ;
261
262 fich.close() ;
263
264 cout << endl << "Requested orbital separation : " << separ / km
265 << " km" << endl ;
266
267 //-----------------------------------------------------------------------
268 // Construction of a binary system
269 //-----------------------------------------------------------------------
270
271 Binary star(mp1, nzet1, eos1, irrot1,
272 mp2, nzet2, eos2, irrot2, conf_flat) ;
273
274 //-----------------------------------------------------------------------
275 // Computation of two static configurations
276 //-----------------------------------------------------------------------
277
278 double precis = 1.e-12 ;
279
280 cout << endl << "Computation of a static configuration for star 1"
281 << endl << "================================================" << endl ;
282 (star.set(1)).equilibrium_spher(ent_c1, precis) ;
283
284 (star.set(1)).set_logn_auto (star(1).get_logn()) ;
285 (star.set(1)).set_lnq_auto (star(1).get_lnq()) ;
286
287
288 cout << endl << "Computation of a static configuration for star 2"
289 << endl << "================================================" << endl ;
290
291 (star.set(2)).equilibrium_spher(ent_c2, precis) ;
292
293 (star.set(2)).set_logn_auto (star(2).get_logn()) ;
294 (star.set(2)).set_lnq_auto (star(2).get_lnq()) ;
295
296 //-----------------------------------------------------------------------
297 // Sets the stars at Newtonian (Keplerian) position
298 //-----------------------------------------------------------------------
299
300 // Omega and rotation axis
301 // -----------------------
302
303 double total_mass = star(1).mass_g() + star(2).mass_g() ;
304
305 star.set_omega() = sqrt( g_si/g_unit * total_mass / pow(separ, 3.) ) ;
306
307 star.set_x_axe() = 0 ;
308
309
310 // Position of the two stars
311 // -------------------------
312
313 for (int i=1 ; i<=2 ; i++) {
314
315 double xa_et = (star(3-i).mass_g()) / total_mass * separ ;
316 if (i == 1) xa_et = - xa_et ;
317
318 ((star.set(i)).set_mp()).set_ori(xa_et, 0., 0.) ;
319 }
320
321 // Orientation of the two stars
322 // ----------------------------
323
324 // Star 1 aligned with the absolute frame :
325 ((star.set(1)).set_mp()).set_rot_phi(0.) ;
326
327 // Star 2 anti-aligned with the absolute frame :
328 ((star.set(2)).set_mp()).set_rot_phi(M_PI) ;
329
330
331 cout << endl
332 << "=============================================================" << endl
333 << "=============================================================" << endl ;
334 cout << endl << "Final characteristics of the computed system : " << endl ;
335 cout.precision(16) ;
336 cout << star << endl ;
337
338 //-----------------------------------------------------------------------
339 // The result is written in a file
340 //-----------------------------------------------------------------------
341
342 FILE* fresu = fopen("ini.d", "w") ;
343
344 int mer = 0 ;
345 fwrite(&mer, sizeof(int), 1, fresu) ; // mer
346
347 mg1.sauve(fresu) ;
348 mp1.sauve(fresu) ;
349 eos1.sauve(fresu) ;
350
351 mg2.sauve(fresu) ;
352 mp2.sauve(fresu) ;
353 eos2.sauve(fresu) ;
354
355 star.sauve(fresu) ;
356
357 fclose(fresu) ;
358
359 // Cleaning
360 // --------
361
362 delete peos1 ;
363 delete peos2 ;
364
365 return EXIT_SUCCESS ;
366
367
368 }