Debian Codegraph @

Codes/Rot_star/test_maclaurin.C

raw
1 /*
2 * Test program for solving Maclaurin-like figures
3 * One zone for the internal of the star
4 *
5 */
6
7 /*
8 * Copyright (c) 1999-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 test_maclaurin_C[] = "$Header: /cvsroot/Lorene/Codes/Rot_star/test_maclaurin.C,v 1.4 2014/10/13 08:53:59 j_novak Exp $" ;
29
30 /*
31 * $Id: test_maclaurin.C,v 1.4 2014/10/13 08:53:59 j_novak Exp $
32 * $Log: test_maclaurin.C,v $
33 * Revision 1.4 2014/10/13 08:53:59 j_novak
34 * Lorene classes and functions now belong to the namespace Lorene.
35 *
36 * Revision 1.3 2014/10/06 15:09:46 j_novak
37 * Modified #include directives to use c++ syntax.
38 *
39 * Revision 1.2 2003/01/09 11:07:51 j_novak
40 * headcpp.h is now compliant with C++ norm.
41 * The include files have been ordered, as well as the local_settings_linux
42 *
43 * Revision 1.1.1.1 2001/11/20 15:19:31 e_gourgoulhon
44 * LORENE
45 *
46 * Revision 1.2 1999/12/23 13:39:23 keisuke
47 * Non significant change (for test only).
48 *
49 * Revision 1.1 1999/12/23 13:35:01 keisuke
50 * Initial revision
51 *
52 *
53 * $Header: /cvsroot/Lorene/Codes/Rot_star/test_maclaurin.C,v 1.4 2014/10/13 08:53:59 j_novak Exp $
54 *
55 */
56
57 // headers C
58 #include <cstdlib>
59 #include <cmath>
60
61 // headers Lorene
62 #include "type_parite.h"
63 #include "cmp.h"
64 #include "graphique.h"
65 #include "utilitaires.h"
66
67 namespace Lorene {
68 // Local prototypes:
69 Cmp eos_local(const Cmp& ent, int nzet, double n_index) ;
70 }
71 //**********************************************************************
72
73 int main(){
74
75 // Identification of all the subroutines called by the code :
76
77 system("ident test_maclaurin > identif_maclaurin.d") ;
78
79 //-----------------------------------------------------------------------
80 // Input from file "part.d"
81 //-----------------------------------------------------------------------
82
83 int type_t, type_p, nt, np, nz, l;
84 char blabla[80];
85 // const double criteria = 1.e-8 ;
86 double n_index, radius ;
87
88 //----------------------------------------------------
89 // Declear the polytropic index
90 //----------------------------------------------------
91 cout << "Input a polytropic index: " ;
92 cin >> n_index ;
93 cout << "Input an equatorial radius of the star : " ;
94 cin >> radius ;
95
96 ifstream fich("part.d") ;
97 fich >> nt; fich.getline(blabla, 80);
98 fich >> np; fich.getline(blabla, 80);
99 fich >> nz; fich.getline(blabla, 80);
100
101 cout << "nb de points en phi : np = " << np << endl;
102 cout << "nb de points en theta : nt = " << nt << endl;
103 cout << "nb de zones : nz = " << nz << endl;
104
105 // initialisation des tableaux decrivant chaque zone
106
107 int* nr = new int[nz];
108 int* nt_tab = new int[nz];
109 int* np_tab = new int[nz];
110 double* bornes = new double[nz+1];
111 int* type_r = new int[nz];
112
113 fich >> bornes[nz] ; fich.getline(blabla, 80) ;
114 for (l=0; l<nz; l++) {
115 fich >> nr[l];
116 fich >> bornes[l];
117 fich >> type_r[l]; fich.getline(blabla, 80);
118 np_tab[l] = np ;
119 nt_tab[l] = nt ;
120 }
121 if (type_r[nz-1]==UNSURR) bornes[nz] = 1./bornes[nz] ;
122
123 fich.close();
124
125
126 //-----------------------------------------------------------------------
127 // Construction of a multi-grid
128 //-----------------------------------------------------------------------
129
130 type_t = SYM ;
131 type_p = NONSYM ;
132
133 Mg3d mg(nz, nr, type_r, nt_tab, type_t, np_tab, type_p) ;
134
135 cout << endl << "Grid mg : " << mg << endl ;
136
137 //-----------------------------------------------------------------------
138 // Construction of a mapping
139 //-----------------------------------------------------------------------
140
141 Map_af mp(mg, bornes) ;
142 cout << "Mapping mp : " << mp << endl ;
143
144 //-----------------------------------------------------------------------
145 // Construction of a Cmp
146 //-----------------------------------------------------------------------
147
148 Cmp rho(mp) ;
149
150 const Coord& r = mp.r ;
151 // const Coord& x = mp.x ;
152 // const Coord& y = mp.y ;
153 const Coord& sint = mp.sint ;
154
155 rho = 1 ;
156 rho.annule(nz-1) ; // rho = 1 in internal domains
157 // rho = 0 in external domain
158
159 rho.set_dzpuis(4) ;
160 rho.std_base_scal() ; // Sets the standard basis for spectral expansions
161
162 int nr_s = mg.get_nr(nz-2) ;
163
164 Cmp pot(mp) ;
165 Cmp rho_prev(mp) ;
166 Cmp rot(mp) ;
167
168 Cmp ent(mp) ;
169 double ent_c = 1 ; // central value of enthalpy
170 double ent_s = 0 ; // surface value of enthalpy
171
172 double omega2 ;
173 double omega2_prev ;
174 double rel_omega ;
175 omega2 = 0 ;
176
177 do {
178
179 // Solving the Poisson equation
180 //------------------------------
181 pot = - rho.poisson() ;
182
183 // Obtaining "lambda" in order to rescale the mapping
184 //----------------------------------------------------
185 double pot_c = pot(0,0,0,0) ; // central value of potential
186
187 // surface value of potential in the equatorial plane
188 double pot_seq = pot(nz-2,0,nt-1,nr_s-1) ;
189
190 double radi = mp.val_r(nz-2,1.,M_PI/2,0) ;
191
192 double lambda = radius / radi ;
193 cout << "lambda : " << lambda << endl ;
194
195 // Angular velocity
196 //------------------
197 omega2_prev = omega2 ;
198 omega2 = 8.*(ent_s - ent_c - pot_seq + pot_c) / (radius * radius) ;
199 cout << "Omega^2/(pi G rho_c) : " << omega2 << endl ;
200
201 rel_omega = fabs(1. - omega2_prev / omega2) ;
202 cout << "Relative error in Omega^2 : " << rel_omega << endl ;
203
204 // New potential after rescaling
205 //-------------------------------
206 pot = lambda * lambda * pot ;
207 pot_c = lambda * lambda * pot_c ;
208 pot_seq = lambda * lambda * pot_seq ;
209
210 // First integral of motion
211 //--------------------------
212 rot = 0.125 * omega2 * r * r * sint * sint ;
213 // rot.annule(nz-1) ;
214 ent = ent_c + pot - pot_c + rot ; // enthalpy
215 ent.annule(nz-1) ;
216
217 // Rescale of the map
218 //--------------------
219 mp.homothetie( lambda ) ;
220
221 rho_prev = rho ;
222
223 // EOS : rho = rho(H)
224 //--------------------
225 rho = eos_local(ent, nz-1, n_index) ;
226
227 rho.set_dzpuis(4) ;
228 rho.std_base_scal() ;
229
230 cout << max(abs(rho - rho_prev)) << endl ;
231 cout << "Maximum error in rho : "
232 << max(diffrel(rho, rho_prev)) << endl ;
233
234 } while(max(diffrel(rho, rho_prev)) > 1.e-10) ;
235
236 arrete() ;
237
238 cout << "Coef of rho : " << endl ;
239 rho.affiche_seuil(cout) ;
240
241 cout << "Coef of pot : " << endl ;
242 pot.affiche_seuil(cout) ;
243
244 arrete() ;
245 cout << "Value of pot at the origin : " << pot(0,0,0,0) << endl ;
246 cout << "Value of pot at the surface (r=radius_eq) : "
247 << pot(nz-1,0,0,0) << endl ;
248 cout << "Value of pot at the surface (r=radius_eq) : "
249 << pot(nz-2,0,0,nr_s-1) << endl ;
250
251
252 // Checking whether or not the potential satisfies the Poisson equation
253 //----------------------------------------------------------------------
254 Cmp lap = - pot.laplacien() ;
255
256 cout << "max( |lap(pot) - rho| ) " << max(abs(lap - rho)) << endl ;
257 cout << "relative error : " << diffrel(lap, rho) << endl ;
258
259
260 // Serching the radius to the north pole
261 //---------------------------------------
262 double zaxis = 0 ;
263 do {
264 zaxis += 1.e-1 ;
265 } while(ent.val_point(zaxis,0,0) >= 0) ;
266 zaxis = zaxis - 1.e-1 ;
267 do {
268 zaxis += 1.e-2 ;
269 } while(ent.val_point(zaxis,0,0) >= 0) ;
270 zaxis = zaxis - 1.e-2 ;
271 do {
272 zaxis += 1.e-3 ;
273 } while(ent.val_point(zaxis,0,0) >= 0) ;
274 zaxis = zaxis - 1.e-3 ;
275 do {
276 zaxis += 1.e-4 ;
277 } while(ent.val_point(zaxis,0,0) >= 0) ;
278 zaxis = zaxis - 1.e-4 ;
279 do {
280 zaxis += 1.e-5 ;
281 } while(ent.val_point(zaxis,0,0) >= 0) ;
282 zaxis = zaxis - 1.e-5 ;
283 do {
284 zaxis += 1.e-6 ;
285 } while(ent.val_point(zaxis,0,0) >= 0) ;
286 zaxis = zaxis - 1.e-6 ;
287
288 arrete() ;
289
290 double radius_z = zaxis ;
291 cout << "Radius of the star at the north pole : " << radius_z
292 << endl ;
293
294 // Radius of the star
295 //--------------------
296 double radius_eq = mp.val_r(nz-2,1.,M_PI/2,0) ;
297 cout << "Radius of the star in the equatorial plane : "
298 << radius_eq << endl ;
299
300 cout << "Ratio of the axes a_3/a_1 : " << radius_z/radius_eq << endl ;
301 cout << "Eccentricity : " << sqrt(1. - pow(radius_z / radius_eq, 2))
302 << endl ;
303
304 // Angular velocity
305 //------------------
306 double omega = sqrt(omega2) ;
307 cout << "Angular velocity of the star Omega/(pi G rho_c)^{1/2} : "
308 << omega << endl ;
309 cout << "Omega^2/(pi G rho_c) : " << omega2 << endl ;
310
311 arrete() ;
312
313 // Mass of the star
314 //------------------
315 double mass = rho.integrale() ;
316 cout << "Mass/rho_c : " << mass << endl ;
317
318 // Total energy of the star
319 //--------------------------
320 Cmp rho_n(mp) ;
321
322 rho_n = pow(abs(rho), 1 + 1/n_index) ;
323 rho_n.annule(nz-1) ;
324 rho_n.set_dzpuis(4) ;
325 rho_n.std_base_scal() ;
326
327 double energy_internal = 4. * M_PI *
328 (1 / (1 + n_index)) * rho_n.integrale() * radius_eq / (mass * mass) ;
329 cout << "Internal energy of the axisymmetric star : "
330 << "E_int/(GM^2/radius_eq) : "
331 << n_index * energy_internal << endl ;
332
333 Cmp rho_pot(mp) ;
334 rho_pot = rho * pot ;
335 rho_pot.annule(nz-1) ;
336 rho_pot.set_dzpuis(4) ;
337 rho_pot.std_base_scal() ;
338 double energy_selfgrav = -2. * M_PI * rho_pot.integrale() * radius_eq /
339 (mass * mass) ;
340 cout << "Self-gravity energy of the axisymmetric star : "
341 << "E_self/(GM^2/radius_eq) : "
342 << energy_selfgrav << endl ;
343
344 Cmp rr(mp) ;
345 Cmp rho_quad(mp) ;
346 rr = r * r * sint * sint ;
347 rr.annule(nz-1) ;
348 rr.set_dzpuis(4) ;
349 rr.std_base_scal() ;
350 rho_quad = rho * rr ;
351 rho_quad.annule(nz-1) ;
352 rho_quad.set_dzpuis(4) ;
353 rho_quad.std_base_scal() ;
354 double energy_kinetic = 0.5 * M_PI * omega2 * rho_quad.integrale() *
355 radius_eq / (mass * mass) ;
356 cout << "Kinetic energy of the axisymmetric star : "
357 << "E_kinet/(GM^2/radius_eq) : "
358 << energy_kinetic << endl ;
359
360 double energy_total = n_index * energy_internal + energy_selfgrav
361 + energy_kinetic ;
362
363 cout << "Total energy of the axisymmetric star : "
364 << "E/(GM^2/radius_eq) : "
365 << energy_total << endl ;
366
367 // Angular momentum
368 //------------------
369 double angmom = sqrt(M_PI) * omega * rho_quad.integrale() /
370 sqrt( mass * mass * mass * radius_eq ) ;
371
372 cout << "Angular momentum of the axisymmetric star : "
373 << "J/(GM^3 radius_eq)^{1/2} : "
374 << angmom << endl ;
375
376 // Ratio T/|W|
377 //-------------
378 cout << "Ratio T/|W| : "
379 << energy_kinetic / fabs(energy_selfgrav) << endl ;
380
381 // Virial relation
382 //-----------------
383 double virial = 3. * energy_internal + energy_selfgrav
384 + 2. * energy_kinetic ;
385 cout << "Virial relation : " << virial << endl ;
386
387 //------------------------------------------
388 // Plot the figures
389 //------------------------------------------
390 double rmax ;
391 cout << "r_max ?" << endl ;
392 cin >> rmax ;
393
394 des_profile(rho, 0., rmax, 0., 0., "rho/rho_c", "rho (z direction)") ;
395 des_profile(rho, 0., rmax, M_PI/2, 0., "rho/rho_c", "rho (x-y plane)") ;
396 des_profile(ent,0.,rmax,0.,0., "enthalpy", "enthalpy (z direction)") ;
397 des_profile(ent,0.,rmax,M_PI/2,0., "enthalpy", "enthalpy (x-y plane)") ;
398 des_coupe_x(rho, 0., -rmax, rmax, -rmax, rmax, "rho (y-z plane)") ;
399 des_coupe_y(rho, 0., -rmax, rmax, -rmax, rmax, "rho (z-x plane)") ;
400 des_coupe_z(rho, 0., -rmax, rmax, -rmax, rmax, "rho (x-y plane)") ;
401
402 des_profile(rho_n,0.,rmax,0.,0.,"internal","internal (z direction)") ;
403 des_profile(rho_n,0.,rmax,M_PI/2,0.,"internal","internal (x-y plane)") ;
404 des_profile(rho_pot,0.,rmax,0.,0.,"selfgrav","selfgrav (z direction)") ;
405 des_profile(rho_pot,0.,rmax,M_PI/2,0.,"selfgrav","selfgrav (x-y plane)") ;
406 des_profile(rho_quad,0.,rmax,0.,0.,"kinetic","kinetic (z direction)") ;
407 des_profile(rho_quad,0.,rmax,M_PI/2,0.,"kinetic","kinetic (x-y plane)") ;
408
409 des_coef_xi(rho.va, 0, 0, 0, 1.e-14, "log|c_i|", "domain no. 0") ;
410 des_coef_theta(rho.va, 0, 0, 0) ;
411 des_coef_phi(rho.va, 0, 0, 0) ;
412
413 des_coef_xi(rho.va, 1, 0, 0, 1.e-14, "log|c_i|", "domain no. 1") ;
414 des_coef_theta(rho.va, 0, 0, 0) ;
415 des_coef_phi(rho.va, 0, 0, 0) ;
416
417 // des_coef_xi(rho.va, 2, 0, 0, 1.e-14, "log|c_i|", "domain no. 2") ;
418 // des_coef_theta(rho.va, 0, 0, 0) ;
419 // des_coef_phi(rho.va, 0, 0, 0) ;
420
421 exit(-1) ;
422
423 }