Debian Codegraph @

Codes/Bin_star_ncp/init_bin_ncp.C

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