示例#1
0
def fitting_method_subpart_skyrme(central_pressure, surface_guess, mass_guess,
                                  f1, f2, lst_x, lst_y, lst_z):
    fitting_point = surface_guess / 2.0
    small_x = 0.001
    yout, zout = central_pressure, 0
    xout = small_x
    num_steps = 400
    hsout = fitting_point / float(num_steps)
    lst_x.append(0)
    lst_y.append(yout)
    lst_z.append(zout)

    for j in range(num_steps):
        if xout + hsout - fitting_point > -0.00000001:
            hsout = fitting_point - xout
            xout, yout, zout = rungeKetta(xout, yout, zout, f1, f2, hsout, 0)
            lst_x.append(xout)
            lst_y.append(yout)
            lst_z.append(zout)
            break
        else:
            xout, yout, zout = rungeKetta(xout, yout, zout, f1, f2, hsout, 0)
            lst_x.append(xout)
            lst_y.append(yout)
            lst_z.append(zout)

    to_reverse_x = []
    to_reverse_y = []
    to_reverse_z = []
    xin = surface_guess
    yin, zin = 0, mass_guess
    hsin = -fitting_point / float(num_steps)
    to_reverse_x.append(xin)
    to_reverse_y.append(yin)
    to_reverse_z.append(zin)
    for i in range(num_steps):
        if fitting_point - (xin + hsin) > -0.000000001:
            hsin = fitting_point - xin
            xin, yin, zin = rungeKetta(xin, yin, zin, f1, f2, hsin, 0)
            break
        else:
            xin, yin, zin = rungeKetta(xin, yin, zin, f1, f2, hsin, 0)
            to_reverse_x.append(xin)
            to_reverse_y.append(yin)
            to_reverse_z.append(zin)
    to_reverse_x.reverse()
    to_reverse_y.reverse()
    to_reverse_z.reverse()
    lst_x.extend(to_reverse_x)
    lst_y.extend(to_reverse_y)
    lst_z.extend(to_reverse_z)
    Y = yin - yout
    Z = zin - zout
    return Y, Z
def fitting_method_subpart(zeta, sigma, f1, f2, lst_x, lst_y, lst_z, surface, G, total_mass):
	fitting_point = surface/2.0
	xout = 0
	yout = zeta
	zout = -5 * zeta
	num_steps = 100
	hsout = fitting_point/(num_steps)
	lst_x.append(xout)
	lst_y.append(yout)
	lst_z.append(zout)
	for j in range(num_steps):
		if xout + hsout - fitting_point > -0.00000001:
			hsout = fitting_point - xout
			xout, yout, zout = rungeKetta(xout, yout, zout, f1, f2, hsout, 2)
			lst_x.append(xout)
			lst_y.append(yout)
			lst_z.append(zout)
			break
		else:
			xout, yout, zout = rungeKetta(xout, yout, zout, f1, f2, hsout, 2)
			lst_x.append(xout)
			lst_y.append(yout)
			lst_z.append(zout)
		
	to_reverse_x = []
	to_reverse_y = []
	to_reverse_z = []
	xin = surface
	yin = 1
	zin = -(4 + (sigma**(2) * surface**(3)/(G * total_mass)))
	hsin = -fitting_point/(num_steps)
	to_reverse_x.append(xin)
	to_reverse_y.append(yin)
	to_reverse_z.append(zin)
	for i in range(num_steps):
		if fitting_point - (xin + hsin) > -0.000000001:
			hsin = fitting_point - xin
			xin, yin, zin = rungeKetta(xin, yin, zin, f1, f2, hsin, 2)
			break
		else:
			xin, yin, zin = rungeKetta(xin, yin, zin, f1, f2, hsin, 2)
			to_reverse_x.append(xin)
			to_reverse_y.append(yin)
			to_reverse_z.append(zin)
	to_reverse_x.reverse()
	to_reverse_y.reverse()
	to_reverse_z.reverse()
	lst_x.extend(to_reverse_x)
	lst_y.extend(to_reverse_y)
	lst_z.extend(to_reverse_z)
	Y = yin - yout
	Z = zin - zout
	return Y, Z
