def sol_tov(rho_center): rmin = dr rmax = 20000.0 r = pylab.arange(rmin, rmax + dr, dr) m = pylab.zeros_like(r) P = pylab.zeros_like(r) m[0] = (4.0 / 3.0) * pi * rho_center * r[0]**3 P[0] = eos(rho_center) y = pylab.array([P[0], m[0]]) i = 0 while P[i] > 0.0 and i < len(r) - 1: y = rk4(tov, y, r[i], dr) P[i + 1] = y[0] m[i + 1] = y[1] i = i + 1 rho = pylab.array(list(map(lambda p: inv_eos(p), P))) m, r, rho, P = m[:i], r[:i], rho[:i], P[:i] # Give restriction for region if isentropic: # Consider the isentropic case # We use conventional finite differencing to handle this case drhodr = get_dfdr(rho, dr) rprime = (r[-1] - r)[::-1] # Inward integration variable # Specific internal energy from thermo identities u_integrand = (-P * drhodr / (rho**2))[::-1] # Interpolation integrand_interpol = iterp1d(rprime, u_integrand, kind='cubic') urhs = lambda u, rprime: integrand_interpol(rprime) u = np.zeros_like(r) for i in range(0, len(rprime) - 1): u[i + 1] = rk4(urhs, u[i], rprime[i], dr) # Using RK4 to integrate u = u[::-1] # Reverse u else: u = np.zeros_like(r) return m, m[-1] / Msun, r, rho, P, u # Return the mass and radius of star
def sol_tov(rho_center): rmin = dr rmax = 2.e10 r = pylab.arange(rmin, rmax + dr, dr) m = pylab.zeros_like(r) P = pylab.zeros_like(r) rho = pylab.zeros_like(r) i = 0 rho[i] = rho_center m[i] = (4.0 / 3.0) * pi * dr**3 P[i] = eos(rho_center, 0.0) y = pylab.array([P[i], m[i]]) while P[i] > 0.0 and i < len(r) - 1: y = rk4(tov, y, r[i], dr, rho[i]) m[i + 1] = y[1] P[i + 1] = y[0] rho[i + 1] = bisection(2 * rho[i], 0.1 * rho[i], 1.e-8, P[i + 1]) i = i + 1 if P[i] < 0.0: P[i] = 0.0 rho[i] = 0.0 m, r, rho, P = m[:i], r[:i], rho[:i], P[:i] # Give restriction for region return m, m[-1] / Msun, r, rho, P # Return the mass and radius of star