1
0

general debug and display angular momentum and mechanical energy curves

This commit is contained in:
Thibault Barnouin
2021-10-30 13:24:02 +02:00
parent a82d316cc9
commit 9a16400a89
3 changed files with 20 additions and 10 deletions

View File

@@ -34,7 +34,7 @@ def frogleap(duration, step, dyn_syst, recover_param=False, display=False):
q_array = dyn_syst.get_positions() q_array = dyn_syst.get_positions()
p_array = dyn_syst.get_momenta() p_array = dyn_syst.get_momenta()
E = np.zeros(N) E = np.zeros(N)
L = np.zeros(N) L = np.zeros((N,3))
if display: if display:
d = DynamicUpdate() d = DynamicUpdate()
@@ -53,13 +53,14 @@ def frogleap(duration, step, dyn_syst, recover_param=False, display=False):
body.p = p_array[i] body.p = p_array[i]
if body.m != 0.: if body.m != 0.:
body.v = body.p/body.m body.v = body.p/body.m
dyn_syst.COMShift()
E[j] = dyn_syst.Eval() E[j] = dyn_syst.Eval()
L[j] = dyn_syst.Lval() L[j] = dyn_syst.Lval()
if display: if display:
# In center of mass frame # In center of mass frame
q_cm = np.array([0.,0.])#np.sum(m_array.reshape((q_array.shape[0],1))*q_array, axis=0)/m_array.sum() q_cm = np.sum(m_array.reshape((q_array.shape[0],1))*q_array, axis=0)/m_array.sum()
# display progression # display progression
d.on_running(q_array[:,0]-q_cm[0], q_array[:,1]-q_cm[1]) d.on_running(q_array[:,0]-q_cm[0], q_array[:,1]-q_cm[1])
time.sleep(0.01) time.sleep(0.01)

View File

@@ -55,7 +55,6 @@ class System:
return coord return coord
def COMShift(self): #Shift coordinates of bodies in system to COM frame and set COM at rest def COMShift(self): #Shift coordinates of bodies in system to COM frame and set COM at rest
comcoord = self.COM
for body in self.bodylist: for body in self.bodylist:
body.q = body.q - self.COM() body.q = body.q - self.COM()
body.p = body.p - self.COMV() body.p = body.p - self.COMV()

22
main.py
View File

@@ -2,20 +2,21 @@
# -*- coding:utf-8 -*- # -*- coding:utf-8 -*-
from sys import exit as sysexit from sys import exit as sysexit
import numpy as np import numpy as np
import matplotlib.pyplot as plt
from lib.integrator import frogleap from lib.integrator import frogleap
from lib.objects import Body, System from lib.objects import Body, System
def main(): def main():
#initialisation #initialisation
m = np.array([1e10, 1, 0]) m = np.array([1e5, 1e5, 0.1])
x1 = np.array([0, 0, 0]) x1 = np.array([-1, 0, 0])
x2 = np.array([1, 0, 0]) x2 = np.array([1, 0, 0])
x3 = np.array([10, 0, 0]) x3 = np.array([100, 0, 0])
q = np.array([x1, x2, x3]) q = np.array([x1, x2, x3])
v1 = np.array([0, 0, 0]) v1 = np.array([0, 0, 0])
v2 = np.array([0, 0, 0]) v2 = np.array([0, 1, 0])
v3 = np.array([0, 0, 0]) v3 = np.array([0, 0, 0])
v = np.array([v1, v2, v3]) v = np.array([v1, v2, v3])
@@ -23,9 +24,18 @@ def main():
for i in range(3): for i in range(3):
bodylist.append(Body(m[i], q[i], v[i])) bodylist.append(Body(m[i], q[i], v[i]))
dyn_syst = System(bodylist) dyn_syst = System(bodylist)
dyn_syst.COMShift()
new_dyn_syst = frogleap(10, 0.1, dyn_syst, display=False) E, L = frogleap(10, 0.01, dyn_syst, recover_param=True, display=True)
print(np.all(new_dyn_syst.get_positions() == dyn_syst.get_positions())) fig1 = plt.figure()
ax1 = fig1.add_subplot(111)
ax1.plot(np.arange(E.shape[0]), E, label=r"$E_m$")
ax1.legend()
fig2 = plt.figure()
ax2 = fig2.add_subplot(111)
ax2.plot(np.arange(L.shape[0]), np.sum(L**2,axis=1), label=r"$L^2$")
ax2.legend()
plt.show()
return 0 return 0
if __name__ == '__main__': if __name__ == '__main__':