Skip to content

Commit cac79e1

Browse files
committed
Merge pull request #23 from PyCOMPLETE/InterfChangesFromEcloud
Interf changes from ecloud
2 parents 5bdfd10 + c4bebfb commit cac79e1

26 files changed

+712
-663
lines changed

field_maps/Transverse_Efield_map.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,15 @@
99
class Transverse_Efield_map(object):
1010
def __init__(self, xg, yg, Ex, Ey, n_slices, z_cut,
1111
L_interaction, flag_clean_slices = False, wrt_slice_centroid = False):
12-
13-
self.slicer = UniformBinSlicer(n_slices = n_slices, z_cuts=(-z_cut, z_cut))
12+
13+
if type(z_cut) is float:
14+
z_cuts = (-z_cut, z_cut)
15+
elif type(z_cut) is tuple:
16+
z_cuts = z_cut
17+
else:
18+
raise ValueError('Type not recognized!')
19+
20+
self.slicer = UniformBinSlicer(n_slices = n_slices, z_cuts=z_cuts)
1421
self.L_interaction = L_interaction
1522
self.flag_clean_slices = flag_clean_slices
1623
self.wrt_slice_centroid = wrt_slice_centroid

particles/particles.py

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,41 @@ def reorder(self, permutation, except_for_attrs=[]):
194194
continue
195195
reordered = getattr(self, attr)[permutation]
196196
setattr(self, attr, reordered)
197+
198+
def __add__(self, other):
199+
'''Merges two beams.
200+
'''
201+
#print 'Checks still to be added!!!!!!'
202+
203+
self_coords_n_momenta_dict = self.get_coords_n_momenta_dict()
204+
other_coords_n_momenta_dict = other.get_coords_n_momenta_dict()
205+
206+
result = Particles(macroparticlenumber=self.macroparticlenumber+other.macroparticlenumber,
207+
particlenumber_per_mp=self.particlenumber_per_mp, charge=self.charge,
208+
mass=self.mass, circumference=self.circumference, gamma=self.gamma, coords_n_momenta_dict={})
209+
210+
211+
for coord in self_coords_n_momenta_dict.keys():
212+
#setattr(result, coord, np.concatenate((self_coords_n_momenta_dict[coord].copy(), other_coords_n_momenta_dict[coord].copy())))
213+
result.update({coord: np.concatenate((self_coords_n_momenta_dict[coord].copy(), other_coords_n_momenta_dict[coord].copy()))})
214+
215+
return result
216+
217+
def __radd__(self, other):
218+
if other==0:
219+
self_coords_n_momenta_dict = self.get_coords_n_momenta_dict()
220+
result = Particles(macroparticlenumber=self.macroparticlenumber,
221+
particlenumber_per_mp=self.particlenumber_per_mp, charge=self.charge,
222+
mass=self.mass, circumference=self.circumference, gamma=self.gamma, coords_n_momenta_dict={})
223+
224+
for coord in self_coords_n_momenta_dict.keys():
225+
#setattr(result, coord, np.concatenate((self_coords_n_momenta_dict[coord].copy(), other_coords_n_momenta_dict[coord].copy())))
226+
result.update({coord: self_coords_n_momenta_dict[coord].copy()})
227+
else:
228+
result = self.__add__(other)
229+
230+
return result
231+
197232

198233
# Statistics methods
199234

testing/interactive-tests/ApertureNLossesTest.ipynb

Lines changed: 25 additions & 25 deletions
Large diffs are not rendered by default.

testing/interactive-tests/BeamOptics.ipynb

Lines changed: 71 additions & 79 deletions
Large diffs are not rendered by default.

testing/interactive-tests/DetunersCythonTest.ipynb

Lines changed: 27 additions & 28 deletions
Large diffs are not rendered by default.

testing/interactive-tests/DetunersTest.ipynb

Lines changed: 23 additions & 21 deletions
Large diffs are not rendered by default.

testing/interactive-tests/GeneratorTest.ipynb

Lines changed: 59 additions & 60 deletions
Large diffs are not rendered by default.

testing/interactive-tests/MonitorTest.ipynb

