eos_cs2_poly.h
Go to the documentation of this file.
1 /*
2  -------------------------------------------------------------------
3 
4  Copyright (C) 2017-2020, 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  /** \brief EOS with a constant speed of sound
153  */
155 
156  protected:
157 
158  /** \brief Chemical potential integration constant
159  */
160  double C1;
161  /** \brief Energy density integration constant
162  */
163  double C2;
164 
165  public:
166 
167  /** \brief Speed of sound
168  */
169  double cs2;
170 
171  eos_cs2_const() {
172  cs2=1.0;
173  C1=0.0;
174  C2=0.0;
175  }
176 
177  /** \brief Fix the integration constants by specifying the
178  pressure, baryon chemical potential, and energy density
179  */
180  void fix_integ_consts(double mub1, double ed1, double pr1) {
181  double nb1=(ed1+pr1)/mub1;
182  C1=mub1*pow(nb1,-cs2);
183  C2=(ed1*cs2-pr1)/(1.0+cs2);
184  return;
185  }
186 
187  /** \brief Return the chemical potential in \f$ \mathrm{fm}^{-1}
188  \f$, including the rest mass, given the baryon density in \f$
189  \mathrm{fm}^{-3} \f$
190  */
191  double mu_from_nb(double nb) {
192  return C1*pow(nb,cs2);
193  }
194 
195  /** \brief Return the energy density in \f$ \mathrm{fm}^{-4} \f$,
196  including the rest mass energy density, given the baryon density
197  in \f$ \mathrm{fm}^{-3} \f$
198  */
199  double ed_from_nb(double nb) {
200  return C1*pow(nb,cs2+1.0)/(1.0+cs2)+C2;
201  }
202 
203  /** \brief Return the energy density in \f$ \mathrm{fm}^{-4} \f$,
204  including the rest mass energy density, given the baryon density
205  in \f$ \mathrm{fm}^{-3} \f$
206  */
207  double nb_from_ed(double ed) {
208  return pow((ed-C2)*(1.0+cs2)/C1,1.0/(1.0+cs2));
209  }
210 
211  /** \brief Return the pressure in \f$ \mathrm{fm}^{-4} \f$
212  given the baryon density
213  in \f$ \mathrm{fm}^{-3} \f$
214  */
215  double pr_from_nb(double nb) {
216  return C1*cs2*pow(nb,cs2+1.0)/(1.0+cs2)-C2;
217  }
218 
219  };
220 
221 }
222 
223 #endif
o2scl::eos_cs2_poly::pr_from_nb
double pr_from_nb(double nb)
Return the pressure in given the baryon density in .
Definition: eos_cs2_poly.h:146
o2scl::eos_cs2_poly::a2i
double a2i
Second speed of sound parameter.
Definition: eos_cs2_poly.h:58
o2scl::eos_cs2_poly::fix_params
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
O2SCL_ERR2
#define O2SCL_ERR2(d, d2, n)
o2scl::eos_cs2_const::C1
double C1
Chemical potential integration constant.
Definition: eos_cs2_poly.h:160
o2scl::eos_cs2_poly::cs2_from_nb
double cs2_from_nb(double nb)
Return the squared sound speed given the baryon density in .
Definition: eos_cs2_poly.h:114
o2scl::eos_cs2_poly::C2
double C2
Energy density integration constant.
Definition: eos_cs2_poly.h:70
o2scl::eos_cs2_poly::fix_integ_consts
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
o2scl::eos_cs2_poly::a4i
double a4i
Fourth speed of sound parameter.
Definition: eos_cs2_poly.h:64
o2scl::eos_cs2_const::fix_integ_consts
void fix_integ_consts(double mub1, double ed1, double pr1)
Fix the integration constants by specifying the pressure, baryon chemical potential,...
Definition: eos_cs2_poly.h:180
o2scl::eos_cs2_const
EOS with a constant speed of sound.
Definition: eos_cs2_poly.h:154
o2scl::exc_einval
exc_einval
o2scl::eos_cs2_poly::C1
double C1
Chemical potential integration constant.
Definition: eos_cs2_poly.h:67
o2scl::eos_cs2_const::C2
double C2
Energy density integration constant.
Definition: eos_cs2_poly.h:163
o2scl::eos_cs2_poly::ed_from_nb
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
o2scl::eos_cs2_const::ed_from_nb
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:199
o2scl::eos_cs2_const::cs2
double cs2
Speed of sound.
Definition: eos_cs2_poly.h:169
o2scl::eos_cs2_poly::a1i
double a1i
First speed of sound parameter.
Definition: eos_cs2_poly.h:55
o2scl::eos_cs2_poly::a3i
double a3i
Third speed of sound parameter.
Definition: eos_cs2_poly.h:61
o2scl::eos_cs2_poly
An EOS based on a polynomial speed of sound.
Definition: eos_cs2_poly.h:50
o2scl::eos_cs2_poly::mu_from_nb
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
o2scl::eos_cs2_const::pr_from_nb
double pr_from_nb(double nb)
Return the pressure in given the baryon density in .
Definition: eos_cs2_poly.h:215
o2scl::eos_cs2_const::nb_from_ed
double nb_from_ed(double ed)
Return the energy density in , including the rest mass energy density, given the baryon density in .
Definition: eos_cs2_poly.h:207
o2scl::eos_cs2_const::mu_from_nb
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:191

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