diff --git a/tracking/particles.py b/tracking/particles.py index 68e29141ac97bdeabf1304c9a61398e945603b7e..451ee4e1cf0c04586ac95f39ba9be1da2c078c93 100644 --- a/tracking/particles.py +++ b/tracking/particles.py @@ -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]) diff --git a/tracking/rf.py b/tracking/rf.py index 8f7998d7eabab0775f5d8dcdf0bfb788f651665f..a12098a23c78379a194fc5d48a99998e12e3332f 100644 --- a/tracking/rf.py +++ b/tracking/rf.py @@ -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"): """