Lines changed: 20 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"cells": [
33
{
44
"cell_type": "code",
5-
"execution_count": 1,
5+
"execution_count": 7,
66
"metadata": {
77
"collapsed": false
88
},
@@ -15,21 +15,11 @@
1515
},
1616
{
1717
"cell_type": "code",
18-
"execution_count": 2,
18+
"execution_count": 8,
1919
"metadata": {
2020
"collapsed": false
2121
},
22-
"outputs": [
23-
{
24-
"name": "stdout",
25-
"output_type": "stream",
26-
"text": [
27-
"PyHEADTAIL v1.2.0-153-gbc0ea69a06-dirty\n",
28-
"\n",
29-
"\n"
30-
]
31-
}
32-
],
22+
"outputs": [],
3323
"source": [
3424
"import numpy as np\n",
3525
"from scipy.constants import m_p, c, e\n",
@@ -45,7 +35,7 @@
4535
},
4636
{
4737
"cell_type": "code",
48-
"execution_count": 7,
38+
"execution_count": 9,
4939
"metadata": {
5040
"collapsed": false
5141
},
@@ -143,7 +133,7 @@
143133
},
144134
{
145135
"cell_type": "code",
146-
"execution_count": 8,
136+
"execution_count": 10,
147137
"metadata": {
148138
"collapsed": false
149139
},
@@ -177,7 +167,7 @@
177167
},
178168
{
179169
"cell_type": "code",
180-
"execution_count": 9,
170+
"execution_count": 11,
181171
"metadata": {
182172
"collapsed": false
183173
},
@@ -197,7 +187,7 @@
197187
},
198188
{
199189
"cell_type": "code",
200-
"execution_count": 10,
190+
"execution_count": 12,
201191
"metadata": {
202192
"collapsed": false
203193
},
@@ -206,18 +196,7 @@
206196
"name": "stdout",
207197
"output_type": "stream",
208198
"text": [
209-
"0.0598522977141\n"
210-
]
211-
},
212-
{
213-
"ename": "KeyboardInterrupt",
214-
"evalue": "",
215-
"output_type": "error",
216-
"traceback": [
217-
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
218-
"\u001b[0;31mKeyboardInterrupt\u001b[0m Traceback (most recent call last)",
219-
"\u001b[0;32m<ipython-input-10-39c3aff5b0d1>\u001b[0m in \u001b[0;36m<module>\u001b[0;34m()\u001b[0m\n\u001b[1;32m 30\u001b[0m \u001b[0mslice_monitor\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mdump\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mbunch\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 31\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m---> 32\u001b[0;31m \u001b[0mslice_set_pmon\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mbunch\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mget_slices\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0munibin_slicer\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 33\u001b[0m \u001b[0marrays_dict\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mupdate\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m{\u001b[0m\u001b[0;34m'slidx'\u001b[0m\u001b[0;34m:\u001b[0m \u001b[0mslice_set_pmon\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mslice_index_of_particle\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m'zz'\u001b[0m\u001b[0;34m:\u001b[0m \u001b[0mbunch\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mz\u001b[0m\u001b[0;34m}\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 34\u001b[0m \u001b[0mparticle_monitor\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mdump\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mbunch\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0marrays_dict\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
220-
"\u001b[0;31mKeyboardInterrupt\u001b[0m: "
199+
"0.0614682430577\n"
221200
]
222201
}
223202
],
@@ -228,7 +207,7 @@
228207
" alpha_0, Q_s, R)\n",
229208
"\n",
230209
"trans_map = TransverseMap(\n",
231-
" C, s, alpha_x, beta_x, D_x, alpha_y, beta_y, D_y, Q_x, Q_y)\n",
210+
" s, alpha_x, beta_x, D_x, alpha_y, beta_y, D_y, Q_x, Q_y)\n",
232211
"\n",
233212
"# Slicer config for SliceMonitor.\n",
234213
"unibin_slicer = UniformBinSlicer(n_slices=10, n_sigma_z=None, z_cuts=None)\n",
@@ -263,7 +242,7 @@
263242
},
264243
{
265244
"cell_type": "code",
266-
"execution_count": 7,
245+
"execution_count": 13,
267246
"metadata": {
268247
"collapsed": false
269248
},
@@ -283,6 +262,15 @@
283262
},
284263
"outputs": [],
285264
"source": []
265+
},
266+
{
267+
"cell_type": "code",
268+
"execution_count": null,
269+
"metadata": {
270+
"collapsed": true
271+
},
272+
"outputs": [],
273+
"source": []
286274
}
287275
],
288276
"metadata": {
@@ -301,7 +289,7 @@
301289
"name": "python",
302290
"nbconvert_exporter": "python",
303291
"pygments_lexer": "ipython2",
304-
"version": "2.7.10"
292+
"version": "2.7.11"
305293
}
306294
},
307295
"nbformat": 4,

testing/interactive-tests/RFBucketHamiltonianDeformation.ipynb

Lines changed: 56 additions & 34 deletions
Large diffs are not rendered by default.

testing/interactive-tests/RFQTest.ipynb

Lines changed: 13 additions & 21 deletions
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)