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&) ;
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) ;
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 ;
193 ost <<
"Number of points in file : " <<
lognb->get_taille() << 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') ;
245 lognb->set_etat_qcq() ;
246 loge->set_etat_qcq() ;
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 ;
327 lognb->set_etat_qcq() ;
328 loge->set_etat_qcq() ;
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 ;
401 static int i_near =
lognb->get_taille() / 2 ;
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 ;
426 static int i_near =
lognb->get_taille() / 2 ;
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) ;
449 static int i_near =
lognb->get_taille() / 2 ;
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.) ;
476 static int i_near =
lognb->get_taille() / 2 ;
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) ;
string authors
Authors - reference for the table.
virtual void read_table_lorene()
Reads the file containing the table in LORENE format and initializes the arrays lognb ,...
virtual int identify() const
Returns a number to identify the sub-classe of Dyn_eos the object belongs to.
virtual ostream & operator>>(ostream &) const
Operator >>.
Dyn_eos_tab()
Default constructor to be called by derived classes.
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...
string tablename
Name of the file containing the tabulated data.
virtual bool operator!=(const Dyn_eos &) const
Comparison operator (difference).
virtual void read_table_compose()
Reads the files .nb and .thermo containing the table in CompOSE format and initializes the arrays log...
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 void sauve(FILE *) const
Save in a file.
bool compose_format
Are(is) the table(s) in CompOSE format?
virtual ~Dyn_eos_tab()
Destructor.
virtual bool operator==(const Dyn_eos &) const
Comparison operator (egality).
double nbmax
Upper boundary of the baryon density interval.
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...
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.
double nbmin
Lower boundary of the baryon density interval.
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.
Dyn_eos()
Standard constructor.
void set_etat_qcq()
Sets the logical state to ETATQCQ (ordinary state).
double & set(int i)
Read/write of a particular element (index i) (1D case).
Cmp log10(const Cmp &)
Basis 10 logarithm.
Cmp pow(const Cmp &, int)
Power .
Cmp log(const Cmp &)
Neperian logarithm.
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.
int fread_be(int *aa, int size, int nb, FILE *fich)
Reads integer(s) from a binary file according to the big endian convention.
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.
Standard units of space, time and mass.