Skip to content

Commit 231875a

Browse files
committed
start working on the savings
1 parent 65cc007 commit 231875a

File tree

1 file changed

+36
-17
lines changed

1 file changed

+36
-17
lines changed

test_physics/Simulation_with_eclouds.py

Lines changed: 36 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
# compute sigma x and y
77
epsn_x = 2.5e-6
88
epsn_y = 2.5e-6
9+
B_multip = [0.5]
910

1011
filename = '../../PyECLOUD/testing/tests_PyEC4PyHT/headtail_for_test/test_protons/SPS_Q20_proton_check_dipole_3kicks_20150212_prb.dat'
1112
B_multip = [0.5]
@@ -96,30 +97,30 @@ def init_master(self):
9697
print 'Bunch initialized.'
9798

9899
#replace particles with HDTL ones
99-
n_part_per_turn = 5000
100+
self.n_part_per_turn = 5000
100101
appo = np.loadtxt(filename)
101102

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,:]
103+
parid = np.reshape(appo[:,0], (-1, self.n_part_per_turn))[::self.n_segments,:]
104+
x = np.reshape(appo[:,1], (-1, self.n_part_per_turn))[::self.n_segments,:]
105+
xp = np.reshape(appo[:,2], (-1, self.n_part_per_turn))[::self.n_segments,:]
106+
y = np.reshape(appo[:,3], (-1, self.n_part_per_turn))[::self.n_segments,:]
107+
yp =np.reshape(appo[:,4], (-1, self.n_part_per_turn))[::self.n_segments,:]
108+
z = np.reshape(appo[:,5], (-1, self.n_part_per_turn))[::self.n_segments,:]
109+
zp = np.reshape(appo[:,6], (-1, self.n_part_per_turn))[::self.n_segments,:]
109110
self.N_turns = len(x[:,0])
110111

111112
# replace first particles with HEADTAIL ones
112-
bunch.x[:n_part_per_turn] = x[0,:]
113-
bunch.xp[:n_part_per_turn] = xp[0,:]
114-
bunch.y[:n_part_per_turn] = y[0,:]
115-
bunch.yp[:n_part_per_turn] = yp[0,:]
116-
bunch.z[:n_part_per_turn] = z[0,:]
117-
bunch.dp[:n_part_per_turn] =zp[0,:]
113+
bunch.x[:self.n_part_per_turn] = x[0,:]
114+
bunch.xp[:self.n_part_per_turn] = xp[0,:]
115+
bunch.y[:self.n_part_per_turn] = y[0,:]
116+
bunch.yp[:self.n_part_per_turn] = yp[0,:]
117+
bunch.z[:self.n_part_per_turn] = z[0,:]
118+
bunch.dp[:self.n_part_per_turn] =zp[0,:]
118119

119120
# save id and momenta before track
120-
self.id_before = bunch.id[bunch.id<=n_part_per_turn]
121-
self.xp_before = bunch.xp[bunch.id<=n_part_per_turn]
122-
self.yp_before = bunch.yp[bunch.id<=n_part_per_turn]
121+
self.id_before = bunch.id[bunch.id<=self.n_part_per_turn]
122+
self.xp_before = bunch.xp[bunch.id<=self.n_part_per_turn]
123+
self.yp_before = bunch.yp[bunch.id<=self.n_part_per_turn]
123124

124125
# initial slicing
125126
from PyHEADTAIL.particles.slicing import UniformBinSlicer
@@ -151,6 +152,24 @@ def finalize_turn_on_master(self, pieces_treated):
151152
for ele in self.non_parallel_part:
152153
ele.track(bunch)
153154

155+
# id and momenta after track
156+
id_after = bunch.id[bunch.id<=self.n_part_per_turn]
157+
xp_after = bunch.xp[bunch.id<=self.n_part_per_turn]
158+
z_after = bunch.z[bunch.id<=self.n_part_per_turn]
159+
yp_after = bunch.yp[bunch.id<=self.n_part_per_turn]
160+
161+
# sort id and momenta after track
162+
indsort = np.argsort(id_after)
163+
id_after = np.take(id_after, indsort)
164+
xp_after = np.take(xp_after, indsort)
165+
yp_after = np.take(yp_after, indsort)
166+
z_after = np.take(z_after, indsort)
167+
168+
# save results
169+
import myfilemanager as mfm
170+
mfm.save_dict_to_h5('particles_at_turn_%d.h5'%self.ring_of_CPUs.i_turn,{\
171+
172+
154173
# prepare next turn (re-slice)
155174
new_pieces_to_be_treated = bunch.extract_slices(self.slicer)
156175
orders_to_pass = ['reset_clouds']

0 commit comments

Comments
 (0)