LORENE
strot_cfc_equil.C
1 /*
2  * Function Star_rot_CFC::equilibrium
3  *
4  * (see file star_rot_cfc.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 // Lorene headers
30 #include "star_rot_cfc.h"
31 
32 #include "utilitaires.h"
33 #include "unites.h"
34 
35 namespace Lorene {
36 void Star_rot_CFC::equilibrium(double ent_c, double omega0,
37  double fact_omega, int , const Tbl& ent_limit,
38  const Itbl& icontrol, const Tbl& control,
39  double mbar_wanted, double aexp_mass, Tbl& diff){
40 
41 
42  // Fundamental constants and units
43  // --------------------------------
44  using namespace Unites ;
45 
46  // For the display
47  // ---------------
48  char display_bold[]="x[1m" ; display_bold[0] = 27 ;
49  char display_normal[] = "x[0m" ; display_normal[0] = 27 ;
50 
51  // Grid parameters
52  // ----------------
53 
54  const Mg3d* mg = mp.get_mg() ;
55  int nz = mg->get_nzone() ; // total number of domains
56  int nzm1 = nz - 1 ;
57 
58  // Index of the point at phi=0, theta=pi/2 at the surface of the star:
59  int type_t = mg->get_type_t() ;
60  assert( ( type_t == SYM) || (type_t == NONSYM) ) ;
61  int l_b = nzet - 1 ;
62  int i_b = mg->get_nr(l_b) - 1 ;
63  int j_b = (type_t == SYM ? mg->get_nt(l_b) - 1 : mg->get_nt(l_b)/2 ) ;
64  int k_b = 0 ;
65 
66  // Value of the enthalpy defining the surface of the star
67  double ent_b = ent_limit(nzet-1) ;
68 
69  // Parameters to control the iteration
70  // -----------------------------------
71 
72  int mer_max = icontrol(0) ;
73  int mer_rot = icontrol(1) ;
74  int mer_change_omega = icontrol(2) ;
75  int mer_fix_omega = icontrol(3) ;
76  int mer_mass = icontrol(4) ;
77  int delta_mer_kep = icontrol(5) ;
78 
79  // Protections:
80  if (mer_change_omega < mer_rot) {
81  cout << "Star_rot_CFC::equilibrium: mer_change_omega < mer_rot !"
82  << endl ;
83  cout << " mer_change_omega = " << mer_change_omega << endl ;
84  cout << " mer_rot = " << mer_rot << endl ;
85  abort() ;
86  }
87  if (mer_fix_omega < mer_change_omega) {
88  cout << "Star_rot_CFC::equilibrium: mer_fix_omega < mer_change_omega !"
89  << endl ;
90  cout << " mer_fix_omega = " << mer_fix_omega << endl ;
91  cout << " mer_change_omega = " << mer_change_omega << endl ;
92  abort() ;
93  }
94 
95  // In order to converge to a given baryon mass, shall the central
96  // enthalpy be varied or Omega ?
97  bool change_ent = true ;
98  if (mer_mass < 0) {
99  change_ent = false ;
100  mer_mass = abs(mer_mass) ;
101  }
102 
103 
104  double precis = control(0) ;
105  double omega_ini = control(1) ;
106  double relax = control(2) ;
107  double relax_prev = double(1) - relax ;
108 
109  // Error indicators
110  // ----------------
111 
112  diff.annule_hard() ;
113  double& diff_ent = diff.set(0) ;
114 
115  double alpha_r = 1 ;
116 
117  // Initializations
118  // ---------------
119 
120  // Initial angular velocities
121  omega = 0 ;
122 
123  double accrois_omega = (omega0 - omega_ini) /
124  double(mer_fix_omega - mer_change_omega) ;
125 
126 
127  update_metric() ; //update of the metric quantities
128 
129  equation_of_state() ; // update of the density, pressure,...etc
130 
131  hydro_euler() ; //update of the hydro quantities relative to the
132  // Eulerian observer
133 
134  // Quantities at the previous step :
135  Scalar ent_prev = ent ;
136  Scalar logn_prev = logn ;
137  Scalar psi_prev = psi ;
138  // Vector beta_prev = beta ;
139 
140  // Output files
141  // -------------
142 
143  ofstream fichconv("convergence.d") ; // Output file for diff_ent
144  fichconv << "# diff_ent GRV2 max_triax vit_triax" << endl ;
145 
146  ofstream fichfreq("frequency.d") ; // Output file for omega
147  fichfreq << "# f [Hz]" << endl ;
148 
149  ofstream fichevol("evolution.d") ; // Output file for various quantities
150  fichevol <<
151  "# |dH/dr_eq/dH/dr_pole| r_pole/r_eq ent_c"
152  << endl ;
153 
154  diff_ent = 1 ;
155  double err_grv2 = 1 ;
156 
157 
158 
159 //=========================================================================
160 // Start of iteration
161 //=========================================================================
162 
163  for(int mer=0 ; (diff_ent > precis) && (mer<mer_max) ; mer++) {
164 
165  cout << "-----------------------------------------------" << endl ;
166  cout << "step: " << mer << endl ;
167  cout << "diff_ent = " << display_bold << diff_ent << display_normal
168  << endl ;
169  cout << "err_grv2 = " << err_grv2 << endl ;
170  fichconv << mer ;
171  fichfreq << mer ;
172  fichevol << mer ;
173 
174 
175  // switch on rotation
176  if (mer >= mer_rot) {
177 
178  if (mer < mer_change_omega) {
179  omega = omega_ini ;
180  }
181  else {
182  if (mer <= mer_fix_omega) {
183  omega = omega_ini + accrois_omega *
184  (mer - mer_change_omega) ;
185  }
186  }
187 
188 
189  }
190 
191  //---------------------------------------------//
192  // Resolution of the Poisson equation for psi //
193  //---------------------------------------------//
194 
195  Scalar psi_new(mp) ;
196 
197  solve_psi( psi_new ) ;
198 
199  psi_new.std_spectral_base() ;
200 
201 
202  //---------------------------------------------------//
203  // Resolution of the Poisson equation for logn //
204  // Note: ln_f is due to the fluid part //
205  // ln_q is due to the quadratic metric part //
206  //---------------------------------------------------//
207 
208  Scalar ln_f_new(mp) ;
209  Scalar ln_q_new(mp) ;
210 
211  solve_logn_f( ln_f_new ) ;
212  solve_logn_q( ln_q_new ) ;
213 
214  ln_f_new.std_spectral_base() ;
215  ln_q_new.std_spectral_base() ;
216 
217 
218  //--------------------------------------------------//
219  // Resolution of the Poisson equation for shift //
220  //--------------------------------------------------//
221 
222  Vector beta_new(mp, CON, mp.get_bvect_spher()) ;
223 
224  solve_shift( beta_new ) ;
225 
226  //------------------------------------
227  // Determination of the fluid velocity
228  //------------------------------------
229 
230  if (mer > mer_fix_omega + delta_mer_kep) {
231 
232  omega *= fact_omega ; // Increase of the angular velocity if
233  } // fact_omega != 1
234 
235  bool omega_trop_grand = false ;
236  bool kepler = true ;
237 
238  while ( kepler ) {
239 
240  // Possible decrease of Omega to ensure a velocity < c
241 
242  bool superlum = true ;
243 
244  while ( superlum ){
245 
246  // New fluid velocity :
247  //
248 
249  u_euler.set(1).set_etat_zero() ;
250  u_euler.set(2).set_etat_zero() ;
251 
252  u_euler.set(3) = omega ;
253  u_euler.set(3).annule(nzet,nzm1) ; // nzet is defined in class Star
255  u_euler.set(3).mult_rsint() ;
256  u_euler.set(3) += beta(3) ;
257  u_euler.set(3).annule(nzet,nzm1) ;
258 
259  u_euler = u_euler / nn ;
260 
261 
262  // v2 (square of norm of u_euler)
263  // -------------------------------
264 
265  v2 = contract(contract(gamma.cov(), 0, u_euler, 0), 0, u_euler, 0) ;
266 
267  // Is the new velocity larger than c in the equatorial plane ?
268 
269  superlum = false ;
270 
271  for (int l=0; l<nzet; l++) {
272  for (int i=0; i<mg->get_nr(l); i++) {
273 
274  double u2 = v2.val_grid_point(l, 0, j_b, i) ;
275  if (u2 >= 1.) { // superluminal velocity
276  superlum = true ;
277  cout << "U > c for l, i : " << l << " " << i
278  << " U = " << sqrt( u2 ) << endl ;
279  }
280  }
281  }
282  if ( superlum ) {
283  cout << "**** VELOCITY OF LIGHT REACHED ****" << endl ;
284  omega /= fact_omega ; // Decrease of Omega
285  cout << "New rotation frequency : "
286  << omega/(2.*M_PI) * f_unit << " Hz" << endl ;
287  omega_trop_grand = true ;
288  }
289  } // end of while ( superlum )
290 
291 
292  // New computation of U (this time is not superluminal)
293  // as well as of gam_euler, ener_euler,...etc
294 
295  hydro_euler() ;
296 
297 
298 
299  //--------------------------------//
300  // First integral of motion //
301  //--------------------------------//
302 
303  Scalar mlngamma(mp) ; // -log( gam_euler )
304 
305  mlngamma = - log( gam_euler ) ;
306 
307  // Equatorial values of various potentials :
308  double ln_f_b = ln_f_new.val_grid_point(l_b, k_b, j_b, i_b) ;
309  double ln_q_b = ln_q_new.val_grid_point(l_b, k_b, j_b, i_b) ;
310  double mlngamma_b = mlngamma.val_grid_point(l_b, k_b, j_b, i_b) ;
311 
312  // Central values of various potentials :
313  double ln_f_c = ln_f_new.val_grid_point(0,0,0,0) ;
314  double ln_q_c = ln_q_new.val_grid_point(0,0,0,0) ;
315  double mlngamma_c = 0 ;
316 
317  // Scale factor to ensure that the (log of) enthalpy is equal to
318  // ent_b at the equator
319  double alpha_r2 = ( ent_c - ent_b + mlngamma_c - mlngamma_b
320  + ln_q_c - ln_q_b) / ( ln_f_b - ln_f_c ) ;
321 
322  alpha_r = sqrt(alpha_r2) ;
323 
324  cout << "alpha_r = " << alpha_r << endl ;
325 
326  // Rescaling of the grid (no adaptation!)
327  //---------------------------------------
328  mp.homothetie(alpha_r) ;
329 
330  // Readjustment of logn :
331  // -----------------------
332 
333  logn = alpha_r2 * ln_f_new + ln_q_new ;
334 
335  double logn_c = logn.val_grid_point(0,0,0,0) ;
336 
337  // First integral of motion -> (log of) enthalpy in all space
338  // ----------------------------------------------------------
339 
340  ent = (ent_c + logn_c + mlngamma_c) - logn - mlngamma ;
341 
342 
343  // --------------------------------------------------------------
344  // Test: is the enthalpy negative somewhere in the equatorial plane
345  // inside the star?
346  // --------------------------------------------------------
347 
348  kepler = false ;
349  for (int l=0; l<nzet; l++) {
350  int imax = mg->get_nr(l) - 1 ;
351  if (l == l_b) imax-- ; // The surface point is skipped
352  for (int i=0; i<imax; i++) {
353  if ( ent.val_grid_point(l, 0, j_b, i) < 0. ) {
354  kepler = true ;
355  cout << "ent < 0 for l, i : " << l << " " << i
356  << " ent = " << ent.val_grid_point(l, 0, j_b, i) << endl ;
357  }
358  }
359  }
360 
361  if ( kepler ) {
362  cout << "**** KEPLERIAN VELOCITY REACHED ****" << endl ;
363  omega /= fact_omega ; // Omega is decreased
364  cout << "New rotation frequency : "
365  << omega/(2.*M_PI) * f_unit << " Hz" << endl ;
366  omega_trop_grand = true ;
367  }
368 
369  } // End of while ( kepler )
370 
371  if ( omega_trop_grand ) { // fact_omega is decreased for the
372  // next step
373  fact_omega = sqrt( fact_omega ) ;
374  cout << "**** New fact_omega : " << fact_omega << endl ;
375  }
376 
377 
378 //---------------------------------
379  // Equation of state
380  //---------------------------------
381 
382  equation_of_state() ; // computes new values for nbar (n), ener (e),
383  // and press (p) from the new ent (H)
384 
385  hydro_euler() ;
386 
387  beta = beta_new ;
388 
389  //---------------------------------------
390  // Calculate error of the GRV2 identity
391  //---------------------------------------
392 
393  err_grv2 = grv2() ;
394 
395 
396  //--------------------------------------
397  // Relaxations on some quantities....?
398  //
399  //--------------------------------------
400 
401  if (mer >= 10) {
402  logn = relax * logn + relax_prev * logn_prev ;
403 
404  psi = relax * psi_new + relax_prev * psi_prev ;
405 
406  }
407 
408  // Update of the metric quantities :
409 
410  update_metric() ;
411 
412  //---------------------------
413  // Informations display
414  // More to come later......
415  //---------------------------
416 
417  // partial_display(cout) ; // What is partial_display(cout) ?
418  fichfreq << " " << omega / (2*M_PI) * f_unit ;
419  fichevol << " " << ent_c ;
420 
421 
422  //-----------------------------------------
423  // Convergence towards a given baryon mass
424  //-----------------------------------------
425 
426  if (mer > mer_mass) {
427 
428  double xx ;
429  if (mbar_wanted > 0.) {
430  xx = mass_b() / mbar_wanted - 1. ;
431  cout << "Discrep. baryon mass <-> wanted bar. mass : " << xx
432  << endl ;
433  }
434  else{
435  xx = mass_g() / fabs(mbar_wanted) - 1. ;
436  cout << "Discrep. grav. mass <-> wanted grav. mass : " << xx
437  << endl ;
438  }
439  double xprog = ( mer > 2*mer_mass) ? 1. :
440  double(mer-mer_mass)/double(mer_mass) ;
441  xx *= xprog ;
442  double ax = .5 * ( 2. + xx ) / (1. + xx ) ;
443  double fact = pow(ax, aexp_mass) ;
444  cout << " xprog, xx, ax, fact : " << xprog << " " <<
445  xx << " " << ax << " " << fact << endl ;
446 
447  if ( change_ent ) {
448  ent_c *= fact ;
449  }
450  else {
451  if (mer%4 == 0) omega *= fact ;
452  }
453  }
454 
455 
456  //-----------------------------------------------------------
457  // Relative change in enthalpy with respect to previous step
458  // ** Check: Is diffrel(ent, ent_prev) ok?
459  //-----------------------------------------------------------
460 
461  Tbl diff_ent_tbl = diffrel( ent, ent_prev ) ;
462  diff_ent = diff_ent_tbl(0) ;
463  for (int l=1; l<nzet; l++) {
464  diff_ent += diff_ent_tbl(l) ;
465  }
466  diff_ent /= nzet ;
467 
468  fichconv << " " << log10( fabs(diff_ent) + 1.e-16 ) ;
469  fichconv << " " << log10( fabs(err_grv2) + 1.e-16 ) ;
470 
471  //------------------------------
472  // Recycling for the next step
473  //------------------------------
474 
475  ent_prev = ent ;
476  logn_prev = logn ;
477  psi_prev = psi ;
478 
479  fichconv << endl ;
480  fichfreq << endl ;
481  fichevol << endl ;
482  fichconv.flush() ;
483  fichfreq.flush() ;
484  fichevol.flush() ;
485 
486 
487  } // End of main loop
488 
489  //=================================================
490  // End of iteration
491  //=================================================
492 
493  fichconv.close() ;
494  fichfreq.close() ;
495  fichevol.close() ;
496 
497 
498 }
499 }
Cmp log(const Cmp &)
Neperian logarithm.
Definition: cmp_math.C:299
Map & mp
Mapping associated with the star.
Definition: star.h:180
Cmp sqrt(const Cmp &)
Square root.
Definition: cmp_math.C:223
void solve_logn_q(Scalar &ln_q_new) const
Solution of the quadratic part of the Poisson equation for the lapse for rotating stars in CFC...
virtual void set_etat_zero()
Sets the logical state to ETATZERO (zero).
Definition: scalar.C:330
virtual void annule(int l_min, int l_max)
Sets the Scalar to zero in several domains.
Definition: scalar.C:397
Metric gamma
3-metric
Definition: star.h:235
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
Lorene prototypes.
Definition: app_hor.h:67
Standard units of space, time and mass.
const Mg3d * get_mg() const
Gives the Mg3d on which the mapping is defined.
Definition: map.h:783
double & set(int i)
Read/write of a particular element (index i) (1D case)
Definition: tbl.h:301
Tensor field of valence 0 (or component of a tensorial field).
Definition: scalar.h:393
int get_type_t() const
Returns the type of sampling in the direction: SYM : : symmetry with respect to the equatorial pl...
Definition: grilles.h:502
Basic integer array class.
Definition: itbl.h:122
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
Scalar ent
Log-enthalpy.
Definition: star.h:190
Vector beta
Shift vector.
Definition: star.h:228
Tensor field of valence 1.
Definition: vector.h:188
Tbl diffrel(const Cmp &a, const Cmp &b)
Relative difference between two Cmp (norme version).
Definition: cmp_math.C:507
double val_grid_point(int l, int k, int j, int i) const
Returns the value of the field at a specified grid point.
Definition: scalar.h:643
int nzet
Number of domains of *mp occupied by the star.
Definition: star.h:183
virtual void hydro_euler()
Computes the hydrodynamical quantities relative to the Eulerian observer from those in the fluid fram...
Scalar gam_euler
Lorentz factor between the fluid and Eulerian observers.
Definition: star.h:204
double omega
Rotation angular velocity ([f_unit] )
Definition: star_rot_cfc.h:60
virtual void homothetie(double lambda)=0
Sets a new radial scale.
void solve_shift(Vector &shift_new) const
Solution of the shift equation for rotating stars in CFC.
int get_nzone() const
Returns the number of domains.
Definition: grilles.h:465
virtual double mass_b() const
Baryonic mass.
Vector u_euler
Fluid 3-velocity with respect to the Eulerian observer.
Definition: star.h:207
void mult_rsint()
Multiplication by everywhere; dzpuis is not changed.
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 .
Scalar logn
Logarithm of the lapse N .
Definition: star.h:222
void solve_logn_f(Scalar &ln_f_new) const
Solution of the `‘matter’&#39; part of the Poisson equation for the lapse for rotating stars in CFC...
int get_nr(int l) const
Returns the number of points in the radial direction ( ) in domain no. l.
Definition: grilles.h:469
void solve_psi(Scalar &psi_new)
Solution of the equations for the conformal factor for rotating stars in CFC.
virtual const Sym_tensor & cov() const
Read-only access to the covariant representation.
Definition: metric.C:283
Multi-domain grid.
Definition: grilles.h:279
Scalar nn
Lapse function N .
Definition: star.h:225
Cmp log10(const Cmp &)
Basis 10 logarithm.
Definition: cmp_math.C:325
void equilibrium(double ent_c, double omega0, double fact_omega, int nzadapt, const Tbl &ent_limit, const Itbl &icontrol, const Tbl &control, double mbar_wanted, double aexp_mass, Tbl &diff)
Computes an equilibrium configuration.
Cmp abs(const Cmp &)
Absolute value.
Definition: cmp_math.C:413
Basic array class.
Definition: tbl.h:164
int get_nt(int l) const
Returns the number of points in the co-latitude direction ( ) in domain no. l.
Definition: grilles.h:474
Scalar & set(int)
Read/write access to a component.
Definition: vector.C:302
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.
void annule_hard()
Sets the Tbl to zero in a hard way.
Definition: tbl.C:375
virtual double mass_g() const
Gravitational mass.