| 1 |
/* |
| 2 |
* Methods of class MEos |
| 3 |
* |
| 4 |
*/ |
| 5 |
|
| 6 |
/* |
| 7 |
* Copyright (c) 2002 Michal Bejger, Eric Gourgoulhon & Leszek Zdunik |
| 8 |
* |
| 9 |
* This file is part of LORENE. |
| 10 |
* |
| 11 |
* LORENE is free software; you can redistribute it and/or modify |
| 12 |
* it under the terms of the GNU General Public License version 2 |
| 13 |
* as published by the Free Software Foundation. |
| 14 |
* |
| 15 |
* LORENE is distributed in the hope that it will be useful, |
| 16 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 17 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 18 |
* GNU General Public License for more details. |
| 19 |
* |
| 20 |
* You should have received a copy of the GNU General Public License |
| 21 |
* along with LORENE; if not, write to the Free Software |
| 22 |
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 23 |
* |
| 24 |
*/ |
| 25 |
|
| 26 |
char meos_C[] = "$Header: /cvsroot/Lorene/C++/Source/Eos/meos.C,v 1.6 2014/10/13 08:52:54 j_novak Exp $" ; |
| 27 |
|
| 28 |
/* |
| 29 |
* $Id: meos.C,v 1.6 2014/10/13 08:52:54 j_novak Exp $ |
| 30 |
* $Log: meos.C,v $ |
| 31 |
* Revision 1.6 2014/10/13 08:52:54 j_novak |
| 32 |
* Lorene classes and functions now belong to the namespace Lorene. |
| 33 |
* |
| 34 |
* Revision 1.5 2014/10/06 15:13:07 j_novak |
| 35 |
* Modified #include directives to use c++ syntax. |
| 36 |
* |
| 37 |
* Revision 1.4 2004/04/01 11:09:26 e_gourgoulhon |
| 38 |
* Copy constructor of MEos: explicit call to the default constructor of |
| 39 |
* base class Eos. |
| 40 |
* |
| 41 |
* Revision 1.3 2002/10/16 14:36:35 j_novak |
| 42 |
* Reorganization of #include instructions of standard C++, in order to |
| 43 |
* use experimental version 3 of gcc. |
| 44 |
* |
| 45 |
* Revision 1.2 2002/04/09 14:42:29 e_gourgoulhon |
| 46 |
* Dummy argument in assignment. |
| 47 |
* |
| 48 |
* Revision 1.1 2002/04/09 14:40:36 e_gourgoulhon |
| 49 |
* Methods for new class MEos |
| 50 |
* |
| 51 |
* |
| 52 |
* |
| 53 |
* $Header: /cvsroot/Lorene/C++/Source/Eos/meos.C,v 1.6 2014/10/13 08:52:54 j_novak Exp $ |
| 54 |
* |
| 55 |
*/ |
| 56 |
|
| 57 |
// C headers |
| 58 |
#include <cstdlib> |
| 59 |
|
| 60 |
// Lorene headers |
| 61 |
#include "headcpp.h" |
| 62 |
#include "eos.h" |
| 63 |
#include "utilitaires.h" |
| 64 |
#include "param.h" |
| 65 |
|
| 66 |
|
| 67 |
//--------------------------------------// |
| 68 |
// Constructors // |
| 69 |
//--------------------------------------// |
| 70 |
|
| 71 |
namespace Lorene { |
| 72 |
MEos::MEos(int ndom_i, const Eos** mono_eos_i) : ndom(ndom_i) , |
| 73 |
constructed_from_file(false) { |
| 74 |
|
| 75 |
|
| 76 |
mono_eos = new const Eos* [ndom] ; |
| 77 |
|
| 78 |
for (int l=0; l<ndom; l++) { |
| 79 |
mono_eos[l] = mono_eos_i[l] ; |
| 80 |
} |
| 81 |
|
| 82 |
} |
| 83 |
|
| 84 |
|
| 85 |
MEos::MEos(const Eos& eos1, const Eos& eos2) : ndom(2) , |
| 86 |
constructed_from_file(false) { |
| 87 |
|
| 88 |
mono_eos = new const Eos* [ndom] ; |
| 89 |
|
| 90 |
mono_eos[0] = &eos1 ; |
| 91 |
mono_eos[1] = &eos2 ; |
| 92 |
|
| 93 |
} |
| 94 |
|
| 95 |
MEos::MEos(const Eos& eos1, const Eos& eos2, const Eos& eos3) : ndom(3) , |
| 96 |
constructed_from_file(false) { |
| 97 |
|
| 98 |
mono_eos = new const Eos* [ndom] ; |
| 99 |
|
| 100 |
mono_eos[0] = &eos1 ; |
| 101 |
mono_eos[1] = &eos2 ; |
| 102 |
mono_eos[2] = &eos3 ; |
| 103 |
|
| 104 |
} |
| 105 |
|
| 106 |
MEos::MEos(const Eos& eos1, const Eos& eos2, const Eos& eos3, const Eos& eos4) : ndom(4) , |
| 107 |
constructed_from_file(false) { |
| 108 |
|
| 109 |
mono_eos = new const Eos* [ndom] ; |
| 110 |
|
| 111 |
mono_eos[0] = &eos1 ; |
| 112 |
mono_eos[1] = &eos2 ; |
| 113 |
mono_eos[2] = &eos3 ; |
| 114 |
mono_eos[3] = &eos4 ; |
| 115 |
|
| 116 |
} |
| 117 |
|
| 118 |
// Copy constructor |
| 119 |
MEos::MEos(const MEos& meos) : Eos(), |
| 120 |
ndom(meos.ndom), |
| 121 |
constructed_from_file(false) { |
| 122 |
|
| 123 |
mono_eos = new const Eos* [ndom] ; |
| 124 |
|
| 125 |
for (int l=0; l<ndom; l++) { |
| 126 |
mono_eos[l] = meos.mono_eos[l] ; |
| 127 |
} |
| 128 |
|
| 129 |
} |
| 130 |
|
| 131 |
|
| 132 |
// Constructor from a binary file |
| 133 |
MEos::MEos(FILE* fich) : Eos(fich), constructed_from_file(true) { |
| 134 |
|
| 135 |
fread_be(&ndom, sizeof(int), 1, fich) ; |
| 136 |
|
| 137 |
mono_eos = new const Eos* [ndom] ; |
| 138 |
|
| 139 |
for (int l=0; l<ndom; l++) { |
| 140 |
mono_eos[l] = Eos::eos_from_file(fich) ; |
| 141 |
} |
| 142 |
} |
| 143 |
|
| 144 |
// Constructor from a formatted file |
| 145 |
MEos::MEos(ifstream& fich) : Eos(fich), |
| 146 |
constructed_from_file(true) { |
| 147 |
|
| 148 |
char blabla[80] ; |
| 149 |
|
| 150 |
fich >> ndom ; fich.getline(blabla, 80) ; |
| 151 |
|
| 152 |
mono_eos = new const Eos* [ndom] ; |
| 153 |
|
| 154 |
for (int l=0; l<ndom; l++) { |
| 155 |
mono_eos[l] = Eos::eos_from_file(fich) ; |
| 156 |
} |
| 157 |
} |
| 158 |
|
| 159 |
|
| 160 |
|
| 161 |
// Destructor |
| 162 |
MEos::~MEos() { |
| 163 |
|
| 164 |
if (constructed_from_file) { |
| 165 |
for (int l=0; l<ndom; l++) { |
| 166 |
delete mono_eos[l] ; |
| 167 |
} |
| 168 |
} |
| 169 |
|
| 170 |
delete [] mono_eos ; |
| 171 |
|
| 172 |
} |
| 173 |
|
| 174 |
//--------------// |
| 175 |
// Assignment // |
| 176 |
//--------------// |
| 177 |
|
| 178 |
void MEos::operator=(const MEos& ) { |
| 179 |
|
| 180 |
cout << "MEos::operator= : not implemented yet !" << endl ; |
| 181 |
abort() ; |
| 182 |
|
| 183 |
} |
| 184 |
|
| 185 |
|
| 186 |
//---------------------------------------// |
| 187 |
// Outputs // |
| 188 |
//---------------------------------------// |
| 189 |
|
| 190 |
void MEos::sauve(FILE* fich) const { |
| 191 |
|
| 192 |
Eos::sauve(fich) ; |
| 193 |
|
| 194 |
fwrite_be(&ndom, sizeof(int), 1, fich) ; |
| 195 |
|
| 196 |
for (int l=0; l<ndom; l++) { |
| 197 |
mono_eos[l]->sauve(fich) ; |
| 198 |
} |
| 199 |
|
| 200 |
} |
| 201 |
|
| 202 |
ostream& MEos::operator>>(ostream & ost) const { |
| 203 |
|
| 204 |
ost << "EOS of class MEos (multi-domain equation of state) : " << endl ; |
| 205 |
ost << " Number of domains : " << ndom << endl ; |
| 206 |
|
| 207 |
for (int l=0; l<ndom; l++) { |
| 208 |
ost << "Equation of state in domain " << l << " : " << endl ; |
| 209 |
ost << "-------------------------------" << endl ; |
| 210 |
ost << *(mono_eos[l]) ; |
| 211 |
} |
| 212 |
|
| 213 |
return ost ; |
| 214 |
|
| 215 |
} |
| 216 |
|
| 217 |
//------------------------// |
| 218 |
// Comparison operators // |
| 219 |
//------------------------// |
| 220 |
|
| 221 |
|
| 222 |
bool MEos::operator==(const Eos& eos_i) const { |
| 223 |
|
| 224 |
bool resu = true ; |
| 225 |
|
| 226 |
if ( eos_i.identify() != identify() ) { |
| 227 |
cout << "The second EOS is not of type MEos !" << endl ; |
| 228 |
resu = false ; |
| 229 |
} |
| 230 |
else{ |
| 231 |
|
| 232 |
const MEos& eos = dynamic_cast<const MEos&>( eos_i ) ; |
| 233 |
|
| 234 |
if (eos.ndom != ndom) { |
| 235 |
cout << "The two MEos have different number of domains" << endl ; |
| 236 |
resu = false ; |
| 237 |
|
| 238 |
} |
| 239 |
else { |
| 240 |
for (int l=0; l<ndom; l++) { |
| 241 |
resu = resu && ( *(mono_eos[l]) == *(eos.mono_eos[l]) ) ; |
| 242 |
} |
| 243 |
} |
| 244 |
} |
| 245 |
|
| 246 |
return resu ; |
| 247 |
|
| 248 |
} |
| 249 |
|
| 250 |
bool MEos::operator!=(const Eos& eos_i) const { |
| 251 |
|
| 252 |
return !(operator==(eos_i)) ; |
| 253 |
|
| 254 |
} |
| 255 |
|
| 256 |
|
| 257 |
//------------------------------// |
| 258 |
// Computational routines // |
| 259 |
//------------------------------// |
| 260 |
|
| 261 |
// Baryon density from enthalpy |
| 262 |
//------------------------------ |
| 263 |
|
| 264 |
double MEos::nbar_ent_p(double ent, const Param* par) const { |
| 265 |
|
| 266 |
int l0 = par->get_int() ; // index of the domain |
| 267 |
|
| 268 |
return mono_eos[l0]->nbar_ent_p(ent) ; |
| 269 |
|
| 270 |
} |
| 271 |
|
| 272 |
// Energy density from enthalpy |
| 273 |
//------------------------------ |
| 274 |
|
| 275 |
double MEos::ener_ent_p(double ent, const Param* par) const { |
| 276 |
|
| 277 |
int l0 = par->get_int() ; // index of the domain |
| 278 |
|
| 279 |
return mono_eos[l0]->ener_ent_p(ent) ; |
| 280 |
} |
| 281 |
|
| 282 |
// Pressure from enthalpy |
| 283 |
//------------------------ |
| 284 |
|
| 285 |
double MEos::press_ent_p(double ent, const Param* par) const { |
| 286 |
|
| 287 |
int l0 = par->get_int() ; // index of the domain |
| 288 |
|
| 289 |
return mono_eos[l0]->press_ent_p(ent) ; |
| 290 |
} |
| 291 |
|
| 292 |
// dln(n)/ln(H) from enthalpy |
| 293 |
//--------------------------- |
| 294 |
|
| 295 |
double MEos::der_nbar_ent_p(double ent, const Param* par) const { |
| 296 |
|
| 297 |
int l0 = par->get_int() ; // index of the domain |
| 298 |
|
| 299 |
return mono_eos[l0]->der_nbar_ent_p(ent) ; |
| 300 |
} |
| 301 |
|
| 302 |
// dln(e)/ln(H) from enthalpy |
| 303 |
//--------------------------- |
| 304 |
|
| 305 |
double MEos::der_ener_ent_p(double ent, const Param* par) const { |
| 306 |
|
| 307 |
int l0 = par->get_int() ; // index of the domain |
| 308 |
|
| 309 |
return mono_eos[l0]->der_ener_ent_p(ent) ; |
| 310 |
} |
| 311 |
|
| 312 |
// dln(p)/ln(H) from enthalpy |
| 313 |
//--------------------------- |
| 314 |
|
| 315 |
double MEos::der_press_ent_p(double ent, const Param* par) const { |
| 316 |
|
| 317 |
int l0 = par->get_int() ; // index of the domain |
| 318 |
|
| 319 |
return mono_eos[l0]->der_press_ent_p(ent) ; |
| 320 |
} |
| 321 |
|
| 322 |
|
| 323 |
|
| 324 |
} |