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