Skip to content

Commit c7839be

Browse files
committed
In Resonator class: remove arguments (R_shunt, frequency, Q) from _function_transverse
and _function_longitudinal. These parameters can be accessed directly using self. ..., to make the code cleaner.
1 parent d7d5b86 commit c7839be

File tree

1 file changed

+29
-34
lines changed

1 file changed

+29
-34
lines changed

impedances/wakes.py

Lines changed: 29 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -322,78 +322,73 @@ def get_wake_kicks(self, slicer_mode):
322322

323323
# Dipole wake kick x.
324324
if self.Yokoya_X1:
325-
wake_function = self._function_transverse(
326-
self.R_shunt, self.frequency, self.Q, self.Yokoya_X1)
325+
wake_function = self._function_transverse(self.Yokoya_X1)
327326
wake_kicks.append(DipoleWakeKickX(wake_function, slicer_mode))
328327

329328
# Quadrupole wake kick x.
330329
if self.Yokoya_X2:
331-
wake_function = self._function_transverse(
332-
self.R_shunt, self.frequency, self.Q, self.Yokoya_X2)
330+
wake_function = self._function_transverse(self.Yokoya_X2)
333331
wake_kicks.append(QuadrupoleWakeKickX(wake_function, slicer_mode))
334332

335333
# Dipole wake kick y.
336334
if self.Yokoya_Y1:
337-
wake_function = self._function_transverse(
338-
self.R_shunt, self.frequency, self.Q, self.Yokoya_Y1)
335+
wake_function = self._function_transverse(self.Yokoya_Y1)
339336
wake_kicks.append(DipoleWakeKickY(wake_function, slicer_mode))
340337

341338
# Quadrupole wake kick y.
342339
if self.Yokoya_Y2:
343-
wake_function = self._function_transverse(
344-
self.R_shunt, self.frequency, self.Q, self.Yokoya_Y2)
340+
wake_function = self._function_transverse(self.Yokoya_Y2)
345341
wake_kicks.append(QuadrupoleWakeKickY(wake_function, slicer_mode))
346342

347343
# Constant wake kick z.
348344
if self.switch_Z:
349-
wake_function = self._function_longitudinal(
350-
self.R_shunt, self.frequency, self.Q, 1)
345+
wake_function = self._function_longitudinal(1)
351346
wake_kicks.append(ConstantWakeKickZ(wake_function, slicer_mode))
352347

353348
return wake_kicks
354349

355-
def _function_transverse(self, R_shunt, frequency, Q, Yokoya_factor):
350+
def _function_transverse(self, Yokoya_factor):
356351
""" Define the wake function (transverse) of a resonator with
357352
the given parameters according to Alex Chao's resonator model
358353
(Eq. 2.82) and definitions of the resonator in HEADTAIL. """
359-
omega = 2 * np.pi * frequency
360-
alpha = omega / (2 * Q)
354+
omega = 2 * np.pi * self.frequency
355+
alpha = omega / (2 * self.Q)
361356
omegabar = np.sqrt(np.abs(omega**2 - alpha**2))
362357

363358
def wake(beta, dz):
364359
dt = dz.clip(max=0) / (beta * c)
365-
if Q > 0.5:
366-
y = (Yokoya_factor * R_shunt * omega**2 / (Q*omegabar) *
367-
np.exp(alpha*dt) * sin(omegabar*dt))
368-
elif Q == 0.5:
369-
y = (Yokoya_factor * R_shunt * omega**2 / Q *
360+
if self.Q > 0.5:
361+
y = (Yokoya_factor * self.R_shunt * omega**2 / (self.Q *
362+
omegabar) * np.exp(alpha*dt) * sin(omegabar*dt))
363+
elif self.Q == 0.5:
364+
y = (Yokoya_factor * self.R_shunt * omega**2 / self.Q *
370365
np.exp(alpha*dt) * dt)
371366
else:
372-
y = (Yokoya_factor * R_shunt * omega**2 / (Q*omegabar) *
373-
np.exp(alpha*dt) * np.sinh(omegabar*dt))
367+
y = (Yokoya_factor * self.R_shunt * omega**2 / (self.Q *
368+
omegabar) * np.exp(alpha*dt) * np.sinh(omegabar*dt))
374369
return y
375370
return wake
376371

377-
def _function_longitudinal(self, R_shunt, frequency, Q, Yokoya_factor):
372+
def _function_longitudinal(self, Yokoya_factor):
378373
""" Define the wake function (longitudinal) of a resonator with
379374
the given parameters according to Alex Chao's resonator model
380375
(Eq. 2.82) and definitions of the resonator in HEADTAIL. """
381-
omega = 2 * np.pi * frequency
382-
alpha = omega / (2 * Q)
383-
omegabar = np.sqrt(np.abs(omega ** 2 - alpha ** 2))
376+
omega = 2 * np.pi * self.frequency
377+
alpha = omega / (2 * self.Q)
378+
omegabar = np.sqrt(np.abs(omega**2 - alpha**2))
384379

385380
def wake(beta, dz):
386381
dt = dz.clip(max=0) / (beta * c)
387-
if Q > 0.5:
388-
y = (-Yokoya_factor * (np.sign(dz) - 1) * R_shunt * alpha *
389-
np.exp(alpha * dt) * (cos(omegabar * dt) +
390-
alpha / omegabar * sin(omegabar*dt)))
391-
elif Q == 0.5:
392-
y = (-Yokoya_factor * (np.sign(dz) - 1) * R_shunt * alpha *
393-
np.exp(alpha * dt) * (1. + alpha * dt))
394-
elif Q < 0.5:
395-
y = (-Yokoya_factor * (np.sign(dz) - 1) * R_shunt * alpha *
396-
np.exp(alpha * dt) * (np.cosh(omegabar * dt) +
382+
if self.Q > 0.5:
383+
y = (-Yokoya_factor * (np.sign(dz) - 1) * self.R_shunt *
384+
alpha * np.exp(alpha * dt) * (cos(omegabar * dt) +
385+
alpha / omegabar * sin(omegabar*dt)))
386+
elif self.Q == 0.5:
387+
y = (-Yokoya_factor * (np.sign(dz) - 1) * self.R_shunt *
388+
alpha * np.exp(alpha * dt) * (1. + alpha * dt))
389+
elif self.Q < 0.5:
390+
y = (-Yokoya_factor * (np.sign(dz) - 1) * self.R_shunt *
391+
alpha * np.exp(alpha * dt) * (np.cosh(omegabar * dt) +
397392
alpha / omegabar * np.sinh(omegabar * dt)))
398393
return y
399394
return wake

0 commit comments

Comments
 (0)