32char et_rot_mag_equil_C[] =
"$Header: /cvsroot/Lorene/C++/Source/Etoile/et_rot_mag_equil.C,v 1.21 2014/10/13 08:52:58 j_novak Exp $" ;
109#include "et_rot_mag.h"
115 double fact_omega,
int nzadapt,
const Tbl& ent_limit,
116 const Itbl& icontrol,
const Tbl& control,
double mbar_wanted,
117 double aexp_mass,
Tbl& diff,
const double Q0,
const double a_j0,
118 Cmp (*f_j)(
const Cmp&,
const double),
119 Cmp (*M_j)(
const Cmp& x,
const double)) {
127 char display_bold[]=
"x[1m" ; display_bold[0] = 27 ;
128 char display_normal[] =
"x[0m" ; display_normal[0] = 27 ;
143 int i_b = mg->
get_nr(l_b) - 1 ;
144 int j_b = mg->
get_nt(l_b) - 1 ;
148 double ent_b = ent_limit(
nzet-1) ;
153 int mer_max = icontrol(0) ;
154 int mer_rot = icontrol(1) ;
155 int mer_change_omega = icontrol(2) ;
156 int mer_fix_omega = icontrol(3) ;
157 int mer_mass = icontrol(4) ;
158 int mermax_poisson = icontrol(5) ;
159 int delta_mer_kep = icontrol(6) ;
160 int mer_mag = icontrol(7) ;
161 int mer_change_mag = icontrol(8) ;
162 int mer_fix_mag = icontrol(9) ;
163 int mag_filter = icontrol(10) ;
166 if (mer_change_omega < mer_rot) {
167 cout <<
"Etoile_rot::equilibrium: mer_change_omega < mer_rot !" << endl ;
168 cout <<
" mer_change_omega = " << mer_change_omega << endl ;
169 cout <<
" mer_rot = " << mer_rot << endl ;
172 if (mer_fix_omega < mer_change_omega) {
173 cout <<
"Etoile_rot::equilibrium: mer_fix_omega < mer_change_omega !"
175 cout <<
" mer_fix_omega = " << mer_fix_omega << endl ;
176 cout <<
" mer_change_omega = " << mer_change_omega << endl ;
182 bool change_ent = true ;
185 mer_mass =
abs(mer_mass) ;
188 double precis = control(0) ;
189 double omega_ini = control(1) ;
190 double relax = control(2) ;
191 double relax_prev = double(1) - relax ;
192 double relax_poisson = control(3) ;
193 double thres_adapt = control(4) ;
194 double precis_adapt = control(5) ;
195 double Q_ini = control(6) ;
196 double a_j_ini = control (7) ;
202 double& diff_ent = diff.
set(0) ;
213 int nz_search =
nzet + 1 ;
216 double reg_map = 1. ;
218 par_adapt.
add_int(nitermax, 0) ;
220 par_adapt.
add_int(nzadapt, 1) ;
223 par_adapt.
add_int(nz_search, 2) ;
225 par_adapt.
add_int(adapt_flag, 3) ;
244 par_adapt.
add_tbl(ent_limit, 0) ;
250 double precis_poisson = 1.e-16 ;
252 Param par_poisson_nuf ;
253 par_poisson_nuf.
add_int(mermax_poisson, 0) ;
254 par_poisson_nuf.
add_double(relax_poisson, 0) ;
255 par_poisson_nuf.
add_double(precis_poisson, 1) ;
259 Param par_poisson_nuq ;
260 par_poisson_nuq.
add_int(mermax_poisson, 0) ;
261 par_poisson_nuq.
add_double(relax_poisson, 0) ;
262 par_poisson_nuq.
add_double(precis_poisson, 1) ;
266 Param par_poisson_tggg ;
267 par_poisson_tggg.
add_int(mermax_poisson, 0) ;
268 par_poisson_tggg.
add_double(relax_poisson, 0) ;
269 par_poisson_tggg.
add_double(precis_poisson, 1) ;
275 Param par_poisson_dzeta ;
282 Param par_poisson_vect ;
284 par_poisson_vect.
add_int(mermax_poisson, 0) ;
285 par_poisson_vect.
add_double(relax_poisson, 0) ;
286 par_poisson_vect.
add_double(precis_poisson, 1) ;
295 Param par_poisson_At ;
298 par_poisson_At.
add_int(mermax_poisson, 0) ;
300 par_poisson_At.
add_double(precis_poisson, 1) ;
303 par_poisson_At.
add_int(mag_filter, 1) ;
305 Param par_poisson_Avect ;
310 par_poisson_Avect.
add_int(mermax_poisson, 0) ;
311 par_poisson_Avect.
add_double(relax_poisson, 0) ;
312 par_poisson_Avect.
add_double(precis_poisson, 1) ;
316 par_poisson_Avect.
add_int(mag_filter, 1) ;
327 double accrois_omega = (omega0 - omega_ini) /
328 double(mer_fix_omega - mer_change_omega) ;
329 double accrois_Q = (Q0 - Q_ini) /
330 double(mer_fix_mag - mer_change_mag);
331 double accrois_a_j = (a_j0 - a_j_ini) /
332 double(mer_fix_mag - mer_change_mag);
384 ofstream fichconv(
"convergence.d") ;
385 fichconv <<
"# diff_ent GRV2 " << endl ;
387 ofstream fichfreq(
"frequency.d") ;
388 fichfreq <<
"# f [Hz]" << endl ;
390 ofstream fichevol(
"evolution.d") ;
392 "# |dH/dr_eq/dH/dr_pole| r_pole/r_eq ent_c"
396 double err_grv2 = 1 ;
402 for(
int mer=0 ; (diff_ent > precis) && (mer<mer_max) ; mer++ ) {
404 cout <<
"-----------------------------------------------" << endl ;
405 cout <<
"step: " << mer << endl ;
406 cout <<
"diff_ent = " << display_bold << diff_ent << display_normal
408 cout <<
"err_grv2 = " << err_grv2 << endl ;
413 if (mer >= mer_rot) {
415 if (mer < mer_change_omega) {
419 if (mer <= mer_fix_omega) {
420 omega = omega_ini + accrois_omega *
421 (mer - mer_change_omega) ;
427 if (mer >= mer_mag) {
428 if (mer < mer_change_mag) {
433 if (mer <= mer_fix_mag) {
434 Q = Q_ini + accrois_Q * (mer - mer_change_mag) ;
435 a_j = a_j_ini + accrois_a_j * (mer - mer_change_mag) ;
445 f_j, par_poisson_At, par_poisson_Avect) ;
466 source_nuf = qpig *
nbar ;
488 (source_tggg.
set()).mult_rsint() ;
523 for (
int i=0; i<3; i++) {
524 source_shift.
set(i) += squad(i) ;
528 if (source_shift.
get_etat() == ETATZERO) {
530 for (
int i=0; i<3; i++) {
531 source_shift.
set(i) = mtmp(i) ;
536 for (
int i=0; i<3; i++)
537 source_shift.
set(i) += mtmp(i) ;
546 source_nuf().poisson(par_poisson_nuf,
nuf.
set()) ;
554 source_nuq().poisson(par_poisson_nuq,
nuq.
set()) ;
561 if (source_shift.
get_etat() != ETATZERO) {
563 for (
int i=0; i<3; i++) {
564 if(source_shift(i).dz_nonzero()) {
565 assert( source_shift(i).get_dzpuis() == 4 ) ;
568 (source_shift.
set(i)).set_dzpuis(4) ;
576 double lambda_shift = double(1) / double(3) ;
578 if ( mg->
get_np(0) == 1 ) {
582 source_shift.
poisson_vect(lambda_shift, par_poisson_vect,
602 if (mer > mer_fix_omega + delta_mer_kep) {
604 omega *= fact_omega ;
607 bool omega_trop_grand = false ;
614 bool superlum = true ;
630 ((
uuu.
set()).va).set_base( (tmp.
va).base ) ;
638 for (
int l=0; l<
nzet; l++) {
639 for (
int i=0; i<mg->
get_nr(l); i++) {
641 double u1 =
uuu()(l, 0, j_b, i) ;
644 cout <<
"U > c for l, i : " << l <<
" " << i
645 <<
" U = " << u1 << endl ;
650 cout <<
"**** VELOCITY OF LIGHT REACHED ****" << endl ;
651 omega /= fact_omega ;
652 cout <<
"New rotation frequency : "
653 <<
omega/(2.*M_PI) * f_unit <<
" Hz" << endl ;
654 omega_trop_grand = true ;
675 mlngamma = - 0.5 *
uuu*
uuu ;
685 double nuf_b =
nuf()(l_b, k_b, j_b, i_b) ;
686 double nuq_b =
nuq()(l_b, k_b, j_b, i_b) ;
687 double mlngamma_b = mlngamma()(l_b, k_b, j_b, i_b) ;
688 double mag_b = mag()(l_b, k_b, j_b, i_b) ;
691 double nuf_c =
nuf()(0,0,0,0) ;
692 double nuq_c =
nuq()(0,0,0,0) ;
693 double mlngamma_c = 0 ;
694 double mag_c = mag()(0,0,0,0) ;
698 double alpha_r2 = ( ent_c - ent_b + mlngamma_c - mlngamma_b
699 + nuq_c - nuq_b + mag_c - mag_b)
700 / ( nuf_b - nuf_c ) ;
701 alpha_r =
sqrt(alpha_r2) ;
702 cout <<
"alpha_r = " << alpha_r << endl ;
708 double nu_c =
logn()(0,0,0,0) ;
713 ent = (ent_c + nu_c + mlngamma_c + mag_c) -
logn - mlngamma
721 for (
int l=0; l<
nzet; l++) {
722 int imax = mg->
get_nr(l) - 1 ;
723 if (l == l_b) imax-- ;
724 for (
int i=0; i<imax; i++) {
725 if (
ent()(l, 0, j_b, i) < 0. ) {
727 cout <<
"ent < 0 for l, i : " << l <<
" " << i
728 <<
" ent = " <<
ent()(l, 0, j_b, i) << endl ;
734 cout <<
"**** KEPLERIAN VELOCITY REACHED ****" << endl ;
735 omega /= fact_omega ;
736 cout <<
"New rotation frequency : "
737 <<
omega/(2.*M_PI) * f_unit <<
" Hz" << endl ;
738 omega_trop_grand = true ;
743 if ( omega_trop_grand ) {
745 fact_omega =
sqrt( fact_omega ) ;
746 cout <<
"**** New fact_omega : " << fact_omega << endl ;
756 double dent_eq =
ent().dsdr()(l_b, k_b, j_b, i_b) ;
757 double dent_pole =
ent().dsdr()(l_b, k_b, 0, i_b) ;
758 double rap_dent = fabs( dent_eq / dent_pole ) ;
759 cout <<
"| dH/dr_eq / dH/dr_pole | = " << rap_dent << endl ;
761 if ( rap_dent < thres_adapt ) {
763 cout <<
"******* FROZEN MAPPING *********" << endl ;
814 mp.
poisson2d(source_dzf(), source_dzq(), par_poisson_dzeta,
817 err_grv2 = lbda_grv2 - 1;
818 cout <<
"GRV2: " << err_grv2 << endl ;
833 logn = relax *
logn + relax_prev * logn_prev ;
835 dzeta = relax *
dzeta + relax_prev * dzeta_prev ;
847 fichfreq <<
" " <<
omega / (2*M_PI) * f_unit ;
848 fichevol <<
" " << rap_dent ;
850 fichevol <<
" " << ent_c ;
856 if (mer > mer_mass) {
859 if (mbar_wanted > 0.) {
860 xx =
mass_b() / mbar_wanted - 1. ;
861 cout <<
"Discrep. baryon mass <-> wanted bar. mass : " << xx
865 xx =
mass_g() / fabs(mbar_wanted) - 1. ;
866 cout <<
"Discrep. grav. mass <-> wanted grav. mass : " << xx
869 double xprog = ( mer > 2*mer_mass) ? 1. :
870 double(mer-mer_mass)/double(mer_mass) ;
872 double ax = .5 * ( 2. + xx ) / (1. + xx ) ;
873 double fact =
pow(ax, aexp_mass) ;
874 cout <<
" xprog, xx, ax, fact : " << xprog <<
" " <<
875 xx <<
" " << ax <<
" " << fact << endl ;
881 if (mer%4 == 0)
omega *= fact ;
891 diff_ent = diff_ent_tbl(0) ;
892 for (
int l=1; l<
nzet; l++) {
893 diff_ent += diff_ent_tbl(l) ;
897 fichconv <<
" " <<
log10( fabs(diff_ent) + 1.e-16 ) ;
898 fichconv <<
" " <<
log10( fabs(err_grv2) + 1.e-16 ) ;
Component of a tensorial field *** DEPRECATED : use class Scalar instead ***.
void mult_rsint()
Multiplication by .
int get_etat() const
Returns the logical state.
Valeur va
The numerical value of the Cmp
void std_base_scal()
Sets the spectral bases of the Valeur va to the standard ones for a scalar.
void annule(int l)
Sets the Cmp to zero in a given domain.
void set_etat_zero()
Sets the logical state to ETATZERO (zero).
virtual void MHD_comput()
Computes the electromagnetic part of the stress-energy tensor.
Cmp A_phi
-component of the electromagnetic potential 1-form divided by .
double a_j
Amplitude of the curent/charge function.
void magnet_comput(const int adapt_flag, Cmp(*f_j)(const Cmp &x, const double), Param &par_poisson_At, Param &par_poisson_Avect)
Computes the electromagnetic quantities solving the Maxwell equations (6) and (7) of [Bocquet,...
Cmp A_t
t-component of the elecctromagnetic potential 1-form, divided by .
virtual double mass_g() const
Gravitational mass.
bool is_conduct() const
Tells if the star is made of conducting or isolating material.
virtual double grv2() const
Error on the virial identity GRV2.
Tenseur E_em
electromagnetic energy density in the Eulerian frame
Tenseur Jp_em
component of the electromagnetic momentum density 3-vector, as measured in the Eulerian frame.
double Q
In the case of a perfect conductor, the requated baryonic charge.
void equilibrium_mag(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, const double Q0, const double a_j0, Cmp(*f_j)(const Cmp &x, const double), Cmp(*M_j)(const Cmp &x, const double))
Computes an equilibrium configuration.
Tenseur ssjm1_wshift
Effective source at the previous step for the resolution of the vector Poisson equation for .
Tenseur uuu
Norm of u_euler.
double omega
Rotation angular velocity ([f_unit] )
Tenseur & logn
Metric potential = logn_auto.
virtual void hydro_euler()
Computes the hydrodynamical quantities relative to the Eulerian observer from those in the fluid fram...
Tenseur nuq
Part of the Metric potential = logn generated by the quadratic terms.
Tenseur khi_shift
Scalar used in the decomposition of shift , following Shibata's prescription [Prog.
Tenseur tggg
Metric potential .
Tenseur nuf
Part of the Metric potential = logn generated by the matter terms.
Cmp ssjm1_tggg
Effective source at the previous step for the resolution of the Poisson equation for tggg .
Tenseur nphi
Metric coefficient .
virtual double mass_b() const
Baryon mass.
Tenseur bbb
Metric factor B.
void update_metric()
Computes metric coefficients from known potentials.
Tenseur & dzeta
Metric potential = beta_auto.
Cmp ssjm1_nuf
Effective source at the previous step for the resolution of the Poisson equation for nuf by means of ...
void fait_nphi()
Computes tnphi and nphi from the Cartesian components of the shift, stored in shift .
Cmp ssjm1_khi
Effective source at the previous step for the resolution of the Poisson equation for the scalar by m...
Tenseur_sym tkij
Tensor related to the extrinsic curvature tensor by .
Tenseur b_car
Square of the metric factor B.
Cmp ssjm1_nuq
Effective source at the previous step for the resolution of the Poisson equation for nuq by means of ...
Tenseur w_shift
Vector used in the decomposition of shift , following Shibata's prescription [Prog.
int nzet
Number of domains of *mp occupied by the star.
double ray_eq() const
Coordinate radius at , [r_unit].
Tenseur nnn
Total lapse function.
Tenseur nbar
Baryon density in the fluid frame.
virtual void equation_of_state()
Computes the proper baryon and energy density, as well as pressure from the enthalpy.
Tenseur u_euler
Fluid 3-velocity with respect to the Eulerian observer.
Tenseur gam_euler
Lorentz factor between the fluid and Eulerian observers.
Map & mp
Mapping associated with the star.
Tenseur press
Fluid pressure.
bool relativistic
Indicator of relativity: true for a relativistic star, false for a Newtonian one.
Tenseur ener_euler
Total energy density in the Eulerian frame.
Tenseur shift
Total shift vector.
Tenseur s_euler
Trace of the stress tensor in the Eulerian frame.
Tenseur ent
Log-enthalpy (relativistic case) or specific enthalpy (Newtonian case)
Tenseur a_car
Total conformal factor .
double ray_pole() const
Coordinate radius at [r_unit].
Basic integer array class.
Radial mapping of rather general form.
virtual void homothetie(double lambda)
Sets a new radial scale.
const Base_vect_cart & get_bvect_cart() const
Returns the Cartesian basis associated with the coordinates (x,y,z) of the mapping,...
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.
virtual void adapt(const Cmp &ent, const Param &par, int nbr=0)=0
Adaptation of the mapping to a given scalar field.
const Base_vect_spher & get_bvect_spher() const
Returns the orthonormal vectorial basis associated with the coordinates of the mapping.
const Cmp & cmp_zero() const
Returns the null Cmp defined on *this.
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.
const Mg3d * get_mg() const
Gives the Mg3d on which the mapping is defined.
int get_np(int l) const
Returns the number of points in the azimuthal direction ( ) in domain no. l.
int get_nt(int l) const
Returns the number of points in the co-latitude direction ( ) in domain no. l.
int get_nzone() const
Returns the number of domains.
int get_nr(int l) const
Returns the number of points in the radial direction ( ) in domain no. l.
void add_double(const double &x, int position=0)
Adds the the address of a new double to the list.
void add_cmp_mod(Cmp &ti, int position=0)
Adds the address of a new modifiable Cmp to the list.
void add_double_mod(double &x, int position=0)
Adds the address of a new modifiable double to the list.
void add_int_mod(int &n, int position=0)
Adds the address of a new modifiable int to the list.
void add_tenseur_mod(Tenseur &ti, int position=0)
Adds the address of a new modifiable Tenseur to the list.
void add_int(const int &n, int position=0)
Adds the address of a new int to the list.
void add_tbl(const Tbl &ti, int position=0)
Adds the address of a new Tbl to the list.
void set_etat_qcq()
Sets the logical state to ETATQCQ (ordinary state).
double & set(int i)
Read/write of a particular element (index i) (1D case)
Tensor handling *** DEPRECATED : use class Tensor instead ***.
Cmp & set()
Read/write for a scalar (see also operator=(const Cmp&) ).
void set_etat_qcq()
Sets the logical state to ETATQCQ (ordinary state).
void set_std_base()
Set the standard spectal basis of decomposition for each component.
void set_etat_zero()
Sets the logical state to ETATZERO (zero state).
const Tenseur & gradient_spher() const
Returns the gradient of *this (Spherical coordinates) (scalar field only).
void change_triad(const Base_vect &new_triad)
Sets a new vectorial basis (triad) of decomposition and modifies the components accordingly.
void poisson_vect(double lambda, Param &par, Tenseur &shift, Tenseur &vect, Tenseur &scal) const
Solves the vectorial Poisson equation : .
int get_etat() const
Returns the logical state.
void coef_i() const
Computes the physical value of *this.
Cmp sqrt(const Cmp &)
Square root.
Cmp log10(const Cmp &)
Basis 10 logarithm.
Tbl diffrel(const Cmp &a, const Cmp &b)
Relative difference between two Cmp (norme version).
Cmp pow(const Cmp &, int)
Power .
Cmp abs(const Cmp &)
Absolute value.
Cmp log(const Cmp &)
Neperian logarithm.
Tenseur flat_scalar_prod(const Tenseur &t1, const Tenseur &t2)
Scalar product of two Tenseur when the metric is : performs the contraction of the last index of t1 w...
Standard electro-magnetic units.