00001 /* 00002 ------------------------------------------------------------------- 00003 00004 Copyright (C) 2006, 2007, 2008, 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.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_view &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_view &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 /// Check that the EOS is valid 00203 int check_eos(); 00204 00205 /// \name Low-density EOS 00206 //@{ 00207 00208 /// true if we are using the low-density eos (false) 00209 bool ldeos; 00210 00211 /** 00212 \brief Low-density EOS switch 00213 00214 This is \c true if the ldeos has been read by set_ldeos. This 00215 is useful, since then we know whether or not we need 00216 to free the memory for the LD EOS in the destructor 00217 */ 00218 bool ldeos_read; 00219 00220 /// the path to the low-density EOS 00221 std::string ldpath; 00222 /// column in low-density eos for energy density 00223 int ldcole; 00224 /// column in low-density eos for pressure 00225 int ldcolp; 00226 /// column in low-density eos for baryon density 00227 int ldcolnb; 00228 /// file containing low-density EOS 00229 table *ld_eos; 00230 00231 /// highest pressure in low-density EOS 00232 double presld; 00233 /// highest energy density in low-density EOS 00234 double eld; 00235 /// highest baryon density in low-density EOS 00236 double nbld; 00237 00238 /// Transition pressure 00239 double prest; 00240 /// Transition width 00241 double pwidth; 00242 //@} 00243 00244 /// \name User EOS 00245 //@{ 00246 00247 /// file containing eos 00248 table *eost; 00249 00250 /// number of lines in eos file 00251 int nfile; 00252 00253 /// column for energy density in eos file 00254 int cole; 00255 /// column for pressure in eos file 00256 int colp; 00257 /// column for baryon density in eos file 00258 int colnb; 00259 00260 /// True if an EOS has been specified 00261 bool eos_read; 00262 //@} 00263 00264 /// \name Units 00265 //@{ 00266 00267 /// Units for energy density 00268 std::string eunits; 00269 /// Units for pressure 00270 std::string punits; 00271 /// Units for baryon density 00272 std::string nunits; 00273 00274 /// unit conversion factor for energy density (default 1.0) 00275 double efactor; 00276 /// unit conversion factor for pressure (default 1.0) 00277 double pfactor; 00278 /// unit conversion factor for baryon density (default 1.0) 00279 double nfactor; 00280 00281 //@} 00282 00283 /// Linear EOS interpolation 00284 void interp(const ovector_view &x, const ovector_view &y, 00285 double xx, double &yy, int n1, int n2); 00286 00287 #endif 00288 00289 }; 00290 00291 /** 00292 \brief The Buchdahl EOS for the TOV solver 00293 00294 Given the eos 00295 \f[ 00296 \rho = 12 \sqrt{p_{*} P}- 5 P 00297 \f] 00298 the TOV equation has an analytical solution 00299 \f[ 00300 R=(1-\beta) \sqrt{\frac{\pi}{288 p_{*} G (1-2 \beta)}} 00301 \f] 00302 where \f$ \beta = GM/R \f$. 00303 00304 The central pressure and energy density are 00305 \f[ 00306 P_c = 36 p_{*} \beta^2 00307 \f] 00308 \f[ 00309 {\rho}_c = 72 p_{*} \beta (1-5 \beta/2) 00310 \f] 00311 00312 Physical solutions are obtained only for \f$ P< 25 p_{*}/144 \f$ 00313 and \f$ \beta<1/6 \f$ . 00314 00315 (Lattimer & Prakash, 2001) 00316 00317 \todo Fix the reference above 00318 00319 \future Figure out what to do with the buchfun() function 00320 */ 00321 class tov_buchdahl_eos : public tov_eos { 00322 00323 public: 00324 00325 tov_buchdahl_eos() { 00326 Pstar=3.2e-5; 00327 } 00328 00329 virtual ~tov_buchdahl_eos() {} 00330 00331 /** 00332 \brief The parameter with units of pressure in units of solar 00333 masses per km cubed (default value \f$ 3.2 \times 10^{-5} \f$ 00334 ) 00335 */ 00336 double Pstar; 00337 00338 /** 00339 \brief Given the pressure, produce the energy and number densities 00340 00341 If the baryon density is not specified, it should be set to 00342 zero or \ref baryon_column should be set to false 00343 */ 00344 virtual int get_eden(double P, double &e, double &nb) { 00345 e=12.0*sqrt(Pstar*P)-5.0*P; 00346 nb=0.0; 00347 return 0; 00348 } 00349 00350 /// Given the pressure, produce all the remaining quantities 00351 virtual int get_aux(double P, size_t &np, ovector_view &auxp) { 00352 np=0; 00353 return 0; 00354 } 00355 00356 /** 00357 \brief Fill a list with strings for the names of the remaining 00358 quanities 00359 */ 00360 virtual int get_names(size_t &np, std::vector<std::string> &pnames) { 00361 np=0; 00362 return 0; 00363 } 00364 00365 #ifdef O2SCL_NEVER_DEFINED 00366 00367 int buchfun(size_t bv, const ovector_view &bx, ovector_view &by, 00368 void *&pa) { 00369 double u, rp; 00370 u=bx[0]; 00371 rp=bx[1]; 00372 by[0]=rp*(1.0-beta+u)/(1.0-2.0*beta)-buchrad; 00373 by[1]=beta/biga/rp*sin(biga*rp); 00374 return gsl_success; 00375 } 00376 00377 #endif 00378 00379 }; 00380 00381 /** 00382 \brief Standard polytropic EOS \f$ p = K \rho^{1+1/n} \f$ 00383 00384 Any units are permissible, but if this is to be used with \ref 00385 tov_solve, then the units of \f$ K \f$ must be consistent with 00386 the units set in \ref tov_solve::set_units(). 00387 */ 00388 class tov_polytrope_eos : public tov_eos { 00389 00390 public: 00391 00392 tov_polytrope_eos() { 00393 K=1.0; 00394 n=3.0; 00395 } 00396 00397 virtual ~tov_polytrope_eos() {} 00398 00399 /** 00400 \brief Coefficient (default 1.0) 00401 */ 00402 double K; 00403 00404 /// Index (default 3.0) 00405 double n; 00406 00407 /** 00408 \brief Given the pressure, produce the energy and number densities 00409 00410 If the baryon density is not specified, it should be set to 00411 zero or \ref baryon_column should be set to false 00412 */ 00413 virtual int get_eden(double P, double &e, double &nb) { 00414 e=pow(P/K,1.0/(1.0+1.0/n)); 00415 nb=0.0; 00416 return 0; 00417 } 00418 00419 /// Given the pressure, produce all the remaining quantities 00420 virtual int get_aux(double P, size_t &np, ovector_view &auxp) { 00421 np=0; 00422 return 0; 00423 } 00424 00425 /** 00426 \brief Fill a list with strings for the names of the remaining 00427 quanities 00428 */ 00429 virtual int get_names(size_t &np, std::vector<std::string> &pnames) { 00430 np=0; 00431 return 0; 00432 } 00433 00434 }; 00435 00436 #ifndef DOXYGENP 00437 } 00438 #endif 00439 00440 #endif 00441 00442
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