1
0

remove COMShift everywhere

This commit is contained in:
Thibault Barnouin
2022-01-13 21:30:45 +01:00
parent ce7f70d2eb
commit e34e23c450
16 changed files with 93 additions and 77 deletions

View File

@@ -27,7 +27,6 @@ def Kick(dyn_syst, dt):
def LP(dyn_syst, dt): def LP(dyn_syst, dt):
dyn_syst.COMShift()
Drift(dyn_syst, dt / 2) Drift(dyn_syst, dt / 2)
Kick(dyn_syst, dt) Kick(dyn_syst, dt)
Drift(dyn_syst, dt / 2) Drift(dyn_syst, dt / 2)
@@ -43,16 +42,23 @@ def leapfrog(dyn_syst, bin_syst, duration, dt, recover_param=False, display=Fals
d.launch(dyn_syst.blackstyle) d.launch(dyn_syst.blackstyle)
N = np.ceil(duration / dt).astype(int) N = np.ceil(duration / dt).astype(int)
E = np.zeros(N,dtype=np.longdouble) E = np.zeros(N+1,dtype=np.longdouble)
L = np.zeros((N, 3),dtype=np.longdouble) L = np.zeros((N+1, 3),dtype=np.longdouble)
sma = np.zeros(N,dtype=np.longdouble) sma = np.zeros(N+1,dtype=np.longdouble)
ecc = np.zeros(N,dtype=np.longdouble) ecc = np.zeros(N+1,dtype=np.longdouble)
phi = np.zeros(N,dtype=np.longdouble) phi = np.zeros(N+1,dtype=np.longdouble)
for j in range(N):
E[0] = dyn_syst.ECOM
L[0] = dyn_syst.LCOM
sma[0] = bin_syst.smaCOM
ecc[0] = bin_syst.eccCOM
phi[0] = dyn_syst.phi
for j in range(1,N+1):
LP(dyn_syst,dt) LP(dyn_syst,dt)
E[j] = dyn_syst.E E[j] = dyn_syst.ECOM
L[j] = dyn_syst.L L[j] = dyn_syst.LCOM
sma[j] = bin_syst.smaCOM sma[j] = bin_syst.smaCOM
ecc[j] = bin_syst.eccCOM ecc[j] = bin_syst.eccCOM
phi[j] = dyn_syst.phi phi[j] = dyn_syst.phi

View File

@@ -69,7 +69,6 @@ def Correct(dyn_syst, dt): # correct position and velocities of bodies in syste
def HPC(dyn_syst, dt): # update position and velocities of bodies in system with hermite predictor corrector def HPC(dyn_syst, dt): # update position and velocities of bodies in system with hermite predictor corrector
dyn_syst.COMShift()
Update_a(dyn_syst) Update_a(dyn_syst)
Update_j(dyn_syst) Update_j(dyn_syst)
Predict(dyn_syst, dt) Predict(dyn_syst, dt)
@@ -89,17 +88,23 @@ def hermite(dyn_syst, bin_syst, duration, dt, recover_param=False, display=False
d.launch(dyn_syst.blackstyle) d.launch(dyn_syst.blackstyle)
N = np.ceil(duration / dt).astype(int) N = np.ceil(duration / dt).astype(int)
E = np.zeros(N,dtype=np.longdouble) E = np.zeros(N+1,dtype=np.longdouble)
L = np.zeros((N, 3),dtype=np.longdouble) L = np.zeros((N+1, 3),dtype=np.longdouble)
sma = np.zeros(N,dtype=np.longdouble) sma = np.zeros(N+1,dtype=np.longdouble)
ecc = np.zeros(N,dtype=np.longdouble) ecc = np.zeros(N+1,dtype=np.longdouble)
phi = np.zeros(N,dtype=np.longdouble) phi = np.zeros(N+1,dtype=np.longdouble)
for j in range(N): E[0] = dyn_syst.ECOM
L[0] = dyn_syst.LCOM
sma[0] = bin_syst.smaCOM
ecc[0] = bin_syst.eccCOM
phi[0] = dyn_syst.phi
for j in range(1,N+1):
HPC(dyn_syst, dt) HPC(dyn_syst, dt)
E[j] = dyn_syst.E E[j] = dyn_syst.ECOM
L[j] = dyn_syst.L L[j] = dyn_syst.LCOM
sma[j] = bin_syst.smaCOM sma[j] = bin_syst.smaCOM
ecc[j] = bin_syst.eccCOM ecc[j] = bin_syst.eccCOM
phi[j] = dyn_syst.phi phi[j] = dyn_syst.phi

View File

@@ -24,10 +24,10 @@ class Body:
self.vp = np.zeros(3,dtype=np.longdouble) self.vp = np.zeros(3,dtype=np.longdouble)
def __repr__(self): # Called upon "print(body)" 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, self.q, self.v)
def __str__(self): # Called upon "str(body)" def __str__(self): # Called upon "str(body)"
return r"Body of mass: {0:.1e} $M_\odot$".format(self.m/Ms) return r"Body of mass: {0:.1e} $M_\odot$".format(self.m)
@property @property
def p(self): def p(self):
@@ -67,19 +67,12 @@ class System(Body):
zdata = np.array([body.q[2] 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 return xdata, ydata, zdata
def get_positionsCOM(self): #return the positions of the bodies in the center of mass frame
def get_velocities(self): #return the positions of the bodies COM = self.COM
vxdata = np.array([body.v[0] for body in self.bodylist],dtype=np.longdouble) xdata = np.array([body.q[0]-COM[0] for body in self.bodylist],dtype=np.longdouble)
vydata = np.array([body.v[1] for body in self.bodylist],dtype=np.longdouble) ydata = np.array([body.q[1]-COM[1] for body in self.bodylist],dtype=np.longdouble)
vzdata = np.array([body.v[2] 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 vxdata, vydata, vzdata return xdata, ydata, zdata
def get_momenta(self): #return the momenta of the bodies
pxdata = np.array([body.p[0] for body in self.bodylist],dtype=np.longdouble)
pydata = np.array([body.p[1] for body in self.bodylist],dtype=np.longdouble)
pzdata = np.array([body.p[2] for body in self.bodylist],dtype=np.longdouble)
return pxdata, pydata, pzdata
@property @property
def M(self): #return total system mass def M(self): #return total system mass
@@ -149,29 +142,24 @@ class System(Body):
return E return E
@property @property
def LCOM(self): #return angular momentum in the center of mass of a binary system def ECOM(self): #return total energy of bodies in system in the center of mass frame
#self.COMShiftBin() T, W = 0, 0
LCOM = np.zeros(3,dtype=np.longdouble) COM, COMV = self.COM, self.COMV
dr = self.bodylist[0].m/self.mu*self.bodylist[0].q#b
dv = self.bodylist[0].m/self.mu*self.bodylist[0].v#b
LCOM = self.mu*np.cross(dr,dv)
return LCOM
@property
def ECOM(self): #return mechanical energy in the center of mass of a binary system
#self.COMShiftBin()
dr = self.bodylist[0].m/self.mu*self.bodylist[0].q#b
dv = self.bodylist[0].m/self.mu*self.bodylist[0].v#b
ECOM = self.mu/2.*np.linalg.norm(dv)**2 - Ga*self.M*self.mu/np.linalg.norm(dr)
return ECOM
@property
def L(self): #return angular momentum of bodies in system
L = np.zeros(3,dtype=np.longdouble)
for body in self.bodylist: for body in self.bodylist:
L = L + np.cross(body.q,body.p) T = T + 1./2.*body.m*np.linalg.norm(body.v-COMV)**2
for otherbody in self.bodylist:
if body != otherbody:
rij = np.linalg.norm(body.q-otherbody.q)
W = W - Ga*body.m*otherbody.m/rij
E = T + W
return E
@property
def LCOM(self): #return angular momentum of bodies in system
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 return L
@property @property
@@ -187,6 +175,13 @@ class System(Body):
E = T + W E = T + W
return E 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 @property
def eccCOM(self): #exentricity of two body sub system def eccCOM(self): #exentricity of two body sub system
if len(self.bodylist) == 2 : if len(self.bodylist) == 2 :

View File

@@ -53,7 +53,7 @@ class DynamicUpdate():
self.lines = [] self.lines = []
for i,body in enumerate(self.dyn_syst.bodylist): for i,body in enumerate(self.dyn_syst.bodylist):
x, y, z = body.q x, y, z = body.q/au-self.dyn_syst.COM/au
lines, = self.ax.plot([x],[y],[z],'o',color="C{0:d}".format(i),label="{0:s}".format(str(body))) lines, = self.ax.plot([x],[y],[z],'o',color="C{0:d}".format(i),label="{0:s}".format(str(body)))
self.lines.append(lines) self.lines.append(lines)
self.lines = np.array(self.lines) self.lines = np.array(self.lines)
@@ -74,7 +74,7 @@ class DynamicUpdate():
self.ax.set_zlabel('AU') self.ax.set_zlabel('AU')
def on_running(self, dyn_syst, step=None, label=None): def on_running(self, dyn_syst, step=None, label=None):
xdata, ydata, zdata = dyn_syst.get_positions() xdata, ydata, zdata = dyn_syst.get_positionsCOM()
values = np.sqrt(np.sum((np.array((xdata,ydata,zdata))**2).T,axis=1))/au values = np.sqrt(np.sum((np.array((xdata,ydata,zdata))**2).T,axis=1))/au
self.min_x, self.max_x = -np.max([np.abs(values).max(),self.max_x]), np.max([np.abs(values).max(),self.max_x]) self.min_x, self.max_x = -np.max([np.abs(values).max(),self.max_x]), np.max([np.abs(values).max(),self.max_x])
self.set_lims() self.set_lims()
@@ -134,30 +134,40 @@ def display_parameters(E,L,sma,ecc,phi,parameters,savename=""):
fig3 = plt.figure(figsize=(15,7)) fig3 = plt.figure(figsize=(15,7))
ax3 = fig3.add_subplot(111) ax3 = fig3.add_subplot(111)
ax3.plot(np.arange(sma[-1].shape[0])*step[-1]/yr, sma[-1]/au, label="a (step of {0:.2e}s)".format(step[-1])) for i in range(len(E)):
ax3.plot(np.arange(ecc[-1].shape[0])*step[-1]/yr, ecc[-1], label="e (step of {0:.2e}s)".format(step[-1])) ax3.plot(np.arange(E[i].shape[0])*step[-1]/yr, E[i], label="step of {0:.2e}s".format(step[i]))
ax3.set(xlabel=r"$t \, [yr]$", ylabel=r"$a \, [au] \, or \, e$") ax3.set(xlabel=r"$t \, [yr]$", ylabel=r"$E \, [J]$")
ax3.legend() ax3.legend()
fig3.suptitle("Semi major axis and eccentricity "+title2) fig3.suptitle("Mechanical energy of the whole system "+title2)
fig3.savefig("plots/{0:s}a_e.png".format(savename),bbox_inches="tight") fig3.savefig("plots/{0:s}E.png".format(savename),bbox_inches="tight")
fig4 = plt.figure(figsize=(15,7)) fig4 = plt.figure(figsize=(15,7))
ax4 = fig4.add_subplot(111) ax4 = fig4.add_subplot(111)
for i in range(len(E)): for i in range(len(L)):
ax4.plot(np.arange(E[i].shape[0])*step[-1]/yr, E[i], label="step of {0:.2e}s".format(step[i])) L2 = np.array([np.linalg.norm(Li)**2 for Li in L[i]])
ax4.set(xlabel=r"$t \, [yr]$", ylabel=r"$E \, [J]$") ax4.plot(np.arange(L[i].shape[0])*step[i]/yr, L2, label=r"$L^2$ for step of {0:.2e}s".format(step[i]))
ax4.set(xlabel=r"$t \, [yr]$", ylabel=r"$\left|\vec{L}\right|^2 \, [kg^2 \cdot m^4 \cdot s^{-2}]$",yscale='log')
ax4.legend() ax4.legend()
fig4.suptitle("Mechanical energy of the whole system "+title2) fig4.suptitle("Squared norm of the kinetic moment of the whole system "+title2)
fig4.savefig("plots/{0:s}E.png".format(savename),bbox_inches="tight") fig4.savefig("plots/{0:s}L.png".format(savename),bbox_inches="tight")
fig5 = plt.figure(figsize=(15,7)) fig5 = plt.figure(figsize=(15,7))
ax5 = fig5.add_subplot(111) ax5 = fig5.add_subplot(111)
for i in range(len(phi)): ax5.plot(np.arange(sma[-1].shape[0])*step[-1]/yr, sma[-1]/au, label="a (step of {0:.2e}s)".format(step[-1]))
ax5.plot(np.arange(phi[i].shape[0])*step[-1]/yr, phi[i], label="step of {0:.2e}s".format(step[i])) ax5.plot(np.arange(ecc[-1].shape[0])*step[-1]/yr, ecc[-1], label="e (step of {0:.2e}s)".format(step[-1]))
ax5.set(xlabel=r"$t \, [yr]$", ylabel=r"$\phi \, [^{\circ}]$") ax5.set(xlabel=r"$t \, [yr]$", ylabel=r"$a \, [au] \, or \, e$")
ax5.legend() ax5.legend()
fig5.suptitle("Inclination angle of the perturbator's orbital plane "+title2) fig5.suptitle("Semi major axis and eccentricity "+title2)
fig5.savefig("plots/{0:s}phi.png".format(savename),bbox_inches="tight") fig5.savefig("plots/{0:s}a_e.png".format(savename),bbox_inches="tight")
fig6 = plt.figure(figsize=(15,7))
ax6 = fig6.add_subplot(111)
for i in range(len(phi)):
ax6.plot(np.arange(phi[i].shape[0])*step[-1]/yr, phi[i], label="step of {0:.2e}s".format(step[i]))
ax6.set(xlabel=r"$t \, [yr]$", ylabel=r"$\phi \, [^{\circ}]$")
ax6.legend()
fig6.suptitle("Inclination angle of the perturbator's orbital plane "+title2)
fig6.savefig("plots/{0:s}phi.png".format(savename),bbox_inches="tight")
plt.show(block=True) plt.show(block=True)

View File

@@ -12,9 +12,9 @@ from lib.units import *
def main(): def main():
#initialisation #initialisation
m = np.array([1., 1., 1e-1],dtype=np.longdouble)*Ms#/Ms # Masses in Solar mass m = np.array([1., 1., 1e-1],dtype=np.longdouble)*Ms#/Ms # Masses in Solar mass
a = np.array([1., 1., 10.],dtype=np.longdouble)/2.*au#/au # Semi-major axis in astronomical units a = np.array([1., 1., 10.],dtype=np.longdouble)*au#/au # Semi-major axis in astronomical units
e = np.array([0., 0., 0.25],dtype=np.longdouble) # Eccentricity e = np.array([0., 0., 0.25],dtype=np.longdouble) # Eccentricity
psi = np.array([0., 0., 60.],dtype=np.longdouble)*np.pi/180. # Inclination of the orbital plane in degrees psi = np.array([0., 0., 80.],dtype=np.longdouble)*np.pi/180. # Inclination of the orbital plane in degrees
x1 = np.array([0., -1., 0.],dtype=np.longdouble)*a[0]*(1.+e[0]) x1 = np.array([0., -1., 0.],dtype=np.longdouble)*a[0]*(1.+e[0])
x2 = np.array([0., 1., 0.],dtype=np.longdouble)*a[1]*(1.+e[1]) x2 = np.array([0., 1., 0.],dtype=np.longdouble)*a[1]*(1.+e[1])
@@ -27,7 +27,7 @@ def main():
v = np.array([v1, v2, v3],dtype=np.longdouble) v = np.array([v1, v2, v3],dtype=np.longdouble)
#integration parameters #integration parameters
duration, step = 5000*yr, np.array([30.*86400.],dtype=np.longdouble) #integration time and step in seconds duration, step = 500*yr, np.array([30./1.*86400.],dtype=np.longdouble) #integration time and step in seconds
step = np.sort(step)[::-1] step = np.sort(step)[::-1]
integrator = "leapfrog" integrator = "leapfrog"
n_bodies = 3 n_bodies = 3

Binary file not shown.

Before

Width:  |  Height:  |  Size: 111 KiB

After

Width:  |  Height:  |  Size: 111 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 37 KiB

After

Width:  |  Height:  |  Size: 34 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 95 KiB

After

Width:  |  Height:  |  Size: 89 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 95 KiB

After

Width:  |  Height:  |  Size: 60 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 31 KiB

After

Width:  |  Height:  |  Size: 31 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 56 KiB

After

Width:  |  Height:  |  Size: 184 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 34 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 67 KiB

After

Width:  |  Height:  |  Size: 62 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 57 KiB

After

Width:  |  Height:  |  Size: 134 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 63 KiB

After

Width:  |  Height:  |  Size: 34 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 56 KiB

After

Width:  |  Height:  |  Size: 213 KiB