def integrate_solar_system(sun, planets, time_end=5.0 | units.yr, n_steps=500): """ evolve the system using kepler_orbiters """ converter = nbody_system.nbody_to_si(1 | units.MSun, 1 | units.AU) planets_around_sun = Kepler(converter, channel_type="sockets") # central particle planets_around_sun.central_particle.add_particles(sun[0:1]) # to set the central particle at the center of the coordinate system #planets_around_sun.central_particle.position = (0.0, 0.0, 0.0) | units.AU #planets_around_sun.central_particle.velocity = (0.0, 0.0, 0.0) | units.kms # orbiters planets_around_sun.orbiters.add_particles(planets) planets_around_sun.commit_particles() # to change the integration method #planets_around_sun.parameters.method = 1 #print planets_around_sun.get_method() channel_from_planetets_to_framework = planets_around_sun.orbiters.new_channel_to( planets) channel_from_sun_to_framework = planets_around_sun.central_particle.new_channel_to( sun) positions_sun = quantities.AdaptingVectorQuantity() positions_planets = quantities.AdaptingVectorQuantity() dt = time_end / float(n_steps) time = 0.0 | units.yr print " ** evolving solar system for", time_end.in_( units.yr), ", with time-step of", dt.in_(units.yr) print " this might take a while" while time <= time_end: #print "\t", time.in_(units.yr) planets_around_sun.evolve_model(time) channel_from_planetets_to_framework.copy() channel_from_sun_to_framework.copy() positions_sun.append(sun.position) positions_planets.append(planets.position) time += dt print " **" planets_around_sun.stop() return positions_sun, positions_planets
def test1(self): convert_nbody = nbody_system.nbody_to_si(1.0 | units.MSun, 149.5e6 | units.km) instance = Kepler( convert_nbody) #, redirection="none")#, debugger="xterm") instance.initialize_code() stars = self.new_system_of_sun_and_earth() earth = stars[1] instance.central_particle.add_particle(stars[0]) earth = instance.orbiters.add_particle(stars[1]) instance.commit_particles() instance.evolve_model(365 | units.day) instance.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.assertAlmostEqual(position_at_start, position_after_full_rotation, 6) 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, 3) 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 test1(self): convert_nbody = nbody_system.nbody_to_si(1.0 | units.MSun, 149.5e6 | units.km) instance = Kepler(convert_nbody)#, redirection="none")#, debugger="xterm") instance.initialize_code() stars = self.new_system_of_sun_and_earth() earth = stars[1] instance.central_particle.add_particle(stars[0]) earth = instance.orbiters.add_particle(stars[1]) instance.commit_particles() instance.evolve_model(365 | units.day) instance.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.assertAlmostEqual(position_at_start, position_after_full_rotation, 6) 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, 3) 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 test0(self): instance = Kepler() instance.stop()