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_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_eden { 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 /// Free the table memory 00075 int free_table() { 00076 if (table_alloc) { 00077 delete tnuc; 00078 if (!one_table) delete tneut; 00079 table_alloc=false; 00080 } 00081 return 0; 00082 } 00083 00084 public: 00085 00086 tabulated_eos() { 00087 table_alloc=false; 00088 one_table=false; 00089 } 00090 00091 virtual ~tabulated_eos() { 00092 if (table_alloc) { 00093 delete tnuc; 00094 if (!one_table) delete tneut; 00095 } 00096 } 00097 00098 /** 00099 \brief Equation of state as a function of density 00100 */ 00101 virtual int calc_e(fermion &ne, fermion &pr, thermo &th) { 00102 00103 if (table_alloc==false) { 00104 O2SCL_ERR_RET("No EOS specified in tabulated_eos::calc_e().", 00105 gsl_einval); 00106 } 00107 double barn=ne.n+pr.n; 00108 double xp=pr.n/barn; 00109 double delta=(1.0-2.0*xp); 00110 00111 // The energy density of nuclear matter 00112 double ednuc=(tnuc->interp(srho_nuc,barn,snuc)/o2scl_const::hc_mev_fm+ 00113 ne.m)*barn; 00114 // The symmetry energy density 00115 double edsym=(tneut->interp(srho_neut,barn,sneut)- 00116 tnuc->interp(srho_nuc,barn,snuc))/ 00117 o2scl_const::hc_mev_fm*barn; 00118 // The total energy density 00119 th.ed=ednuc+delta*delta*edsym; 00120 00121 // The derivatives of the energy densities wrt the baryon density 00122 double dednucdn=tnuc->deriv(srho_nuc,barn,snuc)/ 00123 o2scl_const::hc_mev_fm*barn+ednuc/barn; 00124 double dedsymdn=barn*(tneut->deriv(srho_neut,barn,sneut)- 00125 tnuc->deriv(srho_nuc,barn,snuc))/ 00126 o2scl_const::hc_mev_fm+edsym/barn; 00127 00128 // The chemical potentials 00129 ne.mu=(dednucdn+delta*delta*dedsymdn)+4.0*delta*edsym*xp/barn; 00130 pr.mu=(dednucdn+delta*delta*dedsymdn)+4.0*delta*edsym*(xp-1.0)/barn; 00131 00132 // The pressure 00133 th.pr=-th.ed+ne.n*ne.mu+pr.n*pr.mu; 00134 00135 return 0; 00136 } 00137 00138 /** \brief Set the EOS through vectors specifying the densities and 00139 energies 00140 */ 00141 template <class vec_t> 00142 int set_eos(size_t n, vec_t &rho, vec_t &Enuc, vec_t &Eneut) { 00143 00144 free_table(); 00145 00146 tnuc=new table(n); 00147 tnuc->line_of_names("rho nuc neut"); 00148 srho_nuc="rho"; 00149 srho_neut="rho"; 00150 snuc="nuc"; 00151 sneut="neut"; 00152 for(size_t i=0;i<n;i++) { 00153 double line[3]={rho[i],Enuc[i],Eneut[i]}; 00154 tnuc->line_of_data(3,line); 00155 } 00156 tneut=tnuc; 00157 table_alloc=true; 00158 one_table=true; 00159 00160 return 0; 00161 } 00162 00163 /** \brief Set the EOS through vectors specifying the densities and 00164 energies 00165 */ 00166 template<class vec_t> 00167 int set_eos(size_t n_nuc, vec_t &rho_nuc, vec_t &E_nuc, 00168 size_t n_neut, vec_t &rho_neut, vec_t &E_neut) { 00169 00170 free_table(); 00171 00172 tnuc=new table(n_nuc); 00173 tneut=new table(n_neut); 00174 tnuc->line_of_names("rho nuc"); 00175 tneut->line_of_names("rho neut"); 00176 srho_nuc="rho"; 00177 srho_neut="rho"; 00178 snuc="nuc"; 00179 sneut="neut"; 00180 for(size_t i=0;i<n_nuc;i++) { 00181 double line[2]={rho_nuc[i],E_nuc[i]}; 00182 tnuc->line_of_data(2,line); 00183 } 00184 for(size_t i=0;i<n_neut;i++) { 00185 double line[2]={rho_neut[i],E_neut[i]}; 00186 tneut->line_of_data(2,line); 00187 } 00188 table_alloc=true; 00189 return 0; 00190 } 00191 00192 /// Return the internal table 00193 table &get_nuc_table() { 00194 return *tnuc; 00195 } 00196 00197 /// Return the internal table 00198 table &get_neut_table() { 00199 return *tneut; 00200 } 00201 00202 #ifdef O2SCL_NEVER_DEFINED 00203 // Deprecated for collection modifications 00204 00205 /* \brief Set the EOS by specifying a file containing a \ref 00206 table object 00207 00208 */ 00209 int read_file(std::string fname, std::string rho_str, 00210 std::string nuc_str, std::string neut_str) { 00211 00212 base_ioc bio; 00213 collection co; 00214 std::string name; 00215 int sz, sz2; 00216 int vp; 00217 00218 int ret=co.in_one(fname,"table",name,vp,sz,sz2); 00219 int ret=0; 00220 if (ret!=0) { 00221 O2SCL_ERR_RET("Input table failed in tabulated_eos::read_file().", 00222 gsl_efailed); 00223 } 00224 00225 free_table(); 00226 00227 tnuc=(table *)vp; 00228 tneut=tnuc; 00229 srho_nuc=rho_str; 00230 srho_neut=rho_str; 00231 snuc=nuc_str; 00232 sneut=neut_str; 00233 table_alloc=true; 00234 one_table=true; 00235 00236 return 0; 00237 } 00238 #endif 00239 00240 }; 00241 00242 #ifndef DOXYGENP 00243 } 00244 #endif 00245 00246 #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