Debian Codegraph @

C++/Source/Eos/eos_fermi.C

raw
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 char 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
61 namespace Lorene {
62 Eos_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
73 Eos_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 // ----------------
84 Eos_Fermi::Eos_Fermi(const Eos_Fermi& eosi) :
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 // ----------------------------
95 Eos_Fermi::Eos_Fermi(FILE* fich) :
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 // ---------------------------------
108 Eos_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
123 Eos_Fermi::~Eos_Fermi(){
124
125 // does nothing
126
127 }
128 //--------------//
129 // Assignment //
130 //--------------//
131
132 void Eos_Fermi::operator=(const Eos_Fermi& eosi) {
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
148 void Eos_Fermi::set_auxiliary() {
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
162 double Eos_Fermi::get_m() const {
163 return m_0 ;
164 }
165
166 int Eos_Fermi::get_g_degen() const {
167 return g_s ;
168 }
169
170
171
172 //------------------------//
173 // Comparison operators //
174 //------------------------//
175
176
177 bool 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
210 bool Eos_Fermi::operator!=(const Eos& eos_i) const {
211
212 return !(operator==(eos_i)) ;
213
214 }
215
216
217 //------------//
218 // Outputs //
219 //------------//
220
221 void 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
230 ostream& 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
248 double 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
264 double 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
282 double 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
301 double 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
311 double 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
321 double 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 }