当前位置: 首页>>代码示例>>Python>>正文


Python interface.SSE类代码示例

本文整理汇总了Python中amuse.community.sse.interface.SSE的典型用法代码示例。如果您正苦于以下问题:Python SSE类的具体用法?Python SSE怎么用?Python SSE使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了SSE类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test16

    def test16(self):
        print "test evolution of 1000 star sampled over flattish IMF"
        
        number_of_stars=1000
        
        class notsorandom(object):
            def random(self,N):
                return numpy.array(range(N))/(N-1.)
            def random_sample(self,N):
                return numpy.array(range(N))/(N-1.)

        masses = new_salpeter_mass_distribution(
            number_of_stars, 
            mass_min = 0.1 | units.MSun,
            mass_max = 100.0 | units.MSun, 
            alpha = -1.01,random=notsorandom()
        )
 
        stars=Particles(mass=masses)

        instance=SSE()
        instance.particles.add_particles(stars)
        
        i=0
        for p in instance.particles:
          print i,p.mass,
          p.evolve_for(13.2 | units.Gyr)
          print p.mass
          i+=1
        instance.stop()
开发者ID:vdhelm,项目名称:amuse,代码行数:30,代码来源:test_sse.py

示例2: test18

 def test18(self):
     print "SSE validation"
     sse_src_path = os.path.join(os.path.dirname(sys.modules[SSE.__module__].__file__), 'src')
     if not os.path.exists(os.path.join(sse_src_path, "evolve.in")):
         self.skip("Not in a source release")
     instance = SSE()
     instance.particles.add_particle(Particle(mass = 1.416 | units.MSun))
     instance.particles[0].evolve_for(7000.0 | units.Myr)
     evolved_star = instance.particles.copy()[0]
     evolved_star.temperature = instance.particles[0].temperature
     instance.stop()
    
     testpath = get_path_to_results()
     shutil.copy(os.path.join(sse_src_path, "evolve.in"), os.path.join(testpath, "evolve.in"))
     
     call([os.path.join(sse_src_path, "sse")], cwd=testpath)
     
     with open(os.path.join(testpath, "evolve.dat"), "r") as sse_output:
         lines = sse_output.readlines()
         sse_final_result = lines[-2].split()
     
     self.assertAlmostEqual(evolved_star.age, float(sse_final_result[0]) | units.Myr, 3)
     self.assertAlmostEqual(evolved_star.stellar_type, float(sse_final_result[1]) | units.stellar_type, 3)
     self.assertAlmostEqual(evolved_star.initial_mass, float(sse_final_result[2]) | units.MSun, 3)
     self.assertAlmostEqual(evolved_star.mass, float(sse_final_result[3]) | units.MSun, 3)
     self.assertAlmostEqual(evolved_star.luminosity, 10**float(sse_final_result[4]) | units.LSun, 3)
     self.assertAlmostEqual(evolved_star.radius, 10**float(sse_final_result[5]) | units.RSun, 3)
     self.assertAlmostRelativeEqual(evolved_star.temperature, 10**float(sse_final_result[6]) | units.K, 2)
     self.assertAlmostEqual(evolved_star.core_mass, float(sse_final_result[7]) | units.MSun, 3)
     self.assertAlmostEqual(evolved_star.convective_envelope_mass, float(sse_final_result[8]) | units.MSun, 3)
     self.assertAlmostEqual(evolved_star.epoch, float(sse_final_result[9]) | units.Myr, 3)
     self.assertAlmostEqual(evolved_star.spin, float(sse_final_result[10]) | units.yr**-1, 3)
开发者ID:vdhelm,项目名称:amuse,代码行数:32,代码来源:test_sse.py

示例3: test17

 def test17(self):
     print "evolve_one_step and evolve_for after particle removal and addition"
     particles = Particles(10)
     particles.mass = range(1, 11) | units.MSun
     instance = SSE()
     instance.particles.add_particles(particles)
     self.assertAlmostEqual(instance.particles.age, 0.0 | units.yr)
     time_steps = numpy.linspace(0.1, 1.0, num=10) | units.Myr
     for i in range(10):
         instance.particles[i].evolve_for(time_steps[i])
     self.assertAlmostEqual(instance.particles.age, time_steps)
     
     instance.particles.remove_particles(particles[[1, 4, 8]])
     revived = instance.particles.add_particle(particles[4])
     revived.evolve_for(numpy.pi | units.Myr)
     for star in instance.particles:
         star.evolve_for(star.age)
     self.assertAlmostEqual(instance.particles.age[:-1], 2*time_steps[[0, 2,3, 5,6,7, 9]])
     self.assertAlmostEqual(instance.particles.age[-1], 2*numpy.pi | units.Myr)
     
     instance.particles.remove_particles(particles[[2, 5, 6]])
     instance.particles.add_particles(particles[[8, 1]])
     self.assertEqual(len(instance.particles), 7)
     expected_ages = instance.particles.age + instance.particles.time_step
     for star in instance.particles:
         star.evolve_one_step()
     self.assertAlmostEqual(instance.particles.age, expected_ages)
     instance.stop()
开发者ID:vdhelm,项目名称:amuse,代码行数:28,代码来源:test_sse.py

示例4: simulate_evolution_tracks

def simulate_evolution_tracks():
    stellar_evolution = SSE()

    star = datamodel.Particle()
    star.mass = stellar_mass

    star = stellar_evolution.particles.add_particle(star)

    luminosity_at_time = [] | units.LSun
    temperature_at_time = [] | units.K

    print("Evolving a star with mass:", stellar_mass)
    is_evolving = True
    while is_evolving and star.age < end_time:
        luminosity_at_time.append(star.luminosity)
        temperature_at_time.append(star.temperature)
        previous_age = star.age
        # if we do not specify an end_time in the evolve_model function
        # a stellar evolution code will evolve to the next
        # 'natural' timestep, this will ensure all interesting physics
        # is seen in the hr diagram
        stellar_evolution.evolve_model()
        is_evolving = (star.age != previous_age)

    stellar_evolution.stop()

    return temperature_at_time, luminosity_at_time
开发者ID:amusecode,项目名称:amuse,代码行数:27,代码来源:hrdiagram.py

示例5: plottillagb

def plottillagb():
    sun = datamodel.Particle(
        mass=1 | units.MSun,
        radius=1 | units.RSun
    )

    sse = SSE()
    sse.particles.add_particle(sun)

    channel_from_se_to_memory = sse.particles.new_channel_to(sun.as_set())
    channel_from_se_to_memory.copy()

    masses = [] | units.MSun

    timerange = numpy.arange(11500, 13500, 10) | units.Myr
    for time in timerange:
        sse.evolve_model(time)
        channel_from_se_to_memory.copy()
        masses.append(sun.mass)
        print(time.as_quantity_in(units.Myr),
              sun.mass.as_quantity_in(units.MSun))

    sse.stop()

    figure = pyplot.figure(figsize=(6, 6))

    subplot = figure.add_subplot(1, 1, 1)
    subplot.plot(timerange.value_in(units.Gyr),
                 masses.value_in(units.MSun), '.')
    subplot.set_xlabel('t (Gyr)')
    subplot.set_ylabel('mass (MSun)')

    pyplot.show()
开发者ID:amusecode,项目名称:amuse,代码行数:33,代码来源:agb.py

示例6: test23

 def test23(self):
     instance = SSE()
     p=Particles(mass = [1.0, 10.0] | units.MSun, temperature=[10,10] | units.K)
     stars = instance.particles.add_particles(p)
     channel=stars.new_channel_to(p)
     channel.copy_attributes(["mass","temperature"])
     self.assertEqual(stars.temperature, p.temperature)
     instance.stop()
开发者ID:Ingwar,项目名称:amuse,代码行数:8,代码来源:test_sse.py

示例7: test6

    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()
开发者ID:vdhelm,项目名称:amuse,代码行数:33,代码来源:test_sse.py

示例8: test21

 def test21(self):
     instance = SSE()
     stars = instance.particles.add_particles(Particles(mass = 30 | units.MSun))
     mass_loss_wind = stars[0].mass_loss_wind
     self.assertAlmostRelativeEquals(mass_loss_wind, 1.703e-07 | units.MSun / units.yr, 3)
     instance.evolve_model(1 | units.Myr)
     dm = (1 | units.Myr)* mass_loss_wind
     self.assertAlmostRelativeEquals(stars[0].mass, (30 | units.MSun) - dm  ,  3)
     self.assertAlmostRelativeEquals(stars[0].mass_loss_wind, 2.053e-07 | units.MSun / units.yr, 3)
 
     instance.stop()
开发者ID:vdhelm,项目名称:amuse,代码行数:11,代码来源:test_sse.py

示例9: test9

 def test9(self):
     print "Test: large number of particles"
     stellar_evolution = SSE(max_message_length=500)
     stellar_evolution.commit_parameters()
     number_of_particles = 10000
     print "Has been tested with up to a million particles!"
     print "Now using ", number_of_particles, "particles only, for speed."
     stars = Particles(number_of_particles)
     stars.mass = 1.0 | units.MSun
     stellar_evolution.particles.add_particles(stars)
     self.assertEqual(len(stellar_evolution.particles), number_of_particles)
     stellar_evolution.stop()
开发者ID:vdhelm,项目名称:amuse,代码行数:12,代码来源:test_sse.py

示例10: stellar_lifetime

def stellar_lifetime(mZAMS, z=0.02):
    global se
    if se is None:
        se = SSE()
        se.parameters.metallicity = z
    se.particles.add_particle(Particle(mass=mZAMS))
    while not stellar_remnant_state(se.particles[0]):
        se.evolve_model()
    t_end = se.particles[0].age
    # tpe = se.particles[0].stellar_type
    se.particles.remove_particle(se.particles[0])
    return t_end
开发者ID:amusecode,项目名称:amuse,代码行数:12,代码来源:stellar_lifetime_vs_mass.py

