56 #include "utilitaires.h" 61 void interpol_herm(
const Tbl& ,
const Tbl&,
const Tbl&,
double,
int&,
64 void interpol_linear(
const Tbl&,
const Tbl&,
double,
int&,
double&) ;
75 bool compose) :
Dyn_eos(name_i), tablename(tablename_i),
76 compose_format(compose), lognb(0x0),
77 loge(0x0), dlesdlnb(0x0), c_sound2(0x0)
94 loge(0x0), dlesdlnb(0x0), c_sound2(0x0)
98 size_t ret = fread(tmp_string,
sizeof(
char), nc, fich) ;
102 cerr <<
"Dyn_eos_tab: constructor from a binary file:" << endl ;
103 cerr <<
"Problems in reading the table name." << endl ;
104 cerr <<
"Aborting..." << endl ;
108 fread_be(&comp,
sizeof(
int), 1, fich) ;
121 loge(0x0), dlesdlnb(0x0), c_sound2(0x0)
123 fich.seekg(0, fich.beg) ;
124 fich.ignore(1000,
'\n') ;
126 fich.ignore(1000,
'\n') ;
127 getline(fich,
name,
'\n') ;
158 cout <<
"The second EOS is not of type Dyn_eos_tab !" << endl ;
180 char tmp_string[160] ;
182 fwrite(tmp_string,
sizeof(
char), 160, fich) ;
189 ost <<
"EOS of class Dyn_eos_tab." << endl ;
190 ost <<
"Built from file " <<
tablename << endl ;
191 ost << ((
compose_format == 0) ?
"Old LORENE format" :
"CompOSE format") << endl ;
192 ost <<
"Authors : " <<
authors << endl ;
209 cerr <<
"Dyn_eos_tab::read_table_lorene(): " << endl ;
210 cerr <<
"Problem in opening the EOS file!" << endl ;
211 cerr <<
"While trying to open " <<
tablename << endl ;
212 cerr <<
"Aborting..." << endl ;
216 fich.ignore(1000,
'\n') ;
219 for (
int i=0; i<3; i++) {
220 fich.ignore(1000,
'\n') ;
224 fich >> nbp ; fich.ignore(1000,
'\n') ;
226 cerr <<
"Dyn_eos_tab::read_table_lorene(): " << endl ;
227 cerr <<
"Wrong value for the number of lines!" << endl ;
228 cerr <<
"nbp = " << nbp << endl ;
229 cerr <<
"Aborting..." << endl ;
233 for (
int i=0; i<3; i++) {
234 fich.ignore(1000,
'\n') ;
249 double rhonuc_cgs = rhonuc_si * 1e-3 ;
250 double c2_cgs = c_si * c_si * 1e4 ;
253 double nb_fm3, rho_cgs, p_cgs ;
255 cout <<
"Dyn_eos_tab: reading Lorene format table from the file " 257 for (
int i=0; i<nbp; i++) {
262 fich >> p_cgs ; fich.ignore(1000,
'\n') ;
263 if ( (nb_fm3<0) || (rho_cgs<0) || (p_cgs < 0) ){
264 cout <<
"Dyn_eos_tab::read_table_lorene(): " << endl ;
265 cout <<
"Negative value in table!" << endl ;
266 cout <<
"nb = " << nb_fm3 <<
", rho = " << rho_cgs <<
267 ", p = " << p_cgs << endl ;
268 cout <<
"Aborting..." << endl ;
272 press.
set(i) = p_cgs / (c2_cgs*rhonuc_cgs) ;
273 nb.
set(i) = 10.*nb_fm3 ;
274 ro.
set(i) = rho_cgs / rhonuc_cgs ;
287 cout <<
"nbmin, nbmax : " <<
nbmin <<
" " <<
nbmax << endl ;
301 string file_thermo =
tablename +
".thermo" ;
303 ifstream in_nb(file_nb.data()) ;
305 cerr <<
"Dyn_eos_tab::read_table_compose(): " << endl ;
306 cerr <<
"Problem in opening the EOS file!" << endl ;
307 cerr <<
"While trying to open " << file_nb << endl ;
308 cerr <<
"Aborting..." << endl ;
315 in_nb >> index1 >> index2 ;
316 int nbp = index2 - index1 + 1 ;
333 double nb_fm3, rho_cgs, p_cgs, p_over_nb_comp, eps_comp ;
337 double rhonuc_cgs = rhonuc_si * 1e-3 ;
338 double c2_cgs = c_si * c_si * 1e4 ;
339 double m_neutron_MeV, m_proton_MeV ;
341 ifstream in_p_rho (file_thermo.data()) ;
343 cerr <<
"Dyn_eos_tab::read_table_compose(): " << endl ;
344 cerr <<
"Problem in opening the EOS file!" << endl ;
345 cerr <<
"While trying to open " << file_thermo << endl ;
346 cerr <<
"Aborting..." << endl ;
349 in_p_rho >> m_neutron_MeV >> m_proton_MeV ;
350 in_p_rho.ignore(1000,
'\n') ;
352 double p_convert = mev_si * 1.e45 * 10. ;
353 double eps_convert = mev_si * 1.e42 / (c_si*c_si) ;
357 cout <<
"Dyn_eos_tab: reading CompOSE format table from the file " 359 for (
int i=0; i<nbp; i++) {
361 in_p_rho >> dummy_n >> dummy_n >> dummy_n >> p_over_nb_comp ;
362 in_p_rho >> dummy_x >> dummy_x >> dummy_x >> dummy_x >> dummy_x >> eps_comp ;
363 in_p_rho.ignore(1000,
'\n') ;
364 p_cgs = p_over_nb_comp * nb_fm3 * p_convert ;
365 rho_cgs = ( eps_comp + 1. ) * m_neutron_MeV * nb_fm3 * eps_convert ;
367 if ( (nb_fm3<0) || (rho_cgs<0) || (p_cgs < 0) ){
368 cout <<
"Dyn_eos_tab::read_table_compose(): " << endl ;
369 cout <<
"Negative value in table!" << endl ;
370 cout <<
"nb = " << nb_fm3 <<
", rho = " << rho_cgs <<
371 ", p = " << p_cgs << endl ;
372 cout <<
"Aborting..." << endl ;
376 press.
set(i) = (p_cgs / c2_cgs) / rhonuc_cgs ;
377 nb.
set(i) = 10. * nb_fm3 ;
378 ro.
set(i) = rho_cgs / rhonuc_cgs ;
391 cout <<
"nbmin, nbmax : " <<
nbmin <<
" " <<
nbmax << endl ;
403 if ( nbar >
nbmin ) {
405 cout <<
"Dyn_eos_tab::ent_nbar_p : nbar > nbmax !" << endl ;
408 double lognb0 =
log10( nbar ) ;
413 double ee =
pow(
double(10), loge0) ;
414 double resu = dlesdlnb0*ee / nbar ;
428 if ( nbar >
nbmin ) {
430 cout <<
"Dyn_eos_tab::ener_nbar_p : nbar > nbmax !" << endl ;
433 double lognb0 =
log10( nbar ) ;
438 return pow(
double(10), loge0) ;
451 if ( nbar >
nbmin ) {
453 cout <<
"Dyn_eos_tab::press_nbar_p : nbar > nbmax !" << endl ;
456 double lognb0 =
log10( nbar ) ;
461 double ee =
pow(
double(10), loge0) ;
462 double hnb = ee * dlesdlnb0 ;
466 return pow(10.,(*
loge)(0))*((*dlesdlnb)(0) - 1.) ;
478 if ( nbar >
nbmin ) {
480 cout <<
"Dyn_eos_tab::press_nbar_p : nbar > nbmax !" << endl ;
483 double lognb0 =
log10( nbar ) ;
486 interpol_linear(*
lognb, *
c_sound2, lognb0, i_near, csound0) ;
Cmp log(const Cmp &)
Neperian logarithm.
virtual void sauve(FILE *) const
Save in a file.
virtual int identify() const =0
Returns a number to identify the sub-classe of Dyn_eos the object belongs to.
Standard units of space, time and mass.
double & set(int i)
Read/write of a particular element (index i) (1D case)
string tablename
Name of the file containing the tabulated data.
virtual double ent_nbar_p(double nbar, const Param *par=0x0) const
Computes the log-enthalpy from the baryon density and extra parameters (virtual function implemented ...
virtual int identify() const
Returns a number to identify the sub-classe of Dyn_eos the object belongs to.
double nbmin
Lower boundary of the baryon density interval.
void set_etat_qcq()
Sets the logical state to ETATQCQ (ordinary state).
Equation of state for use in dynamical code base class.
virtual void sauve(FILE *) const
Save in a file.
virtual double press_nbar_p(double nbar, const Param *par=0x0) const
Computes the pressure from the baryon density and extra parameters (virtual function implemented in t...
virtual double ener_nbar_p(double nbar, const Param *par=0x0) const
Computes the total energy density from the baryon density and extra parameters (virtual function impl...
void compute_derivative(const Tbl &xx, const Tbl &ff, Tbl &dfdx)
Derives a function defined on an unequally-spaced grid, approximating it by piecewise parabolae...
virtual bool operator==(const Dyn_eos &) const
Comparison operator (egality)
int fwrite_be(const int *aa, int size, int nb, FILE *fich)
Writes integer(s) into a binary file according to the big endian convention.
virtual double csound_square_nbar_p(double nbar, const Param *par=0x0) const
Computes the sound speed squared from the baryon density with extra parameters.
Cmp pow(const Cmp &, int)
Power .
int fread_be(int *aa, int size, int nb, FILE *fich)
Reads integer(s) from a binary file according to the big endian convention.
virtual void read_table_compose()
Reads the files .nb and .thermo containing the table in CompOSE format and initializes the arrays log...
string authors
Authors - reference for the table.
Cmp log10(const Cmp &)
Basis 10 logarithm.
int get_taille() const
Gives the total size (ie dim.taille)
Dyn_eos_tab()
Default constructor to be called by derived classes.
virtual ~Dyn_eos_tab()
Destructor.
virtual bool operator!=(const Dyn_eos &) const
Comparison operator (difference)
bool compose_format
Are(is) the table(s) in CompOSE format?
double nbmax
Upper boundary of the baryon density interval.
virtual void read_table_lorene()
Reads the file containing the table in LORENE format and initializes the arrays lognb ...
virtual ostream & operator>>(ostream &) const
Operator >>