hoteos.C
/*
* Methods of the class Hot_eos.
*
* (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 version 2
* as published by the Free Software Foundation.
*
* 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 hoteos_C[] = "$Header: /cvsroot/Lorene/C++/Source/Eos/hoteos.C,v 1.2 2015/09/10 13:28:18 j_novak Exp $" ;
/*
* $Id: hoteos.C,v 1.2 2015/09/10 13:28:18 j_novak Exp $
* $Log $
*
* $Header $
*
*/
// C headers
#include <cassert>
// Lorene headers
#include "hoteos.h"
#include "eos.h"
#include "tensor.h"
#include "utilitaires.h"
namespace Lorene {
//--------------//
// Constructors //
//--------------//
// Standard constructor without name
// ---------------------------------
Hot_eos::Hot_eos(){}
// Standard constructor with name
// ---------------------------------
Hot_eos::Hot_eos(const string& name_i):name(name_i){
set_der_0x0() ;
}
Hot_eos::Hot_eos(const char* name_i):name(name_i){
set_der_0x0() ;
}
// Copy constructor
// ----------------
Hot_eos::Hot_eos(const Hot_eos& eos_i):name(eos_i.name){
set_der_0x0() ;
}
// Constructor from a binary file
// ------------------------------
Hot_eos::Hot_eos(FILE* fich){
int taille ;
fread(&taille, sizeof(int), 1, fich) ;
assert(taille > 0) ;
char* t_name = new char[taille] ;
fread(t_name, sizeof(char), taille, fich) ;
set_name(t_name) ;
delete [] t_name ;
set_der_0x0() ;
}
// Constructor from a formatted file
// ---------------------------------
Hot_eos::Hot_eos(ifstream& fich){
char t_name[100] ;
fich.getline(t_name, 100) ;
set_name(t_name) ;
set_der_0x0() ;
}
//--------------//
// Destructor //
//--------------//
Hot_eos::~Hot_eos(){
Hot_eos::del_deriv() ;
}
//----------------------------------//
// Management of derived quantities //
//----------------------------------//
void Hot_eos::del_deriv() const {
if (p_cold_eos != 0x0) delete p_cold_eos ;
set_der_0x0() ;
}
void Hot_eos::set_der_0x0() const {
p_cold_eos = 0x0 ;
}
void Hot_eos::set_name(const char* name_i) {
name.assign(name_i) ;
}
//------------//
// Outputs //
//------------//
void Hot_eos::sauve(FILE* fich) const {
int ident = identify() ;
fwrite_be(&ident, sizeof(int), 1, fich) ;
int taille = int(name.size()) ;
fwrite_be(&taille, sizeof(int), 1, fich) ;
fwrite(name.c_str(), sizeof(char), name.size(), fich) ;
}
ostream& operator<<(ostream& ost, const Hot_eos& eqetat) {
ost << eqetat.get_name() << endl ;
eqetat >> ost ;
return ost ;
}
//-------------------------------//
// Generic computational routine //
//-------------------------------//
void Hot_eos::calcule(const Scalar& ent, const Scalar& sb, int nzet, int l_min,
double (Hot_eos::*fait)(double, double) const,
Scalar& resu) const {
assert(ent.get_etat() != ETATNONDEF) ;
assert(sb.get_etat() != ETATNONDEF) ;
const Map* mp = &(ent.get_mp()) ; // Mapping
const Mg3d* mg = mp->get_mg() ; // Multi-grid
int nz = mg->get_nzone() ; // total number of domains
if (ent.get_etat() == ETATZERO) {
resu.set_etat_zero() ;
return ;
}
assert(ent.get_etat() == ETATQCQ) ;
const Valeur& vent = ent.get_spectral_va() ;
vent.coef_i() ; // the values in the configuration space are required
const Valeur* vsb = &sb.get_spectral_va() ;
Valeur vzero(mg) ;
if (sb.get_etat() == ETATZERO) {
vzero.annule_hard() ;
vsb = &vzero ;
}
assert(vsb->get_mg() == vent.get_mg()) ;
// Preparations for a point by point computation:
resu.set_etat_qcq() ;
Valeur& vresu = resu.set_spectral_va() ;
vresu.set_etat_c_qcq() ;
vresu.c->set_etat_qcq() ;
// Loop on domains where the computation has to be done :
for (int l = l_min; l< l_min + nzet; l++) {
assert(l>=0) ;
assert(l<nz) ;
bool tsb0 = false ;
Tbl* tent = vent.c->t[l] ;
Tbl* tsb = vsb->c->t[l] ;
Tbl* tresu = vresu.c->t[l] ;
if (tent->get_etat() == ETATZERO) {
tresu->set_etat_zero() ;
}
else {
assert( tent->get_etat() == ETATQCQ ) ;
tresu->set_etat_qcq() ;
if (tsb->get_etat() == ETATZERO) {
tsb0 = true ;
tsb = new Tbl(tent->dim) ;
tsb->annule_hard() ;
}
for (int i=0; i<tent->get_taille(); i++) {
tresu->t[i] = (this->*fait)( tent->t[i], tsb->t[i] ) ;
}
} // End of the case where ent != 0 in the considered domain
if (tsb0) delete tsb ;
} // End of the loop on domains where the computation had to be done
// resu is set to zero in the other domains :
if (l_min > 0) {
resu.annule(0, l_min-1) ;
}
if (l_min + nzet < nz) {
resu.annule(l_min + nzet, nz - 1) ;
}
}
// Baryon density from enthalpy
//------------------------------
Scalar Hot_eos::nbar_Hs(const Scalar& ent, const Scalar& sb, int nzet, int l_min)
const {
Scalar resu(ent.get_mp()) ;
calcule(ent, sb, nzet, l_min, &Hot_eos::nbar_Hs_p, resu) ;
return resu ;
}
// Energy density from enthalpy
//------------------------------
Scalar Hot_eos::ener_Hs(const Scalar& ent, const Scalar& sb, int nzet, int l_min)
const {
Scalar resu(ent.get_mp()) ;
calcule(ent, sb, nzet, l_min, &Hot_eos::ener_Hs_p, resu) ;
return resu ;
}
// Pressure from enthalpy
//-----------------------
Scalar Hot_eos::press_Hs(const Scalar& ent, const Scalar& sb, int nzet, int l_min)
const {
Scalar resu(ent.get_mp()) ;
calcule(ent, sb, nzet, l_min, &Hot_eos::press_Hs_p, resu) ;
return resu ;
}
// Temperature from enthalpy
//--------------------------
Scalar Hot_eos::temp_Hs(const Scalar& ent, const Scalar& sb, int nzet, int l_min)
const {
Scalar resu(ent.get_mp()) ;
calcule(ent, sb, nzet, l_min, &Hot_eos::temp_Hs_p, resu) ;
return resu ;
}
}
Lorene::Hot_eos::get_name
const string & get_name() const
Returns the hot EOS name.
Definition hoteos.h:120
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::del_deriv
virtual void del_deriv() const
Deletes all the derived quantities.
Definition hoteos.C:109
Lorene::Hot_eos::nbar_Hs_p
virtual double nbar_Hs_p(double ent, double sb) const =0
Computes the baryon density from the log-enthalpy and entropy per baryon (virtual function implemente...
Lorene::Hot_eos::calcule
void calcule(const Scalar &thermo1, const Scalar &thermo2, int nzet, int l_min, double(Hot_eos::*fait)(double, double) const, Scalar &resu) const
General computational method for Scalar 's.
Definition hoteos.C:153
Lorene::Hot_eos::ener_Hs_p
virtual double ener_Hs_p(double ent, double sb) const =0
Computes the total energy density from the log-enthalpy and entropy per baryon (virtual function impl...
Lorene::Hot_eos::p_cold_eos
Eos * p_cold_eos
Corresponding cold Eos.
Definition hoteos.h:108
Lorene::Hot_eos::temp_Hs_p
virtual double temp_Hs_p(double ent, double sb) const =0
Computes the temperature from the log-enthalpy and entropy per baryon (virtual function implemented i...
Lorene::Hot_eos::press_Hs
Scalar press_Hs(const Scalar &ent, const Scalar &sb, int nzet, int l_min=0) const
Computes the pressure from the log-enthalpy and entropy per baryon.
Definition hoteos.C:266
Lorene::Hot_eos::nbar_Hs
Scalar nbar_Hs(const Scalar &ent, const Scalar &sb, int nzet, int l_min=0) const
Computes the baryon density field from the log-enthalpy field and entropy per baryon.
Definition hoteos.C:236
Lorene::Hot_eos::Hot_eos
Hot_eos()
Standard constructor.
Definition hoteos.C:56
Lorene::Hot_eos::ener_Hs
Scalar ener_Hs(const Scalar &ent, const Scalar &sb, int nzet, int l_min=0) const
Computes the total energy density from the log-enthalpy and entropy per baryon.
Definition hoteos.C:252
Lorene::Hot_eos::temp_Hs
Scalar temp_Hs(const Scalar &ent, const Scalar &sb, int nzet, int l_min=0) const
Computes the temperature field from the log-enthalpy field and entropy per baryon.
Definition hoteos.C:280
Lorene::Hot_eos::set_der_0x0
void set_der_0x0() const
Sets to 0x0 all the pointers on derived quantities.
Definition hoteos.C:114
Lorene::Hot_eos::press_Hs_p
virtual double press_Hs_p(double ent, double sb) const =0
Computes the pressure from the log-enthalpy and entropy per baryon (virtual function implemented in t...
Lorene::Hot_eos::~Hot_eos
virtual ~Hot_eos()
Destructor.
Definition hoteos.C:101
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::Hot_eos::operator<<
friend ostream & operator<<(ostream &, const Hot_eos &)
Display.
Definition hoteos.C:143
Lorene::Hot_eos::set_name
void set_name(const char *)
Sets the hot EOS name.
Definition hoteos.C:118
Lorene::Mg3d
Multi-domain grid.
Definition grilles.h:273
Lorene::Mg3d::get_nzone
int get_nzone() const
Returns the number of domains.
Definition grilles.h:448
Lorene::Mtbl::t
Tbl ** t
Array (size nzone ) of pointers on the Tbl 's.
Definition mtbl.h:132
Lorene::Mtbl::set_etat_qcq
void set_etat_qcq()
Sets the logical state to ETATQCQ (ordinary state).
Definition mtbl.C:299
Lorene::Scalar
Tensor field of valence 0 (or component of a tensorial field).
Definition scalar.h:387
Lorene::Scalar::set_etat_qcq
virtual void set_etat_qcq()
Sets the logical state to ETATQCQ (ordinary state).
Definition scalar.C:353
Lorene::Scalar::set_etat_zero
virtual void set_etat_zero()
Sets the logical state to ETATZERO (zero).
Definition scalar.C:324
Lorene::Scalar::annule
virtual void annule(int l_min, int l_max)
Sets the Scalar to zero in several domains.
Definition scalar.C:391
Lorene::Scalar::set_spectral_va
Valeur & set_spectral_va()
Returns va (read/write version).
Definition scalar.h:604
Lorene::Scalar::get_spectral_va
const Valeur & get_spectral_va() const
Returns va (read only version).
Definition scalar.h:601
Lorene::Scalar::get_etat
int get_etat() const
Returns the logical state ETATNONDEF (undefined), ETATZERO (null) or ETATQCQ (ordinary).
Definition scalar.h:554
Lorene::Tbl
Basic array class.
Definition tbl.h:161
Lorene::Tbl::dim
Dim_tbl dim
Number of dimensions, size,...
Definition tbl.h:172
Lorene::Tbl::get_etat
int get_etat() const
Gives the logical state.
Definition tbl.h:394
Lorene::Tbl::annule_hard
void annule_hard()
Sets the Tbl to zero in a hard way.
Definition tbl.C:372
Lorene::Tbl::set_etat_zero
void set_etat_zero()
Sets the logical state to ETATZERO (zero).
Definition tbl.C:347
Lorene::Tbl::set_etat_qcq
void set_etat_qcq()
Sets the logical state to ETATQCQ (ordinary state).
Definition tbl.C:361
Lorene::Tbl::get_taille
int get_taille() const
Gives the total size (ie dim.taille).
Definition tbl.h:397
Lorene::Tbl::t
double * t
The array of double.
Definition tbl.h:173
Lorene::Valeur
Values and coefficients of a (real-value) function.
Definition valeur.h:287
Lorene::Valeur::set_etat_c_qcq
void set_etat_c_qcq()
Sets the logical state to ETATQCQ (ordinary state) for values in the configuration space (Mtbl c ).
Definition valeur.C:701
Lorene::Valeur::c
Mtbl * c
Values of the function at the points of the multi-grid.
Definition valeur.h:299
Lorene::Valeur::coef_i
void coef_i() const
Computes the physical value of *this.
Definition valeur_coef_i.C:140
Lorene::Valeur::get_mg
const Mg3d * get_mg() const
Returns the Mg3d on which the this is defined.
Definition valeur.h:729
Lorene::Valeur::annule_hard
void annule_hard()
Sets the Valeur to zero in a hard way.
Definition valeur.C:723
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::Tensor::get_mp
const Map & get_mp() const
Returns the mapping.
Definition tensor.h:861
Lorene
Lorene prototypes.
Definition app_hor.h:64
Lorene::Map
Map(const Mg3d &)
Constructor from a multi-domain 3D grid.
Definition map.C:139