AstroDynamics.orbits¶
Module Contents¶
Classes¶
Numerical techniques for solving the two-body problem. |
Functions¶
|
Function to return the position and velocity vectors of Halley's comet |
Function to configure the matplotlib.pyplot style. This function is called before any images are saved. |
- class AstroDynamics.orbits.orbit(M, m, X, x, V, v, dt, tend, integrator, approx=True)[source]¶
Numerical techniques for solving the two-body problem.
The methods calculate the orbital elements of the system, including the energy and angular momentum at each timestep.
Note: The inputs must be in code units.
- Parameters:
M (float) – Mass of the star.
m (float) – Mass of the planet.
X (np.ndarray) – Initial position vector of the star.
x (np.ndarray) – Initial position vector of the planet.
V (np.ndarray) – Initial velocity vector of the star.
v (np.ndarray) – Initial velocity vector of the planet.
dt (float) – Timestep to use for the integration.
tend (int) – Number of timesteps.
integrator (str) – Integrator to use, options include ‘euler’ and …
approx (bool) – If True then the acceleration will be calculated using the 1/r^3 approximation in which the unit vector is abosorbed by the denominator. Defaults to True.
- energy¶
Energy of the system, which should be conserved at all timesteps.
- Type:
np.ndarray
- energy_error¶
Energy error of the system.
- Type:
np.ndarray
- h¶
Angular momentum of the system, as a function of time.
- Type:
np.ndarray
- h_error¶
Angular momentum error of the system, as a function of time.
- Type:
np.ndarray
- X_vec¶
X-position of the star as a function of integrated time.
- Type:
np.ndarray
- Y_vec¶
Y-position of the star as a function of integrated time.
- Type:
np.ndarray
- x_vec¶
X-position of the planet as a function of integrated time.
- Type:
np.ndarray
- y_vec¶
Y-position of the planet as a function of integrated time.
- Type:
np.ndarray
- _run_()[source]¶
Calculates the orbital characteristics.
- Parameters:
None –
- Returns:
None
- Raises:
ValueError – If self.integrator is not a string or is not ‘euler’
This method must be called directly if the class parameters are updated after initialization.
- euler_integrator()[source]¶
Executes the Euler integration method and calculates time taken to complete.
- Parameters:
None –
- Returns:
None
Saves time taken to complete in self.integration_time.
- runge_kutta_integrator()[source]¶
Executes the Runge-Kutta integration method and calculates time taken to complete.
- Parameters:
None –
- Returns:
None
Saves time taken to complete in self.integration_time.
- leapfrog_integrator()[source]¶
Executes the leapfrog integration method, also called the Störmer method or the Verlet method.
- Parameters:
None –
- Returns:
None
Saves time taken to complete in self.integration_time.
- calc_acceleration(x, X)[source]¶
Calculates the acceleration of both bodies at a given position.
- Parameters:
None –
- Returns:
Two floats, the acceleration of the planet and the acceleration of the star, respectively.
- Return type:
- calc_energy(Vx, vx, Vy, vy)[source]¶
Calculates the energy of the two-body system, assuming z-components are zero!
- Parameters:
- Returns:
The energy of the two-body system at the input positions.
- Return type:
- calc_com()[source]¶
Calculates the position vector of the center of mass vector at a given timestep.
- Parameters:
None –
- Returns:
The length of the center of mass position vector.
- Return type:
- calc_comv(Vx, vx, Vy, vy)[source]¶
Calculates the velocity vector of the center of mass of the two objects.
- Parameters:
- Returns:
The velocity of the center of mass.
- Return type:
- plot_com(savefig=False)[source]¶
Plots the COM position of the star and the planet’s orbit.
- Parameters:
savefig (bool, optional) – If True, the image will be saved to the home directory, unless a path attribute is set. Defaults to False, which will output the figure.
- Returns:
The resulting plot.
- Return type:
AxesImage
- plot_vcom(savefig=False)[source]¶
Plots the COM velocity of the star and the planet’s orbit.
- Parameters:
savefig (bool, optional) – If True, the image will be saved to the home directory, unless a path attribute is set. Defaults to False, which will output the figure.
- Returns:
The resulting plot.
- Return type:
AxesImage
- plot_orbit(savefig=False)[source]¶
Plots the XY position of the star and the planet’s orbit.
- Parameters:
savefig (bool, optional) – If True, the image will be saved to the home directory, unless a path attribute is set. Defaults to False, which will output the figure.
- Returns:
The resulting plot.
- Return type:
AxesImage
- plot_energy(savefig=False)[source]¶
Plots the energy of the system as a function of the integration timesteps.
- Parameters:
savefig (bool, optional) – If True, the image will be saved to the home directory, unless a path attribute is set. Defaults to False, which will output the figure.
- Returns:
The resulting plot.
- Return type:
AxesImage
- plot_momentum(savefig=False)[source]¶
Plots the momentum of the system as a function of the integration timesteps.
- Parameters:
savefig (bool, optional) – If True, the image will be saved to the home directory, unless a path attribute is set. Defaults to False, which will output the figure.
- Returns:
The resulting plot.
- Return type:
AxesImage