Esempio n. 1
0
def gen_galaxy(pos, DM_pos, m, mDM, mBH, v, vDM):
    """Generate a galaxy (Bodylist) of a massive black hole M and n stars, with initial positions, velocities and masses randomly distributed"""
    posarray = pos
    n = len(pos)
    nDM = len(DM_pos)
    massarray = m
    velarray = v
    bodies = [cs.Body3(pos=np.zeros(3), vel=np.zeros(3), mass=mBH)]
    for i in range(n):
        bodies.append(
            cs.Body3(pos=posarray[i], vel=velarray[i], mass=massarray[i]))

    posarrayDM = DM_pos
    massarrayDM = mDM

    bodiesDM = []
    velarrayDM = vDM
    for i in range(0, nDM):
        bodiesDM.append(
            cs.Body3(pos=posarrayDM[i],
                     vel=velarrayDM[i],
                     mass=massarrayDM[i],
                     dark_matter=True))

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

    return cs.BodyList3(np.array(allbodies))
Esempio n. 2
0
def genDMG(n, M=sc.Msgra, R=1, RD=sc.RDmw/sc.RCmw, spherical=False, nDM=0, rho0=1, Rs=10, c=12):
    """Generate a galaxy (Bodylist) of a massive black hole M and n stars, with initial positions, velocities and masses randomly distributed"""

    theta = np.random.uniform(0, 2 * np.pi, n)
    if spherical == True:
        phi = np.pi/2 - np.random.normal(0,0.1,n)
    else:
        phi = np.pi/2
    r = rd.radSample(R,RD,n)
    x = r * np.cos(theta) * np.sin(phi)
    y = r * np.sin(theta) * np.sin(phi)
    z = r * np.cos(phi)
    posarray = np.column_stack((x, y, z))

    v = np.sqrt(sc.G*M*(1/r))
    v_x = -np.sin(theta) * v
    v_y = np.cos(theta) * v
    v_z = np.zeros(n)
    velarray = np.column_stack((v_x, v_y, v_z))

    massarray = md.massSample(n)

    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]))


    thetaDM = np.random.uniform(0,2*np.pi,nDM)
    phiDM = np.random.uniform(0,np.pi,nDM)
    rDM = DMrd.DMradSample(nDM, rho0, Rs, c)
    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))

    vDM = np.sqrt(sc.G*M*(1/rDM))
    v_xDM = -np.sin(thetaDM) * vDM
    v_yDM = np.cos(thetaDM) * vDM
    v_zDM = np.zeros(nDM)
    velarrayDM = np.column_stack((v_xDM, v_yDM, v_zDM))

    massarrayDM = 100*md.massSample(nDM)

    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))
Esempio n. 3
0
def make_body(pos, vel, m, dark_matter=False):
    """A more flexible wrapper for the Body3 constructor. Accepts native python objects
     such as lists and floats, as well as numpy objects"""
    return cs.Body3(np.array(pos, dtype=np.double),
                    np.array(vel, dtype=np.double),
                    np.double(m),
                    dark_matter=dark_matter)
Esempio n. 4
0
def genEGalaxy(n,M=sc.Msgra,R=1,RD=sc.RDmw/sc.RCmw,space=False,elliptical=False,spiralarms=1):
    """Generate a galaxy (Bodylist) of a massive black hole M and n stars, with initial positions, velocities and masses randomly distributed"""

    massarray = md.massSample(n)

    if space == True:
        phi = np.pi/2 - np.random.normal(0,0.1,n)
    else:
        phi = np.pi/2

    if elliptical == True:
        spiral  = 1
        e = 0.5*np.ones(n)+np.random.normal(0,0.005,n)
    else:
        spiral = 0
        e = np.zeros(n)

    r = rd.radSample(n,R,RD)
    for i in range(len(r)):
        if r[i] <= sc.RCmw:
            theta = np.random.uniform(0,2*np.pi,n)
        else:
            theta = (1-spiral) * np.random.uniform(0, 2 * np.pi, n) + spiral * (-2*np.pi*r/np.amax(r)+np.pi/10*np.random.normal(0,1,n)+np.pi*np.random.randint(0,2,n))
    a = r/(1+e)
    x = r * np.cos(theta) * np.sin(phi)
    y = r * np.sin(theta) * np.sin(phi)
    z = r * np.cos(phi)
    posarray = np.column_stack((x, y, z))
    plt.scatter(x,y)
    plt.show()

    v = np.sqrt(sc.G*(M+massarray)*(2/r-1/a))
    v_x = -np.sin(theta) * v
    v_y = np.cos(theta) * v
    v_z = np.zeros(n)
    velarray = np.column_stack((v_x, v_y, v_z))
    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))
Esempio n. 5
0
# v0 = np.array([[0, 0, 0], [0, 100, 50], [-100, 0, 20], [-10, -30, 0]], dtype=np.double)
# m = np.array([1e6, 1, 10000, 10], dtype=np.double)
# bodylist = utils.zip_to_bodylist(r0, v0, m)
# N = len(bodylist)

# ---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)
}