eos_bf_poly.C

00001 /*
00002  * Methods of the class Eos_bf_poly.
00003  *
00004  * (see file eos_bifluid.h for documentation).
00005  */
00006 
00007 /*
00008  *   Copyright (c) 2001-2002 Jerome Novak
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_bf_poly_C[] = "$Header: /cvsroot/Lorene/C++/Source/Eos/eos_bf_poly.C,v 1.19 2008/08/19 06:42:00 j_novak Exp $" ;
00030 
00031 /*
00032  * $Id: eos_bf_poly.C,v 1.19 2008/08/19 06:42:00 j_novak Exp $
00033  * $Log: eos_bf_poly.C,v $
00034  * Revision 1.19  2008/08/19 06:42:00  j_novak
00035  * Minor modifications to avoid warnings with gcc 4.3. Most of them concern
00036  * cast-type operations, and constant strings that must be defined as const char*
00037  *
00038  * Revision 1.18  2004/05/13 15:27:42  r_prix
00039  * fixed a little eos-bug also in the relativistic case (same as done already in Newt)
00040  *
00041  * Revision 1.17  2003/12/17 23:12:32  r_prix
00042  * replaced use of C++ <string> by standard ANSI char* to be backwards compatible
00043  * with broken compilers like MIPSpro Compiler 7.2 on SGI Origin200. ;-)
00044  *
00045  * Revision 1.16  2003/12/10 08:58:20  r_prix
00046  * - added new Eos_bifluid paramter for eos-file: bool slow_rot_style
00047  *  to indicate if we want this particular kind of EOS-inversion (only works for
00048  *  the  Newtonian 'analytic' polytropes) --> replaces former dirty hack with gamma1<0
00049  *
00050  * Revision 1.15  2003/12/05 15:09:47  r_prix
00051  * adapted Eos_bifluid class and subclasses to use read_variable() for
00052  * (formatted) file-reading.
00053  *
00054  * Revision 1.14  2003/12/04 14:24:41  r_prix
00055  * a really dirty hack: gam1 < 0 signals to use 'slow-rot-style' EOS
00056  * inversion  (i.e. typeos=5). This only works for the 'analytic EOS'.
00057  *
00058  * Revision 1.13  2003/11/18 18:28:38  r_prix
00059  * moved particle-masses m_1, m_2 of the two fluids into class eos_bifluid (from eos_bf_poly)
00060  *
00061  * Revision 1.12  2003/03/17 10:28:04  j_novak
00062  * Removed too strong asserts on beta and kappa
00063  *
00064  * Revision 1.11  2003/02/07 10:47:43  j_novak
00065  * The possibility of having gamma5 xor gamma6 =0 has been introduced for
00066  * tests. The corresponding parameter files have been added.
00067  *
00068  * Revision 1.10  2002/10/16 14:36:34  j_novak
00069  * Reorganization of #include instructions of standard C++, in order to
00070  * use experimental version 3 of gcc.
00071  *
00072  * Revision 1.9  2002/05/31 16:13:36  j_novak
00073  * better inversion for eos_bifluid
00074  *
00075  * Revision 1.8  2002/05/10 09:26:52  j_novak
00076  * Added new class Et_rot_mag for magnetized rotating neutron stars (under development)
00077  *
00078  * Revision 1.7  2002/05/02 15:16:22  j_novak
00079  * Added functions for more general bi-fluid EOS
00080  *
00081  * Revision 1.6  2002/04/05 09:09:36  j_novak
00082  * The inversion of the EOS for 2-fluids polytrope has been modified.
00083  * Some errors in the determination of the surface were corrected.
00084  *
00085  * Revision 1.5  2002/01/16 15:03:28  j_novak
00086  * *** empty log message ***
00087  *
00088  * Revision 1.4  2002/01/11 14:09:34  j_novak
00089  * Added newtonian version for 2-fluid stars
00090  *
00091  * Revision 1.3  2001/12/04 21:27:53  e_gourgoulhon
00092  *
00093  * All writing/reading to a binary file are now performed according to
00094  * the big endian convention, whatever the system is big endian or
00095  * small endian, thanks to the functions fwrite_be and fread_be
00096  *
00097  * Revision 1.2  2001/11/29 15:05:26  j_novak
00098  * The entrainment term in 2-fluid eos is modified
00099  *
00100  * Revision 1.1.1.1  2001/11/20 15:19:27  e_gourgoulhon
00101  * LORENE
00102  *
00103  * Revision 1.4  2001/08/31  15:48:50  novak
00104  * The flag tronc has been added to nbar_ent_p
00105  *
00106  * Revision 1.3  2001/08/27 09:52:21  novak
00107  * New version of formulas
00108  *
00109  * Revision 1.2  2001/06/22 15:36:46  novak
00110  * Modification de trans2Eos
00111  *
00112  * Revision 1.1  2001/06/21 15:24:46  novak
00113  * Initial revision
00114  *
00115  *
00116  * $Header: /cvsroot/Lorene/C++/Source/Eos/eos_bf_poly.C,v 1.19 2008/08/19 06:42:00 j_novak Exp $
00117  *
00118  */
00119 
00120 // Headers C
00121 #include <stdlib.h>
00122 #include <math.h>
00123 
00124 // Headers Lorene
00125 #include "eos_bifluid.h"
00126 #include "param.h"
00127 #include "eos.h"
00128 #include "cmp.h"
00129 #include "utilitaires.h"
00130 
00131 //****************************************************************************
00132 // local prototypes
00133 double puis(double, double) ;
00134 double enthal1(const double x, const Param& parent) ;
00135 double enthal23(const double x, const Param& parent) ;
00136 double enthal(const double x, const Param& parent) ;      
00137 //****************************************************************************
00138 
00139             //--------------//
00140             // Constructors //
00141             //--------------//
00142 
00143 // Standard constructor with gam1 = gam2 = 2, 
00144 // gam3 = gam4 = gam5 = gam6 = 1, m_1 = 1 and m_2 =1
00145 // -------------------------------------------------
00146 Eos_bf_poly::Eos_bf_poly(double kappa1, double kappa2, double kappa3, double bet) :
00147   Eos_bifluid("bi-fluid polytropic EOS", 1, 1), 
00148   gam1(2), gam2(2),gam3(1),gam4(1),gam5(1),
00149   gam6(1),kap1(kappa1), kap2(kappa2), kap3(kappa3),beta(bet),
00150   relax(0.5), precis(1.e-9), ecart(1.e-8) 
00151 {
00152 
00153   determine_type() ;
00154   set_auxiliary() ; 
00155 
00156 }  
00157 
00158 // Standard constructor with everything specified
00159 // -----------------------------------------------
00160 Eos_bf_poly::Eos_bf_poly(double gamma1, double gamma2, double gamma3,
00161              double gamma4, double gamma5, double gamma6,
00162              double kappa1, double kappa2, double kappa3,
00163              double bet, double mass1, double mass2, 
00164              double rel, double prec, double ec) : 
00165   Eos_bifluid("bi-fluid polytropic EOS", mass1, mass2), 
00166   gam1(gamma1),gam2(gamma2),gam3(gamma3),gam4(gamma4),gam5(gamma5),
00167   gam6(gamma6),kap1(kappa1),kap2(kappa2),kap3(kappa3),beta(bet), 
00168   relax(rel), precis(prec), ecart(ec) 
00169 {
00170 
00171   determine_type() ;
00172   set_auxiliary() ; 
00173 
00174 }  
00175   
00176 // Copy constructor
00177 // ----------------
00178 Eos_bf_poly::Eos_bf_poly(const Eos_bf_poly& eosi) : 
00179     Eos_bifluid(eosi), 
00180     gam1(eosi.gam1), gam2(eosi.gam2), gam3(eosi.gam3),
00181     gam4(eosi.gam4), gam5(eosi.gam5), gam6(eosi.gam6),
00182     kap1(eosi.kap1), kap2(eosi.kap2), kap3(eosi.kap3),
00183     beta(eosi.beta),
00184         typeos(eosi.typeos), relax(eosi.relax), precis(eosi.precis),
00185         ecart(eosi.ecart) {
00186   
00187     set_auxiliary() ; 
00188 
00189 }  
00190   
00191 
00192 // Constructor from binary file
00193 // ----------------------------
00194 Eos_bf_poly::Eos_bf_poly(FILE* fich) : 
00195     Eos_bifluid(fich) {
00196         
00197     fread_be(&gam1, sizeof(double), 1, fich) ;      
00198     fread_be(&gam2, sizeof(double), 1, fich) ;      
00199     fread_be(&gam3, sizeof(double), 1, fich) ;      
00200     fread_be(&gam4, sizeof(double), 1, fich) ;      
00201     fread_be(&gam5, sizeof(double), 1, fich) ;      
00202     fread_be(&gam6, sizeof(double), 1, fich) ;      
00203     fread_be(&kap1, sizeof(double), 1, fich) ;      
00204     fread_be(&kap2, sizeof(double), 1, fich) ;      
00205     fread_be(&kap3, sizeof(double), 1, fich) ;      
00206     fread_be(&beta, sizeof(double), 1, fich) ;      
00207     fread_be(&relax, sizeof(double), 1, fich) ; 
00208     fread_be(&precis, sizeof(double), 1, fich) ;    
00209     fread_be(&ecart, sizeof(double), 1, fich) ; 
00210     
00211     determine_type() ;
00212     set_auxiliary() ; 
00213 
00214 
00215 }
00216 
00217 
00218 // Constructor from a formatted file
00219 // ---------------------------------
00220 Eos_bf_poly::Eos_bf_poly( char *fname ) : 
00221     Eos_bifluid(fname) 
00222 {
00223   int res = 0;
00224 
00225   res += read_variable (fname, const_cast<char*>("gamma1"), gam1);
00226   res += read_variable (fname, const_cast<char*>("gamma2"), gam2);
00227   res += read_variable (fname, const_cast<char*>("gamma3"), gam3);
00228   res += read_variable (fname, const_cast<char*>("gamma4"), gam4);
00229   res += read_variable (fname, const_cast<char*>("gamma5"), gam5);
00230   res += read_variable (fname, const_cast<char*>("gamma6"), gam6);
00231   res += read_variable (fname, const_cast<char*>("kappa1"), kap1);
00232   res += read_variable (fname, const_cast<char*>("kappa2"), kap2);
00233   res += read_variable (fname, const_cast<char*>("kappa3"), kap3);
00234   res += read_variable (fname, const_cast<char*>("beta"), beta);
00235 
00236 
00237   if (res != 0)
00238     {
00239       cerr << "ERROR: could not read all required eos-paramters for Eos_bf_poly()" << endl;
00240       exit (-1);
00241     }
00242 
00243   determine_type() ;
00244 
00245   if (get_typeos() == 4)
00246     {
00247     res += read_variable (fname, const_cast<char*>("relax"), relax);
00248     res += read_variable (fname, const_cast<char*>("precis"), precis);
00249     res += read_variable (fname, const_cast<char*>("ecart"), ecart);
00250     }
00251   else if (get_typeos() == 0) // analytic EOS: check if we want slow-rot-style inversion
00252     {
00253       bool slowrot = false;
00254       read_variable (fname, const_cast<char*>("slow_rot_style"), slowrot); // dont require this variable!
00255       if (slowrot)
00256     typeos = 5;  // type=5 is reserved for (type0 + slow-rot-style)
00257     }
00258 
00259 
00260   if (res != 0)
00261     {
00262       cerr << "ERROR: could not read all required eos-paramters for Eos_bf_poly()" << endl;
00263       exit (-1);
00264     }
00265 
00266 
00267   set_auxiliary() ; 
00268 
00269 }
00270             //--------------//
00271             //  Destructor  //
00272             //--------------//
00273 
00274 Eos_bf_poly::~Eos_bf_poly(){
00275   
00276   //Does nothing ...
00277         
00278 }
00279             //--------------//
00280             //  Assignment  //
00281             //--------------//
00282 
00283 void Eos_bf_poly::operator=(const Eos_bf_poly& eosi) {
00284     
00285   // Assignment of quantities common to all the derived classes of Eos_bifluid
00286   Eos_bifluid::operator=(eosi) ;        
00287     
00288     gam1 = eosi.gam1 ; 
00289     gam2 = eosi.gam2 ; 
00290     gam3 = eosi.gam3 ; 
00291     kap1 = eosi.kap1 ; 
00292     kap2 = eosi.kap2 ; 
00293     kap3 = eosi.kap3 ;
00294     beta = eosi.beta ;
00295     typeos = eosi.typeos ;
00296     relax = eosi.relax ;
00297     precis = eosi.precis ;
00298     ecart = eosi.ecart ;
00299     
00300     set_auxiliary() ; 
00301     
00302 }
00303 
00304 
00305           //-----------------------//
00306           //    Miscellaneous      //
00307           //-----------------------//
00308 
00309 void Eos_bf_poly::set_auxiliary() {
00310     
00311     gam1m1 = gam1 - double(1) ; 
00312     gam2m1 = gam2 - double(1) ; 
00313     gam34m1 = gam3 + gam4 - double(1) ; 
00314     gam56m1 = gam5 + gam6 - double(1) ;
00315 
00316     if (fabs(kap3*kap3-kap2*kap1) < 1.e-15) {
00317       cout << "WARNING!: Eos_bf_poly: the parameters are degenerate!" << endl ;
00318       abort() ;
00319     }
00320 
00321 }
00322 
00323 void Eos_bf_poly::determine_type() {
00324     
00325   if ((gam1 == double(2)) && (gam2 == double(2)) && (gam3 == double(1))
00326       && (gam4 == double(1)) && (gam5 == double(1)) 
00327       && (gam6 == double(0))) {
00328     typeos = -1 ;
00329     cout << "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" <<endl ;
00330     cout << "WARNING!! The entrainment factor does not depend on" <<endl ;
00331     cout << " density 2! This may be incorrect and should only be used"<<endl ;
00332     cout << " for testing purposes..." << endl ;
00333     cout << "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" <<endl ;
00334   }
00335   else if ((gam1 == double(2)) && (gam2 == double(2)) && (gam3 == double(1))
00336       && (gam4 == double(1)) && (gam5 == double(0)) 
00337       && (gam6 == double(1))) {
00338     typeos = -2 ;
00339     cout << "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" <<endl ;
00340     cout << "WARNING!! The entrainment factor does not depend on" << endl ;
00341     cout << " density 1! This may be incorrect and should only be used"<<endl ;
00342     cout << " for testing purposes..." << endl ;
00343     cout << "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" <<endl ;
00344   }
00345   else if ((gam1 == double(2)) && (gam2 == double(2)) && (gam3 == double(1))
00346       && (gam4 == double(1)) && (gam5 == double(1)) 
00347       && (gam6 == double(1))) {
00348     typeos = 0 ;
00349   }
00350   else if ((gam3 == double(1)) && (gam4 == double(1)) && (gam5 == double(1)) 
00351       && (gam6 == double(1))) {
00352     typeos = 1 ;
00353   }
00354   else if ((gam3 == double(1)) && (gam5 == double(1))) {
00355     typeos = 2 ;
00356   }
00357   else if ((gam4 == double(1)) && (gam6 == double(1))) {
00358     typeos = 3 ;
00359     return ;
00360   }
00361   else {
00362     typeos = 4 ;
00363   }
00364 
00365   cout << "DEBUG: EOS-type was determined as typeos = " << typeos << endl;
00366     
00367   return ;  
00368 }
00369 
00370             //------------------------//
00371             //  Comparison operators  //
00372             //------------------------//
00373 
00374 
00375 bool Eos_bf_poly::operator==(const Eos_bifluid& eos_i) const {
00376     
00377   bool resu = true ; 
00378     
00379   if ( eos_i.identify() != identify() ) {
00380     cout << "The second EOS is not of type Eos_bf_poly !" << endl ; 
00381     resu = false ; 
00382   }
00383   else{
00384     
00385     const Eos_bf_poly& eos = dynamic_cast<const Eos_bf_poly&>( eos_i ) ; 
00386     
00387     if ((eos.gam1 != gam1)||(eos.gam2 != gam2)||(eos.gam3 != gam3)
00388     ||(eos.gam4 != gam4)||(eos.gam5 != gam5)||(eos.gam6 != gam6)) {
00389       cout 
00390     << "The two Eos_bf_poly have different gammas : " << gam1 << " <-> " 
00391     << eos.gam1 << ", " << gam2 << " <-> " 
00392     << eos.gam2 << ", " << gam3 << " <-> " 
00393     << eos.gam3 << ", " << gam4 << " <-> " 
00394     << eos.gam4 << ", " << gam5 << " <-> " 
00395     << eos.gam5 << ", " << gam6 << " <-> " 
00396     << eos.gam6 << endl ; 
00397       resu = false ; 
00398     }
00399     
00400     if ((eos.kap1 != kap1)||(eos.kap2 != kap2)|| (eos.kap3 != kap3)){
00401       cout 
00402     << "The two Eos_bf_poly have different kappas : " << kap1 << " <-> " 
00403     << eos.kap1 << ", " << kap2 << " <-> " 
00404     << eos.kap2 << ", " << kap3 << " <-> " 
00405     << eos.kap3 << endl ; 
00406       resu = false ; 
00407     }
00408     
00409     if (eos.beta != beta) {
00410       cout 
00411     << "The two Eos_bf_poly have different betas : " << beta << " <-> " 
00412     << eos.beta << endl ; 
00413       resu = false ; 
00414     }
00415 
00416     if ((eos.m_1 != m_1)||(eos.m_2 != m_2)) {
00417       cout 
00418     << "The two Eos_bf_poly have different masses : " << m_1 << " <-> " 
00419     << eos.m_1 << ", " << m_2 << " <-> " 
00420     << eos.m_2 << endl ; 
00421       resu = false ; 
00422     }
00423     
00424   }
00425   
00426   return resu ; 
00427   
00428 }
00429 
00430 bool Eos_bf_poly::operator!=(const Eos_bifluid& eos_i) const {
00431  
00432     return !(operator==(eos_i)) ; 
00433        
00434 }
00435 
00436 
00437             //------------//
00438             //  Outputs   //
00439             //------------//
00440 
00441 void Eos_bf_poly::sauve(FILE* fich) const {
00442 
00443     Eos_bifluid::sauve(fich) ; 
00444     
00445     fwrite_be(&gam1, sizeof(double), 1, fich) ; 
00446     fwrite_be(&gam2, sizeof(double), 1, fich) ; 
00447     fwrite_be(&gam3, sizeof(double), 1, fich) ; 
00448     fwrite_be(&gam4, sizeof(double), 1, fich) ; 
00449     fwrite_be(&gam5, sizeof(double), 1, fich) ; 
00450     fwrite_be(&gam6, sizeof(double), 1, fich) ; 
00451     fwrite_be(&kap1, sizeof(double), 1, fich) ; 
00452     fwrite_be(&kap2, sizeof(double), 1, fich) ; 
00453     fwrite_be(&kap3, sizeof(double), 1, fich) ; 
00454     fwrite_be(&beta, sizeof(double), 1, fich) ; 
00455     fwrite_be(&relax, sizeof(double), 1, fich) ;
00456     fwrite_be(&precis, sizeof(double), 1, fich) ;
00457     fwrite_be(&ecart, sizeof(double), 1, fich) ;
00458    
00459 }
00460 
00461 ostream& Eos_bf_poly::operator>>(ostream & ost) const {
00462     
00463     ost << "EOS of class Eos_bf_poly (relativistic polytrope) : " << endl ; 
00464     ost << "   Adiabatic index gamma1 :      " << gam1 << endl ; 
00465     ost << "   Adiabatic index gamma2 :      " << gam2 << endl ; 
00466     ost << "   Adiabatic index gamma3 :      " << gam3 << endl ; 
00467     ost << "   Adiabatic index gamma4 :      " << gam4 << endl ; 
00468     ost << "   Adiabatic index gamma5 :      " << gam5 << endl ; 
00469     ost << "   Adiabatic index gamma6 :      " << gam6 << endl ; 
00470     ost << "   Pressure coefficient kappa1 : " << kap1 << 
00471        " rho_nuc c^2 / n_nuc^gamma" << endl ; 
00472     ost << "   Pressure coefficient kappa2 : " << kap2 << 
00473        " rho_nuc c^2 / n_nuc^gamma" << endl ; 
00474     ost << "   Pressure coefficient kappa3 : " << kap3 << 
00475        " rho_nuc c^2 / n_nuc^gamma" << endl ; 
00476     ost << "   Coefficient beta : " << beta << 
00477        " rho_nuc c^2 / n_nuc^gamma" << endl ; 
00478     ost << "   Type for inversion : " << typeos << endl ;
00479     ost << "   Parameters for inversion (used if typeos = 4) : " << endl ;
00480     ost << "   relaxation : " << relax << endl ;
00481     ost << "   precision for zerosec_b : " << precis << endl ;
00482     ost << "   final discrepancy in the result : " << ecart << endl ;
00483     
00484     return ost ;
00485 
00486 }
00487 
00488 
00489             //------------------------------//
00490             //    Computational routines    //
00491             //------------------------------//
00492 
00493 // Baryon densities from enthalpies 
00494 //---------------------------------
00495 
00496 bool Eos_bf_poly::nbar_ent_p(const double ent1, const double ent2, 
00497                   const double delta2, double& nbar1, 
00498                   double& nbar2) const {  
00499 
00500   // RP: follow Newtonian case in this: the following is wrong, I think
00501   //  bool one_fluid = ((ent1<=0.)||(ent2<=0.)) ;
00502 
00503   bool one_fluid = false;
00504 
00505   if (!one_fluid) {
00506     switch (typeos) {
00507     case 5:  // same as typeos=0 but with slow-rot-style inversion
00508     case 0: {
00509       double kpd = kap3+beta*delta2 ;
00510       double determ = kap1*kap2 - kpd*kpd ;
00511     
00512       nbar1 = (kap2*(exp(ent1) - m_1) - kpd*(exp(ent2) - m_2)) / determ ;
00513       nbar2 = (kap1*(exp(ent2) - m_2) - kpd*(exp(ent1) - m_1)) / determ ;
00514       one_fluid = ((nbar1 < 0.)||(nbar2 < 0.)) ;
00515       break ;
00516     }
00517     case 1: {
00518       double b1 = exp(ent1) - m_1 ;
00519       double b2 = exp(ent2) - m_2 ;
00520       double denom = kap3 + beta*delta2 ;
00521       if (fabs(denom) < 1.e-15) {
00522     nbar1 = puis(2*b1/(gam1*kap1), 1./gam1m1) ;
00523     nbar2 = puis(2*b2/(gam2*kap2), 1./gam2m1) ;
00524     one_fluid = ((nbar1 < 0.)||(nbar2 < 0.)) ;
00525       }
00526       else {
00527     double coef0 = 0.5*gam2*kap2/pow(denom, gam2m1) ;
00528     double coef1 = 0.5*kap1*gam1 ;
00529     Param parent ;
00530     parent.add_double(coef0, 0) ;
00531     parent.add_double(b1, 1) ;
00532     parent.add_double(coef1, 2) ;
00533     parent.add_double(gam1m1,3) ;
00534     parent.add_double(gam2m1,4) ;
00535     parent.add_double(denom, 5) ;
00536     parent.add_double(b2, 6) ;
00537 
00538     double xmin, xmax ;
00539     double f0 = enthal1(0.,parent) ;
00540     if (fabs(f0)<1.e-15) {
00541       nbar1 = 0. ;}
00542     else {
00543       double cas = (gam1m1*gam2m1 - 1.)*f0;
00544       assert (fabs(cas) > 1.e-15) ;
00545       xmin = 0. ;
00546       xmax = cas/fabs(cas) ;
00547       do {
00548         xmax *= 1.1 ;
00549         if (fabs(xmax) > 1.e10) {
00550           cout << "Problem in Eos_bf_poly::nbar_ent_p!" << endl ;
00551           cout << f0 << ", " << cas << endl ; // to be removed!!
00552           cout << "typeos = 1" << endl ;
00553           abort() ;
00554         }
00555       } while (enthal1(xmax,parent)*f0 > 0.) ;
00556       double l_precis = 1.e-12 ;
00557       int nitermax = 400 ;
00558       int niter = 0 ;
00559       nbar1 = zerosec_b(enthal1, parent, xmin, xmax, l_precis, 
00560                 nitermax, niter) ;
00561     }
00562     nbar2 = (b1 - coef1*puis(nbar1, gam1m1))/denom ;
00563     double resu1 = coef1*puis(nbar1,gam1m1) + denom*nbar2 ;
00564     double resu2 = 0.5*gam2*kap2*puis(nbar2,gam2m1) + denom*nbar1 ;
00565     double erreur = fabs((log(fabs(1+resu1))-ent1)/ent1) + 
00566       fabs((log(fabs(1+resu2))-ent2)/ent2) ;
00567     one_fluid = ((nbar1 < 0.)||(nbar2 < 0.)||(erreur > 1.e-4)) ;
00568       }
00569       break ;
00570     }
00571     case 2: {
00572       double b1 = exp(ent1) - m_1 ;
00573       double b2 = exp(ent2) - m_2 ;
00574       double denom = kap3 + beta*delta2 ;
00575       if (fabs(denom) < 1.e-15) {
00576     nbar1 = puis(2*b1/(gam1*kap1), 1./gam1m1) ;
00577     nbar2 = puis(2*b2/(gam2*kap2), 1./gam2m1) ;
00578     one_fluid = ((nbar1 < 0.)||(nbar2 < 0.)) ;
00579       }
00580       else {
00581     double coef0 = beta*delta2 ;
00582     double coef1 = 0.5*kap1*gam1 ;
00583     double coef2 = 0.5*kap2*gam2 ;
00584     double coef3 = 1./gam1m1 ;
00585     Param parent ;
00586     parent.add_double(b1, 0) ;
00587     parent.add_double(kap3, 1) ;
00588     parent.add_double(gam4, 2) ;
00589     parent.add_double(coef0, 3) ;
00590     parent.add_double(gam6,4) ;
00591     parent.add_double(coef1, 5) ;
00592     parent.add_double(coef3, 6) ;
00593     parent.add_double(coef2, 7) ;
00594     parent.add_double(gam2m1, 8) ;
00595     parent.add_double(b2, 9) ;
00596 
00597     double xmin, xmax ;
00598     double f0 = enthal23(0.,parent) ;
00599     if (fabs(f0)<1.e-15) {
00600       nbar2 = 0. ;}
00601     else {
00602       double pmax = (fabs(kap3) < 1.e-15 ? 0. : gam4*(gam4-1) ) ;
00603       double ptemp = (fabs(kap3*coef0) < 1.e-15  ? 0. 
00604               : gam6*(gam4-1) ) ;
00605       pmax = (pmax>ptemp ? pmax : ptemp) ;
00606       ptemp = (fabs(kap3*coef0) < 1.e-15 ? 0. : gam4*(gam6-1) ) ;
00607       pmax = (pmax>ptemp ? pmax : ptemp) ;
00608       ptemp = (fabs(coef0) < 1.e-15 ? 0. : gam6*(gam6-1) ) ;
00609       pmax = (pmax>ptemp ? pmax : ptemp) ;
00610       double cas = (pmax - gam1m1*gam2m1)*f0;
00611       //      cout << "Pmax, cas: " << pmax << ", " << cas << endl ;
00612       assert (fabs(cas) > 1.e-15) ;
00613       xmin = 0. ;
00614       xmax = cas/fabs(cas) ;
00615       do {
00616         xmax *= 1.1 ;
00617         if (fabs(xmax) > 1.e10) {
00618           cout << "Problem in Eos_bf_poly::nbar_ent_p!" << endl ;
00619           cout << "typeos = 2" << endl ;
00620           abort() ;
00621         }
00622       } while (enthal23(xmax,parent)*f0 > 0.) ;
00623       double l_precis = 1.e-12 ;
00624       int nitermax = 400 ;
00625       int niter = 0 ;
00626       nbar2 = zerosec_b(enthal23, parent, xmin, xmax, l_precis, 
00627                 nitermax, niter) ;
00628     }
00629     nbar1 = (b1 - kap3*puis(nbar2,gam4) - coef0*puis(nbar2,gam6))
00630       / coef1 ;
00631     nbar1 = puis(nbar1,coef3) ;
00632     double resu1 = coef1*puis(nbar1,gam1m1) + kap3*puis(nbar2,gam4)
00633       + coef0*puis(nbar2, gam6) ;
00634     double resu2 = coef2*puis(nbar2,gam2m1) 
00635       + gam4*kap3*puis(nbar2, gam4-1)*nbar1
00636       + gam6*coef0*puis(nbar2, gam6-1)*nbar1 ;
00637     double erreur = fabs((log(fabs(1+resu1))-ent1)/ent1) + 
00638       fabs((log(fabs(1+resu2))-ent2)/ent2) ;
00639     //cout << "Erreur d'inversion: " << erreur << endl ;
00640     one_fluid = ((nbar1 < 0.)||(nbar2 < 0.)||(erreur > 1.e-4)) ;
00641       }
00642       break ;
00643     }
00644     case 3: {
00645       double b1 = exp(ent1) - m_1 ;
00646       double b2 = exp(ent2) - m_2 ;
00647       double denom = kap3 + beta*delta2 ;
00648       if (fabs(denom) < 1.e-15) {
00649     nbar1 = puis(2*b1/(gam1*kap1), 1./gam1m1) ;
00650     nbar2 = puis(2*b2/(gam2*kap2), 1./gam2m1) ;
00651     one_fluid = ((nbar1 < 0.)||(nbar2 < 0.)) ;
00652       }
00653       else {
00654     double coef0 = beta*delta2 ;
00655     double coef1 = 0.5*kap1*gam1 ;
00656     double coef2 = 0.5*kap2*gam2 ;
00657     double coef3 = 1./gam2m1 ;
00658     Param parent ;
00659     parent.add_double(b2, 0) ;
00660     parent.add_double(kap3, 1) ;
00661     parent.add_double(gam3, 2) ;
00662     parent.add_double(coef0, 3) ;
00663     parent.add_double(gam5, 4) ;
00664     parent.add_double(coef2, 5) ;
00665     parent.add_double(coef3, 6) ;
00666     parent.add_double(coef1, 7) ;
00667     parent.add_double(gam1m1, 8) ;
00668     parent.add_double(b1, 9) ;
00669     
00670     double xmin, xmax ;
00671     double f0 = enthal23(0.,parent) ;
00672     if (fabs(f0)<1.e-15) {
00673       nbar1 = 0. ;}
00674     else {
00675       double pmax = (fabs(kap3) < 1.e-15 ? 0. : gam3*(gam3-1) ) ;
00676       double ptemp = (fabs(kap3*coef0) < 1.e-15  ? 0. 
00677               : gam5*(gam3-1) ) ;
00678       pmax = (pmax>ptemp ? pmax : ptemp) ;
00679       ptemp = (fabs(kap3*coef0) < 1.e-15 ? 0. : gam3*(gam5-1) ) ;
00680       pmax = (pmax>ptemp ? pmax : ptemp) ;
00681       ptemp = (fabs(coef0) < 1.e-15 ? 0. : gam5*(gam5-1) ) ;
00682       pmax = (pmax>ptemp ? pmax : ptemp) ;
00683       double cas = (pmax - gam1m1*gam2m1)*f0;
00684       //      cout << "Pmax, cas: " << pmax << ", " << cas << endl ;
00685       assert (fabs(cas) > 1.e-15) ;
00686       xmin = 0. ;
00687       xmax = cas/fabs(cas) ;
00688       do {
00689         xmax *= 1.1 ;
00690         if (fabs(xmax) > 1.e10) {
00691           cout << "Problem in Eos_bf_poly::nbar_ent_p!" << endl ;
00692           cout << "typeos = 3" << endl ;
00693           abort() ;
00694         }
00695       } while (enthal23(xmax,parent)*f0 > 0.) ;
00696       double l_precis = 1.e-12 ;
00697       int nitermax = 400 ;
00698       int niter = 0 ;
00699       nbar1 = zerosec_b(enthal23, parent, xmin, xmax, l_precis, 
00700                 nitermax, niter) ;
00701     }
00702     nbar2 = (b2 - kap3*puis(nbar1,gam3) - coef0*puis(nbar1,gam5))
00703       / coef2 ;
00704     nbar2 = puis(nbar2,coef3) ;
00705     double resu1 = coef1*puis(nbar1,gam1m1) 
00706       + gam3*kap3*puis(nbar1,gam3-1)*nbar2
00707       + coef0*gam5*puis(nbar1, gam5-1)*nbar2 ;
00708     double resu2 = coef2*puis(nbar2,gam2m1) 
00709       + kap3*puis(nbar1, gam3) + coef0*puis(nbar1, gam5);
00710     double erreur = fabs((log(fabs(1+resu1))-ent1)/ent1) + 
00711       fabs((log(fabs(1+resu2))-ent2)/ent2) ;
00712     one_fluid = ((nbar1 < 0.)||(nbar2 < 0.)||(erreur > 1.e-4)) ;
00713       }
00714       break ;
00715     }    
00716     case 4:{
00717       double b1 = exp(ent1) - m_1 ; 
00718       double b2 = exp(ent2) - m_2 ; 
00719       double denom = kap3 + beta*delta2 ;
00720       if (fabs(denom) < 1.e-15) {
00721     nbar1 = puis(2*b1/(gam1*kap1), 1./gam1m1) ;
00722     nbar2 = puis(2*b2/(gam2*kap2), 1./gam2m1) ;
00723     one_fluid = ((nbar1 < 0.)||(nbar2 < 0.)) ;
00724       }
00725       else {
00726     int nitermax = 200 ;
00727     int niter = 0 ;
00728     int nmermax = 800 ;
00729     
00730     double a11 = 0.5*gam1*kap1 ;
00731     double a13 = gam3*kap3 ;
00732     double a14 = beta*gam5*delta2 ;
00733     
00734     double a22 = 0.5*gam2*kap2 ;
00735     double a23 = gam4*kap3 ;
00736     double a24 = beta*gam6*delta2 ;
00737     
00738     double n1l, n2l, n1s, n2s ;
00739     
00740     double delta = a11*a22 - (a13+a14)*(a23+a24) ;
00741     n1l = (a22*b1 - (a13+a14)*b2)/delta ;
00742     n2l = (a11*b2 - (a23+a24)*b1)/delta ;
00743     n1s = puis(b1/a11, 1./(gam1m1)) ;
00744     n2s = puis(b2/a22, 1./(gam2m1)) ;
00745     
00746     double n1m = (n1l<0. ? n1s : sqrt(n1l*n1s)) ;
00747     double n2m = (n2l<0. ? n2s : sqrt(n2l*n2s)) ;
00748     
00749     Param parf1 ;
00750     Param parf2 ;
00751     double c1, c2, c3, c4, c5, c6, c7 ;
00752     c1 = gam1m1 ;
00753     c2 = gam3 - 1. ;
00754     c3 = gam5 - 1. ;
00755     c4 = a11 ;
00756     c5 = a13*puis(n2m,gam4) ;
00757     c6 = a14*puis(n2m,gam6) ;
00758     c7 = b1 ; 
00759     parf1.add_double_mod(c1,0) ;
00760     parf1.add_double_mod(c2,1) ;
00761     parf1.add_double_mod(c3,2) ;
00762     parf1.add_double_mod(c4,3) ;
00763     parf1.add_double_mod(c5,4) ;
00764     parf1.add_double_mod(c6,5) ;
00765     parf1.add_double_mod(c7,6) ;
00766     
00767     double d1, d2, d3, d4, d5, d6, d7 ;
00768     d1 = gam2m1 ;
00769     d2 = gam4 - 1. ;
00770     d3 = gam6 - 1. ;
00771     d4 = a22 ;
00772     d5 = a23*puis(n1m,gam3) ;
00773     d6 = a24*puis(n1m,gam5) ;
00774     d7 = b2 ; 
00775     parf2.add_double_mod(d1,0) ;
00776     parf2.add_double_mod(d2,1) ;
00777     parf2.add_double_mod(d3,2) ;
00778     parf2.add_double_mod(d4,3) ;
00779     parf2.add_double_mod(d5,4) ;
00780     parf2.add_double_mod(d6,5) ;
00781     parf2.add_double_mod(d7,6) ;
00782     
00783     double xmin = -3*(n1s>n2s ? n1s : n2s) ;
00784     double xmax = 3*(n1s>n2s ? n1s : n2s) ;
00785     
00786     double n1 = n1m ;
00787     double n2 = n2m ;
00788     bool sortie = true ;
00789     int mer = 0 ;
00790     
00791     //cout << "Initial guess: " << n1 << ", " << n2 << endl ;
00792     n1s *= 0.1 ;
00793     n2s *= 0.1 ;
00794     do {
00795       //cout << "n1, n2: " << n1 << ", " << n2 << endl ;
00796       n1 = zerosec_b(&enthal, parf1, xmin, xmax, precis, nitermax, niter) ;
00797       n2 = zerosec_b(&enthal, parf2, xmin, xmax, precis, nitermax, niter) ;
00798       
00799       sortie = (fabs((n1m-n1)/(n1m+n1)) + fabs((n2m-n2)/(n2m+n2)) > ecart) ;
00800       n1m = relax*n1 + (1.-relax)*n1m ;
00801       n2m = relax*n2 + (1.-relax)*n2m ;
00802       if (n2m>-n2s) {
00803         parf1.get_double_mod(4) = a13*puis(n2m,gam4) ;
00804         parf1.get_double_mod(5) = a14*puis(n2m,gam6) ;
00805       }
00806       else {
00807         parf1.get_double_mod(4) = a13*puis(-n2s,gam4) ;
00808         parf1.get_double_mod(5) = a14*puis(-n2s,gam6) ;
00809       }
00810       
00811       if (n1m>-n1s) {
00812         parf2.get_double_mod(4) = a23*puis(n1m,gam3) ;
00813         parf2.get_double_mod(5) = a24*puis(n1m,gam5) ;
00814       }
00815       else {
00816         parf2.get_double_mod(4) = a23*puis(-n1s,gam3) ;
00817         parf2.get_double_mod(5) = a24*puis(-n1s,gam5) ;
00818       }
00819       
00820       mer++ ;
00821     } while (sortie&&(mer<nmermax)) ;
00822     nbar1 = n1m ;
00823     nbar2 = n2m ;
00824     
00825 //      double resu1 = a11*puis(n1,gam1m1) + a13*puis(n1,gam3-1.)*puis(n2,gam4)
00826 //        +a14*puis(n1,gam5-1.)*puis(n2,gam6) ;
00827 //      double resu2 = a22*puis(n2,gam2m1) + a23*puis(n1,gam3)*puis(n2,gam4-1.)
00828 //        +a24*puis(n1,gam5)*puis(n2,gam6-1.) ;
00829     //cout << "Nbre d'iterations: " << mer << endl ;
00830     //cout << "Resus: " << n1m << ", " << n2m << endl ;
00831     //cout << "Verification: " << log(fabs(1+resu1)) << ", " 
00832     //     << log(fabs(1+resu2)) << endl ; 
00833     //    cout << "Erreur: " << fabs(enthal(n1, parf1)/b1) + 
00834     //      fabs(enthal(n2, parf2)/b2) << endl ;
00835     //cout << "Erreur: " << fabs((log(fabs(1+resu1))-ent1)/ent1) + 
00836     //fabs((log(fabs(1+resu2))-ent2)/ent2) << endl ;
00837       }
00838       break ;
00839     }
00840     case -1: {
00841       double determ = kap1*kap2 - kap3*kap3 ;
00842     
00843       nbar1 = (kap2*(exp(ent1) - m_1 - beta*delta2) 
00844            - kap3*(exp(ent2) - m_2)) / determ ;
00845       nbar2 = (kap1*(exp(ent2) - m_2) - kap3*(exp(ent1) - m_1 - beta*delta2))
00846     / determ ;
00847       one_fluid = ((nbar1 < 0.)||(nbar2 < 0.)) ;
00848       break ;
00849     }
00850     case -2: {
00851       double determ = kap1*kap2 - kap3*kap3 ;
00852     
00853       nbar1 = (kap2*(exp(ent1) - m_1 ) 
00854            - kap3*(exp(ent2) - m_2 - beta*delta2)) / determ ;
00855       nbar2 = (kap1*(exp(ent2) - m_2 - beta*delta2) 
00856            - kap3*(exp(ent1) - m_1)) / determ ;
00857       one_fluid = ((nbar1 < 0.)||(nbar2 < 0.)) ;
00858       break ;
00859     }
00860     }
00861   }
00862   return one_fluid ;
00863 }
00864 // One fluid sub-EOSs
00865 //-------------------
00866 
00867 double Eos_bf_poly::nbar_ent_p1(const double ent1) const {
00868   return puis(2*(exp(ent1) - m_1)/(gam1*kap1), 1./gam1m1) ;
00869 }
00870 
00871 double Eos_bf_poly::nbar_ent_p2(const double ent2) const {
00872   return puis(2*(exp(ent2) - m_2)/(gam2*kap2), 1./gam2m1) ;
00873 }
00874 
00875 // Energy density from baryonic densities
00876 //---------------------------------------
00877 
00878 double Eos_bf_poly::ener_nbar_p(const double nbar1, const double nbar2, 
00879                 const double delta2) const {
00880     
00881     if (( nbar1 > double(0) ) || ( nbar2 > double(0))) {
00882       
00883       double n1 = (nbar1>double(0) ? nbar1 : double(0)) ;
00884       double n2 = (nbar2>double(0) ? nbar2 : double(0)) ;
00885       double x2 = ((nbar1>double(0))&&(nbar2>double(0))) ? delta2 : 0 ;
00886 
00887       double resu = 0.5*kap1*pow(n1, gam1) + 0.5*kap2*pow(n2,gam2)
00888     + kap3*pow(n1,gam3)*pow(n2,gam4) + m_1*n1 + m_2*n2
00889     + x2*beta*pow(n1,gam5)*pow(n2,gam6) ;
00890       return resu ;
00891     }
00892     else return 0 ;
00893 }
00894 
00895 // Pressure from baryonic densities
00896 //---------------------------------
00897 
00898 double Eos_bf_poly::press_nbar_p(const double nbar1, const double nbar2,
00899                 const double delta2) const {
00900     
00901   if (( nbar1 > double(0) ) || ( nbar2 > double(0))) {
00902     
00903     double n1 = (nbar1>double(0) ? nbar1 : double(0)) ;
00904     double n2 = (nbar2>double(0) ? nbar2 : double(0)) ;
00905     double x2 = ((nbar1>double(0))&&(nbar2>double(0))) ? delta2 : 0 ;
00906     
00907     double resu = 0.5*gam1m1*kap1*pow(n1,gam1) + 0.5*gam2m1*kap2*pow(n2,gam2)
00908       + gam34m1*kap3*pow(n1,gam3)*pow(n2,gam4) + 
00909       x2*gam56m1*beta*pow(n1,gam5)*pow(n2,gam6) ;
00910     
00911     return resu ;
00912   }
00913   else return 0 ;
00914 }
00915 
00916 // Derivatives of energy
00917 //----------------------
00918 
00919 double Eos_bf_poly::get_K11(const double n1, const double n2, const
00920                    double delta2)  const 
00921 {
00922   double xx ;
00923   if (n1 <= 0.) {
00924     xx = 0. ;
00925   }
00926   else {
00927     xx = 0.5*gam1*kap1 * pow(n1,gam1 - 2) + m_1/n1 + 
00928       gam3*kap3 * pow(n1,gam3 - 2) * pow(n2,gam4) + 
00929       (delta2*(gam5 + 2) - 2)*beta * pow(n1,gam5 - 2)*pow(n2, gam6) ;
00930   }
00931   return xx ;
00932 }
00933 
00934 double Eos_bf_poly::get_K22(const double n1, const double n2, const
00935                    double delta2) const  
00936 {
00937   double xx ;
00938   if (n2 <= 0.) {
00939     xx = 0. ;
00940   }
00941   else {
00942     xx = 0.5*gam2*kap2 * pow(n2,gam2 - 2) + m_2/n2 + 
00943       gam4*kap3 * pow(n2,gam4 - 2) * pow(n1,gam3) + 
00944       (delta2*(gam6 + 2) - 2)*beta * pow(n1, gam5) * pow(n2,gam6 - 2) ;
00945   }
00946   return xx ;
00947 }
00948 
00949 double Eos_bf_poly::get_K12(const double n1, const double n2, const
00950                    double delta2) const  
00951 {
00952   double xx ;
00953   if ((n1 <= 0.) || (n2 <= 0.)) { xx = 0.; }
00954   else { 
00955     double gamma_delta3 = pow(1-delta2,-1.5) ;
00956     xx = 2*beta*pow(n1,gam5-1)*pow(n2,gam6-1) / gamma_delta3 ;
00957   }
00958   return xx ;
00959 }
00960 
00961 // Conversion functions
00962 // ---------------------
00963 
00964 Eos* Eos_bf_poly::trans2Eos() const {
00965 
00966   Eos_poly* eos_simple = new Eos_poly(gam1, kap1, m_1) ;
00967   return eos_simple ;
00968 }
00969 /***************************************************************************
00970  *
00971  *                         Non-class functions
00972  *
00973  ***************************************************************************/
00974 
00975 // New "pow"
00976 //-----------
00977 
00978  double puis(double x, double p) {
00979   assert(p>=0.) ;
00980   if (p==0.) return (x>=0 ? 1 : -1) ;
00981   //if (p==0.) return 1 ;
00982   if (x<0.) return (-pow(-x,p)) ;
00983   else return pow(x,p) ;
00984 }
00985 
00986 // Auxilliary functions for nbar_ent_p
00987 //------------------------------------
00988 
00989 double enthal1(const double x, const Param& parent) {
00990   assert(parent.get_n_double() == 7) ;
00991 
00992   return parent.get_double(0)*puis(parent.get_double(1) - parent.get_double(2)
00993        *puis(x,parent.get_double(3)), parent.get_double(4)) 
00994     + parent.get_double(5)*x - parent.get_double(6) ;
00995 
00996 }
00997 
00998 double enthal23(const double x, const Param& parent) {
00999   assert(parent.get_n_double() == 10) ;
01000 
01001   double nx = (parent.get_double(0) - parent.get_double(1)*
01002            puis(x,parent.get_double(2)) - parent.get_double(3)*
01003            puis(x,parent.get_double(4)) )/parent.get_double(5) ;
01004   nx = puis(nx,parent.get_double(6)) ;
01005   return parent.get_double(7)*puis(x,parent.get_double(8)) 
01006     + parent.get_double(1)*parent.get_double(2)*nx*
01007     puis(x,parent.get_double(2) - 1) 
01008     + parent.get_double(3)*parent.get_double(4)*nx*
01009     puis(x,parent.get_double(4) - 1) 
01010     - parent.get_double(9) ;
01011 
01012 }
01013 
01014 double enthal(const double x, const Param& parent) {
01015   assert(parent.get_n_double_mod() == 7) ;
01016 
01017   double alp1 = parent.get_double_mod(0) ;
01018   double alp2 = parent.get_double_mod(1) ;
01019   double alp3 = parent.get_double_mod(2) ;
01020   double cc1 = parent.get_double_mod(3) ;
01021   double cc2 = parent.get_double_mod(4) ;
01022   double cc3 = parent.get_double_mod(5) ;
01023   double cc4 = parent.get_double_mod(6) ;
01024 
01025   return (cc1*puis(x,alp1) + cc2*puis(x,alp2) + cc3*puis(x,alp3) - cc4) ;
01026 
01027 }
01028 

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