From 7d7581ed53ed6a27faa83c10b7dae4eb9f35ce95 Mon Sep 17 00:00:00 2001
From: gubaidulinvadim <gubaidulinvadim@gmail.com>
Date: Wed, 19 Feb 2025 10:28:33 +0100
Subject: [PATCH] Added an option to choose number of points to be considered
 in the lattice for space-charge tune shift calculation. Renamed the function
 to be 'Gaussian' transverse space-charge.

---
 mbtrack2/instability/instabilities.py | 13 ++++++++-----
 1 file changed, 8 insertions(+), 5 deletions(-)

diff --git a/mbtrack2/instability/instabilities.py b/mbtrack2/instability/instabilities.py
index 275faa6..c67bc22 100644
--- a/mbtrack2/instability/instabilities.py
+++ b/mbtrack2/instability/instabilities.py
@@ -456,7 +456,7 @@ def rwmbi_threshold(ring, beff, rho_material, plane='x'):
     return Ith
 
 
-def transverse_space_charge_tune_shift(ring, bunch_current, **kwargs):
+def transverse_gaussian_space_charge_tune_shift(ring, bunch_current, **kwargs):
     """
     Return the (maximum) transverse space charge tune shift for a Gaussian 
     bunch in the linear approximation, see Eq.(1) of [1].
@@ -480,6 +480,9 @@ def transverse_space_charge_tune_shift(ring, bunch_current, **kwargs):
         If True, use beta fonctions along the lattice.
         If False, local values of beta fonctions are used.
         Default is ring.optics.use_local_values.
+    n_points : int, optional
+        Number of points in the lattice to be considered if use_lattice ==
+        True. Default is 1000.
     sigma_delta : float, optional
         Relative energy spread.
         Default is ring.sigma_delta.
@@ -505,15 +508,15 @@ def transverse_space_charge_tune_shift(ring, bunch_current, **kwargs):
     use_lattice = kwargs.get('use_lattice', not ring.optics.use_local_values)
     sigma_delta = kwargs.get('sigma_delta', ring.sigma_delta)
     gamma = kwargs.get('gamma', ring.gamma)
-
-    q = np.abs(ring.particle.charge)
+    n_points = kwargs.get('n_points', 1000)
+    q = ring.particle.charge
     m = ring.particle.mass
     r_0 = 1 / (4*pi*epsilon_0) * q**2 / (m * c**2)
-    N = bunch_current / ring.f0 / q
+    N = np.abs(bunch_current / ring.f0 / q)
     sigma_z = sigma_s * c
 
     if use_lattice:
-        s = np.linspace(0, ring.L, 1000)
+        s = np.linspace(0, ring.L, n_points)
         beta = ring.optics.beta(s)
         sig_x = (emit_x * beta[0] +
                  ring.optics.dispersion(s)[0]**2 * sigma_delta**2)**0.5
-- 
GitLab