etoile_equil_spher.C

00001 /*
00002  * Method of class Etoile to compute a static spherical configuration.
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 etoile_equil_spher_C[] = "$Header: /cvsroot/Lorene/C++/Source/Etoile/etoile_equil_spher.C,v 1.5 2008/11/14 13:48:06 e_gourgoulhon Exp $" ;
00031 
00032 /*
00033  * $Id: etoile_equil_spher.C,v 1.5 2008/11/14 13:48:06 e_gourgoulhon Exp $
00034  * $Log: etoile_equil_spher.C,v $
00035  * Revision 1.5  2008/11/14 13:48:06  e_gourgoulhon
00036  * Added parameter pent_limit to force the enthalpy values at the
00037  * boundaries between the domains, in case of more than one domain inside
00038  * the star.
00039  *
00040  * Revision 1.4  2004/05/07 12:13:15  k_taniguchi
00041  * Change the position of the initialization of alpha_r.
00042  *
00043  * Revision 1.3  2004/03/25 10:29:06  j_novak
00044  * All LORENE's units are now defined in the namespace Unites (in file unites.h).
00045  *
00046  * Revision 1.2  2003/04/23 15:09:38  j_novak
00047  * Standard basis is set to a_car and nnn before exiting.
00048  *
00049  * Revision 1.1.1.1  2001/11/20 15:19:28  e_gourgoulhon
00050  * LORENE
00051  *
00052  * Revision 2.4  2000/02/02  09:23:51  eric
00053  * Ajout du theoreme du viriel.
00054  * Affichage quantites globales a la fin.
00055  *
00056  * Revision 2.3  2000/01/28  17:18:36  eric
00057  * Modifs mineures.
00058  *
00059  * Revision 2.2  2000/01/27  16:47:16  eric
00060  * Premiere version qui tourne !
00061  *
00062  * Revision 2.1  2000/01/26  13:18:19  eric
00063  * *** empty log message ***
00064  *
00065  * Revision 2.0  2000/01/24  17:13:56  eric
00066  * *** empty log message ***
00067  *
00068  *
00069  * $Header: /cvsroot/Lorene/C++/Source/Etoile/etoile_equil_spher.C,v 1.5 2008/11/14 13:48:06 e_gourgoulhon Exp $
00070  *
00071  */
00072 
00073 // Headers C
00074 #include "math.h"
00075 
00076 // Headers Lorene
00077 #include "etoile.h"
00078 #include "param.h"
00079 #include "unites.h"     
00080 #include "nbr_spx.h"
00081 #include "graphique.h"
00082 
00083 void Etoile::equilibrium_spher(double ent_c, double precis, const Tbl* pent_limit){
00084     
00085     // Fundamental constants and units
00086     // -------------------------------
00087   using namespace Unites ;
00088     
00089     // Initializations
00090     // ---------------
00091     
00092     const Mg3d* mg = mp.get_mg() ; 
00093     int nz = mg->get_nzone() ;      // total number of domains
00094     
00095     // Index of the point at phi=0, theta=pi/2 at the surface of the star:
00096     int l_b = nzet - 1 ; 
00097     int i_b = mg->get_nr(l_b) - 1 ; 
00098     int j_b = mg->get_nt(l_b) - 1 ; 
00099     int k_b = 0 ; 
00100     
00101     // Value of the enthalpy defining the surface of the star
00102     double ent_b = 0 ; 
00103     
00104     // Initialization of the enthalpy field to the constant value ent_c :
00105     
00106     ent = ent_c ; 
00107     ent.annule(nzet, nz-1) ; 
00108         
00109     // Corresponding profiles of baryon density, energy density and pressure
00110     
00111     equation_of_state() ; 
00112     
00113     // Initial metric 
00114     a_car = 1 ;      // this value will remain unchanged in the Newtonian case
00115     beta_auto = 0 ;  // this value will remain unchanged in the Newtonian case
00116     
00117 
00118     // Auxiliary quantities
00119     // --------------------
00120     
00121     // Affine mapping for solving the Poisson equations
00122     Map_af mpaff(mp);   
00123         
00124     Param par_nul   ;    // Param (null) for Map_af::poisson.
00125 
00126     Tenseur ent_jm1(mp) ;   // Enthalpy at previous step
00127     ent_jm1 = 0 ; 
00128     
00129     Tenseur source(mp) ; 
00130     Tenseur logn(mp) ; 
00131     Tenseur logn_quad(mp) ; 
00132     logn = 0 ; 
00133     logn_quad = 0 ; 
00134 
00135     Cmp dlogn(mp) ; 
00136     Cmp dbeta(mp) ; 
00137     
00138     double diff_ent = 1 ;     
00139     int mermax = 200 ;      // Max number of iterations
00140     
00141     double alpha_r = 1 ; 
00142 
00143     //=========================================================================
00144     //          Start of iteration
00145     //=========================================================================
00146 
00147     for(int mer=0 ; (diff_ent > precis) && (mer<mermax) ; mer++ ) {
00148 
00149     cout << "-----------------------------------------------" << endl ;
00150     cout << "step: " << mer << endl ;
00151     cout << "alpha_r: " << alpha_r << endl ;
00152     cout << "diff_ent = " << diff_ent << endl ;    
00153 
00154     //-----------------------------------------------------
00155     // Resolution of Poisson equation for ln(N)
00156     //-----------------------------------------------------
00157 
00158     // Matter part of ln(N)
00159     // --------------------
00160     if (relativistic) {
00161         source = a_car * (ener + 3*press) ;
00162     }
00163     else {
00164         source = nbar ; 
00165     }
00166     
00167     (source.set()).set_dzpuis(4) ; 
00168     
00169     source.set_std_base() ;     // Sets the standard spectral bases. 
00170     
00171     logn_auto.set_etat_qcq() ; 
00172 
00173     mpaff.poisson(source(), par_nul, logn_auto.set()) ; 
00174 
00175     // NB: at this stage logn_auto is in machine units, not in c^2
00176 
00177     // Quadratic part of ln(N)
00178     // -----------------------
00179 
00180     if (relativistic) {
00181         
00182         mpaff.dsdr(logn(), dlogn) ; 
00183         mpaff.dsdr(beta_auto(), dbeta) ; 
00184         
00185         source = - dlogn * dbeta ; 
00186               
00187         logn_quad.set_etat_qcq() ; 
00188         
00189         mpaff.poisson(source(), par_nul, logn_quad.set()) ; 
00190                 
00191     }
00192 
00193     //-----------------------------------------------------
00194     // Computation of the new radial scale
00195     //-----------------------------------------------------
00196 
00197     // alpha_r (r = alpha_r r') is determined so that the enthalpy
00198     // takes the requested value ent_b at the stellar surface
00199     
00200     double nu_mat0_b  = logn_auto()(l_b, k_b, j_b, i_b) ; 
00201     double nu_mat0_c  = logn_auto()(0, 0, 0, 0) ; 
00202 
00203     double nu_quad0_b  = logn_quad()(l_b, k_b, j_b, i_b) ; 
00204     double nu_quad0_c  = logn_quad()(0, 0, 0, 0) ; 
00205 
00206     double alpha_r2 = ( ent_c - ent_b - nu_quad0_b + nu_quad0_c )
00207                 / ( qpig*(nu_mat0_b - nu_mat0_c) ) ;
00208 
00209     alpha_r = sqrt(alpha_r2) ;
00210 
00211 
00212         // One domain inside the star:
00213         // --------------------------- 
00214     if(nzet==1) { 
00215 
00216         mpaff.homothetie( alpha_r ) ; 
00217 
00218         } 
00219                       
00220     //--------------------
00221     // First integral
00222     //--------------------
00223 
00224     // Gravitation potential in units c^2 :
00225     logn_auto = alpha_r2*qpig * logn_auto ;
00226     logn = logn_auto + logn_quad ;
00227 
00228     // Enthalpy in all space
00229     double logn_c = logn()(0, 0, 0, 0) ;
00230     ent = ent_c - logn() + logn_c ;
00231     
00232         // Two or more domains inside the star:
00233         // ------------------------------------ 
00234     if(nzet>1) { 
00235 
00236     // Parameters for the function Map_et::adapt
00237     // -----------------------------------------
00238     
00239     Param par_adapt ; 
00240     int nitermax = 100 ;  
00241     int niter ; 
00242     int adapt_flag = 1 ;    //  1 = performs the full computation, 
00243                 //  0 = performs only the rescaling by 
00244                 //      the factor alpha_r
00245     int nz_search = nzet + 1 ;  // Number of domains for searching the enthalpy
00246                 //  isosurfaces
00247 
00248     int nzadapt = nzet ; 
00249 
00250     //cout << "no. of domains where the ent adjustment will be done: " << nzet << endl ;
00251     //cout << "ent limits: " << ent_limit << endl ; 
00252 
00253     double precis_adapt = 1.e-14 ; 
00254  
00255     double reg_map = 1. ; // 1 = regular mapping, 0 = contracting mapping
00256 
00257     par_adapt.add_int(nitermax, 0) ;   // maximum number of iterations to
00258                        // locate zeros by the secant method
00259     par_adapt.add_int(nzadapt, 1) ;    // number of domains where the adjustment 
00260                        // to the isosurfaces of ent is to be 
00261                        // performed
00262     par_adapt.add_int(nz_search, 2) ;  // number of domains to search for
00263                        // the enthalpy isosurface
00264     par_adapt.add_int(adapt_flag, 3) ; // 1 = performs the full computation, 
00265                        // 0 = performs only the rescaling by 
00266                        // the factor alpha_r
00267     par_adapt.add_int(j_b, 4) ;        // theta index of the collocation point 
00268                            // (theta_*, phi_*)
00269     par_adapt.add_int(k_b, 5) ;        // theta index of the collocation point 
00270                            // (theta_*, phi_*)
00271 
00272     par_adapt.add_int_mod(niter, 0) ;  // number of iterations actually used in 
00273                        // the secant method
00274     
00275     par_adapt.add_double(precis_adapt, 0) ; // required absolute precision in 
00276                     // the determination of zeros by 
00277                     // the secant method
00278     par_adapt.add_double(reg_map, 1) ;  // 1. = regular mapping, 0 = contracting mapping
00279     
00280     par_adapt.add_double(alpha_r, 2) ;  // factor by which all the radial 
00281                     // distances will be multiplied 
00282            
00283     // Enthalpy values for the adaptation
00284     Tbl ent_limit(nzet) ; 
00285     if (pent_limit != 0x0) ent_limit = *pent_limit ; 
00286            
00287     par_adapt.add_tbl(ent_limit, 0) ;   // array of values of the field ent 
00288                         // to define the isosurfaces.              
00289 
00290       double* bornes = new double[nz+1] ;
00291       bornes[0] = 0. ; 
00292 
00293       for(int l=0; l<nz; l++) {
00294  
00295     bornes[l+1] = mpaff.get_alpha()[l]  + mpaff.get_beta()[l] ;     
00296 
00297       } 
00298       bornes[nz] = __infinity ; 
00299  
00300       Map_et mp0(*mg, bornes) ;
00301  
00302         mp0 = mpaff; 
00303         mp0.adapt(ent(), par_adapt) ; 
00304 
00305         //Map_af mpaff_prev (mpaff) ; 
00306 
00307         double alphal, betal ; 
00308 
00309         for(int l=0; l<nz; l++) { 
00310 
00311           alphal = mp0.get_alpha()[l] ; 
00312           betal  = mp0.get_beta()[l] ;
00313  
00314       mpaff.set_alpha(alphal, l) ; 
00315           mpaff.set_beta(betal, l) ;
00316 
00317         } 
00318  
00319 
00320         //mbtest 
00321         int num_r1 = mg->get_nr(0) - 1;        
00322   
00323         cout << "Pressure difference:" << get_press()()(0,0,0,num_r1) - get_press()()(1,0,0,0) << endl ; 
00324     cout << "Difference in enthalpies at the domain boundary:" << endl ;
00325         cout << get_ent()()(0,0,0,num_r1) << endl ; 
00326         cout << get_ent()()(1,0,0,0) << endl ;
00327 
00328         cout << "Enthalpy difference: " << get_ent()()(0,0,0,num_r1) - get_ent()()(1,0,0,0) << endl ;
00329 
00330     // Computation of the enthalpy at the new grid points
00331         //----------------------------------------------------                     
00332 
00333         //mpaff.reevaluate(&mpaff_prev, nzet+1, ent.set()) ;
00334 
00335     } 
00336 
00337     //---------------------
00338     // Equation of state
00339     //---------------------
00340     
00341     equation_of_state() ; 
00342     
00343     if (relativistic) {
00344         
00345         //----------------------------
00346         // Equation for beta = ln(AN)
00347         //----------------------------
00348         
00349         mpaff.dsdr(logn(), dlogn) ; 
00350         mpaff.dsdr(beta_auto(), dbeta) ; 
00351         
00352         source = 3 * qpig * a_car * press ;
00353         
00354         source = source() 
00355              - 0.5 * (  dlogn * dlogn + dbeta * dbeta ) ;
00356     
00357         source.set_std_base() ;     // Sets the standard spectral bases. 
00358 
00359         beta_auto.set_etat_qcq() ; 
00360              
00361         mpaff.poisson(source(), par_nul, beta_auto.set()) ; 
00362         
00363 
00364         // Metric coefficient A^2 update
00365         
00366         a_car = exp(2*(beta_auto - logn)) ;
00367         
00368     }
00369     
00370     // Relative difference with enthalpy at the previous step
00371     // ------------------------------------------------------
00372     
00373     diff_ent = norme( diffrel(ent(), ent_jm1()) ) / nzet ; 
00374 
00375     // Next step
00376     // ---------
00377     
00378     ent_jm1 = ent ; 
00379 
00380 
00381     }  // End of iteration loop 
00382     
00383     //=========================================================================
00384     //          End of iteration
00385     //=========================================================================
00386 
00387 
00388     // The mapping is transfered to that of the star:
00389     // ----------------------------------------------
00390     mp = mpaff ; 
00391     
00392     
00393     // Sets value to all the Tenseur's of the star
00394     // -------------------------------------------
00395     
00396     // ... hydro 
00397     ent.annule(nzet, nz-1) ;    // enthalpy set to zero at the exterior of 
00398                 // the star
00399     ener_euler = ener ; 
00400     s_euler = 3 * press ;
00401     gam_euler = 1 ;  
00402     u_euler = 0 ; 
00403     
00404     // ... metric
00405     nnn = exp( unsurc2 * logn ) ; 
00406     nnn.set_std_base() ;
00407     shift = 0 ; 
00408     a_car.set_std_base() ;
00409 
00410     // Info printing
00411     // -------------
00412     
00413     cout << endl 
00414      << "Characteristics of the star obtained by Etoile::equilibrium_spher : " 
00415      << endl 
00416      << "-----------------------------------------------------------------" 
00417      << endl ; 
00418 
00419     double ray = mp.val_r(l_b, 1., M_PI/2., 0) ; 
00420     cout << "Coordinate radius  :       " << ray / km << " km" << endl ; 
00421 
00422     double rcirc = ray * sqrt( a_car()(l_b, k_b, j_b, i_b) ) ; 
00423     
00424     double compact = qpig/(4.*M_PI) * mass_g() / rcirc ; 
00425 
00426     cout << "Circumferential radius R : " << rcirc/km  << " km" << endl ;
00427     cout << "Baryon mass :       " << mass_b()/msol << " Mo" << endl ;
00428     cout << "Gravitational mass M :  " << mass_g()/msol << " Mo" << endl ;
00429     cout << "Compacity parameter GM/(c^2 R) : " << compact << endl ;
00430 
00431 
00432     //-----------------
00433     // Virial theorem
00434     //-----------------
00435     
00436     //... Pressure term
00437 
00438     source = qpig * a_car * sqrt(a_car) * s_euler ; 
00439     source.set_std_base() ;     
00440     double vir_mat = source().integrale() ; 
00441     
00442     //... Gravitational term
00443 
00444     Cmp tmp = beta_auto() - logn() ; 
00445 
00446     source =  - ( logn().dsdr() * logn().dsdr() 
00447               - 0.5 * tmp.dsdr() * tmp.dsdr() ) 
00448             * sqrt(a_car())  ; 
00449 
00450     source.set_std_base() ;     
00451     double vir_grav = source().integrale() ; 
00452 
00453     //... Relative error on the virial identity GRV3
00454     
00455     double grv3 = ( vir_mat + vir_grav ) / vir_mat ;
00456 
00457     cout << "Virial theorem GRV3 : " << endl ; 
00458     cout << "     3P term    : " << vir_mat << endl ; 
00459     cout << "     grav. term : " << vir_grav << endl ; 
00460     cout << "     relative error : " << grv3 << endl ; 
00461     
00462     if (nzet > 1) {
00463       cout.precision(10) ;
00464 
00465       for (int ltrans = 0; ltrans < nzet-1; ltrans++) {
00466     cout << endl << "Values at boundary between domains no. " << ltrans << " and " <<   ltrans+1 << " for theta = pi/2 and phi = 0 :" << endl ;
00467 
00468     double rt1 = mp.val_r(ltrans, 1., M_PI/2, 0.) ; 
00469     double rt2 = mp.val_r(ltrans+1, -1., M_PI/2, 0.) ; 
00470     cout << "   Coord. r [km] (left, right, rel. diff) : " 
00471       << rt1 / km << "  " << rt2 / km << "  " << (rt2 - rt1)/rt1  << endl ; 
00472   
00473     int ntm1 = mg->get_nt(ltrans) - 1; 
00474     int nrm1 = mg->get_nr(ltrans) - 1 ; 
00475     double ent1 = ent()(ltrans, 0, ntm1, nrm1) ; 
00476     double ent2 = ent()(ltrans+1, 0, ntm1, 0) ; 
00477       cout << "   Enthalpy (left, right, rel. diff) : " 
00478         << ent1 << "  " << ent2 << "  " << (ent2-ent1)/ent1  << endl ; 
00479 
00480     double press1 = press()(ltrans, 0, ntm1, nrm1) ; 
00481     double press2 = press()(ltrans+1, 0, ntm1, 0) ; 
00482       cout << "   Pressure (left, right, rel. diff) : " 
00483       << press1 << "  " << press2 << "  " << (press2-press1)/press1 << endl ; 
00484 
00485     double nb1 = nbar()(ltrans, 0, ntm1, nrm1) ; 
00486     double nb2 = nbar()(ltrans+1, 0, ntm1, 0) ; 
00487       cout << "   Baryon density (left, right, rel. diff) : " 
00488       << nb1 << "  " << nb2 << "  " << (nb2-nb1)/nb1  << endl ; 
00489       }
00490     }
00491 
00492 
00493 /*    double r_max = 1.2 * ray_eq() ; 
00494     des_profile(nbar(), 0., r_max, M_PI/2, 0., "n", "Baryon density") ; 
00495     des_profile(ener(), 0., r_max, M_PI/2, 0., "e", "Energy density") ; 
00496     des_profile(press(), 0., r_max, M_PI/2, 0., "p", "Pressure") ; 
00497     des_profile(ent(), 0., r_max, M_PI/2, 0., "H", "Enthalpy") ; 
00498 */
00499    
00500 }

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