LORENE
eos_poly_newt.C
1 /*
2  * Methods of the class Eos_poly_newt.
3  *
4  * (see file eos.h for documentation).
5  */
6 
7 /*
8  * Copyright (c) 2000-2001 Eric Gourgoulhon
9  *
10  * This file is part of LORENE.
11  *
12  * LORENE is free software; you can redistribute it and/or modify
13  * it under the terms of the GNU General Public License as published by
14  * the Free Software Foundation; either version 2 of the License, or
15  * (at your option) any later version.
16  *
17  * LORENE is distributed in the hope that it will be useful,
18  * but WITHOUT ANY WARRANTY; without even the implied warranty of
19  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20  * GNU General Public License for more details.
21  *
22  * You should have received a copy of the GNU General Public License
23  * along with LORENE; if not, write to the Free Software
24  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
25  *
26  */
27 
28 
29 char eos_poly_newt_C[] = "$Header: /cvsroot/Lorene/C++/Source/Eos/eos_poly_newt.C,v 1.5 2014/10/13 08:52:53 j_novak Exp $" ;
30 
31 /*
32  * $Id: eos_poly_newt.C,v 1.5 2014/10/13 08:52:53 j_novak Exp $
33  * $Log: eos_poly_newt.C,v $
34  * Revision 1.5 2014/10/13 08:52:53 j_novak
35  * Lorene classes and functions now belong to the namespace Lorene.
36  *
37  * Revision 1.4 2014/10/06 15:13:06 j_novak
38  * Modified #include directives to use c++ syntax.
39  *
40  * Revision 1.3 2002/10/16 14:36:35 j_novak
41  * Reorganization of #include instructions of standard C++, in order to
42  * use experimental version 3 of gcc.
43  *
44  * Revision 1.2 2002/04/09 14:32:15 e_gourgoulhon
45  * 1/ Added extra parameters in EOS computational functions (argument par)
46  * 2/ New class MEos for multi-domain EOS
47  *
48  * Revision 1.1.1.1 2001/11/20 15:19:27 e_gourgoulhon
49  * LORENE
50  *
51  * Revision 2.5 2001/02/23 15:16:51 eric
52  * Continuite en ent=0 des quantites derivees.
53  *
54  * Revision 2.4 2001/02/07 09:50:11 eric
55  * Suppression de la fonction derent_ent_p.
56  * Ajout des fonctions donnant les derivees de l'EOS:
57  * der_nbar_ent_p
58  * der_ener_ent_p
59  * der_press_ent_p
60  *
61  * Revision 2.3 2000/02/14 14:49:41 eric
62  * Modif affichage.
63  *
64  * Revision 2.2 2000/02/14 14:33:33 eric
65  * Ajout du constructeur par lecture de fichier formate.
66  *
67  * Revision 2.1 2000/01/21 15:18:56 eric
68  * Ajout des operateurs de comparaison == et !=
69  *
70  * Revision 2.0 2000/01/18 15:14:12 eric
71  * *** empty log message ***
72  *
73  *
74  * $Header: /cvsroot/Lorene/C++/Source/Eos/eos_poly_newt.C,v 1.5 2014/10/13 08:52:53 j_novak Exp $
75  *
76  */
77 
78 // Headers C
79 #include <cstdlib>
80 #include <cstring>
81 #include <cmath>
82 
83 // Headers Lorene
84 #include "eos.h"
85 #include "cmp.h"
86 
87  //--------------//
88  // Constructors //
89  //--------------//
90 
91 // Standard constructor
92 // --------------------
93 namespace Lorene {
94 Eos_poly_newt::Eos_poly_newt(double gamma, double kappa) :
95  Eos_poly(gamma, kappa) {
96 
97  set_name("Newtonian polytropic EOS") ;
98 
99 }
100 
101 
102 // Copy constructor
103 // ----------------
105 
106 
107 // Constructor from a binary file
108 // ------------------------------
110 
111 // Constructor from a formatted file
112 // ---------------------------------
113 Eos_poly_newt::Eos_poly_newt(ifstream& fich) : Eos_poly(fich) {}
114 
115 
116  //--------------//
117  // Destructor //
118  //--------------//
119 
121 
122  // does nothing
123 
124 }
125  //--------------//
126  // Assignment //
127  //--------------//
128 
130 
131  set_name(eosi.name) ;
132 
133  gam = eosi.gam ;
134  kap = eosi.kap ;
135  m_0 = eosi.m_0 ;
136 
137  set_auxiliary() ;
138 
139 }
140  //------------------------//
141  // Comparison operators //
142  //------------------------//
143 
144 bool Eos_poly_newt::operator==(const Eos& eos_i) const {
145 
146  bool resu = true ;
147 
148  if ( eos_i.identify() != identify() ) {
149  cout << "The second EOS is not of type Eos_poly_newt !" << endl ;
150  resu = false ;
151  }
152  else{
153 
154  const Eos_poly_newt& eos = dynamic_cast<const Eos_poly_newt&>( eos_i ) ;
155 
156  if (eos.gam != gam) {
157  cout
158  << "The two Eos_poly_newt have different gamma : " << gam << " <-> "
159  << eos.gam << endl ;
160  resu = false ;
161  }
162 
163  if (eos.kap != kap) {
164  cout
165  << "The two Eos_poly_newt have different kappa : " << kap << " <-> "
166  << eos.kap << endl ;
167  resu = false ;
168  }
169 
170  if (eos.m_0 != m_0) {
171  cout
172  << "The two Eos_poly_newt have different m_0 : " << m_0 << " <-> "
173  << eos.m_0 << endl ;
174  resu = false ;
175  }
176 
177  }
178 
179  return resu ;
180 
181 }
182 
183 bool Eos_poly_newt::operator!=(const Eos& eos_i) const {
184 
185  return !(operator==(eos_i)) ;
186 
187 }
188 
189 
190  //------------//
191  // Outputs //
192  //------------//
193 
194 void Eos_poly_newt::sauve(FILE* fich) const {
195 
196  Eos_poly::sauve(fich) ;
197 
198 }
199 
200 ostream& Eos_poly_newt::operator>>(ostream & ost) const {
201 
202  ost << "EOS of class Eos_poly_newt (Newtonian polytrope) : " << endl ;
203  ost << " Adiabatic index gamma : " << gam << endl ;
204  ost << " Pressure coefficient kappa : " << kap <<
205  " rho_nuc c^2 / n_nuc^gamma" << endl ;
206 
207  return ost ;
208 
209 }
210 
211 
212  //------------------------------//
213  // Computational routines //
214  //------------------------------//
215 
216 // Baryon density from enthalpy
217 //------------------------------
218 
219 double Eos_poly_newt::nbar_ent_p(double ent, const Param* ) const {
220 
221  if ( ent > double(0) ) {
222 
223  return pow( gam1sgamkap * ent, unsgam1 ) ;
224  }
225  else{
226  return 0 ;
227  }
228 }
229 
230 // Energy density from enthalpy
231 //------------------------------
232 
233 double Eos_poly_newt::ener_ent_p(double ent, const Param* ) const {
234 
235  if ( ent > double(0) ) {
236 
237  double nn = pow( gam1sgamkap * ent, unsgam1 ) ;
238 
239  double pp = kap * pow( nn, gam ) ;
240 
241  return unsgam1 * pp + m_0 * nn ;
242  }
243  else{
244  return 0 ;
245  }
246 }
247 
248 // Pressure from enthalpy
249 //------------------------
250 
251 double Eos_poly_newt::press_ent_p(double ent, const Param* ) const {
252 
253  if ( ent > double(0) ) {
254 
255  double nn = pow( gam1sgamkap * ent, unsgam1 ) ;
256 
257  return kap * pow( nn, gam ) ;
258 
259  }
260  else{
261  return 0 ;
262  }
263 }
264 
265 // dln(n)/ln(h) from enthalpy
266 //---------------------------
267 
268 double Eos_poly_newt::der_nbar_ent_p(double , const Param* ) const {
269 
270  return double(1) / gam1 ;
271 
272 }
273 
274 // dln(e)/ln(h) from enthalpy
275 //---------------------------
276 
277 double Eos_poly_newt::der_ener_ent_p(double ent, const Param* ) const {
278 
279  if ( ent > double(0) ) {
280 
281 
282  double nn = pow( gam1sgamkap * ( exp(ent) - double(1) ),
283  unsgam1 ) ;
284 
285  double pp = kap * pow( nn, gam ) ;
286 
287  double ee = unsgam1 * pp + m_0 * nn ;
288 
289 
290  return ( double(1) + pp / ee) / gam1 ;
291 
292  }
293  else{
294  return double(1) / gam1 ; // to ensure continuity at ent=0
295  }
296 }
297 
298 // dln(p)/ln(h) from enthalpy
299 //---------------------------
300 
301 double Eos_poly_newt::der_press_ent_p(double, const Param* ) const {
302 
303  return gam / gam1 ;
304 
305 }
306 
307 }
Polytropic equation of state (Newtonian case).
Definition: eos.h:1044
virtual double der_press_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 (egality)
void operator=(const Eos_poly_newt &)
Assignment to another Eos_poly_newt.
virtual double ener_ent_p(double ent, const Param *par=0x0) const
Computes the total energy density from the specific enthalpy.
virtual double press_ent_p(double ent, const Param *par=0x0) const
Computes the pressure 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 int identify() const
Returns a number to identify the sub-classe of Eos the object belongs to.
virtual void sauve(FILE *) const
Save in a file.
virtual ~Eos_poly_newt()
Destructor.
virtual bool operator!=(const Eos &) const
Comparison operator (difference)
virtual double der_nbar_ent_p(double ent, const Param *par=0x0) const
Computes the logarithmic derivative from the specific enthalpy.
virtual ostream & operator>>(ostream &) const
Operator >>
virtual double nbar_ent_p(double ent, const Param *par=0x0) const
Computes the baryon density from the specific enthalpy.
Eos_poly_newt(double gamma, double kappa)
Standard constructor.
Definition: eos_poly_newt.C:94
Polytropic equation of state (relativistic case).
Definition: eos.h:757
double kap
Pressure coefficient (cf.
Definition: eos.h:771
virtual void sauve(FILE *) const
Save in a file.
Definition: eos_poly.C:335
double gam1sgamkap
Definition: eos.h:788
double unsgam1
Definition: eos.h:787
double gam
Adiabatic index (cf. Eq. (3))
Definition: eos.h:764
double m_0
Individual particule mass (cf.
Definition: eos.h:776
double gam1
Definition: eos.h:786
void set_auxiliary()
Computes the auxiliary quantities gam1 , unsgam1 , gam1sgamkap from the values of gam and kap.
Definition: eos_poly.C:242
Equation of state base class.
Definition: eos.h:190
virtual int identify() const =0
Returns a number to identify the sub-classe of Eos the object belongs to.
char name[100]
EOS name.
Definition: eos.h:196
void set_name(const char *name_i)
Sets the EOS name.
Definition: eos.C:163
Parameter storage.
Definition: param.h:125
Cmp exp(const Cmp &)
Exponential.
Definition: cmp_math.C:270
Cmp pow(const Cmp &, int)
Power .
Definition: cmp_math.C:348
Lorene prototypes.
Definition: app_hor.h:64