コード例 #1
0
    def test5(self):
        halo_number_of_particles = 1000

        conv = nbody_system.nbody_to_si(1.e12 | units.MSun, 100. | units.kpc)

        particles1 = new_galactics_model(halo_number_of_particles,
                                         generate_bulge_flag=False,
                                         generate_disk_flag=False,
                                         order_of_multipole_expansion=0,
                                         halo_random_seed=-1,
                                         do_scale=False)
        particles2 = new_galactics_model(halo_number_of_particles,
                                         conv,
                                         generate_bulge_flag=False,
                                         generate_disk_flag=False,
                                         order_of_multipole_expansion=0,
                                         halo_random_seed=-1,
                                         do_scale=False)
        particles3 = new_galactics_model(halo_number_of_particles,
                                         generate_bulge_flag=False,
                                         generate_disk_flag=False,
                                         order_of_multipole_expansion=0,
                                         halo_random_seed=-1,
                                         do_scale=True)
        particles4 = new_galactics_model(halo_number_of_particles,
                                         conv,
                                         generate_bulge_flag=False,
                                         generate_disk_flag=False,
                                         order_of_multipole_expansion=0,
                                         halo_random_seed=-1,
                                         do_scale=True)

        self.assertEquals(len(particles1), halo_number_of_particles)
        self.assertEquals(len(particles2), halo_number_of_particles)
        self.assertEquals(len(particles3), halo_number_of_particles)
        self.assertEquals(len(particles4), halo_number_of_particles)

        self.assertAlmostEquals(conv.to_nbody(particles2.total_mass()),
                                particles1.total_mass())
        self.assertAlmostEquals(conv.to_nbody(particles4.total_mass()),
                                particles3.total_mass())
        self.assertAlmostEquals(particles3.total_mass(),
                                1. | nbody_system.mass)
        self.assertAlmostRelativeEquals(particles4.total_mass(),
                                        conv.to_si(1. | nbody_system.mass), 12)

        r1 = particles1.position.lengths().std()
        r2 = particles2.position.lengths().std()
        r3 = particles3.position.lengths().std()
        r4 = particles4.position.lengths().std()
        self.assertAlmostEquals(conv.to_nbody(r2), r1)
        self.assertAlmostEquals(conv.to_nbody(r4), r3)
        self.assertTrue(
            r1 / r3 >
            100)  # for the default parameters the scaling is quite drastic
        self.assertTrue(r2 / r4 > 100)
        print r1, r3
        print r2, r4
コード例 #2
0
ファイル: galaxy_merger.py プロジェクト: amusecode/amuse
def make_galaxies():
    if os.path.exists('disk_galactICs.amuse'):
        galaxy1 = read_set_from_file('disk_galactICs.amuse', 'amuse')
    else:
        halo_number_of_particles = NHALO
        converter = nbody_system.nbody_to_si(
            1.0e9 | units.MSun, 1. | units.kpc)
        galaxy1 = new_galactics_model(
                halo_number_of_particles,
                disk_number_of_particles=NDISK,
                generate_bulge_flag=False,
                unit_system_converter=converter,
                disk_random_seed=12345)
        write_set_to_file(galaxy1, 'disk_galactICs.amuse', 'amuse')

    galaxy2 = Particles(len(galaxy1))
    galaxy2.mass = galaxy1.mass
    galaxy2.position = galaxy1.position
    galaxy2.velocity = galaxy1.velocity

    galaxy1.rotate(0.0, numpy.pi/4, 0.0)
    galaxy2.rotate(numpy.pi/6, 0.0, 0.0)
    galaxy1.position += [100.0, 0, 0] | units.kpc
    galaxy2.position -= [100.0, 0, 0] | units.kpc
    galaxy1.velocity += [0.0, 50.0, 0] | units.km/units.s
    galaxy2.velocity -= [0.0, 50.0, 0] | units.km/units.s
    return galaxy1, galaxy2
