Skip to content

Commit

Permalink
Python 3 version of PyECLOUD 8.2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
giadarol committed Nov 27, 2019
1 parent 54ac6d1 commit 07456d7
Show file tree
Hide file tree
Showing 97 changed files with 499 additions and 499 deletions.
2 changes: 1 addition & 1 deletion 002_change_version_number.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

for filename in files:
if filename[-3:] == '.py':
print filename
print(filename)
os.system('cp %s %s'%(filename, filename + 'old'))
with open(filename) as fid:
content = fid.read()
Expand Down
2 changes: 1 addition & 1 deletion 003_change_preamble.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,5 +109,5 @@

with open(path, 'w') as f:
f.writelines(new_lines)
print('Modified %s' % path)
print(('Modified %s' % path))

2 changes: 1 addition & 1 deletion BassErsk.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from cmath import *
from numpy import *
from errffor import errf
from .errffor import errf


def wfun(z):
Expand Down
30 changes: 15 additions & 15 deletions MP_system.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@

import numpy as np
from numpy.random import rand
import hist_for as histf
from . import hist_for as histf
from scipy.constants import e, m_e


Expand Down Expand Up @@ -134,7 +134,7 @@ def __init__(self, N_mp_max, nel_mp_ref_0, fact_split, fact_clean,

def clean_small_MPs(self):

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

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

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

if self.N_mp == 0:
self.set_nel_mp_ref(self.nel_mp_ref_0)
print('Cloud %s: nel_mp_ref set to nel_mp_ref_0'%self.name)
print(('Cloud %s: nel_mp_ref set to nel_mp_ref_0'%self.name))

def set_nel_mp_ref(self, val):
self.nel_mp_ref = val
Expand All @@ -176,7 +176,7 @@ def perform_soft_regeneration(self, target_N_mp):
new_nel_mp_ref = self.nel_mp_ref_0

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

self.set_nel_mp_ref(new_nel_mp_ref)

Expand Down Expand Up @@ -204,13 +204,13 @@ def perform_soft_regeneration(self, target_N_mp):

correct_fact = chrg_before / chrg_after

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

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

chrg = np.sum(self.nel_mp)
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]))
print 'Cloud %s: Done SOFT regeneration. N_mp=%d Nel_tot=%1.2e En_tot=%1.2e'%(self.name, self.N_mp, chrg, erg)
print('Cloud %s: Done SOFT regeneration. N_mp=%d Nel_tot=%1.2e En_tot=%1.2e'%(self.name, self.N_mp, chrg, erg))

def check_for_soft_regeneration(self):

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

if self.flag_async_regen:
if self.N_mp > self.N_mp_async_regen:
print('Cloud %s: Asynchronous clean and regeneration.' %self.name)
print(('Cloud %s: Asynchronous clean and regeneration.' %self.name))
self.clean_small_MPs()
if self.N_mp > self.N_mp_async_regen:
self.perform_soft_regeneration(target_N_mp=self.N_mp_after_async_regen)
Expand All @@ -232,7 +232,7 @@ def check_for_regeneration(self):
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)):
chrg = np.sum(self.nel_mp)
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]))
print 'Cloud %s: Start regeneration. N_mp=%d Nel_tot=%1.2e En_tot=%1.2e'%(self.name, self.N_mp, chrg, erg)
print('Cloud %s: Start regeneration. N_mp=%d Nel_tot=%1.2e En_tot=%1.2e'%(self.name, self.N_mp, chrg, erg))

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

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

print 'Cloud %s: x_max = %e'%(self.name, x_max)
print('Cloud %s: x_max = %e'%(self.name, x_max))

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

print 'Cloud %s: particles_assigned_to grid'%(self.name)
print('Cloud %s: particles_assigned_to grid'%(self.name))

##
#% MATLAB-like indices
Expand All @@ -324,15 +324,15 @@ def check_for_regeneration(self):
indices_nonzero_cells = np.array(list(set(indexes)))
indices_nonzero_cells = np.sort(indices_nonzero_cells)

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

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

