simba.Codes.Elegant package

Submodules

simba.Codes.Elegant.Elegant module

SIMBA ELEGANT Module

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

Classes:

converting the frameworkObject s defined in the frameworkLattice into a string representation of the lattice suitable for ELEGANT input and lattice files.

commands in an ELEGANT input file.

&global_settings portion of the ELEGANT input file.

&run_setup portion of the ELEGANT input file.

&error_elements portion of the ELEGANT input file.

&error_elements portion of the ELEGANT input file.

&scan_elements portion of the ELEGANT input file.

&run_control portion of the ELEGANT input file.

&twiss_output portion of the ELEGANT input file.

&floor_coordinates portion of the ELEGANT input file.

&matrix_output portion of the ELEGANT input file.

&sdds_beam portion of the ELEGANT input file.

&track portion of the ELEGANT input file.

&track portion of the ELEGANT input file.

commands for optimization in the ELEGANT input file.

  • sddsFile: Class for creating, modifying and

saving SDDS files.

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

Bases: frameworkCommand

Generic class for generating elements for an ELEGANT input file

Parameters:
  • args (Any)

  • kwargs (Any)

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

Bases: frameworkLattice

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

Parameters:
  • args (Any)

  • kwargs (Any)

allow_negative_drifts: bool = False

Flag to indicate whether negative drifts are allowed

alphax: float | None = None

Initial alpha_x for matching

alphay: float | None = None

Initial alpha_y for matching

betax: float | None = None

Initial beta_x for matching

betay: float | None = None

Initial beta_y for matching

bunch_charge: float | None = None

Bunch charge

code: str = 'elegant'

String indicating the lattice object type

commandFiles: Dict = {}

Dictionary of elegantCommandFile objects for writing to the ELEGANT input file

commandFilesOrder: List = []

Order in which commands are to be written in the ELEGANT input file

createCommandFiles()[source]

Create the elegantCommandFile objects based on the run settings, lattice and beam parameters, including scans of elements, if defined.

Updates commandFiles and commandFilesOrder

Return type:

None

elegantCommandFile(*args, **kwargs)[source]
final_screen: Any = None

simba.Elements.screen.screen object at the end of the line

hdf5_to_sdds(write=True)[source]

Convert the HDF5 beam input file to an SDDS file, and create a charge object as the first element

Parameters:

write (bool)

Return type:

None

particle_definition: str | None = None

String representation of the initial particle distribution

postProcess()[source]

PostProcess the simulation results, i.e. gather the screens and markers and write their outputs to HDF5.

commandFiles is also cleared

Return type:

None

preProcess()[source]

Prepare the input distribution for ELEGANT based on the prefix in the settings file for this lattice section, and create the ELEGANT command files.

Return type:

None

processElementErrors(elementErrors)[source]

Process the elementErrors dictionary to prepare it for use with the current lattice section in ELEGANT

Parameters:

elementErrors (Dict) – Dictionary of element names and error definitions

Returns:

Formatted dictionary of errors on elements

Return type:

Dict

processElementScan(elementScan, nsteps)[source]

Process the elementScan dictionary to prepare it for use with the current lattice section in ELEGANT

#TODO deprecated?

Parameters:
  • elementScan (Dict[name, item]) – Dictionary of elements and parameters to scan

  • nsteps (int)

Returns:

Dictionary of processed elements to scan if valid, else None

Return type:

Dict or None

processRunSettings()[source]

Process the runSettings object to extract the number of runs and the random number seed, and extract error definitions or a parameter scan definiton pertaining to this lattice section.

Returns:

nruns: Number of runs seed: Random number seedoutput elementErrors: Dict of errors on elements elementScan: Dict of elements and parameters to scan

Return type:

tuple

q: Any = None

charge object

ref_idx: int = None

Reference particle index

run()[source]

Run the code with input ‘filename’

screen_threaded_function: ClassVar[ScatterGatherDescriptor]

Function for converting all screen outputs from ELEGANT into the SIMBA generic beam object and writing files

sdds_to_hdf5(screen, toffset=0.0, ref_index=None)[source]

Convert the SDDS beam file name to HDF5 format and write the beam file.

Parameters:
  • screen (PAdantic.models.diagnostic.DiagnosticElement) – PAdantic DiagnosticElement

  • sddsindex (int) – Index for SDDS file

  • toffset (float, optional) – Temporal offset

  • ref_index (int, optional) – Reference particle index

Return type:

None

