at.lattice.lattice_variables#

Variables are references to scalar attributes of lattice elements. There are 2 kinds of element variables:

  • an ElementVariable is associated to an element object, and acts on all occurences of this object. But it will not affect any copy, neither shallow nor deep, of the original object,

  • a RefptsVariable is not associated to an element object, but to an element location in a Lattice. It acts on any copy of the initial lattice. A ring argument must be provided to the set and get methods to identify the lattice, which may be a possibly modified copy of the original lattice

Classes

RefptsVariable(refpts, attrname[, index])

A reference to a scalar attribute of Lattice elements.

ElementVariable(elements, attrname[, index])

A reference to a scalar attribute of Lattice elements.

class ElementVariable(elements, attrname, index=None, **kwargs)[source]#

Bases: VariableBase

A reference to a scalar attribute of Lattice elements.

It can refer to:

  • a scalar attribute or

  • an element of an array attribute

of one or several Elements of a lattice.

An ElementVariable is associated to an element object, and acts on all occurrences of this object. But it will not affect any copy, neither shallow nor deep, of the original object.

Parameters:
  • elements (Union[Element, Sequence[Element]]) – Element or Sequence[Element] whose attribute is varied

  • attrname (str) – Attribute name

  • index (Optional[int]) – Index in the attribute array. Use None for scalar attributes

Keyword Arguments:
  • name (str) – Name of the Variable. Default: ''

  • bounds (tuple[float, float]) – Lower and upper bounds of the variable value. Default: (-inf, inf)

  • delta (float) – Step. Default: 1.0

property elements#

Return the set of elements acted upon by the variable

class RefptsVariable(refpts, attrname, index=None, **kwargs)[source]#

Bases: VariableBase

A reference to a scalar attribute of Lattice elements.

It can refer to:

  • a scalar attribute or

  • an element of an array attribute

of one or several Elements of a lattice.

A RefptsVariable is not associated to element objets themselves, but to the location of these elements in a lattice. So a RefptsVariable will act equally on any copy of the initial ring. As a consequence, a ring keyword argument (Lattice object) must be supplied for getting or setting the variable.

Parameters:
  • refpts (Refpts) – Location of variable Elements

  • attrname (str) – Attribute name

  • index (Optional[int]) – Index in the attribute array. Use None for scalar attributes

Keyword Arguments:
  • name (str) – Name of the Variable. Default: ''

  • bounds (tuple[float, float]) – Lower and upper bounds of the variable value. Default: (-inf, inf)

  • delta (float) – Step. Default: 1.0

  • ring (Lattice) – If specified, it is used to get and store the initial value of the variable. Otherwise, the initial value is set to None