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

Fix bug for cavity resonator

In track method of cavity resonator, there was an additional phasor decay of bin length.
To avoid that the good boundaries are set bins[0] instead of center[0].
For now the bins are also shared in Beam.mpi_share_distributions
parent 2e81752b
No related branches found
No related tags found
No related merge requests found
......@@ -685,6 +685,9 @@ class Beam:
bunch = self[self.mpi.bunch_num]
bins, sorted_index, profile, center = bunch.binning(n_bin=75)
self.mpi.bins_all = np.empty((len(self), len(bins)), dtype=np.float64)
self.mpi.comm.Allgather([bins, MPI.DOUBLE], [self.mpi.bins_all, MPI.DOUBLE])
self.mpi.center_all = np.empty((len(self), len(center)), dtype=np.float64)
self.mpi.comm.Allgather([center, MPI.DOUBLE], [self.mpi.center_all, MPI.DOUBLE])
......
......@@ -190,7 +190,10 @@ class CavityResonator():
self.nturn = 0
def track(self, beam, ref_frame="beam"):
"""version type mbtrack + formule analytique"""
"""version type mbtrack + formule analytique
phasor is given at t=0 synchronous particle of the bunch 0
"""
if self.tracking is False:
self.init_tracking(beam)
......@@ -201,6 +204,7 @@ class CavityResonator():
if beam.mpi_switch:
# get shared bunch profile for current bunch
bins = beam.mpi.bins_all[j]
center = beam.mpi.center_all[j]
profile = beam.mpi.profile_all[j]
bin_length = center[1]-center[0]
......@@ -218,10 +222,11 @@ class CavityResonator():
# 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)
self.phasor_decay(bins[0], ref_frame=ref_frame)
if index != self.bunch_index:
self.phasor_evol(profile, bin_length, charge_per_mp, ref_frame=ref_frame)
print('here')
else:
# modify beam phasor
for i, center0 in enumerate(center):
......@@ -241,13 +246,16 @@ class CavityResonator():
self.beam_phasor -= 2*charge_per_mp*self.loss_factor*mp_per_bin
self.phasor_decay(bin_length, ref_frame=ref_frame)
self.phasor_decay( (self.distance[index] * self.ring.T1) - center[-1], ref_frame=ref_frame)
self.phasor_decay(-1*bins[-1], ref_frame=ref_frame)
self.phasor_decay(self.distance[index] * self.ring.T1, ref_frame=ref_frame)
if index == self.bunch_index:
# apply kick
bunch["delta"] += energy_change
bunch.energy_change = energy_change
self.nturn += 1
def init_phasor(self, beam):
"""version type mbtrack + formule analytique"""
......@@ -264,6 +272,7 @@ class CavityResonator():
if beam.mpi_switch:
# get shared bunch profile for current bunch
bins = beam.mpi.bins_all[j]
center = beam.mpi.center_all[j]
profile = beam.mpi.profile_all[j]
bin_length = center[1]-center[0]
......@@ -276,9 +285,9 @@ class CavityResonator():
# 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="rf")
self.phasor_decay(bins[0], ref_frame="rf")
self.phasor_evol(profile, bin_length, charge_per_mp, ref_frame="rf")
self.phasor_decay( (self.distance[index] * self.ring.T1) - center[-1], ref_frame="rf")
self.phasor_decay( (self.distance[index] * self.ring.T1) - bins[-1], ref_frame="rf")
def phasor_decay(self, time, ref_frame="beam"):
"""
......
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