SimulationFramework.Codes.ASTRA package

Submodules

SimulationFramework.Codes.ASTRA.ASTRA module

Simframe ASTRA Module

Various objects and functions to handle ASTRA lattices and commands. See ASTRA manual for more details.

Classes:

converting the frameworkObject s defined in the frameworkLattice into a string representation of the lattice suitable for an ASTRA input file.

of the ASTRA input file.

of the ASTRA input file.

of the ASTRA input file.

of the ASTRA input file.

of the ASTRA input file.

class astraLattice(*args, **kwargs)[source]

Bases: frameworkLattice

Class for defining the ASTRA lattice object, used for converting the frameworkLattice into a string representation of the lattice suitable for an ASTRA input file.

Parameters:
  • args (Any)

  • kwargs (Any)

allow_negative_drifts: bool = True

Flag to indicate whether negative drifts are allowed

astra_to_hdf5(cathode=False)[source]

Convert the ASTRA particle distribution file to HDF5 format and write to master_subdir.

Parameters:

cathode (bool) – True if the beam was emitted from a cathode.

Return type:

None

property bunch_charge: float

Bunch charge in coulombs

Returns:

Bunch charge

Return type:

float

code: str = 'astra'

String indicating the lattice object type

find_ASTRA_filename(elem, mult, lattice, master_run_no)[source]

Determine if an output was created by ASTRA for a given element based on its position and the filename.

