Exemple #1
0
def new_disk_with_bump(Mstar=1 | units.MSun,
                       Ndisk=100,
                       Mdisk=0.9 | units.MSun,
                       Rmin=1.0 | units.AU,
                       Rmax=100.0 | units.AU,
                       Mbump=0.1 | units.MSun,
                       Rbump=10.0 | units.AU,
                       abump=10 | units.AU):

    converter = nbody_system.nbody_to_si(Mdisk, Rmin)
    from amuse.ext.protodisk import ProtoPlanetaryDisk
    bodies = ProtoPlanetaryDisk(Ndisk,
                                convert_nbody=converter,
                                densitypower=1.5,
                                Rmin=1,
                                Rmax=Rmax / Rmin,
                                q_out=1.0,
                                discfraction=1.0).result
    Mdisk = bodies.mass.sum()
    bodies.move_to_center()
    com = bodies.center_of_mass()

    mm = Mdisk / float(Ndisk)
    Nbump = Mbump / mm
    bump = new_plummer_gas_model(Nbump,
                                 convert_nbody=nbody_system.nbody_to_si(
                                     Mbump, Rbump))

    bump.x += abump
    r_bump = abump
    inner_particles = bodies.select(lambda r: (com - r).length() < abump,
                                    ["position"])
    M_inner = inner_particles.mass.sum() + Mstar

    v_circ = (constants.G * M_inner *
              (2. / r_bump - 1. / abump)).sqrt().value_in(units.kms)
    bump.velocity += [0, v_circ, 0] | units.kms
    bodies.add_particles(bump)

    bodies = bodies.select(lambda r: (com - r).length() > Rmin, ["position"])
    bodies = bodies.select(lambda r: (com - r).length() < Rmax, ["position"])

    print("Nbump=", Ndisk, Mbump, Rbump, Nbump)
    print("Mass =", Mstar, Mdisk,
          bodies.mass.sum().in_(units.MSun),
          bodies.mass.sum() / Mstar)

    print("X-min/max:", min(bodies.x), max(bodies.x))
    bodies = bodies.select(lambda r: r.length() < 1.0 * Rmax, ["position"])
    print("X-min/max:", min(bodies.x), max(bodies.x))

    return bodies
Exemple #2
0
def initial_conditions(Q, N, Rmax, diskmassfrac, seed_disk):
    '''
	returns Sun + 8 planets, as well as a disk around Neptune
	'''

    #get the solar system objects

    sun_and_planets = new_solar_system()

    #throw out Pluto, get Neptune object from new_solar_system
    N_particles = len(sun_and_planets)
    sun_and_planets = sun_and_planets[:N_particles - 1]
    Nep_ind = len(sun_and_planets) - 1
    Sun = sun_and_planets[0]
    Neptune = sun_and_planets[Nep_ind]

    #hill radius of Neptune
    a_Neptune = np.sqrt(Neptune.x**2 + Neptune.y**2 + Neptune.z**2)
    Neptune_Hill = a_Neptune * (Neptune.mass / Sun.mass)**(1 / 3.)

    #get the disk with appropriate Salpeter mass distribution

    #Salpeter mass function with a range of 1 order of magnitude
    mmin = 0.0005 * Neptune.mass  #mmax goes to 0.005
    masses = new_salpeter_mass_distribution(N,
                                            mass_min=mmin,
                                            mass_max=(10 * mmin))

    #set up converter, protoplanetary disk gas particles
    np.random.seed(seed_disk)  #random seed for the disk
    converter_gas = nbody_system.nbody_to_si(Neptune.mass, Rmax | units.AU)
    gas = ProtoPlanetaryDisk(N,
                             convert_nbody=converter_gas,
                             Rmin=converter_gas.to_nbody(Neptune_Hill).number,
                             Rmax=converter_gas.to_nbody(Rmax
                                                         | units.AU).number,
                             q_out=Q,
                             discfraction=diskmassfrac).result

    #attribute Salpeter masses to the gas
    gas.mass = masses

    #move disk to Neptune's phase space coordinates
    gas.x += Neptune.x
    gas.y += Neptune.y
    gas.z += Neptune.z
    gas.vx += Neptune.vx
    gas.vy += Neptune.vy
    gas.vz += Neptune.vz

    return sun_and_planets, gas
Exemple #3
0
def new_disk_with_bump(Mstar = 10|units.MSun,
                       Ndisk=100, Mdisk=1.0|units.MSun, 
                       Rmin=1.0|units.AU, Rmax=100.0|units.AU, 
                       Mbump=0.1|units.MSun,Rbump=5.0|units.AU, 
                       abump=10|units.AU):

    converter=nbody_system.nbody_to_si(Mstar, Rmin)
    disk = ProtoPlanetaryDisk(Ndisk, convert_nbody=converter,
                              densitypower=1.5, Rmin=1, Rmax=Rmax/Rmin,
                              q_out=1.0, discfraction=Mdisk/Mstar).result
    com = disk.center_of_mass()

    # determine bump's local velocity
    
    inner_particles = disk.select(lambda r: (com-r).length()
                                                   < abump,["position"])
    M_inner = Mstar + inner_particles.mass.sum() 
    v_circ = (constants.G*M_inner*(2./abump - 1./abump)) \
                 .sqrt().value_in(units.kms)

    # initialize bump
    
    Nbump = int(Ndisk*Mbump/Mdisk)
    bump = new_plummer_gas_model(Nbump,
                                 convert_nbody=nbody_system.nbody_to_si(Mbump,
                                                                        Rbump))
    bump.x += abump
    bump.velocity += [0, v_circ, 0] | units.kms

    disk.add_particles(bump)
    disk.move_to_center()
    return disk
def make_giant_molecular_clouds(Ngmc):
    N_thick_disk = int(0.5 * Ngmc)
    N_thin_disk = int(0.5 * Ngmc)
    converter = nbody_system.nbody_to_si(1.e+8 | units.MSun, 1.0 | units.kpc)
    from amuse.ext.protodisk import ProtoPlanetaryDisk
    Rin = 3.5 | units.kpc
    Rout = 7.5 | units.kpc
    masses = new_powerlaw_mass_distribution(N_thick_disk,
                                            alpha=-1.6,
                                            mass_min=1.0e+3 | units.MSun,
                                            mass_max=1.0e+8 | units.MSun)
    MGMCs = masses.sum()
    MWG = MilkyWay_galaxy()
    v_inner = MWG.vel_circ(Rout)
    MGalaxy = v_inner**2 * Rout / constants.G
    print("Masses:", MGMCs.in_(units.MSun), MGalaxy.in_(units.MSun), \
          MGMCs/MGalaxy)
    GMCs = ProtoPlanetaryDisk(len(masses),
                              convert_nbody=converter,
                              Rmin=Rin.value_in(units.kpc),
                              Rmax=Rout.value_in(units.kpc),
                              q_out=30.0,
                              discfraction=MGMCs / MGalaxy).result

    #second population of GMCs
    masses = new_powerlaw_mass_distribution(len(GMCs),
                                            alpha=-1.6,
                                            mass_min=1.e+3 | units.MSun,
                                            mass_max=1.0e+8 | units.MSun)
    GMCs.mass = masses
    MGMCs = masses.sum()
    thin_disk_GMCs = ProtoPlanetaryDisk(N_thin_disk,
                                        convert_nbody=converter,
                                        Rmin=Rin.value_in(units.kpc),
                                        Rmax=2 * Rout.value_in(units.kpc),
                                        q_out=10.0,
                                        discfraction=MGMCs / MGalaxy).result
    thin_disk_GMCs.masses = masses
    GMCs.add_particles(thin_disk_GMCs)
    GMCs.velocity *= -1
    GMCs.mass = new_powerlaw_mass_distribution(len(GMCs),
                                               alpha=-1.6,
                                               mass_min=1.e+3 | units.MSun,
                                               mass_max=1.0e+8 | units.MSun)
    print("v=", v_inner.in_(units.kms))
    print("GMC mass=", GMCs.mass.sum().in_(units.MSun))
    for gi in range(len(GMCs)):
        r = GMCs[gi].position.length()
        vc = MWG.vel_circ(r)
        GMCs[gi].velocity = GMCs[gi].velocity * (vc /
                                                 GMCs[gi].velocity.length())

    return GMCs
Exemple #5
0
def main(t_end, dt):
    stars = init_sun_jupiter()
    Sun = stars[0]
    Jupiter = stars[1]
    orbit0 = orbital_elements_from_binary(stars, G=constants.G)
    a0 = orbit0[2].in_(units.AU)
    e0 = orbit0[3]
    Hill_radius0 = a0 * (1 - e0) * (
        (1.0 | units.MJupiter).value_in(units.MSun) / 3.)**(1. / 3.)
    eps = 1 | units.RSun
    gravity = Gravity(ph4, stars, eps)

    N = 500
    Rmin = 1.0
    Rmax = 100.0
    converter = nbody_system.nbody_to_si(1.0 | units.MSun, 1.0 | units.AU)
    np.random.seed(1)
    disk = ProtoPlanetaryDisk(N, convert_nbody=converter, densitypower=1.5,\
                              Rmin=Rmin, Rmax=Rmax, q_out=1., discfraction=0.01)
    gas = disk.result
    gas.h_smooth = 0.06 | units.AU
    hydro = Hydro(Fi, gas, eps, dt)

    sink = init_sink_particle(0. | units.MSun, Hill_radius0, Jupiter.position,
                              Jupiter.velocity)
    hydro.particles.add_particles(sink)

    a_Jup, e_Jup, times = gravity_hydro_bridge(gravity, hydro, t_end, dt)

    return a_Jup, e_Jup, times