trackBeam: bool = True

Flag to indicate whether to track the beam

write()[source]

Write the ELEGANT lattice and command files to master_subdir using the functions writeElements() and based on the output of createCommandFiles().

Return type:

None

writeElements()[source]

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

Returns:

The lattice represented as a string compatible with ELEGANT

Return type:

str

class elegantOptimisation(*args: Any, **kwargs: Any)[source]

Bases: elegantCommandFile

Class for generating input commands for ELEGANT optimisation. See Elegant optimization variable , Elegant optimization constraint , and Elegant optimization term

add_optimisation_constraint(name, item=None, lower=None, upper=None)[source]

Add an optimization constraint and create the command

Parameters:
  • name (str) – Element name

  • item (str) – Element parameter to be constrained

  • lower (float) – Lower limit allowed for item

  • upper (float) – Upper limit allowed for item

add_optimisation_term(name, item=None, **kwargs)[source]

Add an optimization term and create the command

Parameters:
  • name (str) – Element name

  • item (str) – Element parameter to be constrained

add_optimisation_variable(name, item=None, lower=None, upper=None, step=None, restrict_range=None)[source]

Add an optimization variable and create the command

Parameters:
  • name (str) – Element name

  • item (str) – Element parameter to be varied

  • lower (float) – Lower limit allowed for item

  • upper (float) – Upper limit allowed for item

  • step (int) – Specifies grid size for optimization algorithm

  • restrict_range (int) – If nonzero, the initial value is forced inside the allowed range

constraints: Dict = {}

Dictionary of constraints for the optimization

settings: Dict = {}

Dictionary of optimization settings

terms: Dict = {}

Dictionary of terms to be optimized

variables: Dict = {}

Dictionary of names and variables to be changed

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

Bases: elegantCommandFile

Error control for an ELEGANT input file; see Elegant error control

Parameters:
  • args (Any)

  • kwargs (Any)

elementErrors: Dict = None

Dictionary of elements with errors

error_log: str = '%s.erl'

File to which errors are to be logged

lattice: frameworkLattice = None

`~simba.Framework_objects.frameworkLattice object

Type:

class

no_errors_for_first_step: int = 1

Perform the first run without errors

nruns: int = 1

Number of error runs to perform

objectname: str = 'error_control'

Name of frameworkObject objectname

objecttype: str = 'error_control'

Name of frameworkObject objecttype

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

Bases: elegantCommandFile

Floor coordinates for an ELEGANT input file; see Elegant floor coordinates

Parameters:
  • args (Any)

  • kwargs (Any)

X0: float = 0.0

Initial horizontal floor position

Y0: float = 0.0

Initial horizontal floor position

Z0: float = 0.0

Initial longitudinal floor position

filename: str = '%s.flr'

Filename for elegant .flr file

lattice: frameworkLattice = None

`~simba.Framework_objects.frameworkLattice object

Type:

class

magnet_centers: float = 0

Global magnet centre

objectname: str = 'floor_coordinates'

Name of object

objecttype: str = 'floor_coordinates'

Type of object

theta0: float = 0.0

Initial global rotation

property x0: float
property y0: float
property z0: float
class elegant_global_settings_command(*args, **kwargs)[source]

Bases: elegantCommandFile

Global settings for an ELEGANT input file; see Elegant global settings

Parameters:
  • args (Any)

  • kwargs (Any)

inhibit_fsync: int = 0

See this parameter in Elegant global settings for more details.

mpi_io_force_file_sync: int = 0

See this parameter in Elegant global settings for more details.

mpi_io_read_buffer_size: int = 16777216

See this parameter in Elegant global settings for more details.

mpi_io_write_buffer_size: int = 16777216

See this parameter in Elegant global settings for more details.

objectname: str = 'global_settings'

Name of object for frameworkObject

objecttype: str = 'global_settings'

Type of object for frameworkObject

usleep_mpi_io_kludge: int = 0

See this parameter in Elegant global settings for more details.

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

Bases: elegantCommandFile

Matrix output for an ELEGANT input file; see Elegant matrix output

Parameters:
  • args (Any)

  • kwargs (Any)

SDDS_output: str = '%s.mat'

File to which matrix data is to be written

SDDS_output_order: int = 2

Matrix output order for the SDDS file

full_matrix_only: int = 0

A flag indicating that only the matrix of the entire accelerator is to be output.

objectname: str = 'matrix_output'

Name of object

objecttype: str = 'matrix_output'

Type of object

