meos.C

00001 /*
00002  *  Methods of class MEos
00003  *
00004  */
00005 
00006 /*
00007  *   Copyright (c) 2002 Michal Bejger, Eric Gourgoulhon & Leszek Zdunik
00008  *
00009  *   This file is part of LORENE.
00010  *
00011  *   LORENE is free software; you can redistribute it and/or modify
00012  *   it under the terms of the GNU General Public License version 2
00013  *   as published by the Free Software Foundation.
00014  *
00015  *   LORENE is distributed in the hope that it will be useful,
00016  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
00017  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00018  *   GNU General Public License for more details.
00019  *
00020  *   You should have received a copy of the GNU General Public License
00021  *   along with LORENE; if not, write to the Free Software
00022  *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00023  *
00024  */
00025 
00026 char meos_C[] = "$Header: /cvsroot/Lorene/C++/Source/Eos/meos.C,v 1.4 2004/04/01 11:09:26 e_gourgoulhon Exp $" ;
00027 
00028 /*
00029  * $Id: meos.C,v 1.4 2004/04/01 11:09:26 e_gourgoulhon Exp $
00030  * $Log: meos.C,v $
00031  * Revision 1.4  2004/04/01 11:09:26  e_gourgoulhon
00032  * Copy constructor of MEos: explicit call to the default constructor of
00033  * base class Eos.
00034  *
00035  * Revision 1.3  2002/10/16 14:36:35  j_novak
00036  * Reorganization of #include instructions of standard C++, in order to
00037  * use experimental version 3 of gcc.
00038  *
00039  * Revision 1.2  2002/04/09 14:42:29  e_gourgoulhon
00040  * Dummy argument in assignment.
00041  *
00042  * Revision 1.1  2002/04/09 14:40:36  e_gourgoulhon
00043  * Methods for new class MEos
00044  *
00045  *
00046  *
00047  * $Header: /cvsroot/Lorene/C++/Source/Eos/meos.C,v 1.4 2004/04/01 11:09:26 e_gourgoulhon Exp $
00048  *
00049  */
00050 
00051 // C headers
00052 #include <stdlib.h>
00053 
00054 // Lorene headers
00055 #include "headcpp.h"
00056 #include "eos.h"
00057 #include "utilitaires.h"
00058 #include "param.h"
00059 
00060 
00061                         //--------------------------------------//
00062                         //              Constructors            //
00063                         //--------------------------------------//
00064 
00065 MEos::MEos(int ndom_i, const Eos** mono_eos_i) : ndom(ndom_i) ,
00066                                constructed_from_file(false) {
00067 
00068 
00069         mono_eos = new const Eos* [ndom] ;
00070 
00071         for (int l=0; l<ndom; l++) {
00072                 mono_eos[l] =  mono_eos_i[l] ;
00073         }
00074 
00075 }
00076 
00077 
00078 MEos::MEos(const Eos& eos1, const Eos& eos2) : ndom(2) ,
00079                                constructed_from_file(false) {
00080 
00081         mono_eos = new const Eos* [ndom] ;
00082 
00083         mono_eos[0] = &eos1 ;
00084         mono_eos[1] = &eos2 ;
00085 
00086 }
00087 
00088 MEos::MEos(const Eos& eos1, const Eos& eos2, const Eos& eos3) : ndom(3) ,
00089                                constructed_from_file(false) {
00090 
00091         mono_eos = new const Eos* [ndom] ;
00092 
00093         mono_eos[0] = &eos1 ;
00094         mono_eos[1] = &eos2 ;
00095         mono_eos[2] = &eos3 ;
00096 
00097 }
00098 
00099 MEos::MEos(const Eos& eos1, const Eos& eos2, const Eos& eos3, const Eos& eos4) : ndom(4) ,
00100                                constructed_from_file(false) {
00101 
00102         mono_eos = new const Eos* [ndom] ;
00103 
00104         mono_eos[0] = &eos1 ;
00105         mono_eos[1] = &eos2 ;
00106         mono_eos[2] = &eos3 ;
00107         mono_eos[3] = &eos4 ;
00108 
00109 }
00110 
00111 // Copy constructor
00112 MEos::MEos(const MEos& meos) : Eos(),
00113                                ndom(meos.ndom),
00114                                constructed_from_file(false) {
00115 
00116         mono_eos = new const Eos* [ndom] ;
00117 
00118         for (int l=0; l<ndom; l++) {
00119                 mono_eos[l] =  meos.mono_eos[l] ;
00120         }
00121 
00122 }
00123 
00124 
00125 //  Constructor from a binary file
00126 MEos::MEos(FILE* fich) : Eos(fich), constructed_from_file(true) {
00127 
00128     fread_be(&ndom, sizeof(int), 1, fich) ;
00129 
00130     mono_eos = new const Eos* [ndom] ;
00131 
00132     for (int l=0; l<ndom; l++) {
00133         mono_eos[l] = Eos::eos_from_file(fich) ;
00134     }
00135 }
00136 
00137 //  Constructor from a formatted  file
00138 MEos::MEos(ifstream& fich) : Eos(fich),
00139                              constructed_from_file(true) {
00140 
00141     char blabla[80] ;
00142 
00143     fich >> ndom ; fich.getline(blabla, 80) ;
00144 
00145     mono_eos = new const Eos* [ndom] ;
00146 
00147     for (int l=0; l<ndom; l++) {
00148         mono_eos[l] = Eos::eos_from_file(fich) ;
00149     }
00150 }
00151 
00152 
00153 
00154 // Destructor
00155 MEos::~MEos() {
00156 
00157         if (constructed_from_file) {
00158                 for (int l=0; l<ndom; l++) {
00159                         delete mono_eos[l] ;
00160                 }
00161         }
00162 
00163         delete [] mono_eos ;
00164 
00165 }
00166 
00167             //--------------//
00168             //  Assignment  //
00169             //--------------//
00170 
00171 void MEos::operator=(const MEos& ) {
00172 
00173         cout << "MEos::operator=  : not implemented yet !" << endl ;
00174                 abort() ;
00175 
00176 }
00177 
00178 
00179                      //---------------------------------------//
00180                         //              Outputs                  //
00181                         //---------------------------------------//
00182 
00183 void MEos::sauve(FILE* fich) const {
00184 
00185     Eos::sauve(fich) ;
00186 
00187     fwrite_be(&ndom, sizeof(int), 1, fich) ;
00188 
00189     for (int l=0; l<ndom; l++) {
00190         mono_eos[l]->sauve(fich) ;
00191     }
00192 
00193 }
00194 
00195 ostream& MEos::operator>>(ostream & ost) const {
00196 
00197     ost << "EOS of class MEos (multi-domain equation of state) : " << endl ;
00198     ost << "   Number of domains :      " << ndom << endl ;
00199 
00200     for (int l=0; l<ndom; l++) {
00201         ost << "Equation of state in domain " << l << " : " << endl ;
00202         ost << "-------------------------------" << endl ; 
00203         ost << *(mono_eos[l]) ;
00204     }
00205 
00206     return ost ;
00207 
00208 }
00209 
00210             //------------------------//
00211             //  Comparison operators  //
00212             //------------------------//
00213 
00214 
00215 bool MEos::operator==(const Eos& eos_i) const {
00216 
00217     bool resu = true ;
00218 
00219     if ( eos_i.identify() != identify() ) {
00220     cout << "The second EOS is not of type MEos !" << endl ;
00221     resu = false ;
00222     }
00223     else{
00224 
00225     const MEos& eos = dynamic_cast<const MEos&>( eos_i ) ;
00226 
00227         if (eos.ndom != ndom) {
00228                 cout <<  "The two MEos have different number of domains" << endl ;
00229                 resu = false ;
00230 
00231         }
00232         else {
00233                 for (int l=0; l<ndom; l++) {
00234                         resu = resu && ( *(mono_eos[l]) == *(eos.mono_eos[l]) )  ;
00235                 }
00236         }
00237     }
00238 
00239     return resu ;
00240 
00241 }
00242 
00243 bool MEos::operator!=(const Eos& eos_i) const {
00244 
00245     return !(operator==(eos_i)) ;
00246 
00247 }
00248 
00249 
00250             //------------------------------//
00251             //    Computational routines    //
00252             //------------------------------//
00253 
00254 // Baryon density from enthalpy
00255 //------------------------------
00256 
00257 double MEos::nbar_ent_p(double ent, const Param* par) const {
00258 
00259         int l0 = par->get_int() ;        // index of the domain
00260 
00261         return mono_eos[l0]->nbar_ent_p(ent) ;
00262 
00263 }
00264 
00265 // Energy density from enthalpy
00266 //------------------------------
00267 
00268 double MEos::ener_ent_p(double ent, const Param* par) const {
00269 
00270         int l0 = par->get_int() ;        // index of the domain
00271 
00272         return mono_eos[l0]->ener_ent_p(ent) ;
00273 }
00274 
00275 // Pressure from enthalpy
00276 //------------------------
00277 
00278 double MEos::press_ent_p(double ent, const Param* par) const {
00279 
00280         int l0 = par->get_int() ;        // index of the domain
00281 
00282         return mono_eos[l0]->press_ent_p(ent) ;
00283 }
00284 
00285 // dln(n)/ln(H) from enthalpy
00286 //---------------------------
00287 
00288 double MEos::der_nbar_ent_p(double ent, const Param* par) const {
00289 
00290         int l0 = par->get_int() ;        // index of the domain
00291 
00292         return mono_eos[l0]->der_nbar_ent_p(ent) ;
00293 }
00294 
00295 // dln(e)/ln(H) from enthalpy
00296 //---------------------------
00297 
00298 double MEos::der_ener_ent_p(double ent, const Param* par) const {
00299 
00300         int l0 = par->get_int() ;        // index of the domain
00301 
00302         return mono_eos[l0]->der_ener_ent_p(ent) ;
00303 }
00304 
00305 // dln(p)/ln(H) from enthalpy
00306 //---------------------------
00307 
00308 double MEos::der_press_ent_p(double ent, const Param* par) const {
00309 
00310         int l0 = par->get_int() ;        // index of the domain
00311 
00312         return mono_eos[l0]->der_press_ent_p(ent) ;
00313 }
00314 
00315 
00316 

Generated on Tue Feb 7 01:35:18 2012 for LORENE by  doxygen 1.4.6