LORENE
eos_bf_file.C
1 /*
2  * Methods for Eos_bifluid and file manipulation
3  *
4  * (see file eos_bifluid.h for documentation)
5  */
6 
7 /*
8  * Copyright (c) 2001 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 char eos_bf_file_C[] = "$Header: /cvsroot/Lorene/C++/Source/Eos/eos_bf_file.C,v 1.11 2015/06/11 14:41:59 a_sourie Exp $" ;
30 
31 /*
32  * $Id: eos_bf_file.C,v 1.11 2015/06/11 14:41:59 a_sourie Exp $
33  * $Log: eos_bf_file.C,v $
34  * Revision 1.11 2015/06/11 14:41:59 a_sourie
35  * Corrected minor bug
36  *
37  * Revision 1.10 2015/06/10 14:39:17 a_sourie
38  * New class Eos_bf_tabul for tabulated 2-fluid EoSs and associated functions for the computation of rotating stars with such EoSs.
39  *
40  * Revision 1.9 2014/10/13 08:52:52 j_novak
41  * Lorene classes and functions now belong to the namespace Lorene.
42  *
43  * Revision 1.8 2014/10/06 15:13:06 j_novak
44  * Modified #include directives to use c++ syntax.
45  *
46  * Revision 1.7 2014/04/25 10:43:51 j_novak
47  * The member 'name' is of type string now. Correction of a few const-related issues.
48  *
49  * Revision 1.6 2008/08/19 06:42:00 j_novak
50  * Minor modifications to avoid warnings with gcc 4.3. Most of them concern
51  * cast-type operations, and constant strings that must be defined as const char*
52  *
53  * Revision 1.5 2003/12/05 15:09:47 r_prix
54  * adapted Eos_bifluid class and subclasses to use read_variable() for
55  * (formatted) file-reading.
56  *
57  * Revision 1.4 2002/10/16 14:36:34 j_novak
58  * Reorganization of #include instructions of standard C++, in order to
59  * use experimental version 3 of gcc.
60  *
61  * Revision 1.3 2002/01/11 14:09:34 j_novak
62  * Added newtonian version for 2-fluid stars
63  *
64  * Revision 1.2 2001/12/04 21:27:53 e_gourgoulhon
65  *
66  * All writing/reading to a binary file are now performed according to
67  * the big endian convention, whatever the system is big endian or
68  * small endian, thanks to the functions fwrite_be and fread_be
69  *
70  * Revision 1.1.1.1 2001/11/20 15:19:27 e_gourgoulhon
71  * LORENE
72  *
73  * Revision 1.1 2001/06/21 15:22:15 novak
74  * Initial revision
75  *
76  *
77  * $Header: /cvsroot/Lorene/C++/Source/Eos/eos_bf_file.C,v 1.11 2015/06/11 14:41:59 a_sourie Exp $
78  *
79  */
80 
81 // Headers C
82 #include <cstdlib>
83 
84 // Header Lorene
85 #include "headcpp.h"
86 #include "eos_bifluid.h"
87 #include "utilitaires.h"
88 
89  //--------------------------------------//
90  // Identification virtual functions //
91  //--------------------------------------//
92 
93 
94 namespace Lorene {
95 int Eos_bf_poly::identify() const { return 1; }
96 
97 int Eos_bf_poly_newt::identify() const { return 2; }
98 
99 int Eos_bf_tabul::identify() const { return 3; }
100 
101  //---------------------------------------------//
102  // EOS construction from a binary file //
103  //---------------------------------------------//
104 
106 
107  Eos_bifluid* p_eos ;
108 
109  // Type (class) of EOS :
110  int identificator ;
111  fread_be(&identificator, sizeof(int), 1, fich) ;
112 
113  switch(identificator) {
114 
115  case 1 : {
116  p_eos = new Eos_bf_poly(fich) ;
117  break ;
118  }
119 
120  case 3 : {
121  p_eos = new Eos_bf_tabul(fich) ;
122  break ;
123  }
124 
125  default : {
126  cout << "Eos_bifluid::eos_from_file : unknown type of EOS !" << endl ;
127  cout << " identificator = " << identificator << endl ;
128  abort() ;
129  break ;
130  }
131 
132  }
133 
134  return p_eos ;
135 
136 }
137 
138  //----------------------------------------------//
139  // EOS construction from a formatted file //
140  //----------------------------------------------//
141 
143 
144  int identificator ;
145 
146  // EOS identificator :
147  if (read_variable (fname, const_cast<char*>("ident"), identificator) != 0)
148  {
149  cerr << "ERROR: Could not read the required variable 'ident' in " << fname << endl;
150  exit (-1);
151  }
152 
153  Eos_bifluid* p_eos ;
154 
155  switch(identificator) {
156 
157  case 1 : {
158  p_eos = new Eos_bf_poly(fname) ;
159  break ;
160  }
161 
162  case 2 : {
163  p_eos = new Eos_bf_poly_newt(fname) ;
164  break ;
165  }
166 
167  default : {
168  cout << "Eos_bifluid::eos_from_file : unknown type of EOS !" << endl ;
169  cout << " identificator = " << identificator << endl ;
170  abort() ;
171  break ;
172  }
173 
174  }
175 
176  return p_eos ;
177 
178 }
179 
180  //----------------------------------------------//
181  // EOS construction from a formatted file //
182  //----------------------------------------------//
183 
185 
186  int identificator ;
187  char blabla[80] ;
188 
189  // EOS identificator :
190  fich >> identificator ; fich.getline(blabla, 80) ;
191 
192  Eos_bifluid* p_eos ;
193 
194  switch(identificator) {
195 
196  case 3 : {
197  p_eos = new Eos_bf_tabul(fich) ;
198  break ;
199  }
200 
201  default : {
202  cout << "Eos_bifluid::eos_from_file : unknown type of EOS !" << endl ;
203  cout << " identificator = " << identificator << endl ;
204  abort() ;
205  break ;
206  }
207 
208  }
209 
210  return p_eos ;
211 
212 }
213 
214 
215 
216 
217 
218 
219 }
Analytic equation of state for two fluids (Newtonian case).
Definition: eos_bifluid.h:1258
virtual int identify() const
Returns a number to identify the sub-classe of Eos_bifluid the object belongs to.
Definition: eos_bf_file.C:97
Analytic equation of state for two fluids (relativistic case).
Definition: eos_bifluid.h:814
virtual int identify() const
Returns a number to identify the sub-classe of Eos_bifluid the object belongs to.
Definition: eos_bf_file.C:95
Class for a two-fluid (tabulated) equation of state.
Definition: eos_bifluid.h:1534
virtual int identify() const
Returns a number to identify the sub-classe of Eos the object belongs to.
Definition: eos_bf_file.C:99
2-fluids equation of state base class.
Definition: eos_bifluid.h:173
static Eos_bifluid * eos_from_file(FILE *)
Construction of an EOS from a binary file.
Definition: eos_bf_file.C:105
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 read_variable(const char *fname, const char *var_name, char *fmt, void *varp)
Reads a variable from file.
Lorene prototypes.
Definition: app_hor.h:64