コード例 #3
0
    def slowtest4(self):
        print "Generate a model for a disk galaxy (10k disk, no bulge, 20k halo) - SI units"
        halo_number_of_particles = 20000
        converter = generic_unit_converter.ConvertBetweenGenericAndSiUnits(
            constants.G, 1.0e12 | units.MSun, 50.0 | units.kpc)
        particles = new_galactics_model(halo_number_of_particles,
                                        disk_number_of_particles=10000,
                                        generate_bulge_flag=False,
                                        do_scale=True,
                                        unit_system_converter=converter)

        self.assertEquals(len(particles), 30000)
        self.assertAlmostRelativeEquals(particles.total_mass(),
                                        1.0e12 | units.MSun, 10)
        self.assertAlmostRelativeEquals(
            particles.kinetic_energy(),
            converter.to_si(0.25 | nbody_system.energy), 10)

        disk = particles[:10000]
        self.assertAlmostRelativeEquals(disk.total_mass(),
                                        2.156e10 | units.MSun, 3)
        self.assertAlmostRelativeEquals(
            disk.position.lengths_squared().amax().sqrt().in_(units.kpc),
            15.584 | units.kpc, 3)

        self.assertAlmostRelativeEquals(
            disk.position.std(axis=0).in_(units.kpc),
            [3.5934, 3.6768, 0.17078] | units.kpc, 3)

        write_set_to_file(
            particles,
            os.path.join(get_path_to_results(), 'disk_galactICs.amuse'),
            'amuse')
コード例 #4
0
def make_galaxies():
    if os.path.exists('disk_galactICs.amuse'):
        galaxy1 = read_set_from_file('disk_galactICs.amuse', 'amuse')
    else:
        halo_number_of_particles = NHALO
        converter = nbody_system.nbody_to_si(1.0e9 | units.MSun,
                                             1. | units.kpc)
        galaxy1 = new_galactics_model(halo_number_of_particles,
                                      disk_number_of_particles=NDISK,
                                      generate_bulge_flag=False,
                                      unit_system_converter=converter,
                                      disk_random_seed=12345)
        write_set_to_file(galaxy1, 'disk_galactICs.amuse', 'amuse')

    galaxy2 = Particles(len(galaxy1))
    galaxy2.mass = galaxy1.mass
    galaxy2.position = galaxy1.position
    galaxy2.velocity = galaxy1.velocity

    galaxy1.rotate(0.0, numpy.pi / 4, 0.0)
    galaxy2.rotate(numpy.pi / 6, 0.0, 0.0)
    galaxy1.position += [100.0, 0, 0] | units.kpc
    galaxy2.position -= [100.0, 0, 0] | units.kpc
    galaxy1.velocity += [0.0, 50.0, 0] | units.km / units.s
    galaxy2.velocity -= [0.0, 50.0, 0] | units.km / units.s
    return galaxy1, galaxy2
コード例 #5
0
ファイル: galaxy_merger.py プロジェクト: tjardaboekholt/amuse
def make_galaxies():
    # File 'disk_galactICs.amuse' contains 30k particles, (10k disk, no bulge, 20k halo)
    if os.path.exists('disk_galactICs.amuse'):
        galaxy1 = read_set_from_file('disk_galactICs.amuse', 'amuse')
    else:
        halo_number_of_particles = 20000
        converter = generic_unit_converter.ConvertBetweenGenericAndSiUnits(
            constants.G, 1.0e12 | units.MSun, 50.0 | units.kpc)
        galaxy1 = new_galactics_model(halo_number_of_particles,
                                      disk_number_of_particles=10000,
                                      generate_bulge_flag=False,
                                      do_scale=True,
                                      unit_system_converter=converter)
        write_set_to_file(galaxy1, 'disk_galactICs.amuse', 'amuse')

    galaxy2 = Particles(len(galaxy1))
    galaxy2.mass = galaxy1.mass
    galaxy2.position = galaxy1.position
    galaxy2.velocity = galaxy1.velocity

    galaxy1.rotate(0.0, numpy.pi / 4, 0.0)
    galaxy2.rotate(numpy.pi / 6, 0.0, 0.0)
    galaxy1.position += [100.0, 0, 0] | units.kpc
    galaxy2.position -= [100.0, 0, 0] | units.kpc
    galaxy1.velocity += [0.0, 50.0, 0] | units.km / units.s
    galaxy2.velocity -= [0.0, 50.0, 0] | units.km / units.s
    return galaxy1, galaxy2
コード例 #6
0
 def test1(self):
     halo_number_of_particles = 100
     particles = new_galactics_model(halo_number_of_particles, generate_bulge_flag = False, 
         generate_disk_flag = False, order_of_multipole_expansion = 0, halo_random_seed = -1, 
         do_scale = True)
     
     self.assertEquals(len(particles), halo_number_of_particles)
     self.assertAlmostEquals(particles.total_mass(), 1.0 | nbody_system.mass)
     self.assertAlmostEquals(particles.kinetic_energy(), 
         0.25 | nbody_system.energy)
