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