Debian Codegraph @

Codes/Bin_star/init_bin_regu.C

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