From c4e06696c6da86c8c2697a504b2e95b5a13863be Mon Sep 17 00:00:00 2001
From: Gamelin Alexis <gamelin@synchrotron-soleil.fr>
Date: Tue, 6 Apr 2021 15:21:03 +0200
Subject: [PATCH] Minor changes

Change back invariant name to cs_invariant
Simplify SkewQuadrupole track method
---
 tracking/element.py           | 19 +++++--------------
 tracking/monitors/monitors.py |  6 +++---
 tracking/monitors/plotting.py |  4 ++--
 tracking/particles.py         |  4 ++--
 4 files changed, 12 insertions(+), 21 deletions(-)

diff --git a/tracking/element.py b/tracking/element.py
index 34fdc76..911817a 100644
--- a/tracking/element.py
+++ b/tracking/element.py
@@ -203,8 +203,8 @@ class TransverseMap(Element):
         
 class SkewQuadrupole:
     """
-    Skew quadrupole element used to introduce betatron coupling. The length of
-    the quadrupole is neglected.
+    Thin skew quadrupole element used to introduce betatron coupling (the 
+    length of the quadrupole is neglected).
     
     Parameters
     ----------
@@ -226,16 +226,7 @@ class SkewQuadrupole:
         ----------
         bunch : Bunch or Beam object
         """
-        matrix = np.zeros((4,4,len(bunch)))
-        matrix[0,0,:] = 1
-        matrix[1,1,:] = 1
-        matrix[2,2,:] = 1
-        matrix[3,3,:] = 1
-        matrix[1,2,:] = -1*self.strength
-        matrix[3,0,:] = -1*self.strength
         
-        xp = bunch['xp'] + matrix[1,2,:]*bunch['y']
-        yp = bunch['yp'] + matrix[3,0,:]*bunch['x']
-    
-        bunch['xp'] = xp
-        bunch['yp'] = yp
+        bunch['xp'] = bunch['xp'] - self.strength * bunch['y']
+        bunch['yp'] = bunch['yp'] - self.strength * bunch['x']
+
diff --git a/tracking/monitors/monitors.py b/tracking/monitors/monitors.py
index 88ae258..32f0af2 100644
--- a/tracking/monitors/monitors.py
+++ b/tracking/monitors/monitors.py
@@ -16,7 +16,7 @@ from mbtrack2.tracking.element import Element
 from mbtrack2.tracking.particles import Bunch, Beam
 from scipy.interpolate import interp1d
 from abc import ABCMeta
-#from mpi4py import MPI
+from mpi4py import MPI
 
 class Monitor(Element, metaclass=ABCMeta):
     """
@@ -269,10 +269,10 @@ class BunchMonitor(Monitor):
         group_name = "BunchData_" + str(self.bunch_number)
         dict_buffer = {"mean":(6, buffer_size), "std":(6, buffer_size),
                      "emit":(3, buffer_size), "current":(buffer_size,),
-                     "action":(2, buffer_size)}
+                     "cs_invariant":(2, buffer_size)}
         dict_file = {"mean":(6, total_size), "std":(6, total_size),
                      "emit":(3, total_size), "current":(total_size,),
-                     "action":(2, total_size)}
+                     "cs_invariant":(2, total_size)}
         self.monitor_init(group_name, save_every, buffer_size, total_size,
                           dict_buffer, dict_file, file_name, mpi_mode)
         
diff --git a/tracking/monitors/plotting.py b/tracking/monitors/plotting.py
index bbd39ba..a457a39 100644
--- a/tracking/monitors/plotting.py
+++ b/tracking/monitors/plotting.py
@@ -123,7 +123,7 @@ def plot_bunchdata(filename, bunch_number, dataset, dimension="x", x_var="time")
     bunch_number : int
         Bunch to plot. This has to be identical to 'bunch_number' parameter in 
         'BunchMonitor' object.
-    dataset : {"current", "emit", "mean", "std", "action"}
+    dataset : {"current", "emit", "mean", "std", "cs_invariant"}
         HDF5 file's dataset to be plotted.
     dimension : str, optional
         The dimension of the dataset to plot. Use "None" for "current",
@@ -175,7 +175,7 @@ def plot_bunchdata(filename, bunch_number, dataset, dimension="x", x_var="time")
         
         label = label_list[axis_index]
         
-    elif dataset == "action":
+    elif dataset == "cs_invariant":
         dimension_dict = {"x":0, "y":1}
         axis_index = dimension_dict[dimension]
         y_var = file[group][dataset][axis_index]
diff --git a/tracking/particles.py b/tracking/particles.py
index c9ad596..f662f67 100644
--- a/tracking/particles.py
+++ b/tracking/particles.py
@@ -232,9 +232,9 @@ class Bunch:
         return np.array([emitX, emitY, emitS])
     
     @property
-    def action(self):
+    def cs_invariant(self):
         """
-        Return the average action (Couran-Snyder invariant) of each plane.
+        Return the average Courant-Snyder invariant of each plane.
 
         """
         Jx = (self.ring.optics.local_gamma[0] * self['x']**2) + \
-- 
GitLab