Skip to content
Snippets Groups Projects
Commit 2e81752b authored by Gamelin Alexis's avatar Gamelin Alexis
Browse files

Allow for CavityResonator tracking without mpi

Add single core tracking for CavityResonator
Correct missing ref_frame is CavityResonator.track
Change phase of generator voltage to be the bin phase
Correct generator phase for non integer m
Change init_phasor track time to 10 times
Change phasor_evolution k to change order of steps
parent 665273f5
No related branches found
No related tags found
No related merge requests found
......@@ -181,12 +181,13 @@ class CavityResonator():
"""
# Number of the tracked bunch in this processor
self.bunch_index = beam.mpi.bunch_num
if beam.mpi_switch:
self.bunch_index = beam.mpi.bunch_num # Number of the tracked bunch in this processor
self.distance = beam.distance_between_bunches
self.valid_bunch_index = np.where(beam.filling_pattern == True)[0]
self.tracking = True
self.nturn = 0
def track(self, beam, ref_frame="beam"):
"""version type mbtrack + formule analytique"""
......@@ -198,33 +199,41 @@ class CavityResonator():
index = self.valid_bunch_index[j]
# get shared bunch profile for current bunch
center = beam.mpi.center_all[j]
profile = beam.mpi.profile_all[j]
bin_length = center[1]-center[0]
charge_per_mp = beam.mpi.charge_per_mp_all[j]
if beam.mpi_switch:
# get shared bunch profile for current bunch
center = beam.mpi.center_all[j]
profile = beam.mpi.profile_all[j]
bin_length = center[1]-center[0]
charge_per_mp = beam.mpi.charge_per_mp_all[j]
if index == self.bunch_index:
sorted_index = beam.mpi.sorted_index
else:
# get bunch profile for current bunch
(bins, sorted_index, profile, center) = bunch.binning()
bin_length = center[1]-center[0]
charge_per_mp = bunch.charge_per_mp
self.bunch_index = index
if index == self.bunch_index:
sorted_index = beam.mpi.sorted_index
energy_change = bunch["tau"]*0
energy_change = bunch["tau"]*0
# phasor is given at t=0 synchronous particle of the bunch
# remove part of beam phasor decay to be at the start of the binning
self.phasor_decay(center[0], ref_frame=ref_frame)
if index != self.bunch_index:
self.phasor_evol(profile, bin_length, charge_per_mp)
self.phasor_evol(profile, bin_length, charge_per_mp, ref_frame=ref_frame)
else:
# modify beam phasor
for i, center0 in enumerate(center):
mp_per_bin = profile[i]
if mp_per_bin == 0:
self.phasor_decay(bin_length)
self.phasor_decay(bin_length, ref_frame=ref_frame)
continue
ind = (sorted_index == i)
Vgene = self.Vg*np.cos(self.m*self.ring.omega1*bunch["tau"][ind] + self.theta_g)
phase = self.m * self.ring.omega1 * (center0 + self.ring.T1* (j + self.ring.h * self.nturn))
Vgene = self.Vg*np.cos(phase + self.theta_g)
Vbeam = np.real(self.beam_phasor)
Vtot = Vgene + Vbeam - charge_per_mp*self.loss_factor*mp_per_bin
energy_change[ind] = Vtot / self.ring.E0
......@@ -246,18 +255,24 @@ class CavityResonator():
if self.tracking is False:
self.init_tracking(beam)
n_turn = int(self.filling_time/self.ring.T0*5)
n_turn = int(self.filling_time/self.ring.T0*10)
for i in range(n_turn):
for j, bunch in enumerate(beam.not_empty):
index = self.valid_bunch_index[j]
# get shared bunch profile for current bunch
center = beam.mpi.center_all[j]
profile = beam.mpi.profile_all[j]
bin_length = center[1]-center[0]
charge_per_mp = beam.mpi.charge_per_mp_all[j]
if beam.mpi_switch:
# get shared bunch profile for current bunch
center = beam.mpi.center_all[j]
profile = beam.mpi.profile_all[j]
bin_length = center[1]-center[0]
charge_per_mp = beam.mpi.charge_per_mp_all[j]
else:
# get bunch profile for current bunch
(bins, sorted_index, profile, center) = bunch.binning()
bin_length = center[1]-center[0]
charge_per_mp = bunch.charge_per_mp
# phasor is given at t=0 synchronous particle of the bunch
# remove part of beam phasor decay to be at the start of the binning
......@@ -308,7 +323,7 @@ class CavityResonator():
self.phasor_decay(deltaT, ref_frame)
# Phasor evolution due to induced voltage by marco-particles
k = np.arange(1, n_bin + 1)
k = np.arange(0, n_bin)
var = np.exp( (-1/self.filling_time + 1j*delta) *
(n_bin-k) * deltaT )
sum_tot = np.sum(profile * var)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment