コード例 #1
0
ファイル: merge_recipes.py プロジェクト: rieder/ekster
def form_new_star(
    densest_gas_particle,
    gas_particles,
    # density_threshold=
):
    """
    Forms a new star by merging all gas particles within a Jeans radius of the
    densest particle. Returns the new star and all particles used to make it.
    """
    new_star = Particle()
    gas_copy = gas_particles.copy()

    # densest_gas_particle = gas_copy.sorted_by_attribute("density")[0]
    jeans_radius = 0.025 | units.parsec  # 100 | units.AU
    gas_copy.position -= densest_gas_particle.position
    gas_copy.distance_to_core = gas_copy.position.lengths()
    dense_gas = gas_copy.select(lambda x: x < jeans_radius,
                                ["distance_to_core"])
    new_star.mass = dense_gas.mass.sum()
    new_star.position = (dense_gas.center_of_mass() +
                         densest_gas_particle.position)
    new_star.velocity = dense_gas.center_of_mass_velocity()
    new_star.radius = jeans_radius
    absorbed_gas = dense_gas

    return new_star, absorbed_gas
コード例 #2
0
ファイル: orbit_in_potential.py プロジェクト: amusecode/amuse
def new_single_star(mass, pos, vel):
    single_star = Particle()
    single_star.mass = mass
    single_star.position = pos
    single_star.velocity = vel
    single_star.radius = 1.0 | units.RSun
    return single_star
コード例 #3
0
ファイル: star_to_sph.py プロジェクト: Ingwar/amuse
    def result(self):
        if self.pickle_file is None:
            self.retrieve_stellar_structure()
        else:
            self.unpickle_stellar_structure()

        if self.with_core_particle:
            self.setup_core_parameters()

        sph_particles = self.convert_to_SPH()
        if self.do_relax:
            for result_string in self.relax(sph_particles):
                print result_string

        specific_internal_energy, composition, mu = self.interpolate_internal_energy(
            sph_particles.position.lengths(),
            do_composition_too = self.do_store_composition
        )
        sph_particles.u = specific_internal_energy
        if self.do_store_composition:
            sph_particles.add_vector_attribute("composition", self.species_names)
            sph_particles.composition = composition
            sph_particles.mu = mu

        if self.with_core_particle and self.core_radius:
            core_particle = Particle()
            core_particle.mass = self.core_mass
            core_particle.position = [0.0, 0.0, 0.0] | units.m
            core_particle.velocity = [0.0, 0.0, 0.0] | units.m / units.s
            core_particle.radius = self.core_radius
            return StellarModelInSPH(gas_particles=sph_particles, core_particle=core_particle, core_radius=self.core_radius)
        return StellarModelInSPH(gas_particles=sph_particles, core_particle=None, core_radius=None)
コード例 #4
0
    def result(self):
        if self.pickle_file is None:
            self.retrieve_stellar_structure()
        else:
            self.unpickle_stellar_structure()

        if self.with_core_particle:
            self.setup_core_parameters()

        sph_particles = self.convert_to_SPH()
        if self.do_relax:
            for result_string in self.relax(sph_particles):
                print(result_string)

        specific_internal_energy, composition, mu = self.interpolate_internal_energy(
            sph_particles.position.lengths(),
            do_composition_too = self.do_store_composition
        )
        sph_particles.u = specific_internal_energy
        if self.do_store_composition:
            sph_particles.add_vector_attribute("composition", self.species_names)
            sph_particles.composition = composition
            sph_particles.mu = mu

        if self.with_core_particle and self.core_radius:
            core_particle = Particle()
            core_particle.mass = self.core_mass
            core_particle.position = [0.0, 0.0, 0.0] | units.m
            core_particle.velocity = [0.0, 0.0, 0.0] | units.m / units.s
            core_particle.radius = self.core_radius
            return StellarModelInSPH(gas_particles=sph_particles, core_particle=core_particle, core_radius=self.core_radius)
        return StellarModelInSPH(gas_particles=sph_particles, core_particle=None, core_radius=None)
