|
| 1 | +from PyHEADTAIL.machines.synchrotron import BasicSynchrotron |
| 2 | +import numpy as np |
| 3 | +from scipy.constants import c, e, m_p |
| 4 | + |
| 5 | +class SPS(BasicSynchrotron): |
| 6 | + |
| 7 | + def __init__(self, machine_configuration=None, optics_mode='smooth', **kwargs): |
| 8 | + |
| 9 | + |
| 10 | + longitudinal_mode = 'linear' |
| 11 | + h_RF = 4620 |
| 12 | + mass = m_p |
| 13 | + charge = e |
| 14 | + |
| 15 | + if machine_configuration=='Q26-injection': |
| 16 | + p0 = 26e9 * e /c |
| 17 | + p_increment = 0. |
| 18 | + accQ_x = 26.13 |
| 19 | + accQ_y = 26.18 |
| 20 | + V_RF = 2e6 |
| 21 | + dphi_RF = 0. |
| 22 | + alpha = 0.00192 |
| 23 | + beta_x = 42. |
| 24 | + D_x = 0 |
| 25 | + beta_y = 42. |
| 26 | + D_y = 0 |
| 27 | + elif machine_configuration=='Q20-injection': |
| 28 | + p0 = 26e9 * e /c |
| 29 | + p_increment = 0. |
| 30 | + accQ_x = 20.13 |
| 31 | + accQ_y = 20.18 |
| 32 | + V_RF = 5.75e6 |
| 33 | + dphi_RF = 0. |
| 34 | + alpha = 0.00308642 |
| 35 | + beta_x = 54.6 |
| 36 | + D_x = 0 |
| 37 | + beta_y = 54.6 |
| 38 | + D_y = 0 |
| 39 | + else: |
| 40 | + raise ValueError('machine_configuration not recognized!') |
| 41 | + |
| 42 | + |
| 43 | + |
| 44 | + if optics_mode=='smooth': |
| 45 | + if 's' in kwargs.keys(): raise ValueError('s vector cannot be provided if optics_mode = "smooth"') |
| 46 | + |
| 47 | + n_segments = kwargs['n_segments'] |
| 48 | + circumference = 1100*2*np.pi |
| 49 | + |
| 50 | + name = None |
| 51 | + |
| 52 | + |
| 53 | + |
| 54 | + alpha_x = None |
| 55 | + alpha_y = None |
| 56 | + |
| 57 | + s = None |
| 58 | + |
| 59 | + elif optics_mode=='non-smooth': |
| 60 | + if 'n_segments' in kwargs.keys(): raise ValueError('n_segments cannot be provided if optics_mode = "non-smooth"') |
| 61 | + n_segments = None |
| 62 | + circumference = None |
| 63 | + |
| 64 | + name = kwargs['name'] |
| 65 | + |
| 66 | + beta_x = kwargs['beta_x'] |
| 67 | + beta_y = kwargs['beta_y'] |
| 68 | + |
| 69 | + try: |
| 70 | + D_x = kwargs['D_x'] |
| 71 | + except KeyError: |
| 72 | + D_x = 0*np.array(kwargs['s']) |
| 73 | + try: |
| 74 | + D_y = kwargs['D_y'] |
| 75 | + except KeyError: |
| 76 | + D_y = 0*np.array(kwargs['s']) |
| 77 | + |
| 78 | + alpha_x = kwargs['alpha_x'] |
| 79 | + alpha_y = kwargs['alpha_y'] |
| 80 | + |
| 81 | + s = kwargs['s'] |
| 82 | + |
| 83 | + else: |
| 84 | + raise ValueError('optics_mode not recognized!') |
| 85 | + |
| 86 | + |
| 87 | + # detunings |
| 88 | + Qp_x = 0 |
| 89 | + Qp_y = 0 |
| 90 | + |
| 91 | + app_x = 0 |
| 92 | + app_y = 0 |
| 93 | + app_xy = 0 |
| 94 | + |
| 95 | + i_octupole_focusing = None |
| 96 | + i_octupole_defocusing = None |
| 97 | + octupole_knob = None |
| 98 | + |
| 99 | + for attr in kwargs.keys(): |
| 100 | + if kwargs[attr] is not None: |
| 101 | + if type(kwargs[attr]) is list or type(kwargs[attr]) is np.ndarray: |
| 102 | + str2print = '[%s ...]'%repr(kwargs[attr][0]) |
| 103 | + else: |
| 104 | + str2print = repr(kwargs[attr]) |
| 105 | + self.prints('Synchrotron init. From kwargs: %s = %s' |
| 106 | + % (attr, str2print)) |
| 107 | + temp = kwargs[attr] |
| 108 | + exec('%s = temp'%attr) |
| 109 | + |
| 110 | + |
| 111 | + |
| 112 | + |
| 113 | + |
| 114 | + |
| 115 | + super(SPS, self).__init__(optics_mode=optics_mode, circumference=circumference, n_segments=n_segments, s=s, name=name, |
| 116 | + alpha_x=alpha_x, beta_x=beta_x, D_x=D_x, alpha_y=alpha_y, beta_y=beta_y, D_y=D_y, |
| 117 | + accQ_x=accQ_x, accQ_y=accQ_y, Qp_x=Qp_x, Qp_y=Qp_y, app_x=app_x, app_y=app_y, app_xy=app_xy, |
| 118 | + alpha_mom_compaction=alpha, longitudinal_mode=longitudinal_mode, |
| 119 | + h_RF=np.atleast_1d(h_RF), V_RF=np.atleast_1d(V_RF), dphi_RF=np.atleast_1d(dphi_RF), p0=p0, p_increment=p_increment, |
| 120 | + charge=charge, mass=mass) |
| 121 | + |
| 122 | +class shortSPS(BasicSynchrotron): |
| 123 | + |
| 124 | + def __init__(self, machine_configuration=None, optics_mode='smooth', **kwargs): |
| 125 | + |
| 126 | + |
| 127 | + longitudinal_mode = 'linear' |
| 128 | + h_RF = 4620/6 |
| 129 | + mass = m_p |
| 130 | + charge = e |
| 131 | + |
| 132 | + |
| 133 | + if machine_configuration=='Q20-injection-like': |
| 134 | + p0 = 26e9 * e /c |
| 135 | + p_increment = 0. |
| 136 | + accQ_x = 5.13 |
| 137 | + accQ_y = 5.18 |
| 138 | + V_RF = 5.75e6 |
| 139 | + dphi_RF = 0. |
| 140 | + alpha = 6*0.00308642 |
| 141 | + beta_x = 54.6 |
| 142 | + D_x = 0 |
| 143 | + beta_y = 54.6 |
| 144 | + D_y = 0 |
| 145 | + else: |
| 146 | + raise ValueError('machine_configuration not recognized!') |
| 147 | + |
| 148 | + |
| 149 | + |
| 150 | + if optics_mode=='smooth': |
| 151 | + if 's' in kwargs.keys(): raise ValueError('s vector cannot be provided if optics_mode = "smooth"') |
| 152 | + |
| 153 | + n_segments = kwargs['n_segments'] |
| 154 | + circumference = 1100*2*np.pi/6. |
| 155 | + |
| 156 | + name = None |
| 157 | + |
| 158 | + |
| 159 | + |
| 160 | + alpha_x = None |
| 161 | + alpha_y = None |
| 162 | + |
| 163 | + s = None |
| 164 | + |
| 165 | + elif optics_mode=='non-smooth': |
| 166 | + if 'n_segments' in kwargs.keys(): raise ValueError('n_segments cannot be provided if optics_mode = "non-smooth"') |
| 167 | + n_segments = None |
| 168 | + circumference = None |
| 169 | + |
| 170 | + name = kwargs['name'] |
| 171 | + |
| 172 | + beta_x = kwargs['beta_x'] |
| 173 | + beta_y = kwargs['beta_y'] |
| 174 | + |
| 175 | + try: |
| 176 | + D_x = kwargs['D_x'] |
| 177 | + except KeyError: |
| 178 | + D_x = 0*np.array(kwargs['s']) |
| 179 | + try: |
| 180 | + D_y = kwargs['D_y'] |
| 181 | + except KeyError: |
| 182 | + D_y = 0*np.array(kwargs['s']) |
| 183 | + |
| 184 | + alpha_x = kwargs['alpha_x'] |
| 185 | + alpha_y = kwargs['alpha_y'] |
| 186 | + |
| 187 | + s = kwargs['s'] |
| 188 | + |
| 189 | + else: |
| 190 | + raise ValueError('optics_mode not recognized!') |
| 191 | + |
| 192 | + |
| 193 | + # detunings |
| 194 | + Qp_x = 0 |
| 195 | + Qp_y = 0 |
| 196 | + |
| 197 | + app_x = 0 |
| 198 | + app_y = 0 |
| 199 | + app_xy = 0 |
| 200 | + |
| 201 | + i_octupole_focusing = None |
| 202 | + i_octupole_defocusing = None |
| 203 | + octupole_knob = None |
| 204 | + |
| 205 | + for attr in kwargs.keys(): |
| 206 | + if kwargs[attr] is not None: |
| 207 | + if type(kwargs[attr]) is list or type(kwargs[attr]) is np.ndarray: |
| 208 | + str2print = '[%s ...]'%repr(kwargs[attr][0]) |
| 209 | + else: |
| 210 | + str2print = repr(kwargs[attr]) |
| 211 | + self.prints('Synchrotron init. From kwargs: %s = %s' |
| 212 | + % (attr, str2print)) |
| 213 | + temp = kwargs[attr] |
| 214 | + exec('%s = temp'%attr) |
| 215 | + |
| 216 | + |
| 217 | + |
| 218 | + |
| 219 | + |
| 220 | + |
| 221 | + super(shortSPS, self).__init__(optics_mode=optics_mode, circumference=circumference, n_segments=n_segments, s=s, name=name, |
| 222 | + alpha_x=alpha_x, beta_x=beta_x, D_x=D_x, alpha_y=alpha_y, beta_y=beta_y, D_y=D_y, |
| 223 | + accQ_x=accQ_x, accQ_y=accQ_y, Qp_x=Qp_x, Qp_y=Qp_y, app_x=app_x, app_y=app_y, app_xy=app_xy, |
| 224 | + alpha_mom_compaction=alpha, longitudinal_mode=longitudinal_mode, |
| 225 | + h_RF=np.atleast_1d(h_RF), V_RF=np.atleast_1d(V_RF), dphi_RF=np.atleast_1d(dphi_RF), p0=p0, p_increment=p_increment, |
| 226 | + charge=charge, mass=mass) |
0 commit comments