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