1
0

Initial conditions for 3 bodies

This commit is contained in:
Thibault Barnouin
2021-11-05 14:31:30 +01:00
parent 0d4cb52421
commit 6987baaf3a
7 changed files with 33 additions and 22 deletions

View File

@@ -10,7 +10,9 @@ import time
import numpy as np
from lib.plots import DynamicUpdate
globals()["G"] = 1. #Gravitationnal constant
globals()['G'] = 6.67e-11 #Gravitational constant in SI units
globals()['Ms'] = 2e30 #Solar mass in kg
globals()['au'] = 1.5e11 #Astronomical unit in m
def dp_dt(m_array, q_array):
"""
@@ -20,7 +22,7 @@ def dp_dt(m_array, q_array):
dp_array = np.zeros(q_array.shape)
for i in range(q_array.shape[0]):
q_j = np.delete(q_array, i, 0)
m_j = np.delete(m_array, i, 0)#.reshape((q_j.shape[0],1))
m_j = np.delete(m_array, i, 0)
dp_array[i] = -G*m_array[i]*np.sum(m_j/np.sum(np.sqrt(np.sum((q_j-q_array[i])**2, axis=0)))**3*(q_j-q_array[i]), axis=0)
dp_array[np.isnan(dp_array)] = 0.
return dp_array

View File

@@ -5,6 +5,9 @@ Class definition for physical atribute
"""
import numpy as np
globals()['G'] = 6.67e-11 #Gravitational constant in SI units
globals()['Ms'] = 2e30 #Solar mass in kg
globals()['au'] = 1.5e11 #Astronomical unit in m
class Body:
@@ -67,7 +70,6 @@ class System:
return L
def Eval(self): #return total energy of bodies in system
G = 1. #Gravitational constant (here normalized)
T = 0
W = 0
for body in self.bodylist:

View File

@@ -30,17 +30,18 @@ class DynamicUpdate():
def on_running(self, xdata, ydata, zdata, step=None, label=None):
#Update data (with the new _and_ the old points)
self.lines.set_data_3d(xdata, ydata, zdata)
if not label is None:
self.ax.set_title(label)
#Need both of these in order to rescale
self.ax.relim()
self.ax.autoscale_view()
#We need to draw *and* flush
self.fig.canvas.draw()
self.fig.canvas.flush_events()
if not step is None and step%10==0:
self.fig.savefig("tmp/{0:05d}.png".format(step),bbox_inches="tight")
if not step is None and step%100==0:
self.lines.set_data_3d(xdata, ydata, zdata)
if not label is None:
self.ax.set_title(label)
#Need both of these in order to rescale
self.ax.relim()
self.ax.autoscale_view()
#We need to draw *and* flush
self.fig.canvas.draw()
self.fig.canvas.flush_events()
if not step is None and step%100==0:
self.fig.savefig("tmp/{0:05d}.png".format(step),bbox_inches="tight")
#Example
def __call__(self):