コード例 #1
0
    def test6(self):
        print("Test whether a set of stars evolves synchronously...")
        #       Create an array of stars with a range in stellar mass
        masses = [.5, 1., 2., 5., 10., 30.] | units.MSun
        number_of_stars = len(masses)
        stars = Particles(number_of_stars)
        stars.mass = masses

        #       Initialize stellar evolution code
        instance = SSE()
        instance.commit_parameters()
        instance.particles.add_particles(stars)
        instance.commit_particles()

        from_code_to_model = instance.particles.new_channel_to(stars)
        from_code_to_model.copy()

        instance.evolve_model(end_time=125 | units.Myr)
        from_code_to_model.copy()

        end_types = (
            "deeply or fully convective low mass MS star",
            "Main Sequence star",
            "Main Sequence star",
            "Carbon/Oxygen White Dwarf",
            "Neutron Star",
            "Black Hole",
        )
        for i in range(number_of_stars):
            self.assertAlmostEqual(stars[i].age, 125.0 | units.Myr)
            self.assertTrue(stars[i].mass <= masses[i])
            self.assertEqual(str(stars[i].stellar_type), end_types[i])
        instance.stop()
コード例 #2
0
 def test12(self):
     print("Testing adding and removing particles from stellar evolution code...")
     
     particles = Particles(3)
     particles.mass = 1.0 | units.MSun
     
     instance = SSE()
     instance.initialize_code()
     instance.commit_parameters()
     self.assertEqual(len(instance.particles), 0) # before creation
     instance.particles.add_particles(particles[:-1])
     instance.commit_particles()
     instance.evolve_model(1.0 | units.Myr)
     self.assertEqual(len(instance.particles), 2) # before remove
     self.assertAlmostEqual(instance.particles.age, 1.0 | units.Myr)
     
     instance.particles.remove_particle(particles[0])
     self.assertEqual(len(instance.particles), 1)
     instance.evolve_model(2.0 | units.Myr)
     self.assertAlmostEqual(instance.particles[0].age, 2.0 | units.Myr)
     
     instance.particles.add_particles(particles[::2])
     self.assertEqual(len(instance.particles), 3) # it's back...
     self.assertAlmostEqual(instance.particles[0].age, 2.0 | units.Myr)
     self.assertAlmostEqual(instance.particles[1].age, 0.0 | units.Myr)
     self.assertAlmostEqual(instance.particles[2].age, 0.0 | units.Myr) # ... and rejuvenated.
     
     instance.evolve_model(3.0 | units.Myr) # The young stars keep their age offset from the old star
     self.assertAlmostEqual(instance.particles.age, [3.0, 1.0, 1.0] | units.Myr)
     instance.evolve_model(4.0 | units.Myr)
     self.assertAlmostEqual(instance.particles.age, [4.0, 2.0, 2.0] | units.Myr)
     instance.stop()
コード例 #3
0
ファイル: test_sse.py プロジェクト: vdhelm/amuse
 def test12(self):
     print "Testing adding and removing particles from stellar evolution code..."
     
     particles = Particles(3)
     particles.mass = 1.0 | units.MSun
     
     instance = SSE()
     instance.initialize_code()
     instance.commit_parameters()
     self.assertEquals(len(instance.particles), 0) # before creation
     instance.particles.add_particles(particles[:-1])
     instance.commit_particles()
     instance.evolve_model(1.0 | units.Myr)
     self.assertEquals(len(instance.particles), 2) # before remove
     self.assertAlmostEqual(instance.particles.age, 1.0 | units.Myr)
     
     instance.particles.remove_particle(particles[0])
     self.assertEquals(len(instance.particles), 1)
     instance.evolve_model(2.0 | units.Myr)
     self.assertAlmostEqual(instance.particles[0].age, 2.0 | units.Myr)
     
     instance.particles.add_particles(particles[::2])
     self.assertEquals(len(instance.particles), 3) # it's back...
     self.assertAlmostEqual(instance.particles[0].age, 2.0 | units.Myr)
     self.assertAlmostEqual(instance.particles[1].age, 0.0 | units.Myr)
     self.assertAlmostEqual(instance.particles[2].age, 0.0 | units.Myr) # ... and rejuvenated.
     
     instance.evolve_model(3.0 | units.Myr) # The young stars keep their age offset from the old star
     self.assertAlmostEqual(instance.particles.age, [3.0, 1.0, 1.0] | units.Myr)
     instance.evolve_model(4.0 | units.Myr)
     self.assertAlmostEqual(instance.particles.age, [4.0, 2.0, 2.0] | units.Myr)
     instance.stop()
