Skip to content
Snippets Groups Projects
Commit 484a22ad authored by Alexis GAMELIN's avatar Alexis GAMELIN
Browse files

Fix Ncav bug

FB parameters to fix in future!
parent 26351e54
No related branches found
No related tags found
1 merge request!13v0.7.0
...@@ -1142,37 +1142,46 @@ class CavityResonator(): ...@@ -1142,37 +1142,46 @@ class CavityResonator():
return pos, voltage_rec return pos, voltage_rec
def to_pycolleff(self): def to_pycolleff(self, Impedance=True):
from pycolleff.longitudinal_equilibrium import ImpedanceSource from pycolleff.longitudinal_equilibrium import ImpedanceSource
cav = ImpedanceSource() cav = ImpedanceSource()
cav.harm_rf = self.m cav.harm_rf = self.m
cav.Q = self.QL cav.Q = self.QL
RoverQ = self.RL/self.QL RoverQ = self.RL/self.QL
cav.shunt_impedance = self.Ncav * RoverQ * cav.Q cav.shunt_impedance = RoverQ * cav.Q
cav.ang_freq_rf = self.ring.omega1 cav.ang_freq_rf = self.ring.omega1
cav.ang_freq = cav.harm_rf * cav.ang_freq_rf cav.ang_freq = cav.harm_rf * cav.ang_freq_rf
cav.detune_w = 2 * np.pi * self.detune cav.detune_w = 2 * np.pi * self.detune
cav.calc_method = ImpedanceSource.Methods.ImpedanceDFT
if self.Vg != 0: if self.Vg != 0:
cav.active_passive = ImpedanceSource.ActivePassive.Active cav.active_passive = ImpedanceSource.ActivePassive.Active
# Define PID transfer function for control loop if Impedance:
def pid_transfer_func(w, wrf, gain=1, kp=1, ki=1, kd=0, delay=0): cav.calc_method = ImpedanceSource.Methods.ImpedanceDFT
# If you do not want to worry about the details of the voltage gap # Define PID transfer function for control loop
# control system, you can use SIRIUS parameters in this function. def pid_transfer_func(w, wrf, gain=1, kp=1, ki=1, kd=0, delay=0):
phase = wrf * delay phase = wrf * delay
exp_delay = np.exp(-1j * delay * w) exp_delay = np.exp(-1j * delay * w)
exp_phase = np.exp(1j * phase) exp_phase = np.exp(1j * phase)
eps = 1e-16 eps = 1e-16
pid_ctrl = kp + ki / 1j / (w - wrf + eps) + kd * 1j * (w - wrf) pid_ctrl = kp + ki / 1j / (w - wrf + eps) + kd * 1j * (w - wrf)
transfer = gain * pid_ctrl * exp_delay * exp_phase transfer = gain * pid_ctrl * exp_delay * exp_phase
return transfer return transfer
cav.loop_ctrl_ang_freq = self.ring.omega1 delay = 1.9e-6
cav.loop_ctrl_transfer = partial(pid_transfer_func, kp=1, ki=1, delay=0) ki = 0.01
kp = 2.96e-6
kd = 0
cav.loop_ctrl_ang_freq = self.ring.omega1
cav.loop_ctrl_transfer = partial(pid_transfer_func, kp=kp, ki=ki, delay=delay)
# cav.loop_ctrl_transfer = partial(pid_transfer_func, kp=0, ki=1, delay=0)
else:
cav.calc_method = ImpedanceSource.Methods.Wake
else: else:
cav.active_passive = ImpedanceSource.ActivePassive.Passive cav.active_passive = ImpedanceSource.ActivePassive.Passive
if Impedance:
cav.calc_method = ImpedanceSource.Methods.ImpedanceDFT
else:
cav.calc_method = ImpedanceSource.Methods.Wake
return cav return cav
......
...@@ -585,7 +585,7 @@ class Synchrotron: ...@@ -585,7 +585,7 @@ class Synchrotron:
TimeLag=TimeLag) TimeLag=TimeLag)
return at_simple_ring return at_simple_ring
def to_pycolleff(self, I0, Vrf, bunch_number): def to_pycolleff(self, I0, Vrf, bunch_number, delta=0):
from pycolleff.colleff import Ring from pycolleff.colleff import Ring
ring = Ring() ring = Ring()
...@@ -607,8 +607,9 @@ class Synchrotron: ...@@ -607,8 +607,9 @@ class Synchrotron:
ring.damptx = self.tau[0] # [s] ring.damptx = self.tau[0] # [s]
ring.dampty = self.tau[1] # [s] ring.dampty = self.tau[1] # [s]
ring.dampte = self.tau[2] # [s] ring.dampte = self.tau[2] # [s]
ring.en_lost_rad = self.U0 # [eV] ring.en_lost_rad = self.U0 # [eV]
ring.gap_voltage = Vrf # [V] ring.gap_voltage = Vrf # [V]
ring.delta_HC = delta
return ring return ring
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