//------------------------------------------------- // tov_solver.C: Copyright 2019, Joshua Faber // Licensing terms: please use similar terms to either the GPL or Creative Commons-BY-SA. Thanks! // To call this routine, look at the definitions in Read et al. (2008)-- PRD 79, 124032 (2009); arXiv:0812.2163 // Note: you likely have at least a moral obligation to cite their work if using their EOS model //------------------------------------------------- // The call is name_string P_1 gam_1 gam_2 gam_3 // where name_string is a string that is appended to the end of the filename for ID purposes // P_1 is the logarithm of the cgs pressure at log(rho_cgs)=14.7 // and the 3 gamma's are the 3-part polytrope adiabatic indicies // There are two files created: // par_eos.d.name_string is a Lorene-compatible par_eos.d file // densenthmassradius.name_string is a tabulation of central density, log(enthalpy), gravitational mass. // radius in km, compactness, and baryon mass // Finally the code will output to screen the configuration details for the model with the largest baryon mass, then stop. //------------------------------------------------- #include #include #include #include #include #include #include double lowdens=1.0; // Physical constants double msun = 1.98847e33; double kilometer=1.0e5; double ggrav=6.67408e-8; double speedlight=2.9979e10; using namespace std; void rk4(double x, double* y, double step, int npoly, double* kpoly, double* gam, double* rhob, double* aread); void derivs(double x, double* v, double* y, int npoly, double* kpoly, double* gam, double* rhob, double* aread); double enth(double rho, int npoly, double* kpoly, double* gam, double* rhob, double* aread); int main(int argc, char** argv) { int i,j,npoly; double gam[7],kpoly[7],rhobreak[6],rhob[6],pressbreak[6],pressb[6],pcgs[6]; string eosname=argv[1]; string filename="par_eos.d."+eosname; string filename2="densenthmassradius."+eosname; ofstream outfile,outfile2; outfile.open(filename.c_str()); outfile2.open(filename2.c_str()); double presspoly=atof(argv[2]); //See read et al. for the underlying piecewise polytropic EOS model and low-density crust parameters npoly=7; gam[0]=1.58425; gam[1]=1.28733; gam[2]=0.62223; gam[3]=1.35692; gam[4]=atof(argv[3]); gam[5]=atof(argv[4]); gam[6]=atof(argv[5]); kpoly[0]=6.8011e-9; rhobreak[0]=7.3875; rhobreak[1]=11.5779; rhobreak[2]=12.4196; rhobreak[4]=14.7; rhobreak[5]=15.0; pressbreak[0]=log10(kpoly[0])+gam[0]*rhobreak[0]; pressbreak[1]=pressbreak[0]+gam[1]*(rhobreak[1]-rhobreak[0]); pressbreak[2]=pressbreak[1]+gam[2]*(rhobreak[2]-rhobreak[1]); for(i=0; i<=2; i++)pcgs[i]=pressbreak[i]+2.0*log10(speedlight); double presscrust=pcgs[2]; rhobreak[3]=(presspoly-presscrust+rhobreak[2]*gam[3]-rhobreak[4]*gam[4])/(gam[3]-gam[4]); pressbreak[3]=pressbreak[2]+gam[3]*(rhobreak[3]-rhobreak[2]); pressbreak[4]=pressbreak[3]+gam[4]*(rhobreak[4]-rhobreak[3]); pressbreak[5]=pressbreak[4]+gam[5]*(rhobreak[5]-rhobreak[4]); for(i=0; i<=5; i++)rhob[i]=pow(10.0,rhobreak[i]); for(i=0; i<=5; i++)pressb[i]=pow(10.0,pressbreak[i]); for(i=3; i<=5; i++)pcgs[i]=pressbreak[i]+2.0*log10(speedlight); for(i=1; i<=6; i++)kpoly[i]=kpoly[i-1]*pow(rhob[i-1],gam[i-1]-gam[i]); // for(i=0;i<=5;i++)cout<<"gam,k,rho,p,pcgs,rhob:"<oldmass; iloop++) { for(i=0; inewmass)outfile2<0) { for (i=0; irhob[i])nsegment+=1; } press=kpoly[nsegment]*pow(rho,gam[nsegment]); dpdrho=gam[nsegment]*press/rho; if(nsegment==0) { eps=rho+press/(gam[0]-1.0); } else { eps=rho*(1.0+aread[nsegment])+press/(gam[nsegment]-1); } } else { press = 0; eps=0; dpdrho = 0; } //We'll want to rescale away from density-based cgs units here. //If P and rho are DIVIDED by a factor f, then r and m must each be multiplied by a factor f^{1/2} to balance //dm/dr is dimensionless //dP/dr divides by f^{-3/2} double refdens=msun/pow(ggrav*msun/speedlight/speedlight,3.0); double rhoref=rho/refdens; double epsref=eps/refdens; double pressref=press/refdens; if(x>0 && rho>0) { v[0] = -1.0/x/x*(epsref+pressref)*(mass+4.0*M_PI*x*x*x*pressref)/(1.0-2.0*mass/x)/dpdrho; v[1] = 4.0*M_PI*x*x*(epsref); v[2] = 4.0*M_PI*x*x*(rhoref)/sqrt(1.0-2.0*mass/x); } else { v[0]=0.; v[1]=0.; v[2]=0.; } v[0]*=pow(refdens,1.0); } double enth(double rho, int npoly, double* kpoly, double* gam, double* rhob, double* aread) { int i,nsegment=0; double enthval; if(rho>0) { for (i=0; irhob[i])nsegment+=1; } enthval=1.0+aread[nsegment]+kpoly[nsegment]*gam[nsegment]*pow(rho,gam[nsegment]-1.0)/(gam[nsegment]-1.0); } else { enthval=0.0; } return enthval; }