File: eos_fermi.C

package info (click to toggle)
lorene 0.0.0~cvs20161116%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 26,472 kB
  • sloc: cpp: 212,946; fortran: 21,645; makefile: 1,750; sh: 4
file content (328 lines) | stat: -rw-r--r-- 6,982 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
/*
 * Methods of the class Eos_Fermi.
 *
 * (see file eos.h for documentation).
 */

/*
 *   Copyright (c) 2012 Eric Gourgoulhon
 *
 *   This file is part of LORENE.
 *
 *   LORENE is free software; you can redistribute it and/or modify
 *   it under the terms of the GNU General Public License as published by
 *   the Free Software Foundation; either version 2 of the License, or
 *   (at your option) any later version.
 *
 *   LORENE is distributed in the hope that it will be useful,
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *   GNU General Public License for more details.
 *
 *   You should have received a copy of the GNU General Public License
 *   along with LORENE; if not, write to the Free Software
 *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 *
 */


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 $" ;

/*
 * $Id: eos_fermi.C,v 1.2 2014/10/13 08:52:52 j_novak Exp $
 * $Log: eos_fermi.C,v $
 * Revision 1.2  2014/10/13 08:52:52  j_novak
 * Lorene classes and functions now belong to the namespace Lorene.
 *
 * Revision 1.1  2012/10/26 14:09:33  e_gourgoulhon
 * Added new class Eos_Fermi
 *
 *
 * $Header: /cvsroot/Lorene/C++/Source/Eos/eos_fermi.C,v 1.2 2014/10/13 08:52:52 j_novak Exp $
 *
 */

// Headers C
#include <cstdlib>
#include <cstring>
#include <cmath>

// Headers Lorene
#include "eos.h"
#include "utilitaires.h"

			//--------------//
			// Constructors //
			//--------------//

// Standard constructor with g_s = 2
// ----------------------------------

namespace Lorene {
Eos_Fermi::Eos_Fermi(double mass) : 
	Eos("Degenerate ideal Fermi gas"), 
	m_0(mass), g_s(2) {

    set_auxiliary() ; 

}  

// Standard constructor
// --------------------

Eos_Fermi::Eos_Fermi(double mass, int g_degen) : 
	Eos("Degenerate ideal Fermi gas"), 
	m_0(mass), g_s(g_degen) {

    set_auxiliary() ; 

}  


// Copy constructor
// ----------------
Eos_Fermi::Eos_Fermi(const Eos_Fermi& eosi) : 
	Eos(eosi), 
	m_0(eosi.m_0), g_s(eosi.g_s) {

    set_auxiliary() ; 

}  
  

// Constructor from binary file
// ----------------------------
Eos_Fermi::Eos_Fermi(FILE* fich) : 
	Eos(fich) {
        
    fread_be(&m_0, sizeof(double), 1, fich) ;		
    fread_be(&g_s, sizeof(int), 1, fich) ;		

    set_auxiliary() ; 

}


// Constructor from a formatted file
// ---------------------------------
Eos_Fermi::Eos_Fermi(ifstream& fich) : 
	Eos(fich) {

    char blabla[80] ;
        
    fich >> m_0 ; fich.getline(blabla, 80) ;
    fich >> g_s ; fich.getline(blabla, 80) ;
 
    set_auxiliary() ; 

}
			//--------------//
			//  Destructor  //
			//--------------//

Eos_Fermi::~Eos_Fermi(){
    
    // does nothing
        
}
			//--------------//
			//  Assignment  //
			//--------------//

void Eos_Fermi::operator=(const Eos_Fermi& eosi) {
    
    set_name(eosi.name) ; 
    
    m_0 = eosi.m_0 ;
    g_s = eosi.g_s ;

    set_auxiliary() ;

}


		  //-----------------------//
		  //	Miscellaneous	   //
		  //-----------------------//

void Eos_Fermi::set_auxiliary() {

    n_0 =  2.19780778967127e-26 * double(g_s) * m_0 * m_0 * m_0 ;

    p_0 = 1.34236578162651e-10 * n_0 * m_0 ;
    
    ener_0 = double(3) * p_0 ; 
    
    cout << "n_0 = " << n_0 << endl ; 
    cout << "p_0 = " << p_0 << endl ; 
    cout << "ener_0 = " << ener_0 << endl ; 

}

double Eos_Fermi::get_m() const {
    return m_0 ;
}

int Eos_Fermi::get_g_degen() const {
    return g_s ; 
}



