00001 /* 00002 ------------------------------------------------------------------- 00003 00004 Copyright (C) 2006, 2007, 2008, 2009, Andrew W. Steiner 00005 00006 This file is part of O2scl. 00007 00008 O2scl is free software; you can redistribute it and/or modify 00009 it under the terms of the GNU General Public License as published by 00010 the Free Software Foundation; either version 3 of the License, or 00011 (at your option) any later version. 00012 00013 O2scl is distributed in the hope that it will be useful, 00014 but WITHOUT ANY WARRANTY; without even the implied warranty of 00015 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00016 GNU General Public License for more details. 00017 00018 You should have received a copy of the GNU General Public License 00019 along with O2scl. If not, see <http://www.gnu.org/licenses/>. 00020 00021 ------------------------------------------------------------------- 00022 */ 00023 #ifndef O2SCL_TOV_SOLVE_H 00024 #define O2SCL_TOV_SOLVE_H 00025 00026 #include <o2scl/tov_eos.h> 00027 #include <o2scl/smart_interp.h> 00028 #include <o2scl/table_units.h> 00029 00030 #ifndef DOXYGENP 00031 namespace o2scl { 00032 #endif 00033 00034 /** 00035 \brief Class to solve the Tolman-Oppenheimer-Volkov equations 00036 00037 \hline 00038 <b>Mathematical background:</b> 00039 00040 The TOV equations (i.e. Einstein's equations for a static 00041 spherically symmetric object) are 00042 \f[ 00043 \frac{d m}{d r} = 4 \pi r^2 \varepsilon 00044 \f] 00045 \f[ 00046 \frac{d P}{d r} = - \frac{G \varepsilon m}{r^2} 00047 \left( 1+\frac{P}{\varepsilon}\right) 00048 \left( 1+\frac{4 \pi P r^3}{m} \right) 00049 \left( 1-\frac{2 G m}{r}\right)^{-1} 00050 \f] 00051 where \f$r\f$ is the radial coordinate, \f$m(r)\f$ is the mass 00052 enclosed within a radius \f$r\f$, and \f$\varepsilon(r)\f$ and 00053 \f$P(r)\f$ are the energy density and pressure at \f$r\f$, and 00054 \f$G\f$ is the gravitational constant. The boundary conditions 00055 are \f$m(r=0)=0\f$ the condition \f$P(r=R)=0\f$ for some fixed 00056 radius \f$R\f$. These boundary conditions give a series of 00057 solutions to the TOV equations as a function of the radius, 00058 although they do not necessarily have a solution for all radii. 00059 00060 The gravitational mass is given by 00061 \f[ 00062 M_G = \int_0^R 4 \pi r^2 \varepsilon d r 00063 \f] 00064 while the baryonic mass is given by 00065 \f[ 00066 M_B = \int_0^R 4 \pi r^2 n_B m_B 00067 \left(1-\frac{G m}{r}\right)^{-1/2} d r 00068 \f] 00069 where \f$n_B(r)\f$ is the baryon number density at radius 00070 \f$r\f$ and \f$m_B\f$ is the mass of one baryon. 00071 00072 The gravitational potential, \f$\Phi(r)\f$ can be determined from 00073 \f[ 00074 \frac{d \Phi}{d r} = - \frac{1}{\varepsilon} 00075 \frac{ d P}{d r} \left(1+\frac{P}{\varepsilon}\right)^{-1} 00076 \f] 00077 00078 The proper boundary condition for the gravitational potential 00079 is 00080 \f[ 00081 \Phi(r=R) = \frac{1}{2} \ln \left(1-\frac{2 G M}{R} \right) 00082 \f] 00083 00084 The surface gravity is computed as 00085 \f[ 00086 g = \frac{G M }{R^2}\left(1-\frac{2 G M}{R}\right)^{-1/2} 00087 \f] 00088 which is given in inverse kilometers and the redshift is 00089 \f[ 00090 z = \left(1-\frac{2 G M}{R}\right)^{-1/2} - 1 00091 \f] 00092 which is unitless. 00093 00094 \hline 00095 <b>General usage notes:</b> 00096 00097 The equation of state may be changed at any time, by specifying 00098 the appropriate tov_eos object 00099 00100 Screen output: 00101 - \c verbose=0 - Nothing 00102 - \c verbose=1 - Basic information 00103 - \c verbose=2 - For each profile computation, report solution 00104 information at every kilometer. 00105 - \c verbose=3 - Report profile information at every 20 grid points. A 00106 keypress is required after each profile. 00107 00108 \hline 00109 <b>Accuracy:</b> 00110 00111 The present code, as demonstrated in the tests, gives the 00112 correct central pressure and energy density of the analytical 00113 solution by Buchdahl to within less than 1 \part in \f$ 10^5 \f$. 00114 00115 \hline 00116 <b>Other details and todos:</b> 00117 00118 \note The function star_fun() returns <tt>gsl_efailed</tt> 00119 without calling the error handler in the case that the solver 00120 can recover gracefully from, for example, a negative pressure. 00121 00122 \todo 00123 - baryon mass doesn't work for fixed() (This may be fixed. We should 00124 make sure it's tested.) 00125 - Combine maxoutsize and kmax? 00126 - Document column naming issues 00127 - Document surface gravity and redshift 00128 00129 \comment 00130 To solve the calling of the error handler, I need to rewrite the 00131 adaptive stepper to simply stop if the base stepper makes a step 00132 which is too large. That demands creating a new version of 00133 gsl_astep::evolve_apply(). The question is how to communicate 00134 the information from the tov derivs() function to the new 00135 version of gsl_astep::evolve_apply(). An easy way would be to 00136 just create a new return value which indicates the step should 00137 be shortened, and just stop if the step becomes too short. 00138 Alternatively, instead of modifying evolve_apply(), we could 00139 just ensure the adaptive stepper bails out correctly if the 00140 stepper returns a nonzero value and then have the caller 00141 (starfun) take care of it. This would probably be better. We 00142 might have to make sure that gsl_astep does not set yout if the 00143 step fails. (3/27/09 - It looks like this might be fixed now?) 00144 \endcomment 00145 00146 \hline 00147 */ 00148 class tov_solve { 00149 public: 00150 00151 /// \name Basic properties 00152 //@{ 00153 /// mass 00154 double mass; 00155 /// radius 00156 double rad; 00157 /// baryonic mass 00158 double bmass; 00159 /// gravitational potential 00160 double gpot; 00161 //@} 00162 00163 /// \name Solution parameters 00164 /** 00165 These parameters can be changed at any time. 00166 */ 00167 //@{ 00168 /// Use general relativistic version (default true) 00169 bool generel; 00170 /** \brief calculate the gravitational potential and the enclosed 00171 baryon mass (default false) 00172 */ 00173 bool calcgpot; 00174 /// smallest allowed radial stepsize (default 1.0e-4) 00175 double hmin; 00176 /// largest allowed radial stepsize (default 0.05) 00177 double hmax; 00178 /// initial radial stepsize (default 4.0e-3) 00179 double hstart; 00180 /// control for output (default 1) 00181 int verbose; 00182 /// maximum radius for integration in km (default 60) 00183 double maxradius; 00184 //@} 00185 00186 /// \name Mass versus radius parameters 00187 00188 //@{ 00189 /// Beginning pressure (default 7.0e-7) 00190 double prbegin; 00191 /// Ending pressure (default 8.0e-3) 00192 double prend; 00193 /// Increment for pressure (default 1.1) 00194 double princ; 00195 /// Use 'princ' as a multiplier, not an additive increment (default true) 00196 bool logmode; 00197 /** \brief Guess for central pressure in solar masses per km3 00198 (default \f$ 5.2 \times 10^{-5} \f$) 00199 00200 This guess is used in the function fixed(). 00201 */ 00202 double prguess; 00203 /// Beginning pressure for maximum mass guess (default 7.0e-5) 00204 double max_begin; 00205 /// Ending pressure for maximum mass guess (default 5.0e-3) 00206 double max_end; 00207 /// Increment for pressure for maximum mass guess (default 1.3) 00208 double max_inc; 00209 //@} 00210 00211 /// \name Fixed mass parameters 00212 00213 //@{ 00214 /** 00215 \brief Target mass 00216 00217 Use negative values to indicate a mass measured relative to the 00218 maximum mass. For example, if the EOS has a maximum mass of 2.0, then 00219 -0.15 will give the profile of a 1.85 solar mass star. 00220 */ 00221 double tmass; 00222 //@} 00223 00224 /// \name Results 00225 00226 //@{ 00227 /** \brief Return the results data table 00228 */ 00229 table_units &get_results() {return out_table;} 00230 //@} 00231 00232 //-------------------------------------------- 00233 // Function prototypes 00234 00235 tov_solve(); 00236 00237 virtual ~tov_solve(); 00238 00239 /// \name Actual solution of equations 00240 //@{ 00241 /// Calculate the mass vs. radius curve 00242 int mvsr(); 00243 /// Calculate the profile of a star with fixed mass 00244 int fixed(double d_tmass); 00245 /// Calculate the profile of the maximum mass star 00246 int max(); 00247 //@} 00248 00249 /** 00250 \brief Check the solution (unfinished) 00251 */ 00252 int solution_check(); 00253 00254 /// Set units 00255 int set_units(double s_efactor=1.0, double s_pfactor=1.0, 00256 double s_nbfactor=1.0); 00257 00258 /** 00259 \brief Set units 00260 00261 Valid entries for the units of energy density and pressure are: 00262 - "g/cm^3" 00263 - "erg/cm^3" 00264 - "MeV/fm^3" 00265 - "fm^-4" 00266 - "Msun/km^3" (i.e. solar masses per cubic kilometer) 00267 00268 Valid entries for the units of baryon density are: 00269 - "m^-3" 00270 - "cm^-3" 00271 - "fm^-3" 00272 */ 00273 int set_units(std::string eunits="", std::string punits="", 00274 std::string nunits=""); 00275 00276 /** 00277 \brief Set maximum storage for integration 00278 00279 The variable \c s_kmax is the maximum number of radial 00280 integration stepsk while \c s_maxoutsize is the maximum number 00281 of points that will be output for any profile. 00282 00283 If \c s_kmax is less than zero, there is no limit on 00284 the number of radial steps. 00285 */ 00286 int set_kmax(int s_maxoutsize=400, int s_kmax=40000); 00287 00288 /// Set the EOS to use 00289 int set_eos(tov_eos &ter) { 00290 te=&ter; 00291 eos_set=true; 00292 return 0; 00293 } 00294 00295 /** 00296 \brief Set solver 00297 */ 00298 int set_mroot(mroot<int,mm_funct<int> > &s_mrp) 00299 {mroot_ptr=&s_mrp; return 0;}; 00300 00301 /** 00302 \brief Set minimizer 00303 */ 00304 int set_minimize(minimize<int,funct<int> > &s_mp) 00305 {min_ptr=&s_mp; return 0;}; 00306 00307 /** 00308 \brief Set the adaptive stepper 00309 */ 00310 int set_stepper(adapt_step<int,ode_funct<int> > &sap) 00311 {as_ptr=&sap; return 0;}; 00312 00313 /// The default minimizer 00314 gsl_min_brent<int,funct<int> > def_min; 00315 00316 /// The default solver 00317 gsl_mroot_hybrids<int,mm_funct<int> > def_solver; 00318 00319 /// The default adaptive stepper 00320 gsl_astep<int,ode_funct<int> > def_stepper; 00321 00322 /// If true, compute the angular velocity (default false) 00323 bool compute_ang_vel; 00324 00325 /// The angular velocity 00326 double cap_omega; 00327 00328 /// The schwarzchild radius in km 00329 double schwarz_km; 00330 00331 #ifndef DOXYGEN_INTERNAL 00332 00333 protected: 00334 00335 /** 00336 \brief Ensure \c col does not match strings in \c cnames 00337 */ 00338 int make_unique_name(std::string &col, 00339 std::vector<std::string> &cnames); 00340 00341 /// The EOS 00342 tov_eos *te; 00343 00344 /// True if the EOS has been set 00345 bool eos_set; 00346 00347 /** \brief Define some necessary I/O objects 00348 00349 \future Is this really required? 00350 */ 00351 base_ioc bio; 00352 00353 /// \name User EOS 00354 //@{ 00355 /// Units for energy density 00356 std::string eunits; 00357 /// Units for pressure 00358 std::string punits; 00359 /// Units for baryon density 00360 std::string nunits; 00361 /// unit conversion factor for energy density (default 1.0) 00362 double efactor; 00363 /// unit conversion factor for pressure (default 1.0) 00364 double pfactor; 00365 /// unit conversion factor for baryon density (default 1.0) 00366 double nfactor; 00367 //@} 00368 00369 /// maximum storage size (default 40000) 00370 int kmax; 00371 /// maximum size of output file (default 400) 00372 int maxoutsize; 00373 00374 /** 00375 \brief Smallest allowed pressure for integration (default: -100) 00376 00377 This can't be much 00378 smaller since we need to compute numbers near exp(-presmin) 00379 */ 00380 double presmin; 00381 00382 /// \name Integration storage 00383 //@{ 00384 ovector rky[6], rkx, rkdydx[6]; 00385 //@} 00386 00387 /// The output table 00388 table_units out_table; 00389 00390 /// The solver 00391 mroot<int,mm_funct<int> > *mroot_ptr; 00392 00393 /// The minimizer 00394 minimize<int,funct<int> > *min_ptr; 00395 00396 /// The default adaptive stepper 00397 adapt_step<int,ode_funct<int> > *as_ptr; 00398 00399 /// The ODE step function 00400 virtual int derivs(double x, size_t nv, const ovector_base &y, 00401 ovector_base &dydx, int &pa); 00402 00403 /// The ODE step function for the angular velocity 00404 virtual int derivs_ang_vel(double x, size_t nv, const ovector_base &y, 00405 ovector_base &dydx, int &pa); 00406 00407 /// Output a stellar profile 00408 virtual int profile_out(double xx); 00409 00410 /// The minimizer function to compute the maximum mass 00411 virtual double maxfun(double maxx, int &pa); 00412 00413 /** 00414 \brief The solver function to compute the stellar profile 00415 00416 */ 00417 virtual int starfun(size_t ndvar, const ovector_base &ndx, 00418 ovector_base &ndy, int &pa); 00419 00420 /// Compute the angular velocity 00421 int ang_vel(); 00422 00423 /// Interpolation object for derivs_ang_vel() 00424 smart_interp<> smi; 00425 00426 #endif 00427 00428 }; 00429 00430 #ifndef DOXYGENP 00431 } 00432 #endif 00433 00434 #endif 00435 00436
Documentation generated with Doxygen and provided under the GNU Free Documentation License. See License Information for details.
Project hosting provided by
,
O2scl Sourceforge Project Page