Debian Codegraph @

Codes/Rot_star/test_jacobi.C

raw
1 /*
2 * Test program for solving Jacobi-like figures
3 *
4 */
5
6 /*
7 * Copyright (c) 1999-2001 Keisuke Taniguchi
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 test_jacobi_C[] = "$Header: /cvsroot/Lorene/Codes/Rot_star/test_jacobi.C,v 1.4 2014/10/13 08:53:59 j_novak Exp $" ;
28
29 /*
30 * $Id: test_jacobi.C,v 1.4 2014/10/13 08:53:59 j_novak Exp $
31 * $Log: test_jacobi.C,v $
32 * Revision 1.4 2014/10/13 08:53:59 j_novak
33 * Lorene classes and functions now belong to the namespace Lorene.
34 *
35 * Revision 1.3 2014/10/06 15:09:46 j_novak
36 * Modified #include directives to use c++ syntax.
37 *
38 * Revision 1.2 2003/01/09 11:07:51 j_novak
39 * headcpp.h is now compliant with C++ norm.
40 * The include files have been ordered, as well as the local_settings_linux
41 *
42 * Revision 1.1.1.1 2001/11/20 15:19:31 e_gourgoulhon
43 * LORENE
44 *
45 * Revision 1.1 1999/12/24 13:32:14 keisuke
46 * Initial revision
47 *
48 *
49 * $Header: /cvsroot/Lorene/Codes/Rot_star/test_jacobi.C,v 1.4 2014/10/13 08:53:59 j_novak Exp $
50 *
51 */
52
53
54 // headers C
55 #include <cstdlib>
56 #include <cmath>
57
58 // headers Lorene
59 #include "type_parite.h"
60 #include "cmp.h"
61 #include "graphique.h"
62 #include "utilitaires.h"
63 #include "param.h"
64
65 namespace Lorene {
66 // Local prototypes:
67 Cmp eos_local(const Cmp& ent, int nzet, double n_index) ;
68 double funct_zero_ent(double r, const Param& par) ;
69 }
70 //**********************************************************************
71
72 int main(){
73
74 // Identification of all the subroutines called by the code :
75
76 system("ident test_jacobi > identif_jacobi.d") ;
77
78 //-----------------------------------------------------------------------
79 // Input from file "part.d"
80 //-----------------------------------------------------------------------
81
82 int type_t, type_p, nt, np, nz, l;
83 char blabla[80];
84 double n_index, radius_x, radius_y ;
85
86 //----------------------------------------------------
87 // Declear the polytropic index
88 //----------------------------------------------------
89 cout << "Input a polytropic index: ";
90 cin >> n_index;
91
92 cout << "Input the radius_x of the star : " ;
93 cin >> radius_x ;
94 cout << "Input the radius_y of the star (< radius_x ) : " ;
95 cin >> radius_y ;
96
97 ifstream fich("part.d") ;
98 fich >> nt; fich.getline(blabla, 80);
99 fich >> np; fich.getline(blabla, 80);
100 fich >> nz; fich.getline(blabla, 80);
101
102 cout << "nb of points in phi : np = " << np << endl;
103 cout << "nb of points in theta : nt = " << nt << endl;
104 cout << "nb of zones : nz = " << nz << endl;
105
106 // initialisation des tableaux decrivant chaque zone
107
108 int* nr = new int[nz];
109 int* nt_tab = new int[nz];
110 int* np_tab = new int[nz];
111 double* bornes = new double[nz+1];
112 int* type_r = new int[nz];
113
114 fich >> bornes[nz] ; fich.getline(blabla, 80) ;
115 for (l=0; l<nz; l++) {
116 fich >> nr[l];
117 fich >> bornes[l];
118 fich >> type_r[l]; fich.getline(blabla, 80);
119 np_tab[l] = np ;
120 nt_tab[l] = nt ;
121 }
122 if (type_r[nz-1]==UNSURR) bornes[nz] = 1./bornes[nz] ;
123
124 fich.close();
125
126
127 //-----------------------------------------------------------------------
128 // Construction of a multi-grid
129 //-----------------------------------------------------------------------
130
131 type_t = SYM ;
132 type_p = NONSYM ;
133
134 Mg3d mg(nz, nr, type_r, nt_tab, type_t, np_tab, type_p) ;
135
136 cout << endl << "Grid mg : " << mg << endl ;
137
138 //-----------------------------------------------------------------------
139 // Construction of a mapping
140 //-----------------------------------------------------------------------
141
142 Map_af mp(mg, bornes) ;
143 cout << "Mapping mp : " << mp << endl ;
144
145
146 //-----------------------------------------------------------------------
147 // Construction of a Cmp
148 //-----------------------------------------------------------------------
149
150 // Obtaining "lambda" in order to rescale the mapping
151 //----------------------------------------------------
152 double lambda = radius_x ;
153
154 // Rescale of the map
155 //--------------------
156 mp.homothetie( lambda ) ;
157
158 Cmp rho(mp) ;
159 Cmp rho1(mp) ;
160 Cmp rho2(mp) ;
161 Cmp circle1(mp) ;
162 Cmp circle2(mp) ;
163
164 const Coord& r = mp.r ;
165 const Coord& x = mp.x ;
166 // const Coord& y = mp.y ;
167 const Coord& sint = mp.sint ;
168
169 circle1 = pow(abs(r*r - x + 0.25), 0.5) ;
170 circle1.annule(nz-1) ;
171 circle1.set_dzpuis(4) ;
172 circle1.std_base_scal() ;
173
174 rho1.set_etat_qcq() ;
175 (rho1.va).set_etat_c_qcq() ;
176 (rho1.va).c->set_etat_qcq() ;
177
178 circle2 = pow(abs(r*r + x + 0.25), 0.5) ;
179 circle2.annule(nz-1) ;
180 circle2.set_dzpuis(4) ;
181 circle2.std_base_scal() ;
182
183 rho2.set_etat_qcq() ;
184 (rho2.va).set_etat_c_qcq() ;
185 (rho2.va).c->set_etat_qcq() ;
186
187 int nr_s = mg.get_nr(nz-2) ;
188
189 //-------------------------------------------
190 // Initial densty profile
191 //-------------------------------------------
192
193 for (int l=0; l<nz; l++) {
194
195 (rho1.va).c->t[l]->set_etat_qcq() ;
196 (rho2.va).c->t[l]->set_etat_qcq() ;
197
198 for (int k=0; k<np; k++) {
199 for (int j=0; j<nt; j++) {
200 for (int i=0; i<nr_s; i++) {
201
202 double circ1 = circle1(l, k, j, i) ;
203
204 if (circ1 <= 0.5) {
205 rho1.set(l, k, j, i) = 1 ;
206 }
207 else {
208 rho1.set(l, k, j, i) = 0 ;
209 }
210
211 double circ2 = circle2(l, k, j, i) ;
212 if (circ2 <= 0.5) {
213 rho2.set(l, k, j, i) = 1 ;
214 }
215 else {
216 rho2.set(l, k, j, i) = 0 ;
217 }
218
219 }
220 }
221 }
222 }
223
224 rho = rho1 + rho2 ;
225 rho.annule(nz-1) ;
226
227 rho.set_dzpuis(4) ;
228 rho.std_base_scal() ; // Sets the standard basis for spectral expansions
229
230 Cmp pot(mp) ;
231 Cmp rho_prev(mp) ;
232 Cmp rot(mp) ;
233
234 Cmp ent(mp) ;
235 ent = pow(rho, 1/n_index) ;
236 ent.annule(nz-1) ;
237 ent.set_dzpuis(4) ;
238 ent.std_base_scal() ;
239
240 double omega2 ;
241 double omega2_prev ;
242 double rel_omega ;
243 omega2 = 0 ;
244
245 double cc ;
246 double cc_prev ;
247 double rel_cc ;
248 cc = 0 ;
249
250 double rmax ;
251 cout << "r_max ?" << endl ;
252 cin >> rmax ;
253
254 do {
255
256 /*
257 des_coupe_x(rho,0.,-rmax,rmax,-rmax,rmax,"rho (y-z plane)",&ent) ;
258 des_coupe_y(rho,0.,-rmax,rmax,-rmax,rmax,"rho (z-x plane)",&ent) ;
259 des_coupe_z(rho,0.,-rmax,rmax,-rmax,rmax,"rho (x-y plane)",&ent) ;
260 */
261
262 // Solving the Poisson equation
263 //------------------------------
264 pot = - rho.poisson() ;
265
266
267 // Surface potentials
268 //--------------------
269 // surface value of potential in the x-axis direction
270 // double pot_sx_2 = pot(nz-2,0,nt-1,nr_s-1) ;
271 double pot_sx = pot.val_point(radius_x,M_PI/2,0) ;
272
273 // Computation of the radius to the y-axis
274 //-----------------------------------------
275
276 Param par_funct_zero_y ;
277 par_funct_zero_y.add_cmp(ent) ;
278 double phi_search_y = M_PI/2 ;
279 double theta_search_y = M_PI/2 ;
280 par_funct_zero_y.add_double(theta_search_y, 0) ;
281 par_funct_zero_y.add_double(phi_search_y, 1) ;
282
283 double r_min_search_y = 0 ;
284 double r_max_search_y = radius_x ;
285 double precis_y = 1e-10 ;
286 int nitermax_y = 100 ;
287 int niter_y ;
288
289 double r_y = zerosec(funct_zero_ent, par_funct_zero_y,
290 r_min_search_y, r_max_search_y, precis_y,
291 nitermax_y, niter_y) ;
292
293 cout << "Radius to the y-axis direction : " << r_y << endl ;
294
295 // surface value of potential in the y-axis direction
296 double pot_sy = pot.val_point(radius_y,M_PI/2,M_PI/2) ;
297
298 /*
299 double rel_rad_y = fabs(1. - radius_y / r_y) ;
300 cout << "Relative error in radius_y : " << rel_rad_y << endl ;
301
302 cout << "The surface values of the potential : " << endl
303 << pot_sx << endl << pot_sx_2 << endl << pot_sy << endl ;
304
305 double radi_x = mp.val_r(nz-2,1.,M_PI/2,0) ;
306 double rel_rad_x = fabs(1. - radius_x / radi_x) ;
307 cout << "Relative error in radius_x : " << rel_rad_x << endl ;
308 */
309
310
311 // Angular velocity
312 //------------------
313 omega2_prev = omega2 ;
314
315 omega2 = 8. * (- pot_sx + pot_sy) /
316 (radius_x * radius_x - radius_y * radius_y) ;
317 cout << "Omega^2/(pi G rho_c) : " << omega2 << endl ;
318
319 rel_omega = fabs(1. - omega2_prev / omega2) ;
320 cout << "Relative error in Omega^2 : " << rel_omega << endl ;
321
322 // Integration constant
323 //----------------------
324 cc_prev = cc ;
325
326 /*
327 cc = (radius_y * radius_y * pot_sx
328 - radius_x * radius_x * pot_sy) /
329 (radius_x * radius_x - radius_y * radius_y) ;
330 */
331
332 cc = - pot_sx - 0.125 * omega2 * radius_x * radius_x ;
333
334 cout << "Integration constant : " << cc << endl ;
335
336 rel_cc = fabs(1. - cc_prev / cc) ;
337 cout << "Relative error in cc : " << rel_cc << endl ;
338
339 // First integral of motion
340 //--------------------------
341 rot = 0.125 * omega2 * r * r * sint * sint ;
342 rot.annule(nz-1) ;
343 ent = pot + rot + cc ; // enthalpy
344 ent.annule(nz-1) ;
345 ent.set_dzpuis(4) ;
346 ent.std_base_scal() ;
347
348 cout << "The central value of the enthalpy : " << ent(0,0,0,0)
349 << endl ;
350 /*
351 cout << "The surface values of the enthalpy : " << endl
352 << ent.val_point(radius_x,M_PI/2,0) << endl
353 << ent(nz-2,0,nt-1,nr_s-1) << endl
354 << ent(nz-1,0,nt-1,0) << endl
355 << ent.val_point(radius_y,M_PI/2,M_PI/2) << endl
356 << ent.val_point(radius_y,M_PI/2,0) << endl ;
357 */
358
359 rho_prev = rho ;
360
361 // EOS : rho = rho(H)
362 //--------------------
363 rho = eos_local(ent, nz-1, n_index) ;
364 rho.set_dzpuis(4) ;
365 rho.std_base_scal() ;
366
367 cout << max(abs(rho - rho_prev)) << endl ;
368
369 cout << "Maximum difference between rho and rho_prev : "
370 << max(diffrel(rho, rho_prev)) << endl ;
371
372 arrete() ;
373
374 } while(max(diffrel(rho, rho_prev)) > 1.e-4) ;
375
376 arrete() ;
377
378 cout << "Coef of rho : " << endl ;
379 rho.affiche_seuil(cout) ;
380
381 cout << "Coef of pot : " << endl ;
382 pot.affiche_seuil(cout) ;
383
384 arrete() ;
385 cout << "Value of pot at the origin : " << pot(0,0,0,0) << endl ;
386 cout << "Value of pot at the surface (r=ray) : " << pot(nz-1,0,0,0)
387 << endl ;
388 cout << "Value of pot at the surface (r=ray) : " << pot(nz-2,0,0,nr_s-1)
389 << endl ;
390
391 // Checking whether or not the potential satisfies the Poisson equation
392 //----------------------------------------------------------------------
393 Cmp lap = - pot.laplacien() ;
394
395 cout << "max( |lap(pot) - rho| ) " << max(abs(lap - rho)) << endl ;
396 cout << "relative error : " << diffrel(lap, rho) << endl ;
397
398 // Searching the radius to the z-axis direction
399 //----------------------------------------------
400 Param par_funct_zero_z ;
401 par_funct_zero_z.add_cmp(ent) ;
402 double phi_search_z = 0 ;
403 double theta_search_z = 0 ;
404 par_funct_zero_z.add_double(theta_search_z, 0) ;
405 par_funct_zero_z.add_double(phi_search_z, 1) ;
406
407 double r_min_search_z = 0 ;
408 double r_max_search_z = radius_x ;
409 double precis_z = 1e-10 ;
410 int nitermax_z = 100 ;
411 int niter_z ;
412
413 double r_z = zerosec(funct_zero_ent, par_funct_zero_z,
414 r_min_search_z, r_max_search_z, precis_z,
415 nitermax_z, niter_z) ;
416
417 // Radius of the star
418 //--------------------
419 double ray = mp.val_r(nz-2,1.,M_PI/2,0) ;
420 cout << "Radius of the star in the x-axis direction : " << ray << endl ;
421
422 cout << "Radius of the star in the y-axis direction : " << radius_y
423 << endl ;
424
425 cout << "Radius of the star in the pole : " << r_z
426 << endl ;
427
428 cout << "The ratio of the axis : a_2/a_1 : " << radius_y/ray << endl
429 << "The ratio of the axis : a_3/a_1 : " << r_z/ray << endl ;
430
431 // Angular velocity
432 //------------------
433 double omega = sqrt(omega2) ;
434
435 cout << "Angular velocity of the star Omega/(pi G rho_c)^{1/2} : "
436 << omega << endl ;
437 cout << "Angular velocity Omega^2/(pi G rho_c) : "
438 << omega2 << endl ;
439
440 arrete() ;
441
442 // Mass of the star
443 //------------------
444 double mass = rho.integrale() ;
445 cout << "Mass/rho_c : " << mass << endl ;
446
447 // Total energy of the star
448 //--------------------------
449 Cmp rho_n(mp) ;
450
451 rho_n = pow(abs(rho), 1 + 1/n_index) ;
452 rho_n.annule(nz-1) ;
453 rho_n.set_dzpuis(4) ;
454 rho_n.std_base_scal() ;
455
456 double energy_internal = 4 * M_PI *
457 (1 / (1 + n_index)) * rho_n.integrale() * ray / (mass * mass) ;
458 cout << "Internal energy of the triaxial star : E_int/(GM^2/ray) : "
459 << n_index * energy_internal << endl ;
460
461 Cmp rho_pot(mp) ;
462 rho_pot = rho * pot ;
463 rho_pot.annule(nz-1) ;
464 rho_pot.set_dzpuis(4) ;
465 rho_pot.std_base_scal() ;
466 double energy_selfgrav = -2. * M_PI * rho_pot.integrale() * ray /
467 (mass * mass) ;
468 cout <<
469 "Self-gravity energy of the triaxial star : E_self/(GM^2/ray) : "
470 << energy_selfgrav << endl ;
471
472 Cmp rr(mp) ;
473 Cmp rho_quad(mp) ;
474 rr = r * r * sint * sint ;
475 rho_quad = rho * rr ;
476 rho_quad.annule(nz-1) ;
477 rho_quad.set_dzpuis(4) ;
478 rho_quad.std_base_scal() ;
479 double energy_kinetic = 0.5 * M_PI * omega2 * rho_quad.integrale() *
480 ray / (mass * mass) ;
481 cout << "Kinetic energy of the triaxial star : E_kinet/(GM^2/ray) : "
482 << energy_kinetic << endl ;
483
484 double energy_total = n_index * energy_internal + energy_selfgrav
485 + energy_kinetic ;
486
487 cout << "Total energy of the triaxial star : E/(GM^2/ray) : "
488 << energy_total << endl ;
489
490 // Angular momentum
491 //------------------
492 double angmom = sqrt(M_PI) * omega * rho_quad.integrale() /
493 sqrt( mass * mass * mass * ray) ;
494
495 cout <<
496 "Angular momentum of the triaxial star : J/(GM^3 ray)^{1/2} : "
497 << angmom << endl ;
498
499 // Virial relation
500 //-----------------
501 double virial = 3. * energy_internal + energy_selfgrav
502 + 2. * energy_kinetic ;
503 cout << "Virial relation : " << virial << endl ;
504
505 //------------------------------------------
506 // Plot the figures
507 //------------------------------------------
508 // double rmax ;
509 // cout << "r_max ?" << endl ;
510 // cin >> rmax ;
511
512 des_profile(rho,0.,rmax,M_PI/2, 0.,"rho/rho_c","rho (x direction)") ;
513 des_profile(rho,0.,rmax,M_PI/2,M_PI/2,"rho/rho_c","rho (y direction)") ;
514 des_profile(rho,0.,rmax,0.,0.,"rho/rho_c","rho (z direction)") ;
515 des_profile(ent,0.,rmax,M_PI/2,0.,"ent","enthalpy (x direction)") ;
516 des_profile(ent,0.,rmax,M_PI/2,M_PI/2,"ent","enthalpy (y direction)") ;
517 des_profile(ent,0.,rmax,0.,0.,"ent","enthalpy (z direction)") ;
518
519 des_coupe_x(rho,0.,-rmax,rmax,-rmax,rmax,"rho (x-z plane)",&ent) ;
520 des_coupe_y(rho,0.,-rmax,rmax,-rmax,rmax,"rho (y-z plane)",&ent) ;
521 des_coupe_z(rho,0.,-rmax,rmax,-rmax,rmax,"rho (x-y plane)",&ent) ;
522
523 des_coef_xi(rho.va, 0, 0, 0, 1.e-14, "log|c_i|", "domain no. 0") ;
524 des_coef_theta(rho.va, 0, 0, 0) ;
525 des_coef_phi(rho.va, 0, 0, 0) ;
526
527 /*
528 des_coef_xi(rho.va, 1, 0, 0, 1.e-14, "log|c_i|", "domain no. 1") ;
529 des_coef_theta(rho.va, 1, 0, 0) ;
530 des_coef_phi(rho.va, 1, 0, 0) ;
531 */
532 exit(-1) ;
533
534 }
535