Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
giadarol committed Jun 11, 2018
2 parents b48e140 + 5099ddc commit 7affa66
Show file tree
Hide file tree
Showing 55 changed files with 409 additions and 58 deletions.
2 changes: 1 addition & 1 deletion 002_change_version_number.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
with open(filename) as fid:
content=fid.read()
if '[email protected]' in content:
content=content.replace('PyECLOUD Version 7.2.0', 'PyECLOUD Version 7.2.0')
content=content.replace('PyECLOUD Version 7.3.0', 'PyECLOUD Version 7.3.0')
with open(filename,'w') as fid:
fid.write(content)

Expand Down
2 changes: 1 addition & 1 deletion 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 7.2.0
# PyECLOUD Version 7.3.0
#
#
# Main author: Giovanni IADAROLA
Expand Down
2 changes: 1 addition & 1 deletion 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 7.2.0
# PyECLOUD Version 7.3.0
#
#
# Main author: Giovanni IADAROLA
Expand Down
13 changes: 9 additions & 4 deletions PyEC4PyHT.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 7.2.0
# PyECLOUD Version 7.3.0
#
#
# Main author: Giovanni IADAROLA
Expand Down Expand Up @@ -84,7 +84,7 @@ def __init__(self, L_ecloud, slicer, Dt_ref, pyecl_input_folder='./', flag_clean
beam_monitor=None, verbose=False,
**kwargs):

print 'PyECLOUD Version 7.2.0'
print 'PyECLOUD Version 7.3.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 Down Expand Up @@ -155,7 +155,7 @@ def __init__(self, L_ecloud, slicer, Dt_ref, pyecl_input_folder='./', flag_clean

self.N_tracks = 0

self.cloudsim.spacech_ele.flag_decimate = False
#self.cloudsim.spacech_ele.flag_decimate = False



Expand Down Expand Up @@ -310,16 +310,21 @@ def _track_single_slice(self, beam, ix, dz):
dummybeamtim.tt_curr = self.cloudsim.t_sc_ON + 1. # In order to have the PIC activated
dummybeamtim.lam_t_curr = np.mean(beam.particlenumber_per_mp/dz)*len(ix)
dummybeamtim.Dt = dt
dummybeamtim.Dt_curr = dt
dummybeamtim.sigmax = np.std(beam.x[ix])
dummybeamtim.sigmay = np.std(beam.y[ix])
dummybeamtim.x_beam_pos = np.mean(beam.x[ix])+self.x_beam_offset
dummybeamtim.y_beam_pos = np.mean(beam.y[ix])+self.y_beam_offset
dummybeamtim.flag_new_bunch_pass = False

# Force space charge recomputation (to be switched between bunches in multibunch mode)
force_recompute_space_charge = True

# Perform cloud simulation step
self.cloudsim.sim_time_step(beamtim_obj=dummybeamtim,
Dt_substep_custom=Dt_substep, N_sub_steps_custom=N_sub_steps,
kick_mode_for_beam_field=self.kick_mode_for_beam_field)
kick_mode_for_beam_field=self.kick_mode_for_beam_field,
force_recompute_space_charge=force_recompute_space_charge)


