1
0

object = system

Properties
This commit is contained in:
Alex_Hubert
2021-11-18 19:50:07 +01:00
parent 53ce8be084
commit ff1c46df71
5 changed files with 55 additions and 22 deletions

View File

@@ -28,12 +28,15 @@ class Body:
def __str__(self): # Called upon "str(body)"
return r"Body of mass: {0:.2f} $M_\odot$".format(self.m)
class System:
class System(Body):
def __init__(self, bodylist, blackstyle=True):
self.blackstyle = blackstyle
self.blackstyle = blackstyle #for dark mode in plot
self.bodylist = np.array(bodylist)
self.time = 0
self.time = 0 #lifetime of system
self.m = self.M
self.q = self.COM
self.v = self.COMV
@property
def get_masses(self): #return the masses of each object
@@ -60,39 +63,43 @@ class System:
pzdata = np.array([body.p[2] for body in self.bodylist])
return pxdata, pydata, pzdata
def Mass(self): #return total system mass
@property
def M(self): #return total system mass
mass = 0
for body in self.bodylist:
mass = mass + body.m
return mass
@property
def COM(self): #return center of mass in cartesian np_array
coord = np.zeros(3)
for body in self.bodylist:
coord = coord + body.m*body.q
coord = coord/self.Mass()
coord = coord/self.M
return coord
@property
def COMV(self): #return center of mass velocity in cartesian np_array
coord = np.zeros(3)
for body in self.bodylist:
coord = coord + body.p
coord = coord/self.Mass()
coord = coord/self.M
return coord
def COMShift(self): #Shift coordinates of bodies in system to COM frame and set COM at rest
for body in self.bodylist:
body.q = body.q - self.COM()
body.p = body.p - self.COMV()
return 0
body.q = body.q - self.COM
body.p = body.p - self.COMV
def Lval(self): #return angular momentum of bodies in system
@property
def L(self): #return angular momentum of bodies in system
L = np.zeros(3)
for body in self.bodylist:
L = L + np.cross(body.q,body.p)
return L
def Eval(self): #return total energy of bodies in system
@property
def E(self): #return total energy of bodies in system
T = 0
W = 0
for body in self.bodylist:
@@ -101,7 +108,8 @@ class System:
if body != otherbody:
rij = np.linalg.norm(body.q-otherbody.q)
W = W - G*body.m*otherbody.m/rij
return T + W
E = T + W
return E
def Drift(self, dt):
for body in self.bodylist:
@@ -140,8 +148,8 @@ class System:
for j in range(N):
self.LP(dt)
E[j] = self.Eval()
L[j] = self.Lval()
E[j] = self.E
L[j] = self.L
if display and j%5==0:
# display progression
@@ -237,8 +245,8 @@ class System:
for j in range(N):
self.HPC(dt)
E[j] = self.Eval()
L[j] = self.Lval()
E[j] = self.E
L[j] = self.L
if display and j%100==0:
# display progression
@@ -261,3 +269,33 @@ class System:
def __str__(self): # Called upon "str(system)"
return str([str(body) for body in self.bodylist])
@property
def mu(self):
sum = 0
prod = 1
for body in self.bodylist:
prod = prod * body.m
mu = prod/self.M
return mu
@property
def ex(self): #exentricity of system (if composed of 2 bodies)
if len(self.bodylist) != 2 :
return np.nan
else:
k = (2.*self.E*(np.linalg.norm(self.L)**2))/((G**2)*(self.M**2)*(self.mu**3)) + 1.
return k
@property
def sma(self): #semi major axis of system (if composed of 2 bodies)
if len(self.bodylist) != 2 :
return np.nan
else:
sma = -G*self.M*self.mu/(2.*self.E)
return sma