def test1(self):
     convert_nbody = nbody_system.nbody_to_si(1.0 | units.MSun, 149.5e6 | units.km)
     instance = PhiGRAPE(convert_nbody, **default_test_options)#, debugger="xterm")
     instance.initialize_code()
     instance.parameters.set_defaults()
     instance.parameters.initial_timestep_parameter = 0.001
     instance.parameters.timestep_parameter = 0.001
     
     stars = self.new_system_of_sun_and_earth()
     earth = stars[1]
     instance.particles.add_particles(stars)
     instance.commit_particles()
 
     position_at_start = earth.position.value_in(units.AU)[0]
     instance.evolve_model(365 | units.day)
     instance.particles.copy_values_of_all_attributes_to(stars)
     position_after_full_rotation = earth.position.value_in(units.AU)[0]
     self.assertAlmostEqual(position_at_start, position_after_full_rotation, 2)
     
     instance.evolve_model(365.0 + (365.0 / 2) | units.day)
     instance.particles.copy_values_of_all_attributes_to(stars)
     position_after_half_a_rotation = earth.position.value_in(units.AU)[0]
     self.assertAlmostEqual(-position_at_start, position_after_half_a_rotation, 2)
     
     instance.evolve_model(365.0 + (365.0 / 2) + (365.0 / 4)  | units.day)
     instance.particles.copy_values_of_all_attributes_to(stars)
     position_after_half_a_rotation = earth.position.value_in(units.AU)[1]
     self.assertAlmostEqual(-position_at_start, position_after_half_a_rotation, 3)
     
     instance.cleanup_code()
     instance.stop()