コード例 #5
0
    def test7(self):
        print "Testing Pikachu states"
        stars = new_plummer_model(100)
        black_hole = Particle()
        black_hole.mass = 1.0 | nbody_system.mass
        black_hole.radius = 0.0 | nbody_system.length
        black_hole.position = [0.0, 0.0, 0.0] | nbody_system.length
        black_hole.velocity = [0.0, 0.0, 0.0] | nbody_system.speed

        print "First do everything manually:"
        instance = self.new_instance_of_an_optional_code(
            Pikachu, **default_options)
        self.assertEquals(instance.get_name_of_current_state(),
                          'UNINITIALIZED')
        instance.initialize_code()
        self.assertEquals(instance.get_name_of_current_state(), 'INITIALIZED')
        #~        instance.parameters.rcut_out_star_star = 1.0 | nbody_system.length
        instance.parameters.timestep = 0.001 | nbody_system.time
        instance.commit_parameters()
        self.assertEquals(instance.get_name_of_current_state(), 'EDIT')
        instance.particles.add_particles(stars)
        instance.commit_particles()
        self.assertEquals(instance.get_name_of_current_state(), 'RUN')
        instance.particles.remove_particle(stars[0])
        instance.particles.add_particle(black_hole)
        self.assertEquals(instance.get_name_of_current_state(), 'UPDATE')
        instance.recommit_particles()
        self.assertEquals(instance.get_name_of_current_state(), 'RUN')
        instance.evolve_model(0.001 | nbody_system.time)
        self.assertEquals(instance.get_name_of_current_state(), 'EVOLVED')
        instance.synchronize_model()
        self.assertEquals(instance.get_name_of_current_state(), 'RUN')
        instance.cleanup_code()
        self.assertEquals(instance.get_name_of_current_state(), 'END')
        instance.stop()

        print "initialize_code(), commit_parameters(), (re)commit_particles(), " \
            "synchronize_model(), and cleanup_code() should be called " \
            "automatically before editing parameters, new_particle(), get_xx(), and stop():"
        instance = self.new_instance_of_an_optional_code(
            Pikachu, **default_options)
        self.assertEquals(instance.get_name_of_current_state(),
                          'UNINITIALIZED')
        instance.parameters.timestep = 0.001 | nbody_system.time
        self.assertEquals(instance.get_name_of_current_state(), 'INITIALIZED')
        instance.particles.add_particles(stars)
        self.assertEquals(instance.get_name_of_current_state(), 'EDIT')
        mass = instance.particles[0].mass
        self.assertEquals(instance.get_name_of_current_state(), 'RUN')
        instance.particles.remove_particle(stars[0])
        instance.particles.add_particle(black_hole)
        self.assertEquals(instance.get_name_of_current_state(), 'UPDATE')
        mass = instance.particles[0].mass
        self.assertEquals(instance.get_name_of_current_state(), 'RUN')
        instance.evolve_model(0.001 | nbody_system.time)
        self.assertEquals(instance.get_name_of_current_state(), 'EVOLVED')
        mass = instance.particles[0].mass
        self.assertEquals(instance.get_name_of_current_state(), 'RUN')
        instance.stop()
        self.assertEquals(instance.get_name_of_current_state(), 'STOPPED')
コード例 #6
0
def new_single_star(mass, pos, vel):
    single_star = Particle()
    single_star.mass = mass
    single_star.position = pos
    single_star.velocity = vel
    single_star.radius = 1.0 | units.RSun
    return single_star
コード例 #7
0
 def new_particle_from_model(self,
                             internal_structure,
                             current_age,
                             key=None):
     tmp_star = Particle(key=key)
     tmp_star.mass = internal_structure["mass"]
     tmp_star.radius = internal_structure["radius"]
     tmp_star.type = "new particle from model"
     return self.particles.add_particle(tmp_star)
コード例 #8
0
ファイル: test_pikachu.py プロジェクト: Ingwar/amuse
    def test7(self):
        print "Testing Pikachu states"
        stars = new_plummer_model(100)
        black_hole = Particle()
        black_hole.mass = 1.0 | nbody_system.mass
        black_hole.radius =  0.0 | nbody_system.length
        black_hole.position = [0.0, 0.0, 0.0] | nbody_system.length
        black_hole.velocity = [0.0, 0.0, 0.0] | nbody_system.speed
        
        print "First do everything manually:"
        instance = self.new_instance_of_an_optional_code(Pikachu, **default_options)
        self.assertEquals(instance.get_name_of_current_state(), 'UNINITIALIZED')
        instance.initialize_code()
        self.assertEquals(instance.get_name_of_current_state(), 'INITIALIZED')
