From 9d3456010e06c45d8364acc0a3e4931fcb05b85c Mon Sep 17 00:00:00 2001
From: nguyed99 <nguyed99@zedat.fu-berlin.de>
Date: Tue, 6 Feb 2024 13:00:25 +0100
Subject: [PATCH] Update unit test, and web visualisation

---
 jobs/tests/test_integrator.py | 7 +++++--
 public/index.html             | 2 +-
 public/threebody.py           | 8 +++++---
 3 files changed, 11 insertions(+), 6 deletions(-)

diff --git a/jobs/tests/test_integrator.py b/jobs/tests/test_integrator.py
index ad4b9e1..7aefb9f 100644
--- a/jobs/tests/test_integrator.py
+++ b/jobs/tests/test_integrator.py
@@ -82,9 +82,12 @@ class IntegratorTest(unittest.TestCase):
 
         self.assertTrue(np.greater(1e-10 + np.zeros(H.shape[0]), H - H[0]).all())
 
-        ## checking total momentum conservation
-        L = np.cross(q[:, :2], p[:, :2]) + np.cross(q[:, 2:], p[:, 2:])
+        ## checking total linear momentum conservation
+        P = p[:, :2] + p[:, 2:]
+        self.assertTrue(np.greater(1e-10 + np.zeros(P[0].shape), P - P[0]).all())
 
+        ## checking total angular momentum conservation
+        L = np.cross(q[:, :2], p[:, :2]) + np.cross(q[:, 2:], p[:, 2:])
         self.assertTrue(np.greater(1e-10 + np.zeros(L.shape[0]), L - L[0]).all())
 
 
diff --git a/public/index.html b/public/index.html
index c3b7bc2..1dd66bd 100644
--- a/public/index.html
+++ b/public/index.html
@@ -48,7 +48,7 @@
 	    <table>
 	      <tr>
 		<td>
-                  <p class="observables" id="angular_mom">
+                  <p class="observables" id="obs">
 		</td>
 	      </tr>
 	    </table>
diff --git a/public/threebody.py b/public/threebody.py
index 272dc27..c2056c1 100644
--- a/public/threebody.py
+++ b/public/threebody.py
@@ -98,11 +98,13 @@ def replot_canvas():
     L2 = float(np.cross(x[2, :], p[2, :]))
     L_tot = L0 + L1 + L2
 
+    P_tot = p[0, :] + p[1, :] + p[2, :]
+
     COM = np.sum(globals['m']) * (globals['m'][0] * x[0, :] + globals['m'][1] * x[1, :] + globals['m'][2] * x[2, :])
 
-    angular_mom = document.getElementById("angular_mom")
-    s = f"L0 = {L0:.6f}Ẑ<br>L1 = {L1:.6f}Ẑ<br>L2 = {L2:.6f}Ẑ<br>L_tot = {L_tot:.6f}Ẑ<br><br>E = {E():.6f}<br> COM = {COM[0]:.6f}X̂,  {COM[1]:.6f}Ŷ"
-    angular_mom.innerHTML = s
+    obs = document.getElementById("angular_mom")
+    s = f"L0 = {L0:.6f}Ẑ<br>L1 = {L1:.6f}Ẑ<br>L2 = {L2:.6f}Ẑ<br>L_tot = {L_tot:.6f}Ẑ<br><br>E = {E():.6f}<br> COM = {COM[0]:.6f}X̂, {COM[1]:.6f}Ŷ<br> P_tot = {P_tot[0]:.6f}X̂, {P_tot[1]:.6f}Ŷ"
+    obs.innerHTML = s
 
 
 def push_queue(func, str):
-- 
GitLab