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_EOS_H 00024 #define O2SCL_TOV_EOS_H 00025 00026 #include <cmath> 00027 #include <iostream> 00028 #include <fstream> 00029 00030 #include <o2scl/constants.h> 00031 #include <o2scl/funct.h> 00032 #include <o2scl/multi_funct.h> 00033 #include <o2scl/mm_funct.h> 00034 #include <o2scl/lib_settings.h> 00035 #include <o2scl/collection.h> 00036 #include <o2scl/table_units.h> 00037 #include <o2scl/base_ioc.h> 00038 00039 #include <o2scl/mroot.h> 00040 #include <o2scl/odestep.h> 00041 #include <o2scl/minimize.h> 00042 #include <o2scl/gsl_min_brent.h> 00043 #include <o2scl/gsl_mroot_hybrids.h> 00044 #include <o2scl/ode_funct.h> 00045 #include <o2scl/gsl_astep.h> 00046 00047 #ifndef DOXYGENP 00048 namespace o2scl { 00049 #endif 00050 00051 /** 00052 \brief A EOS base class for the TOV solver 00053 */ 00054 class tov_eos { 00055 00056 public: 00057 00058 tov_eos() { 00059 baryon_column=false; 00060 verbose=1; 00061 } 00062 00063 virtual ~tov_eos() {} 00064 00065 /// control for output (default 1) 00066 int verbose; 00067 00068 /** 00069 \brief Given the pressure, produce the energy and number densities 00070 00071 If the baryon density is not specified, it should be set to 00072 zero or \ref baryon_column should be set to false 00073 */ 00074 virtual int get_eden(double P, double &e, double &nb) { 00075 return 0; 00076 } 00077 00078 /// Given the pressure, produce all the remaining quantities 00079 virtual int get_aux(double P, size_t &np, ovector_base &auxp) { 00080 np=0; 00081 return 0; 00082 } 00083 00084 /** 00085 \brief Fill a list with strings for the names of the remaining 00086 quanities 00087 */ 00088 virtual int get_names(size_t &np, std::vector<std::string> &pnames) { 00089 np=0; 00090 return 0; 00091 } 00092 00093 /** 00094 \brief Set to true if the baryon density is provided in the 00095 EOS (default false) 00096 */ 00097 bool baryon_column; 00098 00099 }; 00100 00101 /** 00102 \brief An EOS for the TOV solver using simple linear interpolation 00103 and a default low-density EOS 00104 00105 Internally, energy and pressure are stored in units of solar 00106 masses per cubic kilometer and baryon density is stored in units 00107 of fm^{-3}. The user-specified EOS table is left as is, and unit 00108 conversion is performed as needed in get_eden() and other 00109 functions so that results are returned in the units specified by 00110 set_units(). 00111 00112 The function set_units() needs to be called before either of the 00113 functions get_eden() or get_eden_ld() are called. The function 00114 set_units() may be called after calling either the read_table() 00115 functions or the set_low_density_eos() function. 00116 00117 */ 00118 class tov_interp_eos : public tov_eos { 00119 00120 public: 00121 00122 tov_interp_eos(); 00123 00124 virtual ~tov_interp_eos() {} 00125 00126 /// Given the pressure, produce the energy and number densities 00127 virtual int get_eden(double pres, double &ed, double &nb); 00128 00129 /** 00130 \brief Given the pressure, produce the energy and number 00131 densities from the user-specified EOS 00132 */ 00133 virtual int get_eden_user(double pres, double &ed, double &nb); 00134 00135 /** 00136 \brief Given the pressure, produce the energy and number 00137 densities from the low-density EOS 00138 */ 00139 virtual int get_eden_ld(double pres, double &ed, double &nb); 00140 00141 /// Given the pressure, produce all the remaining quantities 00142 virtual int get_aux(double P, size_t &nv, ovector_base &auxp); 00143 00144 /** 00145 \brief Fill a list with strings for the names of the remaining 00146 quanities 00147 */ 00148 virtual int get_names(size_t &np, std::vector<std::string> &pnames); 00149 00150 /// Specify the EOS through a table 00151 int read_table(table &eosat, std::string s_cole="ed", 00152 std::string s_colp="pr", std::string s_colnb="nb"); 00153 00154 /// Specify the EOS through a table in a file 00155 int read_table_file(std::string eosfn, std::string s_cole="ed", 00156 std::string s_colp="pr", std::string s_colnb="nb"); 00157 00158 /** 00159 \brief Set the low-density EOS 00160 */ 00161 int set_low_density_eos(bool s_ldeos, std::string s_nvpath, 00162 int s_nvcole=0, int s_nvcolp=1, int s_nvcolnb=2); 00163 00164 /** \brief Set the units of the user-specified EOS 00165 */ 00166 int set_units(double s_efactor, double s_pfactor, 00167 double s_nfactor); 00168 00169 /** \brief Set the units of the user-specified EOS 00170 */ 00171 int set_units(std::string leunits="", 00172 std::string lpunits="", std::string lnunits=""); 00173 00174 /** 00175 \brief Return limiting and transition pressures 00176 00177 Returns, in order: 00178 - the highest pressure in the low-density EOS 00179 - the transition pressure 00180 - the lowest pressure in the high-density EOS 00181 */ 00182 int get_transition(double &plow, double &ptrans, double &phi); 00183 00184 /** 00185 \brief Set the transition pressure and "width" 00186 00187 Sets the transition pressure and the width (specified as a 00188 number greater than unity in \c pw) of the transition between 00189 the two EOSs. The transition is done smoothly using linear 00190 interpolation between \f$ P=\mathrm{ptrans}/pmathrm{pw} \f$ 00191 and \f$ P=\mathrm{ptrans} \times pmathrm{pw} \f$. 00192 */ 00193 int set_transition(double ptrans, double pw); 00194 00195 #ifndef DOXYGEN_INTERNAL 00196 00197 protected: 00198 00199 /// A base I/O object for reading EOSs 00200 base_ioc bio; 00201 00202 /// For reading the table 00203 table_units_io_type table_units_io; 00204 00205 /// Check that the EOS is valid 00206 int check_eos(); 00207 00208 /// \name Low-density EOS 00209 //@{ 00210 00211 /// true if we are using the low-density eos (false) 00212 bool ldeos; 00213 00214 /** 00215 \brief Low-density EOS switch 00216 00217 This is \c true if the ldeos has been read by set_ldeos. This 00218 is useful, since then we know whether or not we need 00219 to free the memory for the LD EOS in the destructor 00220 */ 00221 bool ldeos_read; 00222 00223 /// the path to the low-density EOS 00224 std::string ldpath; 00225 /// column in low-density eos for energy density 00226 int ldcole; 00227 /// column in low-density eos for pressure 00228 int ldcolp; 00229 /// column in low-density eos for baryon density 00230 int ldcolnb; 00231 /// file containing low-density EOS 00232 table_units *ld_eos; 00233 00234 /// highest pressure in low-density EOS 00235 double presld; 00236 /// highest energy density in low-density EOS 00237 double eld; 00238 /// highest baryon density in low-density EOS 00239 double nbld; 00240 00241 /// Transition pressure 00242 double prest; 00243 /// Transition width 00244 double pwidth; 00245 //@} 00246 00247 /// \name User EOS 00248 //@{ 00249 00250 /// file containing eos 00251 table *eost; 00252 00253 /// number of lines in eos file 00254 int nfile; 00255 00256 /// column for energy density in eos file 00257 int cole; 00258 /// column for pressure in eos file 00259 int colp; 00260 /// column for baryon density in eos file 00261 int colnb; 00262 00263 /// True if an EOS has been specified 00264 bool eos_read; 00265 //@} 00266 00267 /// \name Units 00268 //@{ 00269 00270 /// Units for energy density 00271 std::string eunits; 00272 /// Units for pressure 00273 std::string punits; 00274 /// Units for baryon density 00275 std::string nunits; 00276 00277 /// unit conversion factor for energy density (default 1.0) 00278 double efactor; 00279 /// unit conversion factor for pressure (default 1.0) 00280 double pfactor; 00281 /// unit conversion factor for baryon density (default 1.0) 00282 double nfactor; 00283 00284 //@} 00285 00286 /// Linear EOS interpolation 00287 void interp(const ovector_base &x, const ovector_base &y, 00288 double xx, double &yy, int n1, int n2); 00289 00290 #endif 00291 00292 }; 00293 00294 /** 00295 \brief The Buchdahl EOS for the TOV solver 00296 00297 Given the eos 00298 \f[ 00299 \rho = 12 \sqrt{p_{*} P}- 5 P 00300 \f] 00301 the TOV equation has an analytical solution 00302 \f[ 00303 R=(1-\beta) \sqrt{\frac{\pi}{288 p_{*} G (1-2 \beta)}} 00304 \f] 00305 where \f$ \beta = GM/R \f$. 00306 00307 The central pressure and energy density are 00308 \f[ 00309 P_c = 36 p_{*} \beta^2 00310 \f] 00311 \f[ 00312 {\rho}_c = 72 p_{*} \beta (1-5 \beta/2) 00313 \f] 00314 00315 Physical solutions are obtained only for \f$ P< 25 p_{*}/144 \f$ 00316 and \f$ \beta<1/6 \f$ . 00317 00318 (Lattimer & Prakash, 2001) 00319 00320 \todo Fix the reference above 00321 00322 \future Figure out what to do with the buchfun() function 00323 */ 00324 class tov_buchdahl_eos : public tov_eos { 00325 00326 public: 00327 00328 tov_buchdahl_eos() { 00329 Pstar=3.2e-5; 00330 } 00331 00332 virtual ~tov_buchdahl_eos() {} 00333 00334 /** 00335 \brief The parameter with units of pressure in units of solar 00336 masses per km cubed (default value \f$ 3.2 \times 10^{-5} \f$ 00337 ) 00338 */ 00339 double Pstar; 00340 00341 /** 00342 \brief Given the pressure, produce the energy and number densities 00343 00344 If the baryon density is not specified, it should be set to 00345 zero or \ref baryon_column should be set to false 00346 */ 00347 virtual int get_eden(double P, double &e, double &nb) { 00348 e=12.0*sqrt(Pstar*P)-5.0*P; 00349 nb=0.0; 00350 return 0; 00351 } 00352 00353 /// Given the pressure, produce all the remaining quantities 00354 virtual int get_aux(double P, size_t &np, ovector_base &auxp) { 00355 np=0; 00356 return 0; 00357 } 00358 00359 /** 00360 \brief Fill a list with strings for the names of the remaining 00361 quanities 00362 */ 00363 virtual int get_names(size_t &np, std::vector<std::string> &pnames) { 00364 np=0; 00365 return 0; 00366 } 00367 00368 #ifdef O2SCL_NEVER_DEFINED 00369 00370 int buchfun(size_t bv, const ovector_base &bx, ovector_base &by, 00371 int &pa) { 00372 double u, rp; 00373 u=bx[0]; 00374 rp=bx[1]; 00375 by[0]=rp*(1.0-beta+u)/(1.0-2.0*beta)-buchrad; 00376 by[1]=beta/biga/rp*sin(biga*rp); 00377 return gsl_success; 00378 } 00379 00380 #endif 00381 00382 }; 00383 00384 /** 00385 \brief Standard polytropic EOS \f$ p = K \rho^{1+1/n} \f$ 00386 00387 Any units are permissible, but if this is to be used with \ref 00388 tov_solve, then the units of \f$ K \f$ must be consistent with 00389 the units set in \ref tov_solve::set_units(). 00390 */ 00391 class tov_polytrope_eos : public tov_eos { 00392 00393 public: 00394 00395 tov_polytrope_eos() { 00396 K=1.0; 00397 n=3.0; 00398 } 00399 00400 virtual ~tov_polytrope_eos() {} 00401 00402 /** 00403 \brief Coefficient (default 1.0) 00404 */ 00405 double K; 00406 00407 /// Index (default 3.0) 00408 double n; 00409 00410 /** 00411 \brief Given the pressure, produce the energy and number densities 00412 00413 If the baryon density is not specified, it should be set to 00414 zero or \ref baryon_column should be set to false 00415 */ 00416 virtual int get_eden(double P, double &e, double &nb) { 00417 e=pow(P/K,1.0/(1.0+1.0/n)); 00418 nb=0.0; 00419 return 0; 00420 } 00421 00422 /// Given the pressure, produce all the remaining quantities 00423 virtual int get_aux(double P, size_t &np, ovector_base &auxp) { 00424 np=0; 00425 return 0; 00426 } 00427 00428 /** 00429 \brief Fill a list with strings for the names of the remaining 00430 quanities 00431 */ 00432 virtual int get_names(size_t &np, std::vector<std::string> &pnames) { 00433 np=0; 00434 return 0; 00435 } 00436 00437 }; 00438 00439 #ifndef DOXYGENP 00440 } 00441 #endif 00442 00443 #endif 00444 00445
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