Debian Codegraph @

Codes/Sfluide/sfstar.C

raw
1 /*
2 * Copyright (c) 2002, 2003 Jerome Novak
3 * Copyright (c) 2003, 2004 Reinhard Prix
4 *
5 * This file is part of LORENE.
6 *
7 * LORENE is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
11 *
12 * LORENE is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with LORENE; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 *
21 */
22
23 /***********************************************************************
24 * calculate stationary configuration of superfluid neutron star
25 ***********************************************************************/
26
27 // // headers C
28 #include <cmath>
29 #include <gsl/gsl_integration.h>
30
31 #include <sstream>
32 #include <sys/types.h>
33 #include <dirent.h>
34 #include <sys/stat.h>
35 // headers Lorene
36 #include "et_rot_bifluid.h"
37 #include "utilitaires.h"
38 #include "graphique.h"
39 #include "nbr_spx.h"
40
41 #include "unites.h"
42
43 namespace Lorene{
44 // Local prototype (for drawings only)
45 Cmp raccord_c1(const Cmp& uu, int l1) ;
46 }
47
48 using namespace Lorene ;
49
50 void compare_analytic (Et_rot_bifluid& star, int adapt, const char *resdir);
51 string get_file_base (bool relat, double xp, double sig);
52 string get_file_base (bool relat, double xp, double sig, double eps, double om1, double om2, int typeos, int nzet, int adapt);
53
54 // some global EOS parameters
55 double kap1, kap2, kap3, beta, m1, m2, detA, k1, k2, kk, R;
56 double sigma, eps, eps_n, xp;
57 double nc, rhoc; // central density
58
59
60 //----------------------------------------------------------------------
61 // stuff for GSL-integration of A(r)
62 typedef struct {
63 Cmp *AofR;
64 double theta;
65 double phi;
66 } AofR_params;
67
68 double AofR (double r, void *params);
69 //----------------------------------------------------------------------
70
71 //******************************************************************************
72
73 int main(){
74
75 using namespace Unites ;
76
77 //------------------------------------------------------------------
78 // Parameters of the computation
79 //------------------------------------------------------------------
80 bool relat, graph;
81 int mer_max, mer_rot, mer_change_omega, mer_fix_omega,
82 mermax_poisson, nz, nzet, nt, np;
83 double ent1_c, ent2_c, freq_si, freq2_si, precis, freq_ini_si;
84 double freq2_ini_si,relax, relax_poisson ;
85
86 // adaptive-grid paramters + defaults
87 int nzadapt = 0;
88 double thres_adapt = 0.0;
89 double precis_adapt = 1.e-14;
90
91 const char *parrot = "settings.par"; // config-file
92 int res = 0;
93
94 res += read_variable (parrot, "relat", relat);
95 res += read_variable (NULL, "ent1_c", ent1_c);
96 res += read_variable (NULL, "ent2_c",ent2_c);
97 res += read_variable (NULL, "freq_si", freq_si);
98 res += read_variable (NULL, "freq2_si", freq2_si);
99 res += read_variable (NULL, "mer_max", mer_max);
100 res += read_variable (NULL, "precis", precis);
101 res += read_variable (NULL, "mer_rot", mer_rot);
102 res += read_variable (NULL, "freq_ini_si", freq_ini_si);
103 res += read_variable (NULL, "freq2_ini_si", freq2_ini_si);
104 res += read_variable (NULL, "mer_change_omega", mer_change_omega);
105 res += read_variable (NULL, "mer_fix_omega", mer_fix_omega);
106 res += read_variable (NULL, "relax", relax);
107 res += read_variable (NULL, "mermax_poisson", mermax_poisson);
108 res += read_variable (NULL, "relax_poisson", relax_poisson);
109 res += read_variable (NULL, "graph", graph);
110 res += read_variable (NULL, "nz", nz);
111 res += read_variable (NULL, "nzet", nzet);
112 res += read_variable (NULL, "nt", nt);
113 res += read_variable (NULL, "np", np);
114
115 if ( res != 0 )
116 {
117 cerr << "An error ocurred in reading the parameter file 'settings.par'. Terminating...\n";
118 exit (-1);
119 }
120
121 int* nr = new int[nz];
122 int* nt_tab = new int[nz];
123 int* np_tab = new int[nz];
124 double* bornes = new double[nz+1];
125
126 char cbuf[50]; // man, <ios> does not seem to exist here...
127 for (int l=0; l<nz; l++) {
128 sprintf (cbuf, "nr%d", l);
129 res += read_variable (NULL, cbuf, nr[l]);
130 sprintf (cbuf, "rmin%d", l);
131 res += read_variable (NULL, cbuf, bornes[l]);
132 np_tab[l] = np ;
133 nt_tab[l] = nt ;
134 // cout << "DEBUG: l= "<<l<< ", read in nr[l] = " << nr[l] << "; rmin[l] = " << bornes[l] << endl;
135 }
136
137 bornes[nz] = __infinity ;
138
139 Tbl ent_limit(nzet) ;
140 ent_limit.set_etat_qcq() ;
141 ent_limit.set(nzet-1) = 0 ; // enthalpy at the stellar surface
142 Tbl ent2_limit(ent_limit) ;
143 ent2_limit.set_etat_qcq() ;
144 ent2_limit.set(nzet-1) = 0 ; // enthalpy 2 at the stellar surface
145
146 double tmp;
147 for (int l=0; l<nzet-1; l++) {
148 sprintf (cbuf, "ent_limit%d", l);
149 res += read_variable (NULL, cbuf, tmp);
150 ent_limit.set(l) = tmp;
151 ent2_limit.set(l) = tmp;
152 }
153
154 if ( res != 0 )
155 {
156 cerr << "An error ocurred in reading the parameter file " << parrot <<". Terminating...\n";
157 exit (-1);
158 }
159
160 // Read paramters specific to adaptive grid (optional)
161 // --------------------------------------------------
162 if ( (read_variable (NULL, "nzadapt", nzadapt) == 0) && (nzadapt > 0) ) // do we want adaptive grid?
163 {
164 res += read_variable (NULL, "thres_adapt", thres_adapt);
165 res += read_variable (NULL, "precis_adapt", precis_adapt);
166
167 if (res != 0)
168 cout << "WARNING: some adaptive-grid variables were not found! Using default ... \n";
169 }
170
171 // Read parameters specific to Kepler-limit (optional)
172 // --------------------------------------------------
173 // Default values:
174 int kepler_fluid = 0; // Kepler limit for which fluid? 1,2; 3 = both
175 int kepler_wait_steps = 1; // how many steps after mer_fix_omega shall we start?
176 double kepler_factor = 1.01; // factor to increase omega in each step to approach Kepler (>1!)
177
178 res = 0;
179 if( (read_variable (NULL, "kepler_fluid", kepler_fluid) == 0) && (kepler_fluid > 0) )
180 {
181 res += read_variable (NULL, "kepler_wait_steps", kepler_wait_steps);
182 res += read_variable (NULL, "kepler_factor", kepler_factor);
183
184 if (res != 0)
185 cout << "WARNING: some Kepler-limit parameters were not found in settings.par! Using default ... \n";
186 }
187
188
189 // Read parameters specific to triaxial perturbation (optional)
190 // ------------------------------------------------------------
191 // Default values:
192 int mer_triax = 2000 ; //step at which the 3-D perturbation is switched on
193 double ampli_triax = 1.e-3 ; // relative amplitude of the 3-D perturbation
194
195 res = 0;
196 if( (read_variable (NULL, "mer_triax", mer_triax) == 0) && (mer_triax < mer_max) )
197 {
198 res += read_variable (NULL, "ampli_triax", ampli_triax) ;
199 if (res != 0)
200 cout << "WARNING: some 3D perturbation parameters were not found in settings.par! Using default ... \n";
201 }
202
203 // read parameters related to mass-convergence (optional)
204 // -------------------------------------------------------
205 int mer_mass = -1; /* default: no mass-adaption */
206 double mbar1_wanted, mbar2_wanted, aexp_mass = 0.5;
207 res = 0;
208 if ( (read_variable (parrot, "mer_mass", mer_mass) == 0) && (mer_mass > 0) )
209 {
210 res += read_variable (NULL, "mbar1_wanted", mbar1_wanted);
211 res += read_variable (NULL, "mbar2_wanted", mbar2_wanted);
212
213 if (res != 0)
214 {
215 cout << "ERROR: mer_mass > 0 but 'mbar1_wanted' or 'mbar2_wanted' not set!\n";
216 exit (-1);
217 }
218 // correct units of baryon-masses: (input is in Solar masses)
219 mbar1_wanted *= msol;
220 mbar2_wanted *= msol;
221 read_variable (NULL, "aexp_mass", aexp_mass);
222
223 } /* if fixed baryon masses */
224
225 /* Directory to store results in */
226 char *resdir = NULL;
227 if ( read_variable (NULL, "resdir", &resdir) != 0)
228 resdir = const_cast<char*>("Results"); /* default value */
229
230 // Particular cases
231 // ----------------
232
233 // Initial frequency = final frequency
234 if ( freq_ini_si < 0 ) {
235 freq_ini_si = freq_si ;
236 mer_change_omega = mer_rot ;
237 mer_fix_omega = mer_rot + 1 ;
238 }
239
240
241 //-----------------------------------------------------------------------
242 // Equation of state
243 //-----------------------------------------------------------------------
244
245 /* eos-params are read from the same parameter file now! */
246 Eos_bifluid* peos = Eos_bifluid::eos_from_file(parrot);
247 Eos_bifluid& eos = *peos ;
248
249 //-----------------------------------------------------------------------
250 // Construction of the multi-grid and the mapping
251 //-----------------------------------------------------------------------
252
253 // Type of r sampling :
254 int* type_r = new int[nz];
255 type_r[0] = RARE ;
256 for (int l=1; l<nz-1; l++) {
257 type_r[l] = FIN ;
258 }
259 type_r[nz-1] = UNSURR ;
260
261 // Type of sampling in theta and phi :
262 int type_t = SYM ;
263 int type_p = SYM ;
264
265 Mg3d mg(nz, nr, type_r, nt_tab, type_t, np_tab, type_p) ;
266
267 Map_et mp(mg, bornes) ;
268
269 // Cleaning
270 // --------
271
272 delete [] nr ;
273 delete [] nt_tab ;
274 delete [] np_tab ;
275 delete [] type_r ;
276 delete [] bornes ;
277
278
279
280 cout << endl
281 << "==========================================================" << endl
282 << " Physical parameters " << endl
283 << "=========================================================="
284 << endl ;
285 cout << endl ;
286
287 cout << endl << "Equation of state : "
288 << endl << "================= " << endl ;
289 cout << eos << endl ;
290
291 cout << "Central enthalpy 1 : " << ent1_c << " c^2" << endl ;
292 cout << "Central enthalpy 2 : " << ent2_c << " c^2" << endl ;
293 cout << "Rotation frequency : " << freq_si << " Hz" << endl ;
294 cout << "Rotation frequency 2 : " << freq2_si << " Hz" << endl ;
295 cout << endl
296 << "==========================================================" << endl
297 << " Computational parameters " << endl
298 << "=========================================================="
299 << endl << endl ;
300
301 cout << "Maximum number of steps in the main iteration : "
302 << mer_max << endl ;
303 cout << "Relaxation factor in the main iteration : "
304 << relax << endl ;
305 cout << "Threshold on the enthalpy relative change for ending the computation : "
306 << precis << endl ;
307 cout << "Maximum number of steps in Map_et::poisson : "
308 << mermax_poisson << endl ;
309 cout << "Relaxation factor in Map_et::poisson : "
310 << relax_poisson << endl ;
311
312 cout << endl << "Multi-grid : "
313 << endl << "==========" << endl << mg << endl ;
314 cout << "Mapping : "
315 << endl << "=======" << endl << mp << endl ;
316
317
318 //-----------------------------------------------------------------------
319 // Construction of the star
320 //-----------------------------------------------------------------------
321
322 Et_rot_bifluid star(mp, nzet, relat, eos) ;
323
324 if ( star.is_relativistic() ) {
325 cout << "========================" << endl ;
326 cout << "Relativistic computation" << endl ;
327 cout << "========================" << endl ;
328 }
329 else {
330 cout << "=====================" << endl ;
331 cout << "Newtonian computation" << endl ;
332 cout << "=====================" << endl ;
333 }
334
335 //-----------------------------------------------------------------------
336 // Initialization of the enthalpy field
337 //-----------------------------------------------------------------------
338
339
340 const Coord& r = mp.r ;
341 double ray0 = mp.val_r(nzet-1, 1., 0., 0.) ;
342 Cmp enta(mp) ;
343 enta = ent1_c * ( 1 - r*r / (ray0*ray0) ) ;
344 enta.annule(nz-1) ;
345 enta.std_base_scal() ;
346 Cmp entb = enta * ent2_c/ent1_c ;
347 star.set_enthalpies(enta, entb) ;
348
349 // Initialization of (E,S,U,etc...) (quantities relative to the Eulerian obs)
350 star.hydro_euler() ;
351
352 cout << endl << "Initial star : "
353 << endl << "============ " << endl ;
354
355 cout << star << endl ;
356
357 //-----------------------------------------------------------------------
358 // Computation of the rotating equilibrium
359 //-----------------------------------------------------------------------
360
361 double omega = 2 * M_PI * freq_si / f_unit ;
362 double omega_ini = 2 * M_PI * freq_ini_si / f_unit ;
363
364 double omega2 = 2 * M_PI * freq2_si / f_unit ;
365 double omega2_ini = 2 * M_PI * freq2_ini_si / f_unit ;
366
367 Itbl icontrol(9) ;
368 icontrol.set_etat_qcq() ;
369 icontrol.set(0) = mer_max ;
370 icontrol.set(1) = mer_rot ;
371 icontrol.set(2) = mer_change_omega ;
372 icontrol.set(3) = mer_fix_omega ;
373 icontrol.set(4) = mermax_poisson ;
374 icontrol.set(5) = nzadapt; // nb of domains for adaptive grid
375 icontrol.set(6) = kepler_fluid; // index of fluid for Kepler-search (0=none)
376 icontrol.set(7) = kepler_wait_steps;
377 icontrol.set(8) = mer_triax ; // starting of triaxial perturbations
378
379 Tbl control(9) ;
380 control.set_etat_qcq() ;
381 control.set(0) = precis ;
382 control.set(1) = omega_ini ;
383 control.set(2) = omega2_ini ;
384 control.set(3) = relax ;
385 control.set(4) = relax_poisson ;
386 control.set(5) = thres_adapt;
387 control.set(6) = precis_adapt;
388 control.set(7) = kepler_factor;
389 control.set(8) = ampli_triax ;
390
391 Tbl diff(9) ;
392
393 star.equilibrium_bi(ent1_c, ent2_c, omega, omega2, ent_limit,
394 ent2_limit, icontrol, control, diff,
395 mer_mass, mbar1_wanted, mbar2_wanted, aexp_mass);
396
397
398 cout << endl << "Final star : "
399 << endl << "========== " << endl ;
400
401 cout.precision(10) ;
402 cout << star << endl ;
403
404 double vit_triax = diff(8) ;
405 cout << "Growing rate of triaxial perturbation: " << vit_triax
406 << endl ;
407
408 //-----------------------------------------------
409 // General features of the final configuration
410 // saved in a file
411 //-----------------------------------------------
412
413 ofstream fichfinal("calcul.d") ;
414 fichfinal.precision(10) ;
415
416 if ( star.is_relativistic() ) {
417 fichfinal << "Relativistic computation" << endl ;
418 }
419 else {
420 fichfinal << "Newtonian computation" << endl ;
421 }
422
423 fichfinal << star.get_eos() << endl ;
424
425 fichfinal << endl << "Total CPU time : " << endl ;
426 fichfinal << "Memory size : " << endl << endl ;
427
428 fichfinal << endl << endl ;
429 fichfinal << "Grid : " << endl ;
430 fichfinal << "------ " << endl ;
431 fichfinal << *(star.get_mp().get_mg()) << endl ;
432 fichfinal << endl << "Physical characteristics : " << endl ;
433 fichfinal << "-------------------------" << endl ;
434 fichfinal << star << endl ;
435 fichfinal << "Growing rate of triaxial perturbation: " << vit_triax
436 << endl ;
437 fichfinal << endl <<
438 "==================================================================="
439 << endl ;
440 fichfinal << "Diff_ent : " << diff(0) << endl ;
441 fichfinal << "Relative error on the virial theorem GRV2 : "
442 << star.grv2() << endl ;
443 fichfinal << "Relative error on the virial theorem GRV3 : "
444 << star.grv3() << endl ;
445
446 // total central densities
447 m1 = eos.get_m1();
448 m2 = eos.get_m2();
449 double rhon_c = m1 * star.get_nbar()()(0,0,0,0);
450 double rhop_c = m2 * star.get_nbar2()()(0,0,0,0);
451
452 fichfinal << "\n\nCentral neutron density: " << rhon_c << " x 0.1 fm^-3 \n";
453 fichfinal << "Central proton density: " << rhop_c << " x 0.1 fm^-3 \n";
454 fichfinal << "Total central baryon density : " << rhon_c + rhop_c << " x 0.1 fm^-3 \n\n";
455
456
457 fichfinal << endl <<
458 "================================================================" << endl ;
459 fichfinal <<
460 " PARAMETERS USED FOR THE COMPUTATION (file settings.par) : " << endl ;
461 fichfinal <<
462 "================================================================" << endl ;
463 fichfinal.close() ;
464 system("cat settings.par >> calcul.d") ;
465
466 fichfinal.open("calcul.d", ios::app) ;
467
468 // Identification du code et de ses sous-routines (no. de version RCS) :
469 fichfinal.open("calcul.d", ios::app) ;
470 fichfinal << endl <<
471 "================================================================" << endl ;
472 fichfinal << " IDENTIFICATION OF THE CODE : " << endl ;
473 fichfinal <<
474 "================================================================" << endl ;
475 fichfinal.close() ;
476 system("ident sfstar >> calcul.d") ;
477
478
479 // Saveguard of the whole configuration
480 // ------------------------------------
481
482 FILE* fresu = fopen("resu.d", "w") ;
483
484 star.get_mp().get_mg()->sauve(fresu) ; // writing of the grid
485 star.get_mp().sauve(fresu) ; // writing of the mapping
486 star.get_eos().sauve(fresu) ; // writing of the EOS
487 star.sauve(fresu) ; // writing of the star
488
489 fclose(fresu) ;
490
491 // Drawings
492 // --------
493
494 if (graph == 1) {
495 char title[80] ;
496 char bslash[2] = {92, '\0'} ; // 92 is the ASCII code for backslash
497
498 int nzdes = star.get_nzet() ;
499
500 // Cmp defining the surface of the star (via the density fields)
501 //
502 Cmp surf(mp) ;
503 surf = -0.2*star.get_nbar()()(0,0,0,0) ;
504 surf.annule(0, star.get_nzet()-1) ;
505 surf += star.get_nbar()() ; ;
506
507 surf.std_base_scal();
508
509 // des_profile(surf, 0, 1.5, M_PI/2, 0, "surf before prolonge");
510 surf = prolonge_c1(surf, star.get_nzet()) ;
511 // des_profile(surf, 0, 1.5, M_PI/2, 0, "surf after prolonge");
512
513 Cmp surf2(mp) ;
514 surf2 = -0.2*star.get_nbar2()()(0,0,0,0) ;
515 surf2.annule(0, star.get_nzet()-1) ;
516 surf2 += star.get_nbar2()() ; ;
517 surf2 = prolonge_c1(surf2, star.get_nzet()) ;
518
519 des_bi_coupe_y(star.get_nbar()(), 0., nzdes, "Fluid 1 baryonic density", &surf, &surf) ;
520
521 des_bi_coupe_y(star.get_nbar2()(), 0., nzdes, "Fluid 2 baryonic density", &surf2, &surf2) ;
522
523 des_bi_coupe_y(star.get_logn()(), 0., nzdes, "Grav. potential", &surf, &surf2) ;
524
525 strcpy(title, "Azimuthal shift N") ;
526 strcat(title, bslash) ;
527 strcat(title, "u") ;
528 strcat(title, bslash) ;
529 strcat(title, "gf") ;
530 des_bi_coupe_y(star.get_nphi()(), 0., nzdes, title, &surf, &surf2) ;
531
532 strcpy(title, "Metric potential ") ;
533 strcat(title, bslash) ;
534 strcat(title, "gz") ;
535 des_bi_coupe_y(star.get_dzeta()(), 0., nzdes, title, &surf, &surf2) ;
536
537 }
538
539 // now print out key-values of the configuration in such a "translated" way
540 // that we can compare the results to the analytic solution of PCA02:
541 // if (eos.identify() == 2) // only do that if type = eos_bf_poly_newt
542 // compare_analytic (star, nzadapt, resdir);
543 compare_analytic (star, nzadapt, resdir);
544
545 // Cleaning
546 // --------
547
548 delete peos ;
549
550 exit(EXIT_SUCCESS) ;
551
552 return EXIT_SUCCESS ;
553
554 } // main()
555
556
557 // ----------------------------------------------------------------------
558 // compare_analytic()
559 // print out appropriate "translations" of parameters and results such that
560 // we can compare them to the analytic solution of PCA02
561 //----------------------------------------------------------------------
562 void
563 compare_analytic (Et_rot_bifluid& star, int adapt, const char *resdir)
564 {
565 using namespace Unites ;
566
567 Eos_bf_poly eos = dynamic_cast<const Eos_bf_poly&>(star.get_eos());
568
569 // // let's see if it's really what we called "analytic" EOS in PCA02:
570 // if ( (eos.identify() != 2) || (eos.get_gam1() != 2) || (eos.get_gam2() != 2) ||
571 // (eos.get_gam3() != 1) || (eos.get_gam4() != 1) )
572 // {
573 // cout << "This EOS is not of type Newtonian analytic EOS, compare_analytic() useless here!\n";
574 // return;
575 // }
576 // else
577 // {
578 // cout << "\n\n----------------------------------------------------------------------" << endl;
579 // cout << " compare_analytic() called on AnalyticEOS: now comparing... " << endl << endl;
580 // }
581
582 double muc1 = star.get_ent()()(0,0,0,0);
583 double muc2 = star.get_ent2()()(0,0,0,0);
584 cout.precision (15);
585 if (muc1 != muc2)
586 cout << "\n!! WARNING !!: central chemical potentials differ..!!\n: mu1 = " << muc1 << "; mu2 = " << muc2 << endl;;
587
588 // get "raw" EOS parameters
589 kap1 = eos.get_kap1();
590 kap2 = eos.get_kap2();
591 kap3 = eos.get_kap3();
592 beta = eos.get_beta();
593 m1 = eos.get_m1();
594 m2 = eos.get_m2();
595
596 cout << "Raw EOS parameters: kappa1 = " << kap1 << " kappa2 = " << kap2;
597 cout << " kappa3 = " << kap3 << " beta = " << beta << endl;
598
599
600 // Central densities
601 double nn_c = star.get_nbar()()(0,0,0,0);
602 double np_c = star.get_nbar2()()(0,0,0,0);
603 nc = nn_c + np_c;
604 rhoc = m1 * nn_c + m2 * np_c;
605
606 // baryon densities in natural units
607 // Cmp nn = star.get_nbar()() / nc;
608 // Cmp np = star.get_nbar2()() / nc;
609
610 // translate EOS parameters into x_p, sigma and epsilon
611 detA = kap1*kap2 - kap3*kap3;
612 k1 = m1 * (kap2 - kap3) / detA;
613 k2 = m2 * (kap1 - kap3) / detA;
614 kk = m1*k1 + m2* k2;
615 R = M_PI /sqrt(qpig * kk) ; // analytic prediction
616
617 sigma = - kap3 / kap1;
618 if ( fabs(sigma) < 1e-9 ) sigma = 0;
619 eps = 2.0 * beta * nn_c / m2;
620 eps_n = 2.0 * beta * np_c / m1;
621
622 xp = k2 / (k1 + k2);
623
624 double xp_num = np_c / (nn_c + np_c) ;
625
626 cout << setprecision(9);
627 cout << "Translated EOS parameters: sigma = " << sigma << ", epsilon_c = " << eps << ", xp = " << xp << endl;
628
629 cout << "Central neutron density: " << nn_c << " rho_nuc" << endl;
630 cout << "Central proton density: " << np_c << " rho_nuc" << endl;
631 cout << "Central baryon density: " << nc << " rho_nuc" << endl;
632 double rel = 2* g_si * star.mass_b()*m_unit / (c_si*c_si * R * r_unit);
633 cout << "Relativity parameter: " << rel << endl;
634
635 double om0 = sqrt ( 4.0 * M_PI * g_si * rhoc * rho_unit );
636 cout << "Rotation-rate Unit: " << om0 << endl;
637 double om_n = star.get_omega_c() * f_unit / om0;
638 double om_p = star.get_omega2() * f_unit / om0;
639 cout << "Natural rotation rates: Om_n = " << om_n << "; Om_p = " << om_p << endl;
640 cout << "Analytic static radius: " << R << endl;
641 cout << "eps_p(0) = " << eps << " eps_n(0) = " << eps_n << endl;
642 if ( eps >= 1.0 || eps_n >= 1.0 )
643 cout << "*** WARNING **** negative effective masses if eps, eps_n >= 1 !! \n";
644
645 // ******************************
646 // now start with tests and output
647
648 cout << "Total mass of neutron-fluid: " << star.mass_b1() / msol << " Msol\n";
649 cout << "Total mass of proton-fluid: " << star.mass_b2() / msol << " Msol\n";
650 cout << "Total baryon mass: " << star.mass_b()/msol << "Msol\n";
651
652 // save some data about this configuration:
653 string fname;
654
655 // make sure Results-directory exists, otherwise create it:
656 DIR *thisdir;
657 if ( (thisdir = opendir(resdir)) == NULL)
658 if (mkdir (resdir, S_IREAD|S_IWRITE|S_IEXEC) == -1)
659 {
660 cout << "Failed to create results-dir: " << resdir << endl;
661 exit (-1);
662 }
663 closedir (thisdir);
664
665 // construct path+name for results-file
666 string path = resdir;
667 path += "/";
668 fname = path + get_file_base (star.is_relativistic(), xp, sigma, eps, om_n, om_p, eos.get_typeos(), star.get_nzet(), adapt);
669
670
671 const Map_radial *map = dynamic_cast<const Map_radial*>(&star.get_mp());
672 const Mg3d* mg = map->get_mg() ; // Multi-grid
673
674 //----------------------------------------------------------------------
675 // get radii at intermediate angle, ~pi/4
676
677 const Coord& theta = map->tet ;
678 int g = mg->get_nt(0)/2; // theta close to pi/4
679
680 double thetaI = (+theta)(0,0,g,0);
681 double RnI = map->val_r_jk(star.l_surf()(0,g), star.xi_surf()(0,g), g, 0);
682 double RpI = map->val_r_jk(star.l_surf2()(0,g), star.xi_surf2()(0,g), g, 0);
683
684 cout << "theta = " << thetaI << "; RnI = " << RnI << "; RpI = " << RpI << endl;
685
686 double mnat = rhoc * R * R * R;
687
688 //----------------------------------------------------------------------
689 // calculate magnitude of shift-vector = N^phi B r sin(th)
690 Cmp shiftMag = star.get_tnphi()(); // N^phi r sin(th)
691 shiftMag *= star.get_bbb()();
692
693
694 //----------------------------------------------------------------------
695 // calculate proper radii!
696 Cmp aaa = sqrt( star.get_a_car()()); // a = sqrt(a^2)
697 aaa.std_base_scal();
698 // ok, not too sure about the spectral inner workings of this, so we
699 // integrate this "by hand"... (i.e using GSL...)
700 double rmax;
701 double abserr;
702 size_t neval;
703 double RR_pol_n, RR_pol_p, RR_eq_n, RR_eq_p; // the proper radii
704
705
706 AofR_params params;
707 params.AofR = &aaa;
708 params.phi = 0;
709
710 gsl_function func_AofR;
711 func_AofR.function = AofR;
712 func_AofR.params = &params;
713
714 // RR_pol_n
715 rmax = star.ray_pole(); /* upper limit of integration */
716 params.theta = 0; /* pole */
717 if (gsl_integration_qng (&func_AofR, 0, rmax, 0, 1e-7, &RR_pol_n, &abserr, &neval) )
718 {
719 cout << "Integration of proper radius RR_pol_n failed!" << endl;
720 exit (-1);
721 }
722 cout << "Proper-radius RR_pol_n = "<<RR_pol_n<< ", abserr= "<<abserr<<", neval= "<<neval <<endl;
723 // RR_pol_p
724 rmax = star.ray_pole2(); /* upper limit of integration */
725 params.theta = 0; /* pole */
726 if (gsl_integration_qng (&func_AofR, 0, rmax, 0, 1e-7, &RR_pol_p, &abserr, &neval) )
727 {
728 cout << "Integration of proper radius RR_pol_p failed!" << endl;
729 exit (-1);
730 }
731 cout << "Proper-radius RR_pol_p = "<<RR_pol_p<< ", abserr= "<<abserr<<", neval= "<<neval <<endl;
732 // RR_eq_n
733 rmax = star.ray_eq(); /* upper limit of integration */
734 params.theta = M_PI/2; /* equator */
735 if (gsl_integration_qng (&func_AofR, 0, rmax, 0, 1e-7, &RR_eq_n, &abserr, &neval) )
736 {
737 cout << "Integration of proper radius RR_eq_n failed!" << endl;
738 exit (-1);
739 }
740 cout << "Proper-radius RR_eq_n = "<<RR_eq_n<< ", abserr= "<<abserr<<", neval= "<<neval <<endl;
741 // RR_eq_p
742 rmax = star.ray_eq2(); /* upper limit of integration */
743 params.theta = M_PI/2; /* equator */
744 if (gsl_integration_qng (&func_AofR, 0, rmax, 0, 1e-7, &RR_eq_p, &abserr, &neval) )
745 {
746 cout << "Integration of proper radius RR_eq_p failed!" << endl;
747 exit (-1);
748 }
749 cout << "Proper-radius RR_eq_p = "<<RR_eq_p<< ", abserr= "<<abserr<<", neval= "<<neval <<endl;
750
751
752 cout << "Flattening of neutrons, r_pole/r_eq = " << RR_pol_n / RR_eq_n << endl;
753 cout << "Flattening of protons, r_pole/r_eq = " << RR_pol_p / RR_eq_p << endl;
754
755 //----------------------------------------------------------------------
756
757
758
759 std::ofstream data((fname+".d").c_str());
760 data << setprecision(17);
761
762 data << "# EOS and stellar parameters: \n";
763
764 data << "kappa1 = " << kap1 << endl;
765 data << "kappa2 = " << kap2 << endl;
766 data << "kappa3 = " << kap3 << endl;
767 data << "beta = " << beta << endl;
768
769 data << "muc_n = " << star.get_ent()()(0,0,0,0) << endl;
770 data << "muc_p = " << star.get_ent2()()(0,0,0,0) << endl;
771
772 data << "rhoc = " << nc << " rho_nuc" << endl;
773 data << "Om0 = " << om0 << endl;
774 data << "Relativity-parameter = " << rel << endl;
775
776 data << "\n# in natural units:\n";
777 data << "sigma = " << sigma << endl;
778 data << "epsilon = " << eps << endl;
779 data << "xp = " << xp << endl;
780 data << "xp_num = " << xp_num << endl;
781
782 data << "Om_n = " << om_n << endl;
783 data << "Om_p = " << om_p << endl;
784
785 data << "\n# Global stellar quantities:\n";
786 data << "Mn = " << star.mass_b1() / mnat << endl;
787 data << "Mp = " << star.mass_b2() / mnat << endl;
788
789 data << "Rn = " << star.ray_pole()/R << "\t" << star.ray_eq()/ R << endl;
790 data << "Rp = " << star.ray_pole2()/R << "\t" << star.ray_eq2()/ R << endl;
791
792 data << "\n# Intermediate radii: \n";
793 data << "thetaI = " << thetaI << endl;
794 data << "RXI = " << RnI/R << "\t" << RpI/R << endl;
795
796 data << "\n# Viriel identity violations:" << endl;
797 data << "GRV3 = " << star.grv3() << endl;
798 data << "GRV2 = " << star.grv2() << endl;
799
800 data << "\n# relativistic stuff in physical units: \n";
801 data << "Mbar_n = " << star.mass_b1() / msol << " Msol\n";
802 data << "Mbar_p = " << star.mass_b2() / msol << " Msol\n";
803 data << "Mbar = " << star.mass_b() / msol << " Msol\n";
804 data << "Mgrav = " << star.mass_g() / msol << " Msol\n";
805 data << "Rcirc_n = " << star.r_circ() * 10.0 << " km\n";
806 data << "Rcirc_p = " << star.r_circ2() * 10.0 << " km\n";
807 data << "lapse N(0) = " << star.get_nnn()()(0,0,0,0) << endl;
808 data << "lapse N(eq) = " << star.get_nnn()().va.val_point(0,1,M_PI/2,0) << endl;
809 data << "lapse N(pol) = " << star.get_nnn()().va.val_point(0,1,0, 0) << endl;
810 data << "|N^phi|(eq) = " << shiftMag.va.val_point(0,1,M_PI/2,0) << endl;
811
812 data << "RR_eq_n = " << RR_eq_n << endl;
813 data << "RR_pol_n = " << RR_pol_n << endl;
814 data << "RR_eq_p = " << RR_eq_p << endl;
815 data << "RR_pol_p = " << RR_pol_p << endl;
816
817 // in order to uniquely idenfity the run, we append the output of "calcul.d" to this file:
818 data << "\n======================================================================\n";
819 data << " Identification of the run: calcul.d\n";
820 data << "======================================================================\n";
821 data.close();
822
823 system(("cat calcul.d >> "+fname+".d").c_str()) ;
824
825
826 return;
827
828 } // compare_analytic
829
830 //----------------------------------------------------------------------
831 // function A(r) for numerical integration
832 double AofR (double r, void *params)
833 {
834 double res;
835 AofR_params *myparams = reinterpret_cast<AofR_params*>(params);
836
837 res = myparams->AofR->val_point( r, myparams->theta, myparams->phi);
838
839 return (res);
840
841 } /* AofR() */
842 //----------------------------------------------------------------------
843
844 /*----------------------------------------------------------------------
845 * get_file_base(): construct filename-base from EOS parameters
846 *
847 *----------------------------------------------------------------------*/
848 string
849 get_file_base (bool relat, double xp0, double sig0)
850 {
851 ostringstream s;
852 char cbuf[50]; // man, <ios> does not seem to exist here...
853 const char *head = relat ? "Rel" : "Newt" ;
854
855 sprintf (cbuf, "%s_xp%4.2f_sig%4.2f", head, xp0, sig0);
856
857 s << cbuf;
858
859 return (s.str());
860 }
861
862 string
863 get_file_base (bool relat, double xp0, double sig0, double eps0, double om1, double om2, int typeos, int nzet, int adapt)
864 {
865 ostringstream s;
866 char cbuf[50]; // man, <ios> does not seem to exist here...
867 double relOm;
868
869 if (om2 != 0)
870 relOm = (om1 - om2)/om2;
871 else
872 relOm = 0;
873
874 s << get_file_base (relat, xp0, sig0);
875
876 sprintf (cbuf, "_eps%4.2f_Om%8.6f_R%4.2f%s%s%s", eps0, om2, relOm,
877 (typeos==5)? "_sr" : "",
878 (nzet==2)? "_2dom" : "",
879 (adapt>0)? "_adapt" : "");
880
881 s << cbuf;
882
883 return (s.str());
884 }
885