eos_bf_poly_newt.C

00001 /*
00002  * Methods of the class Eos_bf_poly_newt.
00003  *
00004  * (see file eos_bifluid.h for documentation).
00005  */
00006 
00007 /*
00008  *   Copyright (c) 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_newt_C[] = "$Header: /cvsroot/Lorene/C++/Source/Eos/eos_bf_poly_newt.C,v 1.12 2003/12/17 23:12:32 r_prix Exp $" ;
00030 
00031 /*
00032  * $Id: eos_bf_poly_newt.C,v 1.12 2003/12/17 23:12:32 r_prix Exp $
00033  * $Log: eos_bf_poly_newt.C,v $
00034  * Revision 1.12  2003/12/17 23:12:32  r_prix
00035  * replaced use of C++ <string> by standard ANSI char* to be backwards compatible
00036  * with broken compilers like MIPSpro Compiler 7.2 on SGI Origin200. ;-)
00037  *
00038  * Revision 1.11  2003/12/05 15:09:47  r_prix
00039  * adapted Eos_bifluid class and subclasses to use read_variable() for
00040  * (formatted) file-reading.
00041  *
00042  * Revision 1.10  2003/12/04 14:22:33  r_prix
00043  * removed enthalpy restrictions in eos-inversion
00044  *
00045  * Revision 1.9  2003/11/18 18:28:38  r_prix
00046  * moved particle-masses m_1, m_2 of the two fluids into class eos_bifluid (from eos_bf_poly)
00047  *
00048  * Revision 1.8  2003/02/07 10:47:43  j_novak
00049  * The possibility of having gamma5 xor gamma6 =0 has been introduced for
00050  * tests. The corresponding parameter files have been added.
00051  *
00052  * Revision 1.7  2003/02/06 16:05:56  j_novak
00053  * Corrected an error in the inversion of the EOS for typeos =1,2 and 3.
00054  * Added new parameter files for sfstar.
00055  *
00056  * Revision 1.6  2002/10/16 14:36:34  j_novak
00057  * Reorganization of #include instructions of standard C++, in order to
00058  * use experimental version 3 of gcc.
00059  *
00060  * Revision 1.5  2002/05/31 16:13:36  j_novak
00061  * better inversion for eos_bifluid
00062  *
00063  * Revision 1.4  2002/05/02 15:16:22  j_novak
00064  * Added functions for more general bi-fluid EOS
00065  *
00066  * Revision 1.3  2002/04/05 09:09:36  j_novak
00067  * The inversion of the EOS for 2-fluids polytrope has been modified.
00068  * Some errors in the determination of the surface were corrected.
00069  *
00070  * Revision 1.2  2002/01/16 15:03:28  j_novak
00071  * *** empty log message ***
00072  *
00073  * Revision 1.1  2002/01/11 14:09:34  j_novak
00074  * Added newtonian version for 2-fluid stars
00075  *
00076  *
00077  * $Header: /cvsroot/Lorene/C++/Source/Eos/eos_bf_poly_newt.C,v 1.12 2003/12/17 23:12:32 r_prix Exp $
00078  *
00079  */
00080 
00081 // Headers C
00082 #include <stdlib.h>
00083 #include <math.h>
00084 
00085 // Headers Lorene
00086 #include "eos_bifluid.h"
00087 #include "eos.h"
00088 #include "cmp.h"
00089 #include "utilitaires.h"
00090 
00091 //****************************************************************************
00092 // local prototypes
00093 double puis(double, double) ;
00094 double enthal1(const double x, const Param& parent) ;
00095 double enthal23(const double x, const Param& parent) ;
00096 double enthal(const double x, const Param& parent) ;      
00097 //****************************************************************************
00098 
00099             //--------------//
00100             // Constructors //
00101             //--------------//
00102 
00103 // Standard constructor with gam1 = gam2 = 2, 
00104 // gam3 = gam4 = gam5 = gam6 = 1, m_1 = 1 and m_2 =1
00105 // -------------------------------------------------
00106 Eos_bf_poly_newt::Eos_bf_poly_newt(double kappa1, double kappa2, double kappa3,
00107                    double bet) :
00108   Eos_bf_poly(kappa1, kappa2, kappa3, bet) {
00109   set_name("bi-fluid polytropic non-relativistic EOS") ;
00110 }  
00111 
00112 // Standard constructor with everything specified
00113 // -----------------------------------------------
00114 Eos_bf_poly_newt::Eos_bf_poly_newt(double gamma1, double gamma2, double gamma3,
00115              double gamma4, double gamma5, double gamma6,
00116              double kappa1, double kappa2, double kappa3,
00117              double bet, double mass1, double mass2, 
00118              double l_relax, double l_precis, double l_ecart) : 
00119   Eos_bf_poly(gamma1, gamma2, gamma3, gamma4, gamma5, gamma6,
00120           kappa1, kappa2, kappa3, bet, mass1, mass2, l_relax, l_precis, 
00121           l_ecart) {
00122   set_name("bi-fluid polytropic non-relativistic EOS") ;
00123 } 
00124   
00125 // Copy constructor
00126 // ----------------
00127 Eos_bf_poly_newt::Eos_bf_poly_newt(const Eos_bf_poly_newt& eosi) : 
00128   Eos_bf_poly(eosi) {} 
00129   
00130 
00131 // Constructor from binary file
00132 // ----------------------------
00133 Eos_bf_poly_newt::Eos_bf_poly_newt(FILE* fich) : 
00134   Eos_bf_poly(fich) {} 
00135 
00136 // Constructor from a formatted file
00137 // ---------------------------------
00138 Eos_bf_poly_newt::Eos_bf_poly_newt(char *fname) : 
00139   Eos_bf_poly(fname) {} 
00140 
00141             //--------------//
00142             //  Destructor  //
00143             //--------------//
00144 
00145 Eos_bf_poly_newt::~Eos_bf_poly_newt(){
00146     
00147     // does nothing
00148         
00149 }
00150             //--------------//
00151             //  Assignment  //
00152             //--------------//
00153 
00154 void Eos_bf_poly_newt::operator=(const Eos_bf_poly_newt& eosi) {
00155   
00156   Eos_bf_poly::operator=(eosi) ;        
00157 
00158 }
00159 
00160             //------------------------//
00161             //  Comparison operators  //
00162             //------------------------//
00163 
00164 
00165 bool Eos_bf_poly_newt::operator==(const Eos_bifluid& eos_i) const {
00166     
00167   bool resu = true ; 
00168   
00169   if ( eos_i.identify() != identify() ) {
00170     cout << "The second EOS is not of type Eos_bf_poly_newt !" << endl ; 
00171     resu = false ; 
00172   }
00173   else{
00174     
00175     const Eos_bf_poly_newt& eos = 
00176       dynamic_cast<const Eos_bf_poly_newt&>( eos_i ) ; 
00177     
00178     if ((eos.gam1 != gam1)||(eos.gam2 != gam2)||(eos.gam3 != gam3)
00179     ||(eos.gam4 != gam4)||(eos.gam5 != gam5)||(eos.gam6 != gam6)) {
00180       cout 
00181     << "The two Eos_bf_poly_newt have different gammas : " << gam1 << " <-> " 
00182     << eos.gam1 << ", " << gam2 << " <-> " 
00183     << eos.gam2 << ", " << gam3 << " <-> " 
00184     << eos.gam3 << ", " << gam4 << " <-> " 
00185     << eos.gam4 << ", " << gam5 << " <-> " 
00186     << eos.gam5 << ", " << gam6 << " <-> " 
00187     << eos.gam6 << endl ; 
00188       resu = false ; 
00189     }
00190     
00191     if ((eos.kap1 != kap1)||(eos.kap2 != kap2)|| (eos.kap3 != kap3)){
00192       cout 
00193     << "The two Eos_bf_poly_newt have different kappas : " << kap1 << " <-> " 
00194     << eos.kap1 << ", " << kap2 << " <-> " 
00195     << eos.kap2 << ", " << kap3 << " <-> " 
00196     << eos.kap3 << endl ; 
00197       resu = false ; 
00198     }
00199     
00200     if (eos.beta != beta) {
00201       cout 
00202     << "The two Eos_bf_poly_newt have different betas : " << beta << " <-> " 
00203     << eos.beta << endl ; 
00204       resu = false ; 
00205     }
00206 
00207     if ((eos.m_1 != m_1)||(eos.m_2 != m_2)) {
00208       cout 
00209     << "The two Eos_bf_poly_newt have different masses : " << m_1 << " <-> " 
00210     << eos.m_1 << ", " << m_2 << " <-> " 
00211     << eos.m_2 << endl ; 
00212       resu = false ; 
00213     }
00214     
00215   }
00216   
00217   return resu ; 
00218   
00219 }
00220 
00221 bool Eos_bf_poly_newt::operator!=(const Eos_bifluid& eos_i) const {
00222  
00223     return !(operator==(eos_i)) ; 
00224        
00225 }
00226 
00227 
00228             //------------//
00229             //  Outputs   //
00230             //------------//
00231 
00232 void Eos_bf_poly_newt::sauve(FILE* fich) const {
00233 
00234     Eos_bf_poly::sauve(fich) ; 
00235 }
00236 
00237 ostream& Eos_bf_poly_newt::operator>>(ostream & ost) const {
00238     
00239     ost << "EOS of class Eos_bf_poly_newt (non-relativistic polytrope) : " << endl ; 
00240     ost << "   Adiabatic index gamma1 :      " << gam1 << endl ; 
00241     ost << "   Adiabatic index gamma2 :      " << gam2 << endl ; 
00242     ost << "   Adiabatic index gamma3 :      " << gam3 << endl ; 
00243     ost << "   Adiabatic index gamma4 :      " << gam4 << endl ; 
00244     ost << "   Adiabatic index gamma5 :      " << gam5 << endl ; 
00245     ost << "   Adiabatic index gamma6 :      " << gam6 << endl ; 
00246     ost << "   Pressure coefficient kappa1 : " << kap1 << 
00247        " rho_nuc c^2 / n_nuc^gamma" << endl ; 
00248     ost << "   Pressure coefficient kappa2 : " << kap2 << 
00249        " rho_nuc c^2 / n_nuc^gamma" << endl ; 
00250     ost << "   Pressure coefficient kappa3 : " << kap3 << 
00251        " rho_nuc c^2 / n_nuc^gamma" << endl ; 
00252     ost << "   Coefficient beta : " << beta << 
00253        " rho_nuc c^2 / n_nuc^gamma" << endl ; 
00254     ost << "   Mean particle 1 mass : " << m_1 << " m_B" << endl ;
00255     ost << "   Mean particle 2 mass : " << m_2 << " m_B" << endl ;
00256     ost << "   Parameters for inversion (used if typeos = 4 : " << endl ;
00257     ost << "   relaxation : " << relax << endl ;
00258     ost << "   precision for zerosec_b : " << precis << endl ;
00259     ost << "   final discrepancy in the result : " << ecart << endl ;
00260     
00261     return ost ;
00262 
00263 }
00264 
00265 
00266             //------------------------------//
00267             //    Computational routines    //
00268             //------------------------------//
00269 
00270 // Baryon densities from enthalpies 
00271 //---------------------------------
00272 // RETURN: bool true = if in a one-fluid region, false if two-fluids
00273 
00274 bool Eos_bf_poly_newt::nbar_ent_p(const double ent1, const double ent2, 
00275                   const double delta2, double& nbar1, 
00276                   double& nbar2) const {  
00277 
00278   //RP: I think this is wrong!!
00279   //  bool one_fluid = ((ent1<=0.)||(ent2<=0.)) ;
00280   
00281   bool one_fluid = false;
00282   
00283   if (!one_fluid) {
00284     switch (typeos) {
00285     case 5:  // same as typeos==0, just with slow-rot-style inversion
00286     case 0: {//gamma1=gamma2=2 all others = 1 easy case of a linear system
00287       double kpd = kap3+beta*delta2 ;
00288       double determ = kap1*kap2 - kpd*kpd ;
00289     
00290       nbar1 = (kap2*ent1*m_1 - kpd*ent2*m_2) / determ ;
00291       nbar2 = (kap1*ent2*m_2 - kpd*ent1*m_1) / determ ;
00292       one_fluid = ((nbar1 < 0.)||(nbar2 < 0.)) ;
00293       break ;
00294     }
00295     case 1: { //gamma1 or gamma 2 not= 2; all others = 1
00296       double b1 = ent1*m_1 ;
00297       double b2 = ent2*m_2 ;
00298       double denom = kap3 + beta*delta2 ;
00299       if (fabs(denom) < 1.e-15) {
00300     nbar1 = puis(2*b1/(gam1*kap1), 1./gam1m1) ;
00301     nbar2 = puis(2*b2/(gam2*kap2), 1./gam2m1) ;
00302     one_fluid = ((nbar1 < 0.)||(nbar2 < 0.)) ;
00303       }
00304       else {
00305     double coef0 = 0.5*gam2*kap2/pow(denom, gam2m1) ;
00306     double coef1 = 0.5*kap1*gam1 ;
00307     Param parent ;
00308     parent.add_double(coef0, 0) ;
00309     parent.add_double(b1, 1) ;
00310     parent.add_double(coef1, 2) ;
00311     parent.add_double(gam1m1,3) ;
00312     parent.add_double(gam2m1,4) ;
00313     parent.add_double(denom, 5) ;
00314     parent.add_double(b2, 6) ;
00315 
00316     double xmin, xmax ;
00317     double f0 = enthal1(0.,parent) ;
00318     if (fabs(f0)<1.e-15) {
00319       nbar1 = 0. ;}
00320     else {
00321       double cas = (gam1m1*gam2m1 - 1.)*f0;
00322       assert (fabs(cas) > 1.e-15) ;
00323       xmin = 0. ;
00324       xmax = cas/fabs(cas) ;
00325       do {
00326         xmax *= 1.1 ;
00327         if (fabs(xmax) > 1.e10) {
00328           cout << "Problem in Eos_bf_poly::nbar_ent_p!" << endl ;
00329           cout << f0 << ", " << cas << endl ; // to be removed!!
00330           cout << "typeos = 1" << endl ;
00331           abort() ;
00332         }
00333       } while (enthal1(xmax,parent)*f0 > 0.) ;
00334       double l_precis = 1.e-12 ;
00335       int nitermax = 400 ;
00336       int niter = 0 ;
00337       nbar1 = zerosec_b(enthal1, parent, xmin, xmax, l_precis, 
00338                 nitermax, niter) ;
00339     }
00340     nbar2 = (b1 - coef1*puis(nbar1, gam1m1))/denom ;
00341     double resu1 = coef1*puis(nbar1,gam1m1) + denom*nbar2 ;
00342     double resu2 = 0.5*gam2*kap2*puis(nbar2,gam2m1) + denom*nbar1 ;
00343     double erreur = fabs((resu1/m_1-ent1)/ent1) + 
00344       fabs((resu2/m_2-ent2)/ent2) ;
00345     one_fluid = ((nbar1 < 0.)||(nbar2 < 0.)||(erreur > 1.e-4)) ;
00346       }
00347       break ;
00348     }
00349     case 2: { // gamma3 = gamma5 = 1 at least
00350       double b1 = ent1*m_1 ;
00351       double b2 = ent2*m_2 ;
00352       double denom = kap3 + beta*delta2 ;
00353       if (fabs(denom) < 1.e-15) {
00354     nbar1 = puis(2*b1/(gam1*kap1), 1./gam1m1) ;
00355     nbar2 = puis(2*b2/(gam2*kap2), 1./gam2m1) ;
00356     one_fluid = ((nbar1 < 0.)||(nbar2 < 0.)) ;
00357       }
00358       else {
00359     double coef0 = beta*delta2 ;
00360     double coef1 = 0.5*kap1*gam1 ;
00361     double coef2 = 0.5*kap2*gam2 ;
00362     double coef3 = 1./gam1m1 ;
00363     Param parent ;
00364     parent.add_double(b1, 0) ;
00365     parent.add_double(kap3, 1) ;
00366     parent.add_double(gam4, 2) ;
00367     parent.add_double(coef0, 3) ;
00368     parent.add_double(gam6,4) ;
00369     parent.add_double(coef1, 5) ;
00370     parent.add_double(coef3, 6) ;
00371     parent.add_double(coef2, 7) ;
00372     parent.add_double(gam2m1, 8) ;
00373     parent.add_double(b2, 9) ;
00374 
00375     double xmin, xmax ;
00376     double f0 = enthal23(0.,parent) ;
00377     if (fabs(f0)<1.e-15) {
00378       nbar2 = 0. ;}
00379     else {
00380       double pmax = (fabs(kap3) < 1.e-15 ? 0. : gam4*(gam4-1) ) ;
00381       double ptemp = (fabs(kap3*coef0) < 1.e-15  ? 0. 
00382               : gam6*(gam4-1) ) ;
00383       pmax = (pmax>ptemp ? pmax : ptemp) ;
00384       ptemp = (fabs(kap3*coef0) < 1.e-15 ? 0. : gam4*(gam6-1) ) ;
00385       pmax = (pmax>ptemp ? pmax : ptemp) ;
00386       ptemp = (fabs(coef0) < 1.e-15 ? 0. : gam6*(gam6-1) ) ;
00387       pmax = (pmax>ptemp ? pmax : ptemp) ;
00388       double cas = (pmax - gam1m1*gam2m1)*f0;
00389       //      cout << "Pmax, cas: " << pmax << ", " << cas << endl ;
00390       assert (fabs(cas) > 1.e-15) ;
00391       xmin = 0. ;
00392       xmax = cas/fabs(cas) ;
00393       do {
00394         xmax *= 1.1 ;
00395         if (fabs(xmax) > 1.e10) {
00396           cout << "Problem in Eos_bf_poly::nbar_ent_p!" << endl ;
00397           cout << "typeos = 2" << endl ;
00398           abort() ;
00399         }
00400       } while (enthal23(xmax,parent)*f0 > 0.) ;
00401       double l_precis = 1.e-12 ;
00402       int nitermax = 400 ;
00403       int niter = 0 ;
00404       nbar2 = zerosec_b(enthal23, parent, xmin, xmax, l_precis, 
00405                 nitermax, niter) ;
00406     }
00407     nbar1 = (b1 - kap3*puis(nbar2,gam4) - coef0*puis(nbar2,gam6))
00408       / coef1 ;
00409     nbar1 = puis(nbar1,coef3) ;
00410     double resu1 = coef1*puis(nbar1,gam1m1) + kap3*puis(nbar2,gam4)
00411       + coef0*puis(nbar2, gam6) ;
00412     double resu2 = coef2*puis(nbar2,gam2m1) 
00413       + gam4*kap3*puis(nbar2, gam4-1)*nbar1
00414       + gam6*coef0*puis(nbar2, gam6-1)*nbar1 ;
00415     double erreur = fabs((resu1/m_1-ent1)/ent1) + 
00416       fabs((resu2/m_2-ent2)/ent2) ;
00417     //cout << "Erreur d'inversion: " << erreur << endl ;
00418     one_fluid = ((nbar1 < 0.)||(nbar2 < 0.)||(erreur > 1.e-4)) ;
00419       }
00420       break ;
00421     }
00422     case 3: { //gamma4 = gamm6 = 1 at least
00423       double b1 = ent1*m_1 ;
00424       double b2 = ent2*m_2 ;
00425       double denom = kap3 + beta*delta2 ;
00426       if (fabs(denom) < 1.e-15) {
00427     nbar1 = puis(2*b1/(gam1*kap1), 1./gam1m1) ;
00428     nbar2 = puis(2*b2/(gam2*kap2), 1./gam2m1) ;
00429     one_fluid = ((nbar1 < 0.)||(nbar2 < 0.)) ;
00430       }
00431       else {
00432     double coef0 = beta*delta2 ;
00433     double coef1 = 0.5*kap1*gam1 ;
00434     double coef2 = 0.5*kap2*gam2 ;
00435     double coef3 = 1./gam2m1 ;
00436     Param parent ;
00437     parent.add_double(b2, 0) ;
00438     parent.add_double(kap3, 1) ;
00439     parent.add_double(gam3, 2) ;
00440     parent.add_double(coef0, 3) ;
00441     parent.add_double(gam5, 4) ;
00442     parent.add_double(coef2, 5) ;
00443     parent.add_double(coef3, 6) ;
00444     parent.add_double(coef1, 7) ;
00445     parent.add_double(gam1m1, 8) ;
00446     parent.add_double(b1, 9) ;
00447     
00448     double xmin, xmax ;
00449     double f0 = enthal23(0.,parent) ;
00450     if (fabs(f0)<1.e-15) {
00451       nbar1 = 0. ;}
00452     else {
00453       double pmax = (fabs(kap3) < 1.e-15 ? 0. : gam3*(gam3-1) ) ;
00454       double ptemp = (fabs(kap3*coef0) < 1.e-15  ? 0. 
00455               : gam5*(gam3-1) ) ;
00456       pmax = (pmax>ptemp ? pmax : ptemp) ;
00457       ptemp = (fabs(kap3*coef0) < 1.e-15 ? 0. : gam3*(gam5-1) ) ;
00458       pmax = (pmax>ptemp ? pmax : ptemp) ;
00459       ptemp = (fabs(coef0) < 1.e-15 ? 0. : gam5*(gam5-1) ) ;
00460       pmax = (pmax>ptemp ? pmax : ptemp) ;
00461       double cas = (pmax - gam1m1*gam2m1)*f0;
00462       //      cout << "Pmax, cas: " << pmax << ", " << cas << endl ;
00463       assert (fabs(cas) > 1.e-15) ;
00464       xmin = 0. ;
00465       xmax = cas/fabs(cas) ;
00466       do {
00467         xmax *= 1.1 ;
00468         if (fabs(xmax) > 1.e10) {
00469           cout << "Problem in Eos_bf_poly::nbar_ent_p!" << endl ;
00470           cout << "typeos = 3" << endl ;
00471           abort() ;
00472         }
00473       } while (enthal23(xmax,parent)*f0 > 0.) ;
00474       double l_precis = 1.e-12 ;
00475       int nitermax = 400 ;
00476       int niter = 0 ;
00477       nbar1 = zerosec_b(enthal23, parent, xmin, xmax, l_precis, 
00478                 nitermax, niter) ;
00479     }
00480     nbar2 = (b2 - kap3*puis(nbar1,gam3) - coef0*puis(nbar1,gam5))
00481       / coef2 ;
00482     nbar2 = puis(nbar2,coef3) ;
00483     double resu1 = coef1*puis(nbar1,gam1m1) 
00484       + gam3*kap3*puis(nbar1,gam3-1)*nbar2
00485       + coef0*gam5*puis(nbar1, gam5-1)*nbar2 ;
00486     double resu2 = coef2*puis(nbar2,gam2m1) 
00487       + kap3*puis(nbar1, gam3) + coef0*puis(nbar1, gam5);
00488     double erreur = fabs((resu1/m_1-ent1)/ent1) + 
00489       fabs((resu2/m_2-ent2)/ent2) ;
00490     one_fluid = ((nbar1 < 0.)||(nbar2 < 0.)||(erreur > 1.e-4)) ;
00491       }
00492       break ;
00493     }    
00494     case 4:{ // most general case
00495       double b1 = ent1*m_1 ; 
00496       double b2 = ent2*m_2 ; 
00497       double denom = kap3 + beta*delta2 ;
00498       if (fabs(denom) < 1.e-15) {
00499     nbar1 = puis(2*b1/(gam1*kap1), 1./gam1m1) ;
00500     nbar2 = puis(2*b2/(gam2*kap2), 1./gam2m1) ;
00501     one_fluid = ((nbar1 < 0.)||(nbar2 < 0.)) ;
00502       }
00503       else {
00504     int nitermax = 200 ;
00505     int niter = 0 ;
00506     int nmermax = 800 ;
00507     
00508     double a11 = 0.5*gam1*kap1 ;
00509     double a13 = gam3*kap3 ;
00510     double a14 = beta*gam5*delta2 ;
00511     
00512     double a22 = 0.5*gam2*kap2 ;
00513     double a23 = gam4*kap3 ;
00514     double a24 = beta*gam6*delta2 ;
00515     
00516     double n1l, n2l, n1s, n2s ;
00517     
00518     double delta = a11*a22 - (a13+a14)*(a23+a24) ;
00519     n1l = (a22*b1 - (a13+a14)*b2)/delta ;
00520     n2l = (a11*b2 - (a23+a24)*b1)/delta ;
00521     n1s = puis(b1/a11, 1./(gam1m1)) ;
00522     n2s = puis(b2/a22, 1./(gam2m1)) ;
00523     
00524     double n1m = (n1l<0. ? n1s : sqrt(n1l*n1s)) ;
00525     double n2m = (n2l<0. ? n2s : sqrt(n2l*n2s)) ;
00526     
00527     Param parf1 ;
00528     Param parf2 ;
00529     double c1, c2, c3, c4, c5, c6, c7 ;
00530     c1 = gam1m1 ;
00531     c2 = gam3 - 1. ;
00532     c3 = gam5 - 1. ;
00533     c4 = a11 ;
00534     c5 = a13*puis(n2m,gam4) ;
00535     c6 = a14*puis(n2m,gam6) ;
00536     c7 = b1 ; 
00537     parf1.add_double_mod(c1,0) ;
00538     parf1.add_double_mod(c2,1) ;
00539     parf1.add_double_mod(c3,2) ;
00540     parf1.add_double_mod(c4,3) ;
00541     parf1.add_double_mod(c5,4) ;
00542     parf1.add_double_mod(c6,5) ;
00543     parf1.add_double_mod(c7,6) ;
00544     
00545     double d1, d2, d3, d4, d5, d6, d7 ;
00546     d1 = gam2m1 ;
00547     d2 = gam4 - 1. ;
00548     d3 = gam6 - 1. ;
00549     d4 = a22 ;
00550     d5 = a23*puis(n1m,gam3) ;
00551     d6 = a24*puis(n1m,gam5) ;
00552     d7 = b2 ; 
00553     parf2.add_double_mod(d1,0) ;
00554     parf2.add_double_mod(d2,1) ;
00555     parf2.add_double_mod(d3,2) ;
00556     parf2.add_double_mod(d4,3) ;
00557     parf2.add_double_mod(d5,4) ;
00558     parf2.add_double_mod(d6,5) ;
00559     parf2.add_double_mod(d7,6) ;
00560     
00561     double xmin = -3*(n1s>n2s ? n1s : n2s) ;
00562     double xmax = 3*(n1s>n2s ? n1s : n2s) ;
00563     
00564     double n1 = n1m ;
00565     double n2 = n2m ;
00566     bool sortie = true ;
00567     int mer = 0 ;
00568     
00569     //cout << "Initial guess: " << n1 << ", " << n2 << endl ;
00570     n1s *= 0.1 ;
00571     n2s *= 0.1 ;
00572     do {
00573       //cout << "n1, n2: " << n1 << ", " << n2 << endl ;
00574       n1 = zerosec_b(&enthal, parf1, xmin, xmax, precis, nitermax, niter) ;
00575       n2 = zerosec_b(&enthal, parf2, xmin, xmax, precis, nitermax, niter) ;
00576       
00577       sortie = (fabs((n1m-n1)/(n1m+n1)) + fabs((n2m-n2)/(n2m+n2)) > ecart) ;
00578       n1m = relax*n1 + (1.-relax)*n1m ;
00579       n2m = relax*n2 + (1.-relax)*n2m ;
00580       if (n2m>-n2s) {
00581         parf1.get_double_mod(4) = a13*puis(n2m,gam4) ;
00582         parf1.get_double_mod(5) = a14*puis(n2m,gam6) ;
00583       }
00584       else {
00585         parf1.get_double_mod(4) = a13*puis(-n2s,gam4) ;
00586         parf1.get_double_mod(5) = a14*puis(-n2s,gam6) ;
00587       }
00588       
00589       if (n1m>-n1s) {
00590         parf2.get_double_mod(4) = a23*puis(n1m,gam3) ;
00591         parf2.get_double_mod(5) = a24*puis(n1m,gam5) ;
00592       }
00593       else {
00594         parf2.get_double_mod(4) = a23*puis(-n1s,gam3) ;
00595         parf2.get_double_mod(5) = a24*puis(-n1s,gam5) ;
00596       }
00597       
00598       mer++ ;
00599     } while (sortie&&(mer<nmermax)) ;
00600     nbar1 = n1m ;
00601     nbar2 = n2m ;
00602     
00603 //      double resu1 = a11*puis(n1,gam1m1) + a13*puis(n1,gam3-1.)*puis(n2,gam4)
00604 //        +a14*puis(n1,gam5-1.)*puis(n2,gam6) ;
00605 //      double resu2 = a22*puis(n2,gam2m1) + a23*puis(n1,gam3)*puis(n2,gam4-1.)
00606 //        +a24*puis(n1,gam5)*puis(n2,gam6-1.) ;
00607     //cout << "Nbre d'iterations: " << mer << endl ;
00608     //cout << "Resus: " << n1m << ", " << n2m << endl ;
00609     //cout << "Verification: " << log(fabs(1+resu1)) << ", " 
00610     //     << log(fabs(1+resu2)) << endl ; 
00611     //    cout << "Erreur: " << fabs(enthal(n1, parf1)/b1) + 
00612     //      fabs(enthal(n2, parf2)/b2) << endl ;
00613     //cout << "Erreur: " << fabs((log(fabs(1+resu1))-ent1)/ent1) + 
00614     //fabs((log(fabs(1+resu2))-ent2)/ent2) << endl ;
00615       }
00616       break ;
00617     }
00618     case -1: {
00619       double determ = kap1*kap2 - kap3*kap3 ;
00620     
00621       nbar1 = (kap2*(ent1*m_1 - beta*delta2) - kap3*ent2*m_2) / determ ;
00622       nbar2 = (kap1*ent2*m_2 - kap3*(ent1*m_1 - beta*delta2)) / determ ;
00623       one_fluid = ((nbar1 < 0.)||(nbar2 < 0.)) ;
00624       break ;
00625     }
00626     case -2: {
00627       double determ = kap1*kap2 - kap3*kap3 ;
00628     
00629       nbar1 = (kap2*ent1*m_1 - kap3*(ent2*m_2 - beta*delta2)) / determ ;
00630       nbar2 = (kap1*(ent2*m_2 - beta*delta2) - kap3*ent1*m_1) / determ ;
00631       one_fluid = ((nbar1 < 0.)||(nbar2 < 0.)) ;
00632       break ;
00633     }
00634     }
00635   }
00636   
00637   return one_fluid ;
00638 }
00639 // One fluid sub-EOSs
00640 //-------------------
00641 
00642 double Eos_bf_poly_newt::nbar_ent_p1(const double ent1) const {
00643   return puis(2*ent1*m_1/(gam1*kap1), 1./gam1m1) ;
00644 }
00645 
00646 double Eos_bf_poly_newt::nbar_ent_p2(const double ent2) const {
00647   return puis(2*ent2*m_2/(gam2*kap2), 1./gam2m1) ;
00648 }
00649 
00650 // Energy density from baryonic densities
00651 //---------------------------------------
00652 
00653 double Eos_bf_poly_newt::ener_nbar_p(const double nbar1, const double nbar2, 
00654                 const double delta2) const {
00655     
00656   double n1 = (nbar1>double(0) ? nbar1 : 0) ;
00657   double n2 = (nbar2>double(0) ? nbar2 : 0) ;
00658   double x2 = ((nbar1>double(0))&&(nbar2>double(0))) ? delta2 : 0 ;
00659 
00660   double resu = 0.5*kap1*pow(n1, gam1) + 0.5*kap2*pow(n2,gam2)
00661     + kap3*pow(n1,gam3)*pow(n2,gam4) 
00662     + x2*beta*pow(n1,gam5)*pow(n2,gam6) ;
00663 
00664   return resu ;
00665 
00666 }
00667 
00668 // Pressure from baryonic densities
00669 //---------------------------------
00670 
00671 double Eos_bf_poly_newt::press_nbar_p(const double nbar1, const double nbar2,
00672                 const double delta2) const {
00673     
00674   double n1 = (nbar1>double(0) ? nbar1 : 0) ;
00675   double n2 = (nbar2>double(0) ? nbar2 : 0) ;
00676   double x2 = ((nbar1>double(0))&&(nbar2>double(0))) ? delta2 : 0 ;
00677   
00678   double resu = 0.5*gam1m1*kap1*pow(n1,gam1) + 0.5*gam2m1*kap2*pow(n2,gam2)
00679     + gam34m1*kap3*pow(n1,gam3)*pow(n2,gam4) + 
00680     x2*gam56m1*beta*pow(n1,gam5)*pow(n2,gam6) ;
00681   
00682   return resu ;
00683 
00684 }
00685 
00686 // Derivatives of energy
00687 //----------------------
00688 
00689 double Eos_bf_poly_newt::get_K11(const double n1, const double n2, const
00690                    double)  const 
00691 {
00692   double xx ;
00693   if (n1 <= 0.) xx = 0. ;
00694   else xx = m_1/n1 -2*beta*pow(n1,gam5-2)*pow(n2,gam6) ;
00695 
00696   return xx ;
00697 }
00698 
00699 double Eos_bf_poly_newt::get_K22(const double n1, const double n2, const
00700                    double ) const  
00701 {
00702   double xx ;
00703   if (n2 <= 0.) xx = 0. ;
00704   else xx = m_2/n2 - 2*beta*pow(n1,gam5)*pow(n2,gam6-2) ;
00705 
00706   return xx ;
00707 }
00708 
00709 double Eos_bf_poly_newt::get_K12(const double n1, const double n2, const
00710                    double) const  
00711 {
00712   double xx ;
00713   if ((n1 <= 0.) || (n2 <= 0.)) xx = 0.; 
00714   else xx = 2*beta*pow(n1,gam5-1)*pow(n2,gam6-1) ;
00715 
00716   return xx ;
00717 }
00718 
00719 // Conversion functions
00720 // ---------------------
00721 
00722 Eos* Eos_bf_poly_newt::trans2Eos() const {
00723 
00724   Eos_poly_newt* eos_simple = new Eos_poly_newt(gam1, kap1) ;
00725   return eos_simple ;
00726 
00727 }
00728        

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