|
1 | 1 | import pytest |
| 2 | +from pytest import mark |
2 | 3 | import numpy as np |
3 | 4 |
|
4 | 5 | from pywit.landau_damping import dispersion_integral_2d, find_detuning_coeffs_threshold |
5 | 6 | from pywit.landau_damping import find_detuning_coeffs_threshold_many_tune_shifts |
6 | 7 |
|
7 | 8 |
|
8 | | -def test_dispersion_integral_2d(): |
9 | | - |
10 | | - distribution = 'gaussian' |
11 | | - tune_shift = -7.3622423693e-05-3.0188372754e-06j |
| 9 | +@mark.parametrize('distribution, expected_value', |
| 10 | + [['gaussian', 7153.859519171599 - 2722.966574677259j], |
| 11 | + ['parabolic', 6649.001778623455 - 3168.4257879737443j], |
| 12 | + ]) |
| 13 | +def test_dispersion_integral_2d(distribution: str, expected_value: complex): |
| 14 | + # reference values obtained with DELPHI |
| 15 | + tune_shift = -7.3622423693e-05 - 3.0188372754e-06j |
12 | 16 | b_direct = 7.888357197059519e-05 |
13 | 17 | b_cross = -5.632222163778799e-05 |
14 | 18 |
|
15 | | - # reference value obtained with DELPHI |
16 | | - expected_value = 7153.859519171599-2722.966574677259j |
17 | | - |
18 | | - assert np.isclose(np.real(expected_value), np.real(dispersion_integral_2d(tune_shift=tune_shift, |
19 | | - b_direct=b_direct, |
20 | | - b_cross=b_cross, |
21 | | - distribution=distribution))) |
22 | | - assert np.isclose(np.imag(expected_value), np.imag(dispersion_integral_2d(tune_shift=tune_shift, |
23 | | - b_direct=b_direct, |
24 | | - b_cross=b_cross, |
25 | | - distribution=distribution))) |
26 | | - |
27 | | - distribution = 'parabolic' |
| 19 | + test_value = dispersion_integral_2d(tune_shift=tune_shift, b_direct=b_direct, b_cross=b_cross, |
| 20 | + distribution=distribution) |
28 | 21 |
|
29 | | - # reference value obtained with DELPHI |
30 | | - expected_value = 6649.001778623455-3168.4257879737443j |
| 22 | + assert np.isclose(np.real(expected_value), np.real(test_value)) |
| 23 | + assert np.isclose(np.imag(expected_value), np.imag(test_value)) |
31 | 24 |
|
32 | | - assert np.isclose(np.real(expected_value), np.real(dispersion_integral_2d(tune_shift=tune_shift, |
33 | | - b_direct=b_direct, |
34 | | - b_cross=b_cross, |
35 | | - distribution=distribution))) |
36 | | - assert np.isclose(np.imag(expected_value), np.imag(dispersion_integral_2d(tune_shift=tune_shift, |
37 | | - b_direct=b_direct, |
38 | | - b_cross=b_cross, |
39 | | - distribution=distribution))) |
40 | 25 |
|
41 | | - |
42 | | -def test_find_detuning_coeffs_threshold(): |
| 26 | +@mark.parametrize('b_direct, b_cross, added_b_direct, added_b_cross', |
| 27 | + [[1.980315192200037e-05, -1.4139287608495406e-05, 0, 0], |
| 28 | + [-1.2718161244917965e-05, 9.08066253298482e-06, 0, 0], |
| 29 | + [1.980315192200037e-05, -1.4139287608495406e-05, 1.980315192200037e-05 / 3, |
| 30 | + -1.4139287608495406e-05 / 3], |
| 31 | + [-1.2718161244917965e-05, 9.08066253298482e-06, -1.2718161244917965e-05 / 3, |
| 32 | + 9.08066253298482e-06 / 3], |
| 33 | + ]) |
| 34 | +def test_find_detuning_coeffs_threshold(b_direct: float, b_cross: float, added_b_direct: float, added_b_cross: float): |
43 | 35 | # reference values obtained with the old impedance wake model https://gitlab.cern.ch/IRIS/HLLHC_IW_model |
44 | 36 | # test positive octupole polarity |
45 | 37 | tune_shift = -7.3622423693e-05 - 3.0188372754e-06j |
46 | 38 | q_s = 2e-3 |
47 | | - b_direct = 1.980315192200037e-05 |
48 | | - b_cross = -1.4139287608495406e-05 |
49 | | - assert np.isclose(b_direct, find_detuning_coeffs_threshold(tune_shift=tune_shift, q_s=q_s, reference_b_direct=b_direct, |
50 | | - reference_b_cross=b_cross)[0]) |
51 | | - assert np.isclose(b_cross, find_detuning_coeffs_threshold(tune_shift=tune_shift, q_s=q_s, reference_b_direct=b_direct, |
52 | | - reference_b_cross=b_cross)[1]) |
53 | | - # test negative octupole polarity |
54 | | - b_direct = -1.2718161244917965e-05 |
55 | | - b_cross = 9.08066253298482e-06 |
56 | 39 |
|
57 | | - assert np.isclose(b_direct, find_detuning_coeffs_threshold(tune_shift=tune_shift, q_s=q_s, reference_b_direct=b_direct, |
58 | | - reference_b_cross=b_cross)[0]) |
59 | | - assert np.isclose(b_cross, find_detuning_coeffs_threshold(tune_shift=tune_shift, q_s=q_s, reference_b_direct=b_direct, |
60 | | - reference_b_cross=b_cross)[1]) |
| 40 | + b_direct_test, b_cross_test = find_detuning_coeffs_threshold(tune_shift=tune_shift, q_s=q_s, |
| 41 | + reference_b_direct=b_direct, |
| 42 | + reference_b_cross=b_cross, |
| 43 | + added_b_direct=added_b_direct, |
| 44 | + added_b_cross=added_b_cross) |
| 45 | + |
| 46 | + assert np.isclose(b_direct - added_b_direct, b_direct_test) |
| 47 | + assert np.isclose(b_cross - added_b_cross, b_cross_test) |
61 | 48 |
|
62 | 49 |
|
63 | | -def test_find_detuning_coeffs_threshold_w_added_term(): |
| 50 | +@mark.parametrize('b_direct, b_cross', |
| 51 | + [[3.960630384598084e-05, -2.8278575218404585e-05], |
| 52 | + [-2.5436322491034757e-05, 1.816132506682559e-05], |
| 53 | + ]) |
| 54 | +def test_find_detuning_coeffs_threshold_many_tune_shifts(b_direct: float, b_cross: float): |
64 | 55 | # reference values obtained with the old impedance wake model https://gitlab.cern.ch/IRIS/HLLHC_IW_model |
65 | | - # test positive octupole polarity |
66 | 56 | tune_shift = -7.3622423693e-05 - 3.0188372754e-06j |
67 | 57 | q_s = 2e-3 |
68 | | - b_direct = 1.980315192200037e-05 |
69 | | - b_cross = -1.4139287608495406e-05 |
70 | | - |
71 | | - added_fraction = 1/3 |
| 58 | + tune_shifts = [np.nan, tune_shift, 2 * tune_shift] |
72 | 59 |
|
73 | | - added_b_direct = b_direct * added_fraction |
74 | | - added_b_cross = b_cross * added_fraction |
| 60 | + b_direct_test, b_cross_test = find_detuning_coeffs_threshold_many_tune_shifts(tune_shifts=tune_shifts, q_s=q_s, |
| 61 | + reference_b_direct=b_direct, |
| 62 | + reference_b_cross=b_cross) |
| 63 | + assert np.isclose(b_direct, b_direct_test) |
| 64 | + assert np.isclose(b_cross, b_cross_test) |
75 | 65 |
|
76 | | - assert np.isclose(b_direct * (1-added_fraction), find_detuning_coeffs_threshold(tune_shift=tune_shift, q_s=q_s, |
77 | | - reference_b_direct=b_direct, |
78 | | - reference_b_cross=b_cross, |
79 | | - added_b_direct=added_b_direct, |
80 | | - added_b_cross=added_b_cross)[0]) |
81 | | - assert np.isclose(b_cross * (1-added_fraction), find_detuning_coeffs_threshold(tune_shift=tune_shift, q_s=q_s, |
82 | | - reference_b_direct=b_direct, |
83 | | - reference_b_cross=b_cross, |
84 | | - added_b_direct=added_b_direct, |
85 | | - added_b_cross=added_b_cross)[1]) |
86 | | - # test negative octupole polarity |
87 | | - b_direct = -1.2718161244917965e-05 |
88 | | - b_cross = 9.08066253298482e-06 |
89 | 66 |
|
90 | | - added_b_direct = b_direct * added_fraction |
91 | | - added_b_cross = b_cross * added_fraction |
92 | | - |
93 | | - assert np.isclose(b_direct * (1-added_fraction), find_detuning_coeffs_threshold(tune_shift=tune_shift, q_s=q_s, |
94 | | - reference_b_direct=b_direct, |
95 | | - reference_b_cross=b_cross, |
96 | | - added_b_direct=added_b_direct, |
97 | | - added_b_cross=added_b_cross)[0]) |
98 | | - assert np.isclose(b_cross * (1-added_fraction), find_detuning_coeffs_threshold(tune_shift=tune_shift, q_s=q_s, |
99 | | - reference_b_direct=b_direct, |
100 | | - reference_b_cross=b_cross, |
101 | | - added_b_direct=added_b_direct, |
102 | | - added_b_cross=added_b_cross)[1]) |
103 | | - |
104 | | - |
105 | | -def test_find_detuning_coeffs_threshold_many_tune_shifts(): |
106 | | - # reference values obtained with the old impedance wake model https://gitlab.cern.ch/IRIS/HLLHC_IW_model |
107 | | - tune_shift = -7.3622423693e-05 - 3.0188372754e-06j |
108 | | - q_s = 2e-3 |
109 | | - tune_shifts = [np.nan, tune_shift, 2*tune_shift] |
110 | | - |
111 | | - # test positive octupole polarity |
112 | | - b_direct = 3.960630384598084e-05 |
113 | | - b_cross = -2.8278575218404585e-05 |
114 | | - assert np.isclose(b_direct, find_detuning_coeffs_threshold_many_tune_shifts(tune_shifts=tune_shifts, q_s=q_s, |
115 | | - reference_b_direct=b_direct, |
116 | | - reference_b_cross=b_cross)[0]) |
117 | | - assert np.isclose(b_cross, find_detuning_coeffs_threshold_many_tune_shifts(tune_shifts=tune_shifts, q_s=q_s, |
118 | | - reference_b_direct=b_direct, |
119 | | - reference_b_cross=b_cross)[1]) |
120 | | - # test negative octupole polarity |
121 | | - b_direct = -2.5436322491034757e-05 |
122 | | - b_cross = 1.816132506682559e-05 |
123 | | - assert np.isclose(b_direct, find_detuning_coeffs_threshold_many_tune_shifts(tune_shifts=tune_shifts, q_s=q_s, |
124 | | - reference_b_direct=b_direct, |
125 | | - reference_b_cross=b_cross)[0]) |
126 | | - assert np.isclose(b_cross, find_detuning_coeffs_threshold_many_tune_shifts(tune_shifts=tune_shifts, q_s=q_s, |
127 | | - reference_b_direct=b_direct, |
128 | | - reference_b_cross=b_cross)[1]) |
0 commit comments