et_rot_equilibrium.C

00001 /*
00002  * Function Etoile_rot::equilibrium
00003  *
00004  * (see file etoile.h for documentation)
00005  *
00006  */
00007 
00008 /*
00009  *   Copyright (c) 2000-2001 Eric Gourgoulhon
00010  *
00011  *   This file is part of LORENE.
00012  *
00013  *   LORENE is free software; you can redistribute it and/or modify
00014  *   it under the terms of the GNU General Public License as published by
00015  *   the Free Software Foundation; either version 2 of the License, or
00016  *   (at your option) any later version.
00017  *
00018  *   LORENE is distributed in the hope that it will be useful,
00019  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
00020  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00021  *   GNU General Public License for more details.
00022  *
00023  *   You should have received a copy of the GNU General Public License
00024  *   along with LORENE; if not, write to the Free Software
00025  *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00026  *
00027  */
00028 
00029 
00030 char et_rot_equilibrium_C[] = "$Header: /cvsroot/Lorene/C++/Source/Etoile/et_rot_equilibrium.C,v 1.6 2005/10/05 15:15:31 j_novak Exp $" ;
00031 
00032 /*
00033  * $Id: et_rot_equilibrium.C,v 1.6 2005/10/05 15:15:31 j_novak Exp $
00034  * $Log: et_rot_equilibrium.C,v $
00035  * Revision 1.6  2005/10/05 15:15:31  j_novak
00036  * Added a Param* as parameter of Etoile_rot::equilibrium
00037  *
00038  * Revision 1.5  2004/03/25 10:29:06  j_novak
00039  * All LORENE's units are now defined in the namespace Unites (in file unites.h).
00040  *
00041  * Revision 1.4  2003/11/19 21:30:57  e_gourgoulhon
00042  * -- Relaxation on logn and dzeta performed only if mer >= 10.
00043  * -- err_grv2 is now evaluated also in the Newtonian case
00044  *
00045  * Revision 1.3  2003/10/27 10:54:43  e_gourgoulhon
00046  * Changed local variable name lambda_grv2 to lbda_grv2 in order not
00047  * to shadow method name.
00048  *
00049  * Revision 1.2  2002/10/16 14:36:36  j_novak
00050  * Reorganization of #include instructions of standard C++, in order to
00051  * use experimental version 3 of gcc.
00052  *
00053  * Revision 1.1.1.1  2001/11/20 15:19:28  e_gourgoulhon
00054  * LORENE
00055  *
00056  * Revision 2.19  2000/11/23  15:44:10  eric
00057  * Ajout de l'argument ent_limit.
00058  *
00059  * Revision 2.18  2000/11/19  22:34:15  eric
00060  * Correction erreur ds convergence vers une masse baryonique fixee.
00061  *
00062  * Revision 2.17  2000/11/18  17:13:18  eric
00063  * Modifs pour permettre np=1 (axisymetrie). En particulier,
00064  *  lambda_shift est mis a zero si np=1.
00065  *
00066  * Revision 2.16  2000/11/10  15:17:50  eric
00067  * Ajout des arguments icontrol(7) (delta_mer_kep) et control(6) (precis_adapt)
00068  * Creation des fichiers freqeuncy.d et evolution.d
00069  *
00070  * Revision 2.15  2000/11/08  15:21:16  eric
00071  * Appel de fait_nphi() avant hydro_euler() pour le test sur u_euler.
00072  *
00073  * Revision 2.14  2000/10/25  15:13:36  eric
00074  * omega est initialise a zero.
00075  *
00076  * Revision 2.13  2000/10/23  14:02:55  eric
00077  * Modif de Map_et::adapt: on y rentre desormais avec nz_search
00078  *   dans le cas present nz_search = nzet + 1).
00079  *
00080  * Revision 2.12  2000/10/23  13:47:47  dorota
00081  * Ajout en sortie (dans diff(7)) de vit_triax.
00082  * Suppression de l'initialisation a zero de omega_ini (!)
00083  *
00084  * Revision 2.11  2000/10/20  13:56:43  eric
00085  * Ecriture dans le fichier convergence.d de la vitesse de developpement
00086  *  de la perturbation triaxiale (vit_triax).
00087  *
00088  * Revision 2.10  2000/10/20  13:11:23  eric
00089  * Ajout de l'argument nzadapt.
00090  *
00091  * Revision 2.9  2000/10/17  16:00:24  eric
00092  * Ajout de la perturbation triaxiale.
00093  *
00094  * Revision 2.8  2000/10/12  15:33:22  eric
00095  * Ajout de l'appel a fait_nphi() pour le calcul de tnphi et nphi.
00096  * Emploi de la nouvelle version de Tenseur::set_std_base() : on n'a plus
00097  *  besoin de tester l'etat du tenseur avant.
00098  *
00099  * Revision 2.7  2000/10/11  15:14:09  eric
00100  * Ajout des equations pour tggg et dzeta --> 1ere version complete !
00101  *
00102  * Revision 2.6  2000/10/06  15:06:14  eric
00103  * Version relativiste avec le lapse et le shift uniquement.
00104  * Ca converge.
00105  *
00106  * Revision 2.5  2000/09/18  16:15:26  eric
00107  * Premiers termes relativistes.
00108  *
00109  * Revision 2.4  2000/08/31  15:39:02  eric
00110  * Appel du nouvel operateur Cmp::mult_rsint pour le calcul de uuu.
00111  *
00112  * Revision 2.3  2000/08/25  12:27:55  eric
00113  * modifs mineures (fichconv).
00114  *
00115  * Revision 2.2  2000/08/18  14:01:24  eric
00116  * Premiere version operationnelle (testee en spherique Newtonien)
00117  *
00118  * Revision 2.1  2000/08/17  12:39:47  eric
00119  * *** empty log message ***
00120  *
00121  * Revision 2.0  2000/07/21  16:30:32  eric
00122  * *** empty log message ***
00123  *
00124  *
00125  * $Header: /cvsroot/Lorene/C++/Source/Etoile/et_rot_equilibrium.C,v 1.6 2005/10/05 15:15:31 j_novak Exp $
00126  *
00127  */
00128 
00129 // Headers C
00130 #include <math.h>
00131 
00132 // Headers Lorene
00133 #include "etoile.h"
00134 #include "param.h"
00135 
00136 #include "graphique.h"
00137 #include "utilitaires.h"
00138 #include "unites.h"
00139 
00140 void Etoile_rot::equilibrium(double ent_c, double omega0, double fact_omega, 
00141                  int nzadapt, const Tbl& ent_limit, const Itbl& icontrol,
00142                  const Tbl& control, double mbar_wanted, 
00143                  double aexp_mass, Tbl& diff, Param*) {
00144                  
00145     // Fundamental constants and units
00146     // -------------------------------
00147 
00148   using namespace Unites ;      
00149     
00150     // For the display 
00151     // ---------------
00152     char display_bold[]="x[1m" ; display_bold[0] = 27 ;
00153     char display_normal[] = "x[0m" ; display_normal[0] = 27 ;
00154 
00155     // Grid parameters
00156     // ---------------
00157     
00158     const Mg3d* mg = mp.get_mg() ; 
00159     int nz = mg->get_nzone() ;      // total number of domains
00160     int nzm1 = nz - 1 ; 
00161     
00162     // The following is required to initialize mp_prev as a Map_et:
00163     Map_et& mp_et = dynamic_cast<Map_et&>(mp) ; 
00164         
00165     // Index of the point at phi=0, theta=pi/2 at the surface of the star:
00166     assert(mg->get_type_t() == SYM) ; 
00167     int l_b = nzet - 1 ; 
00168     int i_b = mg->get_nr(l_b) - 1 ; 
00169     int j_b = mg->get_nt(l_b) - 1 ; 
00170     int k_b = 0 ; 
00171     
00172     // Value of the enthalpy defining the surface of the star
00173     double ent_b = ent_limit(nzet-1) ;
00174     
00175     // Parameters to control the iteration
00176     // -----------------------------------
00177     
00178     int mer_max = icontrol(0) ; 
00179     int mer_rot = icontrol(1) ;
00180     int mer_change_omega = icontrol(2) ; 
00181     int mer_fix_omega = icontrol(3) ; 
00182     int mer_mass = icontrol(4) ; 
00183     int mermax_poisson = icontrol(5) ; 
00184     int mer_triax = icontrol(6) ; 
00185     int delta_mer_kep = icontrol(7) ; 
00186 
00187     // Protections:
00188     if (mer_change_omega < mer_rot) {
00189     cout << "Etoile_rot::equilibrium: mer_change_omega < mer_rot !" << endl ;
00190     cout << " mer_change_omega = " << mer_change_omega << endl ; 
00191     cout << " mer_rot = " << mer_rot << endl ; 
00192     abort() ; 
00193     }
00194     if (mer_fix_omega < mer_change_omega) {
00195     cout << "Etoile_rot::equilibrium: mer_fix_omega < mer_change_omega !" 
00196          << endl ;
00197     cout << " mer_fix_omega = " << mer_fix_omega << endl ; 
00198     cout << " mer_change_omega = " << mer_change_omega << endl ; 
00199     abort() ; 
00200     }
00201 
00202     // In order to converge to a given baryon mass, shall the central
00203     // enthalpy be varied or Omega ?
00204     bool change_ent = true ; 
00205     if (mer_mass < 0) {
00206     change_ent = false ; 
00207     mer_mass = abs(mer_mass) ;
00208     }
00209 
00210     double precis = control(0) ; 
00211     double omega_ini = control(1) ; 
00212     double relax = control(2) ;
00213     double relax_prev = double(1) - relax ;  
00214     double relax_poisson = control(3) ; 
00215     double thres_adapt = control(4) ; 
00216     double ampli_triax = control(5) ; 
00217     double precis_adapt = control(6) ; 
00218 
00219 
00220     // Error indicators
00221     // ----------------
00222     
00223     diff.set_etat_qcq() ; 
00224     double& diff_ent = diff.set(0) ; 
00225     double& diff_nuf = diff.set(1) ; 
00226     double& diff_nuq = diff.set(2) ; 
00227 //    double& diff_dzeta = diff.set(3) ; 
00228 //    double& diff_ggg = diff.set(4) ; 
00229     double& diff_shift_x = diff.set(5) ; 
00230     double& diff_shift_y = diff.set(6) ; 
00231     double& vit_triax = diff.set(7) ; 
00232     
00233     // Parameters for the function Map_et::adapt
00234     // -----------------------------------------
00235     
00236     Param par_adapt ; 
00237     int nitermax = 100 ;  
00238     int niter ; 
00239     int adapt_flag = 1 ;    //  1 = performs the full computation, 
00240                 //  0 = performs only the rescaling by 
00241                 //      the factor alpha_r
00242     int nz_search = nzet + 1 ;  // Number of domains for searching the enthalpy
00243                 //  isosurfaces
00244     double alpha_r ; 
00245     double reg_map = 1. ; // 1 = regular mapping, 0 = contracting mapping
00246 
00247     par_adapt.add_int(nitermax, 0) ; // maximum number of iterations to
00248                      // locate zeros by the secant method
00249     par_adapt.add_int(nzadapt, 1) ; // number of domains where the adjustment 
00250                     // to the isosurfaces of ent is to be 
00251                     // performed
00252     par_adapt.add_int(nz_search, 2) ;   // number of domains to search for
00253                     // the enthalpy isosurface
00254     par_adapt.add_int(adapt_flag, 3) ; //  1 = performs the full computation, 
00255                        //  0 = performs only the rescaling by 
00256                        //      the factor alpha_r
00257     par_adapt.add_int(j_b, 4) ; //  theta index of the collocation point 
00258                     //  (theta_*, phi_*)
00259     par_adapt.add_int(k_b, 5) ; //  theta index of the collocation point 
00260                     //  (theta_*, phi_*)
00261 
00262     par_adapt.add_int_mod(niter, 0) ;  //  number of iterations actually used in 
00263                        //  the secant method
00264     
00265     par_adapt.add_double(precis_adapt, 0) ; // required absolute precision in 
00266                          // the determination of zeros by 
00267                          // the secant method
00268     par_adapt.add_double(reg_map, 1)    ;  // 1. = regular mapping, 0 = contracting mapping
00269     
00270     par_adapt.add_double(alpha_r, 2) ;  // factor by which all the radial 
00271                        // distances will be multiplied 
00272            
00273     par_adapt.add_tbl(ent_limit, 0) ;   // array of values of the field ent 
00274                         // to define the isosurfaces.              
00275 
00276     // Parameters for the function Map_et::poisson for nuf
00277     // ----------------------------------------------------
00278 
00279     double precis_poisson = 1.e-16 ;     
00280 
00281     Param par_poisson_nuf ; 
00282     par_poisson_nuf.add_int(mermax_poisson,  0) ;  // maximum number of iterations
00283     par_poisson_nuf.add_double(relax_poisson,  0) ; // relaxation parameter
00284     par_poisson_nuf.add_double(precis_poisson, 1) ; // required precision
00285     par_poisson_nuf.add_int_mod(niter, 0) ;  //  number of iterations actually used 
00286     par_poisson_nuf.add_cmp_mod( ssjm1_nuf ) ; 
00287                        
00288     Param par_poisson_nuq ; 
00289     par_poisson_nuq.add_int(mermax_poisson,  0) ;  // maximum number of iterations
00290     par_poisson_nuq.add_double(relax_poisson,  0) ; // relaxation parameter
00291     par_poisson_nuq.add_double(precis_poisson, 1) ; // required precision
00292     par_poisson_nuq.add_int_mod(niter, 0) ;  //  number of iterations actually used 
00293     par_poisson_nuq.add_cmp_mod( ssjm1_nuq ) ; 
00294                        
00295     Param par_poisson_tggg ; 
00296     par_poisson_tggg.add_int(mermax_poisson,  0) ;  // maximum number of iterations
00297     par_poisson_tggg.add_double(relax_poisson,  0) ; // relaxation parameter
00298     par_poisson_tggg.add_double(precis_poisson, 1) ; // required precision
00299     par_poisson_tggg.add_int_mod(niter, 0) ;  //  number of iterations actually used 
00300     par_poisson_tggg.add_cmp_mod( ssjm1_tggg ) ; 
00301     double lambda_tggg ;
00302     par_poisson_tggg.add_double_mod( lambda_tggg ) ; 
00303     
00304     Param par_poisson_dzeta ; 
00305     double lbda_grv2 ;
00306     par_poisson_dzeta.add_double_mod( lbda_grv2 ) ; 
00307                        
00308     // Parameters for the function Tenseur::poisson_vect
00309     // -------------------------------------------------
00310 
00311     Param par_poisson_vect ; 
00312 
00313     par_poisson_vect.add_int(mermax_poisson,  0) ;  // maximum number of iterations
00314     par_poisson_vect.add_double(relax_poisson,  0) ; // relaxation parameter
00315     par_poisson_vect.add_double(precis_poisson, 1) ; // required precision
00316     par_poisson_vect.add_cmp_mod( ssjm1_khi ) ; 
00317     par_poisson_vect.add_tenseur_mod( ssjm1_wshift ) ; 
00318     par_poisson_vect.add_int_mod(niter, 0) ;   
00319 
00320                        
00321     // Initializations
00322     // ---------------
00323 
00324     // Initial angular velocity
00325     omega = 0 ; 
00326   
00327     double accrois_omega = (omega0 - omega_ini) / 
00328                 double(mer_fix_omega - mer_change_omega) ; 
00329 
00330 
00331     update_metric() ;   // update of the metric coefficients
00332 
00333     equation_of_state() ;   // update of the density, pressure, etc...
00334     
00335     hydro_euler() ; // update of the hydro quantities relative to the 
00336             //  Eulerian observer
00337 
00338     // Quantities at the previous step :    
00339     Map_et mp_prev = mp_et ; 
00340     Tenseur ent_prev = ent ;        
00341     Tenseur logn_prev = logn ;      
00342     Tenseur dzeta_prev = dzeta ;        
00343     
00344     // Creation of uninitialized tensors:
00345     Tenseur source_nuf(mp) ;    // source term in the equation for nuf
00346     Tenseur source_nuq(mp) ;    // source term in the equation for nuq
00347     Tenseur source_dzf(mp) ;    // matter source term in the eq. for dzeta
00348     Tenseur source_dzq(mp) ;    // quadratic source term in the eq. for dzeta
00349     Tenseur source_tggg(mp) ;   // source term in the eq. for tggg
00350     Tenseur source_shift(mp, 1, CON, mp.get_bvect_cart()) ;  
00351                             // source term for shift
00352     Tenseur mlngamma(mp) ;  // centrifugal potential
00353     
00354     // Preparations for the Poisson equations:
00355     // --------------------------------------
00356     if (nuf.get_etat() == ETATZERO) {
00357     nuf.set_etat_qcq() ; 
00358     nuf.set() = 0 ; 
00359     }
00360     
00361     if (relativistic) {
00362     if (nuq.get_etat() == ETATZERO) {
00363         nuq.set_etat_qcq() ; 
00364         nuq.set() = 0 ; 
00365     }
00366 
00367     if (tggg.get_etat() == ETATZERO) {
00368         tggg.set_etat_qcq() ; 
00369         tggg.set() = 0 ; 
00370     }
00371     
00372     if (dzeta.get_etat() == ETATZERO) {
00373         dzeta.set_etat_qcq() ; 
00374         dzeta.set() = 0 ; 
00375     }
00376     }
00377             
00378     ofstream fichconv("convergence.d") ;    // Output file for diff_ent
00379     fichconv << "#     diff_ent     GRV2       max_triax      vit_triax" << endl ; 
00380     
00381     ofstream fichfreq("frequency.d") ;    // Output file for  omega
00382     fichfreq << "#       f [Hz]" << endl ; 
00383     
00384     ofstream fichevol("evolution.d") ;    // Output file for various quantities
00385     fichevol << 
00386     "#       |dH/dr_eq/dH/dr_pole|      r_pole/r_eq ent_c" 
00387     << endl ; 
00388     
00389     diff_ent = 1 ; 
00390     double err_grv2 = 1 ; 
00391     double max_triax_prev = 0 ;     // Triaxial amplitude at previous step
00392     
00393     //=========================================================================
00394     //          Start of iteration
00395     //=========================================================================
00396 
00397     for(int mer=0 ; (diff_ent > precis) && (mer<mer_max) ; mer++ ) {
00398 
00399     cout << "-----------------------------------------------" << endl ;
00400     cout << "step: " << mer << endl ;
00401     cout << "diff_ent = " << display_bold << diff_ent << display_normal
00402          << endl ;    
00403     cout << "err_grv2 = " << err_grv2 << endl ;    
00404     fichconv << mer ;
00405     fichfreq << mer ;
00406     fichevol << mer ;
00407 
00408     if (mer >= mer_rot) {
00409     
00410         if (mer < mer_change_omega) {
00411         omega = omega_ini ; 
00412         }
00413         else {
00414         if (mer <= mer_fix_omega) {
00415             omega = omega_ini + accrois_omega * 
00416                   (mer - mer_change_omega) ;
00417         }
00418         }
00419 
00420     }
00421 
00422     //-----------------------------------------------
00423     //  Sources of the Poisson equations
00424     //-----------------------------------------------
00425     
00426     // Source for nu
00427     // -------------
00428     Tenseur beta = log(bbb) ; 
00429     beta.set_std_base() ; 
00430 
00431     if (relativistic) {
00432         source_nuf =  qpig * a_car *( ener_euler + s_euler ) ; 
00433 
00434         source_nuq = ak_car - flat_scalar_prod(logn.gradient_spher(), 
00435             logn.gradient_spher() + beta.gradient_spher()) ; 
00436     }
00437     else {
00438         source_nuf = qpig * nbar ; 
00439 
00440         source_nuq = 0 ; 
00441     }
00442     source_nuf.set_std_base() ;     
00443     source_nuq.set_std_base() ;     
00444 
00445     // Source for dzeta
00446     // ----------------
00447     source_dzf = 2 * qpig * a_car * (press + (ener_euler+press) * uuu*uuu ) ;
00448     source_dzf.set_std_base() ; 
00449   
00450     source_dzq = 1.5 * ak_car - flat_scalar_prod(logn.gradient_spher(),
00451                              logn.gradient_spher() ) ;      
00452     source_dzq.set_std_base() ;     
00453     
00454     // Source for tggg
00455     // ---------------
00456     
00457     source_tggg = 4 * qpig * nnn * a_car * bbb * press ;
00458     source_tggg.set_std_base() ; 
00459     
00460     (source_tggg.set()).mult_rsint() ; 
00461     
00462 
00463     // Source for shift
00464     // ----------------
00465         
00466     // Matter term: 
00467     source_shift = (-4*qpig) * nnn * a_car  * (ener_euler + press)
00468                 * u_euler ;
00469 
00470     // Quadratic terms:
00471     Tenseur vtmp =  6 * beta.gradient_spher() - 2 * logn.gradient_spher() ;
00472     vtmp.change_triad(mp.get_bvect_cart()) ; 
00473 
00474     Tenseur squad  = nnn * flat_scalar_prod(tkij, vtmp) ;     
00475 
00476     // The addition of matter terms and quadratic terms is performed
00477     //  component by component because u_euler is contravariant,
00478     //  while squad is covariant. 
00479         
00480     if (squad.get_etat() == ETATQCQ) {
00481         for (int i=0; i<3; i++) {
00482         source_shift.set(i) += squad(i) ; 
00483         }
00484     }
00485 
00486     source_shift.set_std_base() ;   
00487 
00488     //----------------------------------------------
00489     // Resolution of the Poisson equation for nuf 
00490     //----------------------------------------------
00491 
00492     source_nuf().poisson(par_poisson_nuf, nuf.set()) ; 
00493     
00494     cout << "Test of the Poisson equation for nuf :" << endl ; 
00495     Tbl err = source_nuf().test_poisson(nuf(), cout, true) ; 
00496     diff_nuf = err(0, 0) ; 
00497     
00498     //---------------------------------------
00499     // Triaxial perturbation of nuf
00500     //---------------------------------------
00501     
00502     if (mer == mer_triax) {
00503     
00504         if ( mg->get_np(0) == 1 ) {
00505         cout << 
00506         "Etoile_rot::equilibrium: np must be stricly greater than 1"
00507         << endl << " to set a triaxial perturbation !" << endl ; 
00508         abort() ; 
00509         }
00510     
00511         const Coord& phi = mp.phi ; 
00512         const Coord& sint = mp.sint ; 
00513         Cmp perturb(mp) ; 
00514         perturb = 1 + ampli_triax * sint*sint * cos(2*phi) ;
00515         nuf.set() = nuf() * perturb ;  
00516         
00517         nuf.set_std_base() ;    // set the bases for spectral expansions
00518                     //  to be the standard ones for a 
00519                     //  scalar field
00520 
00521     }
00522     
00523     // Monitoring of the triaxial perturbation
00524     // ---------------------------------------
00525     
00526     Valeur& va_nuf = nuf.set().va ; 
00527     va_nuf.coef() ;     // Computes the spectral coefficients
00528     double max_triax = 0 ; 
00529 
00530     if ( mg->get_np(0) > 1 ) {
00531 
00532         for (int l=0; l<nz; l++) {  // loop on the domains
00533         for (int j=0; j<mg->get_nt(l); j++) {
00534             for (int i=0; i<mg->get_nr(l); i++) {
00535         
00536             // Coefficient of cos(2 phi) : 
00537             double xcos2p = (*(va_nuf.c_cf))(l, 2, j, i) ; 
00538 
00539             // Coefficient of sin(2 phi) : 
00540             double xsin2p = (*(va_nuf.c_cf))(l, 3, j, i) ; 
00541             
00542             double xx = sqrt( xcos2p*xcos2p + xsin2p*xsin2p ) ; 
00543             
00544             max_triax = ( xx > max_triax ) ? xx : max_triax ;           
00545             }
00546         } 
00547         }
00548         
00549     }
00550     
00551     cout << "Triaxial part of nuf : " << max_triax << endl ; 
00552 
00553     if (relativistic) {
00554         
00555         //----------------------------------------------
00556         // Resolution of the Poisson equation for nuq 
00557         //----------------------------------------------
00558 
00559         source_nuq().poisson(par_poisson_nuq, nuq.set()) ; 
00560         
00561         cout << "Test of the Poisson equation for nuq :" << endl ; 
00562         err = source_nuq().test_poisson(nuq(), cout, true) ;
00563         diff_nuq = err(0, 0) ; 
00564     
00565         //---------------------------------------------------------
00566         // Resolution of the vector Poisson equation for the shift
00567         //---------------------------------------------------------
00568 
00569 
00570         if (source_shift.get_etat() != ETATZERO) {
00571 
00572         for (int i=0; i<3; i++) {
00573             if(source_shift(i).dz_nonzero()) {
00574             assert( source_shift(i).get_dzpuis() == 4 ) ; 
00575             }
00576             else{
00577             (source_shift.set(i)).set_dzpuis(4) ; 
00578             }
00579         }
00580 
00581         }
00582         //##
00583         // source_shift.dec2_dzpuis() ;    // dzpuis 4 -> 2
00584 
00585         double lambda_shift = double(1) / double(3) ; 
00586 
00587         if ( mg->get_np(0) == 1 ) {
00588         lambda_shift = 0 ; 
00589         }
00590     
00591         source_shift.poisson_vect(lambda_shift, par_poisson_vect, 
00592                       shift, w_shift, khi_shift) ;      
00593         
00594         cout << "Test of the Poisson equation for shift_x :" << endl ; 
00595         err = source_shift(0).test_poisson(shift(0), cout, true) ;
00596         diff_shift_x = err(0, 0) ; 
00597     
00598         cout << "Test of the Poisson equation for shift_y :" << endl ; 
00599         err = source_shift(1).test_poisson(shift(1), cout, true) ;
00600         diff_shift_y = err(0, 0) ; 
00601         
00602         // Computation of tnphi and nphi from the Cartesian components
00603         //  of the shift
00604         // -----------------------------------------------------------
00605         
00606         fait_nphi() ; 
00607     
00608         //##    cout.precision(10) ;
00609         //      cout << "nphi : " << nphi()(0, 0, 0, 0)
00610         //           << "  " << nphi()(l_b, k_b, j_b, i_b/2)
00611         //           << "  " << nphi()(l_b, k_b, j_b, i_b) << endl ;
00612 
00613     }
00614 
00615     //-----------------------------------------
00616     // Determination of the fluid velociy U
00617     //-----------------------------------------
00618     
00619     if (mer > mer_fix_omega + delta_mer_kep) {
00620         
00621             omega *= fact_omega ;  // Increase of the angular velocity if 
00622     }              //  fact_omega != 1
00623     
00624     bool omega_trop_grand = false ; 
00625     bool kepler = true ; 
00626 
00627     while ( kepler ) {
00628     
00629         // Possible decrease of Omega to ensure a velocity < c 
00630     
00631         bool superlum = true ; 
00632     
00633         while ( superlum ) {
00634     
00635         // New fluid velocity U :
00636     
00637         Cmp tmp = omega - nphi() ; 
00638         tmp.annule(nzm1) ; 
00639         tmp.std_base_scal() ;
00640     
00641         tmp.mult_rsint() ;      //  Multiplication by r sin(theta)
00642 
00643         uuu = bbb() / nnn() * tmp ; 
00644     
00645         if (uuu.get_etat() == ETATQCQ) {
00646             // Same basis as (Omega -N^phi) r sin(theta) :
00647             ((uuu.set()).va).set_base( (tmp.va).base ) ;   
00648         }
00649 
00650 
00651         // Is the new velocity larger than c in the equatorial plane ?
00652     
00653         superlum = false ; 
00654     
00655         for (int l=0; l<nzet; l++) {
00656             for (int i=0; i<mg->get_nr(l); i++) {
00657         
00658             double u1 = uuu()(l, 0, j_b, i) ; 
00659             if (u1 >= 1.) {     // superluminal velocity
00660                 superlum = true ; 
00661                 cout << "U > c  for l, i : " << l << "  " << i 
00662                  << "   U = " << u1 << endl ;  
00663             }
00664             }
00665         }
00666         if ( superlum ) {
00667             cout << "**** VELOCITY OF LIGHT REACHED ****" << endl ; 
00668             omega /= fact_omega ;    // Decrease of Omega
00669             cout << "New rotation frequency : " 
00670              << omega/(2.*M_PI) * f_unit <<  " Hz" << endl ; 
00671             omega_trop_grand = true ;  
00672         }
00673         }   // end of while ( superlum )
00674 
00675     
00676         // New computation of U (which this time is not superluminal)
00677         //  as well as of gam_euler, ener_euler, etc...
00678         // -----------------------------------
00679 
00680         hydro_euler() ; 
00681     
00682 
00683         //------------------------------------------------------
00684         //  First integral of motion 
00685         //------------------------------------------------------
00686     
00687         // Centrifugal potential : 
00688         if (relativistic) {
00689         mlngamma = - log( gam_euler ) ;
00690         }
00691         else {
00692         mlngamma = - 0.5 * uuu*uuu ; 
00693         }
00694     
00695         // Equatorial values of various potentials :
00696         double nuf_b  = nuf()(l_b, k_b, j_b, i_b) ; 
00697         double nuq_b  = nuq()(l_b, k_b, j_b, i_b) ; 
00698         double mlngamma_b  = mlngamma()(l_b, k_b, j_b, i_b) ; 
00699 
00700         // Central values of various potentials :
00701         double nuf_c = nuf()(0,0,0,0) ; 
00702         double nuq_c = nuq()(0,0,0,0) ; 
00703         double mlngamma_c = 0 ;
00704     
00705         // Scale factor to ensure that the enthalpy is equal to ent_b at 
00706         //  the equator
00707         double alpha_r2 = ( ent_c - ent_b + mlngamma_c - mlngamma_b
00708                 + nuq_c - nuq_b) / ( nuf_b - nuf_c  ) ;
00709         alpha_r = sqrt(alpha_r2) ;
00710         cout << "alpha_r = " << alpha_r << endl ; 
00711 
00712         // Readjustment of nu :
00713         // -------------------
00714 
00715         logn = alpha_r2 * nuf + nuq ;
00716         double nu_c =  logn()(0,0,0,0) ;
00717 
00718         // First integral   --> enthalpy in all space
00719         //-----------------
00720 
00721         ent = (ent_c + nu_c + mlngamma_c) - logn - mlngamma ;
00722 
00723         // Test: is the enthalpy negative somewhere in the equatorial plane
00724         //  inside the star ? If yes, this means that the Keplerian velocity
00725         //  has been overstep.
00726 
00727         kepler = false ; 
00728         for (int l=0; l<nzet; l++) {
00729         int imax = mg->get_nr(l) - 1 ;
00730         if (l == l_b) imax-- ;  // The surface point is skipped
00731         for (int i=0; i<imax; i++) { 
00732             if ( ent()(l, 0, j_b, i) < 0. ) {
00733             kepler = true ;
00734             cout << "ent < 0 for l, i : " << l << "  " << i 
00735                  << "   ent = " << ent()(l, 0, j_b, i) << endl ;  
00736             } 
00737         }
00738         }
00739     
00740         if ( kepler ) {
00741         cout << "**** KEPLERIAN VELOCITY REACHED ****" << endl ; 
00742         omega /= fact_omega ;    // Omega is decreased
00743         cout << "New rotation frequency : " 
00744              << omega/(2.*M_PI) * f_unit << " Hz" << endl ; 
00745         omega_trop_grand = true ;  
00746         }
00747 
00748     }   // End of while ( kepler )
00749     
00750     if ( omega_trop_grand ) {   // fact_omega is decreased for the
00751                     //  next step 
00752         fact_omega = sqrt( fact_omega ) ; 
00753         cout << "**** New fact_omega : " << fact_omega << endl ; 
00754     }
00755 
00756 //##    if (mer >= mer_triax) {
00757 //      des_coupe_y(ent(), 0., 1, "ent before adapt", &(ent()) ) ; 
00758 //      des_coupe_z(ent(), 0., 1, "ent before adapt (EQUAT)", &(ent()) ) ; 
00759 //##    }
00760 
00761     //----------------------------------------------------
00762     // Adaptation of the mapping to the new enthalpy field
00763     //----------------------------------------------------
00764     
00765     // Shall the adaptation be performed (cusp) ?
00766     // ------------------------------------------
00767     
00768     double dent_eq = ent().dsdr()(l_b, k_b, j_b, i_b) ; 
00769     double dent_pole = ent().dsdr()(l_b, k_b, 0, i_b) ;
00770     double rap_dent = fabs( dent_eq / dent_pole ) ; 
00771     cout << "| dH/dr_eq / dH/dr_pole | = " << rap_dent << endl ; 
00772     
00773     if ( rap_dent < thres_adapt ) {
00774         adapt_flag = 0 ;    // No adaptation of the mapping 
00775         cout << "******* FROZEN MAPPING  *********" << endl ; 
00776     }
00777     else{
00778         adapt_flag = 1 ;    // The adaptation of the mapping is to be
00779                 //  performed
00780     }
00781 
00782     mp_prev = mp_et ; 
00783 
00784     mp.adapt(ent(), par_adapt) ; 
00785 
00786 //##    if (mer >= mer_triax) {
00787 //      des_coupe_y(ent(), 0., 1, "ent after adapt", &(ent()) ) ; 
00788 //      des_coupe_z(ent(), 0., 1, "ent after adapt (EQUAT)", &(ent()) ) ; 
00789 //##    }
00790 
00791     //----------------------------------------------------
00792     // Computation of the enthalpy at the new grid points
00793     //----------------------------------------------------
00794     
00795     mp_prev.homothetie(alpha_r) ; 
00796     
00797     mp.reevaluate(&mp_prev, nzet+1, ent.set()) ; 
00798 
00799 //##    if (mer >= mer_triax) {
00800 //      des_coupe_y(ent(), 0., 1, "ent after reevaluate", &(ent()) ) ; 
00801 //      des_coupe_z(ent(), 0., 1, "ent after reevaluate (EQUAT)", &(ent()) ) ; 
00802 //##    }
00803 
00804 
00805     //----------------------------------------------------
00806     // Equation of state  
00807     //----------------------------------------------------
00808     
00809     equation_of_state() ;   // computes new values for nbar (n), ener (e) 
00810                 // and press (p) from the new ent (H)
00811     
00812     //---------------------------------------------------------
00813     // Matter source terms in the gravitational field equations 
00814     //---------------------------------------------------------
00815 
00816     //## Computation of tnphi and nphi from the Cartesian components
00817     //  of the shift for the test in hydro_euler():
00818         
00819         fait_nphi() ; 
00820 
00821     hydro_euler() ;     // computes new values for ener_euler (E), 
00822                 // s_euler (S) and u_euler (U^i)
00823 
00824     if (relativistic) {
00825 
00826         //-------------------------------------------------------
00827         //  2-D Poisson equation for tggg
00828         //-------------------------------------------------------
00829 
00830         mp.poisson2d(source_tggg(), mp.cmp_zero(), par_poisson_tggg,
00831              tggg.set()) ; 
00832         
00833         //-------------------------------------------------------
00834         //  2-D Poisson equation for dzeta
00835         //-------------------------------------------------------
00836 
00837         mp.poisson2d(source_dzf(), source_dzq(), par_poisson_dzeta,
00838              dzeta.set()) ; 
00839         
00840         err_grv2 = lbda_grv2 - 1; 
00841         cout << "GRV2: " << err_grv2 << endl ; 
00842         
00843     }
00844     else {
00845         err_grv2 = grv2() ; 
00846     }
00847 
00848 
00849     //---------------------------------------
00850     // Computation of the metric coefficients (except for N^phi)
00851     //---------------------------------------
00852 
00853     // Relaxations on nu and dzeta :  
00854 
00855     if (mer >= 10) {
00856         logn = relax * logn + relax_prev * logn_prev ;
00857 
00858         dzeta = relax * dzeta + relax_prev * dzeta_prev ; 
00859     }
00860 
00861     // Update of the metric coefficients N, A, B and computation of K_ij :
00862 
00863     update_metric() ; 
00864     
00865     //-----------------------
00866     //  Informations display
00867     //-----------------------
00868 
00869     partial_display(cout) ; 
00870     fichfreq << "  " << omega / (2*M_PI) * f_unit ; 
00871     fichevol << "  " << rap_dent ; 
00872     fichevol << "  " << ray_pole() / ray_eq() ; 
00873     fichevol << "  " << ent_c ; 
00874 
00875     //-----------------------------------------
00876     // Convergence towards a given baryon mass 
00877     //-----------------------------------------
00878 
00879     if (mer > mer_mass) {
00880         
00881         double xx ; 
00882         if (mbar_wanted > 0.) {
00883         xx = mass_b() / mbar_wanted - 1. ;
00884         cout << "Discrep. baryon mass <-> wanted bar. mass : " << xx 
00885              << endl ; 
00886         }
00887         else{
00888         xx = mass_g() / fabs(mbar_wanted) - 1. ;
00889         cout << "Discrep. grav. mass <-> wanted grav. mass : " << xx 
00890              << endl ; 
00891         }
00892         double xprog = ( mer > 2*mer_mass) ? 1. : 
00893                  double(mer-mer_mass)/double(mer_mass) ; 
00894         xx *= xprog ; 
00895         double ax = .5 * ( 2. + xx ) / (1. + xx ) ; 
00896         double fact = pow(ax, aexp_mass) ; 
00897         cout << "  xprog, xx, ax, fact : " << xprog << "  " <<
00898             xx << "  " << ax << "  " << fact << endl ; 
00899 
00900         if ( change_ent ) {
00901         ent_c *= fact ; 
00902         }
00903         else {
00904         if (mer%4 == 0) omega *= fact ; 
00905         }
00906     }
00907     
00908 
00909     //------------------------------------------------------------
00910     //  Relative change in enthalpy with respect to previous step 
00911     //------------------------------------------------------------
00912 
00913     Tbl diff_ent_tbl = diffrel( ent(), ent_prev() ) ; 
00914     diff_ent = diff_ent_tbl(0) ; 
00915     for (int l=1; l<nzet; l++) {
00916         diff_ent += diff_ent_tbl(l) ; 
00917     }
00918     diff_ent /= nzet ; 
00919     
00920     fichconv << "  " << log10( fabs(diff_ent) + 1.e-16 ) ;
00921     fichconv << "  " << log10( fabs(err_grv2) + 1.e-16 ) ;
00922     fichconv << "  " << log10( fabs(max_triax) + 1.e-16 ) ;
00923 
00924     vit_triax = 0 ;
00925     if ( (mer > mer_triax+1) && (max_triax_prev > 1e-13) ) {
00926         vit_triax = (max_triax - max_triax_prev) / max_triax_prev ; 
00927     }
00928 
00929     fichconv << "  " << vit_triax ;
00930     
00931     //------------------------------
00932     //  Recycling for the next step
00933     //------------------------------
00934     
00935     ent_prev = ent ; 
00936     logn_prev = logn ; 
00937     dzeta_prev = dzeta ; 
00938     max_triax_prev = max_triax ; 
00939     
00940     fichconv << endl ;
00941     fichfreq << endl ;
00942     fichevol << endl ;
00943     fichconv.flush() ; 
00944     fichfreq.flush() ; 
00945     fichevol.flush() ; 
00946 
00947     } // End of main loop
00948     
00949     //=========================================================================
00950     //          End of iteration
00951     //=========================================================================
00952 
00953     fichconv.close() ; 
00954     fichfreq.close() ; 
00955     fichevol.close() ; 
00956     
00957 
00958 }

Generated on Tue Feb 7 01:35:16 2012 for LORENE by  doxygen 1.4.6