Parameters:
  • elem (:class:`~SimulationFramework.Framework_objects.frameworkElement) – The element to be checked

  • mult (int) – Multiplication factor for formatting ASTRA-type output

  • lattice (str) – The lattice name

  • master_run_no (int) – Master run number for ASTRA-type output (i.e. <filename>.001)

Returns:

True if the file was found.

Return type:

bool

get_screen_scaling()[source]

Determine the screen scaling factor for screens and BPMs

Returns:

The scaling factor depending on the master_run_no parameter

Return type:

int

headers: Dict = {}

Headers to be included in the ASTRA lattice file

postProcess()[source]

Convert the beam file(s) from the ASTRA output into HDF5 format, see astra_to_hdf5().

Return type:

None

preProcess()[source]

Convert the beam file from the previous lattice section into ASTRA format and set the number of particles based on the input distribution, see hdf5_to_astra().

Return type:

None

property sample_interval: int

Factor by which to reduce the number of particles in the simulation, i.e. every 10th particle.

Returns:

The sampling interval n_red in ASTRA

Return type:

int

screen_threaded_function: ClassVar[ScatterGatherDescriptor]

Function for converting all screen outputs from ASTRA into the SimFrame generic beam object and writing files

property space_charge_mode: str

The space charge type for ASTRA, i.e. “2D”, “3D”.

Returns:

The space charge type for ASTRA

Return type:

str

starting_offset: Tuple[float, float, float] = (0, 0, 0)

Initial offset of first element

starting_rotation: Tuple[float, float, float] = (0, 0, 0)

Initial rotation of first element

property toffset: float

Get the time offset for the reference particle.

Returns:

The time offset in seconds

Return type:

float

write()[source]

Writes the ASTRA input file from writeElements() to <master_subdir>/<self.objectname>.in.

Return type:

None

writeElements()[source]

Write the lattice elements defined in this object into an ASTRA-compatible format; see elementObjects.

Elements are grouped together by type and counted using frameworkCounter

The appropriate headers required for ASTRA are written at the top of the file, see the write_ASTRA function in astra_newrun, astra_header, astra_errors.

Returns:

The lattice represented as a string compatible with ASTRA

Return type:

str

class astra_charge(*args, **kwargs)[source]

Bases: astra_header

Class for generating the &CHARGE namelist for ASTRA. See ASTRA manual for more details.

Parameters:
  • args (Any)

  • kwargs (Any)

cathode: bool = False

Flag to indicate whether the bunch was emitted from a cathode.

cell_var: float = 2

Variation of the cell height in radial direction.

framework_dict()[source]

Create formatted dictionary for generating ASTRA &CHARGE namelist, based on the properties of the class.

Returns:

Formatted dictionary for ASTRA &CHARGE

Return type:

Dict

property grid_size: int

Get the number of space charge bins, see getGridSizes().

Returns:

The number of space charge bins based on the number of particles

Return type:

int

grids: getGrids | None = None

Space charge grids

max_scale: float = 0.1

If one of the space charge scaling factors exceeds the limit 1± max_scale a new space charge calculation is initiated.

min_grid: float = 3.424657e-13

Minimum grid length during emission.

nlong_in: int | None = None

Maximum number of grid cells in longitudinal direction within the bunch length.

npart: int = 32768

Number of particles

nrad: int | None = None

Number of grid cells in radial direction up to the bunch radius.

objectname: str = 'charge'

Name of object

objecttype: str = 'astra_charge'

Type of object

sample_interval: int = 1

Downsampling interval calculated as 2 ** (3 * sample_interval)

smooth_x: int = 2

Smoothing parameter for x-direction. Only for 3D FFT algorithm.

smooth_y: int = 2

Smoothing parameter for y-direction. Only for 3D FFT algorithm.

smooth_z: int = 2

Smoothing parameter for z-direction. Only for 3D FFT algorithm.

property space_charge: bool

Flag to indicate whether space charge is enabled.

Returns:

True if enabled

Return type:

bool

space_charge_2D: bool = True

Enable 2D space charge calculations

space_charge_3D: bool = False

Enable 3D space charge calculations

space_charge_mode: str = 'False'

Space charge mode

class astra_errors(*args, **kwargs)[source]

Bases: astra_header

Class for generating the &ERROR namelist for ASTRA. See ASTRA manual for more details.

Parameters:
  • args (Any)

  • kwargs (Any)

generate_output: bool = True

If true an output file will be generated

global_errors: bool = True

If false, no errors will be generated.

log_error: bool = True

If true an additional log file will be generated which contains the actual element and bunch setting

objectname: str = 'astra_error'

Name of object

objecttype: str = 'global_error'

Type of object

suppress_output: bool = False

If true any generation of output other than the error file is suppressed.

write_ASTRA(n)[source]

Write the text for the ASTRA namelist based on its framework_dict.

Parameters:

n (int) – Index of the ASTRA element

Returns:

ASTRA-compatible string representing the namelist

Return type:

str

class astra_header(*args, **kwargs)[source]

Bases: frameworkElement

Generic class for generating ASTRA namelists

Parameters:
  • args (Any)

  • kwargs (Any)

framework_dict()[source]
Return type:

Dict

write_ASTRA(n)[source]

Write the text for the ASTRA namelist based on its framework_dict.

Parameters:

n (int) – Index of the ASTRA element

Returns:

ASTRA-compatible string representing the namelist

Return type:

str

class astra_newrun(*args, **kwargs)[source]

Bases: astra_header

Class for generating the &NEWRUN namelist for ASTRA. See ASTRA manual for more details.

Parameters:
  • args (Any)

  • kwargs (Any)

auto_phase: bool = True

Phase RF cavities automatically

bunch_charge: float | None = None

Bunch charge

check_ref_part: bool = False

If true, the run will be interrupted if the reference particle is lost during the on- and off-axis reference particle tracking.

framework_dict()[source]

Create formatted dictionary for generating ASTRA &NEWRUN namelist, based on the properties of the class.

Returns:

Formatted dictionary for ASTRA &NEWRUN

Return type:

Dict

h_max: float = 0.07

Maximum time step for the Runge-Kutta integration.

h_min: float = 0.07

Minimum time step for the Runge-Kutta integration.

hdf5_to_astra(prefix='', initial_twiss={'horizontal': {}, 'vertical': {}})[source]

Convert beam input file to ASTRA format and write to master_subdir.

Parameters:
  • prefix (str) – File location / name

  • initial_twiss (Dict) – Dictionary containing initial Twiss parameters.

Return type:

None

head: str = 'trial'

Run name

high_res: bool = True

If true, particle distributions are saved with increased accuracy.

input_particle_definition: str = ''

Name of input particle definition

lprompt: bool = False

If true a pause statement is included at the end of the run to avoid vanishing of the window in case of an error.

objectname: str = 'newrun'

Name of object

objecttype: str = 'astra_newrun'

Type of object

offset: list | ndarray = [0, 0, 0]

Beam offset from nominal axis [x,y,z]

output_particle_definition: str = ''

Name of output particle definition

phase_scan: bool = False

If true, the RF phases of the cavities will be scanned between 0 and 360 degree. Results are saved in the PScan file. The tracking between cavities will be done with the user-defined phases.

run: int = 1

Run number

sample_interval: int = 1

Downsampling factor (as 2**(3 * sample_interval))

toffset: float = 0.0

Time offset of reference particle

track_all: bool = True

If false, only the reference particle will be tracked

class astra_output(*args, **kwargs)[source]

Bases: astra_header

Class for generating the &OUTPUT namelist for ASTRA. See ASTRA manual for more details.

Parameters:
  • args (Any)

  • kwargs (Any)

emits: bool = True

If true, output files according to Table 3 and Table 4 are generated. See ASTRA manual

framework_dict()[source]

Create formatted dictionary for generating ASTRA &OUTPUT namelist, based on the properties of the class.

Returns:

Formatted dictionary for ASTRA &OUTPUT

Return type:

Dict

high_res: bool = True

If true, particle distributions are saved with increased accuracy.

lmagnetized: bool = False

If true, solenoid fields are neglected in the calculation of the beam emittance.

objectname: str = 'output'

Name of object

objecttype: str = 'astra_output'

Type of object

offset: list | ndarray = [0, 0, 0]

Beam offset from nominal axis [x,y,z]

phases: bool = True

If true, output files according to Table 3 and Table 4 are generated. See ASTRA manual

refs: bool = True

If true, output files according to Table 3 and Table 4 are generated. See ASTRA manual

screens: Optional[List[screen]] = None

List of screen objects

tracks: bool = True

If true, output files according to Table 3 and Table 4 are generated. See ASTRA manual

SimulationFramework.Codes.ASTRA.ASTRARules module

Module contents