//************* // tov_solver_polytrope.C // This code generates a sequence of models for polytropes using the TOV // equations for NS structure. // Note that "polytrope" here implies P=kappa * rho^gamma // where "rho" is the REST mass density, not the energy density // Here, we assume kappa=1, since results may be scaled to any value // // The call is just ./executable gam where "gam" is the value of gamma above // // The output is a file gam_n.nnn.dat, where "n.nnn" is the value of gamma. // // (c)2019 Josh Faber, please consider this either GPL // or CC-BY-SA as far as licensing goes. //***************************************************8 #include #include #include #include #include #include #include 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, double k, double gam); void derivs(double x, double* v, double* y, double k, double gam); int main(int argc, char** argv) { double gam = atof(argv[1]); char filename[20]; sprintf(filename,"gam_%.3f.dat",gam); ofstream outfile; outfile.open(filename); double step=1.0e-6; int np = (int) (100.0/step); double* rho = new double [np]; double* mass = new double [np]; double* massb = new double [np]; int i,j; //initial guess double k=1; double compact; int nloop; int nloopmax=800; double rhoc=1.0e-3; for (nloop=0; nloop0) { press = k*pow(rho,gam); eps = press/(gam-1.0); dpdrho = k*gam*pow(rho,gam-1.0); } else { press = 0; eps=0; dpdrho = 0; } if(x>0 && rho>0) { v[0] = -1.0/x/x*(rho+eps+press)*(mass+4.0*M_PI*x*x*x*press)/(1.0-2.0*mass/x)/dpdrho; v[1] = 4.0*M_PI*x*x*(rho+eps); v[2] = 4.0*M_PI*x*x*rho/sqrt(1.0-2.0*mass/x); } else { v[0]=0.; v[1]=0.; v[2]=0.; } }