#~        instance.parameters.rcut_out_star_star = 1.0 | nbody_system.length
        instance.parameters.timestep = 0.001 | nbody_system.time
        instance.commit_parameters()
        self.assertEquals(instance.get_name_of_current_state(), 'EDIT')
        instance.particles.add_particles(stars)
        instance.commit_particles()
        self.assertEquals(instance.get_name_of_current_state(), 'RUN')
        instance.particles.remove_particle(stars[0])
        instance.particles.add_particle(black_hole)
        self.assertEquals(instance.get_name_of_current_state(), 'UPDATE')
        instance.recommit_particles()
        self.assertEquals(instance.get_name_of_current_state(), 'RUN')
        instance.evolve_model(0.001 | nbody_system.time)
        self.assertEquals(instance.get_name_of_current_state(), 'EVOLVED')
        instance.synchronize_model()
        self.assertEquals(instance.get_name_of_current_state(), 'RUN')
        instance.cleanup_code()
        self.assertEquals(instance.get_name_of_current_state(), 'END')
        instance.stop()
        
        print "initialize_code(), commit_parameters(), (re)commit_particles(), " \
            "synchronize_model(), and cleanup_code() should be called " \
            "automatically before editing parameters, new_particle(), get_xx(), and stop():"
        instance = self.new_instance_of_an_optional_code(Pikachu, **default_options)
        self.assertEquals(instance.get_name_of_current_state(), 'UNINITIALIZED')
        instance.parameters.timestep = 0.001 | nbody_system.time
        self.assertEquals(instance.get_name_of_current_state(), 'INITIALIZED')
        instance.particles.add_particles(stars)
        self.assertEquals(instance.get_name_of_current_state(), 'EDIT')
        mass = instance.particles[0].mass
        self.assertEquals(instance.get_name_of_current_state(), 'RUN')
        instance.particles.remove_particle(stars[0])
        instance.particles.add_particle(black_hole)
        self.assertEquals(instance.get_name_of_current_state(), 'UPDATE')
        mass = instance.particles[0].mass
        self.assertEquals(instance.get_name_of_current_state(), 'RUN')
        instance.evolve_model(0.001 | nbody_system.time)
        self.assertEquals(instance.get_name_of_current_state(), 'EVOLVED')
        mass = instance.particles[0].mass
        self.assertEquals(instance.get_name_of_current_state(), 'RUN')
        instance.stop()
        self.assertEquals(instance.get_name_of_current_state(), 'STOPPED')
コード例 #9
0
def new_system(star_mass=1 | units.MSun,
               star_radius=1 | units.RSun,
               disk_minimum_radius=0.05 | units.AU,
               disk_maximum_radius=10 | units.AU,
               disk_mass=20 | MEarth,
               accurancy=0.0001,
               planet_density=3 | units.g / units.cm**3,
               rng=None,
               kepler=None):

    central_particle = Particle()
    central_particle.mass = star_mass
    central_particle.position = (0, 0, 0) | units.AU
    central_particle.velocity = (0, 0, 0) | units.kms
    central_particle.radius = star_radius
    central_particle.name = "star"
    central_particle.type = "star"
    central_particle.id = 0

    if rng is None:
        rng = numpy.random

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

    if kepler is None:
        kepler = Kepler(converter)
        kepler.initialize_code()

    m, r, f = new_planet_distribution(disk_minimum_radius, disk_maximum_radius,
                                      disk_mass, accurancy)

    planets = make_planets(central_particle,
                           m,
                           r,
                           density=planet_density,
                           phi=0,
                           theta=None,
                           kepler=kepler,
                           rng=rng)
    planets.name = "planet"
    planets.type = "planet"
    for i in range(len(planets)):
        planets[i].id = i

    central_particle.planets = planets
    kepler.stop()
    p = Particles()
    p.add_particle(central_particle)
    return p
