Skip to content

Commit

Permalink
Merge branch 'develop' into python3_master
Browse files Browse the repository at this point in the history
  • Loading branch information
giadarol committed Dec 13, 2019
2 parents 0d30755 + f4a83b0 commit 08c5cec
Show file tree
Hide file tree
Showing 50 changed files with 347 additions and 82 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()
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 'giovanni.iadarola@cern.ch' in content:
content = content.replace('PyECLOUD Version 8.3.0', 'PyECLOUD Version 8.3.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
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 8.3.0
# PyECLOUD Version 8.4.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 8.3.0
# PyECLOUD Version 8.4.0
#
#
# Main author: Giovanni IADAROLA
Expand Down
106 changes: 104 additions & 2 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 8.3.0
# PyECLOUD Version 8.4.0
#
#
# Main author: Giovanni IADAROLA
Expand Down Expand Up @@ -66,6 +66,8 @@ class Empty(object):


class DummyBeamTim(object):
"""Dummy beam-timing class to interface with buildup simulation"""

def __init__(self, PyPIC_state):
self.PyPIC_state = PyPIC_state

Expand Down Expand Up @@ -100,6 +102,8 @@ def get_beam_eletric_field(self, MP_e):

class Ecloud(object):
def generate_twin_ecloud_with_shared_space_charge(self):
"""Generate an identical Ecloud objet with shared space-charge member."""

if hasattr(self, "efieldmap"):
raise ValueError(
"Ecloud has been replaced with field map. I cannot generate a twin ecloud!"
Expand Down Expand Up @@ -136,8 +140,105 @@ def __init__(
force_interp_at_substeps_interacting_slices=False,
**kwargs
):
"""
Construct an e-cloud object that can be inserted in a PyHEADTAIL machine
Parameters
---------
L_ecloud : m
Length of the e-cloud interaction
slicer :
PyHEADTAIL slicer object, used to define slices for e-cloud insteraction.
Needs to be provided only if slice_by_slice_mode is False.
Dt_ref : s
Target duration of the sub-steps perfomed in each slice.
pyecl_input_folder : path
Folder containing the PyECLOUD input files defining the e-cloud.
flag_clean_slices : {True, False}
If True, slicing is redone before the e-cloud interation.
This flag has no effect is slice_by_slice_mode is True.
slice_by_slice_mode : {True, False}
- If False, the e-cloud receives a full bunch, slicing is done interally,
the cloud is automatically re-initialized after each interaction.
- If True, the e-cloud receives one slice at a time (the slice object
should have metadata in a member called slice_info. The reinitialization
of the cloud is done based on the meta-data or esplicitly by the user.
space_charge_obj :
- If None a space-charge object (Particle In Cell) is constructed for
the e-cloud
- If not None the provided space-charge objeci is used
kick_mode_for_beam_field : {True, False}
If True, the force of the beam on the electrons is applied as a
discrete kick (used mainly for fast beam-ion simulations).
beam_monitor :
PyHEADTAIL beam-monitor, used sometimes for debug purposes.
verbose : {True, False}
save_pyecl_outp_as : path
File in which cloud evolution is stored.
force_reinterp_at_substeps_interacting_slices : {True, False}
Fields from beams and clouds are re-interpolated at each subsstep.
x_beam_offset : m
Horizontal position of the PyHEADTAIL reference trajectoy in
the PyECLOUD referece system.
y_beam_offset: m
Vertical position of the PyHEADTAIL reference trajectoy in
the PyECLOUD referece system.
probes_position : dict
Positions at which electron density and field can be measured.
enable_kick_x :
Enable horizontal kick from the cloud on the beam.
enable_kick_y :
Enable vertical kick from the cloud on the beam.
**kwargs :
Any input parameter of PyECLOUD can be passes as a keyword arguments.
Parameters definded in the input files are overridden by those passas as
keyword arguments.
Additional information
----------------------
After building the object, the following members can be set to true to record
additional information (which is then attached as a member to the ecloud object
itself. After setting any of these ot true the [ecloud]._reinitialize
function needs to be called to prepare the data storage, which also resets cloud
state.
[ecloud].save_ele_distributions_last_track
[ecloud].save_ele_potential_and_field
[ecloud].save_ele_potential
[ecloud].save_ele_field
[ecloud].save_ele_MP_position
[ecloud].save_ele_MP_velocity
[ecloud].save_ele_MP_size
[ecloud].save_beam_distributions_last_track
[ecloud].save_beam_potential_and_field
[ecloud].save_beam_potential
[ecloud].save_beam_field
"""

print("PyECLOUD Version 8.3.0")
print("PyECLOUD Version 8.4.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 @@ -264,6 +365,7 @@ def __init__(

self.slice_by_slice_mode = slice_by_slice_mode
if self.slice_by_slice_mode:
assert(slicer is None)
self.track = self._track_in_single_slice_mode
self.finalize_and_reinitialize = self._finalize_and_reinitialize

Expand Down
2 changes: 1 addition & 1 deletion 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 8.3.0
# PyECLOUD Version 8.4.0
#
#
# Main author: Giovanni IADAROLA
Expand Down
4 changes: 2 additions & 2 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 8.3.0
# PyECLOUD Version 8.4.0
#
#
# Main author: Giovanni IADAROLA
Expand Down Expand Up @@ -71,7 +71,7 @@ def __init__(
**kwargs
):

print("PyECLOUD Version 8.3.0")
print("PyECLOUD Version 8.4.0")
(
beamtim,
spacech_ele,
Expand Down
2 changes: 1 addition & 1 deletion cloud_manager.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.3.0
# PyECLOUD Version 8.4.0
#
#
# Author and contact: Giovanni IADAROLA
Expand Down
2 changes: 1 addition & 1 deletion cross_ionization.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.3.0
# PyECLOUD Version 8.4.0
#
#
# Main author: Giovanni IADAROLA
Expand Down
6 changes: 3 additions & 3 deletions default_input_parameters.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,9 +149,9 @@
'B_map_file': None,
'Bz_map_file': None, # documented?
'fact_Bmap': 1.,
'B0x': 0.,
'B0y': 0.,
'B0z': 0.,
'B0x': None,
'B0y': None,
'B0z': None,
'B_zero_thrhld': None,
'N_sub_steps': 1,
'B_multip': [],
Expand Down
Binary file modified doc/reference/reference.pdf
Binary file not shown.
3 changes: 3 additions & 0 deletions doc/reference/src/reference.tex
Original file line number Diff line number Diff line change
Expand Up @@ -416,6 +416,9 @@ \subsection{Simulation parameters}
\\ \hline
\textbf{B\_skew} & The skew parameters can be included through B\_skew. For a skew quadrupole with a gradient of 12 T/m, set B\_multip to [0.,0.] and B\_skew to [0.,12.].
B\_skew specifies $b'_n =\frac{\partial^n B_x}{\partial x^n}$ and defaults to {\it None}. \\ \hline
\textbf{B0x, B0y, B0z} & (optional -- default = 0) \newline
[T] Uniform magnetic fields added to the map.
\\ \hline
\end{longtable}


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 8.3.0
# PyECLOUD Version 8.4.0
#
#
# Main author: Giovanni IADAROLA
Expand Down
66 changes: 37 additions & 29 deletions 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 8.3.0
# PyECLOUD Version 8.4.0
#
#
# Main author: Giovanni IADAROLA
Expand Down Expand Up @@ -57,7 +57,8 @@

class pusher_Boris_multipole():

def __init__(self, Dt, N_sub_steps=1, B_multip=None, B_skew=None):
def __init__(self, Dt, N_sub_steps=1, B_multip=None, B_skew=None,
B0x=None, B0y=None, B0z=None):

self.N_sub_steps = N_sub_steps
self.Dt = Dt
Expand All @@ -79,40 +80,47 @@ def __init__(self, Dt, N_sub_steps=1, B_multip=None, B_skew=None):
else:
self.B_field_skew = np.array(B_skew, dtype=float) / factorial

self.B0x = B0x
self.B0y = B0y
self.B0z = B0z
print("Tracker: Boris multipole")

print("N_subst_init=%d" % self.N_sub_steps)

#@profile
def step(self, MP_e, Ex_n, Ey_n, Ez_n=0., Bx_n=np.asarray([0.]), By_n=np.asarray([0.]), Bz_n=np.asarray([0.])):

if (Bx_n == np.asarray([0.])).all() and (By_n == np.asarray([0.])).all() and (Bz_n == np.asarray([0.])).all():
custom_B = 0
else:
custom_B = 1

if MP_e.N_mp > 0:

xn1 = MP_e.x_mp[0:MP_e.N_mp]
yn1 = MP_e.y_mp[0:MP_e.N_mp]
zn1 = MP_e.z_mp[0:MP_e.N_mp]
vxn1 = MP_e.vx_mp[0:MP_e.N_mp]
vyn1 = MP_e.vy_mp[0:MP_e.N_mp]
vzn1 = MP_e.vz_mp[0:MP_e.N_mp]
if Ez_n != 0.:
raise ValueError('Oooops! Not implemented....')
def step(self, MP_e, Ex_n, Ey_n, Ez_n=0., Bx_n=None, By_n=None, Bz_n=None):
MP_e = self.stepcustomDt(MP_e, Ex_n, Ey_n, Ez_n,
Bx_n, By_n, Bz_n,
Dt_substep=self.Dtt, N_sub_steps=self.N_sub_steps)
return MP_e

boris_step_multipole(self.N_sub_steps, self.Dtt, self.B_field, self.B_field_skew,
xn1, yn1, zn1, vxn1, vyn1, vzn1,
Ex_n, Ey_n, Bx_n, By_n, Bz_n, custom_B, MP_e.charge, MP_e.mass)
def stepcustomDt(self, MP_e, Ex_n, Ey_n, Ez_n=0.,
Bx_n=None, By_n=None, Bz_n=None,
Dt_substep=None, N_sub_steps=None):

return MP_e
custom_B = 0
Bx_arr = np.zeros(MP_e.N_mp)
By_arr = np.zeros(MP_e.N_mp)
Bz_arr = np.zeros(MP_e.N_mp)

def stepcustomDt(self, MP_e, Ex_n, Ey_n, Ez_n=0., Bx_n=np.asarray([0.]), By_n=np.asarray([0.]), Bz_n=np.asarray([0.]), Dt_substep=None, N_sub_steps=None):
if self.B0x is not None:
Bx_arr += self.B0x
custom_B = 1
if self.B0y is not None:
By_arr += self.B0y
custom_B = 1
if self.B0z is not None:
Bz_arr += self.B0z
custom_B = 1

if (Bx_n == np.asarray([0.])).all() and (By_n == np.asarray([0.])).all() and (Bz_n == np.asarray([0.])).all():
custom_B = 0
else:
if Bx_n is not None:
Bx_arr += Bx_n
custom_B = 1
if By_n is not None:
By_arr += By_n
custom_B = 1
if Bz_n is not None:
Bz_arr += Bz_n
custom_B = 1

if MP_e.N_mp > 0:
Expand All @@ -128,7 +136,7 @@ def stepcustomDt(self, MP_e, Ex_n, Ey_n, Ez_n=0., Bx_n=np.asarray([0.]), By_n=np
raise ValueError('Oooops! Not implemented....')

boris_step_multipole(N_sub_steps, Dt_substep, self.B_field, self.B_field_skew,
xn1, yn1, zn1, vxn1, vyn1, vzn1,
Ex_n, Ey_n, Bx_n, By_n, Bz_n, custom_B, MP_e.charge, MP_e.mass)
xn1, yn1, zn1, vxn1, vyn1, vzn1,
Ex_n, Ey_n, Bx_arr, By_arr, Bz_arr, custom_B, MP_e.charge, MP_e.mass)

return MP_e
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 8.3.0
# PyECLOUD Version 8.4.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 8.3.0
# PyECLOUD Version 8.4.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 8.3.0
# PyECLOUD Version 8.4.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 8.3.0
# PyECLOUD Version 8.4.0
#
#
# Main author: Giovanni IADAROLA
Expand Down
Loading

0 comments on commit 08c5cec

Please sign in to comment.