Skip to content

Commit 07456d7

Browse files
committed
Python 3 version of PyECLOUD 8.2.0
1 parent 54ac6d1 commit 07456d7

File tree

97 files changed

+499
-499
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

97 files changed

+499
-499
lines changed

002_change_version_number.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
for filename in files:
66
if filename[-3:] == '.py':
7-
print filename
7+
print(filename)
88
os.system('cp %s %s'%(filename, filename + 'old'))
99
with open(filename) as fid:
1010
content = fid.read()

003_change_preamble.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,5 +109,5 @@
109109

110110
with open(path, 'w') as f:
111111
f.writelines(new_lines)
112-
print('Modified %s' % path)
112+
print(('Modified %s' % path))
113113

BassErsk.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from cmath import *
22
from numpy import *
3-
from errffor import errf
3+
from .errffor import errf
44

55

66
def wfun(z):

MP_system.py

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@
5252

5353
import numpy as np
5454
from numpy.random import rand
55-
import hist_for as histf
55+
from . import hist_for as histf
5656
from scipy.constants import e, m_e
5757

5858

@@ -134,7 +134,7 @@ def __init__(self, N_mp_max, nel_mp_ref_0, fact_split, fact_clean,
134134

135135
def clean_small_MPs(self):
136136

137-
print "Cloud %s: Start clean. N_mp=%d Nel=%e"%(self.name, self.N_mp, np.sum(self.nel_mp[0:self.N_mp]))
137+
print("Cloud %s: Start clean. N_mp=%d Nel=%e"%(self.name, self.N_mp, np.sum(self.nel_mp[0:self.N_mp])))
138138

139139
flag_clean = (self.nel_mp < self.nel_mp_cl_th)
140140
flag_keep = ~(flag_clean)
@@ -154,11 +154,11 @@ def clean_small_MPs(self):
154154
if self.flag_lifetime_hist:
155155
self.t_last_impact[0:self.N_mp] = np.array(self.t_last_impact[flag_keep].copy())
156156

157-
print "Cloud %s: Done clean. N_mp=%d Nel=%e"%(self.name, self.N_mp, np.sum(self.nel_mp[0:self.N_mp]))
157+
print("Cloud %s: Done clean. N_mp=%d Nel=%e"%(self.name, self.N_mp, np.sum(self.nel_mp[0:self.N_mp])))
158158

159159
if self.N_mp == 0:
160160
self.set_nel_mp_ref(self.nel_mp_ref_0)
161-
print('Cloud %s: nel_mp_ref set to nel_mp_ref_0'%self.name)
161+
print(('Cloud %s: nel_mp_ref set to nel_mp_ref_0'%self.name))
162162

163163
def set_nel_mp_ref(self, val):
164164
self.nel_mp_ref = val
@@ -176,7 +176,7 @@ def perform_soft_regeneration(self, target_N_mp):
176176
new_nel_mp_ref = self.nel_mp_ref_0
177177

178178
#if new_nel_mp_ref>self.nel_mp_ref_0:removed from version 3.16
179-
print 'Cloud %s: Start SOFT regeneration. N_mp=%d Nel_tot=%1.2e En_tot=%1.2e'%(self.name, self.N_mp, chrg, erg)
179+
print('Cloud %s: Start SOFT regeneration. N_mp=%d Nel_tot=%1.2e En_tot=%1.2e'%(self.name, self.N_mp, chrg, erg))
180180

181181
self.set_nel_mp_ref(new_nel_mp_ref)
182182

@@ -204,13 +204,13 @@ def perform_soft_regeneration(self, target_N_mp):
204204

205205
correct_fact = chrg_before / chrg_after
206206

207-
print 'Cloud %s: Applied correction factor = %e'%(self.name, correct_fact)
207+
print('Cloud %s: Applied correction factor = %e'%(self.name, correct_fact))
208208

209209
self.nel_mp[0:self.N_mp] = self.nel_mp[0:self.N_mp] * correct_fact
210210

211211
chrg = np.sum(self.nel_mp)
212212
erg = np.sum(0.5 / np.abs(self.charge / self.mass) * self.nel_mp[0:self.N_mp] * (self.vx_mp[0:self.N_mp] * self.vx_mp[0:self.N_mp] + self.vy_mp[0:self.N_mp] * self.vy_mp[0:self.N_mp] + self.vz_mp[0:self.N_mp] * self.vz_mp[0:self.N_mp]))
213-
print 'Cloud %s: Done SOFT regeneration. N_mp=%d Nel_tot=%1.2e En_tot=%1.2e'%(self.name, self.N_mp, chrg, erg)
213+
print('Cloud %s: Done SOFT regeneration. N_mp=%d Nel_tot=%1.2e En_tot=%1.2e'%(self.name, self.N_mp, chrg, erg))
214214

215215
def check_for_soft_regeneration(self):
216216

@@ -222,7 +222,7 @@ def check_for_async_regeneration(self):
222222

223223
if self.flag_async_regen:
224224
if self.N_mp > self.N_mp_async_regen:
225-
print('Cloud %s: Asynchronous clean and regeneration.' %self.name)
225+
print(('Cloud %s: Asynchronous clean and regeneration.' %self.name))
226226
self.clean_small_MPs()
227227
if self.N_mp > self.N_mp_async_regen:
228228
self.perform_soft_regeneration(target_N_mp=self.N_mp_after_async_regen)
@@ -232,7 +232,7 @@ def check_for_regeneration(self):
232232
if (self.N_mp > self.N_mp_regen or (self.N_mp < self.N_mp_regen_low and self.nel_mp_ref > self.nel_mp_ref_0)):
233233
chrg = np.sum(self.nel_mp)
234234
erg = np.sum(0.5 / np.abs(self.charge / self.mass) * self.nel_mp[0:self.N_mp] * (self.vx_mp[0:self.N_mp] * self.vx_mp[0:self.N_mp] + self.vy_mp[0:self.N_mp] * self.vy_mp[0:self.N_mp] + self.vz_mp[0:self.N_mp] * self.vz_mp[0:self.N_mp]))
235-
print 'Cloud %s: Start regeneration. N_mp=%d Nel_tot=%1.2e En_tot=%1.2e'%(self.name, self.N_mp, chrg, erg)
235+
print('Cloud %s: Start regeneration. N_mp=%d Nel_tot=%1.2e En_tot=%1.2e'%(self.name, self.N_mp, chrg, erg))
236236

237237
new_nel_mp_ref = chrg / self.N_mp_after_regen
238238
if new_nel_mp_ref < self.nel_mp_ref_0:
@@ -253,7 +253,7 @@ def check_for_regeneration(self):
253253

254254
x_max = (len(hist_vect) - i_cut + 1) * self.Dx_hist_reg + self.bias_x_hist_reg
255255

256-
print 'Cloud %s: x_max = %e'%(self.name, x_max)
256+
print('Cloud %s: x_max = %e'%(self.name, x_max))
257257

258258
flag_clean = (abs(self.x_mp) > x_max)
259259
flag_keep = ~(flag_clean)
@@ -303,7 +303,7 @@ def check_for_regeneration(self):
303303
bias_vz = np.ceil(float(self.Nvz_reg) / 2)
304304
#Attention when trnslating to python
305305

306-
print 'Cloud %s: particles_assigned_to grid'%(self.name)
306+
print('Cloud %s: particles_assigned_to grid'%(self.name))
307307

308308
##
309309
#% MATLAB-like indices
@@ -324,15 +324,15 @@ def check_for_regeneration(self):
324324
indices_nonzero_cells = np.array(list(set(indexes)))
325325
indices_nonzero_cells = np.sort(indices_nonzero_cells)
326326

327-
vect_dens = dict(zip(indices_nonzero_cells, np.zeros(len(indices_nonzero_cells))))
327+
vect_dens = dict(list(zip(indices_nonzero_cells, np.zeros(len(indices_nonzero_cells)))))
328328
#lil_matrix((Nx_reg*Ny_reg*Nvx_reg*Nvy_reg*Nvz_reg,1));#allocate a sparse matrix
329329
#
330330

331331
for i_mp in range(0, self.N_mp):
332332
index_curr = indexes[i_mp]
333333
vect_dens[index_curr] = vect_dens[index_curr] + self.nel_mp[i_mp]
334334

335-
nonzero_cells = np.array(map(vect_dens.get, indices_nonzero_cells))
335+
nonzero_cells = np.array(list(map(vect_dens.get, indices_nonzero_cells)))
336336

337337
#%% retrieve indices of nonempty cells
338338
#% NB use C-like indices
@@ -436,7 +436,7 @@ def check_for_regeneration(self):
436436

437437
chrg = np.sum(self.nel_mp)
438438
erg = np.sum(0.5 / np.abs(self.charge / self.mass) * self.nel_mp[0:self.N_mp] * (self.vx_mp[0:self.N_mp] * self.vx_mp[0:self.N_mp] + self.vy_mp[0:self.N_mp] * self.vy_mp[0:self.N_mp] + self.vz_mp[0:self.N_mp] * self.vz_mp[0:self.N_mp]))
439-
print 'Cloud %s: Done regeneration. N_mp=%d Nel_tot=%1.2e En_tot=%1.2e'%(self.name, self.N_mp, chrg, erg)
439+
print('Cloud %s: Done regeneration. N_mp=%d Nel_tot=%1.2e En_tot=%1.2e'%(self.name, self.N_mp, chrg, erg))
440440

441441
def add_uniform_MP_distrib(self, DNel, E_init, x_max, x_min, y_max, y_min):
442442

@@ -569,7 +569,7 @@ def add_from_file(self, filename_MPs):
569569
self.nel_mp[self.N_mp:self.N_mp + Nint_new_MP] = np.squeeze(dict_MP_init['nel_mp'])
570570

571571
if self.flag_lifetime_hist:
572-
if 't_last_impact' in dict_MP_init.keys():
572+
if 't_last_impact' in list(dict_MP_init.keys()):
573573
self.t_last_impact[self.N_mp:self.N_mp + Nint_new_MP] = np.squeeze(
574574
dict_MP_init['t_last_impact'])
575575
else:

PyEC4PyHT.py

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,9 @@
5757
import numpy as np
5858
from scipy.constants import c, e, m_e
5959

60-
import myloadmat_to_obj as mlm
61-
import init
62-
import buildup_simulation as bsim
60+
from . import myloadmat_to_obj as mlm
61+
from . import init
62+
from . import buildup_simulation as bsim
6363

6464

6565
class Empty(object):
@@ -105,7 +105,7 @@ def __init__(self, L_ecloud, slicer, Dt_ref, pyecl_input_folder='./', flag_clean
105105
beam_monitor=None, verbose=False, save_pyecl_outp_as=None,
106106
**kwargs):
107107

108-
print 'PyECLOUD Version 8.2.0'
108+
print('PyECLOUD Version 8.2.0')
109109

110110
# These git commands return the hash and the branch of the specified git directory.
111111
path_to_git = os.path.dirname(os.path.abspath(__file__)) + '/.git'
@@ -125,8 +125,8 @@ def __init__(self, L_ecloud, slicer, Dt_ref, pyecl_input_folder='./', flag_clean
125125
print(e)
126126
print(git_branch)
127127

128-
print 'PyHEADTAIL module'
129-
print 'Initializing ecloud from folder: ' + pyecl_input_folder
128+
print('PyHEADTAIL module')
129+
print('Initializing ecloud from folder: ' + pyecl_input_folder)
130130
self.slicer = slicer
131131
self.Dt_ref = Dt_ref
132132
self.L_ecloud = L_ecloud
@@ -173,13 +173,13 @@ def __init__(self, L_ecloud, slicer, Dt_ref, pyecl_input_folder='./', flag_clean
173173
self.y_probes = -1
174174
self.Ex_ele_last_track_at_probes = -1
175175
self.Ey_ele_last_track_at_probes = -1
176-
if 'probes_position' in kwargs.keys():
176+
if 'probes_position' in list(kwargs.keys()):
177177
self.save_ele_field_probes = True
178178
self.probes_position = kwargs['probes_position']
179179
self.N_probes = len(self.probes_position)
180180
self.x_probes = []
181181
self.y_probes = []
182-
for ii_probe in xrange(self.N_probes):
182+
for ii_probe in range(self.N_probes):
183183
self.x_probes.append(self.probes_position[ii_probe]['x'])
184184
self.y_probes.append(self.probes_position[ii_probe]['y'])
185185

@@ -236,7 +236,7 @@ def track(self, beam):
236236

237237
if self.track_only_first_time:
238238
if self.N_tracks > 0:
239-
print 'Warning: Track skipped because track_only_first_time is True.'
239+
print('Warning: Track skipped because track_only_first_time is True.')
240240
return
241241

242242
if self.verbose:
@@ -252,9 +252,9 @@ def track(self, beam):
252252

253253
slices = beam.get_slices(self.slicer)
254254

255-
for i in xrange(slices.n_slices - 1, -1, -1):
255+
for i in range(slices.n_slices - 1, -1, -1):
256256
if self.verbose:
257-
print('Slice %d/%d'%(i, slices.n_slices))
257+
print(('Slice %d/%d'%(i, slices.n_slices)))
258258

259259
# select particles in the slice
260260
ix = slices.particle_indices_of_slice(i)
@@ -272,18 +272,18 @@ def track(self, beam):
272272

273273
if self.verbose:
274274
stop_time = time.mktime(time.localtime())
275-
print 'Done track %d in %.1f s'%(self.N_tracks, stop_time - start_time)
275+
print('Done track %d in %.1f s'%(self.N_tracks, stop_time - start_time))
276276

277277
self.N_tracks += 1
278278

279279
def replace_with_recorded_field_map(self, delete_ecloud_data=True):
280280

281281
if self.track_only_first_time:
282-
print 'Warning: replace_with_recorded_field_map resets track_only_first_time = False'
282+
print('Warning: replace_with_recorded_field_map resets track_only_first_time = False')
283283
self.track_only_first_time = False
284284

285285
if not hasattr(self, 'efieldmap'):
286-
from Transverse_Efield_map_for_frozen_cloud import Transverse_Efield_map
286+
from .Transverse_Efield_map_for_frozen_cloud import Transverse_Efield_map
287287
self.efieldmap = Transverse_Efield_map(xg=self.spacech_ele.xg, yg=self.spacech_ele.yg,
288288
Ex=self.Ex_ele_last_track, Ey=self.Ey_ele_last_track, L_interaction=self.L_ecloud,
289289
slicer=self.slicer,
@@ -301,7 +301,7 @@ def replace_with_recorded_field_map(self, delete_ecloud_data=True):
301301
self.cloudsim = None
302302

303303
else:
304-
print 'Warning: efieldmap already exists. I do nothing.'
304+
print('Warning: efieldmap already exists. I do nothing.')
305305

306306
def track_once_and_replace_with_recorded_field_map(self, bunch, delete_ecloud_data=True):
307307
self.save_ele_field = True
@@ -325,7 +325,7 @@ def _track_single_slice(self, slic, ix, dz, force_pyecl_newpass=False):
325325

326326
# Check if the slice interacts with the beam
327327
if hasattr(slic, 'slice_info'):
328-
if 'interact_with_EC' in slic.slice_info.keys():
328+
if 'interact_with_EC' in list(slic.slice_info.keys()):
329329
interact_with_EC = slic.slice_info['interact_with_EC']
330330
else:
331331
interact_with_EC = True
@@ -351,7 +351,7 @@ def _track_single_slice(self, slic, ix, dz, force_pyecl_newpass=False):
351351

352352
# Acquire bunch passage information
353353
if hasattr(slic, 'slice_info'):
354-
if 'info_parent_bunch' in slic.slice_info.keys():
354+
if 'info_parent_bunch' in list(slic.slice_info.keys()):
355355

356356
# check if first slice of first bunch
357357
if slic.slice_info['info_parent_bunch']['i_bunch'] == 0 and slic.slice_info['i_slice'] == 0:

Transverse_Efield_map_for_frozen_cloud.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ def track(self, beam):
4343
slices = beam.get_slices(self.slicer)
4444

4545
sid = 0
46-
for _ in xrange(slices.n_slices):
46+
for _ in range(slices.n_slices):
4747

4848
sid -= 1
4949

0 commit comments

Comments
 (0)