Ejemplo n.º 1
0
def SpiralGalaxy(num):
    alpha = -2*4
    r0 = 2e6
    eps = 1e-3
    randarr1 = np.random.rand(num)
    randarr2 = np.random.rand(num)
    K = 0.3*r0
    #f_r = lambda r: 1/r0*np.exp(-r/r0)
    #f_phi = lambda r: (np.sin(phi))**2
    F_r = lambda r: 1-np.exp(-(r-K)/r0)
    F_r = np.vectorize(F_r)
    F_phi = lambda phi: 1/np.pi*(0.5*phi-0.25*np.sin(2*phi))
    F_phi = np.vectorize(F_phi)
    Finv_r = lambda p: -r0*np.log(1-p)+K
    Finv_r = np.vectorize(Finv_r)
    Finv_phi = lambda p: opt.newton((lambda x: F_phi(x)-p), p,tol = eps)
    Finv_phi = np.vectorize(Finv_phi)
#    p = np.arange(0.01,1,0.01)
#    plt.plot(Finv_phi(p),p)
#    x = np.arange(0,2*np.pi,0.1)
#    plt.plot(x, F_phi(x))
#    plt.show()
    rarr = Finv_r(randarr1)
    phiarr = Finv_phi(randarr2)
    pos = np.array([[rarr[i]*np.cos(phiarr[i]+alpha*np.log(rarr[i])),rarr[i]*np.sin(phiarr[i]+alpha*np.log(rarr[i])),0] for i in range(len(randarr1))])
    v = lambda r: np.sqrt(G*m*num*F_r(r)/r)
    vel = np.array([[v(rarr[i])*(-np.sin(phiarr[i]+alpha*np.log(rarr[i]))),v(rarr[i])*(np.cos(phiarr[i]+alpha*np.log(rarr[i]))),0] for i in range(len(randarr1))])
    col = np.array([[0.75-0.25*np.sin(phiarr[i]),0.75-0.25*np.sin(phiarr[i]+2*np.pi/3),0.75-0.25*np.sin(phiarr[i]-2*np.pi/3)] for i in range(len(randarr1))])
    radius = RADIUS*np.ones((num,1))
    mass = m*np.ones((pos.shape[0], 1))
    return Bodies(pos, vel, mass = mass, radius=radius, dt=DT, color = col)
Ejemplo n.º 2
0
def motionless(num):
    randarr = np.random.rand(num, 2)
    pos = np.array([(STARTSIZE * rand[0] * np.cos(2 * np.pi * rand[1]),
                     STARTSIZE * rand[0] * np.sin(2 * np.pi * rand[1]), 0)
                    for rand in randarr])
    VEL = 0
    vel = np.array([(-VEL * np.sin(2 * np.pi * rand[1]),
                     VEL * np.cos(2 * np.pi * rand[1]), 0)
                    for rand in randarr])
    return Bodies(pos, vel, radius=RADIUS, dt=DT)
Ejemplo n.º 3
0
def randombodiesUnif(num):
    randarr = np.random.rand(num, 2)
    pos = np.array([(STARTSIZE * rand[0] * np.cos(2 * np.pi * rand[1]),
                     STARTSIZE * rand[0] * np.sin(2 * np.pi * rand[1]), 0)
                    for rand in randarr])
    VEL = np.sqrt(G * MASS * N / STARTSIZE)
    vel = np.array([(-VEL * np.sin(2 * np.pi * rand[1]),
                     VEL * np.cos(2 * np.pi * rand[1]), 0)
                    for rand in randarr])
    return Bodies(pos, vel, radius=RADIUS, dt=DT)
Ejemplo n.º 4
0
def RBDonutBlackHole(num):
    randarr = np.random.rand(num,2)
    pos = np.array([[(A + (B-A)*rand[0])*np.cos(2*np.pi*rand[1]),(A + (B-A)*rand[0])*np.sin(2*np.pi*rand[1]) ,np.random.normal(0,WITH) ] for rand in randarr])
    v = lambda r: np.sqrt(G*M/r+G*m*num*(r-A)/((B-A)*r))
    vel = np.array([[v(A+(B-A)*rand[0])*(-np.sin(2*np.pi*rand[1])),v(A+(B-A)*rand[0])*(np.cos(2*np.pi*rand[1])),0] for rand in randarr])
    col = np.array([[0.75-0.25*np.sin(2*np.pi*rand[1]),0.75-0.25*np.sin(2*np.pi*rand[1]+2*np.pi/3),0.75-0.25*np.sin(2*np.pi*rand[1]-2*np.pi/3)] for rand in randarr])
    radius = RADIUS*np.ones((num,1))
    pos2 = np.concatenate((np.array([[0,0,0]]), pos), axis=0)
    vel2 = np.concatenate((np.array([[0,0,0]]), vel), axis=0)
    mass2 = np.concatenate((M*np.ones((1,1)),m*np.ones((pos.shape[0], 1))), axis=0)
    col2 = np.concatenate((np.array([[0.2,0.2,0.2]]), col), axis=0)
    radius2 = np.concatenate((np.array([[5*RADIUS]]),radius), axis = 0)
    return Bodies(pos2, vel2, mass = mass2, radius=radius2, dt=DT, color = col2)