Exemple #6
0
def new_disk_with_bump(Mstar = 1|units.MSun,
                       Ndisk=100, Mdisk=0.9|units.MSun, 
                       Rmin=1.0|units.AU, Rmax=100.0|units.AU, 
                       Mbump=0.1|units.MSun,Rbump=10.0|units.AU, 
                       abump=10|units.AU):
    converter=nbody_system.nbody_to_si(Mdisk, Rmin)
    bodies = ProtoPlanetaryDisk(Ndisk, convert_nbody=converter, 
                                densitypower=1.5, 
                                Rmin=1.0, 
                                Rmax=Rmax/Rmin,
                                q_out=1.0,
                                discfraction=1.0).result
    Mdisk = bodies.mass.sum()
    bodies.move_to_center()
    com = bodies.center_of_mass()

    mm = Mdisk/float(Ndisk)
    Nbump = Mbump/mm
    print "Nbump=", Mbump, Rbump, Nbump
    print "Mass =", Mstar, Mdisk, bodies.mass.sum().in_(units.MSun), bodies.mass.sum()/Mstar
    bump = new_plummer_gas_model(Nbump, convert_nbody=nbody_system.nbody_to_si(Mbump, Rbump))

    bump.x += abump
    r_bump = abump 
    inner_particles = bodies.select(lambda r: (com-r).length()<abump,["position"])
    M_inner = inner_particles.mass.sum() + Mstar

    v_circ = (constants.G*M_inner*(2./r_bump - 1./abump)).sqrt().value_in(units.kms)
    bump.velocity += [0, v_circ, 0] | units.kms
    bodies.add_particles(bump)
    return bodies
Exemple #7
0
def new_disk(Mstar=1 | units.MSun,
             Ndisk=500,
             Rmin=1.0 | units.AU,
             Rmax=100.0 | units.AU):

    Mdisk = 0.01 * Mstar  #setting the mass of the disk to 1% of star

    # Initialise disk
    converter = nbody_system.nbody_to_si(Mstar, Rmin)
    disk = ProtoPlanetaryDisk(Ndisk,
                              convert_nbody=converter,
                              densitypower=1.5,
                              Rmin=1,
                              Rmax=Rmax / Rmin,
                              q_out=1.0,
                              discfraction=Mdisk / Mstar).result
    com = disk.center_of_mass()

    return disk
    def create_disc(self):

        #The following line makes sure masses for ISM and disc particles are equal:
        self.discfraction = (
            self.disc_N *
            (self.ism_slice_mass / self.ism_slice_N)) / self.Mstar

        T_disc = self.T
        cs_disc = ((T_disc * constants.kB) / self.mu).sqrt()
        densitypower = 1.5
        g2 = 2 - densitypower
        k_out = ((1 + self.discfraction) / self.disc_Rmax**3)**0.5
        sigma_out = g2 * self.discfraction / (
            2 * numpy.pi * self.disc_Rmax**densitypower *
            (self.disc_Rmax**g2 - self.disc_Rmin**g2))
        q_out = self.converter.to_generic(cs_disc).value_in(
            nbody_system.length / nbody_system.time) / (numpy.pi * sigma_out /
                                                        k_out)

        print "Number of disk particles:", self.disc_N

        proto = ProtoPlanetaryDisk(self.disc_N,
                                   convert_nbody=self.converter,
                                   discfraction=self.discfraction,
                                   densitypower=1.5,
                                   thermalpower=0,
                                   Rmin=self.disc_Rmin,
                                   Rmax=self.disc_Rmax,
                                   q_out=q_out)
        disc = proto.result

        print "The mass of a disc particle = ", disc.mass[0].value_in(units.kg)

        #Rotate 90 degrees with respect to the z-axis and then theta degrees with respect to the y-axis

        temp_x = disc[:].x
        temp_y = disc[:].y
        temp_z = disc[:].z
        temp_vx = disc[:].vx
        temp_vy = disc[:].vy
        temp_vz = disc[:].vz

        disc.x = temp_z * numpy.cos(self.disc_angle) - temp_y * numpy.sin(
            self.disc_angle)
        disc.y = temp_z * numpy.sin(self.disc_angle) + temp_y * numpy.cos(
            self.disc_angle)
        disc.z = -temp_x

        disc.vx = temp_vz * numpy.cos(self.disc_angle) - temp_vy * numpy.sin(
            self.disc_angle)
        disc.vy = temp_vz * numpy.sin(self.disc_angle) + temp_vy * numpy.cos(
            self.disc_angle)
        disc.vz = -temp_vx

        return disc
Exemple #9
0
def main(N=1000, Lstar=100| units.LSun, boxsize=10| units.parsec, 
         rho=1.0| (units.amu/units.cm**3), t_end=0.1|units.Myr, n_steps=10):

    ionization_fraction = 0.0
    internal_energy = (9. |units.kms)**2

    source=Particles(1)
    source.position = (0, 0, 0) |units.parsec
    source.flux = Lstar/(20. | units.eV)
    source.luminosity = Lstar/(20. | units.eV)
    source.rho = rho
    source.xion = ionization_fraction
    source.u = internal_energy

    converter=nbody_system.nbody_to_si(1|units.MSun, boxsize)
    ism = ProtoPlanetaryDisk(N, convert_nbody=converter, 
                                densitypower=1.5, 
                                Rmin=0.1, 
                                Rmax=1,
                                q_out=1.0,
                                discfraction=1.0).result
    ism = ism.select(lambda r: r.length()<0.5*boxsize,["position"])
    gamma=5./3.
    mu=1.| units.amu
    Tinit = 10000|units.K
    ism.u = 1/(gamma-1)*constants.kB * Tinit/mu
    ism.rho = rho
    ism.flux = 0. | units.s**-1
    ism.xion = ionization_fraction 
    ism.h_smooth = 0 | units.AU

    rad = SimpleXSplitSet(redirect="none")
#    rad = SimpleX()
#    rad = SPHRay()
    rad.parameters.box_size=1.001*boxsize    
    rad.parameters.timestep=0.001 | units.Myr

    rad.src_particles.add_particle(source)
    rad.gas_particles.add_particles(ism)

    channel_to_local_gas = rad.gas_particles.new_channel_to(ism)
    write_set_to_file(ism, "rad.hdf5", 'hdf5')

    time = 0.0 | t_end.unit
    dt = t_end/float(n_steps)
    while time<t_end:
        time += dt
        rad.evolve_model(time)
        channel_to_local_gas.copy_attributes(["xion",])
        write_set_to_file(ism, "rad.hdf5", 'hdf5')

        print "Time=", time
        print "min ionization:", rad.gas_particles.xion.min()
        print "average Xion:", rad.gas_particles.xion.mean()
        print "max ionization:", rad.gas_particles.xion.max()
    rad.stop()
def main(t_end=1000. | units.yr, dt=10. | units.yr):

    print 'Initializing...'
    converter = nbody_system.nbody_to_si(1. | units.MSun, 1. | units.AU)

    # Initialize the gravity system
    Sun_and_Jupiter = init_sun_jupiter()
    Sun = Sun_and_Jupiter[0]
    Jupiter = Sun_and_Jupiter[1]
    orbit0 = orbital_elements_from_binary(Sun_and_Jupiter, G=constants.G)
    a0 = orbit0[2].in_(units.AU)
    e0 = orbit0[3]
    Hill_radius0 = a0 * (1 - e0) * (
        (1.0 | units.MJupiter).value_in(units.MSun) / 3.)**(1. / 3.)

    # Initialising the direct N-body integrator
    gravity = ph4(converter)
    gravity.particles.add_particle(Jupiter)
    gravity.timestep = dt

    # Setting proto-disk parameters
    N = 4000
    Mstar = 1. | units.MSun
    Mdisk = 0.01 * Mstar
    Rmin = 2.
    Rmax = 100.

    # Initialising the proto-planetary disk
    np.random.seed(1)
    disk = ProtoPlanetaryDisk(N,
                              convert_nbody=converter,
                              densitypower=1.5,
                              Rmin=Rmin,
                              Rmax=Rmax,
                              q_out=1.,
                              discfraction=Mdisk / Mstar)
    disk_gas = disk.result

    # Initialize the sink particle
    sink = init_sink_particle(0. | units.MSun, Hill_radius0, Jupiter.position,
                              Jupiter.velocity)

    # Initialising the SPH code
    sph = Fi(converter, mode="openmp")
    sph.gas_particles.add_particles(disk_gas)
    sph.dm_particles.add_particle(Sun)
    sph.parameters.timestep = dt

    # bridge and evolve
    a_Jup, e_Jup, disk_size, times, accreted_mass = gravity_hydro_bridge(
        gravity, sph, sink, [Sun_and_Jupiter, disk_gas], Rmin, t_end, dt)

    return a_Jup, e_Jup, disk_size, times, accreted_mass
def add_debris_disk(star,
                    ndisk_per_MSun,
                    fdisk,
                    masteroid,
                    Rmin,
                    Rmax,
                    alpha=1.5,
                    Q=1.0):

    Ndisk = int(ndisk_per_MSun * star.mass.value_in(units.MSun))
    print("Run with Ndisk = ", Ndisk)

    converter = nbody_system.nbody_to_si(star.mass, Rmin)
    disk = ProtoPlanetaryDisk(Ndisk,
                              convert_nbody=converter,
                              densitypower=alpha,
                              Rmin=Rmin / Rmin,
                              Rmax=Rmax / Rmin,
                              q_out=Q,
                              discfraction=fdisk).result

    disk.mass = masteroid
    disk.name = "asteroid"
    disk.type = "debris"
    disk.host = star.key
    disk.position += star.position
    disk.velocity += star.velocity
    return disk
