File: eos_consistent.C

package info (click to toggle)
lorene 0.0.0~cvs20161116%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 26,472 kB
  • sloc: cpp: 212,946; fortran: 21,645; makefile: 1,750; sh: 4
file content (323 lines) | stat: -rw-r--r-- 8,368 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
/*
 *  Methods of class Eos_consistent
 *
 *  (see file eos_compose.h for documentation).
 *
 */

/*
 *   Copyright (c) 2015 Jerome Novak
 *
 *   This file is part of LORENE.
 *
 *   LORENE is free software; you can redistribute it and/or modify
 *   it under the terms of the GNU General Public License as published by
 *   the Free Software Foundation; either version 2 of the License, or
 *   (at your option) any later version.
 *
 *   LORENE is distributed in the hope that it will be useful,
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *   GNU General Public License for more details.
 *
 *   You should have received a copy of the GNU General Public License
 *   along with LORENE; if not, write to the Free Software
 *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 *
 */


char eos_consistent_C[] = "$Header: /cvsroot/Lorene/C++/Source/Eos/eos_consistent.C,v 1.1 2015/08/04 14:41:29 j_novak Exp $ " ;

/*
 * $Id: eos_consistent.C,v 1.1 2015/08/04 14:41:29 j_novak Exp $
 * $Log: eos_consistent.C,v $
 * Revision 1.1  2015/08/04 14:41:29  j_novak
 * Back to previous version for Eos_CompOSE. Enthalpy-consistent EoS can be accessed using Eos_consistent class (derived from Eos_CompOSE).
 *
 *
 * $Header: /cvsroot/Lorene/C++/Source/Eos/eos_consistent.C,v 1.1 2015/08/04 14:41:29 j_novak Exp $
 *
 */

#include <string>

// Headers Lorene
#include "headcpp.h"
#include "eos.h"
#include "tbl.h"
#include "utilitaires.h"
#include "unites.h"

namespace Lorene {
  void interpol_herm(const Tbl& , const Tbl&, const Tbl&, double, int&,
		   double&, double& ) ;


			//----------------------------//
			//   	Constructors	      //
			//----------------------------//

// Standard constructor
// --------------------			
  Eos_consistent::Eos_consistent(const char* file_name)
    : Eos_CompOSE(file_name)
{}


// Constructor from binary file
// ----------------------------
Eos_consistent::Eos_consistent(FILE* fich) : Eos_CompOSE(fich) 
{}


// Constructor from a formatted file
// ---------------------------------
  Eos_consistent::Eos_consistent(ifstream& fich) : Eos_CompOSE(fich) 
{}


// Constructor from CompOSE data files
// ------------------------------------
  Eos_consistent::Eos_consistent(const string& files) : Eos_CompOSE(files) 
{
  using namespace Unites ;

  // Files containing data and a test
  //---------------------------------
  string file_nb = files + ".nb" ;
  string file_thermo = files + ".thermo" ;

  ifstream in_nb(file_nb.data()) ;

  // obtaining the size of the tables for memory allocation
  //-------------------------------------------------------
  int index1, index2 ;
  in_nb >> index1 >> index2 ;
  int nbp = index2 - index1 + 1 ;
  assert( nbp == logh->get_taille() ) ;

  press = new double[nbp] ;
  nb    = new double[nbp] ;
  ro    = new double[nbp] ; 
 
  // Variables and conversion
  //-------------------------
  double nb_fm3, rho_cgs, p_cgs, p_over_nb_comp, eps_comp ;
  double dummy_x ;
  int dummy_n ;

  double rhonuc_cgs = rhonuc_si * 1e-3 ;
  double c2_cgs = c_si * c_si * 1e4 ;    
  double m_neutron_MeV, m_proton_MeV ;
  
  ifstream in_p_rho (file_thermo.data()) ;
  in_p_rho >> m_neutron_MeV >> m_proton_MeV ; //Neutron and proton masses
  in_p_rho.ignore(1000, '\n') ;

  double p_convert = mev_si * 1.e45 * 10. ; // Conversion from MeV/fm^3 to cgs
  double eps_convert = mev_si * 1.e42 / (c_si*c_si) ; //From meV/fm^3 to g/cm^3

  // Main loop reading the table
  //----------------------------
  for (int i=0; i<nbp; i++) {
    in_nb >> nb_fm3 ;
    in_p_rho >> dummy_n >> dummy_n >> dummy_n >> p_over_nb_comp ;
    in_p_rho >> dummy_x >> dummy_x >> dummy_x >> dummy_x >> dummy_x >> eps_comp ;
    in_p_rho.ignore(1000, '\n') ;
    p_cgs = p_over_nb_comp * nb_fm3 * p_convert ;
    rho_cgs = ( eps_comp + 1. ) * m_neutron_MeV * nb_fm3 * eps_convert ;
    
    press[i] = p_cgs / c2_cgs ; 
    nb[i]    = nb_fm3 ;
    ro[i]    = rho_cgs ; 
  }

  Tbl pp(nbp) ; pp.set_etat_qcq() ;
  Tbl dh(nbp) ; dh.set_etat_qcq() ;
  for (int i=0; i<nbp; i++) {
    pp.set(i) = log(press[i] / rhonuc_cgs) ;
    dh.set(i) = press[i] / (ro[i] + press[i]) ;
  }
    
  Tbl hh  = integ1D(pp, dh) + 1.e-14 ;
    
  for (int i=0; i<nbp; i++) {
    logh->set(i) = log10( hh(i) ) ;
    logp->set(i) = log10( press[i] / rhonuc_cgs ) ;
    dlpsdlh->set(i) = hh(i) / dh(i) ;
    lognb->set(i) = log10(nb[i]) ;
  }
  
  hmin = pow( double(10), (*logh)(0) ) ;
  hmax = pow( double(10), (*logh)(nbp-1) ) ;
 
  // Cleaning
  //---------
  delete [] press ; 
  delete [] nb ; 
  delete [] ro ; 


}



