ideal_gas.C
/*
* 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 ;
//}
}
}
Lorene::Eos_poly
Polytropic equation of state (relativistic case).
Definition eos.h:757
Lorene::Eos
Equation of state base class.
Definition eos.h:190
Lorene::Hot_eos::identify
virtual int identify() const =0
Returns a number to identify the sub-classe of Hot_eos the object belongs to.
Lorene::Hot_eos::p_cold_eos
Eos * p_cold_eos
Corresponding cold Eos.
Definition hoteos.h:108
Lorene::Hot_eos::Hot_eos
Hot_eos()
Standard constructor.
Definition hoteos.C:56
Lorene::Hot_eos::sauve
virtual void sauve(FILE *) const
Save in a file.
Definition hoteos.C:129
Lorene::Hot_eos::name
string name
EOS name.
Definition hoteos.h:72
Lorene::Ideal_gas::set_auxiliary
void set_auxiliary()
Computes the auxiliary quantities gam1 , unsgam1 , gam1sgamkap from the values of gam and kap.
Definition ideal_gas.C:133
Lorene::Ideal_gas::get_m_0
double get_m_0() const
Return the individual particule mass (cf.
Definition ideal_gas.C:151
Lorene::Ideal_gas::nbar_Hs_p
virtual double nbar_Hs_p(double ent, double sb) const
Computes the baryon density from the log-enthalpy and entropy per baryon (virtual function implemente...
Definition ideal_gas.C:250
Lorene::Ideal_gas::Ideal_gas
Ideal_gas(double gamma, double kappa, double mass=1.)
Standard constructor.
Definition ideal_gas.C:64
Lorene::Ideal_gas::sauve
virtual void sauve(FILE *) const
Save in a file.
Definition ideal_gas.C:221
Lorene::Ideal_gas::get_kap
double get_kap() const
Returns the pressure coefficient (cf. Eq. (1)).
Definition ideal_gas.C:147
Lorene::Ideal_gas::m_0
double m_0
Individual particule mass (cf.
Definition hoteos.h:381
Lorene::Ideal_gas::operator==
virtual bool operator==(const Hot_eos &) const
Comparison operator (egality).
Definition ideal_gas.C:175
Lorene::Ideal_gas::gam1sgamkap
double gam1sgamkap
Definition hoteos.h:385
Lorene::Ideal_gas::press_Hs_p
virtual double press_Hs_p(double ent, double sb) const
Computes the pressure from the log-enthalpy and entropy per baryon (virtual function implemented in t...
Definition ideal_gas.C:279
Lorene::Ideal_gas::get_gam
double get_gam() const
Returns the adiabatic index (cf. Eq. (1)).
Definition ideal_gas.C:143
Lorene::Ideal_gas::operator>>
virtual ostream & operator>>(ostream &) const
Operator >>.
Definition ideal_gas.C:231
Lorene::Ideal_gas::operator!=
virtual bool operator!=(const Hot_eos &) const
Comparison operator (difference).
Definition ideal_gas.C:212
Lorene::Ideal_gas::~Ideal_gas
virtual ~Ideal_gas()
Destructor.
Definition ideal_gas.C:110
Lorene::Ideal_gas::ener_Hs_p
virtual double ener_Hs_p(double ent, double sb) const
Computes the total energy density from the log-enthalpy and entropy per baryon (virtual function impl...
Definition ideal_gas.C:263
Lorene::Ideal_gas::temp_Hs_p
virtual double temp_Hs_p(double ent, double sb) const
Computes the temperature from the log-enthalpy and entropy per baryon (virtual function implemented i...
Definition ideal_gas.C:294
Lorene::Ideal_gas::new_cold_Eos
virtual const Eos & new_cold_Eos() const
Returns the corresponding cold Eos.
Definition ideal_gas.C:160
Lorene::Ideal_gas::identify
virtual int identify() const
Returns a number to identify the sub-classe of Hot_eos the object belongs to.
Definition hoteos_from_file.C:58
Lorene::Ideal_gas::gam1
double gam1
Definition hoteos.h:383
Lorene::Ideal_gas::gam
double gam
Adiabatic index .
Definition hoteos.h:369
Lorene::Ideal_gas::operator=
void operator=(const Ideal_gas &)
Assignment to another Ideal_gas.
Definition ideal_gas.C:116
Lorene::Ideal_gas::unsgam1
double unsgam1
Definition hoteos.h:384
Lorene::Ideal_gas::kap
double kap
Pressure coefficient (cf.
Definition hoteos.h:376
Lorene::exp
Cmp exp(const Cmp &)
Exponential.
Definition cmp_math.C:270
Lorene::pow
Cmp pow(const Cmp &, int)
Power .
Definition cmp_math.C:348
Lorene::fread_be
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
Lorene::fwrite_be
int fwrite_be(const int *aa, int size, int nb, FILE *fich)
Writes integer(s) into a binary file according to the big endian convention.
Definition fwrite_be.C:70
Lorene
Lorene prototypes.
Definition app_hor.h:64
Unites
Standard units of space, time and mass.