00001 /* 00002 ------------------------------------------------------------------- 00003 00004 Copyright (C) 2006, 2007, 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_TABULATED_EOS_H 00024 #define O2SCL_TABULATED_EOS_H 00025 00026 #include <cmath> 00027 #include <o2scl/constants.h> 00028 #include <o2scl/hadronic_eos.h> 00029 #include <o2scl/fermion.h> 00030 #include <o2scl/apr_eos.h> 00031 00032 #ifndef DOXYGENP 00033 namespace o2scl { 00034 #endif 00035 00036 /** 00037 \brief EOS from a table 00038 00039 This assumes a symmetry energy which depends quadratically on 00040 the isospin asymmetry in order to construct an EOS from 00041 a table of baryon density and energy per baryon for both 00042 nuclear and pure neutron matter. 00043 00044 Note: If using a tabulated EOS to compute derivatives (like the 00045 compressibility which effectively requires a second derivative), 00046 it is important to tabulated the EOS precisely enough to ensure 00047 that the derivatives are accurate. In the case of ensuring that 00048 the compressibility at saturation density is well reproduced, I 00049 have needed the EOS to be specified with at least 6 digits of 00050 precision on a grid at least as small as 0.002 00051 \f$ \mathrm{fm}^{-3} \f$. 00052 */ 00053 class tabulated_eos : public hadronic_eos { 00054 00055 protected: 00056 00057 /// True if the table has been allocated 00058 bool table_alloc; 00059 00060 /// \name The EOS tables 00061 //@{ 00062 table *tnuc; 00063 table *tneut; 00064 //@} 00065 00066 /// If true, then tnuc and tneut point to the same table 00067 bool one_table; 00068 00069 /// \name Strings for the column names 00070 //@{ 00071 std::string srho_nuc, srho_neut, snuc, sneut; 00072 //@} 00073 00074 public: 00075 00076 tabulated_eos() { 00077 table_alloc=false; 00078 one_table=false; 00079 } 00080 00081 virtual ~tabulated_eos() { 00082 if (table_alloc) { 00083 delete tnuc; 00084 if (!one_table) delete tneut; 00085 } 00086 } 00087 00088 int free_table() { 00089 if (table_alloc) { 00090 delete tnuc; 00091 if (!one_table) delete tneut; 00092 table_alloc=false; 00093 } 00094 return 0; 00095 } 00096 00097 /** 00098 \brief Equation of state as a function of density 00099 */ 00100 virtual int calc_e(fermion &ne, fermion &pr, thermo &th) { 00101 00102 if (table_alloc==false) { 00103 set_err_ret("No EOS specified in tabulated_eos::calc_e().", 00104 gsl_einval); 00105 } 00106 double barn=ne.n+pr.n; 00107 double xp=pr.n/barn; 00108 double delta=(1.0-2.0*xp); 00109 00110 // The energy density of nuclear matter 00111 double ednuc=(tnuc->interp(srho_nuc,barn,snuc)/o2scl_const::hc_mev_fm+ 00112 ne.m)*barn; 00113 // The symmetry energy density 00114 double edsym=(tneut->interp(srho_neut,barn,sneut)- 00115 tnuc->interp(srho_nuc,barn,snuc))/ 00116 o2scl_const::hc_mev_fm*barn; 00117 // The total energy density 00118 th.ed=ednuc+delta*delta*edsym; 00119 00120 // The derivatives of the energy densities wrt the baryon density 00121 double dednucdn=tnuc->deriv(srho_nuc,barn,snuc)/ 00122 o2scl_const::hc_mev_fm*barn+ednuc/barn; 00123 double dedsymdn=barn*(tneut->deriv(srho_neut,barn,sneut)- 00124 tnuc->deriv(srho_nuc,barn,snuc))/ 00125 o2scl_const::hc_mev_fm+edsym/barn; 00126 00127 // The chemical potentials 00128 ne.mu=(dednucdn+delta*delta*dedsymdn)+4.0*delta*edsym*xp/barn; 00129 pr.mu=(dednucdn+delta*delta*dedsymdn)+4.0*delta*edsym*(xp-1.0)/barn; 00130 00131 // The pressure 00132 th.pr=-th.ed+ne.n*ne.mu+pr.n*pr.mu; 00133 00134 return 0; 00135 } 00136 00137 /** \brief Set the EOS through vectors specifying the densities and 00138 energies 00139 */ 00140 template <class vec_t> 00141 int set_eos(size_t n, vec_t &rho, vec_t &Enuc, vec_t &Eneut) { 00142 00143 free_table(); 00144 00145 tnuc=new table(n); 00146 tnuc->line_of_names("rho nuc neut"); 00147 srho_nuc="rho"; 00148 srho_neut="rho"; 00149 snuc="nuc"; 00150 sneut="neut"; 00151 for(size_t i=0;i<n;i++) { 00152 double line[3]={rho[i],Enuc[i],Eneut[i]}; 00153 tnuc->line_of_data(3,line); 00154 } 00155 tneut=tnuc; 00156 table_alloc=true; 00157 one_table=true; 00158 00159 return 0; 00160 } 00161 00162 /** \brief Set the EOS through vectors specifying the densities and 00163 energies 00164 */ 00165 template<class vec_t> 00166 int set_eos(size_t n_nuc, vec_t &rho_nuc, vec_t &E_nuc, 00167 size_t n_neut, vec_t &rho_neut, vec_t &E_neut) { 00168 00169 free_table(); 00170 00171 tnuc=new table(n_nuc); 00172 tneut=new table(n_neut); 00173 tnuc->line_of_names("rho nuc"); 00174 tneut->line_of_names("rho neut"); 00175 srho_nuc="rho"; 00176 srho_neut="rho"; 00177 snuc="nuc"; 00178 sneut="neut"; 00179 for(size_t i=0;i<n_nuc;i++) { 00180 double line[2]={rho_nuc[i],E_nuc[i]}; 00181 tnuc->line_of_data(2,line); 00182 } 00183 for(size_t i=0;i<n_neut;i++) { 00184 double line[2]={rho_neut[i],E_neut[i]}; 00185 tneut->line_of_data(2,line); 00186 } 00187 table_alloc=true; 00188 return 0; 00189 } 00190 00191 /// Return the internal table 00192 table &get_nuc_table() { 00193 return *tnuc; 00194 } 00195 00196 /// Return the internal table 00197 table &get_neut_table() { 00198 return *tneut; 00199 } 00200 00201 /** \brief Set the EOS by specifying a file containing a \ref 00202 table object 00203 */ 00204 int read_file(std::string fname, std::string rho_str, 00205 std::string nuc_str, std::string neut_str) { 00206 00207 base_ioc bio; 00208 collection co; 00209 std::string name; 00210 int sz, sz2; 00211 void *vp; 00212 00213 int ret=co.in_one(fname,"table",name,vp,sz,sz2); 00214 if (ret!=0) { 00215 add_err_ret("Input table failed in tabulated_eos::read_file().", 00216 gsl_efailed); 00217 } 00218 00219 free_table(); 00220 00221 tnuc=(table *)vp; 00222 tneut=tnuc; 00223 srho_nuc=rho_str; 00224 srho_neut=rho_str; 00225 snuc=nuc_str; 00226 sneut=neut_str; 00227 table_alloc=true; 00228 one_table=true; 00229 00230 return 0; 00231 } 00232 00233 00234 }; 00235 00236 #ifndef DOXYGENP 00237 } 00238 #endif 00239 00240 #endif
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