def get_planetary_systems_from_set(bodies, converter=None, RelativePosition=False): # Initialize Kepler if converter == None: converter = nbody_system.nbody_to_si( bodies.mass.sum(), 2 * np.max(bodies.radius.number) | bodies.radius.unit) kep_p = Kepler(unit_converter=converter, redirection='none') kep_p.initialize_code() kep_s = Kepler(unit_converter=converter, redirection='none') kep_s.initialize_code() # Seperate Out Planets and Stars from Bodies stars, planets = util.get_stars(bodies), util.get_planets(bodies) num_stars, num_planets = len(stars), len(planets) # Initialize the Dictionary that Contains all Planetary Systems systems = {} # Start Looping Through Stars to Find Bound Planets for star in stars: system_id = star.id #star.semimajor_axis, star.eccentricity, star.period, star.true_anomaly, star.mean_anomaly, star.kep_energy, star.angular_momentum = \ # None, None, None, None, None, None, None current_system = systems.setdefault(system_id, Particles()) current_system.add_particle(star) for planet in planets: total_mass = star.mass + planet.mass kep_pos = star.position - planet.position kep_vel = star.velocity - planet.velocity kep_p.initialize_from_dyn(total_mass, kep_pos[0], kep_pos[1], kep_pos[2], kep_vel[0], kep_vel[1], kep_vel[2]) a_p, e_p = kep_p.get_elements() if e_p < 1.0: # Check to See if The Stellar System is a Binary # Note: Things get complicated if it is ... noStellarHeirarchy = False for other_star in (stars - star): kep_s.initialize_from_dyn( star.mass + other_star.mass, star.x - other_star.x, star.y - other_star.y, star.z - other_star.z, star.vx - other_star.vx, star.vy - other_star.vy, star.vz - other_star.vz) a_s, e_s = kep_s.get_elements() r_apo = kep_s.get_apastron() HillR = util.calc_HillRadius(a_s, e_s, other_star.mass, star.mass) if e_s >= 1.0 or HillR < r_apo: noStellarHeirarchy = True else: noStellarHeirarchy = False if noStellarHeirarchy: # Get Additional Information on Orbit planet.semimajor_axis = a_p planet.eccentricity = e_p planet.period = kep_p.get_period() planet.true_anomaly, planet.mean_anomaly = kep_p.get_angles( ) #planet.kep_energy, planet.angular_momentum = kep_p.get_integrals() # Add the Planet to the System Set current_system.add_particle(planet) else: # Handling for Planetary Systems in Stellar Heirarchical Structures # Note: This is empty for now, maybe consider doing it by the heaviest bound stellar object as the primary. pass else: continue kep_p.stop() kep_s.stop() return systems
sun_and_stone = Particles(2) sun_and_stone[0].position = [-5.40085336308e+13, -5.92288255636e+13, 0. ] | units.m sun_and_stone[0].velocity = [-68.4281023588, -90.213640012, 0. ] | (units.m / units.s) sun_and_stone[0].mass = 1.98892e+30 | units.kg sun_and_stone[1].position = [2.31421952844e+17, 1.72742642121e+17, 0. ] | units.m sun_and_stone[1].velocity = [500794.477878, 373808.365427, 0. ] | (units.m / units.s) sun_and_stone[1].mass = 0. | units.kg print " particles:" print sun_and_stone converter = nbody_system.nbody_to_si(1 | units.MSun, 1 | units.AU) kepler = Kepler(converter) kepler.initialize_code() kepler.initialize_from_particles(sun_and_stone) semi, ecc = kepler.get_elements() apo = kepler.get_apastron() per = kepler.get_periastron() period = kepler.get_period() kepler.stop() print " semi-major axis ", semi.in_(units.AU) print " eccentricity ", ecc print " apocenter ", apo.in_(units.AU) print " pericenter ", per.in_(units.AU) print " period", period