81 #include "utilitaires.h" 86 int nzadapt,
const Tbl& ent_limit,
const Itbl& icontrol,
87 const Tbl& control,
double mbar_wanted,
88 double aexp_mass,
Tbl& diff,
Param*) {
97 char display_bold[]=
"x[1m" ; display_bold[0] = 27 ;
98 char display_normal[] =
"x[0m" ; display_normal[0] = 27 ;
113 int i_b = mg->
get_nr(l_b) - 1 ;
114 int j_b = mg->
get_nt(l_b) - 1 ;
118 double ent_b = ent_limit(
nzet-1) ;
123 int mer_max = icontrol(0) ;
124 int mer_rot = icontrol(1) ;
125 int mer_change_omega = icontrol(2) ;
126 int mer_fix_omega = icontrol(3) ;
127 int mer_mass = icontrol(4) ;
128 int mermax_poisson = icontrol(5) ;
129 int mer_triax = icontrol(6) ;
130 int delta_mer_kep = icontrol(7) ;
133 if (mer_change_omega < mer_rot) {
134 cout <<
"Star_rot::equilibrium: mer_change_omega < mer_rot !" << endl ;
135 cout <<
" mer_change_omega = " << mer_change_omega << endl ;
136 cout <<
" mer_rot = " << mer_rot << endl ;
139 if (mer_fix_omega < mer_change_omega) {
140 cout <<
"Star_rot::equilibrium: mer_fix_omega < mer_change_omega !" 142 cout <<
" mer_fix_omega = " << mer_fix_omega << endl ;
143 cout <<
" mer_change_omega = " << mer_change_omega << endl ;
149 bool change_ent = true ;
152 mer_mass =
abs(mer_mass) ;
155 double precis = control(0) ;
156 double omega_ini = control(1) ;
157 double relax = control(2) ;
158 double relax_prev = double(1) - relax ;
159 double relax_poisson = control(3) ;
160 double thres_adapt = control(4) ;
161 double ampli_triax = control(5) ;
162 double precis_adapt = control(6) ;
169 double& diff_ent = diff.
set(0) ;
170 double& diff_nuf = diff.
set(1) ;
171 double& diff_nuq = diff.
set(2) ;
174 double& diff_shift_x = diff.
set(5) ;
175 double& diff_shift_y = diff.
set(6) ;
176 double& vit_triax = diff.
set(7) ;
187 int nz_search =
nzet + 1 ;
190 double reg_map = 1. ;
192 par_adapt.
add_int(nitermax, 0) ;
194 par_adapt.
add_int(nzadapt, 1) ;
197 par_adapt.
add_int(nz_search, 2) ;
199 par_adapt.
add_int(adapt_flag, 3) ;
218 par_adapt.
add_tbl(ent_limit, 0) ;
224 double precis_poisson = 1.e-16 ;
230 for (
int i=1; i<=3; i++) {
236 for (
int i=1; i<=3; i++) {
237 cshift.set(i-1) = -
beta(i) ;
242 for (
int i=1; i<=3; i++) {
243 cw_shift.set(i-1) =
w_shift(i) ;
250 Param par_poisson_nuf ;
251 par_poisson_nuf.
add_int(mermax_poisson, 0) ;
252 par_poisson_nuf.
add_double(relax_poisson, 0) ;
253 par_poisson_nuf.
add_double(precis_poisson, 1) ;
257 Param par_poisson_nuq ;
258 par_poisson_nuq.
add_int(mermax_poisson, 0) ;
259 par_poisson_nuq.
add_double(relax_poisson, 0) ;
260 par_poisson_nuq.
add_double(precis_poisson, 1) ;
264 Param par_poisson_tggg ;
265 par_poisson_tggg.
add_int(mermax_poisson, 0) ;
266 par_poisson_tggg.
add_double(relax_poisson, 0) ;
267 par_poisson_tggg.
add_double(precis_poisson, 1) ;
273 Param par_poisson_dzeta ;
280 Param par_poisson_vect ;
282 par_poisson_vect.
add_int(mermax_poisson, 0) ;
283 par_poisson_vect.
add_double(relax_poisson, 0) ;
284 par_poisson_vect.
add_double(precis_poisson, 1) ;
296 double accrois_omega = (omega0 - omega_ini) /
297 double(mer_fix_omega - mer_change_omega) ;
324 ofstream fichconv(
"convergence.d") ;
325 fichconv <<
"# diff_ent GRV2 max_triax vit_triax" << endl ;
327 ofstream fichfreq(
"frequency.d") ;
328 fichfreq <<
"# f [Hz]" << endl ;
330 ofstream fichevol(
"evolution.d") ;
332 "# |dH/dr_eq/dH/dr_pole| r_pole/r_eq ent_c" 336 double err_grv2 = 1 ;
337 double max_triax_prev = 0 ;
343 for(
int mer=0 ; (diff_ent > precis) && (mer<mer_max) ; mer++ ) {
345 cout <<
"-----------------------------------------------" << endl ;
346 cout <<
"step: " << mer << endl ;
347 cout <<
"diff_ent = " << display_bold << diff_ent << display_normal
349 cout <<
"err_grv2 = " << err_grv2 << endl ;
354 if (mer >= mer_rot) {
356 if (mer < mer_change_omega) {
360 if (mer <= mer_fix_omega) {
361 omega = omega_ini + accrois_omega *
362 (mer - mer_change_omega) ;
383 source_nuq =
ak_car - d_logn(1)*(d_logn(1)+d_bet(1))
384 - d_logn(2)*(d_logn(2)+d_bet(2))
385 - d_logn(3)*(d_logn(3)+d_bet(3)) ;
388 source_nuf = qpig *
nbar ;
401 - d_logn(1)*d_logn(1) - d_logn(2)*d_logn(2) - d_logn(3)*d_logn(3) ;
435 cout <<
"Test of the Poisson equation for nuf :" << endl ;
437 diff_nuf = err(0, 0) ;
443 if (mer == mer_triax) {
445 if ( mg->
get_np(0) == 1 ) {
447 "Star_rot::equilibrium: np must be stricly greater than 1" 448 << endl <<
" to set a triaxial perturbation !" << endl ;
455 perturb = 1 + ampli_triax * sint*sint *
cos(2*phi) ;
469 double max_triax = 0 ;
471 if ( mg->
get_np(0) > 1 ) {
473 for (
int l=0; l<nz; l++) {
474 for (
int j=0; j<mg->
get_nt(l); j++) {
475 for (
int i=0; i<mg->
get_nr(l); i++) {
478 double xcos2p = (*(va_nuf.
c_cf))(l, 2, j, i) ;
481 double xsin2p = (*(va_nuf.
c_cf))(l, 3, j, i) ;
483 double xx =
sqrt( xcos2p*xcos2p + xsin2p*xsin2p ) ;
485 max_triax = ( xx > max_triax ) ? xx : max_triax ;
492 cout <<
"Triaxial part of nuf : " << max_triax << endl ;
502 cout <<
"Test of the Poisson equation for nuq :" << endl ;
504 diff_nuq = err(0, 0) ;
511 for (
int i=1; i<=3; i++) {
512 if(source_shift(i).get_etat() != ETATZERO) {
513 if(source_shift(i).dz_nonzero()) {
514 assert( source_shift(i).get_dzpuis() == 4 ) ;
517 (source_shift.set(i)).set_dzpuis(4) ;
522 double lambda_shift = double(1) / double(3) ;
524 if ( mg->
get_np(0) == 1 ) {
530 for (
int i=1; i<=3; i++) {
531 csource_shift.set(i-1) = source_shift(i) ;
533 csource_shift.set(2).set_etat_zero() ;
535 csource_shift.poisson_vect(lambda_shift, par_poisson_vect,
536 cshift, cw_shift, ckhi_shift) ;
538 for (
int i=1; i<=3; i++) {
545 cout <<
"Test of the Poisson equation for shift_x :" << endl ;
546 err = source_shift(1).test_poisson(-
beta(1), cout,
true) ;
547 diff_shift_x = err(0, 0) ;
549 cout <<
"Test of the Poisson equation for shift_y :" << endl ;
550 err = source_shift(2).test_poisson(-
beta(2), cout,
true) ;
551 diff_shift_y = err(0, 0) ;
565 if (mer > mer_fix_omega + delta_mer_kep) {
567 omega *= fact_omega ;
570 bool omega_trop_grand = false ;
577 bool superlum = true ;
600 for (
int l=0; l<
nzet; l++) {
601 for (
int i=0; i<mg->
get_nr(l); i++) {
606 cout <<
"U > c for l, i : " << l <<
" " << i
607 <<
" U = " << u1 << endl ;
612 cout <<
"**** VELOCITY OF LIGHT REACHED ****" << endl ;
613 if (fact_omega == 1.)
throw true ;
615 omega /= fact_omega ;
616 cout <<
"New rotation frequency : " 617 <<
omega/(2.*M_PI) * f_unit <<
" Hz" << endl ;
618 omega_trop_grand = true ;
640 mlngamma = - 0.5 *
uuu*
uuu ;
646 double mlngamma_b = mlngamma.val_grid_point(l_b, k_b, j_b, i_b) ;
651 double mlngamma_c = 0 ;
655 double alpha_r2 = ( ent_c - ent_b + mlngamma_c - mlngamma_b
656 + nuq_c - nuq_b) / ( nuf_b - nuf_c ) ;
657 alpha_r =
sqrt(alpha_r2) ;
658 cout <<
"alpha_r = " << alpha_r << endl ;
669 ent = (ent_c + nu_c + mlngamma_c) -
logn - mlngamma ;
676 for (
int l=0; l<
nzet; l++) {
677 int imax = mg->
get_nr(l) - 1 ;
678 if (l == l_b) imax-- ;
679 for (
int i=0; i<imax; i++) {
682 cout <<
"ent < 0 for l, i : " << l <<
" " << i
689 cout <<
"**** KEPLERIAN VELOCITY REACHED ****" << endl ;
690 if (fact_omega == 1.)
throw true ;
692 omega /= fact_omega ;
693 cout <<
"New rotation frequency : " 694 <<
omega/(2.*M_PI) * f_unit <<
" Hz" << endl ;
695 omega_trop_grand = true ;
701 if ( omega_trop_grand ) {
703 fact_omega =
sqrt( fact_omega ) ;
704 cout <<
"**** New fact_omega : " << fact_omega << endl ;
716 double rap_dent = fabs( dent_eq / dent_pole ) ;
717 cout <<
"| dH/dr_eq / dH/dr_pole | = " << rap_dent << endl ;
719 if ( rap_dent < thres_adapt ) {
721 cout <<
"******* FROZEN MAPPING *********" << endl ;
767 Cmp csource_tggg(source_tggg) ;
778 Cmp csource_dzf(source_dzf) ;
779 Cmp csource_dzq(source_dzq) ;
781 mp.
poisson2d(csource_dzf, csource_dzq, par_poisson_dzeta,
785 err_grv2 = lbda_grv2 - 1;
786 cout <<
"GRV2: " << err_grv2 << endl ;
801 logn = relax *
logn + relax_prev * logn_prev ;
803 dzeta = relax *
dzeta + relax_prev * dzeta_prev ;
815 fichfreq <<
" " << setprecision(16) <<
omega / (2*M_PI) * f_unit ;
816 fichevol <<
" " << setprecision(16) << rap_dent ;
818 fichevol <<
" " << setprecision(16) << ent_c ;
824 if (mer > mer_mass) {
827 if (mbar_wanted > 0.) {
828 xx =
mass_b() / mbar_wanted - 1. ;
829 cout <<
"Discrep. baryon mass <-> wanted bar. mass : " << xx
833 xx =
mass_g() / fabs(mbar_wanted) - 1. ;
834 cout <<
"Discrep. grav. mass <-> wanted grav. mass : " << xx
837 double xprog = ( mer > 2*mer_mass) ? 1. :
838 double(mer-mer_mass)/double(mer_mass) ;
840 double ax = .5 * ( 2. + xx ) / (1. + xx ) ;
841 double fact =
pow(ax, aexp_mass) ;
842 cout <<
" xprog, xx, ax, fact : " << xprog <<
" " <<
843 xx <<
" " << ax <<
" " << fact << endl ;
849 if (mer%4 == 0)
omega *= fact ;
859 diff_ent = diff_ent_tbl(0) ;
860 for (
int l=1; l<
nzet; l++) {
861 diff_ent += diff_ent_tbl(l) ;
865 fichconv <<
" " <<
log10( fabs(diff_ent) + 1.e-16 ) ;
866 fichconv <<
" " <<
log10( fabs(err_grv2) + 1.e-16 ) ;
867 fichconv <<
" " <<
log10( fabs(max_triax) + 1.e-16 ) ;
870 if ( (mer > mer_triax+1) && (max_triax_prev > 1e-13) ) {
871 vit_triax = (max_triax - max_triax_prev) / max_triax_prev ;
874 fichconv <<
" " << vit_triax ;
883 max_triax_prev = max_triax ;
900 for (
int i=1; i<=3; i++) {
virtual 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, Param *=0x0)
Computes an equilibrium configuration.
virtual double mass_g() const
Gravitational mass.
void annule_domain(int l)
Sets the Tensor to zero in a given domain.
Cmp log(const Cmp &)
Neperian logarithm.
Mtbl_cf * c_cf
Coefficients of the spectral expansion of the function.
void add_tenseur_mod(Tenseur &ti, int position=0)
Adds the address of a new modifiable Tenseur to the list.
Vector ssjm1_wshift
Effective source at the previous step for the resolution of the vector Poisson equation for ...
Scalar dzeta
Metric potential .
Component of a tensorial field *** DEPRECATED : use class Scalar instead ***.
Scalar a_car
Square of the metric factor A.
Radial mapping of rather general form.
void add_int(const int &n, int position=0)
Adds the address of a new int to the list.
Map & mp
Mapping associated with the star.
Scalar nuf
Part of the Metric potential = logn generated by the matter terms.
const Cmp & cmp_zero() const
Returns the null Cmp defined on *this.
int get_np(int l) const
Returns the number of points in the azimuthal direction ( ) in domain no. l.
void coef() const
Computes the coeffcients of *this.
Cmp sqrt(const Cmp &)
Square root.
Scalar khi_shift
Scalar used in the decomposition of shift , following Shibata's prescription [Prog.
bool relativistic
Indicator of relativity: true for a relativistic star, false for a Newtonian one. ...
Scalar bbb
Metric factor B.
Standard units of space, time and mass.
Tensor up(int ind, const Metric &gam) const
Computes a new tensor by raising an index of *this.
const Mg3d * get_mg() const
Gives the Mg3d on which the mapping is defined.
double & set(int i)
Read/write of a particular element (index i) (1D case)
Tensor field of valence 0 (or component of a tensorial field).
Scalar poisson() const
Solves the scalar Poisson equation with *this as a source.
virtual double grv2() const
Error on the virial identity GRV2.
virtual void hydro_euler()
Computes the hydrodynamical quantities relative to the Eulerian observer from those in the fluid fram...
virtual void adapt(const Cmp &ent, const Param &par, int nbr=0)=0
Adaptation of the mapping to a given scalar field.
int get_type_t() const
Returns the type of sampling in the direction: SYM : : symmetry with respect to the equatorial pl...
Basic integer array class.
virtual void std_spectral_base()
Sets the spectral bases of the Valeur va to the standard ones for a scalar field. ...
void update_metric()
Computes metric coefficients from known potentials.
Values and coefficients of a (real-value) function.
Scalar nuq
Part of the Metric potential = logn generated by the quadratic terms.
double omega
Rotation angular velocity ([f_unit] )
Scalar nbar
Baryon density in the fluid frame.
virtual void change_triad(const Base_vect &)
Sets a new vectorial basis (triad) of decomposition and modifies the components accordingly.
int get_etat() const
Returns the logical state ETATNONDEF (undefined), ETATZERO (null) or ETATQCQ (ordinary).
Scalar s_euler
Trace of the stress scalar in the Eulerian frame.
Tbl test_poisson(const Scalar &uu, ostream &ostr, bool detail=false) const
Checks if a Poisson equation with *this as a source has been correctly solved.
const Vector & derive_con(const Metric &gam) const
Returns the "contravariant" derivative of *this with respect to some metric , by raising the index of...
Tensor field of valence 1.
Cmp cos(const Cmp &)
Cosine.
const Metric_flat & flat_met_cart() const
Returns the flat metric associated with the Cartesian coordinates and with components expressed in th...
Tbl diffrel(const Cmp &a, const Cmp &b)
Relative difference between two Cmp (norme version).
Scalar ssjm1_tggg
Effective source at the previous step for the resolution of the Poisson equation for tggg ...
void set_dzpuis(int)
Modifies the dzpuis flag.
void add_double_mod(double &x, int position=0)
Adds the address of a new modifiable double to the list.
double val_grid_point(int l, int k, int j, int i) const
Returns the value of the field at a specified grid point.
Coord phi
coordinate centered on the grid
void set_etat_qcq()
Sets the logical state to ETATQCQ (ordinary state).
int nzet
Number of domains of *mp occupied by the star.
Scalar nphi
Metric coefficient .
Scalar gam_euler
Lorentz factor between the fluid and Eulerian observers.
Cmp & set()
Read/write for a scalar (see also operator=(const Cmp&) ).
virtual void poisson2d(const Cmp &source_mat, const Cmp &source_quad, Param &par, Cmp &uu) const =0
Computes the solution of a 2-D Poisson equation.
Scalar press
Fluid pressure.
virtual double mass_b() const
Baryon mass.
Scalar ssjm1_nuq
Effective source at the previous step for the resolution of the Poisson equation for nuq by means of ...
void add_tbl(const Tbl &ti, int position=0)
Adds the address of a new Tbl to the list.
int get_nzone() const
Returns the number of domains.
virtual void homothetie(double lambda)
Sets a new radial scale.
Vector u_euler
Fluid 3-velocity with respect to the Eulerian observer.
Sym_tensor tkij
Tensor related to the extrinsic curvature tensor by .
void mult_rsint()
Multiplication by everywhere; dzpuis is not changed.
Cmp pow(const Cmp &, int)
Power .
Tenseur contract(const Tenseur &, int id1, int id2)
Self contraction of two indices of a Tenseur .
Scalar logn
Logarithm of the lapse N .
Active physical coordinates and mapping derivatives.
double ray_pole() const
Coordinate radius at [r_unit].
int get_nr(int l) const
Returns the number of points in the radial direction ( ) in domain no. l.
virtual void partial_display(ostream &) const
Printing of some informations, excluding all global quantities.
void add_scalar_mod(Scalar &ti, int position=0)
Adds the address of a new modifiable Scalar to the list.
const Base_vect_cart & get_bvect_cart() const
Returns the Cartesian basis associated with the coordinates (x,y,z) of the mapping, i.e.
Scalar nn
Lapse function N .
Cmp log10(const Cmp &)
Basis 10 logarithm.
Cmp abs(const Cmp &)
Absolute value.
Scalar ssjm1_khi
Effective source at the previous step for the resolution of the Poisson equation for the scalar by m...
Scalar uuu
Norm of u_euler.
virtual void reevaluate(const Map *mp_prev, int nzet, Cmp &uu) const =0
Recomputes the values of a Cmp at the collocation points after a change in the mapping.
void add_double(const double &x, int position=0)
Adds the the address of a new double to the list.
double ray_eq() const
Coordinate radius at , [r_unit].
const Scalar & dsdr() const
Returns of *this .
Scalar ssjm1_nuf
Effective source at the previous step for the resolution of the Poisson equation for nuf by means of ...
int get_nt(int l) const
Returns the number of points in the co-latitude direction ( ) in domain no. l.
Valeur & set_spectral_va()
Returns va (read/write version)
Scalar & set(int)
Read/write access to a component.
void set_etat_qcq()
Sets the logical state to ETATQCQ (ordinary state).
void add_cmp_mod(Cmp &ti, int position=0)
Adds the address of a new modifiable Cmp to the list.
Scalar tggg
Metric potential .
void equation_of_state()
Computes the proper baryon and energy density, as well as pressure from the enthalpy.
void fait_nphi()
Computes tnphi and nphi from the Cartesian components of the shift, stored in shift ...
const Vector & derive_cov(const Metric &gam) const
Returns the gradient (1-form = covariant vector) of *this
Vector w_shift
Vector used in the decomposition of shift , following Shibata's prescription [Prog.
Scalar ener_euler
Total energy density in the Eulerian frame.
const Metric_flat & flat_met_spher() const
Returns the flat metric associated with the spherical coordinates and with components expressed in th...
Tensor handling *** DEPRECATED : use class Tensor instead ***.
void add_int_mod(int &n, int position=0)
Adds the address of a new modifiable int to the list.
const Valeur & get_spectral_va() const
Returns va (read only version)