To find a dimensionless mass, ˜M, dimensionless distance, ˜r, and dimensionless time, ˜t, we note GM/rc2 is dimensionless GMrc2=Gρ0r2c2=Gc2n−2Knr2→˜r=√Gcn−1Kn/2r=rr0,
So we will need a Mfid which is define such that the (SENR) code units \MfidBar=1 or in other words in SENR codes units: ˉM=MMfid
Sound speed cs is defined as
∂P∂ρ=c2s,so if we have a polytropic EOS, where
P=Kρ(1+1/n),then
∂P∂ρ=c2s=(1+1n)Kρ1/n.Let's adopt the notation
[ρ]="the units of ρ"Using this notation and the fact that n is dimensionless, the above expression implies
[ρ1/n]=[c2sK]⟹[ρ]=[c2sK]nI think you found the inverse to be true.
The TOV equations are dPdr=−μGMr2(1+Pμc2)(1+4πr3PMc2)(1−2GMrc2)−1dMdr=4πμr2,
In dimensionless units they are d˜Pd˜r=−(˜μ+˜P)(˜M+4π˜r3˜P)˜r2(1−2˜M˜r)d˜Md˜r=4π˜μ˜r2
At this point, we need to discuss how to numerically integrate these models. First we pick a central baryonic mass density ˜ρ0,c, then we compute a central pressure ˜Pc and central mass-energy density ˜μc. At ˜r=0, we assume that ˜μ=˜μc is a constant and so d˜Pd˜r=−(˜μc+˜Pc)(˜M(˜r≪1)+4π˜r3˜Pc)˜r2(1−2˜M(˜r≪1)˜r)d˜Md˜r=4π˜μc˜r2→˜M(˜r≪1)=4π3˜μc˜r3
Let consider an alternative formulation where rather than setting K=1, we set the characteristic mass Mfid=M0. In this case, r0=GM0c2t0=GM0c3ρ0=M0r30=c6G3M20=6.17×1017(M01M⊙)−2
The metric for the TOV equation (taken) from wikipedia is ds2=−c2eνdt2+(1−2GMrc2)−1dr2+r2dΩ2
Lets write this in dimensionless units: ds2=exp(ν)d˜t2−(1−2˜M˜r)−1d˜r2+˜r2dΩ2
import sys
import numpy as np
import scipy.integrate as si
import math
import matplotlib.pyplot as pl
n = 1.
rho_central = 0.129285
P0 = 1. # ZACH NOTES: CHANGED FROM 100.
gamma = 1. + 1./n
gam1 = gamma - 1.
def pressure( rho) :
return P0*rho**gamma
def rhs( r, y) :
# In \tilde units
#
P = y[0]
m = y[1]
nu = y[2]
rbar = y[3]
rho = (P/P0)**(1./gamma)
mu = rho + P/gam1
dPdr = 0.
drbardr = 0.
if( r < 1e-4 or m <= 0.) :
m = 4*math.pi/3. * mu*r**3
dPdr = -(mu + P)*(4.*math.pi/3.*r*mu + 4.*math.pi*r*P)/(1.-8.*math.pi*mu*r*r)
drbardr = 1./(1. - 8.*math.pi*mu*r*r)**0.5
else :
dPdr = -(mu + P)*(m + 4.*math.pi*r**3*P)/(r*r*(1.-2.*m/r))
drbardr = 1./(1. - 2.*m/r)**0.5*rbar/r
dmdr = 4.*math.pi*r*r*mu
dnudr = -2./(P + mu)*dPdr
return [dPdr, dmdr, dnudr, drbardr]
def integrateStar( P, showPlot = False, dumpData = False, compareFile="TOV/output_EinsteinToolkitTOVSolver.txt") :
integrator = si.ode(rhs).set_integrator('dop853')
y0 = [P, 0., 0., 0.]
integrator.set_initial_value(y0,0.)
dr = 1e-5
P = y0[0]
PArr = []
rArr = []
mArr = []
nuArr = []
rbarArr = []
r = 0.
while integrator.successful() and P > 1e-9*y0[0] :
P, m, nu, rbar = integrator.integrate(r + dr)
r = integrator.t
dPdr, dmdr, dnudr, drbardr = rhs( r+dr, [P,m,nu,rbar])
dr = 0.1*min(abs(P/dPdr), abs(m/dmdr))
dr = min(dr, 1e-2)
PArr.append(P)
rArr.append(r)
mArr.append(m)
nuArr.append(nu)
rbarArr.append( rbar)
M = mArr[-1]
R = rArr[-1]
nuArr_np = np.array(nuArr)
# Rescale solution to nu so that it satisfies BC: exp(nu(R))=exp(nutilde-nu(r=R)) * (1 - 2m(R)/R)
# Thus, nu(R) = (nutilde - nu(r=R)) + log(1 - 2*m(R)/R)
nuArr_np = nuArr_np - nuArr_np[-1] + math.log(1.-2.*mArr[-1]/rArr[-1])
rArrExtend_np = 10.**(np.arange(0.01,5.0,0.01))*rArr[-1]
rArr.extend(rArrExtend_np)
mArr.extend(rArrExtend_np*0. + M)
PArr.extend(rArrExtend_np*0.)
phiArr_np = np.append( np.exp(nuArr_np), 1. - 2.*M/rArrExtend_np)
rbarArr.extend( 0.5*(np.sqrt(rArrExtend_np*rArrExtend_np-2.*M*rArrExtend_np) + rArrExtend_np - M))
# Appending a Python array does what one would reasonably expect.
# Appending a numpy array allocates space for a new array with size+1,
# then copies the data over... over and over... super inefficient.
mArr_np = np.array(mArr)
rArr_np = np.array(rArr)
PArr_np = np.array(PArr)
rbarArr_np = np.array(rbarArr)
rhoArr_np = (PArr_np/P0)**(1./gamma)
confFactor_np = rArr_np/rbarArr_np
#confFactor_np = (1.0 / 12.0) * np.log(1.0/(1.0 - 2.0*mArr_np/rArr_np))
Grr_np = 1.0/(1.0 - 2.0*mArr_np/rArr_np)
Gtt_np = phiArr_np
if( showPlot) :
r,rbar,rprop,rho,m,phi = np.loadtxt( compareFile, usecols=[0,1,2,3,4,5],unpack=True)
pl.plot(rArr_np[rArr_np < r[-1]], rbarArr_np[rArr_np < r[-1]],lw=2,color="black")
#pl.plot(r, rbar, lw=2,color="red")
pl.show()
if( dumpData) :
np.savetxt( "output.txt", np.transpose([rArr_np,rhoArr_np,PArr_np,mArr_np,phiArr_np,confFactor_np,rbarArr_np]), fmt="%.15e")
np.savetxt( "metric.txt", np.transpose([rArr_np, Grr_np, Gtt_np]),fmt="%.15e")
# np.savetxt( "output.txt", zip(rArr,rhoArr,mArr,phiArr), fmt="%12.7e")
# return rArr[-1], mArr[-1], phiArr[-1]
return R, M
mass = []
radius = []
R_TOV,M_TOV = integrateStar(pressure(rho_central), showPlot=True, dumpData=True)
print("Just generated a TOV star with r= "+str(R_TOV)+" , m = "+str(M_TOV)+" , m/r = "+str(M_TOV/R_TOV)+" .")
#for rho0 in np.arange(0.01, 1., 0.01):
# r,m = integrateStar(pressure(rho0))
# mass.append(m)
# radius.append(r)
#print(mass, radius)
#pl.clf()
#pl.plot(radius,mass)
#pl.show()
Just generated a TOV star with r= 0.9565681425227097 , m = 0.14050303285288188 , m/r = 0.1468824086931645 .
# Generate the Sedov Problem
rArr_np = np.arange(0.01,5.,0.01)
rbarArr_np = rArr_np
rhoArr_np = np.ones(rArr_np.size)*0.1
mArr_np = 4.*np.pi/3.*rArr_np**3*rhoArr_np
PArr_np = rhoArr_np*1e-6
PArr_np[rArr_np < 0.5] = 1e-2
phiArr_np = np.ones(rArr_np.size)
confFactor_np = rArr_np/rbarArr_np
if sys.version_info[0] < 3:
np.savetxt( "sedov.txt", zip(rArr_np,rhoArr_np,PArr_np,mArr_np,phiArr_np,confFactor_np,rbarArr_np), fmt="%.15e")
else:
np.savetxt( "sedov.txt", list(zip(rArr_np,rhoArr_np,PArr_np,mArr_np,phiArr_np,confFactor_np,rbarArr_np)), fmt="%.15e")
pl.semilogx(rArr_np, rhoArr_np)
pl.show()
Above, the line element was written: ds2=−c2eνdt2+(1−2GMrc2)−1dr2+r2dΩ2.
In terms of G=c=1 units adopted by NRPy+, this becomes: ds2=−eνdt2+(1−2Mr)−1dr2+r2dΩ2.
The ADM 3+1 line element for this diagonal metric in spherical coordinates is given by: ds2=(−α2+βkβk)dt2+γrrdr2+γθθdθ2+γϕϕdϕ2,
from which we can immediately read off the ADM quantities: α=eν/2βk=0γrr=(1−2Mr)−1γθθ=r2γϕϕ=r2sin2θ
The above metric is given in spherical coordinates and we need everything in Cartesian coordinates. Given this the transformation to Cartesian coordinates is gμν=Λμ′μΛν′νgμ′ν′,
import sympy as sp # SymPy: The Python computer algebra package upon which NRPy+ depends
import NRPy_param_funcs as par # NRPy+: parameter interface
from outputC import outputC # NRPy+: Basic C code output functionality
import indexedexp as ixp # NRPy+: Symbolic indexed expression (e.g., tensors, vectors, etc.) support
import reference_metric as rfm # NRPy+: Reference metric support
# The ADM & BSSN formalisms only work in 3D; they are 3+1 decompositions of Einstein's equations.
# To implement axisymmetry or spherical symmetry, simply set all spatial derivatives in
# the relevant angular directions to zero; DO NOT SET DIM TO ANYTHING BUT 3.
# Step 0: Set spatial dimension (must be 3 for BSSN)
DIM = 3
# Set the desired *output* coordinate system to Cylindrical:
par.set_parval_from_str("reference_metric::CoordSystem","Cartesian")
rfm.reference_metric()
CoordType_in = "Spherical"
r_th_ph_or_Cart_xyz_of_xx = []
if CoordType_in == "Spherical":
r_th_ph_or_Cart_xyz_of_xx = rfm.xxSph
elif CoordType_in == "Cartesian":
r_th_ph_or_Cart_xyz_of_xx = rfm.xx_to_Cart
Jac_dUSphorCart_dDrfmUD = ixp.zerorank2()
for i in range(DIM):
for j in range(DIM):
Jac_dUSphorCart_dDrfmUD[i][j] = sp.diff(r_th_ph_or_Cart_xyz_of_xx[i],rfm.xx[j])
Jac_dUrfm_dDSphorCartUD, dummyDET = ixp.generic_matrix_inverter3x3(Jac_dUSphorCart_dDrfmUD)
betaU = ixp.zerorank1()
gammaDD = ixp.zerorank2()
gammaSphDD = ixp.zerorank2()
grr, gthth, gphph = sp.symbols("grr gthth gphph")
gammaSphDD[0][0] = grr
gammaSphDD[1][1] = gthth
gammaSphDD[2][2] = gphph
betaSphU = ixp.zerorank1()
for i in range(DIM):
for j in range(DIM):
betaU[i] += Jac_dUrfm_dDSphorCartUD[i][j] * betaSphU[j]
for k in range(DIM):
for l in range(DIM):
gammaDD[i][j] += Jac_dUSphorCart_dDrfmUD[k][i]*Jac_dUSphorCart_dDrfmUD[l][j] * gammaSphDD[k][l]
outputC([gammaDD[0][0], gammaDD[0][1], gammaDD[0][2], gammaDD[1][1], gammaDD[1][2], gammaDD[2][2]],
["mi.gamDDxx", "mi.gamDDxy", "mi.gamDDxz", "mi.gamDDyy", "mi.gamDDyz","mi.gamDDzz"], filename="NRPY+spherical_to_Cartesian_metric.h")
Wrote to file "NRPY+spherical_to_Cartesian_metric.h"