本文整理汇总了Python中amuse.community.evtwin.interface.EVtwin.get_number_of_particles方法的典型用法代码示例。如果您正苦于以下问题:Python EVtwin.get_number_of_particles方法的具体用法?Python EVtwin.get_number_of_particles怎么用?Python EVtwin.get_number_of_particles使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类amuse.community.evtwin.interface.EVtwin
的用法示例。
在下文中一共展示了EVtwin.get_number_of_particles方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test5
# 需要导入模块: from amuse.community.evtwin.interface import EVtwin [as 别名]
# 或者: from amuse.community.evtwin.interface.EVtwin import get_number_of_particles [as 别名]
def test5(self):
print "Testing adding and removing particles from stellar evolution code..."
particles = Particles(3)
particles.mass = 0.3 | units.MSun
instance = EVtwin()#redirection="none")
instance.initialize_code()
instance.parameters.verbosity = True
instance.commit_parameters()
stars = instance.particles
self.assertEquals(len(stars), 0) # before creation
stars.add_particles(particles[:-1])
instance.commit_particles()
instance.evolve_model(1.0 | units.Myr)
self.assertEquals(len(stars), 2) # before remove
self.assertAlmostEqual(stars.age, 1.0 | units.Myr)
stars.remove_particle(particles[0])
self.assertEquals(len(stars), 1)
self.assertEquals(instance.get_number_of_particles(), 1)
instance.evolve_model(2.0 | units.Myr)
self.assertAlmostEqual(stars[0].age, 2.0 | units.Myr)
stars.add_particles(particles[::2])
self.assertEquals(len(stars), 3) # it's back...
self.assertAlmostEqual(stars[0].age, 2.0 | units.Myr)
self.assertAlmostEqual(stars[1].age, 0.0 | units.Myr)
self.assertAlmostEqual(stars[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(stars.age, [3.0, 1.0, 1.0] | units.Myr)
instance.evolve_model(4.0 | units.Myr)
self.assertAlmostEqual(stars.age, [4.0, 2.0, 2.0] | units.Myr)
instance.stop()