def one_direction_shot_adiabatic_radial(n=2):
 	lei= get_information_polytrope(n=n)
 	lst_M = lei[-1]
 	lst_P = lei[-2]
 	lst_rho = lei[-3]
 	lst_R = lei[-4]
 	total_mass = lei[-5]
 	surface = lei[-6]
 	G = lei[-7]
 	sigma_guess = (3.9 * G * total_mass * surface**(-3))
 	zeta_outside = 1
 	num_steps =300
 	hs = -surface/(num_steps)
 	for i in range(1000):
 		print(i)
 		R = surface
 		zeta = zeta_outside
 		delP = -(((sigma_guess * surface**(3))/(G * total_mass)) * zeta + 4 * zeta)
 		print(delP)
 		delPdr = createDelPdr(lst_P, lst_rho, lst_R, lst_M, G, sigma_guess, surface)
	 	for j in range(num_steps):
	 		R, zeta, delP = rungeKetta(R, zeta, delP, dcdr, delPdr, hs, n)
	 	bc = 3 * zeta + 0.6 * delP
	 	print(R)
	 	print(zeta)
	 	print(delP)
	 	delta = 0.001

	 	shiftsigma_guess = sigma_guess * (1 + delta)
	 	R = surface
	 	zeta = zeta_outside
 		delP = -(((shiftsigma_guess * surface**(3))/(G * total_mass)) * zeta + 4 * zeta)
 		newdelPdr = createDelPdr(lst_P, lst_rho, lst_R, lst_M, G, shiftsigma_guess, surface)
	 	for j in range(num_steps):
	 		R, zeta, delP = rungeKetta(R, zeta, delP, dcdr, newdelPdr, hs, n)
	 	sbc = 3 * zeta + 0.6 * delP

	 	print(bc)
	 	print(sbc)
	 	break
示例#4
0
def shooting_direct(central_density, f1, f2):
    small_x = 0.00001
    y, z = central_density, 0
    x = small_x
    approximate_radius = 2 * 10**(6)
    hs = approximate_radius / 1000
    lst_x = [0]
    lst_y = [central_density]
    lst_z = [0]
    for i in range(10000):
        x, y, z = rungeKetta(x, y, z, f1, f2, hs, gamma)
        lst_x.append(x)
        lst_y.append(y)
        lst_z.append(z)
        if abs(y) < 3 * hs and hs > (approximate_radius / 10000000):
            hs = hs / 2
        if y < 0.000001:
            break
    print("Surface at: ", x / (10**(5)))
    print("Total mass: ", z / mass_sun)
示例#5
0
def shooting_skyrme(central_pressure):
    small_x = 0.00001
    y, z = central_pressure, 0.0
    x = small_x
    approximate_radius = 2 * 10**(6)
    hs = approximate_radius / 1000
    hs = 1.15988 * 10**(2)
    lst_x = [0.0]
    lst_y = [central_pressure]
    lst_z = [0.0]
    lst_logbrunt = []
    lst_brunt = []
    lst_x_logbrunt = []
    lst_x_brunt = []
    lst_speed_sound = []
    lst_n = []
    lst_xp = []
    lst_xe = []
    lst_xmu = []
    lst_xn = []
    for i in range(10000):
        x, y, z = rungeKetta(x, y, z, dPSkyrme, dMSkyrme, hs, gamma)
        print(x)
        lst_x.append(x)
        lst_y.append(y)
        lst_z.append(z)
        g = (z * G) / (x**(2))
        try:
            curr_n = extract_n_pressure(y)
            if rho(curr_n) > 10**(14):
                xp, xe, xmu, xn = get_I(curr_n, sc=True)
                lst_xp.append(xp)
                lst_xe.append(xe)
                lst_xmu.append(xmu)
                lst_xn.append(xn)
                lst_n.append(curr_n)

                adiabatic_speed = get_v_adiabatic(curr_n)
                xdiff, ydiff, zdiff = rungeKetta(x, y, z, dPSkyrme, dMSkyrme,
                                                 0.1, gamma)
                n_diff = extract_n_pressure(ydiff)
                equilibrium_ratio = (ydiff - y) / (
                    (energy_density(n_diff) - energy_density(curr_n)))
                if adiabatic_speed / c > 1:
                    print(adiabatic_speed / c)
                    print('Adiabatic speed suspicious')
                elif equilibrium_ratio > 1:
                    print(equilibrium_ratio)
                    print('Equilibrium speed suspicious')
                equilibrium_speed = c * equilibrium_ratio
                brunt = (g**(2) * ((1 / equilibrium_speed)**(2) -
                                   (1 / adiabatic_speed)**(2)))**(0.5)
                lst_x_logbrunt.append(x)
                lst_logbrunt.append(math.log(brunt, 10))
                lst_speed_sound.append(adiabatic_speed)
                if brunt < 10**(4.5):
                    lst_x_brunt.append(x)
                    lst_brunt.append(brunt)

        except Exception as e:
            value = 2
        if abs(y) < 2 * hs and hs > (approximate_radius / 10, 000, 000):
            hs = hs / 2
        if y < 0.000001:
            break
        if x > 10**(4):
            break
    #print(y)
    print("Surface at: ", x / (10**(5)))
    print("Total mass: ", z / mass_sun)
    #return lst_n, lst_xp, lst_xe, lst_xmu, lst_xn
    #return [x/(10**(5)), z/mass_sun]
    lst_xrho = []
    lst_rho = []
    lst_P = []
    for i in range(len(lst_y)):
        try:
            curr_n = extract_n_pressure(lst_y[i])
            curr_rho = rho(curr_n)
            lst_P.append(lst_y[i])
            lst_rho.append(curr_rho)
            lst_xrho.append(lst_x[i])
        except:
            pass
    print(lst_x[:5])
    print(lst_y[:5])
    lst_mass = [lst_z[i] / mass_sun for i in range(len(lst_z))]
    print(lst_mass[:5])
    return lst_x_brunt, lst_brunt, lst_x_logbrunt, lst_logbrunt, lst_xrho, lst_rho, lst_P
示例#6
0
def shooting_skyrme(central_pressure):
    small_x = 0.00001
    y, z = central_pressure, 0.0
    x = small_x
    approximate_radius = 2 * 10**(6)
    hs = approximate_radius / 1000
    hs = 1.15988 * 10**(2)
    lst_x = [0.0]
    lst_y = [central_pressure]
    lst_z = [0.0]
    lst_logbrunt = []
    lst_brunt = []
    lst_x_logbrunt = []
    lst_x_brunt = []
    lst_speed_sound = []
    lst_eq_speed = []
    lst_n = []
    lst_xp = []
    lst_xe = []
    lst_xmu = []
    lst_xn = []
    lst_g = []
    lst_rho2 = []
    for i in range(10000):
        x, y, z = rungeKetta(x, y, z, dPSkyrme, dMSkyrme, hs, gamma)
        print(x)
        lst_x.append(x)
        lst_y.append(y)
        lst_z.append(z)
        g = (z * G) / (x**(2))
        lst_g.append(g**(2))
        try:
            curr_n = extract_n_pressure(y / conversion_pressure)
            if rho(curr_n) > 1.6 * 10**(14):
                xp, xe, xmu, xn = get_I(curr_n, sc=True)
                lst_xp.append(xp * curr_n * 10**(39))
                lst_xe.append(xe * curr_n * 10**(39))
                lst_xmu.append(xmu * curr_n * 10**(39))
                lst_xn.append(xn * curr_n * 10**(39))
                lst_n.append(curr_n * 10**(39))

                adiabatic_speed = get_v_adiabatic(curr_n)
                xdiff, ydiff, zdiff = rungeKetta(x, y, z, dPSkyrme, dMSkyrme,
                                                 10, gamma)
                n_diff = extract_n_pressure(ydiff / conversion_pressure)
                equilibrium_ratio = (ydiff - y) / (
                    conversion_pressure *
                    (energy_density(n_diff) - energy_density(curr_n)))
                if adiabatic_speed / c > 1:
                    print(adiabatic_speed / c)
                    print('Adiabatic speed suspicious')
                elif equilibrium_ratio > 1:
                    print(equilibrium_ratio)
                    print('Equilibrium speed suspicious')
                equilibrium_speed = c * equilibrium_ratio
                lst_eq_speed.append(equilibrium_speed**(2))
                brunt = (g**(2) * ((1 / equilibrium_speed)**(2) -
                                   (1 / adiabatic_speed)**(2)))**(0.5)
                lst_x_logbrunt.append(x)
                lst_logbrunt.append(math.log(brunt, 10))
                lst_speed_sound.append(adiabatic_speed**(2))
                lst_x_brunt.append(x)
                lst_brunt.append(brunt**(2))
                lst_rho2.append(rho(curr_n))

        except Exception as e:
            value = 2
        if abs(y) < 2 * hs and hs > (approximate_radius / 10, 000, 000):
            hs = hs / 2
        if y < 0.000001:
            break
    #print(y)

    print("Surface at: ", x / (10**(5)))
    print("Total mass: ", z / mass_sun)
    #return lst_n, lst_xp, lst_xe, lst_xmu, lst_xn
    #return [x/(10**(5)), z/mass_sun]
    lst_mass = [lst_z[i] / mass_sun for i in range(len(lst_z))]

    surface = x
    total_mass = z
    lst_r = lst_x
    lst_m = lst_z
    lst_moverM = [-29.0]
    for i in range(1, len(lst_m)):
        lst_moverM.append(math.log(lst_m[i] / total_mass))
    lst_P = lst_y
    lst_rho = []
    for i in range(len(lst_P)):
        try:
            val = getrho(lst_P[i])
            if val > 3 * 10**(14):
                lst_rho.append(val)
            else:
                lst_rho.append(getRhoBSM(lst_P[i]))
        except:
            try:
                val = getRhoBSM(lst_P[i])
                lst_rho.append(val)
            except:
                val = getRhoPoly(lst_P[i])
                lst_rho.append(val)
    adiabatic_exp = []
    adiabatic_val = 0
    for i in range(len(lst_rho)):
        y = lst_P[i]
        try:
            curr_n = extract_n_pressure(y / conversion_pressure)
            adiabatic_speed = get_v_adiabatic(curr_n)
            adiabatic_val = adiabatic_speed * (lst_rho[i] / y)
            adiabatic_exp.append(adiabatic_val)
        except:
            if i != (len(lst_rho) - 1):
                top = lst_P[i + 1] - lst_P[i - 1]
                bot = lst_rho[i + 1] - lst_rho[i - 1]
                adiabatic_val = top / bot * (lst_rho[i] / y)
                adiabatic > exp.append(adiabatic_val)
            else:
                adiabatic_exp.append(adiabatic_val)
    deriv_diff = []
    diff_val = 0
    for i in range(len(lst_r)):
        if i != (len(lst_r) - 1):
            top1 = lst_P[i + 1] - lst_P[i]
            top2 = lst_rho[i + 1] - lst_rho[i]
            bot = lst_r[i + 1] - lst_r[i]
            term1 = (1. / adiabatic_exp[i]) * (top1 / bot) * (lst_r[i] /
                                                              lst_P[i])
            term2 = (top2 / bot) * (lst_r[i] / lst_rho[i])
            diff_val = term1 - term2
            deriv_diff.append(diff_val)
        else:
            deriv_diff.append(diff_val)

    lst_Rminusr = [surface - lst_x[i] for i in range(len(lst_r))]
    print(len(lst_r))
    print(len(lst_moverM))
    print(len(lst_P))
    print(len(lst_rho))
    print(len(adiabatic_exp))
    print(len(deriv_diff))
    print(len(lst_Rminusr))
    print('writing')
    file = open('skyrme.fgong', 'w')
    nl = "\n"
    file.write("fee" + nl)
    file.write("fi" + nl)
    file.write("fo" + nl)
    file.write("fum" + nl)
    separator = " "
    file.write(
        str(len(lst_r)) + separator + "15" + separator + "40" + separator +
        "1300" + nl)
    empty_val = str(0.0) + separator
    file.write(
        str(total_mass) + separator + str(surface) + separator +
        get_n_copies(empty_val, 12) + str(0.0) + nl)
    for i in range(len(lst_r)):
        print(i)
        full_string = ""
        full_string = full_string + str(lst_r[i]) + separator + str(
            lst_moverM[i]) + separator
        full_string = full_string + empty_val
        full_string = full_string + str(lst_P[i]) + separator + str(
            lst_rho[i]) + separator
        full_string = full_string + get_n_copies(empty_val, 4)
        full_string = full_string + str(adiabatic_exp[i]) + separator
        full_string = full_string + get_n_copies(empty_val, 4)
        full_string = full_string + str(deriv_diff[i]) + separator
        full_string = full_string + get_n_copies(empty_val, 2)
        full_string = full_string + str(lst_Rminusr[i]) + separator
        full_string = full_string + get_n_copies(empty_val, 21)
        full_string = full_string + str(0.0) + nl
        file.write(full_string)
    file.close()
    return surface, total_mass, lst_r, lst_moverM, lst_P, lst_rho, adiabatic_exp, deriv_diff, lst_Rminusr