53 n_lim1(n_lim0), n_lim2(n_lim0), m_n(m_n0) {
55 cerr <<
"Deprecated constructor, please do not use ! Aborting..." << endl; abort() ;
56 set_name(
"Pseudo-polytropic fit of cold, beta-equilibrated EoS") ;
59 coefs =
new Tbl(coefs0) ;
60 n_coefs = coefs->get_taille() ;
62 double x_lim =
log(n_lim1*0.1) ;
63 double alpha = (*coefs)(n_coefs-1) ;
64 double sum_poly = 0., sum_der_poly = 0. ;
65 for (
int i=0; i<n_coefs-1; i++){
66 sum_poly += (*coefs)(i)*
pow(x_lim,
double(i)) ;
67 sum_der_poly += (i == 0) ? 0. : (*coefs)(i)*
double(i)*
pow(x_lim,
double(i-1)) ;
69 ent_lim1 = log1p(
exp(alpha*x_lim)*((alpha+1)*sum_poly + sum_der_poly)) ;
77 n_lim1(eosi.n_lim1), n_lim2(eosi.n_lim2), ent_lim1(eosi.ent_lim1), ent_lim2(eosi.ent_lim2),
78 m_n(eosi.m_n), Lambda(eosi.Lambda), ddd(eosi.ddd), Kappa_GPP(eosi.Kappa_GPP),
79 Gamma_GPP(eosi.Gamma_GPP), Lambda_GPP(eosi.Lambda_GPP), ddd_GPP(eosi.ddd_GPP), n_coefs(eosi.n_coefs) {}
86 fread_be(&n_coefs,
sizeof(
int), 1, fich) ;
87 coefs =
new Tbl(fich) ;
88 fread_be(&kappa_low,
sizeof(
double), 1, fich) ;
89 fread_be(&gamma_low,
sizeof(
double), 1, fich) ;
90 fread_be(&n_lim1,
sizeof(
double), 1, fich) ;
91 fread_be(&ent_lim1,
sizeof(
double), 1, fich) ;
92 fread_be(&n_lim2,
sizeof(
double), 1, fich) ;
93 fread_be(&ent_lim2,
sizeof(
double), 1, fich) ;
94 fread_be(&m_n,
sizeof(
double), 1, fich) ;
95 fread_be(&Lambda,
sizeof(
double), 1, fich) ;
96 fread_be(&ddd,
sizeof(
double), 1, fich) ;
97 fread_be(&Kappa_GPP,
sizeof(
double), 1, fich) ;
98 fread_be(&Gamma_GPP,
sizeof(
double), 1, fich) ;
99 fread_be(&Lambda_GPP,
sizeof(
double), 1, fich) ;
100 fread_be(&ddd_GPP,
sizeof(
double), 1, fich) ;
102 eos_low =
new Eos_poly(gamma_low, kappa_low) ;
109 fich >> n_coefs ; fich.ignore(1000,
'\n') ;
112 for (
int i=0; i < n_coefs; i++)
113 fich >> coefs->
set(i) ;
114 fich.ignore(1000,
'\n') ;
116 fich >> n_lim1 ; fich.ignore(1000,
'\n') ;
117 fich >> n_lim2 ; fich.ignore(1000,
'\n') ;
119 fich >> kappa_low ; fich.ignore(1000,
'\n') ;
121 fich >> gamma_low ; fich.ignore(1000,
'\n') ;
123 fich >> m_n ; fich.ignore(1000,
'\n') ;
125 fich >> Lambda ; fich.ignore(1000,
'\n') ;
127 fich >> ddd ; fich.ignore(1000,
'\n') ;
129 fich >> Kappa_GPP ; fich.ignore(1000,
'\n');
131 fich >> Gamma_GPP ; fich.ignore(1000,
'\n');
133 fich >> Lambda_GPP ; fich.ignore(1000,
'\n') ;
135 fich >> ddd_GPP ; fich.ignore(1000,
'\n') ;
137 double x_lim2 =
log(n_lim2*0.1) ;
138 double alpha = (*coefs)(n_coefs-1) ;
139 double sum_poly = 0., sum_der_poly = 0. ;
140 for (
int i=0; i<n_coefs-1; i++){
141 sum_poly += (*coefs)(i)*
pow(x_lim2,
double(i)) ;
142 sum_der_poly += (i == 0) ? 0. : (*coefs)(i)*
double(i)*
pow(x_lim2,
double(i-1)) ;
144 cout << setprecision(16) <<
"nlim1: " << n_lim1*0.1 <<
" n_lim2: " << n_lim2*0.1 << endl <<
" ddd: " << ddd <<
" et: " ;
145 ent_lim2 = log1p(ddd +
exp(alpha*x_lim2)*((alpha+1)*sum_poly + sum_der_poly)) ;
146 ent_lim1 = log1p(ddd_GPP + Gamma_GPP*Kappa_GPP/(Gamma_GPP-1.) *
pow(n_lim1, Gamma_GPP-1.)) ;
147 cout << ent_lim1 << endl;
148 cout << ent_lim2 << endl;
150 eos_low =
new Eos_poly(gamma_low, kappa_low) ;
161 if (coefs != 0x0)
delete coefs ;
162 if (eos_low != 0x0)
delete eos_low ;
174 n_lim1 = eosi.n_lim1 ;
175 n_lim2 = eosi.n_lim2 ;
176 n_coefs = eosi.n_coefs ;
177 gamma_low = eosi.gamma_low ;
178 kappa_low = eosi.kappa_low ;
180 ent_lim1 = eosi.ent_lim1 ;
181 ent_lim2 = eosi.ent_lim2 ;
182 Lambda = eosi.Lambda ;
184 Kappa_GPP = eosi.Kappa_GPP ;
185 Gamma_GPP = eosi.Gamma_GPP ;
186 Lambda_GPP = eosi.Lambda_GPP ;
187 ddd_GPP = eosi.ddd_GPP ;
188 eos_low = eosi.eos_low ;
200 cout <<
"The second EOS is not of type Pseudo_polytrope_1D !" << endl ;
207 for (
int i=0; i < n_coefs; i++)
208 if ((*eos.coefs)(i) != (*coefs)(i)) {
210 <<
"The two Pseudo_polytrope_1D have different coefficients: " << (*coefs)(i) <<
" <-> " 211 << (*eos.coefs)(i) << endl ;
215 if (eos.n_lim1 != n_lim1) {
217 <<
"The two Pseudo_polytrope_1D have different limiting densities n_lim1: " << n_lim1 <<
" <-> " 218 << eos.n_lim1 << endl ;
222 if (eos.ent_lim1 != ent_lim1) {
224 <<
"The two Pseudo_polytrope_1D have different limiting enthalpies ent_lim1: " << ent_lim1 <<
" <-> " 225 << eos.ent_lim1 << endl ;
229 if (eos.n_lim2 != n_lim2) {
231 <<
"The two Pseudo_polytrope_1D have different limiting densities n_lim2: " << n_lim2 <<
" <-> " 232 << eos.n_lim2 << endl ;
236 if (eos.ent_lim2 != ent_lim2) {
238 <<
"The two Pseudo_polytrope_1D have different limiting enthalpies ent_lim2: " << ent_lim2 <<
" <-> " 239 << eos.ent_lim2 << endl ;
243 if (eos.n_coefs != n_coefs) {
245 <<
"The two Pseudo_polytrope_1D have different number of coefficients: " << n_coefs <<
" <-> " 246 << eos.n_coefs << endl ;
250 if (eos.kappa_low != kappa_low) {
252 <<
"The two Pseudo_polytrope_1D have different kappa in low polytrope: " << kappa_low <<
" <-> " 253 << eos.kappa_low << endl ;
257 if (eos.gamma_low != gamma_low) {
259 <<
"The two Pseudo_polytrope_1D have different kappa in low polytrope: " << gamma_low <<
" <-> " 260 << eos.gamma_low << endl ;
266 <<
"The two Pseudo_polytrope_1D have different ddd: " << ddd <<
" <-> " 271 if (eos.Lambda!= Lambda) {
273 <<
"The two Pseudo_polytrope_1D have different Lambda: " << Lambda <<
" <-> " 274 << eos.Lambda << endl ;
278 if (eos.Kappa_GPP!= Kappa_GPP) {
280 <<
"The two Pseudo_polytrope_1D have different Kappa_GPP: " << Kappa_GPP <<
" <-> " 281 << eos.Kappa_GPP << endl ;
285 if (eos.Gamma_GPP!= Gamma_GPP) {
287 <<
"The two Pseudo_polytrope_1D have different Gamma_GPP: " << Gamma_GPP <<
" <-> " 288 << eos.Gamma_GPP << endl ;
292 if (eos.Lambda_GPP!= Lambda_GPP) {
294 <<
"The two Pseudo_polytrope_1D have different Lambda_GPP: " << Lambda_GPP <<
" <-> " 295 << eos.Lambda_GPP << endl ;
299 if (eos.ddd_GPP!= ddd_GPP) {
301 <<
"The two Pseudo_polytrope_1D have different ddd_GPP: " << ddd_GPP <<
" <-> " 302 << eos.ddd_GPP << endl ;
327 fwrite_be(&n_coefs,
sizeof(
int), 1, fich) ;
329 fwrite_be(&kappa_low,
sizeof(
double), 1, fich) ;
330 fwrite_be(&gamma_low,
sizeof(
double), 1, fich) ;
331 fwrite_be(&n_lim1,
sizeof(
double), 1, fich) ;
332 fwrite_be(&ent_lim1,
sizeof(
double), 1, fich) ;
333 fwrite_be(&n_lim2,
sizeof(
double), 1, fich) ;
334 fwrite_be(&ent_lim2,
sizeof(
double), 1, fich) ;
335 fwrite_be(&m_n,
sizeof(
double), 1, fich) ;
336 fwrite_be(&Lambda,
sizeof(
double), 1, fich) ;
337 fwrite_be(&ddd,
sizeof(
double), 1, fich) ;
338 fwrite_be(&Kappa_GPP,
sizeof(
double), 1, fich) ;
339 fwrite_be(&Gamma_GPP,
sizeof(
double), 1, fich) ;
340 fwrite_be(&Lambda_GPP,
sizeof(
double), 1, fich) ;
341 fwrite_be(&ddd_GPP,
sizeof(
double), 1, fich) ;
348 ost << setprecision(16) <<
"EOS of class Pseudo_polytrope_1D (analytical fit of cold EoS): " <<
'\n' ;
349 ost <<
" Coefficients: " << *coefs <<
'\n' ;
350 ost << setprecision(16) <<
" Baryon mass: " << m_n <<
" [MeV]" <<
'\n' ;
351 ost << setprecision(16) <<
" ddd: " << ddd <<
" and Lambda: " << Lambda <<
'\n' ;
352 ost << setprecision(16) <<
" Kappa_GPP: " << Kappa_GPP <<
" and Gamma_GPP: " << Gamma_GPP <<
'\n' ;
353 ost << setprecision(16) <<
" Lambda_GPP: " << ddd <<
" and Lambda_GPP: " << Lambda <<
'\n' ;
354 ost <<
"Low densities polytrope :" <<
'\n' ;
355 cout << *eos_low <<
'\n' ;
356 ost << setprecision(16) <<
" Limiting density n_lim1: " << 0.1*n_lim1 <<
" [fm^-3]" <<
'\n' ;
357 ost << setprecision(16) <<
" Limiting enthalpy h_lim1: " << ent_lim1 <<
" [c^2]" << endl;
358 ost << setprecision(16) <<
" Limiting density n_lim2: " << 0.1*n_lim2 <<
" [fm^-3]" <<
'\n' ;
359 ost << setprecision(16) <<
" Limiting enthalpy h_lim2: " << ent_lim2 <<
" [c^2]" << endl;
375 if (ent >= ent_lim2 ) {
377 auto ent_nb_p = [&](
double nbar) {
378 double xx =
log(nbar*0.1) ;
379 double alpha = (*coefs)(n_coefs-1) ;
380 double sum_poly = 0.;
381 for (
int i=0; i < n_coefs-1; i++){
382 double cc1 = (alpha+1.)*(*coefs)(i) ;
383 double cc2 = (i == n_coefs - 2) ? 0. :
double(i+1)*(*coefs)(i+1) ;
384 sum_poly += (cc1 + cc2)*
pow(xx,
double(i));
386 double arg =
exp(alpha*xx)*sum_poly + ddd ;
387 return log1p(arg) - ent ;
390 double a = n_lim2/2., b =
max(100.*ent, 50.*n_lim2) ;
391 double f0 = ent_nb_p(a), f1 = ent_nb_p(b) ;
392 double c=1., c_old=2., f2 ;
394 assert( f0 * f1 < 0.) ;
395 while(fabs((c-c_old)/c)>eps) {
397 c = (b*f0 - a*f1)/(f0 - f1) ;
411 else if ( (ent_lim1 <= ent) && (ent < ent_lim2)){
413 return pow((expm1(ent)-ddd_GPP)*(Gamma_GPP-1.)/(Kappa_GPP*Gamma_GPP), 1./(Gamma_GPP-1.));
415 else if ( (0 < ent) && (ent < ent_lim1)){
428 if (ent >= ent_lim2 ) {
431 double xx =
log(nbar*0.1) ;
433 double alpha = (*coefs)(n_coefs-1) ;
434 double sum_poly = 0.;
435 for (
int i=0; i < n_coefs-1; i++)
436 sum_poly += (*coefs)(i)*
pow(xx,
double(i));
437 return m_n*Unites::mevpfm3*(
exp(xx)*(1.+ddd) +
exp((alpha+1) * xx)*sum_poly) - Lambda ;
439 else if ( (ent_lim1 <= ent) && (ent < ent_lim2)){
440 double nbar =
pow((expm1(ent)-ddd_GPP)*(Gamma_GPP-1.)/(Kappa_GPP*Gamma_GPP), 1./(Gamma_GPP-1.));
441 return nbar*(1 + (Gamma_GPP-1.)/Gamma_GPP * (1./(Gamma_GPP-1.) * expm1(ent) + ddd_GPP)) - Lambda_GPP;
443 else if ( (0 < ent) && (ent < ent_lim1)){
456 if (ent >= ent_lim2 ) {
460 double xx =
log(nbar*0.1) ;
462 double alpha = (*coefs)(n_coefs-1) ;
463 double sum_poly = 0.;
464 for (
int i=0; i < n_coefs-1; i++){
465 double cc1 = alpha*(*coefs)(i) ;
466 double cc2 = (i == n_coefs - 2) ? 0. :
double(i+1)*(*coefs)(i+1) ;
467 sum_poly += (cc1 + cc2)*
pow(xx,
double(i));
470 return m_n*Unites::mevpfm3*(
exp((alpha+1.)*xx) * sum_poly) + Lambda;
472 else if ( (ent_lim1 <= ent) && (ent < ent_lim2)){
473 return Kappa_GPP*
pow((expm1(ent)-ddd_GPP)*(Gamma_GPP-1.)/(Kappa_GPP*Gamma_GPP), Gamma_GPP/(Gamma_GPP-1.)) + Lambda_GPP;
475 else if ( (0 < ent) && (ent < ent_lim1)){
508 if (ent >= ent_lim2 ) {
510 double xx =
log(nbar*0.1) ;
512 double alpha = (*coefs)(n_coefs-1) ;
513 double sum_poly = 0., sum_der_poly = 0., sum_der2_poly = 0.;
514 for (
int i=0; i < n_coefs-1; i++){
515 sum_poly += (*coefs)(i)*
pow(xx,
double(i));
516 sum_der_poly += (i == 0) ? 0. :
double(i) * (*coefs)(i) *
pow(xx,
double(i-1)) ;
517 sum_der2_poly += (i < 2) ? 0. :
double(i) * double(i-1) * (*coefs)(i) *
pow(xx,
double(i-2)) ;
519 double num = (alpha*(alpha+1.) * sum_poly + (2.*alpha+1.) * sum_der_poly + sum_der2_poly)*
exp(alpha*xx) ;
520 double denom = 1. + ddd + ((alpha+1.) * sum_poly + sum_der_poly)*
exp(alpha*xx) ;
524 else if ( (ent_lim1 <= ent) && (ent < ent_lim2)){
525 return (Gamma_GPP-1.)*(1.-
exp(-ent)*(1.+ddd_GPP));
527 else if ( (0 < ent) && (ent < ent_lim1)){
virtual double ener_ent_p(double ent, const Param *par=0x0) const
Computes the total energy density from the log-enthalpy.
Cmp log(const Cmp &)
Neperian logarithm.
Cmp exp(const Cmp &)
Exponential.
virtual int identify() const
Returns a number to identify the sub-classe of Eos the object belongs to.
Equation of state base class.
double & set(int i)
Read/write of a particular element (index i) (1D case)
virtual int identify() const =0
Returns a number to identify the sub-classe of Eos the object belongs to.
virtual double nbar_ent_p(double ent, const Param *par=0x0) const
Computes the baryon density from the specific enthalpy.
virtual double csound_square_ent_p(double, const Param *) const
Computes the sound speed squared from the enthapy with extra parameters (virtual function implemente...
virtual void sauve(FILE *) const
Save in a file.
void set_etat_qcq()
Sets the logical state to ETATQCQ (ordinary state).
int get_ndim() const
Gives the number of dimensions (ie dim.ndim)
virtual bool operator==(const Eos &) const
Comparison operator (egality)
virtual double ener_ent_p(double ent, const Param *par=0x0) const
Computes the total energy density from the specific enthalpy.
Pseudo_polytrope_1D(const Tbl &, double, double)
Standard constructor.
virtual double nbar_ent_p(double ent, const Param *par=0x0) const
Computes the baryon density from the log-enthalpy.
virtual double press_ent_p(double ent, const Param *par=0x0) const
Computes the pressure from the specific enthalpy.
Polytropic equation of state (relativistic case).
Tbl max(const Cmp &)
Maximum values of a Cmp in each domain.
virtual double csound_square_ent_p(double ent, const Param *par=0x0) const
Computes the sound speed squared from the enthapy with extra parameters (virtual function implemente...
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 press_ent_p(double ent, const Param *par=0x0) const
Computes the pressure from the log-enthalpy.
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.
void operator=(const Pseudo_polytrope_1D &)
Assignment to another Pseudo_polytrope_1D.
virtual ostream & operator>>(ostream &) const
Operator >>
virtual double der_press_ent_p(double ent, const Param *par=0x0) const
Computes the logarithmic derivative from the specific enthalpy.
void c_est_pas_fait(const char *)
Helpful function to say something is not implemented yet.
void set_name(const char *name_i)
Sets the EOS name.
void sauve(FILE *) const
Save in a file.
virtual ~Pseudo_polytrope_1D()
Destructor.
virtual double der_nbar_ent_p(double ent, const Param *par=0x0) const
Computes the logarithmic derivative from the specific enthalpy.
virtual double der_ener_ent_p(double ent, const Param *par=0x0) const
Computes the logarithmic derivative from the specific enthalpy.
virtual bool operator!=(const Eos &) const
Comparison operator (difference)
virtual void sauve(FILE *) const
Save in a file.