In [1]:
%matplotlib inline
import numpy as np
import matplotlib.pyplot as plt
from matplotlib import rc
from matplotlib.colors import LogNorm
rc('text', usetex=True)
plt.rc('font', family='serif')
from __future__ import print_function
from IPython.html.widgets import interact
In [2]:
%%bash
make
./non_axisymmetric_potential
In [3]:
n_bodies = 100
i=1
t_i, x_i, y_i, z_i, v_x_i, v_y_i, v_z_i = np.loadtxt('body_' + str(i).zfill(4) + '.dat', unpack=True, skiprows=1)
n_points = t_i.size
t = np.empty( (n_bodies, n_points))
t[i-1,:] = t_i
x = np.empty( (n_bodies, n_points))
x[i-1,:] = x_i
y = np.empty( (n_bodies, n_points))
y[i-1,:] = y_i
z = np.empty( (n_bodies, n_points))
z[i-1,:] = z_i
v_x = np.empty( (n_bodies, n_points))
v_x[i-1,:] = v_x_i
v_y = np.empty( (n_bodies, n_points))
v_y[i-1,:] = v_y_i
v_z = np.empty( (n_bodies, n_points))
v_z[i-1,:] = v_z_i
for i in range(2, n_bodies+1):
t_i, x_i, y_i, z_i, v_x_i, v_y_i, v_z_i = np.loadtxt('body_' + str(i).zfill(4) + '.dat', unpack=True, skiprows=1)
t[i-1,:] = t_i
x[i-1,:] = x_i
y[i-1,:] = y_i
z[i-1,:] = z_i
v_x[i-1,:] = v_x_i
v_y[i-1,:] = v_y_i
v_z[i-1,:] = v_z_i
In [4]:
plot_step_size = 10
def plot_solution(plot_start=0,body=1):
print("plot range: t= ",plot_start, " - ", plot_start + plot_step_size)
print("x_0 = ", x[body-1, 0])
t_tmp = t[body-1,:]
x_tmp = x[body-1,:]
y_tmp = y[body-1,:]
indices = np.where( ((t_tmp > plot_start) & (t_tmp < plot_start + plot_step_size)))
plt.plot(x_tmp[indices], y_tmp[indices], linestyle='-')
plt.xlabel(r"$x$")
plt.ylabel(r"$y$")
plt.legend([r"Body " + str(1)], loc="upper right")
plt.axvline(0, linestyle = '--')
plt.axhline(0, linestyle = '--')
return
interact(plot_solution, plot_start=(0,plot_step_size*np.floor(t[0,-1] / plot_step_size),plot_step_size), body=(1,n_bodies));
Now let's plot the surface of section. This will be a slice through phase-space, as a way to visualize what regions in phase-space our solutions explore. Since phase-space is a 6-dimension vector space, we need to use these slicings to understand what's happening.
For this surface of section, every time an integration crosses the y=0 plane, going from y < 0 to y > 0 (i.e. once a revolution for quasi-circular orbits), we'll plot its x position and x velocity.
In [5]:
y_shift = np.zeros(y.shape)
y_shift[:, 0] = 0
y_shift[:, 1:] = y[:, :-1]
surface_points = np.where(((y_shift) < 0) & (y > 0))
plt.hist2d(x[surface_points], v_x[surface_points], cmap='Greys', bins=n_bodies, norm=LogNorm())
plt.xlabel(r"$x$")
plt.ylabel(r"$\ddot{x}$")
plt.title(r"Surface of Section --- $y=0$, $\dot{y}>0$ --- $E=-1$, $e=0.3$")
figure_filename = "surface_of_section"
plt.savefig(figure_filename + ".eps")
plt.savefig(figure_filename + ".pdf")