From 34cdf30a21b544482adef7991835061ad4a51dab Mon Sep 17 00:00:00 2001 From: Alexis Gamelin <alexis.gamelin@synchrotron-soleil.fr> Date: Wed, 28 Feb 2024 09:57:27 +0100 Subject: [PATCH] Small change for CavityResonator Add form factor option to set_optimal_detune. Fix priniting in BeamLoadingEquilibrium. --- .gitignore | 1 + mbtrack2/tracking/rf.py | 4 ++-- mbtrack2/utilities/beamloading.py | 35 ++++++++++++++++++------------- 3 files changed, 23 insertions(+), 17 deletions(-) diff --git a/.gitignore b/.gitignore index 2ec607f..1004a58 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,4 @@ *.ipynb_checkpoints* test_*.py *.hdf5 +*.pyc diff --git a/mbtrack2/tracking/rf.py b/mbtrack2/tracking/rf.py index fedc7ab..6e731c5 100644 --- a/mbtrack2/tracking/rf.py +++ b/mbtrack2/tracking/rf.py @@ -803,7 +803,7 @@ class CavityResonator(): """Cavity impedance in [Ohm] for a given frequency f in [Hz]""" return self.RL / (1 + 1j * self.QL * (self.fr / f - f / self.fr)) - def set_optimal_detune(self, I0): + def set_optimal_detune(self, I0, F=1): """ Set detuning to optimal conditions - second Eq. (4.2.1) in [1]. @@ -813,7 +813,7 @@ class CavityResonator(): Beam current in [A]. """ - self.psi = np.arctan(-self.Vbr(I0) / self.Vc * np.sin(self.theta)) + self.psi = np.arctan(-self.Vbr(I0) * F / self.Vc * np.sin(self.theta)) def set_optimal_coupling(self, I0): """ diff --git a/mbtrack2/utilities/beamloading.py b/mbtrack2/utilities/beamloading.py index 1d208c2..caecc15 100644 --- a/mbtrack2/utilities/beamloading.py +++ b/mbtrack2/utilities/beamloading.py @@ -270,7 +270,8 @@ class BeamLoadingEquilibrium(): method='hybr', options=None, plot=False, - CM=True): + CM=True, + verbiose=False): """Solve system of non-linear equation to find the form factors F and PHI at equilibrum. Can be used to compute the equilibrium bunch profile. @@ -284,6 +285,7 @@ class BeamLoadingEquilibrium(): plot : if True, plot the equilibrium bunch profile CM : if True, the system imposes zero center of mass offset, if False, the system imposes energy balance. + verbiose : if True, print out informations about convergence. Returns ------- @@ -294,12 +296,13 @@ class BeamLoadingEquilibrium(): if self.auto_set_MC_theta: x0 = x0 + [self.cavity_list[0].theta] - if CM: - print("The initial center of mass offset is " + - str(self.center_of_mass() * 1e12) + " ps") - else: - print("The initial energy balance is " + - str(self.energy_balance()) + " eV") + if verbiose: + if CM: + print("The initial center of mass offset is " + + str(self.center_of_mass() * 1e12) + " ps") + else: + print("The initial energy balance is " + + str(self.energy_balance()) + " eV") sol = root(lambda x: self.to_solve(x, CM), x0, @@ -318,13 +321,15 @@ class BeamLoadingEquilibrium(): self.F = sol.x[::2] self.PHI = sol.x[1::2] - if CM: - print("The final center of mass offset is " + - str(self.center_of_mass() * 1e12) + " ps") - else: - print("The final energy balance is " + str(self.energy_balance()) + - " eV") - print("The algorithm has converged: " + str(sol.success)) + if verbiose: + if CM: + print("The final center of mass offset is " + + str(self.center_of_mass() * 1e12) + " ps") + else: + print("The final energy balance is " + str(self.energy_balance()) + + " eV") + if not sol.success: + print("The algorithm has converged: " + str(sol.success)) if plot: self.plot_rho(self.B1 / 4, self.B2 / 4) @@ -351,7 +356,7 @@ class BeamLoadingEquilibrium(): The default is None. If None, uniform filling is assumed. MC_index : int, optional Index of the main cavity in cavity_list. The default is 0. - HC_index : TYPE, optional + HC_index : int, optional Index of the harmonic cavity in cavity_list. The default is 1. Returns -- GitLab