def get_moons_for_planet(planet, delta_JD=0. | units.day):
    """
  The Earth's moon
  as for JD = 2457099.500000000 = A.D. 2015-Mar-18 00:00:00.0000 (CT)
  https://ssd.jpl.nasa.gov/?sat_elem
  """

    data = numpy.array([tuple(entry) for entry in _lunar_data],
                       dtype=[('planet_name', 'S10'), ('name', 'S10'),
                              ('mass', '<f8'), ('radius', '<f8'),
                              ('semimajor_axis', '<f8'),
                              ('eccentricity', '<f8'),
                              ('argument_of_peri', '<f8'),
                              ('mean_anomaly', '<f8'), ('inclination', '<f8'),
                              ('longitude_oan', '<f8')])
    moon_data = data[data['planet_name'] == planet.name.encode('UTF-8')]
    print("Planet=", planet.name, "moon=", moon_data["name"])
    moons = Particles()
    if len(moon_data["name"]):
        print(len(moon_data["name"]))
        for moon in moon_data:
            #Ignore the moon for now, because it's complicated
            if planet.name == "EarthMoon":
                planet.mass -= moon["mass"] * 1.e+16 | units.kg
                planet.name = "Earth"
            #print moon
            r, v = get_position(planet.mass,
                                moon["mass"] * 1.e+16 | units.kg,
                                moon["eccentricity"],
                                moon["semimajor_axis"] | units.km,
                                numpy.deg2rad(moon["mean_anomaly"]),
                                numpy.deg2rad(moon["inclination"]),
                                numpy.deg2rad(moon["longitude_oan"]),
                                numpy.deg2rad(moon["argument_of_peri"]),
                                delta_t=delta_JD)
            single_moon = Particle()
            single_moon.type = "moon"
            single_moon.name = moon["name"]
            single_moon.mass = moon["mass"] * 1.e+16 | units.kg
            single_moon.hostname = moon["planet_name"]
            single_moon.radius = moon["radius"] | units.km
            single_moon.position = r
            single_moon.position += planet.position
            single_moon.velocity = v
            single_moon.velocity += planet.velocity
            moons.add_particle(single_moon)

    return moons
コード例 #11
0
def new_particle_from_cluster_core(particles,
                                   unit_converter=None,
                                   density_weighting_power=2,
                                   cm=None,
                                   reuse_hop=False,
                                   hop=HopContainer()):
    """
    Uses Hop to find the density centre (core) of a particle distribution
    and stores the properties of this core on a particle:
    position, velocity, (core) radius and (core) density.
    
    Particles are assigned weights that depend on the density (as determined by 
    Hop) to a certain power.
    The default weighting power is 2, which is most commonly used. Set 
    density_weighting_power to 1 in order to get the original weighting of 
    Casertano & Hut (1985, ApJ, 298, 80).
    
    :argument unit_converter: Required if the particles are in SI units
    :argument density_weighting_power: Particle properties are weighted by density to this power
    """
    if isinstance(hop, HopContainer):
        hop.initialize(unit_converter)
        hop = hop.code
    in_hop = hop.particles.add_particles(particles)
    hop.parameters.density_method = 2
    hop.parameters.number_of_neighbors_for_local_density = 7
    hop.calculate_densities()
    density = in_hop.density.copy()
    if not reuse_hop:
        hop.stop()

    weights = (density**density_weighting_power).reshape((-1, 1))
    # Reshape makes sure that density can be multiplied with vectors, e.g. position

    result = Particle()
    result.density = density.amax()
    total_weight = weights.sum()
    if cm is None:
        result.position = (weights *
                           particles.position).sum(axis=0) / total_weight
    else:
        result.position = cm
    result.velocity = (weights * particles.velocity).sum(axis=0) / total_weight
    result.radius = (
        weights.flatten() *
        (particles.position - result.position).lengths()).sum() / total_weight
    return result
コード例 #12
0
def new_system(
        star_mass = 1|units.MSun, 
        star_radius = 1|units.RSun, 
        disk_minumum_radius = 0.05 | units.AU,
        disk_maximum_radius = 10 | units.AU,
        disk_mass = 20 | MEarth,
        accurancy = 0.0001, 
        planet_density =  3 | units.g/units.cm**3,
        rng = None,
        kepler = None):
            
    central_particle = Particle()
    central_particle.mass =  star_mass
    central_particle.position = (0,0,0) | units.AU
    central_particle.velocity = (0,0,0) | units.kms
    central_particle.radius = star_radius
    
    if rng is None:
        rng = numpy.random
        
    converter = nbody_system.nbody_to_si(1|units.MSun, 1 | units.AU)
    
    if kepler is None:
        kepler = Kepler(converter)
        kepler.initialize_code()
        
    m, r, f = new_planet_distribution(
        disk_minumum_radius, disk_maximum_radius, 
        disk_mass,
        accurancy
    )
    
    planets = make_planets(
        central_particle, 
        m, r, 
        density = planet_density, 
        phi = 0, theta = None, 
        kepler = kepler, 
        rng = rng
    )
    
    central_particle.planets = planets
    kepler.stop()
    p = Particles()
    p.add_particle(central_particle)
    return p
