LORENE
star_rot_cfc.C
1 /*
2  * Methods of class Star_rot_CFC
3  *
4  * (see file star_rot_dirac.h for documentation).
5  *
6  */
7 
8 /*
9  * Copyright (c) 2024 Jerome Novak
10  *
11  * This file is part of LORENE.
12  *
13  * LORENE is free software; you can redistribute it and/or modify
14  * it under the terms of the GNU General Public License version 2
15  * as published by the Free Software Foundation.
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 
30 
31 // Lorene headers
32 #include "star_rot_cfc.h"
33 #include "unites.h"
34 #include "utilitaires.h"
35 
36 
37  //--------------//
38  // Constructors //
39  //--------------//
40 
41 // Standard constructor
42 //-------------------------
43 namespace Lorene {
44  Star_rot_CFC::Star_rot_CFC(Map& mpi, int nzet_i, const Eos& eos_i, int relat_i, int filter)
45  : Star(mpi, nzet_i, eos_i),
46  relat_type(relat_i),
47  spectral_filter(filter),
48  psi(mpi),
49  j_euler(mpi, CON, mpi.get_bvect_spher()),
50  v2(mpi),
51  psi4(mpi),
52  psi2(mpi),
53  flat(mpi.flat_met_spher()),
54  hatA(mpi, CON, mpi.get_bvect_spher()),
55  hatA_quad(mpi)
56 {
57  assert (relat_type == 3) ;
58  assert ((spectral_filter>=0) && (spectral_filter<100)) ;
59 
60  // Initialization to a static state
61  omega = 0 ;
62  v2 = 0 ;
63 
64  // All the matter quantities are initialized to zero
66 
67  // Initialization to a flat case
68  psi = 1 ;
70  psi4 = 1 ;
71  psi2 = 1 ;
73  hatA_quad = 0 ;
74 
75  // Pointers of derived quantities initialized to zero :
76  set_der_0x0() ;
77 
78 }
79 
80 
81 // Copy constructor
82 //-----------------
84  : Star(star),
85  relat_type(star.relat_type),
86  spectral_filter(star.spectral_filter),
87  psi(star.psi),
88  j_euler(star.j_euler),
89  v2(star.v2),
90  psi4(star.psi4),
91  psi2(star.psi2),
92  flat(star.flat),
93  hatA(star.hatA),
94  hatA_quad(star.hatA_quad)
95 {
96 
97  omega = star.omega ;
98 
99  // Pointers of derived quantities initialized to zero :
100  set_der_0x0() ;
101 
102 }
103 
104 
105 //Constructor from a file
106 //------------------------
107 Star_rot_CFC::Star_rot_CFC(Map& mpi, const Eos& eos_i, FILE* fich)
108  : Star(mpi, eos_i, fich),
109  psi(mpi, *(mpi.get_mg()), fich),
110  j_euler(mpi, CON, mpi.get_bvect_spher()),
111  v2(mpi),
112  psi4(mpi),
113  psi2(mpi),
114  flat(mpi.flat_met_spher()),
115  hatA(mpi, CON, mpi.get_bvect_spher()),
116  hatA_quad(mpi)
117 {
118 
119  // Pointers of derived quantities initialized to zero
120  //----------------------------------------------------
121  set_der_0x0() ;
122 
123  fread_be(&relat_type, sizeof(int), 1, fich) ;
124  fread_be(&spectral_filter, sizeof(int), 1, fich) ;
125 
126  // Metric fields are read in the file:
127  fread_be(&omega, sizeof(double), 1, fich) ;
128  Vector shift_tmp(mpi, mpi.get_bvect_spher(), fich) ;
129  beta = shift_tmp ;
130 
131  update_metric() ;
132 
134 
135  hydro_euler() ;
136 
137  // Computation of \hat{A}^{ij} and its norm
138  //------------------------------------------
139  Vector sou_Xi = 2*Unites::qpig*psi4*psi4*psi2*j_euler ;
140  double lambda = 1./3. ;
141  Vector Xi_new = sou_Xi.poisson(lambda) ;
142 
143  hatA = Xi_new.ope_killing_conf(flat) ;
144  hatA_quad = contract(hatA, 0, 1, hatA.up_down(flat), 0, 1) ;
145 
146 }
147 
148 
149  //------------//
150  // Destructor //
151  //------------//
152 
154 
156 
157 }
158 
159 
160  //----------------------------------//
161  // Management of derived quantities //
162  //----------------------------------//
163 
165 
166  if (p_angu_mom != 0x0) delete p_angu_mom ;
167  if (p_grv2 != 0x0) delete p_grv2 ;
168  if (p_grv3 != 0x0) delete p_grv3 ;
169  if (p_tsw != 0x0) delete p_tsw ;
170  if (p_r_circ != 0x0) delete p_r_circ ;
171  if (p_rp_circ != 0x0) delete p_rp_circ ;
172 
173  set_der_0x0() ;
174 
175  Star::del_deriv() ;
176 
177 }
178 
179 
181 
182  p_angu_mom = 0x0 ;
183  p_grv2 = 0x0 ;
184  p_grv3 = 0x0 ;
185  p_tsw = 0x0 ;
186  p_r_circ = 0x0 ;
187  p_rp_circ = 0x0 ;
188 
189 }
190 
191 
193 
195  v2.set_etat_nondef() ;
196 
197  del_deriv() ;
198 
200 
201 }
202 
203 
204 
205  //---------------//
206  // Assignment //
207  //---------------//
208 
209 // Assignment to another Star_rot_CFC
210 // ------------------------------------
211 
213 
214  // Assignment of quantities common to all the derived classes of Star
215  Star::operator=(star) ;
216 
217  // Assignment of proper quantities of class Star_rot_CFC
218  relat_type = star.relat_type ;
220  psi = star.psi ;
221  omega = star.omega ;
222  j_euler = star.j_euler ;
223  v2 = star.v2 ;
224  psi4 = star.psi4 ;
225  psi2 = star.psi2 ;
226  hatA = star.hatA ;
227  hatA_quad = star.hatA_quad ;
228 
229  assert(&flat == &star.flat) ;
230 
231  del_deriv() ; // Deletes all derived quantities
232 
233 }
234 
235 
236  //-----------//
237  // Outputs //
238  //-----------//
239 
240 // Save in a file
241 // --------------
242 
243 void Star_rot_CFC::sauve(FILE* fich) const {
244 
245  Star::sauve(fich) ;
246 
247  psi.sauve(fich) ;
248 
249  fwrite_be(&relat_type, sizeof(int), 1, fich) ;
250  fwrite_be(&spectral_filter, sizeof(int), 1, fich) ;
251  fwrite_be(&omega, sizeof(double), 1, fich) ;
252  beta.sauve(fich) ;
253 
254 }
255 
256 
257 // Printing
258 // ---------
259 
260 ostream& Star_rot_CFC::operator>>(ostream& ost) const {
261 
262  using namespace Unites ;
263 
264  Star::operator>>(ost) ;
265 
266  ost << "Rotating star " ;
267  switch (relat_type) {
268  case 0 : {
269  ost << "in Newtonian theory" << endl ;
270  break;
271  }
272  case 1 : {
273  ost << "in Dirac gauge" << endl ;
274  break ;
275  }
276  case 2 : {
277  ost << "in Conformal Flatness Condition (CFC)" << endl ;
278  break ;
279  }
280  case 3: {
281  ost << "in Conformal Flatness Condition (CFC), with hat{A}^{ij}_{TT} = 0\n"
282  << "(see Cordero-Carrion et al. (2009) for details" << endl ;
283  break ;
284  }
285  default: {
286  cerr << "Star_rot_CFC::operator>> : unknown value for 'relat_type'" << endl ;
287  cerr << "relat_type = " << relat_type << endl ;
288  abort() ;
289  }
290  }
291 
292  // Only uniformly rotating star for the moment....
293  ost << endl ;
294  ost << "Uniformly rotating star" << endl ;
295  ost << "-----------------------" << endl ;
296  if (spectral_filter > 0)
297  ost << "hydro sources of equations are filtered\n"
298  << "with " << spectral_filter << "-order exponential filter" << endl ;
299 
300  double freq = omega/ (2.*M_PI) ;
301  ost << "Omega : " << omega * f_unit
302  << " rad/s f : " << freq * f_unit << " Hz" << endl ;
303  ost << "Rotation period : " << 1000. / (freq * f_unit) << " ms"
304  << endl ;
305 
306  ost << "Error on the virial identity GRV2 : " << endl ;
307  ost << "GRV2 = " << grv2() << endl ;
308  ost << "Error on the virial identity GRV3 : " << endl ;
309  ost << "GRV3 = " << grv3() << endl ;
310 
311  ost << "Angular momentum J : "
312  << angu_mom()/( qpig / (4*M_PI) *msol*msol) << " G M_sol^2 / c"
313  << endl ;
314  ost << "c J / (G M^2) : "
315  << angu_mom()/( qpig / (4*M_PI) * pow(mass_g(), 2.) ) << endl ;
316 
317  if (omega != 0.) {
318  double mom_iner = angu_mom() / omega ;
319  double mom_iner_38si = mom_iner * rho_unit * (pow(r_unit, double(5.))
320  / double(1.e38) ) ;
321  ost << "Moment of inertia: " << mom_iner_38si << " 10^38 kg m^2"
322  << endl ;
323  }
324 
325  ost << "Ratio T/W : " << tsw() << endl ;
326  ost << "Circumferential equatorial radius R_circ : "
327  << r_circ()/km << " km" << endl ;
328  if (mp.get_mg()->get_np(0) == 1)
329  ost << "Circumferential polar radius Rp_circ : "
330  << rp_circ()/km << " km" << endl ;
331  ost << "Coordinate equatorial radius r_eq : " << ray_eq()/km << " km"
332  << endl ;
333  ost << "Flattening r_pole/r_eq : " << aplat() << endl ;
334  if (mp.get_mg()->get_np(0) == 1)
335  ost << "Ellipticity sqrt(1-(Rp_circ/R_circ)^2) : " << ellipt() << endl ;
336 
337  double compact = qpig/(4.*M_PI) * mass_g() / r_circ() ;
338  ost << "Compaction parameter M_g / R_circ : " << compact << endl ;
339 
340 
341  // More to come here.....
342 
343  return ost ;
344 
345 }
346 }
virtual ostream & operator>>(ostream &) const
Operator >> (virtual function called by the operator <<).
Definition: star_rot_cfc.C:260
double * p_grv2
Error on the virial identity GRV2.
Definition: star_rot_cfc.h:98
virtual double tsw() const
Ratio T/W.
Map & mp
Mapping associated with the star.
Definition: star.h:180
int get_np(int l) const
Returns the number of points in the azimuthal direction ( ) in domain no. l.
Definition: grilles.h:479
Scalar psi
Conformal factor .
Definition: star_rot_cfc.h:65
const Base_vect_spher & get_bvect_spher() const
Returns the orthonormal vectorial basis associated with the coordinates of the mapping.
Definition: map.h:801
virtual double grv3() const
Error on the virial identity GRV3.
Lorene prototypes.
Definition: app_hor.h:67
Standard units of space, time and mass.
Equation of state base class.
Definition: eos.h:209
const Mg3d * get_mg() const
Gives the Mg3d on which the mapping is defined.
Definition: map.h:783
virtual void set_etat_nondef()
Sets the logical state of all components to ETATNONDEF (undefined state).
Definition: tensor.C:498
virtual double angu_mom() const
Angular momentum.
Base class for coordinate mappings.
Definition: map.h:688
virtual void del_deriv() const
Deletes all the derived quantities.
Definition: star_rot_cfc.C:164
virtual double r_circ() const
Circumferential equatorial radius.
int spectral_filter
Spectral exponential filtering order.
Definition: star_rot_cfc.h:58
Tensor up_down(const Metric &gam) const
Computes a new tensor by raising or lowering all the indices of *this .
double * p_rp_circ
Circumferential polar radius.
Definition: star_rot_cfc.h:102
void operator=(const Star_rot_CFC &)
Assignment to another Star_rot_CFC.
Definition: star_rot_cfc.C:212
Scalar psi4
Conformal factor .
Definition: star_rot_cfc.h:81
virtual void std_spectral_base()
Sets the spectral bases of the Valeur va to the standard ones for a scalar field. ...
Definition: scalar.C:790
virtual void sauve(FILE *) const
Save in a binary file.
Definition: tensor.C:915
virtual void set_etat_nondef()
Sets the logical state to ETATNONDEF (undefined).
Definition: scalar.C:350
Base class for stars.
Definition: star.h:175
virtual void sauve(FILE *) const
Save in a file.
Definition: star_rot_cfc.C:243
Star_rot_CFC(Map &mp_i, int nzet_i, const Eos &eos_i, int relat_i=3, int filter=0)
Standard constructor.
Definition: star_rot_cfc.C:44
Vector beta
Shift vector.
Definition: star.h:228
Tensor field of valence 1.
Definition: vector.h:188
void operator=(const Star &)
Assignment to another Star.
Definition: star.C:354
Sym_tensor ope_killing_conf(const Metric &gam) const
Computes the conformal Killing operator associated with a given metric.
Definition: vector.C:468
Class for relativistic rotating stars in Conformal Flatness Condition and maximal slicing...
Definition: star_rot_cfc.h:39
virtual void hydro_euler()
Computes the hydrodynamical quantities relative to the Eulerian observer from those in the fluid fram...
virtual void sauve(FILE *) const
Save in a file.
Definition: scalar.C:692
virtual double aplat() const
Flattening r_pole/r_eq.
double omega
Rotation angular velocity ([f_unit] )
Definition: star_rot_cfc.h:60
int relat_type
Relativistic flag.
Definition: star_rot_cfc.h:50
Vector poisson(double lambda, int method=6) const
Solves the vector Poisson equation with *this as a source.
virtual double rp_circ() const
Circumferential polar radius.
double * p_angu_mom
Angular momentum.
Definition: star_rot_cfc.h:97
double * p_r_circ
Circumferential equatorial radius.
Definition: star_rot_cfc.h:101
int fwrite_be(const int *aa, int size, int nb, FILE *fich)
Writes integer(s) into a binary file according to the big endian convention.
Definition: fwrite_be.C:73
Cmp pow(const Cmp &, int)
Power .
Definition: cmp_math.C:351
Tenseur contract(const Tenseur &, int id1, int id2)
Self contraction of two indices of a Tenseur .
int fread_be(int *aa, int size, int nb, FILE *fich)
Reads integer(s) from a binary file according to the big endian convention.
Definition: fread_be.C:72
virtual void del_deriv() const
Deletes all the derived quantities.
Definition: star.C:301
virtual void del_hydro_euler()
Sets to ETATNONDEF (undefined state) the hydrodynamical quantities relative to the Eulerian observer...
Definition: star.C:333
void set_der_0x0() const
Sets to 0x0 all the pointers on derived quantities.
Definition: star_rot_cfc.C:180
double ray_eq() const
Coordinate radius at , [r_unit].
Definition: star_global.C:111
double * p_tsw
Ratio T/W.
Definition: star_rot_cfc.h:100
double * p_grv3
Error on the virial identity GRV3.
Definition: star_rot_cfc.h:99
virtual ostream & operator>>(ostream &) const
Operator >> (virtual function called by the operator <<).
Definition: star.C:420
virtual ~Star_rot_CFC()
Destructor.
Definition: star_rot_cfc.C:153
virtual void sauve(FILE *) const
Save in a file.
Definition: star.C:400
virtual void set_etat_zero()
Sets the logical state of all components to ETATZERO (zero state).
Definition: tensor.C:506
void equation_of_state()
Computes the proper baryon and energy density, as well as pressure from the enthalpy.
Definition: star.C:465
void update_metric()
Computes metric quantities from known potentials.
virtual double grv2() const
Error on the virial identity GRV2.
Vector j_euler
Momentum density 3-vector with respect to the Eulerian observer.
Definition: star_rot_cfc.h:75
virtual void del_hydro_euler()
Sets to ETATNONDEF (undefined state) the hydrodynamical quantities relative to the Eulerian observer...
Definition: star_rot_cfc.C:192
virtual double mass_g() const
Gravitational mass.
virtual double ellipt() const
Ellipticity e.
const Metric_flat & flat
flat metric (spherical components)
Definition: star_rot_cfc.h:85