# Build MP_system-like object with beam coordinates
Expand Down
29 changes: 25 additions & 4 deletions beam_and_timing.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 7.2.0
# PyECLOUD Version 7.3.0
#
#
# Main author: Giovanni IADAROLA
Expand Down Expand Up @@ -94,6 +94,8 @@ def __init__(self,flag_bunched_beam, fact_beam, coast_dens, beam_charge, beam_fi
if chamb.is_outside(np.array([x_beam_pos]),np.array([y_beam_pos])):
raise ValueError('The beam is outside the chamber!')

flag_unif_Dt = True

if flag_bunched_beam:
print 'Start beam profile generation.'

Expand Down Expand Up @@ -130,11 +132,23 @@ def __init__(self,flag_bunched_beam, fact_beam, coast_dens, beam_charge, beam_fi
lam_t_array=bunch_train4(t, b_spac,t_offs,ppb_vect,sigmaz_vect);
print 'Done beam profile generation.'
else:
print 'Loading beam profile from file:'
print beam_long_prof_file

dict_lam=sio.loadmat(beam_long_prof_file)
t=np.squeeze(dict_lam['t'].real)
lam_t_array=np.squeeze(dict_lam['lam_t_array'].real)
t_inter=t[-1]
Dt=t[1]-t[0]

Dt_vect = np.diff(t)
if (np.max(np.abs(Dt_vect))-np.mean(np.abs(Dt_vect))) > 1e-4*np.mean(np.abs(Dt_vect)):
flag_unif_Dt = False
else:
print 'Beam profile loaded from file.'
print 'Uniform time step detected.'
print 'The time step Dt provided in simulation_parameters.input will be ignored.'
Dt=t[1]-t[0]
print 'Time step set to Dt = %.3e s.'%Dt

if flag_secodary_beam:
if len(t)!=len(t_primary_beam):
Expand Down Expand Up @@ -284,7 +298,8 @@ def __init__(self,flag_bunched_beam, fact_beam, coast_dens, beam_charge, beam_fi


else:
print 'Loading beam field map from file'
print 'Loading beam field map from file:'
print beam_field_file
dict_beam=sio.loadmat(beam_field_file)

Ex_beam=np.squeeze(dict_beam['Ex'].real)
Expand Down Expand Up @@ -316,6 +331,11 @@ def __init__(self,flag_bunched_beam, fact_beam, coast_dens, beam_charge, beam_fi
self.xx_beam=xx_beam
self.yy_beam=yy_beam

if not(flag_unif_Dt):
print 'Cloud simulation in non-uniform Dt mode.'
print 'Dt provided in input will be used only as reference for savings and substeps.'

self.flag_unif_Dt=flag_unif_Dt
self.Nt=Nt
self.b_spac=b_spac
self.lam_t_array=lam_t_array
Expand Down Expand Up @@ -343,6 +363,7 @@ def __init__(self,flag_bunched_beam, fact_beam, coast_dens, beam_charge, beam_fi
def next_time_step(self):
self.ii_curr+=1
self.tt_curr=self.t[self.ii_curr]
self.Dt_curr=self.t[self.ii_curr+1]-self.t[self.ii_curr]
self.lam_t_curr=self.lam_t_array[self.ii_curr]
self.pass_numb=int(np.floor(self.tt_curr/self.b_spac));
self.flag_new_bunch_pass=(self.pass_numb>self._pass_numb_old)
Expand All @@ -352,7 +373,7 @@ def next_time_step(self):


def end_simulation(self):
return ((self.ii_curr+1)>=self.Nt)
return ((self.ii_curr+2)>=self.Nt) # I need the last point to compute Dt

def get_beam_eletric_field(self, MP_e):

Expand Down
28 changes: 20 additions & 8 deletions buildup_simulation.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
#
# This file is part of the code:
#
# PyECLOUD Version 7.2.0
# PyECLOUD Version 7.3.0
#
#
# Main author: Giovanni IADAROLA
Expand Down Expand Up @@ -60,7 +60,7 @@ class BuildupSimulation(object):
def __init__(self, pyecl_input_folder='./', skip_beam=False, skip_spacech_ele=False,
skip_pyeclsaver=False, ignore_kwargs=[], spacech_ele=None, **kwargs):

print 'PyECLOUD Version 7.2.0'
print 'PyECLOUD Version 7.3.0'
beamtim, spacech_ele, t_sc_ON, flag_presence_sec_beams, sec_beams_list, \
config_dict, flag_multiple_clouds, cloud_list = init.read_input_files_and_init_components(\
pyecl_input_folder=pyecl_input_folder,
Expand Down Expand Up @@ -112,7 +112,8 @@ def run(self, t_end_sim = None):



def sim_time_step(self, beamtim_obj=None, Dt_substep_custom=None, N_sub_steps_custom=None, kick_mode_for_beam_field=False):
def sim_time_step(self, beamtim_obj=None, Dt_substep_custom=None, N_sub_steps_custom=None, kick_mode_for_beam_field=False,
force_recompute_space_charge=False):

if beamtim_obj is not None:
beamtim = beamtim_obj
Expand All @@ -128,6 +129,7 @@ def sim_time_step(self, beamtim_obj=None, Dt_substep_custom=None, N_sub_steps_cu

flag_recompute_space_charge = spacech_ele.check_for_recomputation(t_curr=beamtim.tt_curr)


# Loop over clouds: gather fields, move, generate new MPs
for i_cloud, cloud in enumerate(cloud_list):
MP_e = cloud.MP_e
Expand Down Expand Up @@ -170,9 +172,19 @@ def sim_time_step(self, beamtim_obj=None, Dt_substep_custom=None, N_sub_steps_cu
old_pos=MP_e.get_positions()

## Motion
if Dt_substep_custom is None and N_sub_steps_custom is None:
if Dt_substep_custom is None and N_sub_steps_custom is None and beamtim.flag_unif_Dt:
# Standard simulation mode
MP_e = dynamics.step(MP_e, Ex_n, Ey_n)
elif Dt_substep_custom is None and N_sub_steps_custom is None and not(beamtim.flag_unif_Dt):
# Dt from non-uniform beam profile
if self.config_dict['track_method'] not in ['Boris', 'BorisMultipole']:
raise ValueError("""track_method should be 'Boris' or 'BorisMultipole' to use custom substeps!""")
Dt_substep_target = cloud.dynamics.Dt/cloud.dynamics.N_sub_steps
N_substeps_curr = np.round(beamtim.Dt_curr/Dt_substep_target)
Dt_substep_curr = beamtim.Dt_curr/N_substeps_curr
MP_e = dynamics.stepcustomDt(MP_e, Ex_n, Ey_n, Dt_substep=Dt_substep_curr, N_sub_steps=N_substeps_curr)
else:
# Custom steps and substeps provided as arguments of sim_time_step
if self.config_dict['track_method'] not in ['Boris', 'BorisMultipole']:
raise ValueError("""track_method should be 'Boris' or 'BorisMultipole' to use custom substeps!""")
MP_e = dynamics.stepcustomDt(MP_e, Ex_n, Ey_n, Dt_substep=Dt_substep_custom, N_sub_steps=N_sub_steps_custom)
Expand All @@ -182,11 +194,11 @@ def sim_time_step(self, beamtim_obj=None, Dt_substep_custom=None, N_sub_steps_cu

## Gas ionization (main and secondary beams)
if(beamtim.tt_curr<t_ion and gas_ion_flag==1):
MP_e = resgasion.generate(MP_e, beamtim.lam_t_curr, beamtim.Dt, beamtim.sigmax, beamtim.sigmay,
MP_e = resgasion.generate(MP_e, beamtim.lam_t_curr, beamtim.Dt_curr, beamtim.sigmax, beamtim.sigmay,
x_beam_pos = beamtim.x_beam_pos, y_beam_pos = beamtim.y_beam_pos)
if flag_presence_sec_beams:
for sec_beam in sec_beams_list:
MP_e = resgasion.generate(MP_e, sec_beam.lam_t_curr, sec_beam.Dt, sec_beam.sigmax, sec_beam.sigmay,
MP_e = resgasion.generate(MP_e, sec_beam.lam_t_curr, sec_beam.Dt_curr, sec_beam.sigmax, sec_beam.sigmay,
x_beam_pos = sec_beam.x_beam_pos, y_beam_pos = sec_beam.y_beam_pos)

## Photoemission (main and secondary beams)
Expand All @@ -195,10 +207,10 @@ def sim_time_step(self, beamtim_obj=None, Dt_substep_custom=None, N_sub_steps_cu
if flag_presence_sec_beams:
for sec_beam in sec_beams_list:
lam_curr_phem += sec_beam.lam_t_curr
phemiss.generate(MP_e, lam_curr_phem, beamtim.Dt)
phemiss.generate(MP_e, lam_curr_phem, beamtim.Dt_curr)

# Compute space charge field
if (beamtim.tt_curr>t_sc_ON) and flag_recompute_space_charge:
if ((beamtim.tt_curr>t_sc_ON) and flag_recompute_space_charge) or force_recompute_space_charge:
flag_reset = cloud is cloud_list[0] # The first cloud resets the distribution
flag_solve = cloud is cloud_list[-1] # The last cloud computes the fields
spacech_ele.recompute_spchg_efield(MP_e, flag_solve=flag_solve, flag_reset=flag_reset)
Expand Down
2 changes: 1 addition & 1 deletion dynamics_Boris_f2py.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 7.2.0
# PyECLOUD Version 7.3.0
#
#
# Main author: Giovanni IADAROLA
Expand Down
2 changes: 1 addition & 1 deletion dynamics_Boris_multipole.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 7.2.0
# PyECLOUD Version 7.3.0
#
#
# Main author: Giovanni IADAROLA
Expand Down
2 changes: 1 addition & 1 deletion dynamics_dipole.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 7.2.0
# PyECLOUD Version 7.3.0
#
#
# Main author: Giovanni IADAROLA
Expand Down
2 changes: 1 addition & 1 deletion dynamics_strong_B_generalized.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 7.2.0
# PyECLOUD Version 7.3.0
#
#
# Main author: Giovanni IADAROLA
Expand Down
2 changes: 1 addition & 1 deletion electron_emission.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 7.2.0
# PyECLOUD Version 7.3.0
#
#
# Main author: Giovanni IADAROLA
Expand Down
2 changes: 1 addition & 1 deletion gas_ionization_class.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 7.2.0
# PyECLOUD Version 7.3.0
#
#
# Main author: Giovanni IADAROLA
Expand Down
2 changes: 1 addition & 1 deletion gen_photoemission_class.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 7.2.0
# PyECLOUD Version 7.3.0
#
#
# Main author: Giovanni IADAROLA
Expand Down
2 changes: 1 addition & 1 deletion geom_impact_ellip.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 7.2.0
# PyECLOUD Version 7.3.0
#
#
# Main author: Giovanni IADAROLA
Expand Down
2 changes: 1 addition & 1 deletion geom_impact_poly.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 7.2.0
# PyECLOUD Version 7.3.0
#
#
# Main author: Giovanni IADAROLA
Expand Down
2 changes: 1 addition & 1 deletion geom_impact_poly_fast_impact.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 7.2.0
# PyECLOUD Version 7.3.0
#
#
# Main author: Giovanni IADAROLA
Expand Down
2 changes: 1 addition & 1 deletion geom_impact_rect_fast_impact.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 7.2.0
# PyECLOUD Version 7.3.0
#
#
# Main author: Giovanni IADAROLA
Expand Down
2 changes: 1 addition & 1 deletion h000_find_and_modify_preamble.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
#
# This file is part of the code:
#
# PyECLOUD Version 7.2.0
# PyECLOUD Version 7.3.0
#
#
# Main author: Giovanni IADAROLA
Expand Down
2 changes: 1 addition & 1 deletion impact_management_class.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 7.2.0
# PyECLOUD Version 7.3.0
#
#
# Main author: Giovanni IADAROLA
Expand Down
Loading

0 comments on commit 7affa66

Please sign in to comment.