eos_cs2_poly.h
Go to the documentation of this file.
1 /*
2  -------------------------------------------------------------------
3 
4  Copyright (C) 2017-2018, Andrew W. Steiner
5 
6  This file is part of O2scl.
7 
8  O2scl is free software; you can redistribute it and/or modify
9  it under the terms of the GNU General Public License as published by
10  the Free Software Foundation; either version 3 of the License, or
11  (at your option) any later version.
12 
13  O2scl is distributed in the hope that it will be useful,
14  but WITHOUT ANY WARRANTY; without even the implied warranty of
15  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  GNU General Public License for more details.
17 
18  You should have received a copy of the GNU General Public License
19  along with O2scl. If not, see <http://www.gnu.org/licenses/>.
20 
21  -------------------------------------------------------------------
22 */
23 /** \file eos_cs2_poly.h
24  \brief File defining \ref o2scl::eos_cs2_poly
25 */
26 #ifndef O2SCL_EOS_CS2_POLY_H
27 #define O2SCL_EOS_CS2_POLY_H
28 
29 #include <gsl/gsl_sf_hyperg.h>
30 
31 #include <o2scl/constants.h>
32 #include <o2scl/err_hnd.h>
33 
34 namespace o2scl {
35 
36  /** \brief An EOS based on a polynomial speed of sound
37 
38  Based on \ref Constantinou17 .
39 
40  This class constructs an EOS based on a speed of sound of the form
41  \f[
42  c_s^2 = a_1 + \frac{a_2 n_B^{a_3}}{1+a_4 n_B^{a_3}}
43  \f]
44  where \f$ n_B \f$ is the baryon number density .
45 
46  The EOS requires a hypergeometric function which only converges
47  under specific conditions on the parameters.
48 
49  */
50  class eos_cs2_poly {
51 
52  protected:
53  /** \brief First speed of sound parameter
54  */
55  double a1i;
56  /** \brief Second speed of sound parameter
57  */
58  double a2i;
59  /** \brief Third speed of sound parameter
60  */
61  double a3i;
62  /** \brief Fourth speed of sound parameter
63  */
64  double a4i;
65  /** \brief Chemical potential integration constant
66  */
67  double C1;
68  /** \brief Energy density integration constant
69  */
70  double C2;
71 
72  public:
73 
74  eos_cs2_poly() {
75  C1=0.0;
76  C2=0.0;
77  }
78 
79  /** \brief Fix \f$ a_1 \f$ and \f$ a_2 \f$ based on fitting
80  to the sound speed at two different densities
81  */
82  void fix_params(double nb0, double cs20, double nb1, double cs21,
83  double a3, double a4) {
84  a3i=a3;
85  a4i=a4;
86  double nb0a3=pow(nb0,a3);
87  double nb1a3=pow(nb1,a3);
88  a1i=(cs21*nb0a3-cs20*nb1a3-a4*cs20*nb0a3*nb1a3+a4*cs21*nb0a3*nb1a3)/
89  (nb0a3-nb1a3);
90  a2i=(cs20-cs21)*(1.0+a4*nb0a3)*(1.0+a4*nb1a3)/(nb0a3-nb1a3);
91  return;
92  }
93 
94  /** \brief Fix the integration constants by specifying the
95  chemical potential at some baryon density and the energy density
96  at another baryon density
97  */
98  void fix_integ_consts(double nb1, double mu1, double nb2, double ed2) {
99  C1=mu1*pow(nb1,-a1i)*pow(1.0+a4i*pow(nb1,a3i),-a2i/a3i/a4i);
100  double na3=pow(nb2,a3i);
101  if (fabs(-a4i*na3)>1.0) {
102  O2SCL_ERR2("Fourth argument of hyperg_2F1 greater than 1 ",
103  "in eos_cs2_poly::fix_coeffs().",o2scl::exc_einval);
104  }
105  C2=((1.0+a1i)*ed2-pow(nb2,1.0+a1i)*C1*
106  gsl_sf_hyperg_2F1((1.0+a1i)/a3i,-a2i/a3i/a4i,(1.0+a1i+a3i)/a3i,
107  -a4i*na3))/(1.0+a1i);
108  return;
109  }
110 
111  /** \brief Return the squared sound speed given the baryon density
112  in \f$ \mathrm{fm}^{-3} \f$
113  */
114  double cs2_from_nb(double nb) {
115  double nba3=pow(nb,a3i);
116  return a1i+a2i*nba3/(1.0+a4i*nba3);
117  }
118 
119  /** \brief Return the chemical potential in \f$ \mathrm{fm}^{-1}
120  \f$, including the rest mass, given the baryon density in \f$
121  \mathrm{fm}^{-3} \f$
122  */
123  double mu_from_nb(double nb) {
124  return pow(nb,a1i)*pow(1.0+a4i*pow(nb,a3i),a2i/a3i/a4i)*C1;
125  }
126 
127  /** \brief Return the energy density in \f$ \mathrm{fm}^{-4} \f$,
128  including the rest mass energy density, given the baryon density
129  in \f$ \mathrm{fm}^{-3} \f$
130  */
131  double ed_from_nb(double nb) {
132  double na3=pow(nb,a3i);
133  if (fabs(-a4i*na3)>1.0) {
134  O2SCL_ERR2("Fourth argument of hyperg_2F1 greater than 1 ",
135  "in eos_cs2_poly::ed_from_nb().",o2scl::exc_einval);
136  }
137  return C2+pow(nb,1.0+a1i)*C1*
138  gsl_sf_hyperg_2F1((1.0+a1i)/a3i,-a2i/a3i/a4i,1.0+(1.0+a1i)/a3i,
139  -a4i*na3)/(1.0+a1i);
140  }
141 
142  /** \brief Return the pressure in \f$ \mathrm{fm}^{-4} \f$
143  given the baryon density
144  in \f$ \mathrm{fm}^{-3} \f$
145  */
146  double pr_from_nb(double nb) {
147  return -ed_from_nb(nb)+nb*mu_from_nb(nb);
148  }
149 
150  };
151 
152 }
153 
154 #endif
double mu_from_nb(double nb)
Return the chemical potential in , including the rest mass, given the baryon density in ...
Definition: eos_cs2_poly.h:123
double cs2_from_nb(double nb)
Return the squared sound speed given the baryon density in .
Definition: eos_cs2_poly.h:114
void fix_params(double nb0, double cs20, double nb1, double cs21, double a3, double a4)
Fix and based on fitting to the sound speed at two different densities.
Definition: eos_cs2_poly.h:82
double a2i
Second speed of sound parameter.
Definition: eos_cs2_poly.h:58
An EOS based on a polynomial speed of sound.
Definition: eos_cs2_poly.h:50
double pr_from_nb(double nb)
Return the pressure in given the baryon density in .
Definition: eos_cs2_poly.h:146
void fix_integ_consts(double nb1, double mu1, double nb2, double ed2)
Fix the integration constants by specifying the chemical potential at some baryon density and the ene...
Definition: eos_cs2_poly.h:98
double a3i
Third speed of sound parameter.
Definition: eos_cs2_poly.h:61
double ed_from_nb(double nb)
Return the energy density in , including the rest mass energy density, given the baryon density in ...
Definition: eos_cs2_poly.h:131
#define O2SCL_ERR2(d, d2, n)
double C1
Chemical potential integration constant.
Definition: eos_cs2_poly.h:67
double C2
Energy density integration constant.
Definition: eos_cs2_poly.h:70
double a1i
First speed of sound parameter.
Definition: eos_cs2_poly.h:55
double a4i
Fourth speed of sound parameter.
Definition: eos_cs2_poly.h:64

Documentation generated with Doxygen. Provided under the GNU Free Documentation License (see License Information).