LORENE
hoteos_from_file.C
1 /*
2  * Methods for Hot_eos and file manipulation
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: hoteos_from_file.C,v 1.5 2022/04/06 12:38:26 g_servignat Exp $
33  * $Log: hoteos_from_file.C,v $
34  * Revision 1.5 2022/04/06 12:38:26 g_servignat
35  * Added Ye_eos_tabul identificator
36  *
37  * Revision 1.4 2022/03/01 10:03:06 g_servignat
38  * Corrected all pure virtual interference between Hot_eos derived classes ; amended use of interpol_linear_2D
39  *
40  * Revision 1.3 2016/12/05 16:17:52 j_novak
41  * Suppression of some global variables (file names, loch, ...) to prevent redefinitions
42  *
43  * Revision 1.2 2015/12/08 10:52:18 j_novak
44  * New class Hoteos_tabul for tabulated temperature-dependent EoSs.
45  *
46  * Revision 1.1 2015/03/17 14:20:00 j_novak
47  * New class Hot_eos to deal with temperature-dependent EOSs.
48  *
49  * $Header: /cvsroot/Lorene/C++/Source/Eos/hoteos_from_file.C,v 1.5 2022/04/06 12:38:26 g_servignat Exp $
50  *
51  */
52 
53 // Headers C
54 #include <cstdlib>
55 
56 // Header Lorene
57 #include "headcpp.h"
58 #include "hoteos.h"
59 #include "utilitaires.h"
60 
61 namespace Lorene {
62 
63  //--------------------------------------//
64  // Identification virtual functions //
65  //--------------------------------------//
66 
67  int Ideal_gas::identify() const { return 1; }
68 
69  int Hoteos_tabul::identify() const { return 2; }
70 
71  int Ye_eos_tabul::identify() const {return 3;}
72 
73 
74  //-------------------------------------------------//
75  // Hot EOS construction from a binary file //
76  //-------------------------------------------------//
77 
79 
80  Hot_eos* p_eos ;
81 
82  // Type (class) of EOS :
83  int identificator ;
84  fread_be(&identificator, sizeof(int), 1, fich) ;
85 
86  switch(identificator) {
87 
88  case 1 : {
89  p_eos = new Ideal_gas(fich) ;
90  break ;
91  }
92 
93  case 2 : {
94  p_eos = new Hoteos_tabul(fich) ;
95  break ;
96  }
97 
98  case 3 : {
99  p_eos = new Ye_eos_tabul(fich) ;
100  break ;
101  }
102 
103  default : {
104  cout << "Hot_eos::hoteos_from_file : unknown type of EOS !" << endl ;
105  cout << " identificator = " << identificator << endl ;
106  abort() ;
107  break ;
108  }
109 
110  }
111 
112  return p_eos ;
113 
114  }
115 
116  //--------------------------------------------------//
117  // Hot EOS construction from a formatted file //
118  //--------------------------------------------------//
119 
121 
122  int identificator ;
123  if (!fich) {
124  cerr << "Hot_eos::hoteos_from_file: file cannot be opened!" << endl ;
125  abort() ;
126  }
127 
128  // EOS identificator :
129  fich >> identificator ; fich.ignore(1000, '\n') ;
130 
131  Hot_eos* p_eos ;
132 
133  switch(identificator) {
134 
135  case 1 : {
136  p_eos = new Ideal_gas(fich) ;
137  break ;
138  }
139 
140  case 2 : {
141  p_eos = new Hoteos_tabul(fich) ;
142  break ;
143  }
144 
145  default : {
146  cout << "Hot_eos::hoteos_from_file : unknown type of EOS !" << endl ;
147  cout << " identificator = " << identificator << endl ;
148  abort() ;
149  break ;
150  }
151 
152  }
153 
154  return p_eos ;
155 
156  }
157 
158 
159 }
virtual int identify() const
Returns a number to identify the sub-classe of Hot_eos the object belongs to.
Lorene prototypes.
Definition: app_hor.h:67
Ideal-gas (temperature-dependent) equation of state, with mass-term in the energy density...
Definition: hoteos.h:513
virtual int identify() const
Returns a number to identify the sub-classe of Hot_eos the object belongs to.
Hot (temperature-dependent) tabulated equation of state, read from a file.
Definition: hoteos.h:748
Out of beta-equilibrium tabulated equation of state, read from a file.
Definition: hoteos.h:983
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
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.
static Hot_eos * hoteos_from_file(FILE *)
Construction of an EOS from a binary file.