LLRFLibsPy库中opt_QL_detuning函数解读

opt_QL_detuning 函数用于计算在给定腔体电压、束流电流和束流相位下,优化的加载 Q 因子、失谐和输入耦合系数。这些优化参数用于最大化腔体的性能,特别是在超导(SC)和常规(NC)腔体中。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
def opt_QL_detuning(f0, vc0, ib0, phib, Q0, roQ_or_RoQ, 
machine = 'linac',
cav_type = 'sc'):
'''
Derive the optimal loaded Q and detuning.

Refer to LLRF Book section 3.3.9.

Parameters:
f0: float, RF operating frequency, Hz
vc0: float, desired cavity voltage, V
ib0: float, desired average beam current, A
phib: float, desired beam phase, degree
Q0: float, unloaded quality factor (for SC cavity,
give it a very high value like 1e10)
roQ_or_RoQ: float, cavity r/Q of Linac or R/Q of circular accelerator, Ohm
(see the note below)
machine: string, ``linac`` or ``circular``, used to select r/Q or R/Q
cav_type: string, ``sc`` for superconducting or ``nc`` for normal conducting

Returns:
status: boolean, success (True) or fail (False)
QL_opt: float, optimal loaded quality factor
dw_opt: float, optimal detuning, rad/s
beta_opt: float, optimal input coupling factor

Note:
Linacs define the ``r/Q = Vacc**2 / (w0 * U)`` while circular machines
define ``R/Q = Vacc**2 / (2 * w0 * U)``, where ``Vacc`` is the accelerating
voltage, ``w0`` is the angular cavity resonance frequency and ``U`` is the
cavity energy storage. Therefore, to use this function, one needs to
specify the ``machine`` to be ``linac`` or ``circular``. Generally, we have
``R/Q = 1/2 * r/Q``.
'''
# check the input
if (f0 <= 0.0) or (vc0 < 0.0) or (ib0 < 0.0) or (Q0 <= 0.0) or \
(roQ_or_RoQ <= 0.0):
return False, None, None

# some parameters
if machine == 'circular': shunt_imp = roQ_or_RoQ * 2.0
else: shunt_imp = roQ_or_RoQ
phib_rad = phib * np.pi / 180.0 # beam phase in radian

# calculate the optimal values
dw_opt = -np.pi * f0 * shunt_imp * ib0 * np.sin(phib_rad) / vc0

if cav_type == 'sc':
QL_opt = vc0 /(shunt_imp * ib0 * np.cos(phib_rad))
beta_opt = Q0 / QL_opt - 1.0
else:
beta_opt = shunt_imp * Q0 * ib0 * np.cos(phib_rad) / vc0 + 1.0
QL_opt = Q0 / (beta_opt + 1.0)

# return the results
return True, QL_opt, dw_opt, beta_opt

函数参数

  • f0 (float):RF 工作频率,单位 Hz。
  • vc0 (float):期望的腔体电压,单位 V。
  • ib0 (float):期望的平均束流电流,单位 A。
  • phib (float):期望的束流相位,单位度。
  • Q0 (float):未加载品质因数(对于超导腔,给一个非常高的值,如 1e10)。
  • roQ_or_RoQ (float):Linac 的 r/Q 或者圆形加速器的 R/Q,单位欧姆(具体见注释)。
  • machine (string):linaccircular,用于选择 r/Q 或 R/Q。
  • cav_type (string):sc 表示超导,nc 表示常规导体。

函数返回值

  • status (boolean):成功(True)或失败(False)。
  • QL_opt (float):优化的加载品质因数。
  • dw_opt (float):优化的失谐,单位弧度每秒。
  • beta_opt (float):优化的输入耦合系数。

