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)
    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 #2
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
Exemple #3
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 #4
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
Exemple #5
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 #6
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()
Exemple #7
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 #8
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()