nonzero_cells = np.array(map(vect_dens.get, indices_nonzero_cells))
nonzero_cells = np.array(list(map(vect_dens.get, indices_nonzero_cells)))

#%% retrieve indices of nonempty cells
#% NB use C-like indices
Expand Down Expand Up @@ -436,7 +436,7 @@ def check_for_regeneration(self):

chrg = np.sum(self.nel_mp)
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]))
print 'Cloud %s: Done regeneration. N_mp=%d Nel_tot=%1.2e En_tot=%1.2e'%(self.name, self.N_mp, chrg, erg)
print('Cloud %s: Done regeneration. N_mp=%d Nel_tot=%1.2e En_tot=%1.2e'%(self.name, self.N_mp, chrg, erg))

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

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

if self.flag_lifetime_hist:
if 't_last_impact' in dict_MP_init.keys():
if 't_last_impact' in list(dict_MP_init.keys()):
self.t_last_impact[self.N_mp:self.N_mp + Nint_new_MP] = np.squeeze(
dict_MP_init['t_last_impact'])
else:
Expand Down
34 changes: 17 additions & 17 deletions PyEC4PyHT.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,9 @@
import numpy as np
from scipy.constants import c, e, m_e

import myloadmat_to_obj as mlm
import init
import buildup_simulation as bsim
from . import myloadmat_to_obj as mlm
from . import init
from . import buildup_simulation as bsim


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

print 'PyECLOUD Version 8.2.0'
print('PyECLOUD Version 8.2.0')

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

print 'PyHEADTAIL module'
print 'Initializing ecloud from folder: ' + pyecl_input_folder
print('PyHEADTAIL module')
print('Initializing ecloud from folder: ' + pyecl_input_folder)
self.slicer = slicer
self.Dt_ref = Dt_ref
self.L_ecloud = L_ecloud
Expand Down Expand Up @@ -173,13 +173,13 @@ def __init__(self, L_ecloud, slicer, Dt_ref, pyecl_input_folder='./', flag_clean
self.y_probes = -1
self.Ex_ele_last_track_at_probes = -1
self.Ey_ele_last_track_at_probes = -1
if 'probes_position' in kwargs.keys():
if 'probes_position' in list(kwargs.keys()):
self.save_ele_field_probes = True
self.probes_position = kwargs['probes_position']
self.N_probes = len(self.probes_position)
self.x_probes = []
self.y_probes = []
for ii_probe in xrange(self.N_probes):
for ii_probe in range(self.N_probes):
self.x_probes.append(self.probes_position[ii_probe]['x'])
self.y_probes.append(self.probes_position[ii_probe]['y'])

Expand Down Expand Up @@ -236,7 +236,7 @@ def track(self, beam):

if self.track_only_first_time:
if self.N_tracks > 0:
print 'Warning: Track skipped because track_only_first_time is True.'
print('Warning: Track skipped because track_only_first_time is True.')
return

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

slices = beam.get_slices(self.slicer)

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

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

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

self.N_tracks += 1

def replace_with_recorded_field_map(self, delete_ecloud_data=True):

if self.track_only_first_time:
print 'Warning: replace_with_recorded_field_map resets track_only_first_time = False'
print('Warning: replace_with_recorded_field_map resets track_only_first_time = False')
self.track_only_first_time = False

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

else:
print 'Warning: efieldmap already exists. I do nothing.'
print('Warning: efieldmap already exists. I do nothing.')

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

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

# Acquire bunch passage information
if hasattr(slic, 'slice_info'):
if 'info_parent_bunch' in slic.slice_info.keys():
if 'info_parent_bunch' in list(slic.slice_info.keys()):

# check if first slice of first bunch
if slic.slice_info['info_parent_bunch']['i_bunch'] == 0 and slic.slice_info['i_slice'] == 0:
Expand Down
2 changes: 1 addition & 1 deletion Transverse_Efield_map_for_frozen_cloud.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ def track(self, beam):
slices = beam.get_slices(self.slicer)

sid = 0
for _ in xrange(slices.n_slices):
for _ in range(slices.n_slices):

sid -= 1

Expand Down
Loading

0 comments on commit 07456d7

Please sign in to comment.