Exemple #2
0
 def test1(self):
     convert_nbody = nbody_system.nbody_to_si(1.0 | units.MSun, 149.5e6 | units.km)
     instance = PhiGRAPE(convert_nbody, **default_test_options)#, debugger="xterm")
     instance.initialize_code()
     instance.parameters.set_defaults()
     instance.parameters.initial_timestep_parameter = 0.001
     instance.parameters.timestep_parameter = 0.001
     
     stars = self.new_system_of_sun_and_earth()
     earth = stars[1]
     instance.particles.add_particles(stars)
     instance.commit_particles()
 
     position_at_start = earth.position.value_in(units.AU)[0]
     instance.evolve_model(365 | units.day)
     instance.particles.copy_values_of_all_attributes_to(stars)
     position_after_full_rotation = earth.position.value_in(units.AU)[0]
     self.assertAlmostEqual(position_at_start, position_after_full_rotation, 2)
     
     instance.evolve_model(365.0 + (365.0 / 2) | units.day)
     instance.particles.copy_values_of_all_attributes_to(stars)
     position_after_half_a_rotation = earth.position.value_in(units.AU)[0]
     self.assertAlmostEqual(-position_at_start, position_after_half_a_rotation, 2)
     
     instance.evolve_model(365.0 + (365.0 / 2) + (365.0 / 4)  | units.day)
     instance.particles.copy_values_of_all_attributes_to(stars)
     position_after_half_a_rotation = earth.position.value_in(units.AU)[1]
     self.assertAlmostEqual(-position_at_start, position_after_half_a_rotation, 3)
     
     instance.cleanup_code()
     instance.stop()
 def test16(self):
     instance = PhiGRAPE(number_of_workers = 2, **default_test_options)
     instance.initialize_code()
     instance.parameters.set_defaults()
     print 1
     particles = datamodel.Particles(2)
     particles.x = [-1.0,1.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, 0.5] | nbody_system.mass
     
     instance.particles.add_particles(particles)
     instance.commit_particles()
 
     instance.evolve_model(0.01 | nbody_system.time)
 
     instance.particles.copy_values_of_all_attributes_to(particles)
     
     print instance.particles.position.x
     self.assertAlmostRelativeEquals(instance.particles[0].position.x, -0.999984741095 | nbody_system.length, 8)
     self.assertAlmostRelativeEquals(instance.particles[1].position.x,  0.999969482189 | nbody_system.length, 8)
     
     instance.evolve_model(0.10 | nbody_system.time)
 
     instance.particles.copy_values_of_all_attributes_to(particles)
     
     print instance.particles.position.x
     self.assertAlmostRelativeEquals(instance.particles[0].position.x, -0.999022960148 | nbody_system.length, 8)
     self.assertAlmostRelativeEquals(instance.particles[1].position.x, 0.998045920305 | nbody_system.length, 8)
     
     instance.evolve_model(0.50 | nbody_system.time)
 
     instance.particles.copy_values_of_all_attributes_to(particles)
     
     print instance.particles.position.x
     self.assertAlmostRelativeEquals(instance.particles[0].position.x, -0.984250788742 | nbody_system.length, 8)
     self.assertAlmostRelativeEquals(instance.particles[1].position.x, 0.968501583383 | nbody_system.length, 8)
     
     instance.cleanup_code()
     
     instance.stop()
 def test15(self):
     instance = PhiGRAPE(number_of_workers = 2, **default_test_options)#, redirection = "none")
     instance.initialize_code()
     instance.parameters.set_defaults()
     print 1
     particles = datamodel.Particles(2)
     particles.x = [-1.0,1.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.particles.add_particles(particles)
     instance.commit_particles()
 
     instance.evolve_model(0.01 | nbody_system.time)
 
     instance.particles.copy_values_of_all_attributes_to(particles)
     
     print instance.particles.position.x
     self.assertEquals(instance.particles[0].position.x, -instance.particles[1].position.x)
     self.assertAlmostRelativeEquals(instance.particles[1].position.x, 0.999969482111 | nbody_system.length, 6)
     
     instance.evolve_model(0.10 | nbody_system.time)
 
     instance.particles.copy_values_of_all_attributes_to(particles)
     
     print instance.particles.position.x
     self.assertEquals(instance.particles[0].position.x, -instance.particles[1].position.x)
     self.assertAlmostRelativeEquals(instance.particles[1].position.x, 0.99804560161 | nbody_system.length, 6)
     
     instance.evolve_model(0.50 | nbody_system.time)
 
     instance.particles.copy_values_of_all_attributes_to(particles)
     
     print instance.particles.position.x
     self.assertEquals(instance.particles[0].position.x, -instance.particles[1].position.x)
     self.assertAlmostRelativeEquals(instance.particles[1].position.x, 0.968416814302 | nbody_system.length, 6)
     
     instance.cleanup_code()
     
     instance.stop()
Exemple #5
0
 def test16(self):
     instance = PhiGRAPE(number_of_workers = 2, **default_test_options)
     instance.initialize_code()
     instance.parameters.set_defaults()
     print 1
     particles = datamodel.Particles(2)
     particles.x = [-1.0,1.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, 0.5] | nbody_system.mass
     
     instance.particles.add_particles(particles)
     instance.commit_particles()
 
     instance.evolve_model(0.01 | nbody_system.time)
 
     instance.particles.copy_values_of_all_attributes_to(particles)
     
     print instance.particles.position.x
     self.assertAlmostRelativeEquals(instance.particles[0].position.x, -0.999984741095 | nbody_system.length, 8)
     self.assertAlmostRelativeEquals(instance.particles[1].position.x,  0.999969482189 | nbody_system.length, 8)
     
     instance.evolve_model(0.10 | nbody_system.time)
 
     instance.particles.copy_values_of_all_attributes_to(particles)
     
     print instance.particles.position.x
     self.assertAlmostRelativeEquals(instance.particles[0].position.x, -0.999022960148 | nbody_system.length, 8)
     self.assertAlmostRelativeEquals(instance.particles[1].position.x, 0.998045920305 | nbody_system.length, 8)
     
     instance.evolve_model(0.50 | nbody_system.time)
 
     instance.particles.copy_values_of_all_attributes_to(particles)
     
     print instance.particles.position.x
     self.assertAlmostRelativeEquals(instance.particles[0].position.x, -0.984250788742 | nbody_system.length, 8)
     self.assertAlmostRelativeEquals(instance.particles[1].position.x, 0.968501583383 | nbody_system.length, 8)
     
     instance.cleanup_code()
     
     instance.stop()
Exemple #6
0
 def test15(self):
     instance = PhiGRAPE(number_of_workers = 2, **default_test_options)#, redirection = "none")
     instance.initialize_code()
     instance.parameters.set_defaults()
     print 1
     particles = datamodel.Particles(2)
     particles.x = [-1.0,1.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.particles.add_particles(particles)
     instance.commit_particles()
 
     instance.evolve_model(0.01 | nbody_system.time)
 
     instance.particles.copy_values_of_all_attributes_to(particles)
     
     print instance.particles.position.x
     self.assertEquals(instance.particles[0].position.x, -instance.particles[1].position.x)
     self.assertAlmostRelativeEquals(instance.particles[1].position.x, 0.999969482111 | nbody_system.length, 6)
     
     instance.evolve_model(0.10 | nbody_system.time)
 
     instance.particles.copy_values_of_all_attributes_to(particles)
     
     print instance.particles.position.x
     self.assertEquals(instance.particles[0].position.x, -instance.particles[1].position.x)
     self.assertAlmostRelativeEquals(instance.particles[1].position.x, 0.99804560161 | nbody_system.length, 6)
     
     instance.evolve_model(0.50 | nbody_system.time)
 
     instance.particles.copy_values_of_all_attributes_to(particles)
     
     print instance.particles.position.x
     self.assertEquals(instance.particles[0].position.x, -instance.particles[1].position.x)
     self.assertAlmostRelativeEquals(instance.particles[1].position.x, 0.968416814302 | nbody_system.length, 6)
     
     instance.cleanup_code()
     
     instance.stop()
 def test8(self):
     particles = datamodel.Particles(6)
     particles.mass = nbody_system.mass.new_quantity(range(1,7))
     particles.radius =   0.00001 | nbody_system.length
     particles.position = [[-1.0,0.0,0.0],[1.0,0.0,0.0],[0.0,-1.0,0.0],[0.0,1.0,0.0],[0.0,0.0,-1.0],[0.0,0.0,1.0]] | nbody_system.length
     particles.velocity = [[0.0,0.0,0.0],[0.0,0.0,0.0],[0.0,0.0,0.0],[0.0,0.0,0.0],[0.0,0.0,0.0],[0.0,0.0,0.0]] | nbody_system.speed
     
     for current_mode in ['g6lib','gpu','grape']:
         try:
             instance = PhiGRAPE(mode = current_mode)
         except:
             print "Running PhiGRAPE with mode=" + current_mode, "was unsuccessful."
         else:
             print "Running PhiGRAPE with mode=" + current_mode + "...",
             instance.initialize_code()
             instance.particles.add_particles(particles)
             instance.commit_particles()
             instance.evolve_model(0.1 | nbody_system.time)
             instance.cleanup_code()
             instance.stop()
             print "ok"
Exemple #8
0
 def test8(self):
     particles = datamodel.Particles(6)
     particles.mass = nbody_system.mass.new_quantity(range(1,7))
     particles.radius =   0.00001 | nbody_system.length
     particles.position = [[-1.0,0.0,0.0],[1.0,0.0,0.0],[0.0,-1.0,0.0],[0.0,1.0,0.0],[0.0,0.0,-1.0],[0.0,0.0,1.0]] | nbody_system.length
     particles.velocity = [[0.0,0.0,0.0],[0.0,0.0,0.0],[0.0,0.0,0.0],[0.0,0.0,0.0],[0.0,0.0,0.0],[0.0,0.0,0.0]] | nbody_system.speed
     
     for current_mode in ['g6lib','gpu','grape']:
         try:
             instance = PhiGRAPE(mode = current_mode)
         except:
             print "Running PhiGRAPE with mode=" + current_mode, "was unsuccessful."
         else:
             print "Running PhiGRAPE with mode=" + current_mode + "...",
             instance.initialize_code()
             instance.particles.add_particles(particles)
             instance.commit_particles()
             instance.evolve_model(0.1 | nbody_system.time)
             instance.cleanup_code()
             instance.stop()
             print "ok"
 def test2(self):
     convert_nbody = nbody_system.nbody_to_si(1.0 | units.MSun, 149.5e6 | units.km)
     instance = PhiGRAPE(convert_nbody, **default_test_options)
     
     instance.initialize_code()
     instance.parameters.set_defaults()
     
     stars = self.new_system_of_sun_and_earth()
     earth = stars[1]
     instance.particles.add_particles(stars)
     instance.commit_particles()
 
     for x in range(1,365,30):
         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, "phiGRAPE-earth-sun2.svg")
         figure.savefig(output_file)
     
     instance.cleanup_code()
     instance.stop()
Exemple #10
0
 def test2(self):
     convert_nbody = nbody_system.nbody_to_si(1.0 | units.MSun, 149.5e6 | units.km)
     instance = PhiGRAPE(convert_nbody, **default_test_options)
     
     instance.initialize_code()
     instance.parameters.set_defaults()
     
     stars = self.new_system_of_sun_and_earth()
     earth = stars[1]
     instance.particles.add_particles(stars)
     instance.commit_particles()
 
     for x in range(1,365,30):
         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, "phiGRAPE-earth-sun2.svg")
         figure.savefig(output_file)
     
     instance.cleanup_code()
     instance.stop()