simba.Codes.Ocelot package
Submodules
simba.Codes.Ocelot.Ocelot module
SIMBA Ocelot Module
Various objects and functions to handle OCELOT lattices and commands. See Ocelot github for more details.
- Classes:
ocelotLattice: The Ocelot lattice object, used for
converting the
frameworkObjects defined in theframeworkLatticeinto an Ocelot lattice object, and for tracking through it.
- class ocelotLattice(*args, **kwargs)[source]
Bases:
frameworkLatticeClass for defining the OCELOT lattice object, used for converting the
frameworkLatticeinto an Ocelot lattice object, and for tracking through it.- Parameters:
args (
Any)kwargs (
Any)
-
code:
str= 'ocelot' String indicating the lattice object type
-
final_screen:
Any= None Final screen object
- hdf5_to_npz(prefix='', write=True)[source]
Convert the initial HDF5 particle distribution to Ocelot format and set
pinaccordingly.- Parameters:
prefix (str) – Prefix for particle file
write (bool) – Flag to indicate whether to save the file
- Return type:
None
-
lat_obj:
Any= None Lattice object as an Ocelot MagneticLattice
-
lsc:
bool= True Flag to enable LSC calculations
-
mbi:
Dict= {} Dictionary containing settings for microbunching gain calculation
Physics process for calculating microbunching gain
-
mbin_csr:
int= 5 Number of macroparticle bins for CSR calculations
-
names:
List= None Names of elements in the lattice
Set up the physics processes for Ocelot (i.e. space charge, CSR, wakes etc).
- Returns:
An Ocelot Navigator object
- Return type:
Navigator
-
nbin_csr:
int= 10 Number of longitudinal bins for CSR calculations
-
oceglobal:
Dict= {} Global settings for Ocelot, read in from ocelotLattice.settings[“global”][“OCELOTsettings”] and ocelot_defaults.yaml
-
particle_definition:
str= None Initial particle distribution as a string
- physproc_beamtransform(tws)[source]
Get an Ocelot `BeamTransform`_ physics process based on the wakefield provided.
- Parameters:
tws (Ocelot Twiss object) – Object containing Twiss parameters
- Returns:
A BeamTransform PhysProc
- Return type:
tuple
- physproc_csr()[source]
Get Ocelot CSR physics processes based on the start and end positions provided in file_block. If these are not provided, just include CSR for the entire lattice.
- Returns:
A list of CSR PhysProcs, and their start and end positions
- Return type:
tuple
- physproc_lsc()[source]
Get an Ocelot `LSC`_ physics process
- Returns:
The Ocelot LSC PhysProc
- Return type:
LSC
- physproc_sc(grids)[source]
Get an Ocelot SpaceCharge physics process
- Parameters:
grids (List[int]) – The space charge grid number in x,y,z
- Returns:
The Ocelot SpaceCharge PhysProc
- Return type:
SpaceCharge
- physproc_wake(name, loc, ncell)[source]
Get an Ocelot `Wake`_ physics process based on the wakefield provided.
- Parameters:
name (str) – Name of lattice object associated with the wake
loc (
fieldor str) – If field, then write the field file to ASTRA formatncell (int) – Number of cells, which provides a multiplication factor for the wake
- Returns:
A Wake PhysProc, and its index in the lattice
- Return type:
tuple
-
pin:
Any= None Initial particle distribution as an Ocelot ParticleArray
- postProcess()[source]
Convert the outputs from Ocelot to HDF5 format and save them to master_subdir.
- Return type:
None
-
pout:
Any= None Final particle distribution as an Ocelot ParticleArray
- preProcess()[source]
Get the initial particle distribution defined in file_block[‘input’][‘prefix’] if it exists.
- Return type:
None
-
random_mesh:
bool= True Random meshing for space charge calculations
-
ref_idx:
int= None Reference particle index
-
ref_s:
float= None Reference s position
- screen_threaded_function
Function for converting all screen outputs from ELEGANT into the SIMBA generic
beamobject and writing filesalias of
ScatterGatherDescriptor
-
sigmamin_csr:
float= 1e-05 Minimum size for CSR calculations
-
smooth_param:
float= 0.01 Smoothing parameter
-
trackBeam:
bool= True Flag to indicate whether to track the beam
-
wake_factor:
float= 1.0 Multiplication factor for wakefields
-
wake_filter:
int= 10 Filter parameter for wake calculations
-
wake_sampling:
int= 1000 Number of samples for wake calculations
- write()[source]
Create the lattice object via
writeElements()and save it as a python file to master_subdir.- Return type:
None
simba.Codes.Ocelot.mbi module
@author: Alex Brynes Created on 09.12.2024
- class MBI(lattice, step=1, lamb_range=(1e-06, 5e-05, 10), slices=0, lsc=True, csr=True)[source]
Bases:
PhysProcMicrobunching Gain (MBI) calculation physics process
The beam bunching factor is calculated sequentially along the beamline, following Tsai et al. [All equations referenced herein refer to this paper.] At each simulation step, the bunch slice properties and lattice transfer map up to that point are extracted. The bunching factor in the absence of collective effects – b0 – is also calculated. Based on these parameters, the microbunching integral kernel at each previous step is evaluated and multiplied with b0. The bunching factor at a given location z is then the sum of all previous bunching factors. These bunching factors [bf, pf] are then made attributes of the ~ocelot.cpbd.beam.ParticleArray object.
- lattice
MagneticLattice Lattice used during tracking
- step
int [in Navigator.unit_step] step of the MBI calculation
- lamb_range
tuple Initial wavelength modulation range (metres) [min, max, num_steps]
- slices
int
- Number of time-slices across which to calculate beam slice properties
- Type:
zero takes only the central slice
- lsc
bool Include LSC impedance
- csr
bool Include CSR impedance
- Parameters:
lattice (
MagneticLattice)step (
float)lamb_range (
list)slices (
int)lsc (
bool)csr (
bool)
- apply(p_array, dz)[source]
Apply MBI calculation. Calculates beam slice parameters and optics map, used as input to ~get_bf or ~get_bf_slice. Then updates self.bf and self.pf.
- Parameters:
p_array (
ParticleArray) – particle array objectdz (
float) – step
- Return type:
None
- csrimpedance(lamb, elem)[source]
CSR impedance (Eq. (51))
- Parameters:
lamb (
float) – initial modulation wavelengthelem (
Element) – Ocelot element object
- Return type:
float- Returns:
CSR impedance
- get_bf(lamb_range, slice_params, optics_map, elem)[source]
Calculate bunching factor at the current position (see Eq. (58))
- Parameters:
lamb_range (
list) – range of initial modulation wavelengths [m]slice_params (
list) – list of dicts containing beam slice propertiesoptics_map (
list) – list of first-order transfer matriceselem (
Element) – Ocelot element at the current position
- Return type:
list- Returns:
bunching factors in z and p
- get_bf_slice(lamb_range, slice_params, optics_map, slices, elem)[source]
Calculate bunching factor at the current position (see Eq. (58)) across longitudinal bunch slices
- Parameters:
lamb_range (
list) – range of initial modulation wavelengths [m]slice_params (
list) – list of dicts containing beam slice propertiesoptics_map (
list) – list of first-order transfer matricesslices (
int) – number of slices over which to calculate beam slice properties and bunching factorselem (
Element) – Ocelot element at the current position
- Return type:
list- Returns:
bunching factors in z and p
- get_slice_params(p_array, slices=False)[source]
Calculate beam slice parameters
- Parameters:
p_array (
ParticleArray) – Particle array objectslices (
bool) – if true, calculate beam properties along the full slice; if false, calculate slice properties of the central slice
- Return type:
dict- Returns:
dictionary containing relevant slice parameters obtained from Ocelot global slice analysis
- kernel_K0(lamb, slice_params, optics_map, i1, elem)[source]
Kernel K0 (Eq. (A17a))
- Parameters:
lamb (
float) – initial modulation wavelength [m]slice_params (
list) – list of dicts containing beam slice propertiesoptics_map (
list) – list of first-order transfer matricesi1 (
int) – index from which to calculateelem (
Element) – Ocelot element at the current position
- Return type:
float- Returns:
K0
- kernel_K1(lamb, slice_params, optics_map, i1, elem)[source]
Kernel K1 (Eq. (A17b))
- Parameters:
lamb (
float) – initial modulation wavelength [m]slice_params (
list) – list of dicts containing beam slice propertiesoptics_map (
list) – list of first-order transfer matricesi1 (
int) – index from which to calculateelem (
Element) – Ocelot element at the current position
- Return type:
float- Returns:
K1
- kernel_K2(lamb, slice_params, optics_map, i1, elem)[source]
Kernel K2 (Eq. (A17c))
- Parameters:
lamb (
float) – initial modulation wavelength [m]slice_params (
list) – list of dicts containing beam slice propertiesoptics_map (
list) – list of first-order transfer matricesi1 (
int) – index from which to calculateelem (
Element) – Ocelot element at the current position
- Return type:
float- Returns:
K2
- kernels(lamb, slice_params, optics_map, i1, elem)[source]
Kernels (Eq. (A17a + b))
- Parameters:
lamb (
float) – initial modulation wavelength [m]slice_params (
list) – list of dicts containing beam slice propertiesoptics_map (
list) – list of first-order transfer matricesi1 (
int) – index from which to calculateelem (
Element) – Ocelot element at the current position
- Return type:
list- Returns:
K0, K1, K2
- ld0s(lamb, slice_params, optics_map)[source]
Landau damping between first lattice point and subsequent points (Eq. (46))
- Parameters:
lamb (
list) – initial modulation wavelength [m]slice_params (
list) – list of dicts containing beam slice propertiesoptics_map (
list) – list of first-order transfer matrices
- Return type:
float- Returns:
Landau damping factor LD(0->s)
- ldtaus(lamb, slice_params, optics_map, i1)[source]
Landau damping between two lattice elements (Eq. (50))
- Parameters:
lamb (
list) – initial modulation wavelength [m]slice_params (
list) – list of dicts containing beam slice propertiesoptics_map (
list) – list of first-order transfer matricesi1 (
int) – index from which to calculate
- Return type:
float- Returns:
Landau damping factor LD(tau,s)
- lscimpedance(lamb, slice_params, i1)[source]
LSC impedance (Eq. (52), although here we use a function from PRAB. 23, 014403 (Eq. 26))
- Parameters:
lamb (
float) – initial modulation wavelengthslice_params (
list) – list of dicts containing beam slice propertiesi1 (
int) – index from which to calculate
- Return type:
float- Returns:
LSC impedance
- r56taus(optics_map, i1)[source]
R56 transport parameter between beamline elements (Eq. (49))
- Parameters:
optics_map (
list) – list of first-order transfer matricesi1 (
int) – index from which to calculate
- Return type:
float- Returns:
R56(tau->s)
- b0(lamb, I0)[source]
initial longitudinal bunch factor form shot noise
- Parameters:
lamb (
float) – initial modulation wavelength [m]I0 (
float) – beam current [A]
- k_wn(lamb)[source]
uncompressed wave number in [1/m]
- Parameters:
lamb (
float) – initial modulation wavelength [m]- Returns:
conversion from lambda to k [1/m]
- lattice_transfer_map_z(lattice, energy, zfin)[source]
Function calculates transfer maps, first order only, for the whole lattice, up to zfin.
- Parameters:
lattice – MagneticLattice
energy – the initial electron beam energy [GeV]
zfin – the final z position in the accelerator lattice [m]
- Returns:
first_order_tms - matrix
- Returns:
elem - element located at zfin
- p0(lamb, compression_factor, sdelta, r56, b0)[source]
initial momentum bunch factor form shot noise
- Parameters:
lamb (
float) – initial modulation wavelength [m]compression_factor (
float) – beam longitudinal compression factorsdelta (
float) – fractional energy spreadr56 (
float) – R56 from initial to current simulation step [m]b0 (
float) – bunching factor from shot noise (see ~b0I0 – beam current [A]