Skip to content

Commit

Permalink
Merge pull request #121 from PyCOMPLETE/python3_master
Browse files Browse the repository at this point in the history
Python 3 migration of PyECLOUD
  • Loading branch information
giadarol authored Jan 27, 2020
2 parents 54ac6d1 + 08c5cec commit 3a9eb00
Show file tree
Hide file tree
Showing 123 changed files with 2,012 additions and 864 deletions.
6 changes: 0 additions & 6 deletions 000_run_simulation.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,4 @@
import sys, os
BIN = os.path.expanduser("../")
sys.path.append(BIN)


from PyECLOUD.buildup_simulation import BuildupSimulation


sim = BuildupSimulation()
sim.run()
4 changes: 2 additions & 2 deletions 002_change_version_number.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@

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()
if 'giovanni.iadarola@cern.ch' in content:
content = content.replace('PyECLOUD Version 8.2.0', 'PyECLOUD Version 8.2.0')
content = content.replace('PyECLOUD Version 8.4.0', 'PyECLOUD Version 8.4.0')
with open(filename, 'w') as fid:
fid.write(content)

Expand Down
4 changes: 2 additions & 2 deletions 003_change_preamble.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
#
# This file is part of the code:
#
# PyECLOUD Version 8.2.0
# PyECLOUD Version 8.4.0
#
#
# Main author: Giovanni IADAROLA
Expand Down 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
32 changes: 16 additions & 16 deletions MP_system.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
#
# This file is part of the code:
#
# PyECLOUD Version 8.2.0
# PyECLOUD Version 8.4.0
#
#
# Main author: Giovanni IADAROLA
Expand Down 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
Loading

0 comments on commit 3a9eb00

Please sign in to comment.