00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
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
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053 class tabulated_eos : public hadronic_eos {
00054
00055 protected:
00056
00057
00058 bool table_alloc;
00059
00060
00061
00062 table *tnuc;
00063 table *tneut;
00064
00065
00066
00067 bool one_table;
00068
00069
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
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
00111 double ednuc=(tnuc->interp(srho_nuc,barn,snuc)/o2scl_const::hc_mev_fm+
00112 ne.m)*barn;
00113
00114 double edsym=(tneut->interp(srho_neut,barn,sneut)-
00115 tnuc->interp(srho_nuc,barn,snuc))/
00116 o2scl_const::hc_mev_fm*barn;
00117
00118 th.ed=ednuc+delta*delta*edsym;
00119
00120
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
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
00132 th.pr=-th.ed+ne.n*ne.mu+pr.n*pr.mu;
00133
00134 return 0;
00135 }
00136
00137
00138
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
00163
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
00192 table &get_nuc_table() {
00193 return *tnuc;
00194 }
00195
00196
00197 table &get_neut_table() {
00198 return *tneut;
00199 }
00200
00201
00202
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