代码解释

  1. 输入检查

    • 检查 f0vc0ib0Q0roQ_or_RoQ 是否为正值。如果任何一个条件不满足,返回 FalseNoneNone
    1
    2
    3
    if (f0 <= 0.0) or (vc0 < 0.0) or (ib0 < 0.0) or (Q0 <= 0.0) or \
    (roQ_or_RoQ <= 0.0):
    return False, None, None
  2. 计算一些必要参数

    • 根据 machine 类型计算分流阻抗 shunt_imp。对于 circular 类型,shunt_imp = roQ_or_RoQ * 2.0,对于 linac 类型,shunt_imp = roQ_or_RoQ
    • 将束流相位从度转换为弧度 phib_rad = phib * np.pi / 180.0
    1
    2
    3
    4
    5
    if machine == 'circular': 
    shunt_imp = roQ_or_RoQ * 2.0
    else:
    shunt_imp = roQ_or_RoQ
    phib_rad = phib * np.pi / 180.0 # beam phase in radian
  3. 计算优化值

    • 计算优化的失谐 dw_opt
      $$
      dw_{opt} = -\frac{\pi \cdot f0 \cdot shunt_{imp} \cdot i_{b0} \cdot \sin(phib_{rad})}{v_{c0}}
      $$
    1
    dw_opt = -np.pi * f0 * shunt_imp * ib0 * np.sin(phib_rad) / vc0
    • 对于超导腔体 (cav_type == 'sc'):

      • 计算优化的加载 Q 因子 QL_opt
        $$
        QL_{opt} = \frac{v_{c0}}{shunt_{imp} \cdot i_{b0} \cdot \cos(phib_{rad})}
        $$
      1
      2
      3
      if cav_type == 'sc':
      QL_opt = vc0 / (shunt_imp * ib0 * np.cos(phib_rad))
      beta_opt = Q0 / QL_opt - 1.0
    • 对于常规腔体 (cav_type == 'nc'):

      • 计算优化的输入耦合系数 beta_opt
        $$
        beta_{opt} = \frac{shunt_{imp} \cdot Q0 \cdot i_{b0} \cdot \cos(phib_rad)}{v_{c0}} + 1.0
        $$
      • 计算优化的加载 Q 因子 QL_opt
        $$
        QL_{opt} = \frac{Q0}{beta_{opt} + 1.0}
        $$
      1
      2
      3
      else:
      beta_opt = shunt_imp * Q0 * ib0 * np.cos(phib_rad) / vc0 + 1.0
      QL_opt = Q0 / (beta_opt + 1.0)
  4. 返回结果

    • 返回 True、优化的加载品质因数 QL_opt、优化的失谐 dw_opt 和优化的输入耦合系数 beta_opt
    1
    return True, QL_opt, dw_opt, beta_opt

示例代码

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
# 设置参数
f0 = 1.3e9 # RF 工作频率,Hz
vc0 = 1.5e6 # 期望的腔体电压,V
ib0 = 0.01 # 期望的平均束流电流,A
phib = 30 # 期望的束流相位,度
Q0 = 1e10 # 未加载品质因数
roQ_or_RoQ = 1036 # r/Q 或 R/Q,Ohm
machine = 'linac' # 机器类型
cav_type = 'sc' # 腔体类型

# 计算优化的加载 Q 因子、失谐和输入耦合系数
status, QL_opt, dw_opt, beta_opt = opt_QL_detuning(f0, vc0, ib0, phib, Q0, roQ_or_RoQ,
machine=machine, cav_type=cav_type)

if status:
print("优化的加载品质因数 QL_opt:", QL_opt)
print("优化的失谐 dw_opt:", dw_opt)
print("优化的输入耦合系数 beta_opt:", beta_opt)
else:
print("计算失败")

result:

1
2
3
优化的加载品质因数 QL_opt: 167186.37138695727
优化的失谐 dw_opt: -14103.656619515776
优化的输入耦合系数 beta_opt: 59812.48788804523

在这个示例中,计算了特定参数下的优化加载品质因数、失谐和输入耦合系数。