Skip to content
Snippets Groups Projects
Commit c6d7e9f1 authored by lu.zhao@synchrotron-soleil.fr's avatar lu.zhao@synchrotron-soleil.fr
Browse files

correction rf resonator

parent d5806380
Branches
No related tags found
1 merge request!37Feature feedback iq damper0
......@@ -172,8 +172,6 @@ class CavityResonator:
Plot phasor diagram.
is_DC_Robinson_stable(I0)
Check DC Robinson stability.
is_CBI_stable(I0)
Check Coupled-Bunch-Instability stability.
plot_DC_Robinson_stability()
Plot DC Robinson stability limit.
init_tracking(beam)
......@@ -208,7 +206,8 @@ class CavityResonator:
Mbtrack." IPAC’19, Melbourne, Australia, 2019.
"""
def __init__(self,
def __init__(
self,
ring,
m,
Rs,
......@@ -218,7 +217,9 @@ class CavityResonator:
Ncav=1,
Vc=0,
theta=0,
n_bin=75):
phase_noise=None,
n_bin=75,
):
self.ring = ring
self.feedback = []
self.m = m
......@@ -232,11 +233,10 @@ class CavityResonator:
self.detune = detune
self.Vc = Vc
self.theta = theta
# =============== add: phase noise generator==================
self.phase_noise_generator = None
# =============== END ============================
self.beam_phasor = 0 + 0j
self.beam_phasor = np.zeros(1, dtype=complex)
self.beam_phasor_record = np.zeros((self.ring.h), dtype=complex)
self.generator_phasor_record = np.zeros((self.ring.h), dtype=complex)
self.tracking = False
......@@ -257,9 +257,8 @@ class CavityResonator:
"""
if beam.mpi_switch:
self.bunch_index = (
beam.mpi.bunch_num
) # Number of the tracked bunch in this processor
# Number of the tracked bunch in this processor
self.bunch_index = beam.mpi.bunch_num
self.distance = beam.distance_between_bunches
self.valid_bunch_index = beam.bunch_index
......@@ -284,7 +283,13 @@ class CavityResonator:
if self.tracking is False:
self.init_tracking(beam)
# =============== add:before every turn, add phase noise to generator
if self.phase_noise_generator is not None:
# get a noise from phase noise generator(unit:rad),add it to
# theta_g
noise = self.phase_noise_generator.generate_noise(size=1)
self.theta_g += noise
# =============== END =============================
for index, bunch in enumerate(beam):
if beam.filling_pattern[index]:
......@@ -295,16 +300,16 @@ class CavityResonator:
# mpi -> get shared bunch profile for current bunch
center = beam.mpi.tau_center[rank]
profile = beam.mpi.tau_profile[rank]
bin_length = float(beam.mpi.tau_bin_length[rank][0])
charge_per_mp = float(beam.mpi.charge_per_mp_all[rank])
bin_length = center[1] - center[0]
charge_per_mp = beam.mpi.charge_per_mp_all[rank]
if index == self.bunch_index:
sorted_index = beam.mpi.tau_sorted_index
else:
# no mpi -> get bunch profile for current bunch
if not bunch.is_empty:
if len(bunch) != 0:
(bins, sorted_index, profile,
center) = bunch.binning(n_bin=self.n_bin)
bin_length = bins[1] - bins[0]
bin_length = center[1] - center[0]
charge_per_mp = bunch.charge_per_mp
self.bunch_index = index
else:
......@@ -331,7 +336,7 @@ class CavityResonator:
else:
# modify beam phasor
for i, center0 in enumerate(center):
mp_per_bin = int(profile[i])
mp_per_bin = profile[i]
if mp_per_bin == 0:
self.phasor_decay(bin_length, ref_frame="beam")
......@@ -397,11 +402,10 @@ class CavityResonator:
if beam.mpi_switch:
# get shared bunch profile for current bunch
beam.mpi.share_distributions(beam, n_bin=self.n_bin)
center = beam.mpi.tau_center[j]
profile = beam.mpi.tau_profile[j]
bin_length = float(beam.mpi.tau_bin_length[j][0])
charge_per_mp = float(beam.mpi.charge_per_mp_all[j])
bin_length = center[1] - center[0]
charge_per_mp = beam.mpi.charge_per_mp_all[j]
else:
if i == 0:
# get bunch profile for current bunch
......@@ -422,7 +426,7 @@ class CavityResonator:
profile = self.profile_save[j, :]
center = self.center_save[j, :]
bin_length = bins[1] - bins[0]
bin_length = center[1] - center[0]
charge_per_mp = bunch.charge_per_mp
self.phasor_decay(center[0] - bin_length/2, ref_frame="rf")
......@@ -522,14 +526,13 @@ class CavityResonator:
if self.tracking is False:
self.init_tracking(beam)
N = self.n_bin
N = self.n_bin - 1
delta = self.wr - self.m * self.ring.omega1
n_turn = int(self.filling_time / self.ring.T0 * 10)
T = np.ones(self.ring.h) * self.ring.T1
bin_length = np.zeros(self.ring.h)
charge_per_mp = np.zeros(self.ring.h)
bins = np.zeros((N + 1, self.ring.h))
profile = np.zeros((N, self.ring.h))
center = np.zeros((N, self.ring.h))
......@@ -540,12 +543,12 @@ class CavityResonator:
beam.mpi.share_distributions(beam, n_bin=self.n_bin)
center[:, index] = beam.mpi.tau_center[j]
profile[:, index] = beam.mpi.tau_profile[j]
bin_length[index] = float(beam.mpi.tau_bin_length[j][0])
charge_per_mp[index] = float(beam.mpi.charge_per_mp_all[j])
bin_length[index] = center[1, index] - center[0, index]
charge_per_mp[index] = beam.mpi.charge_per_mp_all[j]
else:
(bins[:, index], sorted_index, profile[:, index],
(bins, sorted_index, profile[:, index],
center[:, index]) = (bunch.binning(n_bin=self.n_bin))
bin_length[index] = bins[1, index] - bins[0, index]
bin_length[index] = center[1, index] - center[0, index]
charge_per_mp[index] = bunch.charge_per_mp
T[index] -= center[-1, index] + bin_length[index] / 2
if index != 0:
......@@ -977,7 +980,7 @@ class CavityResonator:
modes=None,
bool_return=False):
"""
Check Coupled-Bunch-Instability stability.
Check Coupled-Bunch-Instability stability,
Effect of Direct RF feedback is not included.
This method is a wraper around lcbi_growth_rate to caluclate the CBI
......@@ -1031,9 +1034,9 @@ class CavityResonator:
if bool_return:
if growth_rate > 1 / self.ring.tau[2]:
return False
else:
return True
else:
return False
else:
return growth_rate, mu
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment