本文整理汇总了Python中amuse.community.hermite0.interface.Hermite.initialize_code方法的典型用法代码示例。如果您正苦于以下问题:Python Hermite.initialize_code方法的具体用法?Python Hermite.initialize_code怎么用?Python Hermite.initialize_code使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类amuse.community.hermite0.interface.Hermite
的用法示例。
在下文中一共展示了Hermite.initialize_code方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test13
# 需要导入模块: from amuse.community.hermite0.interface import Hermite [as 别名]
# 或者: from amuse.community.hermite0.interface.Hermite import initialize_code [as 别名]
def test13(self):
particles = plummer.new_plummer_model(31)
instance = Hermite(number_of_workers=1)#, debugger="xterm")
instance.initialize_code()
instance.parameters.epsilon_squared = 0.01 | nbody_system.length ** 2
instance.particles.add_particles(particles)
instance.evolve_model(0.1 | nbody_system.time)
instance.synchronize_model()
expected_positions = instance.particles.position
instance.stop()
positions_per_workers = []
for n in [2,3,4,5]:
instance = Hermite(number_of_workers=n)
instance.initialize_code()
instance.parameters.epsilon_squared = 0.01 | nbody_system.length ** 2
instance.particles.add_particles(particles)
instance.evolve_model(0.1 | nbody_system.time)
instance.synchronize_model()
positions_per_workers.append(instance.particles.position)
instance.stop()
for index, n in enumerate([2,3,4,5]):
self.assertAlmostEqual(expected_positions, positions_per_workers[index], 15)
示例2: test5
# 需要导入模块: from amuse.community.hermite0.interface import Hermite [as 别名]
# 或者: from amuse.community.hermite0.interface.Hermite import initialize_code [as 别名]
def test5(self):
convert_nbody = nbody_system.nbody_to_si(5.0 | units.kg, 10.0 | units.m)
instance = Hermite(convert_nbody)
instance.initialize_code()
particles = datamodel.Particles(2)
self.assertEquals(len(instance.particles), 0)
particles.mass = [15.0, 30.0] | units.kg
particles.radius = [10.0, 20.0] | units.m
particles.position = [[10.0, 20.0, 30.0], [20.0, 40.0, 60.0]] | units.m
particles.velocity = [[0.0, 0.0, 0.0], [0.0, 0.0, 0.0]] | units.m / units.s
instance.particles.add_particles(particles)
self.assertEquals(len(instance.particles), 2)
instance.set_state(1, 16|units.kg,
20.0|units.m, 40.0|units.m, 60.0|units.m,
1.0|units.ms, 1.0|units.ms, 1.0|units.ms ,
20.0|units.m)
curr_state = instance.get_state(1)
for expected, actual in zip([16|units.kg,
20.0|units.m, 40.0|units.m, 60.0|units.m,
1.0|units.ms, 1.0|units.ms, 1.0|units.ms ,
20.0|units.m], curr_state):
self.assertAlmostRelativeEquals(expected, actual)
instance.stop()
self.assertEquals(curr_state[0], 16|units.kg, 8)
示例3: test3
# 需要导入模块: from amuse.community.hermite0.interface import Hermite [as 别名]
# 或者: from amuse.community.hermite0.interface.Hermite import initialize_code [as 别名]
def test3(self):
convert_nbody = nbody_system.nbody_to_si(1.0 | units.MSun, 149.5e6 | units.km)
instance = Hermite(convert_nbody)
instance.initialize_code()
instance.parameters.epsilon_squared = 0.00001 | units.AU**2
instance.dt_dia = 5000
stars = datamodel.Stars(2)
star1 = stars[0]
star2 = stars[1]
star1.mass = units.MSun(1.0)
star1.position = units.AU(numpy.array((-1.0,0.0,0.0)))
star1.velocity = units.AUd(numpy.array((0.0,0.0,0.0)))
star1.radius = units.RSun(1.0)
star2.mass = units.MSun(1.0)
star2.position = units.AU(numpy.array((1.0,0.0,0.0)))
star2.velocity = units.AUd(numpy.array((0.0,0.0,0.0)))
star2.radius = units.RSun(100.0)
instance.particles.add_particles(stars)
for x in range(1,2000,10):
instance.evolve_model(x | units.day)
instance.particles.copy_values_of_all_attributes_to(stars)
stars.savepoint()
instance.stop()
示例4: evolve_model
# 需要导入模块: from amuse.community.hermite0.interface import Hermite [as 别名]
# 或者: from amuse.community.hermite0.interface.Hermite import initialize_code [as 别名]
def evolve_model(self):
convert_nbody = nbody_system.nbody_to_si(
1.0 | units.MSun, 149.5e6 | units.km)
hermite = Hermite(convert_nbody)
hermite.initialize_code()
hermite.parameters.epsilon_squared = 0.0 | units.AU**2
stars = self.new_system_of_sun_and_earth()
earth = stars[1]
sun = stars[0]
Earth = blender.Primitives.sphere(10, 10, 0.1) # Make the earth avatar
Sun = blender.Primitives.sphere(32, 32, 1) # Make the sun avatar
hermite.particles.add_particles(stars)
for i in range(1*365):
hermite.evolve_model(i | units.day)
hermite.particles.copy_values_of_all_attributes_to(stars)
# update avatar positions:
Earth.loc = (
1*earth.position.value_in(units.AU)[0],
1*earth.position.value_in(units.AU)[1],
earth.position.value_in(units.AU)[2])
Sun.loc = (
1*sun.position.value_in(units.AU)[0],
1*sun.position.value_in(units.AU)[1],
sun.position.value_in(units.AU)[2])
blender.Redraw()
hermite.print_refs()
hermite.stop()
示例5: test8
# 需要导入模块: from amuse.community.hermite0.interface import Hermite [as 别名]
# 或者: from amuse.community.hermite0.interface.Hermite import initialize_code [as 别名]
def test8(self):
print "Testing Hermite collision_detection"
particles = datamodel.Particles(7)
particles.mass = 0.001 | nbody_system.mass
particles.radius = 0.01 | nbody_system.length
particles.x = [-101.0, -100.0, -0.5, 0.5, 100.0, 101.0, 104.0] | nbody_system.length
particles.y = 0 | nbody_system.length
particles.z = 0 | nbody_system.length
particles.velocity = [[2, 0, 0], [-2, 0, 0]]*3 + [[-4, 0, 0]] | nbody_system.speed
instance = Hermite()
instance.initialize_code()
instance.parameters.set_defaults()
instance.particles.add_particles(particles)
collisions = instance.stopping_conditions.collision_detection
collisions.enable()
instance.evolve_model(1.0 | nbody_system.time)
self.assertTrue(collisions.is_set())
self.assertTrue(instance.model_time < 0.5 | nbody_system.time)
self.assertEquals(len(collisions.particles(0)), 3)
self.assertEquals(len(collisions.particles(1)), 3)
self.assertEquals(len(particles - collisions.particles(0) - collisions.particles(1)), 1)
self.assertEquals(abs(collisions.particles(0).x - collisions.particles(1).x) <=
(collisions.particles(0).radius + collisions.particles(1).radius),
[True, True, True])
sticky_merged = datamodel.Particles(len(collisions.particles(0)))
sticky_merged.mass = collisions.particles(0).mass + collisions.particles(1).mass
sticky_merged.radius = collisions.particles(0).radius
for p1, p2, merged in zip(collisions.particles(0), collisions.particles(1), sticky_merged):
merged.position = (p1 + p2).center_of_mass()
merged.velocity = (p1 + p2).center_of_mass_velocity()
print instance.model_time
print instance.particles
instance.particles.remove_particles(collisions.particles(0) + collisions.particles(1))
instance.particles.add_particles(sticky_merged)
instance.evolve_model(1.0 | nbody_system.time)
print
print instance.model_time
print instance.particles
self.assertTrue(collisions.is_set())
self.assertTrue(instance.model_time < 1.0 | nbody_system.time)
self.assertEquals(len(collisions.particles(0)), 1)
self.assertEquals(len(collisions.particles(1)), 1)
self.assertEquals(len(instance.particles - collisions.particles(0) - collisions.particles(1)), 2)
self.assertEquals(abs(collisions.particles(0).x - collisions.particles(1).x) <=
(collisions.particles(0).radius + collisions.particles(1).radius),
[True])
instance.stop()
示例6: test2
# 需要导入模块: from amuse.community.hermite0.interface import Hermite [as 别名]
# 或者: from amuse.community.hermite0.interface.Hermite import initialize_code [as 别名]
def test2(self):
convert_nbody = nbody_system.nbody_to_si(1.0 | units.MSun, 149.5e6 | units.km)
instance = Hermite(convert_nbody)
instance.initialize_code()
instance.parameters.epsilon_squared = 0.0 | units.AU**2
instance.dt_dia = 5000
stars = self.new_system_of_sun_and_earth()
earth = stars[1]
instance.particles.add_particles(stars)
for x in range(1, 500, 10):
instance.evolve_model(x | units.day)
instance.particles.copy_values_of_all_attributes_to(stars)
stars.savepoint()
if HAS_MATPLOTLIB:
figure = pyplot.figure()
plot = figure.add_subplot(1,1,1)
x_points = earth.get_timeline_of_attribute("x")
y_points = earth.get_timeline_of_attribute("y")
x_points_in_AU = map(lambda (t,x) : x.value_in(units.AU), x_points)
y_points_in_AU = map(lambda (t,x) : x.value_in(units.AU), y_points)
plot.scatter(x_points_in_AU,y_points_in_AU, color = "b", marker = 'o')
plot.set_xlim(-1.5, 1.5)
plot.set_ylim(-1.5, 1.5)
test_results_path = self.get_path_to_results()
output_file = os.path.join(test_results_path, "hermite-earth-sun2.svg")
figure.savefig(output_file)
instance.cleanup_code()
instance.stop()
示例7: test12
# 需要导入模块: from amuse.community.hermite0.interface import Hermite [as 别名]
# 或者: from amuse.community.hermite0.interface.Hermite import initialize_code [as 别名]
def test12(self):
particles = datamodel.Particles(2)
particles.x = [0.0,1.00] | nbody_system.length
particles.y = [0.0,0.0] | nbody_system.length
particles.z = [0.0,0.0] | nbody_system.length
particles.radius = 0.005 | nbody_system.length
particles.vx = [5.1,0.0] | nbody_system.speed
particles.vy = [0.0,0.0] | nbody_system.speed
particles.vz = [0.0,0.0]| nbody_system.speed
particles.mass = [0.1,0.1] | nbody_system.mass
instance = Hermite()
instance.initialize_code()
instance.parameters.stopping_conditions_out_of_box_size = .5 | nbody_system.length
self.assertEquals(instance.parameters.stopping_conditions_out_of_box_size, .5 | nbody_system.length)
instance.particles.add_particles(particles)
instance.stopping_conditions.out_of_box_detection.enable()
instance.evolve_model(0.1 | nbody_system.time)
self.assertTrue(instance.stopping_conditions.out_of_box_detection.is_set())
self.assertAlmostEqual(instance.stopping_conditions.out_of_box_detection.particles(0).x, 1.0 |nbody_system.length, 3)
instance.stop()
示例8: test10
# 需要导入模块: from amuse.community.hermite0.interface import Hermite [as 别名]
# 或者: from amuse.community.hermite0.interface.Hermite import initialize_code [as 别名]
def test10(self):
convert_nbody = nbody_system.nbody_to_si(1.0 | units.MSun, 149.5e6 | units.km)
instance = Hermite(convert_nbody)
instance.initialize_code()
instance.parameters.epsilon_squared = 0.0 | units.AU**2
instance.parameters.stopping_conditions_number_of_steps = 10
self.assertEquals(instance.parameters.stopping_conditions_number_of_steps,10)
stars = self.new_system_of_sun_and_earth()
earth = stars[1]
instance.particles.add_particles(stars)
instance.stopping_conditions.number_of_steps_detection.enable()
instance.evolve_model(365.0 | units.day)
self.assertTrue(instance.stopping_conditions.number_of_steps_detection.is_set())
instance.particles.copy_values_of_all_attributes_to(stars)
instance.cleanup_code()
instance.stop()
示例9: test16
# 需要导入模块: from amuse.community.hermite0.interface import Hermite [as 别名]
# 或者: from amuse.community.hermite0.interface.Hermite import initialize_code [as 别名]
def test16(self):
particles = new_plummer_model(200)
particles.scale_to_standard()
instance = Hermite()
instance.initialize_code()
instance.parameters.epsilon_squared = 0.00000 | nbody_system.length**2
instance.particles.add_particles(particles)
x = numpy.arange(-1,1,0.1) | nbody_system.length
zero = numpy.zeros(len(x)) | nbody_system.length
potential0 = instance.get_potential_at_point(zero, x , zero, zero)
instance.stop()
for n in (2, 3, 4):
instance = Hermite(number_of_workers = n)
instance.initialize_code()
instance.parameters.epsilon_squared = 0.00000 | nbody_system.length**2
instance.particles.add_particles(particles)
potential = instance.get_potential_at_point(zero, x , zero, zero)
self.assertAlmostRelativeEquals(potential0, potential, 8)
instance.stop()
示例10: test11
# 需要导入模块: from amuse.community.hermite0.interface import Hermite [as 别名]
# 或者: from amuse.community.hermite0.interface.Hermite import initialize_code [as 别名]
def test11(self):
particles = datamodel.Particles(2)
particles.x = [0.0,10.0] | nbody_system.length
particles.y = 0 | nbody_system.length
particles.z = 0 | nbody_system.length
particles.radius = 0.005 | nbody_system.length
particles.vx = 0 | nbody_system.speed
particles.vy = 0 | nbody_system.speed
particles.vz = 0 | nbody_system.speed
particles.mass = 1.0 | nbody_system.mass
instance = Hermite()
instance.initialize_code()
instance.parameters.stopping_conditions_number_of_steps = 2
self.assertEquals(instance.parameters.stopping_conditions_number_of_steps, 2)
instance.particles.add_particles(particles)
instance.stopping_conditions.number_of_steps_detection.enable()
instance.evolve_model(10 | nbody_system.time)
self.assertTrue(instance.stopping_conditions.number_of_steps_detection.is_set())
self.assertTrue(instance.model_time < 10 | nbody_system.time)
instance.stop()
示例11: test20
# 需要导入模块: from amuse.community.hermite0.interface import Hermite [as 别名]
# 或者: from amuse.community.hermite0.interface.Hermite import initialize_code [as 别名]
def test20(self):
convert_nbody = nbody_system.nbody_to_si(1.0 | units.MSun, 149.5e6 | units.km)
hermite = Hermite(convert_nbody)
hermite.initialize_code()
hermite.parameters.epsilon_squared = 0.0 | units.AU**2
hermite.parameters.end_time_accuracy_factor = 0.0
hermite.parameters.is_time_reversed_allowed = True
stars = self.new_system_of_sun_and_earth()
earth = stars[1]
hermite.particles.add_particles(stars)
hermite.evolve_model(365.0 | units.day)
hermite.particles.copy_values_of_all_attributes_to(stars)
position_at_start = earth.position.value_in(units.AU)[0]
position_after_full_rotation = earth.position.value_in(units.AU)[0]
self.assertAlmostRelativeEqual(position_at_start, position_after_full_rotation, 6)
hermite.evolve_model(365.0 - (365.0 / 2) | units.day)
hermite.particles.copy_values_of_all_attributes_to(stars)
position_after_half_a_rotation_backward = earth.position.value_in(units.AU)[0]
self.assertAlmostRelativeEqual(-position_at_start, position_after_half_a_rotation_backward, 4)
hermite.evolve_model(365.0 | units.day)
position_at_start = earth.position.value_in(units.AU)[0]
position_after_full_rotation = earth.position.value_in(units.AU)[0]
self.assertAlmostRelativeEqual(position_at_start, position_after_full_rotation, 6)
hermite.cleanup_code()
hermite.stop()
示例12: test14
# 需要导入模块: from amuse.community.hermite0.interface import Hermite [as 别名]
# 或者: from amuse.community.hermite0.interface.Hermite import initialize_code [as 别名]
def test14(self):
instance = Hermite()
instance.initialize_code()
instance.parameters.epsilon_squared = 0.00001 | nbody_system.length**2
particles = datamodel.Particles(2)
particles.mass = [1.0, 1.0] | nbody_system.mass
particles.radius = [0.0001, 0.0001] | nbody_system.length
particles.position = [[0.0,0.0,0.0], [2.0,0.0,0.0]] | nbody_system.length
particles.velocity = [[0.0, 0.0, 0.0], [0.0, 0.0, 0.0]] | nbody_system.speed
instance.particles.add_particles(particles)
zero = 0.0 | nbody_system.length
fx, fy, fz = instance.get_gravity_at_point(zero, 1.0 | nbody_system.length, zero, zero)
self.assertAlmostEqual(fx, 0.0 | nbody_system.acceleration, 6)
self.assertAlmostEqual(fy, 0.0 | nbody_system.acceleration, 6)
self.assertAlmostEqual(fz, 0.0 | nbody_system.acceleration, 6)
for x in (0.25, 0.5, 0.75):
x0 = x | nbody_system.length
x1 = (2.0 - x) | nbody_system.length
potential0 = instance.get_potential_at_point(zero, x0, zero, zero)
potential1 = instance.get_potential_at_point(zero, x1, zero, zero)
fx0, fy0, fz0 = instance.get_gravity_at_point(zero, x0, zero, zero)
fx1, fy1, fz1 = instance.get_gravity_at_point(zero, x1, zero, zero)
self.assertAlmostEqual(fy0, 0.0 | nbody_system.acceleration, 6)
self.assertAlmostEqual(fz0, 0.0 | nbody_system.acceleration, 6)
self.assertAlmostEqual(fy1, 0.0 | nbody_system.acceleration, 6)
self.assertAlmostEqual(fz1, 0.0 | nbody_system.acceleration, 6)
self.assertAlmostEqual(fx0, -1.0 * fx1, 5)
fx = (-1.0 / (x0**2) + 1.0 / (x1**2)) * (1.0 | nbody_system.length ** 3 / nbody_system.time ** 2)
self.assertAlmostEqual(fx, fx0, 2)
self.assertAlmostEqual(potential0, potential1, 5)
instance.stop()
示例13: test4
# 需要导入模块: from amuse.community.hermite0.interface import Hermite [as 别名]
# 或者: from amuse.community.hermite0.interface.Hermite import initialize_code [as 别名]
def test4(self):
convert_nbody = nbody_system.nbody_to_si(5.0 | units.kg, 10.0 | units.m)
instance = Hermite(convert_nbody)
instance.initialize_code()
particles = datamodel.Particles(2)
self.assertEquals(len(instance.particles), 0)
particles.mass = [15.0, 30.0] | units.kg
particles.radius = [10.0, 20.0] | units.m
particles.position = [[10.0, 20.0, 30.0], [20.0, 40.0, 60.0]] | units.m
particles.velocity = [[0.0, 0.0, 0.0], [0.0, 0.0, 0.0]] | units.m / units.s
instance.particles.add_particles(particles)
self.assertEquals(len(instance.particles), 2)
instance.particles.mass = [17.0, 33.0] | units.kg
self.assertEquals(instance.get_mass(0), 17.0| units.kg)
self.assertEquals(instance.get_mass(1), 33.0| units.kg)
instance.stop()