本文整理汇总了Python中amuse.community.hermite0.interface.Hermite类的典型用法代码示例。如果您正苦于以下问题:Python Hermite类的具体用法?Python Hermite怎么用?Python Hermite使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Hermite类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test15
def test15(self):
particles = datamodel.Particles(2)
particles.x = [0.0,10.0] | nbody_system.length
particles.y = 0.0 | nbody_system.length
particles.z = 0.0 | nbody_system.length
particles.vx = 0.0 | nbody_system.speed
particles.vy = 0.0 | nbody_system.speed
particles.vz = 0.0 | nbody_system.speed
particles.mass = 1.0 | nbody_system.mass
instance = Hermite()
instance.particles.add_particles(particles)
instance.commit_particles()
self.assertEquals(instance.particles[0].radius, 0.0 | nbody_system.length)
p = datamodel.Particle(
x = 1.0 | nbody_system.length,
y = 2.0 | nbody_system.length,
z = 3.0 | nbody_system.length,
vx = 1.0 | nbody_system.speed,
vy = 2.0 | nbody_system.speed,
vz = 3.0 | nbody_system.speed,
mass = 1.0 | nbody_system.mass,
radius = 4.0 | nbody_system.length,
)
instance.particles.add_particle(p)
self.assertEquals(instance.particles[0].radius, 0.0 | nbody_system.length)
self.assertEquals(instance.particles[1].radius, 0.0 | nbody_system.length)
self.assertEquals(instance.particles[2].radius, 4.0 | nbody_system.length)
instance.stop()
示例2: simulate_system_until
def simulate_system_until(particles, end_time):
convert_nbody = nbody_system.nbody_to_si(
1.0 | units.MSun, 149.5e6 | units.km)
instance = Hermite(convert_nbody)
instance.parameters.epsilon_squared = 0.0 | units.AU**2
instance.particles.add_particles(particles)
t0 = 0 | units.day
dt = 10 | units.day
t = t0
earth = instance.particles[1]
x_values = quantities.AdaptingVectorQuantity()
y_values = quantities.AdaptingVectorQuantity()
while t < end_time:
instance.evolve_model(t)
x_values.append(earth.x)
y_values.append(earth.y)
t += dt
instance.stop()
return x_values, y_values
示例3: evolve_model
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()
示例4: test17
def test17(self):
particles = new_plummer_model(50)
particles.scale_to_standard()
instance = Hermite()
instance.parameters.epsilon_squared = 0.22000 | nbody_system.length**2
instance.particles.add_particles(particles)
self.assertEquals(len(instance.particles), 50)
instance.reset()
self.assertAlmostRelativeEquals(instance.parameters.epsilon_squared , 0.22000 | nbody_system.length**2)
self.assertEquals(len(instance.particles), 0)
instance.particles.add_particles(particles)
self.assertEquals(len(instance.particles), 50)
示例5: test5
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)
示例6: test3
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()
示例7: test8
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()
示例8: test6
def test6(self):
print "Test6: Testing Hermite parameters"
convert_nbody = nbody_system.nbody_to_si(1.0 | units.yr, 1.0 | units.AU)
instance = Hermite(convert_nbody)
value = instance.get_eps2()
self.assertEquals(0.0 | units.AU**2 , value)
self.assertAlmostEquals(0.0 | units.AU**2, instance.parameters.epsilon_squared, in_units=units.AU**2)
for x in [0.01, 0.1, 0.2]:
instance.parameters.epsilon_squared = x | units.AU**2
self.assertAlmostEquals(x | units.AU**2, instance.parameters.epsilon_squared, in_units=units.AU**2)
value = instance.get_dt_param()
self.assertEquals(0.03 , value)
self.assertAlmostEquals(0.03 , instance.parameters.dt_param)
for x in [0.001, 0.01, 0.1]:
instance.parameters.dt_param = x
self.assertAlmostEquals(x, instance.parameters.dt_param)
value = instance.get_dt_dia()
self.assertAlmostEquals(1.0 | units.yr, value)
self.assertAlmostEquals(1.0 | units.yr, instance.parameters.dt_dia, in_units=units.yr)
for x in [0.1, 10.0, 100.0]:
instance.parameters.dt_dia = x | units.yr
self.assertAlmostEquals(x | units.yr, instance.parameters.dt_dia, in_units=units.yr)
value = instance.get_begin_time()
self.assertEquals(0.0| units.yr, value)
self.assertAlmostEquals(0.0 | units.yr, instance.parameters.begin_time, in_units=units.yr)
for x in [1.0, 10.0, 100.0]:
instance.parameters.begin_time = x | units.yr
self.assertAlmostEquals(x | units.yr, instance.parameters.begin_time, in_units=units.yr)
instance.stop()
示例9: test2
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()
示例10: test22
def test22(self):
hermite = Hermite()
hermite.parameters.epsilon_squared = 0.0 | nbody_system.length**2
particles = datamodel.Particles(2)
particles.position = ([0,0,0], [1,0,0] )| nbody_system.length
particles.velocity = ([-2,0,0], [2,0,0] )| nbody_system.speed
particles.radius = 0| nbody_system.length
particles.mass = 0.1| nbody_system.mass
hermite.particles.add_particles(particles)
hermite.stopping_conditions.out_of_box_detection.enable()
hermite.parameters.stopping_conditions_out_of_box_size = 2 | nbody_system.length
hermite.parameters.stopping_conditions_out_of_box_use_center_of_mass = False
hermite.evolve_model(1 | nbody_system.time)
print hermite.particles.x
print hermite.particles.key, particles[1].key
print hermite.stopping_conditions.out_of_box_detection.particles(0)
self.assertTrue(hermite.stopping_conditions.out_of_box_detection.is_set())
self.assertEquals(len(hermite.stopping_conditions.out_of_box_detection.particles(0)), 1)
self.assertEquals(hermite.stopping_conditions.out_of_box_detection.particles(0)[0].key, particles[1].key)
hermite.stop()
示例11: simulate_small_cluster
def simulate_small_cluster(
number_of_stars=1000,
end_time=40 | nbody_system.time,
number_of_workers=1
):
particles = new_plummer_model(number_of_stars)
particles.scale_to_standard()
gravity = Hermite(number_of_workers=number_of_workers)
gravity.parameters.epsilon_squared = 0.15 | nbody_system.length ** 2
gravity.particles.add_particles(particles)
from_gravity_to_model = gravity.particles.new_channel_to(particles)
time = 0.0 * end_time
total_energy_at_t0 = gravity.kinetic_energy + gravity.potential_energy
positions_at_different_times = []
positions_at_different_times.append(particles.position)
times = []
times.append(time)
print("evolving the model until t = " + str(end_time))
while time < end_time:
time += end_time / 3.0
gravity.evolve_model(time)
from_gravity_to_model.copy()
positions_at_different_times.append(particles.position)
times.append(time)
print_log(time, gravity, particles, total_energy_at_t0)
gravity.stop()
return times, positions_at_different_times
示例12: test10
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()
示例13: test19
def test19(self):
particles = datamodel.Particles(2)
particles.x = [0.0,200.0] | nbody_system.length
particles.y = 0.0 | nbody_system.length
particles.z = 0.0 | nbody_system.length
particles.vx = 0.0 | nbody_system.speed
particles.vy = 0.0 | nbody_system.speed
particles.vz = 0.0 | nbody_system.speed
particles.mass = 1.0 | nbody_system.mass
instance = Hermite()
instance.particles.add_particles(particles)
instance.commit_particles()
self.assertEquals(instance.particles[0].radius, 0.0 | nbody_system.length)
instance.parameters.end_time_accuracy_factor = 0.0
instance.evolve_model(0.1 | nbody_system.time)
self.assertAlmostRelativeEquals(instance.model_time, 0.1 |nbody_system.time, 5)
instance.stop()
示例14: test23
def test23(self):
hermite = Hermite()
hermite.parameters.epsilon_squared = 0.0 | nbody_system.length**2
particles = datamodel.Particles(1)
particles.position = ([0,0,0] )| nbody_system.length
particles.velocity = ([1,0,0] )| nbody_system.speed
particles.radius = 0| nbody_system.length
particles.mass = 0.1| nbody_system.mass
hermite.particles.add_particles(particles)
hermite.evolve_model(1 | nbody_system.time)
print hermite.particles.x
self.assertAlmostRelativeEquals(hermite.model_time, 1 | nbody_system.time)
self.assertAlmostRelativeEquals(hermite.particles[0].x, 1 | nbody_system.length)
hermite.evolve_model(1.5 | nbody_system.time)
print hermite.particles.x
self.assertAlmostRelativeEquals(hermite.model_time, 1.5 | nbody_system.time)
self.assertAlmostRelativeEquals(hermite.particles[0].x, 1.5 | nbody_system.length)
hermite.stop()
示例15: test14
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()