Exemple #12
0
def main(t_end=1000. | units.yr, dt=10. | units.yr):

    print 'Initializing...'
    converter = nbody_system.nbody_to_si(1. | units.MSun, 1. | units.AU)

    # Initialize the gravity system
    Sun_and_Jupiter = init_sun_jupiter()
    Sun = Sun_and_Jupiter[0]
    Jupiter = Sun_and_Jupiter[1]
    orbit0 = orbital_elements_from_binary(Sun_and_Jupiter, G=constants.G)
    a0 = orbit0[2].in_(units.AU)
    e0 = orbit0[3]
    Hill_radius0 = a0 * (1 - e0) * (
        (1.0 | units.MJupiter).value_in(units.MSun) / 3.)**(1. / 3.)

    gravity = ph4(converter)
    gravity.particles.add_particles(Sun_and_Jupiter)
    gravity.timestep = dt

    # initialize the hydrodynamics(SPH) system
    # initialize the protoplanetary disk
    N = 1000
    Mstar = 1. | units.MSun
    Mdisk = 0.01 * Mstar
    Rmin = 2.
    Rmax = 100.

    np.random.seed(1)
    disk = ProtoPlanetaryDisk(N,
                              convert_nbody=converter,
                              densitypower=1.5,
                              Rmin=Rmin,
                              Rmax=Rmax,
                              q_out=1.)
    disk_gas = disk.result
    disk_gas.h_smooth = 0.06 | units.AU

    # initialize the sink particle
    sink = init_sink_particle(0. | units.MSun, Hill_radius0, Jupiter.position,
                              Jupiter.velocity)

    sph = Fi(converter)
    sph.particles.add_particles(sink)
    sph.gas_particles.add_particles(disk_gas)
    sph.parameters.timestep = dt

    # bridge and evolve
    a_Jup, e_Jup, disk_size, times = gravity_hydro_bridge(gravity, sph, \
                                     [Sun_and_Jupiter, disk_gas], Rmin, t_end, dt)

    return a_Jup, e_Jup, disk_size, times
def make_giant_molecular_clouds(Ngmc):
    N_thick_disk = int(0.5*Ngmc)
    N_thin_disk = int(0.5*Ngmc)
    converter=nbody_system.nbody_to_si(1.e+8|units.MSun, 1.0|units.kpc)
    from amuse.ext.protodisk import ProtoPlanetaryDisk
    Rin = 3.5 | units.kpc
    Rout = 7.5 | units.kpc
    masses = new_powerlaw_mass_distribution(N_thick_disk, alpha=-1.6,
                                            mass_min=1.0e+3|units.MSun,
                                            mass_max=1.0e+8|units.MSun)
    MGMCs = masses.sum()
    MWG = MilkyWay_galaxy()    
    v_inner = MWG.vel_circ(Rout)
    MGalaxy = v_inner**2*Rout/constants.G
    print "Masses:", MGMCs.in_(units.MSun), MGalaxy.in_(units.MSun), \
          MGMCs/MGalaxy
    GMCs = ProtoPlanetaryDisk(len(masses), convert_nbody=converter,
                              Rmin=Rin.value_in(units.kpc), 
                              Rmax=Rout.value_in(units.kpc),
                              q_out=30.0, discfraction=MGMCs/MGalaxy).result

    #second population of GMCs
    masses = new_powerlaw_mass_distribution(len(GMCs), alpha=-1.6,
                                            mass_min=1.e+3|units.MSun,
                                            mass_max=1.0e+8|units.MSun)    
    GMCs.mass = masses
    MGMCs = masses.sum()
    thin_disk_GMCs = ProtoPlanetaryDisk(N_thin_disk, convert_nbody=converter,
                              Rmin=Rin.value_in(units.kpc), 
                              Rmax=2*Rout.value_in(units.kpc),
                              q_out=10.0, discfraction=MGMCs/MGalaxy).result
    thin_disk_GMCs.masses = masses
    GMCs.add_particles(thin_disk_GMCs)
    GMCs.velocity *= -1
    GMCs.mass = new_powerlaw_mass_distribution(len(GMCs), alpha=-1.6,
                                                 mass_min=1.e+3|units.MSun,
                                                 mass_max=1.0e+8|units.MSun)
    print "v=", v_inner.in_(units.kms)
    print "GMC mass=", GMCs.mass.sum().in_(units.MSun)
    for gi in range(len(GMCs)):
        r = GMCs[gi].position.length()
        vc = MWG.vel_circ(r)
        GMCs[gi].velocity = GMCs[gi].velocity * (vc/GMCs[gi].velocity.length())

    return GMCs
Exemple #14
0
def test_rotate(phi, theta, chi):
    from amuse.ext.protodisk import ProtoPlanetaryDisk
    converter = nbody_system.nbody_to_si(1.0 | units.MSun, 1.0 | units.au)
    disk = ProtoPlanetaryDisk(1000,
                              convert_nbody=converter,
                              Rmin=1,
                              Rmax=100,
                              q_out=1.0,
                              discfraction=0.01).result

    disk = rotate_particle_set(disk, phi, theta, chi)

    from matplotlib import pyplot

    pyplot.scatter(disk.x.value_in(units.au), disk.y.value_in(units.au))
    pyplot.xlabel("x-axis [au]")
    pyplot.ylabel("y-axis [au]")
    pyplot.show()
    pyplot.scatter(disk.x.value_in(units.au), disk.z.value_in(units.au))
    pyplot.xlabel("x-axis [au]")
    pyplot.ylabel("z-axis [au]")
    pyplot.show()
Exemple #15
0
def initialize_star_and_planetary_system(Mstar, Ndisk, Mdisk, Rmin, Rmax):

    converter=nbody_system.nbody_to_si(Mstar, Rmin)
    disk_massfraction = Mdisk/Mstar
    disk = ProtoPlanetaryDisk(Ndisk, convert_nbody=converter,
                              densitypower=1.5, 
                              Rmin=Rmin.value_in(units.AU), 
                              Rmax=Rmax.value_in(units.AU),
                              q_out=1.0, discfraction=disk_massfraction).result
    #disk.h_smooth= Rmin/Ndisk

    star = Particles(1)
    star.mass = Mstar
    star.radius = 1| units.RSun
    star.position = (0,0,0) | units.AU
    star.velocity = (0,0,0) | units.kms
    planets = make_planets_oligarch.new_system(Mstar, star.radius,
                                               Rmin, Rmax, Mdisk)
    star.add_particles(planets[0].planets)
    print star
    
    return star, disk
def init_body_solar_disk_planetary(Ndisk, Mdisk, Rmin, Rmax):

    print 'Initializing...'
    #converter = nbody_system.nbody_to_si(1.|units.MJupiter, 1.|units.AU)

    # Initialize the solar system
    Sun_Jupiter = init_sun_jupiter()
    Sun = Sun_Jupiter[0]
    Jupiter = Sun_Jupiter[1]

    orbit = orbital_elements_from_binary(Sun_Jupiter, G=constants.G)
    a = orbit[2].in_(units.AU)
    e = orbit[3]
    hr = Hill_radius(a, e, Sun_Jupiter)

    # Initialize the proto-planetary disk
    np.random.seed(1)
    disk_converter = nbody_system.nbody_to_si(Sun.mass, Rmin)
    disk = ProtoPlanetaryDisk(Ndisk,
                              convert_nbody=disk_converter,
                              densitypower=1.5,
                              Rmin=1.0,
                              Rmax=Rmax / Rmin,
                              q_out=1.0,
                              discfraction=Mdisk / Sun.mass)
    disk_gas = disk.result

    # Initialize the sink particle
    sink = init_sink_particle(0. | units.MSun, hr, Jupiter.position,
                              Jupiter.velocity)

    # Initizalize the passing star
    e = 1.2
    Mstar = 2.0 | units.MSun
    pericenter = 200.0 | units.AU
    Pstar = init_passing_star(pericenter, e, Mstar)

    return Sun_Jupiter, disk_gas, sink, Pstar
    Rstar = 695510000 | units.m
    Mdisk = 0.01 | units.MSun
    Rmin = 1
    Rmax = 100
    overwrite = True
    d_plot_dir = 'distribution_plots_4k/'

    # Setting a seed
    np.random.seed(1)

    # Initialising disk
    convert = nbody_system.nbody_to_si(Mstar, 1. | units.AU)
    proto = ProtoPlanetaryDisk(N,
                               convert_nbody=convert,
                               densitypower=1.5,
                               Rmin=Rmin,
                               Rmax=Rmax,
                               q_out=1.,
                               discfraction=Mdisk / Mstar)
    disk_gas = proto.result

    # Initialising star
    sun = Particles(1)
    sun.mass = Mstar
    sun.radius = 0.1 | units.AU
    sun.x = 0. | units.AU
    sun.y = 0. | units.AU
    sun.z = 0. | units.AU
    sun.vx = 0. | units.kms
    sun.vy = 0. | units.kms
    sun.vz = 0. | units.kms
Exemple #18
0
# Locate the star at a certain position
stars[0].x, stars[0].y, stars[
    0].z = 100. | units.au, 0. | units.au, 0. | units.au

# Give it a certain velocity
stars[0].vx, stars[0].vy, stars[0].vz = 20. | (units.au / units.yr), 0. | (
    units.au / units.yr), 0. | (units.au / units.yr)

# Create a converter. In this way we turn n-body system units to the physical units we are interested in
converter = nbody_system.nbody_to_si(1. | units.MSun, 1. | units.au)

# Create protoplanetary disk
N_particles = 1000  # Number of SPH particles
disk = ProtoPlanetaryDisk(N_particles,
                          convert_nbody=converter,
                          densitypower=1.5,
                          Rmin=0.5,
                          Rmax=100,
                          q_out=1.)  # Rmin and Rmax in AU

