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
64namespace Lorene {
65Eos_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
76Eos_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// ----------------------------
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// ---------------------------------
111Eos_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
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
165double 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
180bool 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
213bool Eos_Fermi::operator!=(const Eos& eos_i) const {
214
215 return !(operator==(eos_i)) ;
216
217}
218
219
220 //------------//
221 // Outputs //
222 //------------//
223
224void 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
233ostream& 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
251double 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
267double 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
285double 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
304double 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
314double 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
324double 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}
double get_m() const
Returns the fermion mass in eV/c2.
Definition eos_fermi.C:165
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:233
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
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
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
int get_g_degen() const
Returns the degeneracy factor.
Definition eos_fermi.C:169
virtual void sauve(FILE *) const
Save in a file.
Definition eos_fermi.C:224
double ener_0
Energy density scale [unit: ], where ].
Definition eos.h:2594
virtual ~Eos_Fermi()
Destructor.
Definition eos_fermi.C:126
void operator=(const Eos_Fermi &)
Assignment to another Eos_Fermi.
Definition eos_fermi.C:135
int g_s
Degeneracy parameter.
Definition eos.h:2585
virtual bool operator!=(const Eos &) const
Comparison operator (difference).
Definition eos_fermi.C:213
double m_0
Individual particule mass [unit: eV/c2].
Definition eos.h:2581
virtual bool operator==(const Eos &) const
Comparison operator (egality).
Definition eos_fermi.C:180
double p_0
Pressure scale [unit: ], where ].
Definition eos.h:2600
double n_0
Number density scale [unit: ].
Definition eos.h:2589
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 double press_ent_p(double ent, const Param *par=0x0) const
Computes the pressure from the log-enthalpy.
Definition eos_fermi.C:285
Eos_Fermi(double mass)
Standard constructor (sets g_s to 2).
Definition eos_fermi.C:65
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 set_auxiliary()
Computes the auxiliary quantities n_0 , ener_0.
Definition eos_fermi.C:151
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:189
Eos()
Standard constructor.
Definition eos.C:118
char name[100]
EOS name.
Definition eos.h:212
void set_name(const char *name_i)
Sets the EOS name.
Definition eos.C:173
Parameter storage.
Definition param.h:125
Cmp sqrt(const Cmp &)
Square root.
Definition cmp_math.C:223
Cmp exp(const Cmp &)
Exponential.
Definition cmp_math.C:273
Cmp log(const Cmp &)
Neperian logarithm.
Definition cmp_math.C:299
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
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
Lorene prototypes.
Definition app_hor.h:67
Coord x
x coordinate centered on the grid
Definition map.h:738