예제 #1
0

thetamax = 0.7
n_steps = 5000
n_stars = 10000
# m_star = sc.Msol  # 3.181651515706176e+30
m_stars = MassDist.massSample(n_stars)
print(sum(m_stars)/len(m_stars))
m_BH = sc.Msgra  # / 1e4
mass_ratio = (sc.Mlummw - m_BH)/sum(m_stars)
print(mass_ratio)
m_stars = mass_ratio*m_stars
m_DM = (np.sum(m_stars) + m_BH)*5
galaxy, r_, vnorm = genDMGalaxy(10000, m_stars, m_BH, m_DM)

result = cs.LeapFrogSaveC(galaxy, dt=1e12, n_steps=1, thetamax=thetamax, G=sc.G, save_every=1, epsilon=4e18,
                          DM_mass=m_DM).numpy()

r = utils.get_positions(result)
r = np.linalg.norm(r[0], axis=1)
g = utils.get_vec_attribute(result, 'g')
plt.subplot(1,2,1)
plt.plot(r, np.linalg.norm(g[0], axis=1))
plt.subplot(1,2,2)
plt.plot(r, np.sqrt(r*np.linalg.norm(g[0], axis=1)), label='model')
plt.plot(r_, vnorm, label='theory')
plt.legend()
plt.show()
exit()

