LORENE
eos_incomp.C
1/*
2 * Methods of the class Eos_incomp.
3 *
4 * (see file eos.h for documentation).
5 */
6
7/*
8 * Copyright (c) 2000-2001 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_incomp.C,v 1.7 2016/12/05 16:17:51 j_novak Exp $
33 * $Log: eos_incomp.C,v $
34 * Revision 1.7 2016/12/05 16:17:51 j_novak
35 * Suppression of some global variables (file names, loch, ...) to prevent redefinitions
36 *
37 * Revision 1.6 2014/10/13 08:52:53 j_novak
38 * Lorene classes and functions now belong to the namespace Lorene.
39 *
40 * Revision 1.5 2014/10/06 15:13:06 j_novak
41 * Modified #include directives to use c++ syntax.
42 *
43 * Revision 1.4 2002/10/16 14:36:35 j_novak
44 * Reorganization of #include instructions of standard C++, in order to
45 * use experimental version 3 of gcc.
46 *
47 * Revision 1.3 2002/04/09 14:32:15 e_gourgoulhon
48 * 1/ Added extra parameters in EOS computational functions (argument par)
49 * 2/ New class MEos for multi-domain EOS
50 *
51 * Revision 1.2 2001/12/04 21:27:53 e_gourgoulhon
52 *
53 * All writing/reading to a binary file are now performed according to
54 * the big endian convention, whatever the system is big endian or
55 * small endian, thanks to the functions fwrite_be and fread_be
56 *
57 * Revision 1.1.1.1 2001/11/20 15:19:27 e_gourgoulhon
58 * LORENE
59 *
60 * Revision 2.4 2001/02/07 09:49:08 eric
61 * Suppression de la fonction derent_ent_p.
62 * Ajout des fonctions donnant les derivees de l'EOS:
63 * der_nbar_ent_p
64 * der_ener_ent_p
65 * der_press_ent_p
66 *
67 * Revision 2.3 2000/02/14 14:49:48 eric
68 * Modif affichage.
69 *
70 * Revision 2.2 2000/02/14 14:33:51 eric
71 * Ajout du constructeur par lecture de fichier formate.
72 *
73 * Revision 2.1 2000/01/21 15:18:15 eric
74 * Ajout des operateurs de comparaison == et !=
75 *
76 * Revision 2.0 2000/01/18 16:11:25 eric
77 * *** empty log message ***
78 *
79 *
80 * $Header: /cvsroot/Lorene/C++/Source/Eos/eos_incomp.C,v 1.7 2016/12/05 16:17:51 j_novak Exp $
81 *
82 */
83
84
85// Headers C
86#include <cstdlib>
87#include <cstring>
88#include <cmath>
89
90// Headers Lorene
91#include "eos.h"
92#include "cmp.h"
93#include "utilitaires.h"
94
95 //--------------//
96 // Constructors //
97 //--------------//
98
99// Standard constructor with ent0 = 1
100// ---------------------------------
101namespace Lorene {
103 Eos("EOS for relativistic incompressible matter"),
104 rho0(rho_c), ent0( double(-1.e-6) ) {}
105
106// Standard constructor with ent0 specified
107// ---------------------------------------
108Eos_incomp::Eos_incomp(double rho_c, double ent_c) :
109 Eos("EOS for relativistic incompressible matter"),
110 rho0(rho_c), ent0( ent_c ) {
111
112 assert( ent_c <= double(0) ) ;
113
114}
115
116// Copy constructor
117// ----------------
119 Eos(eosi),
120 rho0(eosi.rho0), ent0(eosi.ent0) {}
121
122
123// Constructor from a binary file
124// ------------------------------
126 Eos(fich) {
127
128 fread_be(&rho0, sizeof(double), 1, fich) ;
129 fread_be(&ent0, sizeof(double), 1, fich) ;
130
131}
132
133// Constructor from a formatted file
134// ---------------------------------
135Eos_incomp::Eos_incomp(ifstream& fich) :
136 Eos(fich) {
137
138 char blabla[80] ;
139
140 fich >> rho0 ; fich.getline(blabla, 80) ;
141 fich >> ent0 ; fich.getline(blabla, 80) ;
142
143}
144 //--------------//
145 // Destructor //
146 //--------------//
147
149
150 // does nothing
151
152}
153 //--------------//
154 // Assignment //
155 //--------------//
156
158
159 set_name(eosi.name) ;
160
161 rho0 = eosi.rho0 ;
162 ent0 = eosi.ent0 ;
163
164}
165
166 //------------------------//
167 // Comparison operators //
168 //------------------------//
169
170bool Eos_incomp::operator==(const Eos& eos_i) const {
171
172 bool resu = true ;
173
174 if ( eos_i.identify() != identify() ) {
175 cout << "The second EOS is not of type Eos_incomp !" << endl ;
176 resu = false ;
177 }
178 else{
179
180 const Eos_incomp& eos = dynamic_cast<const Eos_incomp&>( eos_i ) ;
181
182 if (eos.rho0 != rho0) {
183 cout
184 << "The two Eos_incomp have different rho0 : " << rho0 << " <-> "
185 << eos.rho0 << endl ;
186 resu = false ;
187 }
188
189 if (eos.ent0 != ent0) {
190 cout
191 << "The two Eos_incomp have different ent0 : " << ent0 << " <-> "
192 << eos.ent0 << endl ;
193 resu = false ;
194 }
195
196 }
197
198 return resu ;
199
200}
201
202bool Eos_incomp::operator!=(const Eos& eos_i) const {
203
204 return !(operator==(eos_i)) ;
205
206}
207
208
209
210 //------------//
211 // Outputs //
212 //------------//
213
214void Eos_incomp::sauve(FILE* fich) const {
215
216 Eos::sauve(fich) ;
217
218 fwrite_be(&rho0, sizeof(double), 1, fich) ;
219 fwrite_be(&ent0, sizeof(double), 1, fich) ;
220
221}
222
223ostream& Eos_incomp::operator>>(ostream & ost) const {
224
225 ost << "EOS of class Eos_incomp (relativistic incompressible matter) : "
226 << endl ;
227 ost << " Constant density : " << rho0 << " rho_nuc" << endl ;
228 ost << " Log-enthalpy threshold for non-zero density : " << ent0
229 << " c^2" << endl ;
230
231 return ost ;
232
233}
234
235
236 //------------------------------//
237 // Computational routines //
238 //------------------------------//
239
240// Baryon density from enthalpy
241//------------------------------
242
243double Eos_incomp::nbar_ent_p(double ent, const Param* ) const {
244
245 if ( ent >= ent0 ) {
246
247 return rho0 ;
248 }
249 else{
250 return 0 ;
251 }
252}
253
254// Energy density from enthalpy
255//------------------------------
256
257double Eos_incomp::ener_ent_p(double ent, const Param* ) const {
258
259 if ( ent >= ent0 ) {
260
261 return rho0 ;
262 }
263 else{
264 return 0 ;
265 }
266}
267
268// Pressure from enthalpy
269//------------------------
270
271double Eos_incomp::press_ent_p(double ent, const Param* ) const {
272
273 if ( ent >= ent0 ) {
274
275 return rho0 * (exp(ent) - double(1)) ;
276 }
277 else{
278 return 0 ;
279 }
280}
281
282
283// dln(n)/ln(H) from enthalpy
284//---------------------------
285
286double Eos_incomp::der_nbar_ent_p(double ent, const Param* ) const {
287
288 if ( ent >= ent0 ) {
289
290 return 0 ;
291 }
292 else{
293 return 0 ;
294 }
295}
296
297// dln(e)/ln(H) from enthalpy
298//---------------------------
299
300double Eos_incomp::der_ener_ent_p(double ent, const Param* ) const {
301
302 if ( ent >= ent0 ) {
303
304 return 0 ;
305 }
306 else{
307 return 0 ;
308 }
309}
310
311// dln(p)/ln(H) from enthalpy
312//---------------------------
313
314double Eos_incomp::der_press_ent_p(double ent, const Param* ) const {
315
316 if ( ent >= ent0 ) {
317
318 return ent / (double(1) - exp(-ent)) ;
319
320 }
321 else{
322 return 0 ;
323 }
324}
325
326
327
328}
virtual ~Eos_incomp()
Destructor.
Definition eos_incomp.C:148
Eos_incomp(double rho_c)
Standard constructor.
Definition eos_incomp.C:102
virtual double ener_ent_p(double ent, const Param *par=0x0) const
Computes the total energy density from the log-enthalpy.
Definition eos_incomp.C:257
virtual double der_nbar_ent_p(double ent, const Param *par=0x0) const
Computes the logarithmic derivative from the log-enthalpy.
Definition eos_incomp.C:286
void operator=(const Eos_incomp &)
Assignment to another Eos_incomp.
Definition eos_incomp.C:157
virtual ostream & operator>>(ostream &) const
Operator >>.
Definition eos_incomp.C:223
virtual void sauve(FILE *) const
Save in a file.
Definition eos_incomp.C:214
virtual bool operator!=(const Eos &) const
Comparison operator (difference).
Definition eos_incomp.C:202
virtual double der_ener_ent_p(double ent, const Param *par=0x0) const
Computes the logarithmic derivative from the log-enthalpy.
Definition eos_incomp.C:300
virtual double nbar_ent_p(double ent, const Param *par=0x0) const
Computes the baryon density from the log-enthalpy.
Definition eos_incomp.C:243
virtual bool operator==(const Eos &) const
Comparison operator (egality).
Definition eos_incomp.C:170
virtual int identify() const
Returns a number to identify the sub-classe of Eos the object belongs to.
virtual double der_press_ent_p(double ent, const Param *par=0x0) const
Computes the logarithmic derivative from the log-enthalpy.
Definition eos_incomp.C:314
virtual double press_ent_p(double ent, const Param *par=0x0) const
Computes the pressure from the log-enthalpy.
Definition eos_incomp.C:271
double ent0
Log-enthalpy threshold for setting the energy density to a non zero value (should be negative).
Definition eos.h:1644
double rho0
Constant density .
Definition eos.h:1639
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 exp(const Cmp &)
Exponential.
Definition cmp_math.C:273
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