Element
Class
Overview
The Element
class is
the fundamental building block for defining beamline components in the OCELOT framework.
It serves as a base class for all accelerator optics elements, enabling the definition of various parameters and
allowing the addition of custom properties as needed. Subclasses of Element
represent specific beamline components, such as magnets, cavities, and diagnostic devices.
Attributes
id
(str
): A unique identifier for the element. If not provided, it is auto-generated with a random integer.has_edge
(bool
): Indicates whether the element has edge effects. Default isFalse
.l
(float
): Length of the element (in meters). Default is0.0
.tilt
(float
): Rotation of the element around the beamline axis (in radians). Default is0.0
. A tilt ofπ/4
converts a positive quadrupole into a negative skew.dx
(float
): Horizontal offset (in meters). Default is0.0
.dy
(float
): Vertical offset (in meters). Default is0.0
.params
(dict
): A dictionary to store additional parameters specific to the element.
Methods
__init__(eid=None, has_edge=False)
Initializes the Element
instance.
Parameters:
eid
(str
, optional): Element ID. IfNone
, a unique ID is auto-generated.has_edge
(bool
, optional): Specifies if the element includes edge effects. Default isFalse
.
__hash__()
Computes a hash value for the element instance.
Returns:
int
: Hash value based on the object ID.
__eq__(other)
Checks equality between two Element
instances based on their memory addresses.
Parameters:
other
(Element
): AnotherElement
instance.
Returns:
bool
:True
if the two instances refer to the same object; otherwise,False
.
_default_B(R)
Computes a default displacement vector for the element.
Parameters:
R
(np.ndarray
): Transformation matrix.
Returns:
np.ndarray
: Default displacement vector.
create_first_order_main_params(energy, delta_length=None)
Generates first-order parameters for the element based on its geometry and beam energy.
Parameters:
energy
(float
): Beam energy.delta_length
(float
, optional): Element length for the calculation. If not provided, the full length (l
) is used.
Returns:
FirstOrderParams
: First-order parameter object.
create_second_order_main_params(energy, delta_length=0.0)
Generates second-order parameters for the element.
Parameters:
energy
(float
): Beam energy.delta_length
(float
, optional): Element length for the calculation. Default is0.0
.
Returns:
SecondOrderParams
: Second-order parameter object.
create_delta_e(total_length, delta_length=0.0)
Calculates the energy variation across the element.
Parameters:
total_length
(float
): Total beamline length.delta_length
(float
, optional): Element length. Default is0.0
.
Returns:
float
: Energy variation.
__repr__()
Generates a string representation of the element.
Returns:
str
: String with the element's class name, ID, and memory address.
Summary
The Element
class provides a flexible and extensible foundation for representing accelerator components. Its modular design supports the customization and extension of beamline elements, making it a core part of the OCELOT framework for accelerator simulations.