From 01629896e9d5525e2f89c57d1f27d84ec9530365 Mon Sep 17 00:00:00 2001 From: Alex_Hubert Date: Fri, 22 Oct 2021 15:00:01 +0200 Subject: [PATCH] method : energy Eval --- lib/objects.py | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/lib/objects.py b/lib/objects.py index d757756..cd0dfbd 100755 --- a/lib/objects.py +++ b/lib/objects.py @@ -38,7 +38,7 @@ class System: coord = coord/self.Mass() return coord - def Lval(self,Lbodylist): #return angular momentum of body in bodylist + def Lval(self,Lbodylist): #return angular momentum of bodies in bodylist comcoord = np.zeros(3) for body in Lbodylist: comcoord = comcoord + body.m*body.q @@ -51,6 +51,17 @@ class System: L = L + np.cross(comq[i],body.p) i = i+1 return L + def Eval(self,Lbodylist): #return total energy of bodies in bodylist + G = 1. #Gravitational constant (here normalized) + T = 0 + W = 0 + for body in Lbodylist: + T = T + 1./2.*body.m*np.linalg.norm(body.v)**2 + for otherbody in Lbodylist: + if body != otherbody: + rij = np.linalg.norm(body.q-otherbody.q) + W = W - G*body.m*otherbody.m/rij + return T + W if __name__ == "__main__":