			//------------------------//
			//  Comparison operators  //
			//------------------------//


bool Eos_Fermi::operator==(const Eos& eos_i) const {
    
    bool resu = true ; 
    
    if ( eos_i.identify() != identify() ) {
	cout << "The second EOS is not of type Eos_Fermi !" << endl ; 
	resu = false ; 
    }
    else{
	
	const Eos_Fermi& eos = dynamic_cast<const Eos_Fermi&>( eos_i ) ; 

	if (eos.m_0 != m_0) {
	    cout 
	    << "The two Eos_Fermi have different m_0 : " << m_0 << " <-> " 
		<< eos.m_0 << endl ; 
	    resu = false ; 
	}

	if (eos.g_s != g_s) {
	    cout 
	    << "The two Eos_Fermi have different g_s : " << g_s << " <-> " 
		<< eos.g_s << endl ; 
	    resu = false ; 
	}

	
    }
    
    return resu ; 
    
}

bool Eos_Fermi::operator!=(const Eos& eos_i) const {
 
    return !(operator==(eos_i)) ; 
       
}


			//------------//
			//  Outputs   //
			//------------//

void Eos_Fermi::sauve(FILE* fich) const {

    Eos::sauve(fich) ; 
    
    fwrite_be(&m_0, sizeof(double), 1, fich) ;	
    fwrite_be(&g_s, sizeof(int), 1, fich) ;

}

ostream& Eos_Fermi::operator>>(ostream & ost) const {
    
    ost << "EOS of class Eos_Fermi (degenerate ideal Fermi gas) : " << endl ; 
    ost << "   Fermion mass : " << m_0 << " eV/c2" << endl ;
    ost << "   Degeneracy factor : " << g_s << endl ;

    return ost ;

}


			//------------------------------//
			//    Computational routines    //
			//------------------------------//

// Baryon density from enthalpy
//------------------------------

double Eos_Fermi::nbar_ent_p(double ent, const Param* ) const {

    if ( ent > 0 ) {
        double x2 =  exp(double(2)*ent) - double(1) ; 
        double x = sqrt( x2 ) ; 
        // cout << "nbar: ent,  x = " << ent << " " << x << endl ; 
        return n_0 * x2 * x ;
    }
    else{
        return 0 ;
    }
}

// Energy density from enthalpy
//------------------------------

double Eos_Fermi::ener_ent_p(double ent, const Param* ) const {

    if ( ent > 0 ) {

        double hh = exp(ent) ; 
        double x2 = hh*hh - double(1)  ; 
        double x = sqrt(x2) ; 
        // cout << "ener: ent,  x = " << ent << " " << x << endl ; 
        return ener_0 * (x*(double(2)*x2 + double(1))*hh - log(x+hh)) ;
    }
    else{
        return 0 ;
    }
}

// Pressure from enthalpy
//------------------------

double Eos_Fermi::press_ent_p(double ent, const Param* ) const {

    if ( ent > 0 ) {

        double hh = exp(ent) ; 
        double x2 = hh*hh - double(1)  ; 
        double x = sqrt(x2) ; 
        // cout << "press: ent,  x = " << ent << " " << x << endl ; 
        return p_0 * (x*(double(2)*x2 - double(3))*hh + double(3)*log(x+hh)) ;

    }
    else{
        return 0 ;
    }
}

// dln(n)/ln(H) from enthalpy
//---------------------------

double Eos_Fermi::der_nbar_ent_p(double , const Param* ) const {

    cerr << "Eos_Fermi::der_nbar_ent_p : not implemented yet ! " << endl ; 
    abort() ; 
 
}

// dln(e)/ln(H) from enthalpy
//---------------------------

double Eos_Fermi::der_ener_ent_p(double , const Param* ) const {

    cerr << "Eos_Fermi::der_ener_ent_p : not implemented yet ! " << endl ; 
    abort() ; 

 }

// dln(p)/ln(H) from enthalpy
//---------------------------

double Eos_Fermi::der_press_ent_p(double , const Param* ) const {

    cerr << "Eos_Fermi::der_press_ent_p : not implemented yet ! " << endl ; 
    abort() ; 
    
}

}