			//--------------//
			//  Destructor  //
			//--------------//

Eos_consistent::~Eos_consistent(){

    // does nothing

}


			//------------------------//
			//  Comparison operators  //
			//------------------------//


bool Eos_consistent::operator==(const Eos& eos_i) const {

    bool resu = true ;

    if ( eos_i.identify() != identify() ) {
	cout << "The second EOS is not of type Eos_consistent !" << endl ;
	resu = false ;
    }

    return resu ;

}

bool Eos_consistent::operator!=(const Eos& eos_i) const {

    return !(operator==(eos_i)) ;

}

			//------------------------------//
			//    Computational routines    //
			//------------------------------//

// Baryon density from enthalpy
//------------------------------

double Eos_consistent::nbar_ent_p(double ent, const Param* ) const {

  static int i_near = logh->get_taille() / 2 ;
  
  if ( ent > hmin ) {
    if (ent > hmax) {
      cout << "Eos_consistent::nbar_ent_p : ent > hmax !" << endl ;
      abort() ;
    }
    double logh0 = log10( ent ) ;
    double logp0 ;
    double dlpsdlh0 ;
    interpol_herm(*logh, *logp, *dlpsdlh, logh0, i_near, logp0,
		  dlpsdlh0) ;
    
    double pp = pow(double(10), logp0) ;
    
    double resu = pp / ent * dlpsdlh0 * exp(-ent) ;
    if (i_near == 0) 
      { // Use of linear interpolation for the first interval
	double pp_near = pow(double(10), (*logp)(i_near)) ;
	double ent_near = pow(double(10), (*logh)(i_near)) ;
	resu = pp_near / ent_near * (*dlpsdlh)(i_near) * exp(-ent_near) ;
      }
    return resu ;
  }
  else{
    return 0 ;
  }
}

// Energy density from enthalpy
//------------------------------

double Eos_consistent::ener_ent_p(double ent, const Param* ) const {

  static int i_near = logh->get_taille() / 2 ;
  
  if ( ent > hmin ) {
    if (ent > hmax) {
      cout << "Eos_consistent::ener_ent_p : ent > hmax !" << endl ;
      abort() ;
    }
    double logh0 = log10( ent ) ;
    double logp0 ;
    double dlpsdlh0 ;
    interpol_herm(*logh, *logp, *dlpsdlh, logh0, i_near, logp0,
		  dlpsdlh0) ;
    
    double pp = pow(double(10), logp0) ;
    
    double resu = pp / ent * dlpsdlh0 - pp ;
    if (i_near == 0)
      {
	double pp_near = pow(double(10), (*logp)(i_near)) ;
	double ent_near = pow(double(10), (*logh)(i_near)) ;
	resu = pp_near / ent_near * (*dlpsdlh)(i_near) - pp_near ;
      }
    return resu ;
  }
  else{
    return 0 ;
  }
}

// Pressure from enthalpy
//------------------------

double Eos_consistent::press_ent_p(double ent, const Param* ) const {

  static int i_near = logh->get_taille() / 2 ;
  
  if ( ent > hmin ) {
    if (ent > hmax) {
      cout << "Eos_consistent::press_ent_p : ent > hmax !" << endl ;
      abort() ;
    }
    
    double logh0 = log10( ent ) ;
    double logp0 ;
    double dlpsdlh0 ;
    interpol_herm(*logh, *logp, *dlpsdlh, logh0, i_near, logp0,
		  dlpsdlh0) ;
    if (i_near == 0)
      {
	double logp_near = (*logp)(i_near) ;
	double logp_nearp1 = (*logp)(i_near+1) ;
	double delta = (*logh)(i_near+1) - (*logh)(i_near) ;
	logp0 = (logp_nearp1*(logh0 - (*logh)(i_near)) 
		 - logp_near*(logh0 - (*logh)(i_near+1))) / delta  ;
      }	   
    return pow(double(10), logp0) ;
  }
  else{
    return 0 ;
  }
}

			//------------//
			//  Outputs   //
			//------------//


ostream& Eos_consistent::operator>>(ostream & ost) const {

    ost << "EOS of class Eos_consistent." << endl ;
    ost << "Built from file " << tablename << endl ;
    ost << "Authors : " << authors << endl ;
    ost << "Number of points in file : " << logh->get_taille() << endl ;
    ost << "Table eventually slightly modified to ensure the relation" << endl ;
    ost << "dp = (e+p) dh" << endl ;
    return ost ;
}

			
}