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
|
/*
* Methods of the class Ideal_gas.
*
* (see file hoteos.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 ideal_gas_C[] = "$Header: /cvsroot/Lorene/C++/Source/Eos/ideal_gas.C,v 1.3 2015/09/10 13:54:04 j_novak Exp $" ;
/*
* $Id: ideal_gas.C,v 1.3 2015/09/10 13:54:04 j_novak Exp $
* $Log: ideal_gas.C,v $
* Revision 1.3 2015/09/10 13:54:04 j_novak
* Allows for negative entropy in the temperature function.
*
* Revision 1.1 2015/03/17 14:20:00 j_novak
* New class Hot_eos to deal with temperature-dependent EOSs.
*
*
*
* $Header: /cvsroot/Lorene/C++/Source/Eos/ideal_gas.C,v 1.3 2015/09/10 13:54:04 j_novak Exp $
*
*/
// Headers C
#include <cstdlib>
#include <cmath>
// Headers Lorene
#include "hoteos.h"
#include "eos.h"
#include "utilitaires.h"
#include "unites.h"
namespace Lorene {
//--------------//
// Constructors //
//--------------//
// Standard constructor
// --------------------
Ideal_gas::Ideal_gas(double gam0, double kappa, double mass) :
Hot_eos("Ideal gas EOS"), gam(gam0), kap(kappa), m_0(mass) {
set_auxiliary() ;
}
// Copy constructor
// ----------------
Ideal_gas::Ideal_gas(const Ideal_gas& eosi) :
Hot_eos(eosi), gam(eosi.gam), kap(eosi.kap), m_0(eosi.m_0)
{
set_auxiliary() ;
}
// Constructor from binary file
// ----------------------------
Ideal_gas::Ideal_gas(FILE* fich) :
Hot_eos(fich) {
fread_be(&gam, sizeof(double), 1, fich) ;
fread_be(&kap, sizeof(double), 1, fich) ;
fread_be(&m_0, sizeof(double), 1, fich) ;
set_auxiliary() ;
}
// Constructor from a formatted file
// ---------------------------------
Ideal_gas::Ideal_gas(ifstream& fich) :
Hot_eos(fich) {
fich >> gam ; fich.ignore(80, '\n') ;
fich >> kap ; fich.ignore(80, '\n') ;
fich >> m_0 ; fich.ignore(80, '\n') ;
set_auxiliary() ;
}
//--------------//
// Destructor //
//--------------//
Ideal_gas::~Ideal_gas(){}
//--------------//
// Assignment //
//--------------//
void Ideal_gas::operator=(const Ideal_gas& eosi) {
name = eosi.name ;
gam = eosi.gam ;
kap = eosi.kap ;
m_0 = eosi.m_0 ;
set_auxiliary() ;
}
//-----------------------//
// Miscellaneous //
//-----------------------//
void Ideal_gas::set_auxiliary() {
gam1 = gam - double(1) ;
unsgam1 = double(1) / gam1 ;
gam1sgamkap = m_0 * gam1 / (gam * kap) ;
}
double Ideal_gas::get_gam() const {
return gam ;
}
double Ideal_gas::get_kap() const {
return kap ;
}
double Ideal_gas::get_m_0() const {
return m_0 ;
}
//-------------------------------//
// The corresponding cold Eos //
//-------------------------------//
const Eos& Ideal_gas::new_cold_Eos() const {
if (p_cold_eos == 0x0) {
p_cold_eos = new Eos_poly(gam, kap, m_0) ;
}
return *p_cold_eos ;
}
//------------------------//
// Comparison operators //
//------------------------//
bool Ideal_gas::operator==(const Hot_eos& eos_i) const {
bool resu = true ;
if ( eos_i.identify() != identify() ) {
cout << "The second EOS is not of type Ideal_gas !" << endl ;
resu = false ;
}
else {
const Ideal_gas& eos = dynamic_cast<const Ideal_gas&>( eos_i ) ;
if (eos.gam != gam) {
cout
<< "The two Ideal_gas have different gamma : " << gam << " <-> "
<< eos.gam << endl ;
resu = false ;
}
if (eos.kap != kap) {
cout
<< "The two Ideal_gas have different kappa : " << kap << " <-> "
<< eos.kap << endl ;
resu = false ;
}
if (eos.m_0 != m_0) {
cout
<< "The two Ideal_gas have different m_0 : " << m_0 << " <-> "
<< eos.m_0 << endl ;
resu = false ;
}
}
return resu ;
}
bool Ideal_gas::operator!=(const Hot_eos& eos_i) const {
return !(operator==(eos_i)) ;
}
//------------//
// Outputs //
//------------//
void Ideal_gas::sauve(FILE* fich) const {
Hot_eos::sauve(fich) ;
fwrite_be(&gam, sizeof(double), 1, fich) ;
fwrite_be(&kap, sizeof(double), 1, fich) ;
fwrite_be(&m_0, sizeof(double), 1, fich) ;
}
ostream& Ideal_gas::operator>>(ostream & ost) const {
ost << "Hot EOS of class Ideal_gas (relativistic ideal gas) : " << endl ;
ost << " Adiabatic index gamma : " << gam << endl ;
ost << " Pressure coefficient kappa : " << kap <<
" rho_nuc c^2 / n_nuc^gamma" << endl ;
ost << " Mean particle mass : " << m_0 << " m_B" << endl ;
return ost ;
}
//------------------------------//
// Computational routines //
//------------------------------//
// Baryon density from enthalpy
//------------------------------
double Ideal_gas::nbar_Hs_p(double ent, double sb) const {
if ( ent > 0. ) {
return pow( gam1sgamkap * ( exp(ent) - 1. ), unsgam1 ) * exp(-sb) ;
}
else {
return 0 ;
}
}
// Energy density from enthalpy
//------------------------------
double Ideal_gas::ener_Hs_p(double ent, double sb) const {
if ( ent > 0. ) {
double nn = pow( gam1sgamkap * ( exp(ent) - 1. ), unsgam1 ) * exp(-sb) ;
double pp = kap * pow( nn, gam ) * exp(gam1*sb) ;
return unsgam1 * pp + m_0 * nn ;
}
else {
return 0. ;
}
}
// Pressure from enthalpy
//------------------------
double Ideal_gas::press_Hs_p(double ent, double sb) const {
if ( ent > 0. ) {
double nn = pow( gam1sgamkap * ( exp(ent) - 1. ), unsgam1 ) * exp(-sb) ;
return kap * pow( nn, gam ) * exp(gam1*sb) ;
}
else {
return 0. ;
}
}
// Temperature from enthalpy
//---------------------------
double Ideal_gas::temp_Hs_p(double ent, double) const {
using namespace Unites ;
// if ( ent > 0. ) {
return kap * gam1sgamkap * ( exp(ent) - 1. ) ;
// return m_u_mev * kap * gam1sgamkap * ( exp(ent) - 1. ) ;
//}
//else {
//return 0 ;
//}
}
}
|