disk_particles = disk.result  # Disk particles
disk_particles.h_smooth = 0.06 | units.au  # Smoothing length

# Rotate the disk 90 degrees around x axis
disk = rotate(disk_particles, 90, 0, 0)

# Start SPH code and add particles
sph = Fi(converter)
sph.gas_particles.add_particles(
    disk_particles)  # Disk particles are added as gas particles
sph.dm_particles.add_particles(
    stars[0])  # Star is added as dark matter particle
def get_planetesimals_disk(n_disk,
                           r_in=20.0 | units.AU,
                           r_out=50.0 | units.AU,
                           m_star=1.0 | units.MSun,
                           alpha=None,
                           m_disk=1.0e-15 | units.MSun,
                           seed=42,
                           disk_num=1):
    """
    returns particles of planetesimal disk with given parameters
    """
    numpy.random.seed(seed)  # Mess with random seed

    for i in xrange(int(disk_num) + 4):
        planetesimals = Particles(n_disk)
    print "Seed:", seed
    print planetesimals.key[:10]
    planetesimals.mass = 0.0 | units.MJupiter
    planetesimals.radius = 100.0 | units.km
    planetesimals.collection_attributes.timestamp = 0.0 | units.yr

    if alpha is not None:
        converter = nbody_system.nbody_to_si(m_disk, r_in)
        power_disk = ProtoPlanetaryDisk(n_disk,
                                        convert_nbody=converter,
                                        densitypower=alpha,
                                        Rmin=1.0,
                                        Rmax=1.0 * r_out / r_in,
                                        q_out=0.0,
                                        discfraction=1.0).result
        x = power_disk.x
        y = power_disk.y
        z = power_disk.z  # <--- Mystery error?

        print "X"
        print x.value_in(units.AU)
        print "Y"
        print y.value_in(units.AU)
        print "Z"
        print z.value_in(units.AU)
        #z = 0

        print "MASS"
        print power_disk.mass

        #power_disk.mass = 0.0 * power_disk.mass ###### THIS WORKS!!!! (if you want to switch to this later)

        print power_disk.mass

        a = (x**2 + y**2)**0.5
        print "SM-AXIS"
        print a.value_in(units.AU)

        phi = numpy.arctan2(y.value_in(units.AU), x.value_in(units.AU))
        vc = (constants.G * m_star / a)**0.5
        vx = -vc * numpy.sin(phi)
        vy = vc * numpy.cos(phi)
        vz = 0.0 * vc
        # vz = - vc * numpy.sin(phi) # ???????????????????????????????????????????????????????????????? #

        print "VX"
        print vx.value_in(units.km / units.s)
        print "VY"
        print vy.value_in(units.km / units.s)
        print "VZ"
        print vz.value_in(units.km / units.s)

        print "PLANAR VELOCITY VECTOR"
        print((vx**2 + vy**2)**(0.5)).value_in(units.km / units.s)

        #vx = power_disk.vx
        #vy = power_disk.vy
        #vz = power_disk.vz

        #print "POWER DISK VX"
        #print vx.value_in(units.km / units.s)
        #print "POWER DISK VY"
        #print vy.value_in(units.km / units.s)
        #print "POWER DISK VZ"
        #print vz.value_in(units.km / units.s)

    else:
        a = r_in + (r_out - r_in) * numpy.random.rand(n_disk)
        phi_rand = 2.0 * numpy.pi * numpy.random.rand(n_disk)

        x = a * numpy.cos(phi_rand)
        y = a * numpy.sin(phi_rand)
        z = 0.0 * a

        vc = (constants.G * m_star / a)**0.5
        vx = -vc * numpy.sin(phi_rand)
        vy = vc * numpy.cos(phi_rand)
        vz = 0.0 * vc

    planetesimals.x = x
    planetesimals.y = y
    planetesimals.z = z

    planetesimals.vx = vx
    planetesimals.vy = vy
    planetesimals.vz = vz

    return planetesimals
    Sun_Jupiter = init_sun_jupiter()
    Sun = Sun_Jupiter[0]
    Jupiter = Sun_Jupiter[1]

    orbit = orbital_elements_from_binary(Sun_Jupiter, G=constants.G)
    a = orbit[2].in_(units.AU)
    e = orbit[3]
    hr = Hill_radius(a, e, Sun_Jupiter)

    # Initialize the proto-planetary disk
    np.random.seed(1)
    disk_converter = nbody_system.nbody_to_si(Sun.mass, Rmin)
    disk = ProtoPlanetaryDisk(Ndisk,
                              convert_nbody=disk_converter,
                              densitypower=1.5,
                              Rmin=1.0,
                              Rmax=Rmax / Rmin,
                              q_out=1.0,
                              discfraction=Mdisk / Sun.mass)
    disk_gas = disk.result

    # Initialize the sink particle
    sink = init_sink_particle(0. | units.MSun, hr, Jupiter.position,
                              Jupiter.velocity)

    # Initizalize the passing star
    Pstar = init_passing_star(pericenter, e, Mstar)

    # ------ Running the building and running hydro-code ------
    # Main function
    t, a_Jup, e_Jup, disk_size, accreted_mass = evolve(Sun_Jupiter, disk_gas,
def main(Ndisk, Mstar, Mdisk, Rin, Rout, t_end, Nray, x, y, z):

    time = 0 | units.Myr
    supernova_IIp = Supernova_IIp(10|units.day)
    
    efficiency_factor = 0.1
    Rsn = efficiency_factor * (x**2 + y**2 + z**2)**0.5

    supernova = Particle()
    supernova.position = (x.value_in(units.parsec),
                          y.value_in(units.parsec),
                          z.value_in(units.parsec)) |units.parsec
    supernova.position *= efficiency_factor
    supernova_IIp.particles.add_particle(supernova)
    supernova_IIp.evolve_model(time)
    supernova.luminosity = efficiency_factor**2 * supernova.luminosity
    supernova.xion = 0.0
    supernova.u = (10**51 | units.erg)/(10|units.MSun)
    
    stellar = SeBa()
    star = Particle()
    star.mass = Mstar
    star.position = (0,0,0) | units.AU
    star.velocity = (0,0,0) | units.kms
    stellar.particles.add_particle(star)
    stellar.evolve_model(1|units.Myr)
    star.luminosity = stellar.particles[0].luminosity/(20. | units.eV)
    star.temperature = stellar.particles[0].temperature
    stellar.stop()
    star.u = (9. |units.kms)**2
    star.xion = 0.0
    print star

    print "M=", Mdisk/Mstar    
    converter=nbody_system.nbody_to_si(Mstar, 1 | units.AU)
    disk = ProtoPlanetaryDisk(Ndisk, convert_nbody=converter,
                              Rmin=Rin.value_in(units.AU), 
                              Rmax=Rout.value_in(units.AU),
                              q_out=25.0, discfraction=Mdisk/Mstar).result
####                              q_out=2.0, discfraction=Mdisk/Mstar).result
    print disk.x.max().in_(units.AU)
    print disk.mass.sum().in_(units.MSun)
    print disk.u.max().in_(units.kms**2)
    print disk.mass.min().in_(units.MSun)
    disk.flux = 0. | units.s**-1
    disk.xion = 0.0

    dt = t_end/1000.
    
    hydro = Fi(converter)
    hydro.parameters.use_hydro_flag=True
    hydro.parameters.radiation_flag=False
    hydro.parameters.self_gravity_flag=True
    
    hydro.parameters.gamma=1.
    hydro.parameters.isothermal_flag=True

# Non-isothermal: lowest temperature remains constat at 20K
#    hydro.parameters.gamma=1.66667
#    hydro.parameters.isothermal_flag=False
    
    hydro.parameters.integrate_entropy_flag=False
    hydro.parameters.timestep=0.5 | units.hour #0.125 | units.day
#    hydro.parameters.verbosity=99
    hydro.parameters.epsilon_squared=0.1 | units.AU**2
    hydro.parameters.courant=0.2    
    hydro.parameters.artificial_viscosity_alpha = 0.1 
    
    hydro.gas_particles.add_particles(disk)
    hydro.dm_particles.add_particle(star)
    hydro_to_disk = hydro.gas_particles.new_channel_to(disk)
    hydro_to_star = hydro.dm_particles.new_channel_to(star.as_set())
    disk_to_hydro = disk.new_channel_to(hydro.gas_particles)
    star_to_hydro = star.as_set().new_channel_to(hydro.dm_particles)
    hydro.evolve_model(1|units.hour)
    hydro_to_disk.copy()
    hydro_to_star.copy()
    
    radiative = SPHRay(redirection="file",
                       number_of_workers=4)#, debugger="gdb")
    radiative.parameters.number_of_rays=Nray/dt
    print dt.in_(units.yr)
    radiative.parameters.default_spectral_type=-3.
    radiative.parameters.box_size=10000. | units.AU
    radiative.parameters.ionization_temperature_solver=2
    print radiative.parameters

#    radiative.src_particles.add_particle(star)
    radiative.src_particles.add_particle(supernova)
    radiative.gas_particles.add_particles(disk)

    gas_to_rad = disk.new_channel_to(radiative.gas_particles)
    rad_to_gas = radiative.gas_particles.new_channel_to(disk)
    
    print "Before"
    print "Luminosity:", radiative.src_particles.luminosity
    print "min ionization:", radiative.gas_particles.xion.min()
    print "average Xion:", radiative.gas_particles.xion.mean()
    print "max ionization:", radiative.gas_particles.xion.max()
    print "min u:", radiative.gas_particles.u.min()
    print "average u:", radiative.gas_particles.u.mean()
    print "max u:", radiative.gas_particles.u.max()

    Tmean = [] | units.K
    Tmin = [] | units.K
    Tmax = [] | units.K
    t = [] | units.day
    while radiative.model_time<t_end:

        supernova = update_source_particle(radiative, time+0.5*dt, supernova,
                                           efficiency_factor, supernova_IIp)

        radiative.evolve_model(time+0.5*dt)
        print "RT done at time:", time.in_(units.day)
        rad_to_gas.copy()

        disk_to_hydro.copy()
        star_to_hydro.copy()
        hydro.evolve_model(time + dt)
        hydro_to_disk.copy()
        hydro_to_star.copy()

        supernova = update_source_particle(radiative, time+dt, supernova,
                                           efficiency_factor, supernova_IIp)

        radiative.evolve_model(time+dt)
        print "RT done at time:", time.in_(units.day)
        rad_to_gas.copy()

        time += dt
        print_diagnostics(time, supernova, disk)
        
        Temperature =  mu() / constants.kB * disk.u
        t.append(time)
        Tmean.append(Temperature.mean())
        Tmin.append(Temperature.min())
        Tmax.append(Temperature.max())

        #write_set_to_file(disk, "disk_irradiation.amuse", "amuse")
        
        print "timescale:", (disk.mass.sum().value_in(units.amu) \
                              / ((Rout/Rsn)**2*supernova.luminosity)).in_(units.yr)
        print "scaleheight:", abs(disk.z.value_in(units.AU)).mean()
        
        #pyplot.hist2d(abs(disk.x.value_in(units.AU)), abs(numpy.log10(Temperature.value_in(units.K))), bins=200)
       # pyplot.hist2d(abs(disk.x.value_in(units.AU)), abs(disk.z.value_in(units.AU)), bins=200)
        #,norm=LogNorm())
       #, Temperature.in_(units.K))
#       pyplot.tripcolor(abs(disk.x.value_in(units.AU)), abs(disk.y.value_in(units.AU)), Temperature.in_(units.K))
        #pyplot.hist(abs(disk.x.value_in(units.AU)), 100)
       # pyplot.show()

    print_diagnostics(time, supernova, disk)

    #plot_ionization_fraction(disk.position, disk.xion)
#    plot_ionization_fraction(disk.z, disk.u.value_in(units.kms**2))
#    plot_ionization_fraction(disk.x, disk.u.value_in(units.kms**2))
    radiative.stop()
    plot_temperature(t, Tmin, Tmean, Tmax)
def main(t_end=1000. | units.yr, dt=10. | units.yr):

    print 'Initializing...'
    #converter = nbody_system.nbody_to_si(1.|units.MSun, 1.|units.AU)

    # Initialize the Sun and Jupiter system
    Sun, Jupiter = init_star_planet()
    Sun_and_Jupiter0 = Particles()
    Sun_and_Jupiter0.add_particle(Sun)
    Sun_and_Jupiter0.add_particle(Jupiter)
    orbit0 = orbital_elements_from_binary(Sun_and_Jupiter0, G=constants.G)
    a0 = orbit0[2].in_(units.AU)
    e0 = orbit0[3]
    Hill_radius0 = a0 * (1 - e0) * (
        (1.0 | units.MJupiter).value_in(units.MSun) / 3.)**(1. / 3.)

    # Initialize the passing star
    PassStar = Particle()
    PassStar.mass = 2.0 | units.MSun
    r_ps = 200. | units.AU
    a_ps = 1000. | units.AU
    mu = PassStar.mass * Sun.mass / (PassStar.mass + Sun.mass)
    vx = np.sqrt(constants.G * mu * (2. / r_ps - 1. / a_ps)).in_(units.kms)
    PassStar.velocity = (-vx, 0. | units.kms, 0. | units.kms)
    ds = (Jupiter.position - Sun.position).value_in(units.AU)
    sin_theta = ds[2] / np.sqrt(ds[0]**2 + ds[1]**2)
    cos_theta = np.sqrt(1 - sin_theta**2)
    PassStar.position = (Sun.position).in_(units.AU) + (
        (0., 200. * cos_theta, 200. * sin_theta) | units.AU)

    # Initialize the direct N-body integrator
    gravity_particles = Particles()
    gravity_particles.add_particle(Jupiter)
    gravity_particles.add_particle(PassStar)
    converter_gravity = nbody_system.nbody_to_si(
        gravity_particles.mass.sum(), gravity_particles.position.length())
    gravity = ph4(converter_gravity)
    gravity.particles.add_particles(gravity_particles)
    gravity.timestep = dt

    # Set proto-disk parameters
    N = 4000
    Mstar = 1. | units.MSun
    Mdisk = 0.01 * Mstar
    Rmin = 1. | units.AU
    Rmax = 100. | units.AU

    # Initialize the proto-planetary disk
    np.random.seed(1)
    converter_disk = nbody_system.nbody_to_si(Mstar, Rmin)
    disk = ProtoPlanetaryDisk(N,
                              convert_nbody=converter_disk,
                              densitypower=1.5,
                              Rmin=1.,
                              Rmax=Rmax / Rmin,
                              q_out=1.,
                              discfraction=Mdisk / Mstar)
    disk_gas = disk.result
    disk_star = Particles()
    disk_star.add_particle(Sun)

    # Initialize the sink particle
    sink = init_sink_particle(0. | units.MSun, Hill_radius0, Jupiter.position,
                              Jupiter.velocity)

    # Initialising the SPH code
    #converter_hydro = nbody_system.nbody_to_si(Mdisk, Rmax)
    sph = Fi(converter_disk, mode="openmp")
    sph.gas_particles.add_particles(disk_gas)
    sph.dm_particles.add_particle(disk_star)
    sph.parameters.timestep = dt

    # bridge and evolve
    times, a_Jup, e_Jup, disk_size, accreted_mass = gravity_hydro_bridge(gravity, sph, sink,\
                                     [gravity_particles, disk_star, disk_gas], Rmin, t_end, dt)

    return times, a_Jup, e_Jup, disk_size, accreted_mass
Exemple #23
0
def main(N=1000,
         Lstar=100 | units.LSun,
         boxsize=10 | units.parsec,
         rho=1.0 | (units.amu / units.cm**3),
         t_end=0.1 | units.Myr,
         n_steps=10):

    ionization_fraction = 0.0
    internal_energy = (9. | units.kms)**2

    source = Particles(1)
    source.position = (0, 0, 0) | units.parsec
    source.flux = Lstar / (20. | units.eV)
    source.luminosity = Lstar / (20. | units.eV)
    source.rho = rho
    source.xion = ionization_fraction
    source.u = internal_energy

    converter = nbody_system.nbody_to_si(1 | units.MSun, boxsize)
    ism = ProtoPlanetaryDisk(N,
                             convert_nbody=converter,
                             densitypower=1.5,
                             Rmin=0.1,
                             Rmax=1,
                             q_out=1.0,
                             discfraction=1.0).result
    ism = ism.select(lambda r: r.length() < 0.5 * boxsize, ["position"])
    gamma = 5. / 3.
    mu = 1. | units.amu
    Tinit = 10000 | units.K
    ism.u = 1 / (gamma - 1) * constants.kB * Tinit / mu
    ism.rho = rho
    ism.flux = 0. | units.s**-1
    ism.xion = ionization_fraction
    ism.h_smooth = 0 | units.AU

    rad = SimpleXSplitSet(redirect="none")
    #    rad = SimpleX()
    #    rad = SPHRay()
    rad.parameters.box_size = 1.001 * boxsize
    rad.parameters.timestep = 0.001 | units.Myr

    rad.src_particles.add_particle(source)
    rad.gas_particles.add_particles(ism)

    channel_to_local_gas = rad.gas_particles.new_channel_to(ism)
    write_set_to_file(ism, "rad.hdf5", 'hdf5')

    time = 0.0 | t_end.unit
    dt = t_end / float(n_steps)
    while time < t_end:
        time += dt
        rad.evolve_model(time)
        channel_to_local_gas.copy_attributes([
            "xion",
        ])
        write_set_to_file(ism, "rad.hdf5", 'hdf5')

        print("Time=", time)
        print("min ionization:", rad.gas_particles.xion.min())
        print("average Xion:", rad.gas_particles.xion.mean())
        print("max ionization:", rad.gas_particles.xion.max())
    rad.stop()
Exemple #24
0
def main(Mstar=1 | units.MSun,
         Ndisk=100,
         Mdisk=0.9 | units.MSun,
         Rmin=1.0 | units.AU,
         Rmax=100.0 | units.AU,
         Mbump=0.1 | units.MSun,
         Rbump=10.0 | units.AU,
         abump=10 | units.AU,
         t_end=1,
         n_steps=10):

    converter = nbody_system.nbody_to_si(Mdisk, Rmin)
    from amuse.ext.protodisk import ProtoPlanetaryDisk
    bodies = ProtoPlanetaryDisk(Ndisk,
                                convert_nbody=converter,
                                densitypower=1.5,
                                Rmin=1.0,
                                Rmax=Rmax / Rmin,
                                q_out=1.0,
                                discfraction=1.0).result
    Mdisk = bodies.mass.sum()
    bodies.move_to_center()
    com = bodies.center_of_mass()

    mm = Mdisk / float(Ndisk)
    Nbump = int(Mbump / mm)
    bump = new_plummer_gas_model(Nbump,
                                 convert_nbody=nbody_system.nbody_to_si(
                                     Mbump, Rbump))

    bump.x += abump
    r_bump = abump
    inner_particles = bodies.select(lambda r: (com - r).length() < abump,
                                    ["position"])
    M_inner = inner_particles.mass.sum() + Mstar
    v_circ = (constants.G * M_inner *
              (2. / r_bump - 1. / abump)).sqrt().value_in(units.kms)
    bump.velocity += [0, v_circ, 0] | units.kms
    bodies.add_particles(bump)

    star = Particles(1)
    star.mass = Mstar
    star.radius = Rmin
    star.position = [0, 0, 0] | units.AU
    star.velocity = [0, 0, 0] | units.kms

    import math
    P_bump = (abump**3 * 4 * math.pi**2 / (constants.G *
                                           (Mbump + Mstar))).sqrt()
    t_end *= P_bump

    hydro = Gadget2(converter)
    hydro.gas_particles.add_particles(bodies)
    hydro.dm_particles.add_particles(star)
    Etot_init = hydro.kinetic_energy + hydro.potential_energy + hydro.thermal_energy

    particles = ParticlesSuperset([star, bodies])
    particles.move_to_center()
    particles.new_channel_to(hydro.particles).copy()
    bodies.h_smooth = Rmin  # for the plotting routine
    channel_to_star = hydro.dm_particles.new_channel_to(star)
    channel_to_bodies = hydro.gas_particles.new_channel_to(bodies)

    write_set_to_file(star, "stars.hdf5", "hdf5")
    write_set_to_file(bodies, "hydro.hdf5", "hdf5")

    time = 0.0 | t_end.unit
    dt = t_end / float(n_steps)
    while time < t_end:
        time += dt
        hydro.evolve_model(time)

        channel_to_star.copy()
        channel_to_bodies.copy()
        write_set_to_file(star, "stars.hdf5", "hdf5")
        write_set_to_file(bodies, "hydro.hdf5", "hdf5")
        star.radius = Rmin

        from hydro_sink_particles import hydro_sink_particles
        lost = hydro_sink_particles(star, bodies)
        if len(lost) > 0:
            hydro.particles.remove_particles(lost)
            hydro.particles.synchronize_to(particles)
            print("Disk=", hydro.model_time, len(bodies), len(lost),
                  lost.mass.sum(), star.mass)

        Ekin = hydro.kinetic_energy
        Epot = hydro.potential_energy
        Eth = hydro.thermal_energy
        Etot = Ekin + Epot + Eth
        print("T=",
              hydro.get_time(),
              "M=",
              hydro.gas_particles.mass.sum(),
              end=' ')
        print("E= ", Etot, "Q= ", (Ekin + Eth) / Epot, "dE=",
              (Etot_init - Etot) / Etot)
        print("Star=", hydro.model_time, star[0].mass, star[0].position)

    hydro.stop()
Exemple #25
0
def main(Mstar=1, Ndisk=100, Mdisk= 0.001, Rmin=1, Rmax=100, t_end=10, n_steps=10, filename="nbody.hdf5"):
#    numpy.random.seed(111)
    Mstar = Mstar | units.MSun
    Mdisk = Mdisk | units.MSun
    Rmin = Rmin | units.AU
    Rmax = Rmax | units.AU
    t_end = t_end | units.yr

#    converter=nbody_system.nbody_to_si(Mdisk, Rmax)
    converter=nbody_system.nbody_to_si(Mstar, Rmin)
    disk = ProtoPlanetaryDisk(Ndisk, convert_nbody=converter, densitypower=1.5, 
                              Rmin=Rmin.value_in(units.AU), 
                              Rmax=Rmax.value_in(units.AU),q_out=1.0,
                              discfraction=1.0).result
 

    disk.move_to_center()

    center_of_mass = disk.center_of_mass()
    print center_of_mass
    a_bump = 50 
    Rbump = 10 | units.AU
    bump_location = center_of_mass + ([0, a_bump, 0] | units.AU)
    bump_particles = disk.select(lambda r: (center_of_mass-r).length()<Rbump,["position"])
    Mbump =bump_particles.mass.sum()

    Nbump = len(bump_particles)
    print "Nbump=", len(bump_particles), Mbump, Rbump, Nbump
    print "Mass =", Mstar, Mdisk, disk.mass.sum().in_(units.MSun), disk.mass.sum()/Mstar
    bump = new_plummer_gas_model(Nbump, convert_nbody=nbody_system.nbody_to_si(0.1*Mbump, Rbump))

    a_bump = a_bump | units.AU
    bump.x += a_bump
    r_bump = a_bump 
    inner_particles = disk.select(lambda r: (center_of_mass-r).length()<a_bump,["position"])
    M_inner = inner_particles.mass.sum() + Mstar

    v_circ = (constants.G*M_inner*(2./r_bump - 1./a_bump)).sqrt().value_in(units.kms)
    bump.velocity += [0, v_circ, 0] | units.kms
    print "MM=", M_inner, v_circ

    disk.add_particles(bump)

    disk.h_smooth= Rmin/(Ndisk+Nbump)
    star=Particles(1)
    star.mass=Mstar
    star.radius=1. | units.RSun
    star.position = [0, 0, 0] | units.AU
    star.velocity = [0, 0, 0] | units.kms

#    star2=Particles(1)
#    star2.mass=Mstar
#    star2.radius=1. | units.RSun
#    star2.position = [1, 0, 0] | units.AU
#    star2.velocity = [0, 30, 0] | units.kms
 
    hydro=Fi(converter)
#    hydror = Fi(channel_type="ibis", hostname="galgewater")

 
    hydro.parameters.use_hydro_flag=True
    hydro.parameters.radiation_flag=False
    hydro.parameters.self_gravity_flag=True
    hydro.parameters.gamma=1.
    hydro.parameters.isothermal_flag=True
    hydro.parameters.integrate_entropy_flag=False
    hydro.parameters.timestep=0.125 | units.yr  

    hydro.gas_particles.add_particles(disk)

    gravity = Hermite(converter)
    gravity.particles.add_particles(star)
#    gravity.particles.add_particles(star2)
#    gravity.particles.move_to_center()

    channel_from_gravity_to_framework = gravity.particles.new_channel_to(star)
    channel_from_hydro_to_framework = hydro.particles.new_channel_to(disk)

    # make a repository of the star+disk particles in moving bodies
#    moving_bodies = star.union(disk)
    moving_bodies = ParticlesSuperset([star, disk])

    moving_bodies.move_to_center()

    write_set_to_file(moving_bodies, filename, 'hdf5')
    
    gravity_hydro = bridge.Bridge(use_threading=False)
    gravity_hydro.add_system(gravity, (hydro,) )
    gravity_hydro.add_system(hydro, (gravity,) )

    Etot_init = gravity_hydro.kinetic_energy + gravity_hydro.potential_energy
    Etot_prev = Etot_init

    time = 0.0 | t_end.unit
    dt = t_end/float(n_steps)
    gravity_hydro.timestep = dt/10.
    while time < t_end:
        time += dt
        gravity_hydro.evolve_model(time)

        Etot_prev_se = gravity_hydro.kinetic_energy + gravity_hydro.potential_energy

        channel_from_gravity_to_framework.copy()
        channel_from_hydro_to_framework.copy()
        write_set_to_file(moving_bodies, filename, 'hdf5')

        Ekin = gravity_hydro.kinetic_energy 
        Epot = gravity_hydro.potential_energy
        Etot = Ekin + Epot
        print "T=", time, 
        print "E= ", Etot, "Q= ", Ekin/Epot,
        print "dE=", (Etot_init-Etot)/Etot, "ddE=", (Etot_prev-Etot)/Etot 
        print "star=", star
        Etot_prev = Etot

    gravity_hydro.stop()
Exemple #26
0
def main(Mstar=1,
         Ndisk=100,
         Mdisk=0.001,
         Rmin=1,
         Rmax=100,
         t_end=10,
         n_steps=10,
         filename="nbody.hdf5"):
    #    numpy.random.seed(111)
    Mstar = Mstar | units.MSun
    Mdisk = Mdisk | units.MSun
    Rmin = Rmin | units.AU
    Rmax = Rmax | units.AU
    t_end = t_end | units.yr

    #    converter=nbody_system.nbody_to_si(Mdisk, Rmax)
    converter = nbody_system.nbody_to_si(Mstar, Rmin)
    disk = ProtoPlanetaryDisk(Ndisk,
                              convert_nbody=converter,
                              densitypower=1.5,
                              Rmin=Rmin.value_in(units.AU),
                              Rmax=Rmax.value_in(units.AU),
                              q_out=1.0,
                              discfraction=1.0).result

    disk.move_to_center()

    center_of_mass = disk.center_of_mass()
    print(center_of_mass)
    a_bump = 50
    Rbump = 10 | units.AU
    bump_location = center_of_mass + ([0, a_bump, 0] | units.AU)
    bump_particles = disk.select(
        lambda r: (center_of_mass - r).length() < Rbump, ["position"])
    Mbump = bump_particles.mass.sum()

    Nbump = len(bump_particles)
    print("Nbump=", len(bump_particles), Mbump, Rbump, Nbump)
    print("Mass =", Mstar, Mdisk,
          disk.mass.sum().in_(units.MSun),
          disk.mass.sum() / Mstar)
    bump = new_plummer_gas_model(Nbump,
                                 convert_nbody=nbody_system.nbody_to_si(
                                     0.1 * Mbump, Rbump))

    a_bump = a_bump | units.AU
    bump.x += a_bump
    r_bump = a_bump
    inner_particles = disk.select(
        lambda r: (center_of_mass - r).length() < a_bump, ["position"])
    M_inner = inner_particles.mass.sum() + Mstar

    v_circ = (constants.G * M_inner *
              (2. / r_bump - 1. / a_bump)).sqrt().value_in(units.kms)
    bump.velocity += [0, v_circ, 0] | units.kms
    print("MM=", M_inner, v_circ)

    disk.add_particles(bump)

    disk.h_smooth = Rmin / (Ndisk + Nbump)
    star = Particles(1)
    star.mass = Mstar
    star.radius = 1. | units.RSun
    star.position = [0, 0, 0] | units.AU
    star.velocity = [0, 0, 0] | units.kms

    #    star2=Particles(1)
    #    star2.mass=Mstar
    #    star2.radius=1. | units.RSun
    #    star2.position = [1, 0, 0] | units.AU
    #    star2.velocity = [0, 30, 0] | units.kms

    hydro = Fi(converter)
    #    hydror = Fi(channel_type="ibis", hostname="galgewater")

    hydro.parameters.use_hydro_flag = True
    hydro.parameters.radiation_flag = False
    hydro.parameters.self_gravity_flag = True
    hydro.parameters.gamma = 1.
    hydro.parameters.isothermal_flag = True
    hydro.parameters.integrate_entropy_flag = False
    hydro.parameters.timestep = 0.125 | units.yr

    hydro.gas_particles.add_particles(disk)

    gravity = Hermite(converter)
    gravity.particles.add_particles(star)
    #    gravity.particles.add_particles(star2)
    #    gravity.particles.move_to_center()

    channel_from_gravity_to_framework = gravity.particles.new_channel_to(star)
    channel_from_hydro_to_framework = hydro.particles.new_channel_to(disk)

    # make a repository of the star+disk particles in moving bodies
    #    moving_bodies = star.union(disk)
    moving_bodies = ParticlesSuperset([star, disk])

    moving_bodies.move_to_center()

    write_set_to_file(moving_bodies, filename, 'hdf5')

    gravity_hydro = bridge.Bridge(use_threading=False)
    gravity_hydro.add_system(gravity, (hydro, ))
    gravity_hydro.add_system(hydro, (gravity, ))

    Etot_init = gravity_hydro.kinetic_energy + gravity_hydro.potential_energy
    Etot_prev = Etot_init

    time = 0.0 | t_end.unit
    dt = t_end / float(n_steps)
    gravity_hydro.timestep = dt / 10.
    while time < t_end:
        time += dt
        gravity_hydro.evolve_model(time)

        Etot_prev_se = gravity_hydro.kinetic_energy + gravity_hydro.potential_energy

        channel_from_gravity_to_framework.copy()
        channel_from_hydro_to_framework.copy()
        write_set_to_file(moving_bodies, filename, 'hdf5')

        Ekin = gravity_hydro.kinetic_energy
        Epot = gravity_hydro.potential_energy
        Etot = Ekin + Epot
        print("T=", time, end=' ')
        print("E= ", Etot, "Q= ", Ekin / Epot, end=' ')
        print("dE=", (Etot_init - Etot) / Etot, "ddE=",
              (Etot_prev - Etot) / Etot)
        print("star=", star)
        Etot_prev = Etot

    gravity_hydro.stop()
def main(Ndisk, Mstar, Mdisk, Rin, Rout, t_end, Nray, x, y, z):

    time = 0 | units.Myr
    supernova_IIp = Supernova_IIp(10|units.day)
    
    efficiency_factor = 0.1
    Rsn = efficiency_factor * (x**2 + y**2 + z**2)**0.5

    supernova=Particle()
    supernova.position = (x.value_in(units.parsec),
                          y.value_in(units.parsec),
                          z.value_in(units.parsec)) |units.parsec
    supernova.position *= efficiency_factor
    supernova.luminosity = efficiency_factor**2 * supernova_IIp.luminosity_at_time(time)/(20.|units.eV)
#    supernova.flux = supernova.luminosity
    supernova.xion = 0.0
    supernova.u = (10**51 | units.erg)/(10|units.MSun)
    
    stellar = SeBa()
    star = Particle()
    star.mass = Mstar
    star.position = (0,0,0) | units.AU
    star.velocity = (0,0,0) | units.kms
    stellar.particles.add_particle(star)
    stellar.evolve_model(1|units.Myr)
    star.luminosity = stellar.particles[0].luminosity/(20. | units.eV)
    star.temperature = stellar.particles[0].temperature
    stellar.stop()
    star.u = (9. |units.kms)**2
    star.xion = 0.0
    print star

    print "M=", Mdisk/Mstar    
    converter=nbody_system.nbody_to_si(Mstar, 1 | units.AU)
    disk = ProtoPlanetaryDisk(Ndisk, convert_nbody=converter,
                              Rmin=Rin.value_in(units.AU), 
                              Rmax=Rout.value_in(units.AU),
                              q_out=25.0, discfraction=Mdisk/Mstar).result
####                              q_out=2.0, discfraction=Mdisk/Mstar).result
    print disk.x.max().in_(units.AU)
    print disk.mass.sum().in_(units.MSun)
    print disk.u.max().in_(units.kms**2)
    print disk.mass.min().in_(units.MSun)
    disk.flux = 0. | units.s**-1
    disk.xion = 0.0

    dt = t_end/1000.
    
    hydro = Fi(converter)
    hydro.parameters.use_hydro_flag=True
    hydro.parameters.radiation_flag=False
    hydro.parameters.self_gravity_flag=True
    
    hydro.parameters.gamma=1.
    hydro.parameters.isothermal_flag=True

# Non-isothermal: lowest temperature remains constat at 20K
#    hydro.parameters.gamma=1.66667
#    hydro.parameters.isothermal_flag=False
    
    hydro.parameters.integrate_entropy_flag=False
    hydro.parameters.timestep=0.5 | units.hour #0.125 | units.day
#    hydro.parameters.verbosity=99
    hydro.parameters.epsilon_squared=0.1 | units.AU**2
    hydro.parameters.courant=0.2    
    hydro.parameters.artificial_viscosity_alpha = 0.1 
    
    hydro.gas_particles.add_particles(disk)
    hydro.dm_particles.add_particle(star)
    hydro_to_disk = hydro.gas_particles.new_channel_to(disk)
    hydro_to_star = hydro.dm_particles.new_channel_to(star.as_set())
    disk_to_hydro = disk.new_channel_to(hydro.gas_particles)
    star_to_hydro = star.as_set().new_channel_to(hydro.dm_particles)
    hydro.evolve_model(1|units.hour)
    hydro_to_disk.copy()
    hydro_to_star.copy()
    
    radiative = SPHRay(redirection="file", number_of_workers=4)#, debugger="gdb")
    radiative.parameters.number_of_rays=Nray/dt
    print dt.in_(units.yr)
    radiative.parameters.default_spectral_type=-3.
    radiative.parameters.box_size=10000. | units.AU
    radiative.parameters.ionization_temperature_solver=2
    print radiative.parameters

#    radiative.src_particles.add_particle(star)
    radiative.src_particles.add_particle(supernova)
    radiative.gas_particles.add_particles(disk)

    gas_to_rad = disk.new_channel_to(radiative.gas_particles)
    rad_to_gas = radiative.gas_particles.new_channel_to(disk)
    
    print "Before"
    print "Luminosity:", radiative.src_particles.luminosity
    print "min ionization:", radiative.gas_particles.xion.min()
    print "average Xion:", radiative.gas_particles.xion.mean()
    print "max ionization:", radiative.gas_particles.xion.max()
    print "min u:", radiative.gas_particles.u.min()
    print "average u:", radiative.gas_particles.u.mean()
    print "max u:", radiative.gas_particles.u.max()

    Tmean = [] | units.K
    Tmin = [] | units.K
    Tmax = [] | units.K
    t = [] | units.day
    while radiative.model_time<t_end:

        supernova = update_source_particle(radiative, time+0.5*dt, supernova, efficiency_factor, supernova_IIp)

        radiative.evolve_model(time+0.5*dt)
        print "RT done at time:", time.in_(units.day)
        rad_to_gas.copy()

        disk_to_hydro.copy()
        star_to_hydro.copy()
        hydro.evolve_model(time + dt)
        hydro_to_disk.copy()
        hydro_to_star.copy()

        supernova = update_source_particle(radiative, time+dt, supernova, efficiency_factor, supernova_IIp)

        radiative.evolve_model(time+dt)
        print "RT done at time:", time.in_(units.day)
        rad_to_gas.copy()

        time += dt
        print_diagnostics(time, supernova, disk)
        
        Temperature =  mu() / constants.kB * disk.u
        t.append(time)
        Tmean.append(Temperature.mean())
        Tmin.append(Temperature.min())
        Tmax.append(Temperature.max())

        #write_set_to_file(disk, "disk_irradiation.amuse", "amuse")
        
        print "timescale:", (disk.mass.sum().value_in(units.amu)/((Rout/Rsn)**2*supernova.luminosity)).in_(units.yr)
        print "scaleheight:", abs(disk.z.value_in(units.AU)).mean()
        
        #pyplot.hist2d(abs(disk.x.value_in(units.AU)), abs(numpy.log10(Temperature.value_in(units.K))), bins=200)
       # pyplot.hist2d(abs(disk.x.value_in(units.AU)), abs(disk.z.value_in(units.AU)), bins=200)
        #,norm=LogNorm())
       #, Temperature.in_(units.K))
#       pyplot.tripcolor(abs(disk.x.value_in(units.AU)), abs(disk.y.value_in(units.AU)), Temperature.in_(units.K))
        #pyplot.hist(abs(disk.x.value_in(units.AU)), 100)
       # pyplot.show()

    print_diagnostics(time, supernova, disk)

    #plot_ionization_fraction(disk.position, disk.xion)
#    plot_ionization_fraction(disk.z, disk.u.value_in(units.kms**2))
#    plot_ionization_fraction(disk.x, disk.u.value_in(units.kms**2))
    radiative.stop()
    plot_temperature(t, Tmin, Tmean, Tmax)
        x, y, z, vx, vy, vz)
    rho = rho.reshape((N + 1, N + 1))

    return numpy.transpose(rho)