コード例 #7
0
 def test1(self):
     halo_number_of_particles = 100
     particles = new_galactics_model(halo_number_of_particles, generate_bulge_flag = False, 
         generate_disk_flag = False, order_of_multipole_expansion = 0, halo_random_seed = -1, 
         do_scale = True)
     
     self.assertEquals(len(particles), halo_number_of_particles)
     self.assertAlmostEquals(particles.total_mass(), 1.0 | nbody_system.mass)
     self.assertAlmostEquals(particles.kinetic_energy(), 
         0.25 | nbody_system.energy)
コード例 #8
0
 def slowtest3(self):
     print "Generate a model for M31, using defaults (100k disk, 50k bulge, 200k halo) - Nbody units"
     halo_number_of_particles = 20000
     particles = new_galactics_model(halo_number_of_particles, do_scale = True, 
       bulge_number_of_particles=5000, disk_number_of_particles=10000)
     
     self.assertEquals(len(particles), 35000)
     self.assertAlmostEquals(particles.total_mass(), 1.0 | nbody_system.mass)
     self.assertAlmostEquals(particles.kinetic_energy(), 0.25 | nbody_system.energy)
     
     write_set_to_file(particles, os.path.join(get_path_to_results(), 'M31_galactICs.amuse'), 'amuse')
コード例 #9
0
 def slowtest3(self):
     print "Generate a model for M31, using defaults (100k disk, 50k bulge, 200k halo) - Nbody units"
     halo_number_of_particles = 20000
     particles = new_galactics_model(halo_number_of_particles, do_scale = True, 
       bulge_number_of_particles=5000, disk_number_of_particles=10000)
     
     self.assertEquals(len(particles), 35000)
     self.assertAlmostEquals(particles.total_mass(), 1.0 | nbody_system.mass)
     self.assertAlmostEquals(particles.kinetic_energy(), 0.25 | nbody_system.energy)
     
     write_set_to_file(particles, os.path.join(get_path_to_results(), 'M31_galactICs.amuse'), 'amuse')
コード例 #10
0
    def test5(self):
        halo_number_of_particles = 1000
        
        conv=nbody_system.nbody_to_si(1.e12 | units.MSun, 100. | units.kpc)
        
        particles1 = new_galactics_model(halo_number_of_particles, generate_bulge_flag = False, 
            generate_disk_flag = False, order_of_multipole_expansion = 0, halo_random_seed = -1, 
            do_scale = False)
        particles2 = new_galactics_model(halo_number_of_particles, conv, generate_bulge_flag = False, 
            generate_disk_flag = False, order_of_multipole_expansion = 0, halo_random_seed = -1, 
            do_scale = False)        
        particles3 = new_galactics_model(halo_number_of_particles, generate_bulge_flag = False, 
            generate_disk_flag = False, order_of_multipole_expansion = 0, halo_random_seed = -1, 
            do_scale = True)
        particles4 = new_galactics_model(halo_number_of_particles, conv,generate_bulge_flag = False, 
            generate_disk_flag = False, order_of_multipole_expansion = 0, halo_random_seed = -1, 
            do_scale = True)
            
                        
        self.assertEquals(len(particles1), halo_number_of_particles)
        self.assertEquals(len(particles2), halo_number_of_particles)
        self.assertEquals(len(particles3), halo_number_of_particles)
        self.assertEquals(len(particles4), halo_number_of_particles)
        
        self.assertAlmostEquals(conv.to_nbody(particles2.total_mass()), particles1.total_mass())
        self.assertAlmostEquals(conv.to_nbody(particles4.total_mass()), particles3.total_mass())
        self.assertAlmostEquals(particles3.total_mass(), 1. | nbody_system.mass)
        self.assertAlmostRelativeEquals(particles4.total_mass(), conv.to_si(1. | nbody_system.mass),12)

        r1=particles1.position.lengths().std()
        r2=particles2.position.lengths().std()
        r3=particles3.position.lengths().std()
        r4=particles4.position.lengths().std()
        self.assertAlmostEquals(conv.to_nbody(r2), r1)
        self.assertAlmostEquals(conv.to_nbody(r4), r3)
        self.assertTrue(r1/r3>100) # for the default parameters the scaling is quite drastic
        self.assertTrue(r2/r4>100)
        print r1,r3
        print r2,r4
