LORENE
eos_fermi.C
1 /*
2  * Methods of the class Eos_Fermi.
3  *
4  * (see file eos.h for documentation).
5  */
6 
7 /*
8  * Copyright (c) 2012 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 
30 
31 /*
32  * $Id: eos_fermi.C,v 1.3 2016/12/05 16:17:51 j_novak Exp $
33  * $Log: eos_fermi.C,v $
34  * Revision 1.3 2016/12/05 16:17:51 j_novak
35  * Suppression of some global variables (file names, loch, ...) to prevent redefinitions
36  *
37  * Revision 1.2 2014/10/13 08:52:52 j_novak
38  * Lorene classes and functions now belong to the namespace Lorene.
39  *
40  * Revision 1.1 2012/10/26 14:09:33 e_gourgoulhon
41  * Added new class Eos_Fermi
42  *
43  *
44  * $Header: /cvsroot/Lorene/C++/Source/Eos/eos_fermi.C,v 1.3 2016/12/05 16:17:51 j_novak Exp $
45  *
46  */
47 
48 // Headers C
49 #include <cstdlib>
50 #include <cstring>
51 #include <cmath>
52 
53 // Headers Lorene
54 #include "eos.h"
55 #include "utilitaires.h"
56 
57  //--------------//
58  // Constructors //
59  //--------------//
60 
61 // Standard constructor with g_s = 2
62 // ----------------------------------
63 
64 namespace Lorene {
65 Eos_Fermi::Eos_Fermi(double mass) :
66  Eos("Degenerate ideal Fermi gas"),
67  m_0(mass), g_s(2) {
68 
69  set_auxiliary() ;
70 
71 }
72 
73 // Standard constructor
74 // --------------------
75 
76 Eos_Fermi::Eos_Fermi(double mass, int g_degen) :
77  Eos("Degenerate ideal Fermi gas"),
78  m_0(mass), g_s(g_degen) {
79 
80  set_auxiliary() ;
81 
82 }
83 
84 
85 // Copy constructor
86 // ----------------
88  Eos(eosi),
89  m_0(eosi.m_0), g_s(eosi.g_s) {
90 
91  set_auxiliary() ;
92 
93 }
94 
95 
96 // Constructor from binary file
97 // ----------------------------
98 Eos_Fermi::Eos_Fermi(FILE* fich) :
99  Eos(fich) {
100 
101  fread_be(&m_0, sizeof(double), 1, fich) ;
102  fread_be(&g_s, sizeof(int), 1, fich) ;
103 
104  set_auxiliary() ;
105 
106 }
107 
108 
109 // Constructor from a formatted file
110 // ---------------------------------
111 Eos_Fermi::Eos_Fermi(ifstream& fich) :
112  Eos(fich) {
113 
114  char blabla[80] ;
115 
116  fich >> m_0 ; fich.getline(blabla, 80) ;
117  fich >> g_s ; fich.getline(blabla, 80) ;
118 
119  set_auxiliary() ;
120 
121 }
122  //--------------//
123  // Destructor //
124  //--------------//
125 
127 
128  // does nothing
129 
130 }
131  //--------------//
132  // Assignment //
133  //--------------//
134 
135 void Eos_Fermi::operator=(const Eos_Fermi& eosi) {
136 
137  set_name(eosi.name) ;
138 
139  m_0 = eosi.m_0 ;
140  g_s = eosi.g_s ;
141 
142  set_auxiliary() ;
143 
144 }
145 
146 
147  //-----------------------//
148  // Miscellaneous //
149  //-----------------------//
150 
152 
153  n_0 = 2.19780778967127e-26 * double(g_s) * m_0 * m_0 * m_0 ;
154 
155  p_0 = 1.34236578162651e-10 * n_0 * m_0 ;
156 
157  ener_0 = double(3) * p_0 ;
158 
159  cout << "n_0 = " << n_0 << endl ;
160  cout << "p_0 = " << p_0 << endl ;
161  cout << "ener_0 = " << ener_0 << endl ;
162 
163 }
164 
165 double Eos_Fermi::get_m() const {
166  return m_0 ;
167 }
168 
170  return g_s ;
171 }
172 
173 
174 
175  //------------------------//
176  // Comparison operators //
177  //------------------------//
178 
179 
180 bool Eos_Fermi::operator==(const Eos& eos_i) const {
181 
182  bool resu = true ;
183 
184  if ( eos_i.identify() != identify() ) {
185  cout << "The second EOS is not of type Eos_Fermi !" << endl ;
186  resu = false ;
187  }
188  else{
189 
190  const Eos_Fermi& eos = dynamic_cast<const Eos_Fermi&>( eos_i ) ;
191 
192  if (eos.m_0 != m_0) {
193  cout
194  << "The two Eos_Fermi have different m_0 : " << m_0 << " <-> "
195  << eos.m_0 << endl ;
196  resu = false ;
197  }
198 
199  if (eos.g_s != g_s) {
200  cout
201  << "The two Eos_Fermi have different g_s : " << g_s << " <-> "
202  << eos.g_s << endl ;
203  resu = false ;
204  }
205 
206 
207  }
208 
209  return resu ;
210 
211 }
212 
213 bool Eos_Fermi::operator!=(const Eos& eos_i) const {
214 
215  return !(operator==(eos_i)) ;
216 
217 }
218 
219 
220  //------------//
221  // Outputs //
222  //------------//
223 
224 void Eos_Fermi::sauve(FILE* fich) const {
225 
226  Eos::sauve(fich) ;
227 
228  fwrite_be(&m_0, sizeof(double), 1, fich) ;
229  fwrite_be(&g_s, sizeof(int), 1, fich) ;
230 
231 }
232 
233 ostream& Eos_Fermi::operator>>(ostream & ost) const {
234 
235  ost << "EOS of class Eos_Fermi (degenerate ideal Fermi gas) : " << endl ;
236  ost << " Fermion mass : " << m_0 << " eV/c2" << endl ;
237  ost << " Degeneracy factor : " << g_s << endl ;
238 
239  return ost ;
240 
241 }
242 
243 
244  //------------------------------//
245  // Computational routines //
246  //------------------------------//
247 
248 // Baryon density from enthalpy
249 //------------------------------
250 
251 double Eos_Fermi::nbar_ent_p(double ent, const Param* ) const {
252 
253  if ( ent > 0 ) {
254  double x2 = exp(double(2)*ent) - double(1) ;
255  double x = sqrt( x2 ) ;
256  // cout << "nbar: ent, x = " << ent << " " << x << endl ;
257  return n_0 * x2 * x ;
258  }
259  else{
260  return 0 ;
261  }
262 }
263 
264 // Energy density from enthalpy
265 //------------------------------
266 
267 double Eos_Fermi::ener_ent_p(double ent, const Param* ) const {
268 
269  if ( ent > 0 ) {
270 
271  double hh = exp(ent) ;
272  double x2 = hh*hh - double(1) ;
273  double x = sqrt(x2) ;
274  // cout << "ener: ent, x = " << ent << " " << x << endl ;
275  return ener_0 * (x*(double(2)*x2 + double(1))*hh - log(x+hh)) ;
276  }
277  else{
278  return 0 ;
279  }
280 }
281 
282 // Pressure from enthalpy
283 //------------------------
284 
285 double Eos_Fermi::press_ent_p(double ent, const Param* ) const {
286 
287  if ( ent > 0 ) {
288 
289  double hh = exp(ent) ;
290  double x2 = hh*hh - double(1) ;
291  double x = sqrt(x2) ;
292  // cout << "press: ent, x = " << ent << " " << x << endl ;
293  return p_0 * (x*(double(2)*x2 - double(3))*hh + double(3)*log(x+hh)) ;
294 
295  }
296  else{
297  return 0 ;
298  }
299 }
300 
301 // dln(n)/ln(H) from enthalpy
302 //---------------------------
303 
304 double Eos_Fermi::der_nbar_ent_p(double , const Param* ) const {
305 
306  cerr << "Eos_Fermi::der_nbar_ent_p : not implemented yet ! " << endl ;
307  abort() ;
308 
309 }
310 
311 // dln(e)/ln(H) from enthalpy
312 //---------------------------
313 
314 double Eos_Fermi::der_ener_ent_p(double , const Param* ) const {
315 
316  cerr << "Eos_Fermi::der_ener_ent_p : not implemented yet ! " << endl ;
317  abort() ;
318 
319  }
320 
321 // dln(p)/ln(H) from enthalpy
322 //---------------------------
323 
324 double Eos_Fermi::der_press_ent_p(double , const Param* ) const {
325 
326  cerr << "Eos_Fermi::der_press_ent_p : not implemented yet ! " << endl ;
327  abort() ;
328 
329 }
330 
331 }
Cmp log(const Cmp &)
Neperian logarithm.
Definition: cmp_math.C:299
int get_g_degen() const
Returns the degeneracy factor.
Definition: eos_fermi.C:169
virtual int identify() const
Returns a number to identify the sub-classe of Eos the object belongs to.
Cmp exp(const Cmp &)
Exponential.
Definition: cmp_math.C:273
Cmp sqrt(const Cmp &)
Square root.
Definition: cmp_math.C:223
virtual double der_ener_ent_p(double ent, const Param *par=0x0) const
Computes the logarithmic derivative from the log-enthalpy.
Definition: eos_fermi.C:314
Lorene prototypes.
Definition: app_hor.h:67
virtual ~Eos_Fermi()
Destructor.
Definition: eos_fermi.C:126
Equation of state base class.
Definition: eos.h:209
virtual int identify() const =0
Returns a number to identify the sub-classe of Eos the object belongs to.
virtual double der_nbar_ent_p(double ent, const Param *par=0x0) const
Computes the logarithmic derivative from the log-enthalpy.
Definition: eos_fermi.C:304
void operator=(const Eos_Fermi &)
Assignment to another Eos_Fermi.
Definition: eos_fermi.C:135
virtual double nbar_ent_p(double ent, const Param *par=0x0) const
Computes the baryon density from the log-enthalpy.
Definition: eos_fermi.C:251
double ener_0
Energy density scale [unit: ], where ].
Definition: eos.h:2599
virtual void sauve(FILE *) const
Save in a file.
Definition: eos_fermi.C:224
void set_auxiliary()
Computes the auxiliary quantities n_0 , ener_0.
Definition: eos_fermi.C:151
virtual void sauve(FILE *) const
Save in a file.
Definition: eos.C:189
virtual double der_press_ent_p(double ent, const Param *par=0x0) const
Computes the logarithmic derivative from the log-enthalpy.
Definition: eos_fermi.C:324
virtual ostream & operator>>(ostream &) const
Operator >>
Definition: eos_fermi.C:233
Degenerate ideal Fermi gas.
Definition: eos.h:2577
double p_0
Pressure scale [unit: ], where ].
Definition: eos.h:2605
Parameter storage.
Definition: param.h:125
double m_0
Individual particule mass [unit: eV/c2].
Definition: eos.h:2586
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.
Definition: fwrite_be.C:73
virtual bool operator!=(const Eos &) const
Comparison operator (difference)
Definition: eos_fermi.C:213
int fread_be(int *aa, int size, int nb, FILE *fich)
Reads integer(s) from a binary file according to the big endian convention.
Definition: fread_be.C:72
void set_name(const char *name_i)
Sets the EOS name.
Definition: eos.C:173
double n_0
Number density scale [unit: ].
Definition: eos.h:2594
double get_m() const
Returns the fermion mass in eV/c2.
Definition: eos_fermi.C:165
char name[100]
EOS name.
Definition: eos.h:215
virtual bool operator==(const Eos &) const
Comparison operator (egality)
Definition: eos_fermi.C:180
int g_s
Degeneracy parameter.
Definition: eos.h:2590
virtual double press_ent_p(double ent, const Param *par=0x0) const
Computes the pressure from the log-enthalpy.
Definition: eos_fermi.C:285
virtual double ener_ent_p(double ent, const Param *par=0x0) const
Computes the total energy density from the log-enthalpy.
Definition: eos_fermi.C:267
Eos_Fermi(double mass)
Standard constructor (sets g_s to 2).
Definition: eos_fermi.C:65