eos_poly.C

00001 /*
00002  * Methods of the class Eos_poly.
00003  *
00004  * (see file eos.h for documentation).
00005  */
00006 
00007 /*
00008  *   Copyright (c) 2000-2001 Eric Gourgoulhon
00009  *
00010  *   This file is part of LORENE.
00011  *
00012  *   LORENE is free software; you can redistribute it and/or modify
00013  *   it under the terms of the GNU General Public License as published by
00014  *   the Free Software Foundation; either version 2 of the License, or
00015  *   (at your option) any later version.
00016  *
00017  *   LORENE is distributed in the hope that it will be useful,
00018  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
00019  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00020  *   GNU General Public License for more details.
00021  *
00022  *   You should have received a copy of the GNU General Public License
00023  *   along with LORENE; if not, write to the Free Software
00024  *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00025  *
00026  */
00027 
00028 
00029 char eos_poly_C[] = "$Header: /cvsroot/Lorene/C++/Source/Eos/eos_poly.C,v 1.7 2009/05/25 06:52:27 k_taniguchi Exp $" ;
00030 
00031 /*
00032  * $Id: eos_poly.C,v 1.7 2009/05/25 06:52:27 k_taniguchi Exp $
00033  * $Log: eos_poly.C,v $
00034  * Revision 1.7  2009/05/25 06:52:27  k_taniguchi
00035  * Allowed the case of mu_0 != 1 for der_ener_ent_p and der_press_ent_p.
00036  *
00037  * Revision 1.6  2003/12/10 08:58:20  r_prix
00038  * - added new Eos_bifluid paramter for eos-file: bool slow_rot_style
00039  *  to indicate if we want this particular kind of EOS-inversion (only works for
00040  *  the  Newtonian 'analytic' polytropes) --> replaces former dirty hack with gamma1<0
00041  *
00042  * Revision 1.5  2002/10/16 14:36:35  j_novak
00043  * Reorganization of #include instructions of standard C++, in order to
00044  * use experimental version 3 of gcc.
00045  *
00046  * Revision 1.4  2002/04/11 13:28:40  e_gourgoulhon
00047  * Added the parameter mu_0
00048  *
00049  * Revision 1.3  2002/04/09 14:32:15  e_gourgoulhon
00050  * 1/ Added extra parameters in EOS computational functions (argument par)
00051  * 2/ New class MEos for multi-domain EOS
00052  *
00053  * Revision 1.2  2001/12/04 21:27:53  e_gourgoulhon
00054  *
00055  * All writing/reading to a binary file are now performed according to
00056  * the big endian convention, whatever the system is big endian or
00057  * small endian, thanks to the functions fwrite_be and fread_be
00058  *
00059  * Revision 1.1.1.1  2001/11/20 15:19:27  e_gourgoulhon
00060  * LORENE
00061  *
00062  * Revision 2.9  2001/02/23  15:17:30  eric
00063  * Methodes der_nbar_ent_p, der_ener_ent_p, der_press_ent_p :
00064  *   traitement du cas ent<1.e-13 par un DL
00065  *   continuite des quantites pour ent<=0.
00066  *
00067  * Revision 2.8  2001/02/07  09:50:30  eric
00068  * Suppression de la fonction derent_ent_p.
00069  * Ajout des fonctions donnant les derivees de l'EOS:
00070  *      der_nbar_ent_p
00071  *      der_ener_ent_p
00072  *      der_press_ent_p
00073  *
00074  * Revision 2.7  2000/06/20  08:34:46  eric
00075  * Ajout des fonctions get_gam(), etc...
00076  *
00077  * Revision 2.6  2000/02/14  14:49:34  eric
00078  * Modif affichage.
00079  *
00080  * Revision 2.5  2000/02/14  14:33:15  eric
00081  * Ajout du constructeur par lecture de fichier formate.
00082  *
00083  * Revision 2.4  2000/01/21  16:05:47  eric
00084  * Corrige erreur dans set_auxiliary: calcul de gam1.
00085  *
00086  * Revision 2.3  2000/01/21  15:18:45  eric
00087  * Ajout des operateurs de comparaison == et !=
00088  *
00089  * Revision 2.2  2000/01/18  14:26:37  eric
00090  * *** empty log message ***
00091  *
00092  * Revision 2.1  2000/01/18  13:47:17  eric
00093  * Premiere version operationnelle
00094  *
00095  * Revision 2.0  2000/01/18  10:46:28  eric
00096  * *** empty log message ***
00097  *
00098  *
00099  * $Header: /cvsroot/Lorene/C++/Source/Eos/eos_poly.C,v 1.7 2009/05/25 06:52:27 k_taniguchi Exp $
00100  *
00101  */
00102 
00103 // Headers C
00104 #include <stdlib.h>
00105 #include <string.h>
00106 #include <math.h>
00107 
00108 // Headers Lorene
00109 #include "eos.h"
00110 #include "cmp.h"
00111 #include "utilitaires.h"
00112 
00113             //--------------//
00114             // Constructors //
00115             //--------------//
00116 
00117 // Standard constructor with m_0 = 1 and mu_0 = 1
00118 // -----------------------------------------------
00119 Eos_poly::Eos_poly(double gam0, double kappa) : 
00120     Eos("Relativistic polytropic EOS"), 
00121     gam(gam0), kap(kappa), m_0(double(1)), mu_0(double(1)) {
00122 
00123     set_auxiliary() ; 
00124 
00125 }  
00126 
00127 // Standard constructor with mu_0 = 1
00128 // ----------------------------------
00129 Eos_poly::Eos_poly(double gam0, double kappa, double mass) :
00130     Eos("Relativistic polytropic EOS"),
00131     gam(gam0), kap(kappa), m_0(mass), mu_0(double(1)) {
00132 
00133     set_auxiliary() ;
00134 
00135 }
00136 
00137 // Standard constructor with mu_0 = 1
00138 // ----------------------------------
00139 Eos_poly::Eos_poly(double gam0, double kappa, double mass, double mu_zero) :
00140     Eos("Relativistic polytropic EOS"),
00141     gam(gam0), kap(kappa), m_0(mass), mu_0(mu_zero) {
00142 
00143     set_auxiliary() ;
00144 
00145 }
00146 
00147 // Copy constructor
00148 // ----------------
00149 Eos_poly::Eos_poly(const Eos_poly& eosi) : 
00150     Eos(eosi), 
00151     gam(eosi.gam), kap(eosi.kap), m_0(eosi.m_0), mu_0(eosi.mu_0) {
00152 
00153     set_auxiliary() ; 
00154 
00155 }  
00156   
00157 
00158 // Constructor from binary file
00159 // ----------------------------
00160 Eos_poly::Eos_poly(FILE* fich) : 
00161     Eos(fich) {
00162         
00163     fread_be(&gam, sizeof(double), 1, fich) ;       
00164     fread_be(&kap, sizeof(double), 1, fich) ;       
00165     fread_be(&m_0, sizeof(double), 1, fich) ;
00166 
00167     if (m_0 < 0) {       // to ensure compatibility with previous version (revision <= 1.2)
00168                         //  of Eos_poly
00169         m_0 = fabs( m_0 ) ;
00170         fread_be(&mu_0, sizeof(double), 1, fich) ;
00171     }
00172     else {
00173         mu_0 = double(1) ;
00174     }
00175 
00176     set_auxiliary() ; 
00177 
00178 }
00179 
00180 
00181 // Constructor from a formatted file
00182 // ---------------------------------
00183 Eos_poly::Eos_poly(ifstream& fich) : 
00184     Eos(fich) {
00185 
00186     char blabla[80] ;
00187         
00188     fich >> gam ; fich.getline(blabla, 80) ;
00189     fich >> kap ; fich.getline(blabla, 80) ;
00190     fich >> m_0 ; fich.getline(blabla, 80) ;
00191 
00192     if (m_0 < 0) {       // to ensure compatibility with previous version (revision <= 1.2)
00193                         //  of Eos_poly
00194         m_0 = fabs( m_0 ) ;
00195         fich >> mu_0 ; fich.getline(blabla, 80) ;
00196     }
00197     else {
00198         mu_0 = double(1) ;
00199     }
00200 
00201     set_auxiliary() ; 
00202 
00203 }
00204             //--------------//
00205             //  Destructor  //
00206             //--------------//
00207 
00208 Eos_poly::~Eos_poly(){
00209     
00210     // does nothing
00211         
00212 }
00213             //--------------//
00214             //  Assignment  //
00215             //--------------//
00216 
00217 void Eos_poly::operator=(const Eos_poly& eosi) {
00218     
00219     set_name(eosi.name) ; 
00220     
00221     gam = eosi.gam ; 
00222     kap = eosi.kap ; 
00223     m_0 = eosi.m_0 ;
00224     mu_0 = eosi.mu_0 ;
00225 
00226     set_auxiliary() ;
00227 
00228 }
00229 
00230 
00231           //-----------------------//
00232           //    Miscellaneous      //
00233           //-----------------------//
00234 
00235 void Eos_poly::set_auxiliary() {
00236 
00237     gam1 = gam - double(1) ;
00238 
00239     unsgam1 = double(1) / gam1 ;
00240 
00241     gam1sgamkap = m_0 * gam1 / (gam * kap) ;
00242 
00243     rel_mu_0 = mu_0 / m_0 ;
00244 
00245     ent_0 = log( rel_mu_0 ) ;
00246 
00247 }
00248 
00249 double Eos_poly::get_gam() const {
00250     return gam ;
00251 }
00252 
00253 double Eos_poly::get_kap() const {
00254     return kap ; 
00255 }
00256 
00257 double Eos_poly::get_m_0() const {
00258     return m_0 ;
00259 }
00260 
00261 double Eos_poly::get_mu_0() const {
00262     return mu_0 ;
00263 }
00264 
00265 
00266             //------------------------//
00267             //  Comparison operators  //
00268             //------------------------//
00269 
00270 
00271 bool Eos_poly::operator==(const Eos& eos_i) const {
00272     
00273     bool resu = true ; 
00274     
00275     if ( eos_i.identify() != identify() ) {
00276     cout << "The second EOS is not of type Eos_poly !" << endl ; 
00277     resu = false ; 
00278     }
00279     else{
00280     
00281     const Eos_poly& eos = dynamic_cast<const Eos_poly&>( eos_i ) ; 
00282 
00283     if (eos.gam != gam) {
00284         cout 
00285         << "The two Eos_poly have different gamma : " << gam << " <-> " 
00286         << eos.gam << endl ; 
00287         resu = false ; 
00288     }
00289 
00290     if (eos.kap != kap) {
00291         cout 
00292         << "The two Eos_poly have different kappa : " << kap << " <-> " 
00293         << eos.kap << endl ; 
00294         resu = false ; 
00295     }
00296 
00297     if (eos.m_0 != m_0) {
00298         cout
00299         << "The two Eos_poly have different m_0 : " << m_0 << " <-> "
00300         << eos.m_0 << endl ;
00301         resu = false ;
00302     }
00303 
00304     if (eos.mu_0 != mu_0) {
00305         cout
00306         << "The two Eos_poly have different mu_0 : " << mu_0 << " <-> "
00307         << eos.mu_0 << endl ;
00308         resu = false ;
00309     }
00310 
00311     }
00312     
00313     return resu ; 
00314     
00315 }
00316 
00317 bool Eos_poly::operator!=(const Eos& eos_i) const {
00318  
00319     return !(operator==(eos_i)) ; 
00320        
00321 }
00322 
00323 
00324             //------------//
00325             //  Outputs   //
00326             //------------//
00327 
00328 void Eos_poly::sauve(FILE* fich) const {
00329 
00330     Eos::sauve(fich) ; 
00331     
00332     fwrite_be(&gam, sizeof(double), 1, fich) ;  
00333     fwrite_be(&kap, sizeof(double), 1, fich) ;
00334     double tempo = - m_0 ;
00335     fwrite_be(&tempo, sizeof(double), 1, fich) ;
00336     fwrite_be(&mu_0, sizeof(double), 1, fich) ;
00337 
00338 }
00339 
00340 ostream& Eos_poly::operator>>(ostream & ost) const {
00341     
00342     ost << "EOS of class Eos_poly (relativistic polytrope) : " << endl ; 
00343     ost << "   Adiabatic index gamma :      " << gam << endl ; 
00344     ost << "   Pressure coefficient kappa : " << kap << 
00345        " rho_nuc c^2 / n_nuc^gamma" << endl ; 
00346     ost << "   Mean particle mass : " << m_0 << " m_B" << endl ;
00347     ost << "   Relativistic chemical potential at zero pressure : " << mu_0 << " m_B c^2" << endl ;
00348 
00349     return ost ;
00350 
00351 }
00352 
00353 
00354             //------------------------------//
00355             //    Computational routines    //
00356             //------------------------------//
00357 
00358 // Baryon density from enthalpy
00359 //------------------------------
00360 
00361 double Eos_poly::nbar_ent_p(double ent, const Param* ) const {
00362 
00363     if ( ent > ent_0 ) {
00364 
00365     return pow( gam1sgamkap * ( exp(ent) - rel_mu_0 ), unsgam1 ) ;
00366     }
00367     else{
00368     return 0 ;
00369     }
00370 }
00371 
00372 // Energy density from enthalpy
00373 //------------------------------
00374 
00375 double Eos_poly::ener_ent_p(double ent, const Param* ) const {
00376 
00377     if ( ent > ent_0 ) {
00378 
00379     double nn = pow( gam1sgamkap * ( exp(ent) - rel_mu_0 ),
00380                      unsgam1 ) ;
00381     double pp = kap * pow( nn, gam ) ;
00382 
00383     return  unsgam1 * pp + mu_0 * nn ;
00384     }
00385     else{
00386     return 0 ;
00387     }
00388 }
00389 
00390 // Pressure from enthalpy
00391 //------------------------
00392 
00393 double Eos_poly::press_ent_p(double ent, const Param* ) const {
00394 
00395     if ( ent > ent_0 ) {
00396 
00397     double nn = pow( gam1sgamkap * ( exp(ent) - rel_mu_0 ),
00398                      unsgam1 ) ;
00399 
00400     return kap * pow( nn, gam ) ;
00401 
00402     }
00403     else{
00404     return 0 ;
00405     }
00406 }
00407 
00408 // dln(n)/ln(H) from enthalpy
00409 //---------------------------
00410 
00411 double Eos_poly::der_nbar_ent_p(double ent, const Param* ) const {
00412 
00413     if ( ent > ent_0 ) {
00414 
00415 //## To be adapted
00416         if ( ent < 1.e-13  + ent_0 ) {
00417         return ( double(1) + ent/double(2) + ent*ent/double(12) ) / gam1 ;
00418     }
00419     else {
00420         return ent / (double(1) - rel_mu_0 * exp(-ent)) / gam1 ;
00421     }
00422     }
00423     else{
00424     return double(1) / gam1 ;   //  to ensure continuity at ent=0
00425     }
00426 }
00427 
00428 // dln(e)/ln(H) from enthalpy
00429 //---------------------------
00430 
00431 double Eos_poly::der_ener_ent_p(double ent, const Param* ) const {
00432 
00433     if ( ent > ent_0 ) {
00434 
00435 
00436     double nn = pow( gam1sgamkap * ( exp(ent) - rel_mu_0 ),
00437                      unsgam1 ) ;
00438 
00439     double pp = kap * pow( nn, gam ) ;
00440 
00441     double ee =  unsgam1 * pp + mu_0 * nn ;
00442 
00443 
00444     if ( ent < ent_0 + 1.e-13 ) {
00445         return ( double(1) + ent/double(2) + ent*ent/double(12) ) / gam1
00446         * ( double(1) + pp / ee) ;
00447     }
00448     else {
00449         return ent / (double(1) - rel_mu_0 * exp(-ent)) / gam1
00450         * ( double(1) + pp / ee) ;
00451     }
00452 
00453     }
00454     else{
00455     return double(1) / gam1 ;   //  to ensure continuity at ent=0
00456     }
00457 }
00458 
00459 // dln(p)/ln(H) from enthalpy
00460 //---------------------------
00461 
00462 double Eos_poly::der_press_ent_p(double ent, const Param* ) const {
00463     
00464     if ( ent > double(0) ) {
00465 
00466     if ( ent < ent_0 + 1.e-13 ) {
00467         return gam * ( double(1) + ent/double(2) + ent*ent/double(12) ) 
00468             / gam1 ;
00469     }
00470     else{
00471         return gam * ent / (double(1) - rel_mu_0 * exp(-ent)) / gam1 ;
00472     }
00473     }
00474     else{
00475     return gam / gam1 ; //  to ensure continuity at ent=0
00476     }
00477 }
00478 

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