LORENE
ideal_gas.C
1 /*
2  * Methods of the class Ideal_gas.
3  *
4  * (see file hoteos.h for documentation).
5  */
6 
7 /*
8  * Copyright (c) 2015 Jerome Novak
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: ideal_gas.C,v 1.7 2022/12/15 14:38:27 j_novak Exp $
33  * $Log: ideal_gas.C,v $
34  * Revision 1.7 2022/12/15 14:38:27 j_novak
35  * Change in the call to fread, to avoid compilation warnings
36  *
37  * Revision 1.6 2022/04/06 12:38:05 g_servignat
38  * Added source computation routine and source reading in table for electronic fraction advection equation
39  *
40  * Revision 1.5 2022/03/01 10:03:07 g_servignat
41  * Corrected all pure virtual interference between Hot_eos derived classes ; amended use of interpol_linear_2D
42  *
43  * Revision 1.4 2016/12/05 16:17:52 j_novak
44  * Suppression of some global variables (file names, loch, ...) to prevent redefinitions
45  *
46  * Revision 1.3 2015/09/10 13:54:04 j_novak
47  * Allows for negative entropy in the temperature function.
48  *
49  * Revision 1.1 2015/03/17 14:20:00 j_novak
50  * New class Hot_eos to deal with temperature-dependent EOSs.
51  *
52  *
53  *
54  * $Header: /cvsroot/Lorene/C++/Source/Eos/ideal_gas.C,v 1.7 2022/12/15 14:38:27 j_novak Exp $
55  *
56  */
57 
58 // Headers C
59 #include <cstdlib>
60 #include <cmath>
61 
62 // Headers Lorene
63 #include "hoteos.h"
64 #include "eos.h"
65 #include "utilitaires.h"
66 #include "unites.h"
67 
68 namespace Lorene {
69 
70  //--------------//
71  // Constructors //
72  //--------------//
73 
74  // Standard constructor
75  // --------------------
76  Ideal_gas::Ideal_gas(double gam0, double kappa, double mass) :
77  Hot_eos("Ideal gas EOS"), gam(gam0), kap(kappa), m_0(mass) {
78 
79  set_auxiliary() ;
80 
81  }
82 
83  // Copy constructor
84  // ----------------
86  Hot_eos(eosi), gam(eosi.gam), kap(eosi.kap), m_0(eosi.m_0)
87  {
88  set_auxiliary() ;
89  }
90 
91 
92  // Constructor from binary file
93  // ----------------------------
94  Ideal_gas::Ideal_gas(FILE* fich) :
95  Hot_eos(fich) {
96 
97  fread_be(&gam, sizeof(double), 1, fich) ;
98  fread_be(&kap, sizeof(double), 1, fich) ;
99  fread_be(&m_0, sizeof(double), 1, fich) ;
100 
101  set_auxiliary() ;
102 
103  }
104 
105 
106  // Constructor from a formatted file
107  // ---------------------------------
108  Ideal_gas::Ideal_gas(ifstream& fich) :
109  Hot_eos(fich) {
110 
111  fich >> gam ; fich.ignore(80, '\n') ;
112  fich >> kap ; fich.ignore(80, '\n') ;
113  fich >> m_0 ; fich.ignore(80, '\n') ;
114 
115  set_auxiliary() ;
116 
117  }
118  //--------------//
119  // Destructor //
120  //--------------//
121 
123 
124  //--------------//
125  // Assignment //
126  //--------------//
127 
128  void Ideal_gas::operator=(const Ideal_gas& eosi) {
129 
130  name = eosi.name ;
131 
132  gam = eosi.gam ;
133  kap = eosi.kap ;
134  m_0 = eosi.m_0 ;
135 
136  set_auxiliary() ;
137 
138  }
139 
140 
141  //-----------------------//
142  // Miscellaneous //
143  //-----------------------//
144 
146 
147  gam1 = gam - double(1) ;
148 
149  unsgam1 = double(1) / gam1 ;
150 
151  gam1sgamkap = m_0 * gam1 / (gam * kap) ;
152 
153  }
154 
155  double Ideal_gas::get_gam() const {
156  return gam ;
157  }
158 
159  double Ideal_gas::get_kap() const {
160  return kap ;
161  }
162 
163  double Ideal_gas::get_m_0() const {
164  return m_0 ;
165  }
166 
167 
168  //-------------------------------//
169  // The corresponding cold Eos //
170  //-------------------------------//
171 
172  const Eos& Ideal_gas::new_cold_Eos() const {
173 
174  if (p_cold_eos == 0x0) {
175  p_cold_eos = new Eos_poly(gam, kap, m_0) ;
176  }
177 
178  return *p_cold_eos ;
179  }
180 
181 
182  //------------------------//
183  // Comparison operators //
184  //------------------------//
185 
186 
187  bool Ideal_gas::operator==(const Hot_eos& eos_i) const {
188 
189  bool resu = true ;
190 
191  if ( eos_i.identify() != identify() ) {
192  cout << "The second EOS is not of type Ideal_gas !" << endl ;
193  resu = false ;
194  }
195  else {
196 
197  const Ideal_gas& eos = dynamic_cast<const Ideal_gas&>( eos_i ) ;
198 
199  if (eos.gam != gam) {
200  cout
201  << "The two Ideal_gas have different gamma : " << gam << " <-> "
202  << eos.gam << endl ;
203  resu = false ;
204  }
205 
206  if (eos.kap != kap) {
207  cout
208  << "The two Ideal_gas have different kappa : " << kap << " <-> "
209  << eos.kap << endl ;
210  resu = false ;
211  }
212 
213  if (eos.m_0 != m_0) {
214  cout
215  << "The two Ideal_gas have different m_0 : " << m_0 << " <-> "
216  << eos.m_0 << endl ;
217  resu = false ;
218  }
219  }
220  return resu ;
221  }
222 
223 
224  bool Ideal_gas::operator!=(const Hot_eos& eos_i) const {
225  return !(operator==(eos_i)) ;
226  }
227 
228 
229  //------------//
230  // Outputs //
231  //------------//
232 
233  void Ideal_gas::sauve(FILE* fich) const {
234 
235  Hot_eos::sauve(fich) ;
236 
237  fwrite_be(&gam, sizeof(double), 1, fich) ;
238  fwrite_be(&kap, sizeof(double), 1, fich) ;
239  fwrite_be(&m_0, sizeof(double), 1, fich) ;
240 
241  }
242 
243  ostream& Ideal_gas::operator>>(ostream & ost) const {
244 
245  ost << "Hot EOS of class Ideal_gas (relativistic ideal gas) : " << endl ;
246  ost << " Adiabatic index gamma : " << gam << endl ;
247  ost << " Pressure coefficient kappa : " << kap <<
248  " rho_nuc c^2 / n_nuc^gamma" << endl ;
249  ost << " Mean particle mass : " << m_0 << " m_B" << endl ;
250 
251  return ost ;
252 }
253 
254 
255  //------------------------------//
256  // Computational routines //
257  //------------------------------//
258 
259 // Baryon density from enthalpy
260 //------------------------------
261 
262  double Ideal_gas::nbar_Hs_p(double ent, double sb) const {
263 
264  if ( ent > 0. ) {
265  return pow( gam1sgamkap * ( exp(ent) - 1. ), unsgam1 ) * exp(-sb) ;
266  }
267  else {
268  return 0 ;
269  }
270  }
271 
272 // Energy density from enthalpy
273 //------------------------------
274 
275  double Ideal_gas::ener_Hs_p(double ent, double sb) const {
276 
277  if ( ent > 0. ) {
278  double nn = pow( gam1sgamkap * ( exp(ent) - 1. ), unsgam1 ) * exp(-sb) ;
279  double pp = kap * pow( nn, gam ) * exp(gam1*sb) ;
280 
281  return unsgam1 * pp + m_0 * nn ;
282  }
283  else {
284  return 0. ;
285  }
286  }
287 
288 // Pressure from enthalpy
289 //------------------------
290 
291  double Ideal_gas::press_Hs_p(double ent, double sb) const {
292 
293  if ( ent > 0. ) {
294  double nn = pow( gam1sgamkap * ( exp(ent) - 1. ), unsgam1 ) * exp(-sb) ;
295 
296  return kap * pow( nn, gam ) * exp(gam1*sb) ;
297  }
298  else {
299  return 0. ;
300  }
301  }
302 
303 // Temperature from enthalpy
304 //---------------------------
305 
306  double Ideal_gas::temp_Hs_p(double ent, double) const {
307 
308  using namespace Unites ;
309 
310  // if ( ent > 0. ) {
311  return kap * gam1sgamkap * ( exp(ent) - 1. ) ;
312  // return m_u_mev * kap * gam1sgamkap * ( exp(ent) - 1. ) ;
313  //}
314  //else {
315  //return 0 ;
316  //}
317  }
318 
319  double Ideal_gas::csound_square_Hs_p(double, double) const {
320  cerr << "Ideal_gas::csound_square_Hs_p : function not implemented (yet !) ..." << endl;
321  cerr << "Aborting ..." << endl;
322  abort() ;
323 
324  return 0. ;
325  }
326 
327  double Ideal_gas::chi2_Hs_p(double, double) const {
328  cerr << "Ideal_gas::chi2_Hs_p : function not implemented (yet !) ..." << endl;
329  cerr << "Aborting ..." << endl;
330  abort() ;
331 
332  return 0. ;
333  }
334 
335  double Ideal_gas::mul_Hs_p(double, double) const {
336  cerr << "Ideal_gas::mul_Hs_p : function not implemented (yet !) ..." << endl;
337  cerr << "Aborting ..." << endl;
338  abort() ;
339 
340  return 0. ;
341  }
342 
343  double Ideal_gas::sigma_Hs_p(double, double) const {
344  cerr << "Ideal_gas::sigma_Hs_p : function not implemented (yet !) ..." << endl;
345  cerr << "Aborting ..." << endl;
346  abort() ;
347 
348  return 0. ;
349  }
350 
351 }
virtual double sigma_Hs_p(double ent, const double ye) const
Computes the source terms for electronic fraction advection equation from the enthapy with electronic...
Definition: ideal_gas.C:343
virtual void sauve(FILE *) const
Save in a file.
Definition: ideal_gas.C:233
void set_auxiliary()
Computes the auxiliary quantities gam1 , unsgam1 , gam1sgamkap from the values of gam and kap...
Definition: ideal_gas.C:145
virtual ~Ideal_gas()
Destructor.
Definition: ideal_gas.C:122
Cmp exp(const Cmp &)
Exponential.
Definition: cmp_math.C:273
double unsgam1
Definition: hoteos.h:535
string name
EOS name.
Definition: hoteos.h:90
Eos * p_cold_eos
Corresponding cold Eos.
Definition: hoteos.h:126
double kap
Pressure coefficient (cf.
Definition: hoteos.h:527
virtual double nbar_Hs_p(double ent, double sb) const
Computes the baryon density from the log-enthalpy and entropy per baryon (virtual function implemente...
Definition: ideal_gas.C:262
virtual double temp_Hs_p(double ent, double sb) const
Computes the temperature from the log-enthalpy and entropy per baryon (virtual function implemented i...
Definition: ideal_gas.C:306
Lorene prototypes.
Definition: app_hor.h:67
Standard units of space, time and mass.
Equation of state base class.
Definition: eos.h:209
double m_0
Individual particule mass (cf.
Definition: hoteos.h:532
virtual double csound_square_Hs_p(double ent, const double ye) const
Computes the sound speed squared from the enthapy with electronic fraction (virtual function impleme...
Definition: ideal_gas.C:319
double get_gam() const
Returns the adiabatic index (cf. Eq. (1)).
Definition: ideal_gas.C:155
Ideal-gas (temperature-dependent) equation of state, with mass-term in the energy density...
Definition: hoteos.h:513
virtual ostream & operator>>(ostream &) const
Operator >>
Definition: ideal_gas.C:243
virtual double chi2_Hs_p(double ent, const double ye) const
Computes the chi^2 coefficient from the enthapy with electronic fraction (virtual function implemente...
Definition: ideal_gas.C:327
virtual bool operator!=(const Hot_eos &) const
Comparison operator (difference)
Definition: ideal_gas.C:224
double gam
Adiabatic index .
Definition: hoteos.h:520
virtual double ener_Hs_p(double ent, double sb) const
Computes the total energy density from the log-enthalpy and entropy per baryon (virtual function impl...
Definition: ideal_gas.C:275
virtual const Eos & new_cold_Eos() const
Returns the corresponding cold Eos.
Definition: ideal_gas.C:172
Polytropic equation of state (relativistic case).
Definition: eos.h:812
virtual int identify() const =0
Returns a number to identify the sub-classe of Hot_eos the object belongs to.
virtual double mul_Hs_p(double ent, const double ye) const
Computes the electronic chemical potential from the enthapy with electronic fraction (virtual functio...
Definition: ideal_gas.C:335
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
Cmp pow(const Cmp &, int)
Power .
Definition: cmp_math.C:351
virtual double press_Hs_p(double ent, double sb) const
Computes the pressure from the log-enthalpy and entropy per baryon (virtual function implemented in t...
Definition: ideal_gas.C:291
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
double gam1
Definition: hoteos.h:534
Base class for 2-parameters equations of state (abstract class).
Definition: hoteos.h:85
virtual int identify() const
Returns a number to identify the sub-classe of Hot_eos the object belongs to.
virtual void sauve(FILE *) const
Save in a file.
Definition: hoteos.C:129
void operator=(const Ideal_gas &)
Assignment to another Ideal_gas.
Definition: ideal_gas.C:128
virtual bool operator==(const Hot_eos &) const
Comparison operator (egality)
Definition: ideal_gas.C:187
double gam1sgamkap
Definition: hoteos.h:536
double get_kap() const
Returns the pressure coefficient (cf. Eq. (1)).
Definition: ideal_gas.C:159
Ideal_gas(double gamma, double kappa, double mass=1.)
Standard constructor.
Definition: ideal_gas.C:76
double get_m_0() const
Return the individual particule mass (cf.
Definition: ideal_gas.C:163