Debian Codegraph @

Codes/Mag_eos_star/mag_eos_star.C

raw
1 /*
2 * Main code for computing magnetized stars with B-field dependent EoS.
3 *
4 */
5
6 /*
7 * Copyright (c) 2002 Jerome Novak & Emanuel Marcq
8 * Copyright (c) 2014 Debarati Chatterjee
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 /*
29 * $Id: mag_eos_star.C,v 1.6 2014/10/13 08:53:57 j_novak Exp $
30 * $Log: mag_eos_star.C,v $
31 * Revision 1.6 2014/10/13 08:53:57 j_novak
32 * Lorene classes and functions now belong to the namespace Lorene.
33 *
34 * Revision 1.5 2014/09/22 15:00:09 j_novak
35 * Maximal magnetic field display.
36 *
37 * Revision 1.4 2014/07/04 13:01:47 j_novak
38 * Parameter file for mass-shedding limit.
39 *
40 * Revision 1.3 2014/05/27 12:41:25 j_novak
41 * Added the possibility to converge to a given mgnetic moment.
42 *
43 * Revision 1.2 2014/04/29 13:46:54 j_novak
44 * Addition of swicthes 'use_B_in_eos' and 'include_magnetisation' to control the model.
45 *
46 * Revision 1.1 2014/04/28 14:41:15 j_novak
47 * Files for magnetisation star main code.
48 *
49 *
50 * $Header: /cvsroot/Lorene/Codes/Mag_eos_star/mag_eos_star.C,v 1.6 2014/10/13 08:53:57 j_novak Exp $
51 *
52 */
53
54 // headers C
55 #include <cmath>
56
57 // headers Lorene
58 #include "et_rot_mag.h"
59 #include "eos.h"
60 #include "utilitaires.h"
61 #include "graphique.h"
62 #include "nbr_spx.h"
63 #include "unites.h"
64 #include "metric.h"
65
66 namespace Lorene{
67 // Local prototype (for drawings only)
68 Cmp raccord_c1(const Cmp& uu, int l1) ;
69 }
70
71 using namespace Lorene ;
72
73 // Definition de f_j et de M_j
74 Cmp f_j(const Cmp& x, double a_j){
75 Cmp resu(x.get_mp() ) ;
76 resu = a_j ;
77 return resu ;
78 }
79 Cmp M_j(const Cmp& x, double a_j){
80 return - a_j*x ;
81 }
82 //******************************************************************************
83
84 int main(){
85
86 using namespace Unites_mag ;
87
88 //------------------------------------------------------------------
89 // Parameters of the computation
90 //------------------------------------------------------------------
91
92 char blabla[120] ;
93
94 int relat_i, mer_max, mer_rot, mer_change_omega, mer_fix_omega,
95 delta_mer_kep, mer_mass, mermax_poisson, graph, nz, nzet, nzadapt,
96 nt, np ;
97 double ent_c, freq_si, fact_omega, mbar_wanted, precis, freq_ini_si,
98 thres_adapt, aexp_mass, relax, relax_poisson, precis_adapt ;
99
100 double Q0, a_j0, Q_ini, a_j_ini, magmom_wanted ;
101 int mer_mag, mer_change_mag, mer_fix_mag, mag_in_eos, mer_magmom,
102 use_magnetisation ;
103
104 ifstream fich("parrot.d") ;
105 fich.getline(blabla, 120) ;
106 fich >> relat_i ; fich.getline(blabla, 120) ;
107 bool relat = (relat_i == 1) ;
108 fich >> ent_c ; fich.getline(blabla, 120) ;
109 fich >> freq_si ; fich.getline(blabla, 120) ;
110 fich >> fact_omega ; fich.getline(blabla, 120) ;
111 fich >> mbar_wanted ; fich.getline(blabla, 120) ;
112 mbar_wanted *= msol ;
113 fich >> magmom_wanted ; fich.getline(blabla, 120) ;
114 fich.getline(blabla, 120) ;
115 fich >> Q0 ; fich.getline(blabla,120) ;
116 fich >> a_j0 ; fich.getline(blabla,120) ;
117 fich >> Q_ini; fich.getline(blabla,120) ;
118 fich >> a_j_ini ; fich.getline(blabla,120) ;
119 fich >> mer_mag ; fich.getline(blabla,120) ;
120 fich >> mer_change_mag ; fich.getline(blabla,120) ;
121 fich >> mer_fix_mag ; fich.getline(blabla,120);
122 fich >> mag_in_eos ; fich.getline(blabla,120);
123 fich >> use_magnetisation ; fich.getline(blabla,120);
124 fich.getline(blabla,120);
125 fich >> mer_max ; fich.getline(blabla, 120) ;
126 fich >> precis ; fich.getline(blabla, 120) ;
127 fich >> mer_rot ; fich.getline(blabla, 120) ;
128 fich >> freq_ini_si ; fich.getline(blabla, 120) ;
129 fich >> mer_change_omega ; fich.getline(blabla, 120) ;
130 fich >> mer_fix_omega ; fich.getline(blabla, 120) ;
131 fich >> delta_mer_kep ; fich.getline(blabla, 120) ;
132 fich >> thres_adapt ; fich.getline(blabla, 120) ;
133 fich >> mer_mass ; fich.getline(blabla, 120) ;
134 fich >> mer_magmom ; fich.getline(blabla, 120) ;
135 fich >> aexp_mass ; fich.getline(blabla, 120) ;
136 fich >> relax ; fich.getline(blabla, 120) ;
137 fich >> mermax_poisson ; fich.getline(blabla, 120) ;
138 fich >> relax_poisson ; fich.getline(blabla, 120) ;
139 fich >> precis_adapt ; fich.getline(blabla, 120) ;
140 fich >> graph ; fich.getline(blabla, 120) ;
141 fich.getline(blabla, 120) ;
142 fich >> nz ; fich.getline(blabla, 120) ;
143 fich >> nzet; fich.getline(blabla, 120) ;
144 fich >> nzadapt; fich.getline(blabla, 120) ;
145 fich >> nt; fich.getline(blabla, 120) ;
146 fich >> np; fich.getline(blabla, 120) ;
147
148 int* nr = new int[nz];
149 int* nt_tab = new int[nz];
150 int* np_tab = new int[nz];
151 double* bornes = new double[nz+1];
152
153 fich.getline(blabla, 120);
154 for (int l=0; l<nz; l++) {
155 fich >> nr[l];
156 fich >> bornes[l]; fich.getline(blabla, 120) ;
157 np_tab[l] = np ;
158 nt_tab[l] = nt ;
159 }
160 bornes[nz] = __infinity ;
161
162 Tbl ent_limit(nzet) ;
163 ent_limit.set_etat_qcq() ;
164 ent_limit.set(nzet-1) = 0 ; // enthalpy at the stellar surface
165 for (int l=0; l<nzet-1; l++) {
166 fich >> ent_limit.set(l) ; fich.getline(blabla, 120) ;
167 }
168
169
170 fich.close();
171
172 // Particular cases
173 // ----------------
174
175 // Initial frequency = final frequency
176 if ( freq_ini_si < 0 ) {
177 freq_ini_si = freq_si ;
178 mer_change_omega = mer_rot ;
179 mer_fix_omega = mer_rot + 1 ;
180 }
181
182
183 //-----------------------------------------------------------------------
184 // Equation of state
185 //-----------------------------------------------------------------------
186
187 fich.open("par_eos.d") ;
188
189 Eos* peos = Eos::eos_from_file(fich) ;
190 Eos& eos = *peos ;
191
192 fich.close() ;
193
194 //-----------------------------------------------------------------------
195 // Construction of the multi-grid and the mapping
196 //-----------------------------------------------------------------------
197
198 // Rescale of bornes in the case where there more than 1 domain inside
199 // the star
200
201 for (int l=0; l<nzet-1; l++) {
202
203 bornes[l+1] = bornes[nzet] * sqrt(1 - ent_limit(l) / ent_c) ;
204
205 }
206
207 // Type of r sampling :
208 int* type_r = new int[nz];
209 type_r[0] = RARE ;
210 for (int l=1; l<nz-1; l++) {
211 type_r[l] = FIN ;
212 }
213 type_r[nz-1] = UNSURR ;
214
215 // Type of sampling in theta and phi :
216 int type_t = SYM ;
217 int type_p = SYM ;
218
219 Mg3d mg(nz, nr, type_r, nt_tab, type_t, np_tab, type_p) ;
220
221 Map_et mp(mg, bornes) ;
222
223 // Cleaning
224 // --------
225
226 delete [] nr ;
227 delete [] nt_tab ;
228 delete [] np_tab ;
229 delete [] type_r ;
230 delete [] bornes ;
231
232
233
234 cout << endl
235 << "==========================================================" << endl
236 << " Physical parameters " << endl
237 << "=========================================================="
238 << endl ;
239 cout << endl ;
240
241 cout << endl << "Equation of state : "
242 << endl << "================= " << endl ;
243 cout << eos << endl ;
244
245 cout << "Central enthalpy : " << ent_c << " c^2" << endl ;
246 cout << "Rotation frequency : " << freq_si << " Hz" << endl ;
247 if ( abs(mer_mass) < mer_max ) {
248 cout << "Required Baryon mass [M_sol] : "
249 << mbar_wanted / msol << endl ;
250 }
251 if ( mer_magmom < mer_max ) {
252 cout << "Required magnetic moment [SI] : "
253 << magmom_wanted << endl ;
254 }
255 cout << endl
256 << "==========================================================" << endl
257 << " Computational parameters " << endl
258 << "=========================================================="
259 << endl << endl ;
260
261 cout << "Maximum number of steps in the main iteration : "
262 << mer_max << endl ;
263 cout << "Relaxation factor in the main iteration : "
264 << relax << endl ;
265 cout << "Threshold on the enthalpy relative change for ending the computation : "
266 << precis << endl ;
267 cout << "Maximum number of steps in Map_et::poisson : "
268 << mermax_poisson << endl ;
269 cout << "Relaxation factor in Map_et::poisson : "
270 << relax_poisson << endl ;
271 cout << "Step from which the baryon mass is forced to converge : "
272 << mer_mass << endl ;
273 cout << "Step from which the magnetic moment is forced to converge : "
274 << mer_magmom << endl ;
275 cout << "Exponent for the increase factor of the central enthalpy/CFA : "
276 << aexp_mass << endl ;
277 cout <<
278 "Threshold on |dH/dr|_eq / |dH/dr|_pole for the adaptation of the mapping"
279 << endl << thres_adapt << endl ;
280
281
282 cout << endl << "Multi-grid : "
283 << endl << "==========" << endl << mg << endl ;
284 cout << "Mapping : "
285 << endl << "=======" << endl << mp << endl ;
286
287
288 //-----------------------------------------------------------------------
289 // Construction of the star
290 //-----------------------------------------------------------------------
291
292 Et_magnetisation star(mp, nzet, relat, eos, (use_magnetisation!=0),
293 (mag_in_eos!=0) ) ;
294
295 if ( star.is_relativistic() ) {
296 cout << "========================" << endl ;
297 cout << "Relativistic computation" << endl ;
298 cout << "========================" << endl ;
299 }
300 else {
301 cout << "=====================" << endl ;
302 cout << "Newtonian computation" << endl ;
303 cout << "=====================" << endl ;
304 }
305
306 //-----------------------------------------------------------------------
307 // Initialization of the enthalpy field
308 //-----------------------------------------------------------------------
309
310
311 const Coord& r = mp.r ;
312 double ray0 = mp.val_r(nzet-1, 1., 0., 0.) ;
313 Cmp ent0(mp) ;
314 ent0 = ent_c * ( 1 - r*r / (ray0*ray0) ) ;
315 ent0.annule(nz-1) ;
316 ent0.std_base_scal() ;
317 star.set_enthalpy(ent0) ;
318
319 // Initialization of (n,e,p) from H
320 star.equation_of_state() ;
321
322 // Initialization of (E,S,U,etc...) (quantities relative to the Eulerian obs)
323 star.hydro_euler() ;
324
325 // Initialization of eulerian electromagnetic quantities.
326 star.MHD_comput() ;
327
328
329 cout << endl << "Initial star : "
330 << endl << "============ " << endl ;
331
332 cout << star << endl ;
333
334 //-----------------------------------------------------------------------
335 // Computation of the rotating equilibrium
336 //-----------------------------------------------------------------------
337
338 double omega = 2 * M_PI * freq_si / f_unit ;
339 double omega_ini = 2 * M_PI * freq_ini_si / f_unit ;
340
341 Itbl icontrol(11) ;
342 icontrol.set_etat_qcq() ;
343 icontrol.set(0) = mer_max ;
344 icontrol.set(1) = mer_rot ;
345 icontrol.set(2) = mer_change_omega ;
346 icontrol.set(3) = mer_fix_omega ;
347 icontrol.set(4) = mer_mass ;
348 icontrol.set(5) = mermax_poisson ;
349 icontrol.set(6) = delta_mer_kep ;
350 icontrol.set(7) = mer_mag ;
351 icontrol.set(8) = mer_change_mag ;
352 icontrol.set(9)= mer_fix_mag ;
353 icontrol.set(10) = mer_magmom ;
354
355 Tbl control(8) ;
356 control.set_etat_qcq() ;
357 control.set(0) = precis ;
358 control.set(1) = omega_ini ;
359 control.set(2) = relax ;
360 control.set(3) = relax_poisson ;
361 control.set(4) = thres_adapt ;
362 control.set(5) = precis_adapt ;
363 control.set(6) = Q_ini ;
364 control.set(7) = a_j_ini ;
365
366 Tbl diff(1) ;
367
368 star.equilibrium_mag(ent_c, omega, fact_omega, nzadapt, ent_limit,
369 icontrol, control, mbar_wanted, magmom_wanted,
370 aexp_mass, diff, Q0, a_j0, &f_j, &M_j) ;
371
372
373 cout << endl << "Final star : "
374 << endl << "========== " << endl ;
375
376 cout.precision(10) ;
377 cout << star << endl ;
378
379 const Base_vect_spher& bspher = mp.get_bvect_spher() ;
380 Sym_tensor gij(mp, COV, bspher) ;
381 gij.set_etat_zero() ;
382 gij.set(1,1) = star.get_a_car()() ;
383 gij.set(2,2) = star.get_a_car()() ;
384 gij.set(3,3) = star.get_b_car()() ;
385 Metric gam(gij) ;
386
387 Scalar fac = sqrt(star.get_a_car()()) ;
388 fac.std_spectral_base() ;
389 Vector Bmag(mp, CON, bspher) ;
390 Bmag.set(1) = Scalar(star.Magn()(0)) / fac ;
391 Bmag.set(1).dec_dzpuis(2) ;
392 Bmag.set(2) = Scalar(star.Magn()(1)) / fac ;
393 Bmag.set(2).dec_dzpuis(2) ;
394 Bmag.set(3) = 0 ;
395
396 Scalar norm_B_Euler
397 = sqrt( Scalar(star.get_a_car()())*( Bmag(1)*Bmag(1) + Bmag(2)*Bmag(2) ) ) ;
398 norm_B_Euler.std_spectral_base() ;
399 Tbl maxB = 0.5*(max(abs(Bmag(1))) + max(abs(Bmag(2)))) ;
400 Scalar divB = Bmag.divergence(gam) ;
401 cout << "div(B) / max(B) in each domain : "
402 << max(abs(divB)) / maxB ;
403 cout << "Maximal magnetic field in the Eulerian frame: "
404 << max(max(norm_B_Euler))*mag_unit << " [T]" << endl ;
405
406 // Saveguard of the whole configuration
407 // ------------------------------------
408
409 FILE* fresu = fopen("resu.d", "w") ;
410
411 star.get_mp().get_mg()->sauve(fresu) ; // writing of the grid
412 star.get_mp().sauve(fresu) ; // writing of the mapping
413 star.get_eos().sauve(fresu) ; // writing of the EOS
414 star.sauve(fresu) ; // writing of the star
415
416 fclose(fresu) ;
417
418
419
420 // Drawings
421 // --------
422
423 if (graph == 1) {
424
425 char title[80] ;
426
427 // Cmp defining the surface of the star (via the enthalpy field)
428 Cmp surf = star.get_ent()() ;
429 Cmp surf_ext(mp) ;
430 surf_ext = - 0.2 * surf(0, 0, 0, 0) ;
431 surf_ext.annule(0, star.get_nzet()-1) ;
432 surf.annule(star.get_nzet(), mg.get_nzone()-1) ;
433 surf = surf + surf_ext ;
434 surf = raccord_c1(surf, star.get_nzet()) ;
435
436 int nzdes = star.get_nzet() ;
437
438 des_coupe_y(star.get_At(), 0., nzdes, "A\\dt\\u Potential", &surf,
439 2.) ;
440 des_coupe_y(star.get_Aphi(), 0., nzdes, "Magnetic field", &surf) ;
441 des_coupe_y(norm_B_Euler, 0., nzdes, "Magnetic field norm", &surf) ;
442 des_coupe_y(star.get_ent()(), 0., nzdes, "Enthalpy", &surf) ;
443
444 strcpy(title, "Gravitational potential \\gn") ;
445
446 des_coupe_y(star.get_logn()(), 0., nzdes, title, &surf) ;
447
448
449 strcpy(title, "Azimuthal shift N\\u\\gf") ;
450 des_coupe_y(star.get_nphi()(), 0., nzdes, title, &surf) ;
451
452 strcpy(title, "Metric potential \\gz") ;
453 des_coupe_y(star.get_dzeta()(), 0., nzdes, title, &surf) ;
454
455 strcpy(title, "Metric potential (NB-1) r sin\\gh") ;
456 des_coupe_y(star.get_tggg()(), 0., nzdes, title, &surf) ;
457
458 strcpy(title, "A\\u2\\dK\\uij\\dK\\dij\\u") ;
459 des_coupe_y(star.get_ak_car()(), 0., nzdes, title, &surf) ;
460
461 }
462
463
464 // Cleaning
465 // --------
466
467 delete peos ;
468
469 exit(EXIT_SUCCESS) ;
470
471 return EXIT_SUCCESS ;
472
473 }