コード例 #11
0
def make_galaxy_model(N, M_galaxy, R_galaxy, Mmin, Mmax):
    converter = nbody_system.nbody_to_si(M_galaxy, R_galaxy)
    n_halo = 0
    n_bulge = 0
    n_disk = N
    galaxy = new_galactics_model(n_halo,
                                 converter,
                                 do_scale=True,
                                 bulge_number_of_particles=n_bulge,
                                 disk_number_of_particles=n_disk)
    from amuse.lab import new_powerlaw_mass_distribution
    masses = new_powerlaw_mass_distribution(len(galaxy), Mmin, Mmax, -2.0)
    galaxy.mass = masses
    galaxy.radius = 10 | units.parsec
    galaxy.King_W0 = 3
    return galaxy
コード例 #12
0
 def slowtest4(self):
     print "Generate a model for a disk galaxy (10k disk, no bulge, 20k halo) - SI units"
     halo_number_of_particles = 20000
     converter = generic_unit_converter.ConvertBetweenGenericAndSiUnits(constants.G, 1.0e12 | units.MSun, 50.0 | units.kpc)
     particles = new_galactics_model(halo_number_of_particles, disk_number_of_particles=10000, 
         generate_bulge_flag=False, do_scale=True, unit_system_converter=converter)
     
     self.assertEquals(len(particles), 30000)
     self.assertAlmostRelativeEquals(particles.total_mass(), 1.0e12 | units.MSun, 10)
     self.assertAlmostRelativeEquals(particles.kinetic_energy(), converter.to_si(0.25 | nbody_system.energy), 10)
     
     disk = particles[:10000]
     self.assertAlmostRelativeEquals(disk.total_mass(), 2.156e10 | units.MSun, 3)
     self.assertAlmostRelativeEquals(disk.position.lengths_squared().amax().sqrt().in_(units.kpc),
                                              15.584 | units.kpc, 3)
                           
     self.assertAlmostRelativeEquals(disk.position.std(axis=0).in_(units.kpc), [3.5934, 3.6768, 0.17078] | units.kpc, 3)
     
     write_set_to_file(particles, os.path.join(get_path_to_results(), 'disk_galactICs.amuse'), 'amuse')
コード例 #13
0
def make_galaxy(n_halo, converter, glxy_name, test=False, **kwargs):
    widgets = [
        'Building {} galaxy: '.format(glxy_name),
        pbwg.AnimatedMarker(), ' ',
        pbwg.Timer(),
        pbwg.EndMsg()
    ]
    with pbar.ProgressBar(widgets=widgets, fd=sys.stdout) as progress:
        galaxy = new_galactics_model(n_halo, converter, **kwargs)

    out_path, current_model, tf = create_output_dir(glxy_name, test=test)
    galaxy_data_path = out_path + current_model

    widgets = [
        'Saving {} galaxy data in {}: '.format(glxy_name, out_path),
        pbwg.AnimatedMarker(),
        pbwg.EndMsg()
    ]
    with pbar.ProgressBar(widgets=widgets, fd=sys.stdout) as progress:
        write_set_to_file(galaxy, galaxy_data_path, 'hdf5')

    return galaxy, out_path
コード例 #14
0
ファイル: merge_two_galaxies.py プロジェクト: amusecode/amuse
def make_galaxies(M_galaxy, R_galaxy, n_halo, n_bulge, n_disk):
    converter=nbody_system.nbody_to_si(M_galaxy, R_galaxy)
    galaxy1 = new_galactics_model(n_halo,
                                  converter,
                                  #do_scale = True,
                                  bulge_number_of_particles=n_bulge,
                                  disk_number_of_particles=n_disk)
    galaxy2 = Particles(len(galaxy1))
    galaxy2.mass = galaxy1.mass
    galaxy2.position = galaxy1.position
    galaxy2.velocity = galaxy1.velocity
    
    galaxy1.rotate(0., numpy.pi/2, numpy.pi/4)
    galaxy1.position += [100.0, 100, 0] | units.kpc