property sdds_output: str
property sdds_output_order: int
class elegant_run_control_command(*args, **kwargs)[source]

Bases: elegantCommandFile

Run control for an ELEGANT input file; see Elegant run control

Parameters:
  • args (Any)

  • kwargs (Any)

n_passes: int = 1

Number of passes

n_steps: int = 1

Number of steps

objectname: str = 'run_control'

Name of frameworkObject objectname

objecttype: str = 'run_control'

Name of frameworkObject objecttype

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

Bases: elegantCommandFile

Run setup for an ELEGANT input file; see Elegant run setup

Parameters:
  • args (Any)

  • kwargs (Any)

always_change_p0: int = 1

Match the reference momentum to the beam momentum after each element.

centroid: str = '%s.cen'

File to which centroid data is to be written

default_order: int = 3

The default order of transfer matrices used for elements having matrices.

lattice: frameworkLattice | str = None

`~simba.Framework_objects.frameworkLattice object

Type:

class

lattice_filename: str = None

Name of lattice filename for ELEGANT

objectname: str = 'run_setup'

Name of objectname for elegant run_setup

objecttype: str = 'run_setup'

Name of objecttype for elegant run_setup

pcentral: float = 0.0

Central momentum in units of beta-gamma

s_start: float = 0.0

Starting s position

seed: int = 0

Seed for random number generators

sigma: str = '%s.sig'

File to which sigma data is to be written

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

Bases: elegantCommandFile

Error control for an ELEGANT input file; see Elegant vary element

Parameters:
  • args (Any)

  • kwargs (Any)

enumeration_column: str

Parameter to scan in enumeration_file

enumeration_file: str

Name of SDDS file containing element to scan

index_number: int = 0

Scan number index

item: str

Parameter to scan

lattice: frameworkLattice = None

`~simba.Framework_objects.frameworkLattice object

Type:

class

multiplicative: int = 0

Whether to multiply the original value by the values in the scan range

name: str

Element name to scan

nruns: int = 1

Number of runs to perform

objectname: str = 'vary_element'

Name of frameworkObject objectname

objecttype: str = 'vary_element'

Name of frameworkObject objecttype

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

Bases: elegantCommandFile

SDDS beam input for an ELEGANT input file; see Elegant sdds beam

Parameters:
  • args (Any)

  • kwargs (Any)

center_arrival_time: int = 0

Flag to indicate whether to centre arrival time

fiducialization_bunch: int = 0

Flag to indicate whether bunch is fiducial

input: str = ''

Input filename for ELEGANT

objectname: str = 'sdds_beam'

Name of object

objecttype: str = 'sdds_beam'

Type of object

reuse_bunch: int = 1

Flag to indicate whether bunch is to be reused

sample_interval: float | int = 1

Fraction by which to reduce number of particles

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

Bases: elegantCommandFile

Track command for an ELEGANT input file; see Elegant track

Parameters:
  • args (Any)

  • kwargs (Any)

objectname: str = 'track'

Name of object

objecttype: str = 'track'

Type of object

trackBeam: bool = True

Flag to indicate whether to include the track command

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

Bases: elegantCommandFile

Twiss output for an ELEGANT input file; see Elegant twiss output

Parameters:
  • args (Any)

  • kwargs (Any)

alpha_x: float | None = None

Initial alpha_x; if None, take it from beam

alpha_y: float | None = None

Initial alpha_y; if None, take it from beam

beam: beam

Particle distribution

beta_x: float | None = None

Initial beta_x; if None, take it from beam

beta_y: float | None = None

Initial beta_y; if None, take it from beam

eta_x: float | None = None

Initial eta_x; if None, take it from beam

eta_xp: float | None = None

Initial eta_xp; if None, take it from beam

filename: str = '%s.twi'

Twiss output file

matched: int = 0

Flag to indicate whether beam is matched

objectname: str = 'twiss_output'

Name of object

objecttype: str = 'twiss_output'

Type of object

output_at_each_step: int = 0

Flag to indicate whether to output twiss at each step

radiation_integrals: int = 1

Calculate radiation integrals

statistics: int = 1

Calculate beam statistics

class sddsFile[source]

Bases: object

simple class for writing generic column data to a new SDDS file

add_column(name, data, **kwargs)[source]

add a column of floating point numbers to the file

add_parameter(name, data, **kwargs)[source]

add a parameter of floating point numbers to the file

save(fname)[source]

save the sdds data structure to file

Module contents