if __name__ == "__main__":

    N = 20000
    tend = 10. | units.yr
    Mstar = 1. | units.MSun

    convert = nbody_system.nbody_to_si(Mstar, 1. | units.AU)
    proto = ProtoPlanetaryDisk(N,
                               convert_nbody=convert,
                               densitypower=1.5,
                               Rmin=4,
                               Rmax=20,
                               q_out=1.)
    gas = proto.result
    gas.h_smooth = 0.06 | units.AU

    sun = Particles(1)
    sun.mass = Mstar
    sun.radius = 2. | units.AU
    sun.x = 0. | units.AU
    sun.y = 0. | units.AU
    sun.z = 0. | units.AU
    sun.vx = 0. | units.kms
    sun.vy = 0. | units.kms
    sun.vz = 0. | units.kms
Exemple #29
0
def main(Mstar = 1|units.MSun,
         Ndisk=100, Mdisk=0.9|units.MSun, 
         Rmin=1.0|units.AU, Rmax=100.0|units.AU, 
         Mbump=0.1|units.MSun,Rbump=10.0|units.AU, abump=10|units.AU,
         t_end=1, n_steps=10):

    converter=nbody_system.nbody_to_si(Mdisk, Rmin)
    from amuse.ext.protodisk import ProtoPlanetaryDisk
    bodies = ProtoPlanetaryDisk(Ndisk, convert_nbody=converter, 
                                densitypower=1.5, Rmin=1.0, 
                                Rmax=Rmax/Rmin, q_out=1.0,
                                discfraction=1.0).result
    Mdisk = bodies.mass.sum()
    bodies.move_to_center()
    com = bodies.center_of_mass()

    mm = Mdisk/float(Ndisk)
    Nbump = Mbump/mm
    bump = new_plummer_gas_model(Nbump, convert_nbody=nbody_system.nbody_to_si(Mbump, Rbump))

    bump.x += abump
    r_bump = abump 
    inner_particles = bodies.select(lambda r: (com-r).length()<abump,["position"])
    M_inner = inner_particles.mass.sum() + Mstar
    v_circ = (constants.G*M_inner*(2./r_bump - 1./abump)).sqrt().value_in(units.kms)
    bump.velocity += [0, v_circ, 0] | units.kms
    bodies.add_particles(bump)

    star=Particles(1)
    star.mass=Mstar
    star.radius= Rmin
    star.position = [0, 0, 0] | units.AU
    star.velocity = [0, 0, 0] | units.kms

    import math
    P_bump = (abump**3*4*math.pi**2/(constants.G*(Mbump+Mstar))).sqrt()
    t_end *= P_bump

    hydro = Gadget2(converter)
    hydro.gas_particles.add_particles(bodies)
    hydro.dm_particles.add_particles(star)
    Etot_init = hydro.kinetic_energy + hydro.potential_energy + hydro.thermal_energy

    particles = ParticlesSuperset([star, bodies])
    particles.move_to_center()
    particles.new_channel_to(hydro.particles).copy()
    bodies.h_smooth = Rmin # for the plotting routine
    channel_to_star = hydro.dm_particles.new_channel_to(star)
    channel_to_bodies = hydro.gas_particles.new_channel_to(bodies)

    write_set_to_file(star, "stars.hdf5","hdf5")
    write_set_to_file(bodies, "hydro.hdf5","hdf5")

    time = 0.0 | t_end.unit
    dt = t_end/float(n_steps)
    while time < t_end:
        time += dt
        hydro.evolve_model(time)

        channel_to_star.copy()
        channel_to_bodies.copy()
        write_set_to_file(star, "stars.hdf5","hdf5")
        write_set_to_file(bodies, "hydro.hdf5","hdf5")
        star.radius = Rmin

        from hydro_sink_particles import hydro_sink_particles
        lost = hydro_sink_particles(star, bodies)
        if len(lost)>0:
            hydro.particles.remove_particles(lost)
            hydro.particles.synchronize_to(particles)
            print "Disk=", hydro.model_time, len(bodies), len(lost), lost.mass.sum(), star.mass

        Ekin = hydro.kinetic_energy 
        Epot = hydro.potential_energy
        Eth = hydro.thermal_energy
        Etot = Ekin + Epot + Eth
        print "T=", hydro.get_time(), "M=", hydro.gas_particles.mass.sum(), 
        print "E= ", Etot, "Q= ", (Ekin+Eth)/Epot, "dE=", (Etot_init-Etot)/Etot
        print "Star=", hydro.model_time, star[0].mass, star[0].position

    hydro.stop()