print("Done with step 1")
result = cs.LeapFrogSaveC(galaxy, dt=1e12, n_steps=n_steps, thetamax=thetamax, G=sc.G, save_every=10, epsilon=4e18,
예제 #2
0
    plt.scatter(v_x, v_y)
    plt.show()



    bodies = [cs.Body3(pos=np.zeros(3), vel=np.zeros(3), mass=M)]
    for i in range(1,n):
        bodies.append(cs.Body3(pos=posarray[i], vel=velarray[i], mass=massarray[i]))

    return cs.BodyList3(np.array(bodies))

thetamax = 0.5

n_steps = 500  # int(30/1e-4)
begin = time.time()
result = cs.LeapFrogSaveC(genEGalaxy(2,sc.Msgra,space=True,elliptical=True,spiralarms=2), 1e12, n_steps, thetamax, sc.G)
end = time.time()

s = utils.get_positions(result)
print(s)
print(s[100])
plt.scatter(s[0][:,0],s[0][:,1])
plt.show()

large_xyz = 1e20
medium_xyz = 1e19

large_limits = {"xlim": (-large_xyz, large_xyz), "ylim": (-large_xyz, large_xyz), "zlim": (-large_xyz, large_xyz)}
medium_limits = {"xlim": (-medium_xyz, medium_xyz), "ylim": (-medium_xyz, medium_xyz), "zlim": (-medium_xyz, medium_xyz)}
# plotting.movie3d(s, np.arange(2), until_timestep=1000, skip_steps=10, mode="line", **medium_limits)
    x = r*np.cos(theta)
    y = r*np.sin(theta)
    z = np.zeros(n_stars)
    positions = np.column_stack((x, y, z))
    v_norm = np.sqrt(sc.G*np.cumsum(masses)[:-1]/np.linalg.norm(positions, axis=1) + np.sqrt(sc.G*DM_mass*a_0))  # skip first cumsum value, since masses includes black hole
    v_unit_vec = np.column_stack((-np.sin(theta), np.cos(theta), np.zeros(n_stars)))
    velocities = v_norm.reshape((n_stars, 1)) * v_unit_vec
    positions = np.insert(positions, 0, np.zeros(3), 0)     # add black hole (already present in masses)
    velocities = np.insert(velocities, 0, np.zeros(3), 0)
    # print(velocities)
    # print(velocities*np.expand_dims(masses, axis=0).T)
    # print(np.sum(velocities*np.expand_dims(masses, axis=0).T, axis=0))
    return utils.zip_to_bodylist(positions, velocities, masses)


thetamax = 0.7
n_steps = 2000
m_star = sc.Msol  # 3.181651515706176e+30
M = 10000*m_star*100 + sc.Msgra
galaxy = genDMGalaxy(10000, m_star*100, sc.Msgra, M)

# cs.LeapFrogC(galaxy, 1e12, 5000, thetamax, sc.G)
print("Done with step 1")
result = cs.LeapFrogSaveC(galaxy, dt=1e12, n_steps=n_steps, thetamax=thetamax, G=sc.G, save_every=10, epsilon=4e16, DM_mass=M)
result.save("DM_test.binv")


# result = cs.Result.load("stable2.binv").numpy()
# print(result.shape)
# plotting.movie3d(result, [0], skip_steps=10)
예제 #4
0
import helper_files.galaxy_creator as gc
import barneshut_cpp.cppsim as cs
import helper_files.stellarConstants as sc
import numpy as np

cs.set_thread_count(8)
MW = gc.create_milky_way(1500, 3000)
MW.translate(
    np.array([-1, 0, 0]) * sc.ly * 1e6 / 2 + np.array([0, 2, 0]) * sc.ly * 1e5)
MW.add_velocity(np.array([1, 0, 0]) * 225e3 / 2)
AM = gc.create_andromeda(1500, 3000)
AM.translate(
    np.array([1, 0, 0]) * sc.ly * 1e6 / 2 - np.array([0, 2, 0]) * sc.ly * 1e5)
AM.add_velocity(np.array([-1, 0, 0]) * 225e3 / 2)
Collision = MW + AM
result = cs.LeapFrogSaveC(Collision,
                          dt=1e13,
                          n_steps=8000,
                          thetamax=0.7,
                          G=sc.G,
                          save_every=10,
                          epsilon=4e16)
result.save("collision.binv")
예제 #5
0
from helper_files.galaxy_creator import create_andromeda, create_milky_way
import barneshut_cpp.cppsim as cs
import helper_files.stellarConstants as sc
import numpy as np

cs.set_thread_count(8)


# Load galaxies
MW = cs.Result.load_last("MWMature.binv")
AM = cs.Result.load_last("AMMature.binv")

# Set collision course
MW.translate(np.array([-1, 0, 0])*sc.ly*1e6/1.5)
MW.add_velocity(np.array([1, 0, 0])*225e3/2)

AM.rotate(np.pi/6, np.zeros(3, dtype=np.double), np.array([1,1,0], dtype=np.double))
AM.translate(np.array([1, 0, 0])*sc.ly*1e6/1.5)
AM.add_velocity(np.array([-1, 0, 0])*225e3/2)

CC = MW + AM

result = cs.LeapFrogSaveC(CC, dt=1e13, n_steps=15000, thetamax=0.7, G=sc.G, save_every=100, epsilon=4e16)
result.save("Collision.binv")
예제 #6
0
import barneshut_cpp.cppsim as cs
import numpy as np
import matplotlib.pyplot as plt
from matplotlib import animation
import helper_files.sim_utils as utils
import time
import helper_files.render as render
import Scenarios.genGalaxy as gg
import helper_files.stellarConstants as sc

thetamax = 0.5

n_steps = 5000  # int(30/1e-4)
N = 10000
begin = time.time()
result = cs.LeapFrogSaveC(gg.genGalaxy(N, sc.Msgra, spherical=True), 1e12,
                          n_steps, thetamax, sc.G, 10)
end = time.time()
print("Simulation finished after", end - begin, "s")

result.save("testsave.binv")
print("Saved")
result = result.numpy()
s = utils.get_positions(result)
masses = utils.get_masses(result)[0]

plane = render.Plane(np.array([0, 0, 1]), np.array([0, 0, 0]),
                     np.array([5 / 10**18, 0, 0]), np.array([0, 5 / 10**18,
                                                             0]))
render.animate(s, masses, plane, 400, 400)
예제 #7
0
    v_unit_vec = np.column_stack((-np.sin(theta), np.cos(theta), np.zeros(n_stars)))
    velocities = v_norm.reshape((n_stars, 1)) * v_unit_vec
    positions = np.insert(positions, 0, np.zeros(3), 0)     # add black hole (already present in masses)
    velocities = np.insert(velocities, 0, -np.sum(velocities*m_star, axis=0)/m_bh, 0)
    print(velocities)
    print(velocities*np.expand_dims(masses, axis=0).T)
    print(np.sum(velocities*np.expand_dims(masses, axis=0).T, axis=0))
    return utils.zip_to_bodylist(positions, velocities, masses)


thetamax = 0.7
n_steps = 5000
m_star = sc.Msol  # 3.181651515706176e+30
galaxy1 = genStableGalaxy(10000, m_star, sc.Msgra)
galaxy2 = copy(galaxy1)

# Galaxy 1
print("Galaxy 1")
eps = 0.0
result = cs.LeapFrogSaveC(galaxy1, 1e12, n_steps, thetamax, sc.G, 10, eps)
result.save("stable_test.binv")

# Galaxy 2
print("Galaxy 2")
eps = 15e13
result = cs.LeapFrogSaveC(galaxy2, 1e12, n_steps, thetamax, sc.G, 10, eps)
result.save("stable_test_with_eps.binv")
# result = cs.Result.load("stable2.binv").numpy()
# print(result.shape)
# plotting.movie3d(result, [0], skip_steps=10)
예제 #8
0
    bodiesDM = []
    for i in range(0, nDM):
        bodiesDM.append(cs.Body3(pos=posarrayDM[i], vel=velarrayDM[i], mass=massarrayDM[i]))
    

    allbodies = np.concatenate((bodies,bodiesDM))
    print(len(allbodies))

    return cs.BodyList3(np.array(allbodies))

thetamax = 0.5

n_steps = 5000  # int(30/1e-4)
begin = time.time()

result = cs.LeapFrogSaveC(genDMG(100,M=sc.Msgra,spherical=True,nDM=1000), 1e12, n_steps, thetamax, sc.G)
end = time.time()
result.save("testDMG.binv")

r = utils.get_positions(result.numpy())
rnorm = np.sqrt(r[-1][:,0]**2+r[-1][:,1]**2+r[-1][:,2]**2)
rnormM = rnorm[0:100]
rnormDM = rnorm[101:1100]

v = utils.get_velocities(result.numpy())
vnorm = np.sqrt(v[-1][:,0]**2+v[-1][:,1]**2+v[-1][:,2]**2)
vnormM = vnorm[0:100]
vnormDM = vnorm[101:1100]
plt.scatter(rnormM,vnormM)
plt.scatter(rnormDM,vnormDM)
plt.show()
예제 #9
0
N = len(positions)

galaxy_bodies = utils.zip_to_bodylist(positions, velocities, masses)
galaxy1 = utils.rotate_bodylist(galaxy_bodies, np.pi / 4, np.array([-1, 0, 0]),
                                np.array([0, 1, 0]))
galaxy1 = utils.translate_bodylist(galaxy1, center1)
galaxy1 = utils.add_velocity_bodylist(galaxy1, v1)

galaxy2 = utils.translate_bodylist(galaxy_bodies, center2)
galaxy2 = utils.add_velocity_bodylist(galaxy2, v2)

total_bodylist = utils.concatenate_bodylists(galaxy1, galaxy2)
total_bodylist.check_integrity()
#total_bodylist.save("galaxies.bin")
results = cs.LeapFrogSaveC(total_bodylist, dt, n_steps, thetamax, G, 1, 0)
# for i in range(len(results)):
#     bl = cs.BodyList3(results[i, :])
#     bl.save(f"galaxies{i:3d}.bin")
# exit()
results.save("min.binv")
exit()
large_limits = {
    "xlim": (-1600, 1600),
    "ylim": (-1600, 1600),
    "zlim": (-1600, 1600)
}
s = utils.get_positions(results)
particles = [4 * n for n in range(2 * N // 4)
             ] + [N]  # 1 in 4 particles + second black hole
particle_config = [{"color": "k", "markersize": "10"}] + (N-1)*[{"color": "b"}] + [{"color": "k", "markersize": "10"}] \
예제 #10
0
thetaDM = np.random.uniform(0, 2 * np.pi, n_DM_particles)
phiDM = np.arccos(np.random.uniform(-1, 1, n_DM_particles))
rDM = DMrd.PIradSample(n_DM_particles, R_halo=18)

xDM = rDM * np.cos(thetaDM) * np.sin(phiDM)
yDM = rDM * np.sin(thetaDM) * np.sin(phiDM)
zDM = rDM * np.cos(phiDM)
posarrayDM = np.column_stack((xDM, yDM, zDM))

print('2')

dummy = gen_dummy(posarray, posarrayDM, m_stars, m_DM)
result = cs.LeapFrogSaveC(dummy,
                          dt=0,
                          n_steps=1,
                          thetamax=thetamax,
                          G=sc.G,
                          save_every=1,
                          epsilon=4e18).numpy()
g = np.linalg.norm(utils.get_vec_attribute(result, 'g')[0], axis=1)[1:]
print(len(g))
v_norm = np.sqrt(r * g[0:n_stars])
v_norm_DM = np.sqrt(rDM * g[n_stars:])
plt.subplot(121)
plt.hist(v_norm)
plt.subplot(122)
plt.hist(v_norm_DM)

v_unit_vec = np.column_stack(
    (-np.sin(theta), np.cos(theta), np.zeros(n_stars)))
velocities = v_norm.reshape((n_stars, 1)) * v_unit_vec
예제 #11
0
# ---mini-galaxy: bodies arranged in rings around a black hole---
m_BH = 100000  # mass of black hole
galaxy_bodies = [utils.make_body(np.zeros(3), np.zeros(3), m_BH)]  # black hole
for r in np.arange(1, 10) * 25:  # add stars
    for theta in np.linspace(0, 2 * np.pi, int(3 * r / 25))[:-1]:
        pos = np.array([r * np.sin(theta), r * np.cos(theta), 0],
                       dtype=np.double)
        v = np.array([np.cos(theta), -np.sin(theta), 0],
                     dtype=np.double) * np.sqrt(G * m_BH / r)
        m = np.double(10)
        galaxy_bodies.append(cs.Body3(pos, v, m))
bodylist = cs.BodyList3(np.array(galaxy_bodies))

n_steps = 3000  # int(30/1e-4)
begin = time.time()
result = cs.LeapFrogSaveC(bodylist, 1e-1, n_steps, thetamax, G)
end = time.time()
print("Simulation finished after", end - begin, "s")

s = utils.get_positions(result)

large_limits = {
    "xlim": (-1000, 1000),
    "ylim": (-1000, 1000),
    "zlim": (-1000, 1000)
}
medium_limits = {"xlim": (-300, 300), "ylim": (-300, 300), "zlim": (-300, 300)}
plotting.movie3d(s, [0, 2, 30, 60, -1],
                 until_timestep=1000,
                 skip_steps=10,
                 mode="line",