return z


def g(x, y, z):
    a = (-5.0 / 9.0) * y**(-4.0 / 3.0) * (1.0 + y**(2.0 / 3.0))**(
        -1.0 / 2.0) - (2.0 / 3.0) * y**(-2.0 / 3.0) * (1.0 + y**(2.0 / 3.0))**(
            -3.0 / 2.0) + (1.0 / 3.0) * (1.0 + y**(2.0 / 3.0))**(-5.0 / 2.0)
    b = (5.0 /
         3.0) * y**(-1.0 / 3.0) * (1.0 + y**(2.0 / 3.0))**(-1.0 / 2.0) - (
             1.0 / 3.0) * y**(1.0 / 3.0) * (1.0 + y**(2.0 / 3.0))**(-3.0 / 2.0)
    #print(x, y, z)
    return (-2.0 / x * z) - (a / b) * z**2.0 - (1.0 / b) * y
    #x_start, x_end, h, y0, z0,  f, g


eta2, varrho2, tmp = phy4910.ode_rk4(0.00001, 6, 0.001, 1.0, 0.0, f, g)

y0 = 1.0
varrho_min = varrho2[varrho2 > y0 * 0.001]
eta2_min = eta2[varrho2 > y0 * 0.001]
G = 6.674E-8

print(eta2_min[-1])

k_nr = 3.166E12
k_r = 4.936E14
rho_0 = 3.789E6
lam = ((k_nr * rho_0**(-1.0 / 3.0)) / (4.0 * sp.pi * G))**(1.0 / 2.0)

dm = simps(varrho_min * eta2_min**2.0, eta2_min)
print(f"Dimensionless mass equals {dm}")
def f(eta, varrho, sigma):
    return sigma


def g(eta, varrho, sigma):
    return -2.0 / eta * sigma - pow(varrho, n)


def stop(x, y, z, data):
    return False


# solve the Lane-Emden equation using Runge-Kutta

eta, varrho, sigma = phy4910.ode_rk4(0.000000001, 8.0, 0.001, 1.0, 0.0, f, g,
                                     stop, None)

phy4910.plot_print(eta, varrho, "A1_B1.pdf", r"$\eta$", r"$\varrho$")

# where is the surface?  We can find it by keeping only the positive values of varrho.
# Warning: this assumes that the density function doesn't later on go positive again (i.e. oscillate)
condition = varrho > 0.0
eta = eta[condition]
varrho = varrho[condition]

surface = eta[-1]
print(f"Surface at {surface:.3f}")

# now do the integration
m = np.trapz(np.power(varrho, n) * eta**2, eta)
print(f"The dimensionless mass is {m:.3f}")
G = 6.6743e-8  # cgs units
M_sun = 1.989e33  # grams
R_sun = 6.957e10  # cm


def f(eta, varrho, sigma):
    return sigma


def g(eta, varrho, sigma):
    return -2.0 / eta * sigma - pow(varrho, n)


# solve the Lane-Emden equation using Runge-Kutta

eta, varrho, sigma = phy4910.ode_rk4(0.000000001, 4.0, 0.00001, 1.0, 0.0, f, g)

phy4910.plot_print(eta, varrho, "A1_A1.pdf", r"$\eta$", r"$\varrho$")

# where is the surface?  We can find it by keeping only the positive values of varrho.
# Warning: this assumes that the density function doesn't later on go positive again (i.e. oscillate)
condition = varrho > 0.0
eta = eta[condition]
varrho = varrho[condition]

surface = eta[-1]
print(f"Surface at {surface:.3f}")

# now do the integration
m = np.trapz(np.power(varrho, n) * eta**2, eta)
print(f"The dimensionless mass is {m:.3f}")
import phy4910
import matplotlib
import matplotlib.pyplot as plt
from scipy.integrate import simps


n = 1.5

def f(x, y, z):
    return z;
    
def g(x, y, z):
    #print(x, y, z, n)
    return -2.0 / x * z - np.power(y, n);

eta2, rho2, tmp = phy4910.ode_rk4(0.00001, 3.65401, 0.001, 1.0, 0.0, f, g)

varrho = np.power(rho2,n)
dm = simps(varrho * eta2**2, eta2)
print(f"Dimensionless mass equals {dm}")

rhoc= 4.04636E6
lam = 2.434E8

fig = plt.figure(figsize=(6, 4))
ax = fig.add_subplot(1,1,1)
ax.grid(True)

ax.plot(eta2*lam, rho2**n *rhoc, color='blue')
plt.xlabel('r')
plt.ylabel(r'$\rho$')
Exemple #5
0
import matplotlib.pyplot as plt
from scipy.integrate import simps

n = 3.0


def f(x, y, z):
    return z


def g(x, y, z):
    #print(x, y, z, n)
    return -2.0 / x * z - np.power(y, n)


eta2, rho2, tmp = phy4910.ode_rk4(0.00001, 6.90, 0.001, 1.0, 0.0, f, g)

varrho = np.power(rho2, n)
dm = simps(varrho * eta2**2, eta2)
#print(f"Dimensionless mass equals {dm}")

rhoc = 5.33E7
lam = 4.885199E10 * rhoc**(-1 / 3)

fig = plt.figure(figsize=(6, 4))
ax = fig.add_subplot(1, 1, 1)
ax.grid(True)

ax.plot(eta2, rho2, color="red")
plt.xlabel(r'$\eta (Dimensionless radius)$')
plt.ylabel(r'$\varrho$ (Dimensionless Density')
N = 25
rho_c = np.logspace(4, 12, num=N)
dm = np.zeros(N)
rho_0 = 3.789E6
d_rho_c = rho_c / rho_0  #This is to get dimensionless central density
mass = np.zeros(N)
radius = np.zeros(N)
k_nr = 3.166E12
k_r = 4.936E14
G = 6.674E-8
smconv = 1.989E33  # g
lam = ((k_nr * rho_0**(-1.0 / 3.0)) / (4.0 * sp.pi * G))**(1.0 / 2.0)
srconv = 6.957E10  #cm

for i in range(N):
    eta2, varrho2, tmp = phy4910.ode_rk4(0.00001, 20, 0.0001, d_rho_c[i], 0.0,
                                         f, g)
    varrho_min = varrho2[varrho2 > d_rho_c[i] * 0.001]
    eta2_min = eta2[varrho2 > d_rho_c[i] * 0.001]
    dm[i] = simps(varrho_min * eta2_min**2.0, eta2_min)
    mass[i] = (sp.pi * 4.0 * rho_0 * dm[i] * lam**3.0) / smconv
    radius[i] = (lam * eta2_min[-1]) / srconv
"""print(f"Dimensionless mass equals {dm}")
print (lam)
print (mass)
print (radius)"""

fig = plt.figure(figsize=(6, 4))
ax = fig.add_subplot(1, 1, 1)
ax.grid(True)

ax.semilogx(d_rho_c, mass, '.', color="red")