star_equil_spher.C
/*
* Method of class Star to compute a static spherical configuration.
*
* (see file star.h for documentation).
*
*/
/*
* Copyright (c) 2004 Francois Limousin
*
* This file is part of LORENE.
*
* LORENE is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* LORENE is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with LORENE; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*/
char star_equil_spher_C[] = "$Header: /cvsroot/Lorene/C++/Source/Star/star_equil_spher.C,v 1.15 2014/10/13 08:53:39 j_novak Exp $" ;
/*
* $Id: star_equil_spher.C,v 1.15 2014/10/13 08:53:39 j_novak Exp $
* $Log: star_equil_spher.C,v $
* Revision 1.15 2014/10/13 08:53:39 j_novak
* Lorene classes and functions now belong to the namespace Lorene.
*
* Revision 1.14 2010/10/18 20:16:10 m_bejger
* Commented-out the reevaluation of the mapping for the case of many domains inside the star
*
* Revision 1.13 2010/10/18 18:56:33 m_bejger
* Changed to allow initial data with more than one domain in the star
*
* Revision 1.12 2005/09/14 12:30:52 f_limousin
* Saving of fields lnq and logn in class Star.
*
* Revision 1.11 2005/09/13 19:38:31 f_limousin
* Reintroduction of the resolution of the equations in cartesian coordinates.
*
* Revision 1.10 2005/02/17 17:32:35 f_limousin
* Change the name of some quantities to be consistent with other classes
* (for instance nnn is changed to nn, shift to beta, beta to lnq...)
*
* Revision 1.9 2004/06/22 12:45:31 f_limousin
* Improve the convergence
*
* Revision 1.8 2004/06/07 16:27:47 f_limousin
* Add the computation of virial error.
*
* Revision 1.6 2004/04/08 16:33:42 f_limousin
* The new variable is ln(Q) instead of Q=psi^2*N. It improves the
* convergence of the code.
*
* Revision 1.5 2004/03/25 10:29:26 j_novak
* All LORENE's units are now defined in the namespace Unites (in file unites.h).
*
* Revision 1.4 2004/02/27 09:57:55 f_limousin
* We now update the metric gamma at the end of this routine for
* the calculus of mass_b and mass_g.
*
* Revision 1.3 2004/02/21 17:05:13 e_gourgoulhon
* Method Scalar::point renamed Scalar::val_grid_point.
* Method Scalar::set_point renamed Scalar::set_grid_point.
*
* Revision 1.2 2004/01/20 15:20:35 f_limousin
* First version
*
*
* $Header: /cvsroot/Lorene/C++/Source/Star/star_equil_spher.C,v 1.15 2014/10/13 08:53:39 j_novak Exp $
*
*/
// Headers C
#include "math.h"
// Headers Lorene
#include "tenseur.h"
#include "star.h"
#include "param.h"
#include "graphique.h"
#include "nbr_spx.h"
#include "unites.h"
namespace Lorene {
void Star::equilibrium_spher(double ent_c,
double precis,
const Tbl* pent_limit){
// Fundamental constants and units
// -------------------------------
using namespace Unites ;
// Initializations
// ---------------
const Mg3d* mg = mp.get_mg() ;
int nz = mg->get_nzone() ; // total number of domains
// Index of the point at phi=0, theta=pi/2 at the surface of the star:
int l_b = nzet - 1 ;
int i_b = mg->get_nr(l_b) - 1 ;
int j_b = mg->get_nt(l_b) - 1 ;
int k_b = 0 ;
// Value of the enthalpy defining the surface of the star
double ent_b = 0 ;
// Initialization of the enthalpy field to the constant value ent_c :
ent = ent_c ;
ent.annule(nzet, nz-1) ;
// Corresponding profiles of baryon density, energy density and pressure
equation_of_state() ;
Scalar a_car(mp) ;
a_car = 1 ;
lnq = 0 ;
lnq.std_spectral_base() ;
// Auxiliary quantities
// --------------------
// Affine mapping for solving the Poisson equations
Map_af mpaff(mp);
Param par_nul ; // Param (null) for Map_af::poisson.
Scalar ent_jm1(mp) ; // Enthalpy at previous step
ent_jm1 = 0 ;
Scalar source(mp) ;
Scalar logn_quad(mp) ;
Scalar logn_mat(mp) ;
logn_mat = 0 ;
logn = 0 ;
logn_quad = 0 ;
Scalar dlogn(mp) ;
Scalar dlnq(mp) ;
double diff_ent = 1 ;
int mermax = 200 ; // Max number of iterations
//=========================================================================
// Start of iteration
//=========================================================================
for(int mer=0 ; (diff_ent > precis) && (mer<mermax) ; mer++ ) {
double alpha_r = 1 ;
cout << "-----------------------------------------------" << endl ;
cout << "step: " << mer << endl ;
cout << "alpha_r: " << alpha_r << endl ;
cout << "diff_ent = " << diff_ent << endl ;
//-----------------------------------------------------
// Resolution of Poisson equation for ln(N)
//-----------------------------------------------------
// Matter part of ln(N)
// --------------------
source = a_car * (ener + 3.*press) ;
source.set_dzpuis(4) ;
Cmp source_logn_mat (source) ;
Cmp logn_mat_cmp (logn_mat) ;
logn_mat_cmp.set_etat_qcq() ;
mpaff.poisson(source_logn_mat, par_nul, logn_mat_cmp) ;
logn_mat = logn_mat_cmp ;
// NB: at this stage logn is in machine units, not in c^2
// Quadratic part of ln(N)
// -----------------------
mpaff.dsdr(logn, dlogn) ;
mpaff.dsdr(lnq, dlnq) ;
source = - dlogn * dlnq ;
Cmp source_logn_quad (source) ;
Cmp logn_quad_cmp (logn_quad) ;
logn_quad_cmp.set_etat_qcq() ;
mpaff.poisson(source_logn_quad, par_nul, logn_quad_cmp) ;
logn_quad = logn_quad_cmp ;
//-----------------------------------------------------
// Computation of the new radial scale
//-----------------------------------------------------
// alpha_r (r = alpha_r r') is determined so that the enthalpy
// takes the requested value ent_b at the stellar surface
double nu_mat0_b = logn_mat.val_grid_point(l_b, k_b, j_b, i_b) ;
double nu_mat0_c = logn_mat.val_grid_point(0, 0, 0, 0) ;
double nu_quad0_b = logn_quad.val_grid_point(l_b, k_b, j_b, i_b) ;
double nu_quad0_c = logn_quad.val_grid_point(0, 0, 0, 0) ;
double alpha_r2 = ( ent_c - ent_b - nu_quad0_b + nu_quad0_c )
/ ( qpig*(nu_mat0_b - nu_mat0_c) ) ;
alpha_r = sqrt(alpha_r2) ;
// One domain inside the star:
// ---------------------------
if(nzet==1) mpaff.homothetie( alpha_r ) ;
//--------------------
// First integral
//--------------------
// Gravitation potential in units c^2 :
logn_mat = alpha_r2*qpig * logn_mat ;
logn = logn_mat + logn_quad ;
// Enthalpy in all space
double logn_c = logn.val_grid_point(0, 0, 0, 0) ;
ent = ent_c - logn + logn_c ;
// Two or more domains inside the star:
// ------------------------------------
if(nzet>1) {
// Parameters for the function Map_et::adapt
// -----------------------------------------
Param par_adapt ;
int nitermax = 100 ;
int niter ;
int adapt_flag = 1 ; // 1 = performs the full computation,
// 0 = performs only the rescaling by
// the factor alpha_r
int nz_search = nzet + 1 ; // Number of domains for searching the enthalpy
// isosurfaces
int nzadapt = nzet ;
//cout << "no. of domains where the ent adjustment will be done: " << nzet << endl ;
//cout << "ent limits: " << ent_limit << endl ;
double precis_adapt = 1.e-14 ;
double reg_map = 1. ; // 1 = regular mapping, 0 = contracting mapping
par_adapt.add_int(nitermax, 0) ; // maximum number of iterations to
// locate zeros by the secant method
par_adapt.add_int(nzadapt, 1) ; // number of domains where the adjustment
// to the isosurfaces of ent is to be
// performed
par_adapt.add_int(nz_search, 2) ; // number of domains to search for
// the enthalpy isosurface
par_adapt.add_int(adapt_flag, 3) ; // 1 = performs the full computation,
// 0 = performs only the rescaling by
// the factor alpha_r
par_adapt.add_int(j_b, 4) ; // theta index of the collocation point
// (theta_*, phi_*)
par_adapt.add_int(k_b, 5) ; // theta index of the collocation point
// (theta_*, phi_*)
par_adapt.add_int_mod(niter, 0) ; // number of iterations actually used in
// the secant method
par_adapt.add_double(precis_adapt, 0) ; // required absolute precision in
// the determination of zeros by
// the secant method
par_adapt.add_double(reg_map, 1) ; // 1. = regular mapping, 0 = contracting mapping
par_adapt.add_double(alpha_r, 2) ; // factor by which all the radial
// distances will be multiplied
// Enthalpy values for the adaptation
Tbl ent_limit(nzet) ;
if (pent_limit != 0x0) ent_limit = *pent_limit ;
par_adapt.add_tbl(ent_limit, 0) ; // array of values of the field ent
// to define the isosurfaces.
double* bornes = new double[nz+1] ;
bornes[0] = 0. ;
for(int l=0; l<nz; l++) {
bornes[l+1] = mpaff.get_alpha()[l] + mpaff.get_beta()[l] ;
}
bornes[nz] = __infinity ;
Map_et mp0(*mg, bornes) ;
mp0 = mpaff;
mp0.adapt(ent, par_adapt) ;
//Map_af mpaff_prev (mpaff) ;
double alphal, betal ;
for(int l=0; l<nz; l++) {
alphal = mp0.get_alpha()[l] ;
betal = mp0.get_beta()[l] ;
mpaff.set_alpha(alphal, l) ;
mpaff.set_beta(betal, l) ;
}
// testing printout
//int num_r1 = mg->get_nr(0) - 1;
//cout << "Pressure difference:" << press.val_grid_point(0,0,0,num_r1)
//- press.val_grid_point(1,0,0,0) << endl ;
//cout << "Difference in enthalpies at the domain boundary:" << endl ;
//cout << ent.val_grid_point(0,0,0,num_r1) << endl ;
//cout << ent.val_grid_point(1,0,0,0) << endl ;
//cout << "Enthalpy difference: " << ent.val_grid_point(0,0,0,num_r1)
//- ent.val_grid_point(1,0,0,0) << endl ;
// Computation of the enthalpy at the new grid points
//----------------------------------------------------
//mpaff.reevaluate(&mpaff_prev, nzet+1, ent) ;
}
//---------------------
// Equation of state
//---------------------
equation_of_state() ;
//---------------------
// Equation for lnq_auto
//---------------------
mpaff.dsdr(logn, dlogn) ;
mpaff.dsdr(lnq, dlnq) ;
source = 3 * qpig * a_car * press ;
source = source - 0.5 * ( dlnq * dlnq + dlogn * dlogn ) ;
source.std_spectral_base() ;
Cmp source_lnq (source) ;
Cmp lnq_cmp (logn_quad) ;
lnq_cmp.set_etat_qcq() ;
mpaff.poisson(source_lnq, par_nul, lnq_cmp) ;
lnq = lnq_cmp ;
// Metric coefficient psi4 update
nn = exp( logn ) ;
Scalar qq = exp( lnq ) ;
qq.std_spectral_base() ;
a_car = qq * qq / ( nn * nn ) ;
a_car.std_spectral_base() ;
// Relative difference with enthalpy at the previous step
// ------------------------------------------------------
diff_ent = norme( diffrel(ent, ent_jm1) ) / nzet ;
// Next step
// ---------
ent_jm1 = ent ;
} // End of iteration loop
//=========================================================================
// End of iteration
//=========================================================================
// The mapping is transfered to that of the star:
// ----------------------------------------------
mp = mpaff ;
// Sets value to all the Tenseur's of the star
// -------------------------------------------
nn = exp( logn ) ;
Scalar qq = exp( lnq ) ;
qq.std_spectral_base() ;
a_car = qq * qq / ( nn * nn ) ;
Sym_tensor gamma_cov(mp, COV, mp.get_bvect_cart()) ;
gamma_cov.set_etat_zero() ;
for (int i=1; i<=3; i++){
gamma_cov.set(i,i) = a_car ;
}
gamma = gamma_cov ;
// ... hydro
ent.annule(nzet, nz-1) ; // enthalpy set to zero at the exterior of
// the star
ener_euler = ener ;
s_euler = 3 * press ;
gam_euler = 1 ;
for(int i=1; i<=3; i++) u_euler.set(i) = 0 ;
// Info printing
// -------------
cout << endl
<< "Characteristics of the star obtained by Etoile::equilibrium_spher : "
<< endl
<< "-----------------------------------------------------------------"
<< endl ;
double ray = mp.val_r(l_b, 1., M_PI/2., 0) ;
cout << "Coordinate radius : " << ray / km << " km" << endl ;
double rcirc = ray * sqrt(a_car.val_grid_point(l_b, k_b, j_b, i_b) ) ;
double compact = qpig/(4.*M_PI) * mass_g() / rcirc ;
cout << "Circumferential radius R : " << rcirc/km << " km" << endl ;
cout << "Baryon mass : " << mass_b()/msol << " Mo" << endl ;
cout << "Gravitational mass M : " << mass_g()/msol << " Mo" << endl ;
cout << "Compacity parameter GM/(c^2 R) : " << compact << endl ;
//-----------------
// Virial theorem
//-----------------
//... Pressure term
source = qpig * a_car * sqrt(a_car) * s_euler ;
source.std_spectral_base() ;
double vir_mat = source.integrale() ;
//... Gravitational term
Scalar tmp = lnq - logn ;
source = - ( logn.dsdr() * logn.dsdr()
- 0.5 * tmp.dsdr() * tmp.dsdr() )
* sqrt(a_car) ;
source.std_spectral_base() ;
double vir_grav = source.integrale() ;
//... Relative error on the virial identity GRV3
double grv3 = ( vir_mat + vir_grav ) / vir_mat ;
cout << "Virial theorem GRV3 : " << endl ;
cout << " 3P term : " << vir_mat << endl ;
cout << " grav. term : " << vir_grav << endl ;
cout << " relative error : " << grv3 << endl ;
// To be compatible with class Etoile :
//logn = logn - logn_quad ;
}
}
Lorene::Cmp
Component of a tensorial field *** DEPRECATED : use class Scalar instead ***.
Definition cmp.h:446
Lorene::Cmp::set_etat_qcq
void set_etat_qcq()
Sets the logical state to ETATQCQ (ordinary state).
Definition cmp.C:304
Lorene::Map_af
Affine radial mapping.
Definition map.h:2027
Lorene::Map_af::get_beta
const double * get_beta() const
Returns the pointer on the array beta.
Definition map_af.C:481
Lorene::Map_af::get_alpha
const double * get_alpha() const
Returns the pointer on the array alpha.
Definition map_af.C:477
Lorene::Map_af::set_beta
void set_beta(double beta0, int l)
Modifies the value of in domain no. l.
Definition map_af.C:641
Lorene::Map_af::homothetie
virtual void homothetie(double lambda)
Sets a new radial scale.
Definition map_af.C:537
Lorene::Map_af::poisson
virtual void poisson(const Cmp &source, Param &par, Cmp &uu) const
Computes the solution of a scalar Poisson equation.
Definition map_af_poisson.C:100
Lorene::Map_af::dsdr
virtual void dsdr(const Cmp &ci, Cmp &resu) const
Computes of a Cmp.
Definition map_af_deriv.C:279
Lorene::Map_af::set_alpha
void set_alpha(double alpha0, int l)
Modifies the value of in domain no. l.
Definition map_af.C:630
Lorene::Map_et
Radial mapping of rather general form.
Definition map.h:2752
Lorene::Map_et::get_alpha
const double * get_alpha() const
Returns a pointer on the array alpha (values of in each domain).
Definition map_et.C:1026
Lorene::Map_et::get_beta
const double * get_beta() const
Returns a pointer on the array beta (values of in each domain).
Definition map_et.C:1030
Lorene::Map_et::adapt
virtual void adapt(const Cmp &ent, const Param &par, int nbr_filtre=0)
Adaptation of the mapping to a given scalar field.
Definition map_et_adapt.C:108
Lorene::Mg3d
Multi-domain grid.
Definition grilles.h:273
Lorene::Mg3d::get_nt
int get_nt(int l) const
Returns the number of points in the co-latitude direction ( ) in domain no. l.
Definition grilles.h:457
Lorene::Mg3d::get_nzone
int get_nzone() const
Returns the number of domains.
Definition grilles.h:448
Lorene::Mg3d::get_nr
int get_nr(int l) const
Returns the number of points in the radial direction ( ) in domain no. l.
Definition grilles.h:452
Lorene::Param
Parameter storage.
Definition param.h:125
Lorene::Param::add_double
void add_double(const double &x, int position=0)
Adds the the address of a new double to the list.
Definition param.C:315
Lorene::Param::add_int_mod
void add_int_mod(int &n, int position=0)
Adds the address of a new modifiable int to the list.
Definition param.C:385
Lorene::Param::add_int
void add_int(const int &n, int position=0)
Adds the address of a new int to the list.
Definition param.C:246
Lorene::Param::add_tbl
void add_tbl(const Tbl &ti, int position=0)
Adds the address of a new Tbl to the list.
Definition param.C:522
Lorene::Scalar
Tensor field of valence 0 (or component of a tensorial field).
Definition scalar.h:387
Lorene::Scalar::integrale
double integrale() const
Computes the integral over all space of *this .
Definition scalar_integ.C:61
Lorene::Scalar::std_spectral_base
virtual void std_spectral_base()
Sets the spectral bases of the Valeur va to the standard ones for a scalar field.
Definition scalar.C:784
Lorene::Scalar::val_grid_point
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:637
Lorene::Scalar::dsdr
const Scalar & dsdr() const
Returns of *this .
Definition scalar_deriv.C:113
Lorene::Scalar::set_dzpuis
void set_dzpuis(int)
Modifies the dzpuis flag.
Definition scalar.C:808
Lorene::Star::ener
Scalar ener
Total energy density in the fluid frame.
Definition star.h:193
Lorene::Star::mass_g
virtual double mass_g() const =0
Gravitational mass.
Definition star_global.C:327
Lorene::Star::logn
Scalar logn
Logarithm of the lapse N .
Definition star.h:222
Lorene::Star::nn
Scalar nn
Lapse function N .
Definition star.h:225
Lorene::Star::equilibrium_spher
virtual void equilibrium_spher(double ent_c, double precis=1.e-14, const Tbl *pent_limit=0x0)
Computes a spherical static configuration.
Definition star_equil_spher.C:95
Lorene::Star::ener_euler
Scalar ener_euler
Total energy density in the Eulerian frame.
Definition star.h:198
Lorene::Star::equation_of_state
void equation_of_state()
Computes the proper baryon and energy density, as well as pressure from the enthalpy.
Definition star.C:462
Lorene::Star::gam_euler
Scalar gam_euler
Lorentz factor between the fluid and Eulerian observers.
Definition star.h:204
Lorene::Star::s_euler
Scalar s_euler
Trace of the stress scalar in the Eulerian frame.
Definition star.h:201
Lorene::Star::gamma
Metric gamma
3-metric
Definition star.h:235
Lorene::Star::press
Scalar press
Fluid pressure.
Definition star.h:194
Lorene::Star::ent
Scalar ent
Log-enthalpy.
Definition star.h:190
Lorene::Star::u_euler
Vector u_euler
Fluid 3-velocity with respect to the Eulerian observer.
Definition star.h:207
Lorene::Star::mp
Map & mp
Mapping associated with the star.
Definition star.h:180
Lorene::Star::nzet
int nzet
Number of domains of *mp occupied by the star.
Definition star.h:183
Lorene::Star::mass_b
virtual double mass_b() const =0
Baryon mass.
Definition star_global.C:307
Lorene::Sym_tensor
Class intended to describe valence-2 symmetric tensors.
Definition sym_tensor.h:223
Lorene::Tbl
Basic array class.
Definition tbl.h:161
Lorene::sqrt
Cmp sqrt(const Cmp &)
Square root.
Definition cmp_math.C:220
Lorene::exp
Cmp exp(const Cmp &)
Exponential.
Definition cmp_math.C:270
Lorene::diffrel
Tbl diffrel(const Cmp &a, const Cmp &b)
Relative difference between two Cmp (norme version).
Definition cmp_math.C:504
Lorene::norme
Tbl norme(const Cmp &)
Sums of the absolute values of all the values of the Cmp in each domain.
Definition cmp_math.C:481
Lorene::Tensor::set_etat_zero
virtual void set_etat_zero()
Sets the logical state of all components to ETATZERO (zero state).
Definition tensor.C:497
Lorene::Tensor::set
Scalar & set(const Itbl &ind)
Returns the value of a component (read/write version).
Definition tensor.C:654
Lorene
Lorene prototypes.
Definition app_hor.h:64
Unites
Standard units of space, time and mass.