Skip to content

Commit 65cc007

Browse files
committed
first physics test is running
but no output yet
1 parent 49c1ddc commit 65cc007

File tree

3 files changed

+265
-20
lines changed

3 files changed

+265
-20
lines changed
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import sys, os
2+
BIN = os.path.expanduser("../../")
3+
sys.path.append(BIN)
4+
BIN = os.path.expanduser("../")
5+
sys.path.append(BIN)
6+
7+
from ring_of_CPUs import RingOfCPUs
8+
from Simulation_with_eclouds import Simulation
9+
simulation_content = Simulation()
10+
11+
myCPUring = RingOfCPUs(simulation_content)
12+
13+
myCPUring.run()

test_physics/Simulation_with_eclouds.py

Lines changed: 26 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@
77
epsn_x = 2.5e-6
88
epsn_y = 2.5e-6
99

10+
filename = '../../PyECLOUD/testing/tests_PyEC4PyHT/headtail_for_test/test_protons/SPS_Q20_proton_check_dipole_3kicks_20150212_prb.dat'
11+
B_multip = [0.5]
12+
1013

1114
class Simulation(object):
1215
def __init__(self):
@@ -15,15 +18,15 @@ def __init__(self):
1518
def init_all(self):
1619

1720
n_slices = 64
18-
1921
self.n_slices = n_slices
2022

21-
n_segments=3
23+
n_segments = 3
24+
self.n_segments = n_segments
2225

2326
from machines_for_testing import SPS
24-
machine = SPS(n_segments = n_segments,
27+
self.machine = SPS(n_segments = n_segments,
2528
machine_configuration = 'Q20-injection', accQ_x=20., accQ_y=20.,
26-
RF_at=RF_at='end_of_transverse')
29+
RF_at='end_of_transverse')
2730

2831

2932
# We suppose that all the object that cannot be slice parallelized are at the end of the ring
@@ -46,32 +49,36 @@ def init_all(self):
4649
init_unif_edens=2e11
4750
N_MP_ele_init = 100000
4851
N_mp_max = N_MP_ele_init*4.
49-
52+
5053
# define apertures and Dh_sc to simulate headtail
51-
inj_optics = machine.transverse_map.get_injection_optics()
52-
sigma_x = np.sqrt(inj_optics['beta_x']*epsn_x/machine.betagamma)
53-
sigma_y = np.sqrt(inj_optics['beta_y']*epsn_y/machine.betagamma)
54+
inj_optics = self.machine.transverse_map.get_injection_optics()
55+
sigma_x = np.sqrt(inj_optics['beta_x']*epsn_x/self.machine.betagamma)
56+
sigma_y = np.sqrt(inj_optics['beta_y']*epsn_y/self.machine.betagamma)
5457
x_aper = 20*sigma_x
5558
y_aper = 20*sigma_y
5659
Dh_sc = 2*x_aper/128/2
60+
61+
# initial MP size
62+
nel_mp_ref_0 = init_unif_edens*4*x_aper*y_aper/N_MP_ele_init
5763

5864
import PyECLOUD.PyEC4PyHT as PyEC4PyHT
5965
my_new_part = []
6066
self.my_list_eclouds = []
6167
for ele in self.mypart:
6268
my_new_part.append(ele)
6369
if ele in self.machine.transverse_map:
64-
ecloud_new = PyEC4PyHT.Ecloud(L_ecloud=machine.circumference/N_kicks,
70+
ecloud_new = PyEC4PyHT.Ecloud(slice_by_slice_mode=True,
71+
L_ecloud=self.machine.circumference/n_segments,
6572
slicer=None,
66-
Dt_ref=25e-12, pyecl_input_folder='./drift_sim',
73+
Dt_ref=25e-12,
74+
pyecl_input_folder='../../PyECLOUD/testing/tests_PyEC4PyHT/drift_sim/',
6775
x_aper=x_aper, y_aper=y_aper, Dh_sc=Dh_sc,
6876
init_unif_edens_flag=init_unif_edens_flag,
6977
init_unif_edens=init_unif_edens,
7078
N_MP_ele_init=N_MP_ele_init,
7179
N_mp_max=N_mp_max,
7280
nel_mp_ref_0=nel_mp_ref_0,
7381
B_multip=B_multip)
74-
slice_by_slice_mode=True)
7582
my_new_part.append(ecloud_new)
7683
self.my_list_eclouds.append(ecloud_new)
7784
self.mypart = my_new_part
@@ -89,17 +96,16 @@ def init_master(self):
8996
print 'Bunch initialized.'
9097

9198
#replace particles with HDTL ones
92-
filename = 'headtail_for_test/test_protons/SPS_Q20_proton_check_dipole_3kicks_20150212_prb.dat'
9399
n_part_per_turn = 5000
94100
appo = np.loadtxt(filename)
95-
96-
parid = np.reshape(appo[:,0], (-1, n_part_per_turn))[::N_kicks,:]
97-
x = np.reshape(appo[:,1], (-1, n_part_per_turn))[::N_kicks,:]
98-
xp = np.reshape(appo[:,2], (-1, n_part_per_turn))[::N_kicks,:]
99-
y = np.reshape(appo[:,3], (-1, n_part_per_turn))[::N_kicks,:]
100-
yp =np.reshape(appo[:,4], (-1, n_part_per_turn))[::N_kicks,:]
101-
z = np.reshape(appo[:,5], (-1, n_part_per_turn))[::N_kicks,:]
102-
zp = np.reshape(appo[:,6], (-1, n_part_per_turn))[::N_kicks,:]
101+
102+
parid = np.reshape(appo[:,0], (-1, n_part_per_turn))[::self.n_segments,:]
103+
x = np.reshape(appo[:,1], (-1, n_part_per_turn))[::self.n_segments,:]
104+
xp = np.reshape(appo[:,2], (-1, n_part_per_turn))[::self.n_segments,:]
105+
y = np.reshape(appo[:,3], (-1, n_part_per_turn))[::self.n_segments,:]
106+
yp =np.reshape(appo[:,4], (-1, n_part_per_turn))[::self.n_segments,:]
107+
z = np.reshape(appo[:,5], (-1, n_part_per_turn))[::self.n_segments,:]
108+
zp = np.reshape(appo[:,6], (-1, n_part_per_turn))[::self.n_segments,:]
103109
self.N_turns = len(x[:,0])
104110

105111
# replace first particles with HEADTAIL ones
Lines changed: 226 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,226 @@
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

Comments
 (0)