1
0

tidy things up

This commit is contained in:
Thibault Barnouin
2022-01-18 22:33:33 +01:00
parent e10b4a380c
commit 5168a52ade
13 changed files with 111 additions and 139 deletions

View File

@@ -14,8 +14,6 @@ class Body:
self.m = np.longdouble(mass)
self.q = np.longdouble(position)
self.v = np.longdouble(velocity)
self.qb = np.longdouble(position)
self.vb = np.longdouble(velocity)
self.a = np.zeros(3,dtype=np.longdouble)
self.ap = np.zeros(3,dtype=np.longdouble)
self.j = np.zeros(3,dtype=np.longdouble)
@@ -24,7 +22,8 @@ class Body:
self.vp = np.zeros(3,dtype=np.longdouble)
def __repr__(self): # Called upon "print(body)"
return r"Body of mass: {0:.1e} $M_\odot$, position: {1}, velocity: {2}".format(self.m/Ms, self.q, self.v)
return r"Body of mass: {0:.1e} $M_\odot$, position: {1},\
velocity: {2}".format(self.m/Ms, self.q, self.v)
def __str__(self): # Called upon "str(body)"
return r"Body of mass: {0:.1e} $M_\odot$".format(self.m/Ms)
@@ -48,7 +47,6 @@ class System(Body):
self.m = self.M
self.q = self.COM
self.v = self.COMV
self.coordarray = []
def __repr__(self): # Called upon "print(system)"
return str([print(body) for body in self.bodylist])
@@ -58,20 +56,27 @@ class System(Body):
def get_masses(self): #return the masses of each object
return np.array([body.m for body in self.bodylist],dtype=np.longdouble)
return np.array([body.m for body in self.bodylist],
dtype=np.longdouble)
def get_positions(self): #return the positions of the bodies
xdata = np.array([body.q[0] for body in self.bodylist],dtype=np.longdouble)
ydata = np.array([body.q[1] for body in self.bodylist],dtype=np.longdouble)
zdata = np.array([body.q[2] for body in self.bodylist],dtype=np.longdouble)
xdata = np.array([body.q[0] for body in self.bodylist],
dtype=np.longdouble)
ydata = np.array([body.q[1] for body in self.bodylist],
dtype=np.longdouble)
zdata = np.array([body.q[2] for body in self.bodylist],
dtype=np.longdouble)
return xdata, ydata, zdata
def get_positionsCOM(self): #return the positions of the bodies in the center of mass frame
COM = self.COM
xdata = np.array([body.q[0]-COM[0] for body in self.bodylist],dtype=np.longdouble)
ydata = np.array([body.q[1]-COM[1] for body in self.bodylist],dtype=np.longdouble)
zdata = np.array([body.q[2]-COM[2] for body in self.bodylist],dtype=np.longdouble)
def get_positionsCOM(self): #return the positions of the bodies
COM = self.COM # in the center of mass frame
xdata = np.array([body.q[0]-COM[0] for body in self.bodylist],
dtype=np.longdouble)
ydata = np.array([body.q[1]-COM[1] for body in self.bodylist],
dtype=np.longdouble)
zdata = np.array([body.q[2]-COM[2] for body in self.bodylist],
dtype=np.longdouble)
return xdata, ydata, zdata
@property
@@ -105,45 +110,17 @@ class System(Body):
coord = coord/self.M
return coord
def COMShift(self): #Shift coordinates of bodies in system to COM frame and set COM at rest
COM = self.COM
def COMShift(self): #Shift coordinates of bodies in system to
COM = self.COM # COM frame and set COM at rest
COMV = self.COMV
for body in self.bodylist:
body.q = body.q - COM
body.v = body.v - COMV
def COMShiftBin(self): #Shift coordinates of inner binary system to COM frame and set COM at rest
COM = self.COM
COMV = self.COMV
for body in self.bodylist:
body.qb = body.q - COM
body.vb = body.v - COMV
@property
def LBIN(self): #return angular momentum of inner binary
self.COMShiftBin()
L = np.zeros(3,dtype=np.longdouble)
for body in self.bodylist:
L = L + np.cross(body.qb,body.pb)
return L
@property
def EBIN(self): #return total energy of inner binary
self.COMShiftBin()
def ECOM(self): #return total energy in COM frame
T = np.longdouble(0.)
W = np.longdouble(0.)
for body in self.bodylist:
T = T + 1./2.*body.m*np.linalg.norm(body.vb)**2
for otherbody in self.bodylist:
if body != otherbody:
rij = np.linalg.norm(body.qb-otherbody.qb)
W = W - G*body.m*otherbody.m/rij
E = T + W
return E
@property
def ECOM(self): #return total energy of bodies in system in the center of mass frame
T, W = np.longdouble(0.), np.longdouble(0.)
COM, COMV = self.COM, self.COMV
for body in self.bodylist:
T = T + 1./2.*body.m*np.linalg.norm(body.v-COMV)**2
@@ -155,37 +132,18 @@ class System(Body):
return E
@property
def LCOM(self): #return angular momentum of bodies in system
def LCOM(self): #return angular momentum of bodies in system in COM frame
L = np.zeros(3,dtype=np.longdouble)
COM, COMV = self.COM, self.COMV
for body in self.bodylist:
L = L + np.cross(body.q-COM,body.p-body.m*COMV)
return L
@property
def E(self): #return total energy of bodies in system
T = np.longdouble(0.)
W = np.longdouble(0.)
for body in self.bodylist:
T = T + 1./2.*body.m*np.linalg.norm(body.v)**2
for otherbody in self.bodylist:
if body != otherbody:
rij = np.linalg.norm(body.q-otherbody.q)
W = W - G*otherbody.m*body.m/(2.*rij)
E = T + W
return E
@property
def L(self): #return angular momentum of bodies in system in the center of mass frame
L = np.zeros(3,dtype=np.longdouble)
for body in self.bodylist:
L = L + np.cross(body.q,body.p)
return L
@property
def eccCOM(self): #exentricity of two body sub system
if len(self.bodylist) == 2 :
ecc = (2.*self.ECOM*(np.linalg.norm(self.LCOM)**2))/(G**2*self.M**2*self.mu**3) + 1.
ecc = np.sqrt((2.*self.ECOM*(np.linalg.norm(self.LCOM)**2))
/(G**2*self.M**2*self.mu**3) + 1.)
else :
ecc = np.nan
@@ -200,30 +158,15 @@ class System(Body):
return sma
@property
def ecc(self): #exentricity of two body sub system
if len(self.bodylist) == 2 :
ecc = (2.*self.EBIN*(np.linalg.norm(self.LBIN)**2))/(G**2*self.M**2*self.mu**3) + 1.
else :
ecc = np.nan
return ecc
@property
def sma(self): #semi major axis of two body sub system
if len(self.bodylist) == 2 :
sma = -G*self.mu*self.bodylist[0].m/(2.*self.EBIN)
else :
sma = np.nan
return sma
@property
def phi(self): #return angle in degree between plans formed by perturbator plan and reference plan
def phi(self): #return angle formed by perturbator plan and reference plan
if len(self.bodylist) == 3 :
body1 = self.bodylist[0]
body2 = self.bodylist[2]
n1 = np.cross(body1.q-self.COM, body1.v-self.COMV)
n2 = np.cross(body2.q-self.COM, body2.v-self.COMV)
n1 = np.array([0., 0., 1.], dtype=np.longdouble)
phi = np.arccos(np.dot(n1, n2) / (np.linalg.norm(n1) * np.linalg.norm(n2)))*180./np.pi
phi = np.arccos(np.dot(n1, n2) / (np.linalg.norm(n1)
* np.linalg.norm(n2)))*180./np.pi
else :
phi = np.nan
return phi