Exemple #30
0
def disk_in_cluster(N_stars, N_gasParticles, W0):

	#set up protoplanetary disk
	Mdisk = 1.|units.MSun
	Rdisk = 100.|units.AU # HD 106906 b is at 700 AU
	Rmin, Rmax = 1.|units.AU, Rdisk
	converter_disk = nbody_system.nbody_to_si(Mdisk, Rdisk)

	disk_particles = ProtoPlanetaryDisk(N_gasParticles, convert_nbody=converter_disk, densitypower=1.5, Rmin=Rmin.value_in(units.AU), Rmax=Rmax.value_in(units.AU), q_out=1.0, discfraction=1.0).result

	hydro = Fi(converter_disk, mode='openmp')
	hydro.gas_particles.add_particles(disk_particles)

	hydro_to_framework = hydro.gas_particles.new_channel_to(disk_particles)
	framework_to_hydro = disk_particles.new_channel_to(hydro.gas_particles)

	#set up star cluster
	Mmin, Mmax = 0.1|units.MSun, 100.|units.MSun
	Rvir = 1.|units.parsec

	masses = new_kroupa_mass_distribution(N_stars, Mmax)
	Mtot_init = masses.sum()
	converter_cluster = nbody_system.nbody_to_si(Mtot_init, Rvir)
	stars = new_king_model(N_stars, W0, convert_nbody=converter_cluster)
	stars.mass = masses

	dist_diff = 100. #|units.parsec
	magic_index = -1

	#put the disk around star closest to 1 solar mass
	for i, star in enumerate(stars):

		star_x = star.position.value_in(units.parsec)[0]
		star_y = star.position.value_in(units.parsec)[1]
		star_z = star.position.value_in(units.parsec)[2]

		star_dist = np.sqrt(star_x**2 + star_y**2 + star_z**2)

		i_diff = np.abs(star_dist - 1.0)

		if i_diff < dist_diff:

			magic_index = i
			dist_diff = i_diff

	for gas_particle in disk_particles:

		gas_particle.position += stars[magic_index].position

	gravitating_bodies = ParticlesSuperset([stars, disk_particles])

	gravity = Hermite(converter_cluster)
	gravity.particles.add_particles(gravitating_bodies)

	gravity_to_framework = gravity.particles.new_channel_to(gravitating_bodies)
	framework_to_gravity = gravitating_bodies.new_channel_to(gravity.particles)

	combined = bridge.Bridge()
	combined.add_system(gravity, (hydro,))
	combined.add_system(hydro, (gravity,))

	tend, dt = 10.|units.Myr, 0.005|units.Myr

	sim_times_unitless = np.arange(0., tend.value_in(units.Myr)+dt.value_in(units.Myr), dt.value_in(units.Myr))
	sim_times = [ t|units.Myr for t in sim_times_unitless ]

	plt.rc('font', family = 'serif')
	cmap = cm.get_cmap('nipy_spectral')

	rvals, zvals = [], []

	t0 = time.time()

	for j, t in enumerate(sim_times):

		if j%1 == 0:
			print('')	
			print('simulation time: ', t)
			print('wall time: %.03f minutes'%((time.time()-t0)/60.))

		stars = gravity.particles[:N_stars]
		gas = gravity.particles[N_stars:]

		stars_x = [ stars.position[i].value_in(units.parsec)[0] for i in range(len(stars)) ]
		stars_y = [ stars.position[i].value_in(units.parsec)[1] for i in range(len(stars)) ]

		gas_x = [ gas.position[i].value_in(units.parsec)[0] for i in range(len(gas)) ]
		gas_y = [ gas.position[i].value_in(units.parsec)[1] for i in range(len(gas)) ]

		plt.figure()
		
		colors = np.log10(stars.mass.value_in(units.MSun))

		sc = plt.scatter(stars_x, stars_y, c=colors, s=1, alpha=0.5, label='Stars')
		gas_sc = plt.scatter(gas_x, gas_y, c='r', s=1, alpha=0.8, label='Protoplanetary Disk')
		cbar = plt.colorbar(sc)
		cbar.set_label(r'$\log_{10}(M_{\star}/M_{\odot})$', fontsize=14)

		plt.annotate(r'$M_{\mathrm{cluster}} = %.03f \, M_{\odot}$'%(Mtot_init.value_in(units.MSun)), xy=(0.65, 0.15), xycoords='axes fraction', fontsize=8)
		plt.annotate(r'$t = %.02f$ Myr'%(t.value_in(units.Myr)), xy=(0.65, 0.1), xycoords='axes fraction', fontsize=8)

		plt.xlim(-4.*Rvir.value_in(units.parsec), 4.*Rvir.value_in(units.parsec))
		plt.ylim(-4.*Rvir.value_in(units.parsec), 4.*Rvir.value_in(units.parsec))
		plt.gca().set_aspect('equal')
		plt.xlabel('$x$ (pc)', fontsize=14)
		plt.ylabel('$y$ (pc)', fontsize=14)
		plt.legend(loc='upper left', fontsize=8)
		plt.title(r'King Model, $W_{0} = %.01f$'%(W0), fontsize=14)

		plt.savefig('kingmodel_%s.png'%(str(j).rjust(5, '0')))
		plt.close()

		combined.evolve_model(t)

	combined.stop()

	return 0