144#include "utilitaires.h"
149 void interpol_herm(
const Tbl& ,
const Tbl&,
const Tbl&,
double,
int&,
152 void interpol_linear(
const Tbl&,
const Tbl&,
double,
int&,
double&) ;
154 void interpol_quad(
const Tbl&,
const Tbl&,
double,
int&,
double&) ;
165 const char* path) :
Eos(name_i)
190 char tmp_string[160] ;
191 fread(tmp_string,
sizeof(
char), 160, fich) ;
249 char tmp_string[160] ;
251 fwrite(tmp_string,
sizeof(
char), 160, fich) ;
262 ifstream is_meos(
"meos_is_being_built.d") ;
267 cerr <<
"Eos_tabul::read_table(): " << endl ;
268 cerr <<
"Problem in opening the EOS file!" << endl ;
269 cerr <<
"While trying to open " <<
tablename << endl ;
270 cerr <<
"Aborting..." << endl ;
274 fich.ignore(1000,
'\n') ;
277 for (
int i=0; i<3; i++) {
278 fich.ignore(1000,
'\n') ;
282 fich >> nbp ; fich.ignore(1000,
'\n') ;
284 cerr <<
"Eos_tabul::read_table(): " << endl ;
285 cerr <<
"Wrong value for the number of lines!" << endl ;
286 cerr <<
"nbp = " << nbp << endl ;
287 cerr <<
"Aborting..." << endl ;
291 for (
int i=0; i<3; i++) {
292 fich.ignore(1000,
'\n') ;
295 press =
new double[nbp] ;
296 nb =
new double[nbp] ;
297 ro =
new double[nbp] ;
309 logh->set_etat_qcq() ;
310 logp->set_etat_qcq() ;
312 lognb->set_etat_qcq() ;
315 double rhonuc_cgs = rhonuc_si * 1e-3 ;
316 double c2_cgs = c_si * c_si * 1e4 ;
319 double nb_fm3, rho_cgs, p_cgs ;
321 for (
int i=0; i<nbp; i++) {
326 fich >> p_cgs ; fich.ignore(1000,
'\n') ;
327 if ( (nb_fm3<0) || (rho_cgs<0) || (p_cgs < 0) ){
328 cout <<
"Eos_tabul::read_table(): " << endl ;
329 cout <<
"Negative value in table!" << endl ;
330 cout <<
"nb = " << nb_fm3 <<
", rho = " << rho_cgs <<
331 ", p = " << p_cgs << endl ;
332 cout <<
"Aborting..." << endl ;
336 press[i] = p_cgs / c2_cgs ;
340 press_tbl.
set(i) = press[i] ;
341 nb_tbl.
set(i) = nb[i] ;
342 ro_tbl.
set(i) = ro[i] ;
346 bool store_offset = false ;
347 bool compute_offset = true ;
352 if (temp.find(ok) != string::npos) {
354 compute_offset = false ;
358 store_offset = true ;
362 for (
int i=0; i<nbp; i++) {
363 double h =
log( (ro[i] + press[i]) /
364 (10 * nb[i] * rhonuc_cgs) ) ;
366 if ((i==0) && compute_offset) { ww = h ; }
367 h = h - ww + 1.e-14 ;
370 logp->set(i) =
log10( press[i] / rhonuc_cgs ) ;
371 dlpsdlh->set(i) = h * (ro[i] + press[i]) / press[i] ;
375 if (store_offset ==
true) {
376 ofstream write_meos(
"meos_is_being_built.d", ios_base::app) ;
377 write_meos <<
"ok" << endl ;
378 write_meos << setprecision(16) << ww << endl ;
384 Tbl logp0 = ((*logp) +
log10(rhonuc_cgs)) *
log(10.) ;
391 for (
int i=0; i<nbp; i++) {
393 tmp.
set(i) = - tmp(i) ;
400 cout <<
"hmin, hmax : " <<
hmin <<
" " <<
hmax << endl ;
421 static int i_near =
logh->get_taille() / 2 ;
425 cout <<
"Eos_tabul::nbar_ent_p : ent > hmax !" << endl ;
428 double logh0 =
log10( ent ) ;
434 double pp =
pow(
double(10), logp0) ;
436 double resu = pp / ent * dlpsdlh0 *
exp(-ent) ;
449 static int i_near =
logh->get_taille() / 2 ;
453 cout <<
"Eos_tabul::ener_ent_p : ent > hmax !" << endl ;
456 double logh0 =
log10( ent ) ;
462 double pp =
pow(
double(10), logp0) ;
464 double resu = pp / ent * dlpsdlh0 - pp ;
477 static int i_near =
logh->get_taille() / 2 ;
481 cout <<
"Eos_tabul::press_ent_p : ent > hmax !" << endl ;
485 double logh0 =
log10( ent ) ;
490 return pow(
double(10), logp0) ;
504 cout <<
"Eos_tabul::der_nbar_ent_p : ent > hmax !" << endl ;
528 cout <<
"Eos_tabul::der_ener_ent_p : ent > hmax !" << endl ;
545 static int i_near =
logh->get_taille() / 2 ;
549 cout <<
"Eos_tabul::der_press_ent_p : ent > hmax !" << endl ;
553 double logh0 =
log10( ent ) ;
575 static int i_near =
logh->get_taille() / 2 ;
579 cout <<
"Eos_tabul::der_press_nbar_p : ent > hmax !" << endl ;
583 double logh0 =
log10( ent ) ;
586 interpol_linear(*
logh, *
dlpsdlnb, logh0, i_near, dlpsdlnb0) ;
600 static int i_near =
lognb->get_taille() / 2 ;
604 cout <<
"Eos_tabul::csound_square_ent_p : ent>hmax !" << endl ;
607 double log_ent0 =
log10( ent ) ;
610 interpol_linear(*
logh, *
log_cs2, log_ent0, i_near, log_csound0) ;
612 return pow(10., log_csound0) ;
virtual double press_ent_p(double ent, const Param *par=0x0) const
Computes the pressure from the log-enthalpy.
virtual double ener_ent_p(double ent, const Param *par=0x0) const
Computes the total energy density from the log-enthalpy.
virtual double der_press_ent_p(double ent, const Param *par=0x0) const
Computes the logarithmic derivative from the log-enthalpy.
virtual void read_table()
Reads the file containing the table and initializes in the arrays logh , logp and dlpsdlh .
virtual ~Eos_tabul()
Destructor.
Eos_tabul(const char *name_i, const char *table, const char *path)
Standard constructor.
virtual double nbar_ent_p(double ent, const Param *par=0x0) const
Computes the baryon density from the log-enthalpy.
virtual double der_nbar_ent_p(double ent, const Param *par=0x0) const
Computes the logarithmic derivative from the log-enthalpy.
virtual double der_ener_ent_p(double ent, const Param *par=0x0) const
Computes the logarithmic derivative from the log-enthalpy.
virtual void sauve(FILE *) const
Save in a file.
virtual double csound_square_ent_p(double, const Param *) const
Computes the sound speed squared from the enthapy with extra parameters (virtual function implemente...
string tablename
Name of the file containing the tabulated data.
double hmin
Lower boundary of the enthalpy interval.
virtual double der_press_nbar_p(double ent, const Param *par=0x0) const
Computes the logarithmic derivative from the log-enthalpy.
string authors
Authors - reference for the table.
double hmax
Upper boundary of the enthalpy interval.
virtual void sauve(FILE *) const
Save in a file.
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 exp(const Cmp &)
Exponential.
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.
Standard units of space, time and mass.