LORENE
eos_from_file.C
1 /*
2  * Methods for Eos and file manipulation
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_from_file.C,v 1.19 2023/06/15 08:04:05 g_servignat Exp $
33  * $Log: eos_from_file.C,v $
34  * Revision 1.19 2023/06/15 08:04:05 g_servignat
35  * Added identifier for Pseudo_polytrope_1D and Piecewise_polytrope_1D
36  *
37  * Revision 1.18 2022/04/15 13:39:24 j_novak
38  * New class Eos_compose_fit to generate fitted EoSs from CompOSE tables.
39  *
40  * Revision 1.17 2016/12/05 16:17:51 j_novak
41  * Suppression of some global variables (file names, loch, ...) to prevent redefinitions
42  *
43  * Revision 1.16 2015/08/04 14:41:29 j_novak
44  * Back to previous version for Eos_CompOSE. Enthalpy-consistent EoS can be accessed using Eos_consistent class (derived from Eos_CompOSE).
45  *
46  * Revision 1.15 2015/01/27 14:22:38 j_novak
47  * New methods in Eos_tabul to correct for EoS themro consistency (optional).
48  *
49  * Revision 1.14 2014/10/13 08:52:53 j_novak
50  * Lorene classes and functions now belong to the namespace Lorene.
51  *
52  * Revision 1.13 2014/06/30 16:13:18 j_novak
53  * New methods for reading directly from CompOSE files.
54  *
55  * Revision 1.12 2014/03/06 15:53:35 j_novak
56  * Eos_compstar is now Eos_compOSE. Eos_tabul uses strings and contains informations about authors.
57  *
58  * Revision 1.11 2012/10/26 14:09:33 e_gourgoulhon
59  * Added new class Eos_Fermi
60  *
61  * Revision 1.10 2011/06/16 10:49:18 j_novak
62  * New class Eos_mag for EOSs depending on density and magnetic field.
63  *
64  * Revision 1.9 2010/02/02 13:22:16 j_novak
65  * New class Eos_Compstar.
66  *
67  * Revision 1.8 2005/05/22 20:51:41 k_taniguchi
68  * Add a new Eos Eos_fit_AkmalPR.
69  *
70  * Revision 1.7 2004/09/26 18:53:08 k_taniguchi
71  * Introduction of new EOSs: Eos_fit_SLy4 and Eos_fit_FPS
72  *
73  * Revision 1.6 2004/05/07 08:06:45 k_taniguchi
74  * Add the case of Eos_multi_poly.C
75  *
76  * Revision 1.5 2003/12/08 15:47:03 m_bejger
77  * GlendNH3 EOS (Glendenning 1985, case 3) added
78  *
79  * Revision 1.4 2002/10/16 14:36:35 j_novak
80  * Reorganization of #include instructions of standard C++, in order to
81  * use experimental version 3 of gcc.
82  *
83  * Revision 1.3 2002/04/09 14:32:15 e_gourgoulhon
84  * 1/ Added extra parameters in EOS computational functions (argument par)
85  * 2/ New class MEos for multi-domain EOS
86  *
87  * Revision 1.2 2001/12/04 21:27:53 e_gourgoulhon
88  *
89  * All writing/reading to a binary file are now performed according to
90  * the big endian convention, whatever the system is big endian or
91  * small endian, thanks to the functions fwrite_be and fread_be
92  *
93  * Revision 1.1.1.1 2001/11/20 15:19:27 e_gourgoulhon
94  * LORENE
95  *
96  * Revision 2.6 2001/09/11 16:23:08 eric
97  * Ajout de Eos_AkmalPR, Eos_BBB2 et Eos_BalbN1H1.
98  *
99  * Revision 2.5 2000/11/23 22:34:10 eric
100  * Ajout de Eos_BPAL12.
101  *
102  * Revision 2.4 2000/11/23 14:46:16 eric
103  * Ajout de Eos_strange_cr.
104  *
105  * Revision 2.3 2000/11/22 19:30:55 eric
106  * Ajout des Eos_SLy4 et Eos_FPS
107  *
108  * Revision 2.2 2000/10/24 15:29:22 eric
109  * Ajout de l'EOS matiere etrange (Eos_strange).
110  *
111  * Revision 2.1 2000/02/14 14:33:41 eric
112  * Ajout du constructeur par lecture de fichier formate.
113  *
114  * Revision 2.0 2000/01/21 15:18:08 eric
115  * *** empty log message ***
116  *
117  *
118  * $Header: /cvsroot/Lorene/C++/Source/Eos/eos_from_file.C,v 1.19 2023/06/15 08:04:05 g_servignat Exp $
119  *
120  */
121 
122 // Headers C
123 #include <cstdlib>
124 
125 // Header Lorene
126 #include "headcpp.h"
127 #include "eos.h"
128 #include "eos_multi_poly.h"
129 #include "eos_compose_fit.h"
130 #include "eos_fitting.h"
131 #include "utilitaires.h"
132 
133  //--------------------------------------//
134  // Identification virtual functions //
135  //--------------------------------------//
136 
137 
138 namespace Lorene {
139 int Eos_poly::identify() const { return 1; }
140 
141 int Eos_poly_newt::identify() const { return 2; }
142 
143 int Eos_incomp::identify() const { return 3; }
144 
145 int Eos_incomp_newt::identify() const { return 4; }
146 
147 int Eos_strange::identify() const { return 5; }
148 
149 int Eos_strange_cr::identify() const { return 6; }
150 
151 int Eos_compose_fit::identify() const { return 7; }
152 
153 int Eos_SLy4::identify() const { return 10; }
154 
155 int Eos_FPS::identify() const { return 11; }
156 
157 int Eos_BPAL12::identify() const { return 12; }
158 
159 int Eos_AkmalPR::identify() const { return 13; }
160 
161 int Eos_BBB2::identify() const { return 14; }
162 
163 int Eos_BalbN1H1::identify() const { return 15; }
164 
165 int Eos_GlendNH3::identify() const { return 16; }
166 
167 int Eos_CompOSE::identify() const { return 17; }
168 
169 int Eos_mag::identify() const { return 18; }
170 
171 int Eos_Fermi::identify() const { return 19; }
172 
173 int Eos_consistent::identify() const { return 20; }
174 
175 int Pseudo_polytrope_1D::identify() const { return 21; }
176 
177 int Piecewise_polytrope_1D::identify() const { return 22; }
178 
179 int MEos::identify() const { return 100; }
180 
181 int Eos_multi_poly::identify() const { return 110; }
182 
183 int Eos_fit_SLy4::identify() const { return 120; }
184 
185 int Eos_fit_FPS::identify() const { return 121; }
186 
187 int Eos_fit_AkmalPR::identify() const { return 122; }
188 
189  //---------------------------------------------//
190  // EOS construction from a binary file //
191  //---------------------------------------------//
192 
193 Eos* Eos::eos_from_file(FILE* fich) {
194 
195  Eos* p_eos ;
196 
197  // Type (class) of EOS :
198  int identificator ;
199  fread_be(&identificator, sizeof(int), 1, fich) ;
200 
201  switch(identificator) {
202 
203  case 1 : {
204  p_eos = new Eos_poly(fich) ;
205  break ;
206  }
207 
208  case 2 : {
209  p_eos = new Eos_poly_newt(fich) ;
210  break ;
211  }
212 
213  case 3 : {
214  p_eos = new Eos_incomp(fich) ;
215  break ;
216  }
217 
218  case 4 : {
219  p_eos = new Eos_incomp_newt(fich) ;
220  break ;
221  }
222 
223  case 5 : {
224  p_eos = new Eos_strange(fich) ;
225  break ;
226  }
227 
228  case 6 : {
229  p_eos = new Eos_strange_cr(fich) ;
230  break ;
231  }
232 
233  case 7 : {
234  p_eos = new Eos_compose_fit(fich) ;
235  break ;
236  }
237 
238  case 10 : {
239  p_eos = new Eos_SLy4(fich) ;
240  break ;
241  }
242 
243  case 11 : {
244  p_eos = new Eos_FPS(fich) ;
245  break ;
246  }
247 
248  case 12 : {
249  p_eos = new Eos_BPAL12(fich) ;
250  break ;
251  }
252 
253  case 13 : {
254  p_eos = new Eos_AkmalPR(fich) ;
255  break ;
256  }
257 
258  case 14 : {
259  p_eos = new Eos_BBB2(fich) ;
260  break ;
261  }
262 
263  case 15 : {
264  p_eos = new Eos_BalbN1H1(fich) ;
265  break ;
266  }
267 
268  case 16 : {
269  p_eos = new Eos_GlendNH3(fich) ;
270  break ;
271  }
272 
273  case 17 : {
274  p_eos = new Eos_CompOSE(fich) ;
275  break ;
276  }
277 
278  case 18 : {
279  p_eos = new Eos_mag(fich) ;
280  break ;
281  }
282 
283  case 19 : {
284  p_eos = new Eos_Fermi(fich) ;
285  break ;
286  }
287 
288  case 20 : {
289  p_eos = new Eos_consistent(fich) ;
290  break ;
291  }
292 
293  case 21 : {
294  p_eos = new Pseudo_polytrope_1D(fich) ;
295  break ;
296  }
297 
298  case 22 : {
299  p_eos = new Piecewise_polytrope_1D(fich) ;
300  break ;
301  }
302 
303  case 100 : {
304  p_eos = new MEos(fich) ;
305  break ;
306  }
307 
308  case 110 : {
309  p_eos = new Eos_multi_poly(fich) ;
310  break ;
311  }
312 
313  case 120 : {
314  p_eos = new Eos_fit_SLy4(fich) ;
315  break ;
316  }
317 
318  case 121 : {
319  p_eos = new Eos_fit_FPS(fich) ;
320  break ;
321  }
322 
323  case 122 : {
324  p_eos = new Eos_fit_AkmalPR(fich) ;
325  break ;
326  }
327 
328  default : {
329  cout << "Eos::eos_from_file : unknown type of EOS !" << endl ;
330  cout << " identificator = " << identificator << endl ;
331  abort() ;
332  break ;
333  }
334 
335  }
336 
337  return p_eos ;
338 
339 }
340 
341  //----------------------------------------------//
342  // EOS construction from a formatted file //
343  //----------------------------------------------//
344 
345 Eos* Eos::eos_from_file(ifstream& fich) {
346 
347  int identificator ;
348 
349  // EOS identificator :
350  fich >> identificator ; fich.ignore(1000, '\n') ;
351 
352  Eos* p_eos ;
353 
354  switch(identificator) {
355 
356  case 1 : {
357  p_eos = new Eos_poly(fich) ;
358  break ;
359  }
360 
361  case 2 : {
362  p_eos = new Eos_poly_newt(fich) ;
363  break ;
364  }
365 
366  case 3 : {
367  p_eos = new Eos_incomp(fich) ;
368  break ;
369  }
370 
371  case 4 : {
372  p_eos = new Eos_incomp_newt(fich) ;
373  break ;
374  }
375 
376  case 5 : {
377  p_eos = new Eos_strange(fich) ;
378  break ;
379  }
380 
381  case 6 : {
382  p_eos = new Eos_strange_cr(fich) ;
383  break ;
384  }
385 
386  case 7 : {
387  p_eos = new Eos_compose_fit(fich) ;
388  break ;
389  }
390 
391  case 10 : {
392  p_eos = new Eos_SLy4(fich) ;
393  break ;
394  }
395 
396  case 11 : {
397  p_eos = new Eos_FPS(fich) ;
398  break ;
399  }
400 
401  case 12 : {
402  p_eos = new Eos_BPAL12(fich) ;
403  break ;
404  }
405 
406  case 13 : {
407  p_eos = new Eos_AkmalPR(fich) ;
408  break ;
409  }
410 
411  case 14 : {
412  p_eos = new Eos_BBB2(fich) ;
413  break ;
414  }
415 
416  case 15 : {
417  p_eos = new Eos_BalbN1H1(fich) ;
418  break ;
419  }
420 
421  case 16 : {
422  p_eos = new Eos_GlendNH3(fich) ;
423  break ;
424  }
425 
426  case 17 : {
427  int format ;
428  fich >> format ;
429  fich.ignore(1000, '\n') ;
430 #ifndef NDEBUG
431  cout << "Reading tabulated EoS, with "
432  << ( (format == 0) ? "standard LORENE " : "original CompOSE ")
433  << "format." << endl ;
434 #endif
435  if (format == 1) {
436  fich.ignore(1000, '\n') ;
437  string files_path ;
438  fich >> files_path ;
439  p_eos = new Eos_CompOSE(files_path ) ;
440  }
441  else
442  p_eos = new Eos_CompOSE(fich ) ;
443  break ;
444  }
445 
446  case 18 : {
447  p_eos = new Eos_mag(fich) ;
448  break ;
449  }
450 
451  case 19 : {
452  p_eos = new Eos_Fermi(fich) ;
453  break ;
454  }
455 
456  case 20 : {
457  int format ;
458  fich >> format ;
459  fich.ignore(1000, '\n') ;
460 #ifndef NDEBUG
461  cout << "Reading tabulated EoS, with "
462  << ( (format == 0) ? "standard LORENE " : "original CompOSE ")
463  << "format." << endl ;
464 #endif
465  if (format == 1) {
466  fich.ignore(1000, '\n') ;
467  string files_path ;
468  fich >> files_path ;
469  p_eos = new Eos_consistent(files_path ) ;
470  }
471  else
472  p_eos = new Eos_consistent(fich ) ;
473  break ;
474  }
475 
476  case 21 : {
477  p_eos = new Pseudo_polytrope_1D(fich) ;
478  break ;
479  }
480 
481  case 22 : {
482  p_eos = new Piecewise_polytrope_1D(fich) ;
483  break ;
484  }
485 
486  case 100 : {
487  p_eos = new MEos(fich) ;
488  break ;
489  }
490 
491  case 110 : {
492  p_eos = new Eos_multi_poly(fich) ;
493  break ;
494  }
495 
496  case 120 : {
497  p_eos = new Eos_fit_SLy4(fich) ;
498  break ;
499  }
500 
501  case 121 : {
502  p_eos = new Eos_fit_FPS(fich) ;
503  break ;
504  }
505 
506  case 122 : {
507  p_eos = new Eos_fit_AkmalPR(fich) ;
508  break ;
509  }
510 
511  default : {
512  cout << "Eos::eos_from_file : unknown type of EOS !" << endl ;
513  cout << " identificator = " << identificator << endl ;
514  abort() ;
515  break ;
516  }
517 
518  }
519 
520  return p_eos ;
521 
522 }
523 
524 
525 
526 
527 
528 
529 }
virtual int identify() const
Returns a number to identify the sub-classe of Eos the object belongs to.
Fitted equation of state of AkmalPR.
Definition: eos_fitting.h:370
virtual int identify() const
Returns a number to identify the sub-classe of Eos the object belongs to.
virtual int identify() const
Returns a number to identify the sub-classe of Eos the object belongs to.
Equation of state AkmalPR (Akmal, Pandharipande & Ravenhall 1998).
Definition: eos_tabul.h:664
virtual int identify() const
Returns a number to identify the sub-classe of Eos the object belongs to.
virtual int identify() const
Returns a number to identify the sub-classe of Eos the object belongs to.
virtual int identify() const
Returns a number to identify the sub-classe of Eos the object belongs to.
Fitted equation of state of SLy4.
Definition: eos_fitting.h:226
virtual int identify() const
Returns a number to identify the sub-classe of Eos the object belongs to.
virtual int identify() const
Returns a number to identify the sub-classe of Eos the object belongs to.
Lorene prototypes.
Definition: app_hor.h:67
Equation of state base class.
Definition: eos.h:209
virtual int identify() const
Returns a number to identify the sub-classe of Eos the object belongs to.
Fitted equation of state of FPS.
Definition: eos_fitting.h:298
virtual int identify() const
Returns a number to identify the sub-classe of Eos the object belongs to.
EOS with domain dependency.
Definition: eos.h:2780
Strange matter EOS (MIT Bag model).
Definition: eos.h:1999
Degenerate ideal Fermi gas.
Definition: eos.h:2577
virtual int identify() const
Returns a number to identify the sub-classe of Eos the object belongs to.
virtual int identify() const
Returns a number to identify the sub-classe of Eos the object belongs to.
static Eos * eos_from_file(FILE *)
Construction of an EOS from a binary file.
virtual int identify() const
Returns a number to identify the sub-classe of Eos the object belongs to.
virtual int identify() const
Returns a number to identify the sub-classe of Eos the object belongs to.
Equation of state for the CompOSE database with a consistent computation of the log-enthalpy (deriv...
Definition: eos_compose.h:227
virtual int identify() const
Returns a number to identify the sub-classe of Eos the object belongs to.
Polytropic equation of state (relativistic case).
Definition: eos.h:812
virtual int identify() const
Returns a number to identify the sub-classe of Eos the object belongs to.
Equation of state BPAL12 (Bombaci et al 1995).
Definition: eos_tabul.h:578
Class for a magnetized (tabulated) equation of state.
Definition: eos_mag.h:81
virtual int identify() const
Returns a number to identify the sub-classe of Eos the object belongs to.
Polytropic equation of state (Newtonian case).
Definition: eos.h:1110
Base class for a multiple polytropic equation of state.
virtual int identify() const
Returns a number to identify the sub-classe of Eos the object belongs to.
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
virtual int identify() const
Returns a number to identify the sub-classe of Eos the object belongs to.
virtual int identify() const
Returns a number to identify the sub-classe of Eos the object belongs to.
Equation of state GlendNH3 (Glendenning 1985, case 3 ).
Definition: eos_tabul.h:904
Equation of state BalbN1H1 (Balberg 2000).
Definition: eos_tabul.h:824
virtual int identify() const
Returns a number to identify the sub-classe of Eos the object belongs to.
Equation of state FPS (Friedman-Pandharipande + Skyrme).
Definition: eos_tabul.h:501
Equation of state BBB2 (Baldo, Bombaci & Burgio 1997).
Definition: eos_tabul.h:746
Equation of state SLy4 (Douchin & Haensel 2001).
Definition: eos_tabul.h:423
Equation of state of incompressible matter (Newtonian case).
Definition: eos.h:1821
Equation of state for fitting the 1-parameter EoSs from the CompOSE database.
Strange matter EOS (MIT Bag model) with crust.
Definition: eos.h:2252
virtual int identify() const
Returns a number to identify the sub-classe of Eos the object belongs to.
Equation of state for the CompOSE database.
Definition: eos_compose.h:93
Equation of state of incompressible matter (relativistic case).
Definition: eos.h:1637
virtual int identify() const
Returns a number to identify the sub-classe of Eos the object belongs to.
virtual int identify() const
Returns a number to identify the sub-classe of Eos the object belongs to.
virtual int identify() const
Returns a number to identify the sub-classe of Eos the object belongs to.