Debian Codegraph @

Export/C++/Source/mag_ns_aux.C

raw
1 /*
2 * Constructor of class Mag_NS (magnetized neutron star exportation)
3 * which depends explicitely on Lorene objects.
4 *
5 * (see file mag_ns.h for documentation).
6 */
7
8 /*
9 * Copyright (c) 2002 Eric Gourgoulhon
10 * Copyright (c) 2009 Jerome Novak
11 *
12 * This file is part of LORENE.
13 *
14 * LORENE is free software; you can redistribute it and/or modify
15 * it under the terms of the GNU General Public License version 2
16 * as published by the Free Software Foundation.
17 *
18 * LORENE is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU General Public License for more details.
22 *
23 * You should have received a copy of the GNU General Public License
24 * along with LORENE; if not, write to the Free Software
25 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
26 *
27 */
28
29 char mag_ns_aux_C[] = "$Header: /cvsroot/Lorene/Export/C++/Source/mag_ns_aux.C,v 1.4 2016/02/17 09:46:35 j_novak Exp $" ;
30
31 /*
32 * $Id: mag_ns_aux.C,v 1.4 2016/02/17 09:46:35 j_novak Exp $
33 * $Log: mag_ns_aux.C,v $
34 * Revision 1.4 2016/02/17 09:46:35 j_novak
35 * u_euler output in units of c.
36 *
37 * Revision 1.3 2014/10/13 08:54:06 j_novak
38 * Lorene classes and functions now belong to the namespace Lorene.
39 *
40 * Revision 1.2 2014/05/13 10:06:45 j_novak
41 * Update to take unto account the change in Lorene magnetic units.
42 *
43 * Revision 1.1 2009/11/19 16:15:21 j_novak
44 * Export class for magnetized neutron stars.
45 *
46 *
47 * $Header: /cvsroot/Lorene/Export/C++/Source/mag_ns_aux.C,v 1.4 2016/02/17 09:46:35 j_novak Exp $
48 *
49 */
50
51 #include "../Include/mag_ns.h"
52
53 // C headers
54 #include <cstring>
55 #include <cmath>
56
57 // Lorene headers
58 #include "tenseur.h"
59 #include "et_rot_mag.h"
60 #include "eos.h"
61 #include "unites.h"
62 #include "metric.h"
63 #include "utilitaires.h"
64
65 //----------------------------------------//
66 // Constructor from LORENE data //
67 //----------------------------------------//
68
69 namespace Lorene {
70 Mag_NS::Mag_NS(int nbpoints, const double* xi, const double* yi,
71 const double* zi, const char* filename)
72 : np(nbpoints) {
73
74 using namespace Unites ;
75 using namespace Unites_mag ;
76
77 // Reading of data
78 // ---------------
79 FILE* fich = fopen(filename, "r") ;
80
81 Mg3d spectral_grid(fich) ;
82 int nphi = spectral_grid.get_np(0) ;
83 if (nphi < 4) {
84 cout << "Contructor of Mag_NS: " << endl ;
85 cout << "Fatal problem with initial data, "<< endl ;
86 cout << "the number of points in the phi direction is lower than 4."
87 << endl ;
88 cout << "Impossible to rotate tensors to Cartesian triad. Please give as"
89 << endl ;
90 cout << "an input a result file from magstar with nphi >=4." << endl ;
91 abort() ;
92 }
93 Map_et mapping(spectral_grid, fich) ;
94 Eos* p_eos = Eos::eos_from_file(fich) ;
95
96 Et_rot_mag star(mapping, *p_eos, fich) ;
97 star.equation_of_state() ;
98 star.update_metric() ;
99 star.extrinsic_curvature() ;
100 star.hydro_euler() ;
101
102 const Map& mp = star.get_mp();
103
104 const Base_vect_spher& bspher = mp.get_bvect_spher() ;
105 Sym_tensor gij(mp, COV, bspher) ;
106 gij.set_etat_zero() ;
107 gij.set(1,1) = star.get_a_car()() ;
108 gij.set(2,2) = star.get_a_car()() ;
109 gij.set(3,3) = star.get_b_car()() ;
110 Metric gam(gij) ; //the 3-metric in quasi-isotropic coordinates
111
112 // Initialisation of member data
113 // -----------------------------
114
115 const Eos_poly* p_eos_poly = dynamic_cast<const Eos_poly*>( p_eos ) ;
116 double m_0 = 1. ;
117 if ( p_eos_poly != 0x0 ) {
118 strcpy(eos_name, "Polytropic EOS") ;
119 gamma_poly = p_eos_poly->get_gam() ;
120 kappa_poly = p_eos_poly->get_kap() ;
121 m_0 = p_eos_poly->get_m_0() ;
122 }
123 else {
124 strncpy(eos_name, (star.get_eos()).get_name(), 100) ;
125 gamma_poly = 0 ;
126 kappa_poly = 0 ;
127 cout << "Mag_NS::Mag_NS : not a ploytropic EOS" << endl ;
128 cout << "WARNING!!" << endl ;
129 cout << "exporting the baryon density instead of the mass density!" << endl ;
130 arrete() ;
131 }
132
133 Scalar sp_density = m_0 * star.get_nbar()()*rho_unit ;
134 Scalar sp_energy = star.get_ener()() * rho_unit;
135 omega = star.get_omega_c() * f_unit ;
136 rho_c = m_0*sp_density.val_grid_point(0,0,0,0) ;
137 eps_c = sp_energy.val_grid_point(0,0,0,0) / rho_c - 1. ;
138 mass_b = star.mass_b() / msol ;
139 mass_g = star.mass_g() / msol ;
140 r_eq = star.ray_eq() / km ;
141 r_p = star.ray_pole() / km ;
142 angu_mom = star.angu_mom() / ( ggrav * msol*msol) ;
143 T_over_W = star.tsw() ;
144 magn_mom = star.MagMom() ;
145 b_z_pole =
146 star.Magn()(0).va.val_point(star.l_surf()(0,0), star.xi_surf()(0,0),0.,0.)
147 * mag_unit / 1.e9 ;
148 int theta_eq = mapping.get_mg()->get_nt(star.get_nzet() - 1) - 1 ;
149 b_z_eq = star.Magn()(1).va.val_point(star.l_surf()(0,theta_eq),
150 star.xi_surf()(0,theta_eq),M_PI_2,0.)
151 * mag_unit / 1.e9 ;
152
153 cout.precision(13) ;
154 cout << endl << "Magnetized star read in file : " << endl ;
155 cout << "------------------------------ " << endl ;
156 cout << star << endl ;
157 cout << endl << "Summary : " << endl ;
158 cout << "-------" << endl ;
159 cout << " Omega : " << omega << " rad/s" << endl ;
160 cout << " Baryon mass : " << mass_b
161 << " M_sol" << endl ;
162 cout << " Gravitational mass : " << mass_g
163 << " M_sol" << endl ;
164 cout << " Equatorial radius : " << r_eq
165 << " km" << endl ;
166 cout << " Polar radius : " << r_p
167 << " km" << endl ;
168 cout << " Total angular momentum : " << angu_mom
169 << " G M_sol^2 / c" << endl ;
170 cout << " T/W : " << T_over_W << endl ;
171 cout << " Magnetic momentum : " << magn_mom
172 << " A/m^2" << endl ;
173 cout << " Radial magnetic field polar value : " << b_z_pole
174 << " GT" << endl ;
175 cout << " Tangent magnetic field equatorial value : " << b_z_eq
176 << " GT" << endl ;
177
178 // Creation of the various arrays on the Cartesian grid
179 // ----------------------------------------------------
180
181 alloc_memory() ;
182
183 // Initialisation of the Cartesian grid
184 // ------------------------------------
185
186 for (int i=0; i<np; i++) {
187 xx[i] = xi[i] ;
188 }
189 for (int i=0; i<np; i++) {
190 yy[i] = yi[i] ;
191 }
192 for (int i=0; i<np; i++) {
193 zz[i] = zi[i] ;
194 }
195
196 // Computation of the values at the points of the Cartesian grid
197 // -------------------------------------------------------------
198 assert(star.is_relativistic()) ;
199
200 Scalar sp_lapse = star.get_nnn()() ;
201 Vector sp_shift(mapping, CON, mapping.get_bvect_cart()) ;
202 sp_shift.set(1) = star.get_shift()(0) ; //contravariant representation!!
203 sp_shift.set(2) = star.get_shift()(1) ;
204 sp_shift.set(3) = star.get_shift()(2) ;
205
206 Sym_tensor sp_gamma(mapping, COV, mapping.get_bvect_spher()) ;
207 sp_gamma.set_etat_qcq() ;
208 for (int i=1; i<=3; i++) {
209 for (int j=1; j<=i; j++)
210 sp_gamma.set(i,j) = 0 ;
211 if (i != 3) sp_gamma.set(i,i) = star.get_a_car()() ;
212 else sp_gamma.set(3,3) = star.get_bbb()()*star.get_bbb()() ;
213 }
214 sp_gamma.change_triad(mapping.get_bvect_cart()) ;
215
216 Sym_tensor sp_kij(mapping, COV, mapping.get_bvect_cart()) ;
217 sp_kij.set_etat_qcq() ;
218 for (int i=0; i<3; i++)
219 for (int j=i; j<3; j++) {
220 sp_kij.set(i+1, j+1) =
221 star.get_bbb()()*star.get_bbb()()*star.get_tkij()(i,j) / r_unit ;
222 sp_kij.set(i+1, j+1).dec_dzpuis(2) ;
223 }
224
225 Vector sp_u_euler(mapping, CON, mapping.get_bvect_cart()) ;
226 sp_u_euler.set(1) = star.get_u_euler()(0) ;
227 sp_u_euler.set(2) = star.get_u_euler()(1) ;
228 sp_u_euler.set(3) = star.get_u_euler()(2) ;
229
230 Vector sp_current(mp, CON, mapping.get_bvect_spher()) ;
231 sp_current.set(1) = 0 ;
232 sp_current.set(2) = 0 ;
233 sp_current.set(3) = Scalar(star.get_jphi()*j_unit) ;
234 sp_current.set(3).mult_rsint() ;
235 sp_current.change_triad(mapping.get_bvect_cart()) ;
236 Scalar sp_jt = star.get_jt() * j_unit ;
237
238 Scalar fac = 1.e9*sqrt(star.get_a_car()())/mag_unit ;//to transform B^(i) into B^i
239 fac.std_spectral_base() ;
240 Vector sp_Bmag(mp, CON, bspher) ;
241 sp_Bmag.set(1) = Scalar(star.Magn()(0)) / fac ;
242 sp_Bmag.set(1).dec_dzpuis(2) ;
243 sp_Bmag.set(2) = Scalar(star.Magn()(1)) / fac ;
244 sp_Bmag.set(2).dec_dzpuis(2) ;
245 sp_Bmag.set(3) = 0 ;
246 sp_Bmag.change_triad(mapping.get_bvect_cart()) ;
247
248 for (int i=0; i<np; i++) {
249
250 double x0 = xx[i] * km ; // x, y, z in Lorene's unit
251 double y0 = yy[i] * km ;
252 double z0 = zz[i] * km ;
253
254 // Values of (l, xi, theta, phi) corresponding to (x,y,z):
255 // -------------------------------------------------------
256 double r, theta, phi ; // polar coordinates centered on the star
257 mapping.convert_absolute(x0, y0, z0, r, theta, phi) ;
258
259 // Lapse function
260 // --------------
261
262 nnn[i] = sp_lapse.val_point(r, theta, phi) ;
263
264 // Shift vector
265 // ------------
266
267 beta_x[i] = sp_shift(1).val_point(r, theta, phi) ;
268 beta_y[i] = sp_shift(2).val_point(r, theta, phi) ;
269 beta_z[i] = sp_shift(3).val_point(r, theta, phi) ;
270
271 // 3-metric
272 // ---------
273
274 g_xx[i] = sp_gamma(1,1).val_point(r, theta, phi) ;
275 g_yy[i] = sp_gamma(2,2).val_point(r, theta, phi) ;
276 g_zz[i] = sp_gamma(3,3).val_point(r, theta, phi) ;
277 g_xy[i] = sp_gamma(1,2).val_point(r, theta, phi) ;
278 g_xz[i] = sp_gamma(1,3).val_point(r, theta, phi) ;
279 g_yz[i] = sp_gamma(2,3).val_point(r, theta, phi) ;
280
281 // Extrinsic curvature
282 // -------------------
283
284 k_xx[i] = sp_kij(1,1).val_point(r, theta, phi) ;
285 k_xy[i] = sp_kij(1,1).val_point(r, theta, phi) ;
286 k_xz[i] = sp_kij(1,1).val_point(r, theta, phi) ;
287 k_yy[i] = sp_kij(1,1).val_point(r, theta, phi) ;
288 k_yz[i] = sp_kij(1,1).val_point(r, theta, phi) ;
289 k_zz[i] = sp_kij(1,1).val_point(r, theta, phi) ;
290
291 // Baryon density [kg/m^3]
292 // --------------
293
294 nbar[i] = sp_density.val_point(r, theta, phi) ;
295
296 // Energy density
297 // --------------
298
299 double ener = sp_energy.val_point(r, theta, phi) ;
300
301 if ( nbar[i] == double(0) ) {
302 ener_spec[i] = 0 ;
303 }
304 else {
305 ener_spec[i] = ener / nbar[i] - double(1) ;
306 }
307
308 // 3-velocity with respect to the Eulerian observer
309 // ------------------------------------------------
310 u_euler_x[i] = sp_u_euler(1).val_point(r, theta, phi) ;
311 u_euler_y[i] = sp_u_euler(2).val_point(r, theta, phi) ;
312 u_euler_z[i] = sp_u_euler(3).val_point(r, theta, phi) ;
313
314 // Magnetic field
315 //---------------
316 bb_x[i] = sp_Bmag(1).val_point(r, theta, phi) ;
317 bb_y[i] = sp_Bmag(2).val_point(r, theta, phi) ;
318 bb_z[i] = sp_Bmag(3).val_point(r, theta, phi) ;
319
320 // 4-current
321 //----------
322 jj_t[i] = sp_jt.val_point(r, theta, phi) ;
323 jj_x[i] = sp_current(1).val_point(r, theta, phi) ;
324 jj_y[i] = sp_current(2).val_point(r, theta, phi) ;
325 jj_z[i] = sp_current(3).val_point(r, theta, phi) ;
326
327
328 } // End of loop on the points
329
330
331 delete p_eos ;
332 }
333
334 }