コード例 #13
0
ファイル: solarsystem.py プロジェクト: tjardaboekholt/amuse
def old_new_solar_system():
    """
    Create initial conditions describing the solar system. Returns a single 
    particle set containing the sun, planets and Pluto. The model is centered at 
    the origin (center-of-mass(-velocity) coordinates).
    
    Defined attributes: 
    name, mass, radius, x, y, z, vx, vy, vz
    """
    sun = Particle()
    sun.name = 'SUN'
    sun.mass = 1.0 | units.MSun
    sun.radius = 1.0 | units.RSun
    planets = _planets_only()
    
    particles = Particles()
    particles.add_particle(sun)
    particles.add_particles(planets)
    particles.move_to_center()
    return particles
コード例 #14
0
def get_moons_for_planet(planet, delta_JD=0.|units.day):
  """
  The Earth's moon
  as for JD = 2457099.500000000 = A.D. 2015-Mar-18 00:00:00.0000 (CT)
  https://ssd.jpl.nasa.gov/?sat_elem
  """

  data = numpy.array([tuple(entry) for entry in _lunar_data],
        dtype=[('planet_name','S10'), ('name','S10'), 
        ('mass','<f8'), ('radius','<f8'), ('semimajor_axis','<f8'), 
        ('eccentricity','<f8'), ('argument_of_peri','<f8'),
        ('mean_anomaly','<f8'), ('inclination','<f8'), ('longitude_oan','<f8')])
  moon_data = data[data['planet_name']==planet.name]
  print "Planet=", planet.name, "moon=", moon_data["name"]
  moons = Particles()
  if len(moon_data["name"]):
      print len(moon_data["name"])
      for moon in moon_data:
          #print moon
          r, v = get_position(planet.mass,
                              moon["mass"] * 1.e+16 | units.kg,
                              moon["eccentricity"],
                              moon["semimajor_axis"]|units.km,
                              numpy.deg2rad(moon["mean_anomaly"]),
                              numpy.deg2rad(moon["inclination"]),
                              numpy.deg2rad(moon["longitude_oan"]),
                              numpy.deg2rad(moon["argument_of_peri"]),
                              delta_t=delta_JD)
          single_moon = Particle()
          single_moon.type = "moon"
          single_moon.name = moon["name"]
          single_moon.mass = moon["mass"] * 1.e+16 | units.kg
          single_moon.hostname = moon["planet_name"]
          single_moon.radius = moon["radius"] | units.km
          single_moon.position = r
          single_moon.position += planet.position
          single_moon.velocity = v
          single_moon.velocity += planet.velocity
          moons.add_particle(single_moon)
    
  return moons
コード例 #15
0
ファイル: particle_attributes.py プロジェクト: rieder/amuse
def new_particle_from_cluster_core(
    particles, unit_converter=None, density_weighting_power=2, cm=None, reuse_hop=False, hop=HopContainer()
):
    """
    Uses Hop to find the density centre (core) of a particle distribution
    and stores the properties of this core on a particle:
    position, velocity, (core) radius and (core) density.
    
    Particles are assigned weights that depend on the density (as determined by 
    Hop) to a certain power.
    The default weighting power is 2, which is most commonly used. Set 
    density_weighting_power to 1 in order to get the original weighting of 
    Casertano & Hut (1985, ApJ, 298, 80).
    
    :argument unit_converter: Required if the particles are in SI units
    :argument density_weighting_power: Particle properties are weighted by density to this power
    """
    if isinstance(hop, HopContainer):
        hop.initialize(unit_converter)
        hop = hop.code
    in_hop = hop.particles.add_particles(particles)
    hop.parameters.density_method = 2
    hop.parameters.number_of_neighbors_for_local_density = 7
    hop.calculate_densities()
    density = in_hop.density.copy()
    if not reuse_hop:
        hop.stop()

    weights = (density ** density_weighting_power).reshape((-1, 1))
    # Reshape makes sure that density can be multiplied with vectors, e.g. position

    result = Particle()
    result.density = density.amax()
    total_weight = weights.sum()
    if cm is None:
        result.position = (weights * particles.position).sum(axis=0) / total_weight
    else:
        result.position = cm
    result.velocity = (weights * particles.velocity).sum(axis=0) / total_weight
    result.radius = (weights.flatten() * (particles.position - result.position).lengths()).sum() / total_weight
    return result
コード例 #16
0
 def new_particle_from_model(self, internal_structure, current_age, key=None):
     tmp_star = Particle(key=key)
     tmp_star.mass = internal_structure["mass"]
     tmp_star.radius = internal_structure["radius"]
     tmp_star.type = "new particle from model" | units.string
     return self.particles.add_particle(tmp_star)