コード例 #4
0
ファイル: test_sse.py プロジェクト: vdhelm/amuse
    def test6(self):
        print "Test whether a set of stars evolves synchronously..."
#       Create an array of stars with a range in stellar mass
        masses = [.5, 1., 2., 5., 10., 30.] | units.MSun
        number_of_stars = len(masses)
        stars = Particles(number_of_stars)
        stars.mass = masses

#       Initialize stellar evolution code
        instance = SSE()
        instance.commit_parameters() 
        instance.particles.add_particles(stars)
        instance.commit_particles()
        
        from_code_to_model = instance.particles.new_channel_to(stars)
        from_code_to_model.copy()
        
        instance.evolve_model(end_time = 125 | units.Myr)
        from_code_to_model.copy()
                
        end_types = (
            "deeply or fully convective low mass MS star",
            "Main Sequence star",
            "Main Sequence star",
            "Carbon/Oxygen White Dwarf",
            "Neutron Star",
            "Black Hole",
        )
        for i in range(number_of_stars):
            self.assertAlmostEquals(stars[i].age, 125.0 | units.Myr)
            self.assertTrue(stars[i].mass <= masses[i])
            self.assertEquals(str(stars[i].stellar_type), end_types[i])
        instance.stop()
コード例 #5
0
def planetplot():
    sun, planets = new_solar_system_for_mercury()

    initial = 12.2138 | units.Gyr
    final = 12.3300 | units.Gyr
    step = 10000.0 | units.yr

    timerange = VectorQuantity.arange(initial, final, step)
    gd = MercuryWayWard()
    gd.initialize_code()
    # gd.stopping_conditions.timeout_detection.disable()
    gd.central_particle.add_particles(sun)
    gd.orbiters.add_particles(planets)
    gd.commit_particles()

    se = SSE()
    # se.initialize_code()
    se.commit_parameters()
    se.particles.add_particles(sun)
    se.commit_particles()
    channelp = gd.orbiters.new_channel_to(planets)
    channels = se.particles.new_channel_to(sun)

    for time in timerange:
        err = gd.evolve_model(time-initial)
        channelp.copy()
        # planets.savepoint(time)
        err = se.evolve_model(time)
        channels.copy()
        gd.central_particle.mass = sun.mass
        print(
                sun[0].mass.value_in(units.MSun),
                time.value_in(units.Myr),
                planets[4].x.value_in(units.AU),
                planets[4].y.value_in(units.AU),
                planets[4].z.value_in(units.AU)
                )

    gd.stop()
    se.stop()

    for planet in planets:
        t, x = planet.get_timeline_of_attribute_as_vector("x")
        t, y = planet.get_timeline_of_attribute_as_vector("y")
        plot(x, y, '.')
        native_plot.gca().set_aspect('equal')

    native_plot.show()
コード例 #6
0
def planetplot():
    sun, planets = new_solar_system_for_mercury()

    initial = 12.2138 | units.Gyr
    final = 12.3300 | units.Gyr
    step = 10000.0 | units.yr

    timerange = VectorQuantity.arange(initial, final, step)
    gd = MercuryWayWard()
    gd.initialize_code()
    # gd.stopping_conditions.timeout_detection.disable()
    gd.central_particle.add_particles(sun)
    gd.orbiters.add_particles(planets)
    gd.commit_particles()

    se = SSE()
    # se.initialize_code()
    se.commit_parameters()
    se.particles.add_particles(sun)
    se.commit_particles()
    channelp = gd.orbiters.new_channel_to(planets)
    channels = se.particles.new_channel_to(sun)

    for time in timerange:
        err = gd.evolve_model(time - initial)
        channelp.copy()
        # planets.savepoint(time)
        err = se.evolve_model(time)
        channels.copy()
        gd.central_particle.mass = sun.mass
        print(
            (sun[0].mass.value_in(units.MSun), time.value_in(units.Myr),
             planets[4].x.value_in(units.AU), planets[4].y.value_in(units.AU),
             planets[4].z.value_in(units.AU)))

    gd.stop()
    se.stop()

    for planet in planets:
        t, x = planet.get_timeline_of_attribute_as_vector("x")
        t, y = planet.get_timeline_of_attribute_as_vector("y")
        plot(x, y, '.')
        native_plot.gca().set_aspect('equal')

    native_plot.show()
