![]() |
Equation of State Sub-Library: Version 0.910
|
00001 /* 00002 ------------------------------------------------------------------- 00003 00004 Copyright (C) 2006-2012, 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 /** \brief EOS from a table 00037 00038 This assumes a symmetry energy which depends quadratically on 00039 the isospin asymmetry in order to construct an EOS from 00040 a table of baryon density and energy per baryon for both 00041 nuclear and pure neutron matter. 00042 00043 Note: If using a tabulated EOS to compute derivatives (like the 00044 compressibility which effectively requires a second derivative), 00045 it is important to tabulated the EOS precisely enough to ensure 00046 that the derivatives are accurate. In the case of ensuring that 00047 the compressibility at saturation density is well reproduced, I 00048 have needed the EOS to be specified with at least 6 digits of 00049 precision on a grid at least as small as 0.002 00050 \f$ \mathrm{fm}^{-3} \f$. 00051 */ 00052 class tabulated_eos : public hadronic_eos_eden { 00053 00054 protected: 00055 00056 /// True if the table has been allocated 00057 bool table_alloc; 00058 00059 /// \name The EOS tables 00060 //@{ 00061 table *tnuc; 00062 table *tneut; 00063 //@} 00064 00065 /// If true, then tnuc and tneut point to the same table 00066 bool one_table; 00067 00068 /// \name Strings for the column names 00069 //@{ 00070 std::string srho_nuc, srho_neut, snuc, sneut; 00071 //@} 00072 00073 /// Free the table memory 00074 int free_table() { 00075 if (table_alloc) { 00076 delete tnuc; 00077 if (!one_table) delete tneut; 00078 table_alloc=false; 00079 } 00080 return 0; 00081 } 00082 00083 public: 00084 00085 tabulated_eos() { 00086 table_alloc=false; 00087 one_table=false; 00088 } 00089 00090 virtual ~tabulated_eos() { 00091 if (table_alloc) { 00092 delete tnuc; 00093 if (!one_table) delete tneut; 00094 } 00095 } 00096 00097 /** \brief Equation of state as a function of density 00098 */ 00099 virtual int calc_e(fermion &ne, fermion &pr, thermo &th) { 00100 00101 if (table_alloc==false) { 00102 O2SCL_ERR_RET("No EOS specified in tabulated_eos::calc_e().", 00103 gsl_einval); 00104 } 00105 double barn=ne.n+pr.n; 00106 double xp=pr.n/barn; 00107 double delta=(1.0-2.0*xp); 00108 00109 // The energy density of nuclear matter 00110 double ednuc=(tnuc->interp(srho_nuc,barn,snuc)/o2scl_const::hc_mev_fm+ 00111 ne.m)*barn; 00112 // The symmetry energy density 00113 double edsym=(tneut->interp(srho_neut,barn,sneut)- 00114 tnuc->interp(srho_nuc,barn,snuc))/ 00115 o2scl_const::hc_mev_fm*barn; 00116 // The total energy density 00117 th.ed=ednuc+delta*delta*edsym; 00118 00119 // The derivatives of the energy densities wrt the baryon density 00120 double dednucdn=tnuc->deriv(srho_nuc,barn,snuc)/ 00121 o2scl_const::hc_mev_fm*barn+ednuc/barn; 00122 double dedsymdn=barn*(tneut->deriv(srho_neut,barn,sneut)- 00123 tnuc->deriv(srho_nuc,barn,snuc))/ 00124 o2scl_const::hc_mev_fm+edsym/barn; 00125 00126 // The chemical potentials 00127 ne.mu=(dednucdn+delta*delta*dedsymdn)+4.0*delta*edsym*xp/barn; 00128 pr.mu=(dednucdn+delta*delta*dedsymdn)+4.0*delta*edsym*(xp-1.0)/barn; 00129 00130 // The pressure 00131 th.pr=-th.ed+ne.n*ne.mu+pr.n*pr.mu; 00132 00133 return 0; 00134 } 00135 00136 /** \brief Set the EOS through vectors specifying the densities and 00137 energies 00138 */ 00139 template <class vec_t> 00140 int set_eos(size_t n, vec_t &rho, vec_t &Enuc, vec_t &Eneut) { 00141 00142 free_table(); 00143 00144 tnuc=new table(n); 00145 tnuc->line_of_names("rho nuc neut"); 00146 srho_nuc="rho"; 00147 srho_neut="rho"; 00148 snuc="nuc"; 00149 sneut="neut"; 00150 for(size_t i=0;i<n;i++) { 00151 double line[3]={rho[i],Enuc[i],Eneut[i]}; 00152 tnuc->line_of_data(3,line); 00153 } 00154 tneut=tnuc; 00155 table_alloc=true; 00156 one_table=true; 00157 00158 return 0; 00159 } 00160 00161 /** \brief Set the EOS through vectors specifying the densities and 00162 energies 00163 */ 00164 template<class vec_t> 00165 int set_eos(size_t n_nuc, vec_t &rho_nuc, vec_t &E_nuc, 00166 size_t n_neut, vec_t &rho_neut, vec_t &E_neut) { 00167 00168 free_table(); 00169 00170 tnuc=new table(n_nuc); 00171 tneut=new table(n_neut); 00172 tnuc->line_of_names("rho nuc"); 00173 tneut->line_of_names("rho neut"); 00174 srho_nuc="rho"; 00175 srho_neut="rho"; 00176 snuc="nuc"; 00177 sneut="neut"; 00178 for(size_t i=0;i<n_nuc;i++) { 00179 double line[2]={rho_nuc[i],E_nuc[i]}; 00180 tnuc->line_of_data(2,line); 00181 } 00182 for(size_t i=0;i<n_neut;i++) { 00183 double line[2]={rho_neut[i],E_neut[i]}; 00184 tneut->line_of_data(2,line); 00185 } 00186 table_alloc=true; 00187 return 0; 00188 } 00189 00190 /// Return the internal table 00191 table &get_nuc_table() { 00192 return *tnuc; 00193 } 00194 00195 /// Return the internal table 00196 table &get_neut_table() { 00197 return *tneut; 00198 } 00199 00200 }; 00201 00202 #ifndef DOXYGENP 00203 } 00204 #endif 00205 00206 #endif
Documentation generated with Doxygen. Provided under the GNU Free Documentation License (see License Information).