Reference¶
GravHopper consists of the following submodules:
Simulation¶
General usage:
from gravhopper import Simulation
sim = Simulation(dt=<timestep>, eps=<softening>)
sim.add_IC(<initial conditions>)
sim.run(<N>)
sim.plot_particles()
# Other analysis using sim.positions, sim.velocities, sim.times
IC¶
General usage:
from gravhopper import IC
IC_array = IC.Plummer(totmass=<mass>, a=<length>, N=<N>)
sim.add_IC(IC_array)
Because random sampling is not guaranteed to have the center of mass or mean velocity
of exactly zero, all functions that involve random sampling take an argument
force_origin (default: True) that shifts the final particle positions and velocities
to be at the origin, or to a pre-set other location or velocity using the center_pos
and center_vel arguments.
All functions where GravHopper does the random sampling
allow a random seed to be set using the seed argument to facilitate reproducibility.
This seed is fed directly into numpy.random.default_rng().
unitconverter¶
jbgrav¶
The jbgrav module contains the functions that calculate the N-body force within a simulation. They are used internally within Simulation, but can also be imported and called on their own, and can also calculate potentials:
from gravhopper import jbgrav
from astropy import units as u
from numpy import np
sun = {'pos':[0,0,0]*u.au, 'vel':[0,0,0]*u.km/u.s, 'mass':[1]*u.Msun}
earth = {'pos':[1,0,0]*u.au, 'vel':[0,29.8,0]*u.km/u.s, 'mass':[1]*u.Mearth}
solarsystem = {'pos':np.vstack((sun['pos'],earth['pos'])),
'vel':np.vstack((sun['vel'],earth['vel'])),
'mass':np.vstack((sun['mass'],earth['mass']))}
accelerations, potentials = jbgrav.direct_summation(solarsystem, 0.01*u.au, calc_potential=True)