Ejemplo n.º 5
0
def randomBodiesBlackHole(num):
    vel=np.zeros((num,3))
    pos = (np.random.rand(num, 3))
    for i in range(0,num):
        pos[i][-1]=0
        (pos[i][0],pos[i][1])=(pos[i][0]*STARTSIZE*np.cos(2*np.pi*pos[i][1]),pos[i][0]*STARTSIZE*np.sin(2*np.pi*pos[i][1]))
        vel[i][0]=pos[i][1]*np.sqrt(G*m*N/STARTSIZE)/np.sqrt((pos[i][0])**2+(pos[i][1])**2)
        vel[i][1]=-pos[i][0]*np.sqrt(G*m*N/STARTSIZE)/np.sqrt((pos[i][0])**2+(pos[i][1])**2)
    print(pos.shape)
    print(np.array([[0,0,0]]).shape)
    pos2 = np.concatenate((np.array([[0,0,0]]), pos), axis=0)
    vel2 = np.concatenate((np.array([[0,0,0]]), vel), axis=0)
    mass2 = np.concatenate((M*np.ones((1,1)),m*np.ones((pos.shape[0], 1))), axis=0)
    return Bodies(pos2, vel2, mass = mass2, radius=RADIUS, dt=DT)
Ejemplo n.º 6
0
def RBDonut(num):
    randarr = np.random.rand(num, 2)
    pos = np.array([[(A + (B - A) * rand[0]) * np.cos(2 * np.pi * rand[1]),
                     (A + (B - A) * rand[0]) * np.sin(2 * np.pi * rand[1]),
                     np.random.normal(0, WITH)] for rand in randarr])
    v = lambda r: np.sqrt(G * m * num * (r - A) / ((B - A) * r))
    vel = np.array([[
        v(A + (B - A) * rand[0]) * (-np.sin(2 * np.pi * rand[1])),
        v(A + (B - A) * rand[0]) * (np.cos(2 * np.pi * rand[1])), 0
    ] for rand in randarr])
    col = np.array([[
        0.75 - 0.25 * np.sin(2 * np.pi * rand[1]),
        0.75 - 0.25 * np.sin(2 * np.pi * rand[1] + 2 * np.pi / 3),
        0.75 - 0.25 * np.sin(2 * np.pi * rand[1] - 2 * np.pi / 3)
    ] for rand in randarr])
    radius = RADIUS * np.ones((num, 1))
    mass = m * np.ones((pos.shape[0], 1))
    return Bodies(pos, vel, mass=mass, radius=radius, dt=DT, color=col)
Ejemplo n.º 7
0
def SpiralGalaxyBlackHole3D(num):
    alpha = -2*2
    r0 = 5e7
    eps = 1e-3
    M = 15 * num * m
    randarr1 = np.random.rand(num)
    randarr2 = np.random.rand(num)
    K = 0.25*r0
    #f_r = lambda r: 1/r0*np.exp(-r/r0)
    #f_phi = lambda r: (np.sin(phi))**2
    F_r = lambda r: 1-np.exp(-(r-K)/r0)
    F_r = np.vectorize(F_r)
    F_phi = lambda phi: 1/np.pi*(0.5*phi-0.25*np.sin(2*phi))
    F_phi = np.vectorize(F_phi)
    Finv_r = lambda p: -r0*np.log(1-p)+K
    Finv_r = np.vectorize(Finv_r)
    Finv_phi = lambda p: opt.newton((lambda x: F_phi(x)-p), p,tol = eps)
    Finv_phi = np.vectorize(Finv_phi)
#    p = np.arange(0.01,1,0.01)
#    plt.plot(Finv_phi(p),p)
#    x = np.arange(0,2*np.pi,0.1)
#    plt.plot(x, F_phi(x))
#    plt.show()
    rarr = Finv_r(randarr1)
    phiarr = Finv_phi(randarr2)
    pos = np.array([[rarr[i]*np.cos(phiarr[i]+alpha*np.log(rarr[i])),rarr[i]*np.sin(phiarr[i]+alpha*np.log(rarr[i])),np.random.normal(0,WITH)] for i in range(len(randarr1))])
    v = lambda r: np.sqrt( G*m*F_r(r)/r+ G*M/r)
    vel = np.array([[v(rarr[i])*(-np.sin(phiarr[i]+alpha*np.log(rarr[i]))),v(rarr[i])*(np.cos(phiarr[i]+alpha*np.log(rarr[i]))),0] for i in range(len(randarr1))])
    col = np.array([[0.75-0.25*np.sin(phiarr[i]),0.75-0.25*np.sin(phiarr[i]+2*np.pi/3),0.75-0.25*np.sin(phiarr[i]-2*np.pi/3)] for i in range(len(randarr1))])
    radius = RADIUS*np.ones((num,1))
    #mass = m*np.ones((pos.shape[0], 1))
    pos2 = np.concatenate((np.array([[0,0,0]]), pos), axis=0)
    vel2 = np.concatenate((np.array([[0,0,0]]), vel), axis=0)
    mass2 = np.concatenate((M*np.ones((1,1)),m*np.ones((pos.shape[0], 1))), axis=0)
    col2 = np.concatenate((np.array([[0.2,0.2,0.2]]), col), axis=0)
    radius2 = np.concatenate((np.array([[5*RADIUS]]),radius), axis = 0)
    
    return Bodies(pos2, vel2, mass = mass2, radius=radius2, dt=DT, color = col2)