示例11: test20

 def test20(self):
     print "SSE core_mass and CO_core_mass (low mass stars)"
     instance = SSE()
     stars = instance.particles.add_particles(Particles(mass = [0.6, 1.0] | units.MSun))
     instance.evolve_model(100 | units.Gyr)
     self.assertEqual(str(stars[0].stellar_type), "Helium White Dwarf")
     self.assertAlmostEqual(stars[0].mass, 0.405 | units.MSun, 2)
     self.assertEqual(stars[0].core_mass, stars[0].mass)
     self.assertEqual(stars[0].CO_core_mass, 0 | units.MSun)
     self.assertEqual(str(stars[1].stellar_type), "Carbon/Oxygen White Dwarf")
     self.assertAlmostEqual(stars[1].mass, 0.520 | units.MSun, 2)
     self.assertEqual(stars[1].core_mass, stars[1].mass)
     self.assertEqual(stars[1].CO_core_mass, stars[1].mass)
     instance.stop()
开发者ID:vdhelm,项目名称:amuse,代码行数:14,代码来源:test_sse.py

示例12: test10

 def test10(self):
     stellar_evolution = SSE()
     stellar_evolution.commit_parameters()
     stars = Particles(10)
     stars.mass = 1.0 | units.MSun
     stellar_evolution.particles.add_particles(stars)
     self.assertEquals(stellar_evolution.particles._factory_for_new_collection(), Particles)
     
     filename = os.path.join(get_path_to_results(), "test.h5")
     if os.path.exists(filename):
         os.remove(filename)
         
     io.write_set_to_file(stellar_evolution.particles, filename, 'hdf5')
     stored_stars = io.read_set_from_file(filename, 'hdf5')
     self.assertEquals(len(stars), len(stored_stars))
 
     self.assertAlmostRelativeEquals(stars.mass, stored_stars.mass)
开发者ID:vdhelm,项目名称:amuse,代码行数:17,代码来源:test_sse.py

示例13: test5

 def test5(self):
     sse = SSE()
     sse.commit_parameters() 
     stars = Particles(1)
     
     star = stars[0]
     star.mass = 35 | units.MSun
     star.radius = 0.0 | units.RSun
     
     stars.synchronize_to(sse.particles)
     
     channel = sse.particles.new_channel_to(stars)
     channel.copy_attributes(sse.particles.get_attribute_names_defined_in_store())   
     
     previous_type = star.stellar_type
     results = []
     
     dt = 1 | units.Myr
     t = 0 | units.Myr
     while t < 30 | units.Myr:
         t += dt
         sse.evolve_model(t)
             
     self.assertTrue(sse.particles[0].mass.value_in(units.MSun) < 10.6)
      
     sse.stop()
开发者ID:vdhelm,项目名称:amuse,代码行数:26,代码来源:test_sse.py

示例14: test8

 def test8(self):
     instance = SSE()
     self.assertEqual(instance.parameters.reimers_mass_loss_coefficient, 0.5)
     myvalue = 0.7
     instance.parameters.reimers_mass_loss_coefficient = myvalue
     self.assertEqual(instance.parameters.reimers_mass_loss_coefficient, myvalue)
     instance.commit_parameters()
     self.assertEqual(instance.parameters.reimers_mass_loss_coefficient, myvalue)
     instance.stop()
     
     instance = SSE()
     self.assertEqual(instance.parameters.reimers_mass_loss_coefficient, 0.5)
     myvalue = 0.7
     instance.parameters.reimers_mass_loss_coefficient = myvalue
     instance.parameters.set_defaults()
     instance.commit_parameters()
     self.assertEqual(instance.parameters.reimers_mass_loss_coefficient, 0.5)
     instance.stop()
开发者ID:vdhelm,项目名称:amuse,代码行数:18,代码来源:test_sse.py

示例15: test14b

 def test14b(self):
     print "Testing basic operations: evolve_one_step and evolve_for (on subset)"
     stars = Particles(2)
     stars.mass = 1.0 | units.MSun
     instance = SSE()
     se_stars = instance.particles.add_particles(stars)
     self.assertAlmostEqual(se_stars.age, [0.0, 0.0] | units.yr)
     
     for i in range(3):
         se_stars[:1].evolve_one_step()
     self.assertAlmostEqual(se_stars.age, [1650.46953688, 0.0] | units.Myr, 3)
     number_of_steps = 10
     step_size = se_stars[0].age / number_of_steps
     for i in range(1, number_of_steps + 1):
         se_stars[1:].evolve_for(step_size)
         self.assertAlmostEqual(se_stars.age, [number_of_steps, i] * step_size)
     print se_stars
     self.assertAlmostRelativeEqual(se_stars[0].age,         se_stars[1].age)
     self.assertAlmostRelativeEqual(se_stars[0].luminosity,  se_stars[1].luminosity, 3)
     self.assertAlmostRelativeEqual(se_stars[0].radius,      se_stars[1].radius, 3)
     self.assertAlmostRelativeEqual(se_stars[0].temperature, se_stars[1].temperature, 3)
     instance.stop()
开发者ID:vdhelm,项目名称:amuse,代码行数:22,代码来源:test_sse.py


注:本文中的amuse.community.sse.interface.SSE类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。