| 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 |
char ideal_gas_C[] = "$Header: /cvsroot/Lorene/C++/Source/Eos/ideal_gas.C,v 1.3 2015/09/10 13:54:04 j_novak Exp $" ; |
| 30 |
|
| 31 |
/* |
| 32 |
* $Id: ideal_gas.C,v 1.3 2015/09/10 13:54:04 j_novak Exp $ |
| 33 |
* $Log: ideal_gas.C,v $ |
| 34 |
* Revision 1.3 2015/09/10 13:54:04 j_novak |
| 35 |
* Allows for negative entropy in the temperature function. |
| 36 |
* |
| 37 |
* Revision 1.1 2015/03/17 14:20:00 j_novak |
| 38 |
* New class Hot_eos to deal with temperature-dependent EOSs. |
| 39 |
* |
| 40 |
* |
| 41 |
* |
| 42 |
* $Header: /cvsroot/Lorene/C++/Source/Eos/ideal_gas.C,v 1.3 2015/09/10 13:54:04 j_novak Exp $ |
| 43 |
* |
| 44 |
*/ |
| 45 |
|
| 46 |
// Headers C |
| 47 |
#include <cstdlib> |
| 48 |
#include <cmath> |
| 49 |
|
| 50 |
// Headers Lorene |
| 51 |
#include "hoteos.h" |
| 52 |
#include "eos.h" |
| 53 |
#include "utilitaires.h" |
| 54 |
#include "unites.h" |
| 55 |
|
| 56 |
namespace Lorene { |
| 57 |
|
| 58 |
//--------------// |
| 59 |
// Constructors // |
| 60 |
//--------------// |
| 61 |
|
| 62 |
// Standard constructor |
| 63 |
// -------------------- |
| 64 |
Ideal_gas::Ideal_gas(double gam0, double kappa, double mass) : |
| 65 |
Hot_eos("Ideal gas EOS"), gam(gam0), kap(kappa), m_0(mass) { |
| 66 |
|
| 67 |
set_auxiliary() ; |
| 68 |
|
| 69 |
} |
| 70 |
|
| 71 |
// Copy constructor |
| 72 |
// ---------------- |
| 73 |
Ideal_gas::Ideal_gas(const Ideal_gas& eosi) : |
| 74 |
Hot_eos(eosi), gam(eosi.gam), kap(eosi.kap), m_0(eosi.m_0) |
| 75 |
{ |
| 76 |
set_auxiliary() ; |
| 77 |
} |
| 78 |
|
| 79 |
|
| 80 |
// Constructor from binary file |
| 81 |
// ---------------------------- |
| 82 |
Ideal_gas::Ideal_gas(FILE* fich) : |
| 83 |
Hot_eos(fich) { |
| 84 |
|
| 85 |
fread_be(&gam, sizeof(double), 1, fich) ; |
| 86 |
fread_be(&kap, sizeof(double), 1, fich) ; |
| 87 |
fread_be(&m_0, sizeof(double), 1, fich) ; |
| 88 |
|
| 89 |
set_auxiliary() ; |
| 90 |
|
| 91 |
} |
| 92 |
|
| 93 |
|
| 94 |
// Constructor from a formatted file |
| 95 |
// --------------------------------- |
| 96 |
Ideal_gas::Ideal_gas(ifstream& fich) : |
| 97 |
Hot_eos(fich) { |
| 98 |
|
| 99 |
fich >> gam ; fich.ignore(80, '\n') ; |
| 100 |
fich >> kap ; fich.ignore(80, '\n') ; |
| 101 |
fich >> m_0 ; fich.ignore(80, '\n') ; |
| 102 |
|
| 103 |
set_auxiliary() ; |
| 104 |
|
| 105 |
} |
| 106 |
//--------------// |
| 107 |
// Destructor // |
| 108 |
//--------------// |
| 109 |
|
| 110 |
Ideal_gas::~Ideal_gas(){} |
| 111 |
|
| 112 |
//--------------// |
| 113 |
// Assignment // |
| 114 |
//--------------// |
| 115 |
|
| 116 |
void Ideal_gas::operator=(const Ideal_gas& eosi) { |
| 117 |
|
| 118 |
name = eosi.name ; |
| 119 |
|
| 120 |
gam = eosi.gam ; |
| 121 |
kap = eosi.kap ; |
| 122 |
m_0 = eosi.m_0 ; |
| 123 |
|
| 124 |
set_auxiliary() ; |
| 125 |
|
| 126 |
} |
| 127 |
|
| 128 |
|
| 129 |
//-----------------------// |
| 130 |
// Miscellaneous // |
| 131 |
//-----------------------// |
| 132 |
|
| 133 |
void Ideal_gas::set_auxiliary() { |
| 134 |
|
| 135 |
gam1 = gam - double(1) ; |
| 136 |
|
| 137 |
unsgam1 = double(1) / gam1 ; |
| 138 |
|
| 139 |
gam1sgamkap = m_0 * gam1 / (gam * kap) ; |
| 140 |
|
| 141 |
} |
| 142 |
|
| 143 |
double Ideal_gas::get_gam() const { |
| 144 |
return gam ; |
| 145 |
} |
| 146 |
|
| 147 |
double Ideal_gas::get_kap() const { |
| 148 |
return kap ; |
| 149 |
} |
| 150 |
|
| 151 |
double Ideal_gas::get_m_0() const { |
| 152 |
return m_0 ; |
| 153 |
} |
| 154 |
|
| 155 |
|
| 156 |
//-------------------------------// |
| 157 |
// The corresponding cold Eos // |
| 158 |
//-------------------------------// |
| 159 |
|
| 160 |
const Eos& Ideal_gas::new_cold_Eos() const { |
| 161 |
|
| 162 |
if (p_cold_eos == 0x0) { |
| 163 |
p_cold_eos = new Eos_poly(gam, kap, m_0) ; |
| 164 |
} |
| 165 |
|
| 166 |
return *p_cold_eos ; |
| 167 |
} |
| 168 |
|
| 169 |
|
| 170 |
//------------------------// |
| 171 |
// Comparison operators // |
| 172 |
//------------------------// |
| 173 |
|
| 174 |
|
| 175 |
bool Ideal_gas::operator==(const Hot_eos& eos_i) const { |
| 176 |
|
| 177 |
bool resu = true ; |
| 178 |
|
| 179 |
if ( eos_i.identify() != identify() ) { |
| 180 |
cout << "The second EOS is not of type Ideal_gas !" << endl ; |
| 181 |
resu = false ; |
| 182 |
} |
| 183 |
else { |
| 184 |
|
| 185 |
const Ideal_gas& eos = dynamic_cast<const Ideal_gas&>( eos_i ) ; |
| 186 |
|
| 187 |
if (eos.gam != gam) { |
| 188 |
cout |
| 189 |
<< "The two Ideal_gas have different gamma : " << gam << " <-> " |
| 190 |
<< eos.gam << endl ; |
| 191 |
resu = false ; |
| 192 |
} |
| 193 |
|
| 194 |
if (eos.kap != kap) { |
| 195 |
cout |
| 196 |
<< "The two Ideal_gas have different kappa : " << kap << " <-> " |
| 197 |
<< eos.kap << endl ; |
| 198 |
resu = false ; |
| 199 |
} |
| 200 |
|
| 201 |
if (eos.m_0 != m_0) { |
| 202 |
cout |
| 203 |
<< "The two Ideal_gas have different m_0 : " << m_0 << " <-> " |
| 204 |
<< eos.m_0 << endl ; |
| 205 |
resu = false ; |
| 206 |
} |
| 207 |
} |
| 208 |
return resu ; |
| 209 |
} |
| 210 |
|
| 211 |
|
| 212 |
bool Ideal_gas::operator!=(const Hot_eos& eos_i) const { |
| 213 |
return !(operator==(eos_i)) ; |
| 214 |
} |
| 215 |
|
| 216 |
|
| 217 |
//------------// |
| 218 |
// Outputs // |
| 219 |
//------------// |
| 220 |
|
| 221 |
void Ideal_gas::sauve(FILE* fich) const { |
| 222 |
|
| 223 |
Hot_eos::sauve(fich) ; |
| 224 |
|
| 225 |
fwrite_be(&gam, sizeof(double), 1, fich) ; |
| 226 |
fwrite_be(&kap, sizeof(double), 1, fich) ; |
| 227 |
fwrite_be(&m_0, sizeof(double), 1, fich) ; |
| 228 |
|
| 229 |
} |
| 230 |
|
| 231 |
ostream& Ideal_gas::operator>>(ostream & ost) const { |
| 232 |
|
| 233 |
ost << "Hot EOS of class Ideal_gas (relativistic ideal gas) : " << endl ; |
| 234 |
ost << " Adiabatic index gamma : " << gam << endl ; |
| 235 |
ost << " Pressure coefficient kappa : " << kap << |
| 236 |
" rho_nuc c^2 / n_nuc^gamma" << endl ; |
| 237 |
ost << " Mean particle mass : " << m_0 << " m_B" << endl ; |
| 238 |
|
| 239 |
return ost ; |
| 240 |
} |
| 241 |
|
| 242 |
|
| 243 |
//------------------------------// |
| 244 |
// Computational routines // |
| 245 |
//------------------------------// |
| 246 |
|
| 247 |
// Baryon density from enthalpy |
| 248 |
//------------------------------ |
| 249 |
|
| 250 |
double Ideal_gas::nbar_Hs_p(double ent, double sb) const { |
| 251 |
|
| 252 |
if ( ent > 0. ) { |
| 253 |
return pow( gam1sgamkap * ( exp(ent) - 1. ), unsgam1 ) * exp(-sb) ; |
| 254 |
} |
| 255 |
else { |
| 256 |
return 0 ; |
| 257 |
} |
| 258 |
} |
| 259 |
|
| 260 |
// Energy density from enthalpy |
| 261 |
//------------------------------ |
| 262 |
|
| 263 |
double Ideal_gas::ener_Hs_p(double ent, double sb) const { |
| 264 |
|
| 265 |
if ( ent > 0. ) { |
| 266 |
double nn = pow( gam1sgamkap * ( exp(ent) - 1. ), unsgam1 ) * exp(-sb) ; |
| 267 |
double pp = kap * pow( nn, gam ) * exp(gam1*sb) ; |
| 268 |
|
| 269 |
return unsgam1 * pp + m_0 * nn ; |
| 270 |
} |
| 271 |
else { |
| 272 |
return 0. ; |
| 273 |
} |
| 274 |
} |
| 275 |
|
| 276 |
// Pressure from enthalpy |
| 277 |
//------------------------ |
| 278 |
|
| 279 |
double Ideal_gas::press_Hs_p(double ent, double sb) const { |
| 280 |
|
| 281 |
if ( ent > 0. ) { |
| 282 |
double nn = pow( gam1sgamkap * ( exp(ent) - 1. ), unsgam1 ) * exp(-sb) ; |
| 283 |
|
| 284 |
return kap * pow( nn, gam ) * exp(gam1*sb) ; |
| 285 |
} |
| 286 |
else { |
| 287 |
return 0. ; |
| 288 |
} |
| 289 |
} |
| 290 |
|
| 291 |
// Temperature from enthalpy |
| 292 |
//--------------------------- |
| 293 |
|
| 294 |
double Ideal_gas::temp_Hs_p(double ent, double) const { |
| 295 |
|
| 296 |
using namespace Unites ; |
| 297 |
|
| 298 |
// if ( ent > 0. ) { |
| 299 |
return kap * gam1sgamkap * ( exp(ent) - 1. ) ; |
| 300 |
// return m_u_mev * kap * gam1sgamkap * ( exp(ent) - 1. ) ; |
| 301 |
//} |
| 302 |
//else { |
| 303 |
//return 0 ; |
| 304 |
//} |
| 305 |
} |
| 306 |
|
| 307 |
} |