コード例 #7
0
ファイル: test_sse.py プロジェクト: vdhelm/amuse
 def test7(self):
     print "Test: evolve particles one at a time."
     print "Used to be problematic, since initial_mass of idle particle is set to zero."
     stars = Particles(2)
     stars.mass = 1.0 | units.MSun
     for star in stars:
         print star
         stellar_evolution = SSE()
         stellar_evolution.commit_parameters()
         stellar_evolution.particles.add_particles(star.as_set())
         stellar_evolution.commit_particles()
         from_stellar_evolution_to_model = stellar_evolution.particles.new_channel_to(star.as_set())
         stellar_evolution.evolve_model()
         from_stellar_evolution_to_model.copy()
         stellar_evolution.stop()
     self.assertEquals(stars[0].initial_mass, stars[1].initial_mass)
     self.assertEquals(stars[0].luminosity, stars[1].luminosity)
     self.assertEquals(stars[0].age, stars[1].age)
     print "Solved: SSE_muse_interface.f sets initial_mass to mass when necessary."
コード例 #8
0
 def test7(self):
     print("Test: evolve particles one at a time.")
     print("Used to be problematic, since initial_mass of idle particle is set to zero.")
     stars = Particles(2)
     stars.mass = 1.0 | units.MSun
     for star in stars:
         print(star)
         stellar_evolution = SSE()
         stellar_evolution.commit_parameters()
         stellar_evolution.particles.add_particles(star.as_set())
         stellar_evolution.commit_particles()
         from_stellar_evolution_to_model = stellar_evolution.particles.new_channel_to(star.as_set())
         stellar_evolution.evolve_model()
         from_stellar_evolution_to_model.copy()
         stellar_evolution.stop()
     self.assertEqual(stars[0].initial_mass, stars[1].initial_mass)
     self.assertEqual(stars[0].luminosity, stars[1].luminosity)
     self.assertEqual(stars[0].age, stars[1].age)
     print("Solved: SSE_muse_interface.f sets initial_mass to mass when necessary.")
コード例 #9
0
ファイル: stellar_mean_mass.py プロジェクト: amusecode/amuse
    stellar_evolution.commit_parameters()

    stars = Particles(o.N)
    Mmin = o.Mmin | units.MSun
    Mmax = o.Mmax | units.MSun
    if o.verbose:
        print("#Selected parameters: ")
        print("#\tN=", o.N)
        print("#\tIMF=", o.Mmin, "MSun", o.Mmax, "MSun", o.x_imf)
        print("#\t t [Myr] \t <m> [MSun] \t\t d<m>/dt [MSun/Myr]")

    stars.mass = new_salpeter_mass_distribution(
        o.N, mass_min=Mmin, mass_max=Mmax, alpha=o.x_imf)

    stars = stellar_evolution.particles.add_particles(stars)
    stellar_evolution.commit_particles()
    t = 0 | units.Myr
    mm = stars.mass.sum()/len(stars)
    while t < t_end:
        mm_last = mm
        t += dt
        stellar_evolution.evolve_model(t)
        mm = stars.mass.sum()/len(stars)
        dmm_dt = (mm_last-mm)/dt
        if o.verbose:
            print("t = ", t, "<m>=", mm.as_quantity_in(units.MSun),
                  " d<m>/dt = ", dmm_dt.as_quantity_in(units.MSun/units.Myr))
        else:
            print("\t", t, "\t", mm.as_quantity_in(units.MSun),
                  " \t ", dmm_dt.as_quantity_in(units.MSun/units.Myr))
コード例 #10
0
    stars = Particles(o.N)
    Mmin = o.Mmin | units.MSun
    Mmax = o.Mmax | units.MSun
    if o.verbose:
        print("#Selected parameters: ")
        print("#\tN=", o.N)
        print("#\tIMF=", o.Mmin, "MSun", o.Mmax, "MSun", o.x_imf)
        print("#\t t [Myr] \t <m> [MSun] \t\t d<m>/dt [MSun/Myr]")

    stars.mass = new_salpeter_mass_distribution(o.N,
                                                mass_min=Mmin,
                                                mass_max=Mmax,
                                                alpha=o.x_imf)

    stars = stellar_evolution.particles.add_particles(stars)
    stellar_evolution.commit_particles()
    t = 0 | units.Myr
    mm = stars.mass.sum() / len(stars)
    while t < t_end:
        mm_last = mm
        t += dt
        stellar_evolution.evolve_model(t)
        mm = stars.mass.sum() / len(stars)
        dmm_dt = (mm_last - mm) / dt
        if o.verbose:
            print("t = ", t, "<m>=", mm.as_quantity_in(units.MSun),
                  " d<m>/dt = ", dmm_dt.as_quantity_in(units.MSun / units.Myr))
        else:
            print("\t", t, "\t", mm.as_quantity_in(units.MSun), " \t ",
                  dmm_dt.as_quantity_in(units.MSun / units.Myr))