#    galaxy1.velocity += [-3000.0, 0.0, -3000.0] | units.km/units.s
    galaxy1.velocity += [-10.0, 0.0, -10.0] | units.km/units.s

    galaxy2.rotate(numpy.pi/4, numpy.pi/4, 0.0)
    galaxy2.position -= [100.0, 0, 0] | units.kpc
    galaxy2.velocity -= [0.0, 0.0, 0] | units.km/units.s

    return galaxy1, galaxy2, converter
コード例 #15
0
ファイル: galaxy_merger.py プロジェクト: Ingwar/amuse
def make_galaxies():
    # File 'disk_galactICs.amuse' contains 30k particles, (10k disk, no bulge, 20k halo)
    if os.path.exists('disk_galactICs.amuse'):
        galaxy1 = read_set_from_file('disk_galactICs.amuse', 'amuse')
    else:
        halo_number_of_particles = 20000
        converter = generic_unit_converter.ConvertBetweenGenericAndSiUnits(constants.G, 1.0e12 | units.MSun, 50.0 | units.kpc)
        galaxy1 = new_galactics_model(halo_number_of_particles, disk_number_of_particles=10000, 
            generate_bulge_flag=False, do_scale=True, unit_system_converter=converter)
        write_set_to_file(galaxy1, 'disk_galactICs.amuse', 'amuse')
    
    galaxy2 = Particles(len(galaxy1))
    galaxy2.mass = galaxy1.mass
    galaxy2.position = galaxy1.position
    galaxy2.velocity = galaxy1.velocity
    
    galaxy1.rotate(0.0, numpy.pi/4, 0.0)
    galaxy2.rotate(numpy.pi/6, 0.0, 0.0)
    galaxy1.position += [100.0, 0, 0] | units.kpc
    galaxy2.position -= [100.0, 0, 0] | units.kpc
    galaxy1.velocity += [0.0, 50.0, 0] | units.km/units.s
    galaxy2.velocity -= [0.0, 50.0, 0] | units.km/units.s
    return galaxy1, galaxy2
コード例 #16
0
def make_galaxies(M_galaxy, R_galaxy, n_halo, n_bulge, n_disk):
    converter = nbody_system.nbody_to_si(M_galaxy, R_galaxy)
    galaxy1 = new_galactics_model(
        n_halo,
        converter,
        #do_scale = True,
        bulge_number_of_particles=n_bulge,
        disk_number_of_particles=n_disk)
    galaxy2 = Particles(len(galaxy1))
    galaxy2.mass = galaxy1.mass
    galaxy2.position = galaxy1.position
    galaxy2.velocity = galaxy1.velocity

    galaxy1.rotate(0., numpy.pi / 2, numpy.pi / 4)
    galaxy1.position += [100.0, 100, 0] | units.kpc
    #    galaxy1.velocity += [-3000.0, 0.0, -3000.0] | units.km/units.s
    galaxy1.velocity += [-10.0, 0.0, -10.0] | units.km / units.s

    galaxy2.rotate(numpy.pi / 4, numpy.pi / 4, 0.0)
    galaxy2.position -= [100.0, 0, 0] | units.kpc
    galaxy2.velocity -= [0.0, 0.0, 0] | units.km / units.s

    return galaxy1, galaxy2, converter
コード例 #17
0
import numpy
from amuse.lab import *
from amuse.ext.galactics_model import new_galactics_model

M_galaxy = 1.0e12 | units.MSun  # Mass of the galaxy
R_galaxy = 10 | units.kpc  # Radius of the galaxy
n_halo = 20000  # Number of particles for halo
n_bulge = 10000  # Number of particles for bulge
n_disk = 10000  # Number of particles for disk

# Converter: used to turn n-body system units to the physical units we are interested in
converter = nbody_system.nbody_to_si(M_galaxy, R_galaxy)
galaxy1 = new_galactics_model(n_halo,
                              converter,
                              bulge_number_of_particles=n_bulge,
                              disk_number_of_particles=n_disk)

# rotate function from the galactics_model module
galaxy1.rotate(0., numpy.pi / 2, numpy.pi / 4)

# Set position and velocity for the galaxy
galaxy1.position += [100.0, 100, 0] | units.kpc
galaxy1.velocity += [-10.0, 0.0, -10.0] | units.km / units.s

# Start SPH code
dynamics = Gadget2(converter, number_of_workers=4)
dynamics.parameters.epsilon_squared = (100
                                       | units.parsec)**2  # Softening length

set1 = dynamics.particles.add_particles(galaxy1)
dynamics.particles.move_to_center()