Class ElementSeq

java.lang.Object
xal.model.elem.ElementSeq
All Implemented Interfaces:
Iterable<IComponent>, IComponent, IComposite
Direct Known Subclasses:
ElectromagnetSeq, IdealRfCavity, Lattice, LineModel, RingModel, Sector

public abstract class ElementSeq extends Object implements IComposite

Convenience abstract base class for a composite modeling element. The composite is represented as a sequence of modeling elements, perhaps other composites. Specifically we have an ordered list of child modeling elements.

Propagation of probes (objects exposing the IProbe interface) is done by passing it sequentially to each child. Of course if a child is also a composite the same is done there.

Version:
2.0 February, 2009
Author:
Christopher K. Allen
  • Field Details

    • SIZE_DEF_RESERVE

      public static final int SIZE_DEF_RESERVE
      default number of element positions to reserve in list array
      See Also:
  • Constructor Details

    • ElementSeq

      protected ElementSeq(String strType)
      Creates a new instance of ElementSeq without of the given soft type but without a sequence identifier.
      Parameters:
      strType - soft type of the sequence (defined by the child class)
    • ElementSeq

      protected ElementSeq(String strType, String strId)
      Creates a new instance of ElementSeq with the given soft type and sequence identifier.
      Parameters:
      strType - soft type of the sequence (defined by the child class)
      strId - identifier of the sequence
    • ElementSeq

      protected ElementSeq(String strType, String strId, int szReserve)
      Creates a new instance of ElementSeq with the given soft type and sequence identifier. Also reserves space for a the sequence elements. This saves a little CPU time if the relative size of the sequence is known a priori.
      Parameters:
      strType - soft type of the sequence (defined by the child class)
      strId - identifier of the sequence
      szReserve - number of Element spaces to reserve
  • Method Details

    • setId

      public void setId(String strId)
      Set the string identifier for the element.
      Parameters:
      strId - new string identifier for element
    • setHardwareNodeId

      public void setHardwareNodeId(String strSmfId)
      Sets the string identifier of the hardware node which this element models. Node that this sequence probably models an accelerator sector, or logical unit. Thus, this ID is likely of the type "HEBT", "RING", "DTL", etc.
      Parameters:
      strSmfId - identifier for the modeled hardware node (SMF object)
      Since:
      Sep 2, 2014
    • setComments

      public void setComments(String strComment)
      Sets any user comment associated with this sequence.
      Parameters:
      strComment - string containing user comments
    • getComments

      public String getComments()
      Get any user comments regarding this sequence. Returns the null string if none.
      Returns:
      string containing user comments
    • getLeafCount

      public int getLeafCount()
      Get the number of IElement derived objects contained in this sequence.
      Returns:
      number of Element object w/in sequence
    • getElementList

      public List<IComponent> getElementList()
      Return the list of IElement objects contained in this sequence.
      Returns:
      list of elements composing this sequence
    • getAllElements

      public List<IComponent> getAllElements()
      Returns a list of all elements contained in this sequence, more specifically, all leaf elements.
      Returns:
      list containing all IComponent class elements in this sequence
      Since:
      Sep 11, 2014
    • setAlign

      public void setAlign(R3 vecAlign)
      Set the alignment parameters all at once.
      Parameters:
      vecAlign - (dx,dy,dz)
    • setAlignX

      public void setAlignX(double x)
      Set the horizontal misalignment
      Parameters:
      x - misalignment (in m)
      Since:
      Dec 17, 2014 by Christopher K. Allen
    • setAlignY

      public void setAlignY(double y)
      Set the vertical misalignment
      Parameters:
      y - misalignment (in m)
      Since:
      Dec 17, 2014 by Christopher K. Allen
    • setAlignZ

      public void setAlignZ(double z)
      Set the longitudinal misalignment
      Parameters:
      z - misalignment (in m)
      Since:
      Dec 17, 2014 by Christopher K. Allen
    • getAlignX

      public double getAlignX()
      Get the horizontal misalignment
      Returns:
      the misalignment (in meters)
      Since:
      Dec 17, 2014 by Christopher K. Allen
    • getAlignY

      public double getAlignY()
      Get the vertical misalignment
      Returns:
      the misalignment (in meters)
      Since:
      Dec 17, 2014 by Christopher K. Allen
    • getAlignZ

      public double getAlignZ()
      Get the longitudinal misalignment
      Returns:
      the misalignment (in meters)
      Since:
      Dec 17, 2014 by Christopher K. Allen
    • getPhiX

      public double getPhiX()
    • getPhiY

      public double getPhiY()
    • getPhiZ

      public double getPhiZ()
    • setPhiX

      public void setPhiX(double phix)
    • setPhiY

      public void setPhiY(double phiy)
    • setPhiZ

      public void setPhiZ(double phiz)
    • localBackIterator

      public Iterator<IComponent> localBackIterator()
      Return an Iterator object that iterates over the direct descendants only of this composite element, in reverse order.
      Returns:
      interface to iterator object
      Since:
      Feb 27, 2009
      See Also:
    • globalBackIterator

      public Iterator<IComponent> globalBackIterator()
      Return an Iterator object that iterates over every IComponent object in this composite. For IComponent which are also composite the parent is returned first, then all its children. This would be in reverse order.
      Returns:
      Iterator interface to iterator object
      See Also:
    • childIterator

      public Iterator<IComponent> childIterator()
      Return an Iterator object that cycles through all the direct children of the sequence. Note that any child may have children itself.
      Returns:
      iterator of IElement interfaces
    • concatenateEquals

      public void concatenateEquals(ElementSeq seq)
      Concatenate the indicated ElementSeq object to the tail of this sequence.
      Parameters:
      seq - object to append to this one
    • initializeFrom

      public void initializeFrom(LatticeElement latticeElement)
      Initialization method to be provided by the user
      Specified by:
      initializeFrom in interface IComponent
      Parameters:
      latticeElement - the SMF node to convert
    • getType

      public String getType()
      Get the type identifier for the composite element.
      Specified by:
      getType in interface IComponent
      Returns:
      type identifier for ElementSeq
    • getId

      public String getId()
      Get the sequence identifier
      Specified by:
      getId in interface IComponent
      Returns:
      sequence identifier
    • getHardwareNodeId

      public String getHardwareNodeId()
      Returns the string identifier of the hardware node which this element models. This value is likely a sector of an accelerator structure, such as "HEBT", "RING", "MEBT", etc.
      Specified by:
      getHardwareNodeId in interface IComponent
      Returns:
      the identifier string of the hardware this element models
      Since:
      Sep 2, 2014
    • getLength

      public double getLength()

      Return the length of the sequence. The length of the sequence is determined but summing the lengths of all the contained IComponent objects.

      Specified by:
      getLength in interface IComponent
      Returns:
      total length of the sequence (in meters)
    • getPosition

      public double getPosition()
      Description copied from interface: IComponent

      Return the center position of this component within the immediate parent composite element. If there is no parent then this method should return zero.

      This value is typically a "hardware property," especially if this element models a hardware node. That is, the value is specified in the description of the hardware node and, thus, carries through to the modeling element. The situation is different than the property IComponent.getLatticePosition() where the position is completely dependent upon where the modeling element lies within the overall lattice structure.

      Specified by:
      getPosition in interface IComponent
      Returns:
      center position of this element within the immediate parent container (meters)
      Since:
      Dec 3, 2015, Christopher K. Allen
      See Also:
    • getLatticePosition

      public double getLatticePosition()
      Description copied from interface: IComponent

      Return the (center) position of this component within the global lattice structure to which it belongs. Note the difference between this parameter and that returned by IComponentIComponent.getLength() which returns the position with respect to the direct parent.

      The returned value is not usually a design parameter, in particular if composites are pasted together or otherwise form a larger tree structure. It should be computed according to the current structure of the global composite structure. Thus, moving this element in the lattice should change this value.

      Specified by:
      getLatticePosition in interface IComponent
      Returns:
      the center position of this component within the entire lattice containing this element (not just the parent)
      Since:
      Dec 3, 2015, Christopher K. Allen
      See Also:
    • getParent

      public IComposite getParent()
      Description copied from interface: IComponent
      Returns the composite structure (if any) that owns this component.
      Specified by:
      getParent in interface IComponent
      Returns:
      returns the composite structure owning this composite structure, or null if this structure is top level
      Since:
      Jan 22, 2015 by Christopher K. Allen
      See Also:
    • setParent

      public void setParent(IComposite cpsParent)
      Sets the parent structure containing this composite structure. The parent is assumed to be a composite structure built from component elements.
      Specified by:
      setParent in interface IComponent
      Parameters:
      cpsParent - the composite structure built from this component
      Since:
      Jan 22, 2015 by Christopher K. Allen
      See Also:
    • propagate

      public void propagate(IProbe probe, double pos) throws ModelException
      Specified by:
      propagate in interface IComponent
      Throws:
      ModelException
      Since:
      Feb 27, 2009
      See Also:
    • propagate

      public void propagate(IProbe probe) throws ModelException
      Propagate probe through sequence
      Specified by:
      propagate in interface IComponent
      Specified by:
      propagate in interface IComposite
      Parameters:
      probe - the state of the probe will be advance using the elements dynamics
      Throws:
      ModelException - an error occurred while advancing the probe state
      See Also:
    • backPropagate

      public void backPropagate(IProbe probe, double pos) throws ModelException

      Override of IComponent.propagate(xal.model.IProbe, double)

      NOTES: CKA
      · Support for backward propagation February, 2009.
      · You must use the proper algorithm object for this method to work correctly!

      Specified by:
      backPropagate in interface IComponent
      Parameters:
      probe - probe to be propagate - its state is advanced
      pos - position within element
      Throws:
      ModelException - error advancing the probe state
      Since:
      Feb 27, 2009
      See Also:
    • backPropagate

      public void backPropagate(IProbe probe) throws ModelException

      Backward propagation of probe through sequence.

      NOTES: CKA
      · Support for backward propagation February, 2009.
      · You must use the proper algorithm object for this method to work correctly!

      Specified by:
      backPropagate in interface IComponent
      Parameters:
      probe - the state of the probe will be advance using the elements dynamics
      Throws:
      ModelException - an error occurred while advancing the probe state
    • localIterator

      public Iterator<IComponent> localIterator()
      Return an Iterator object that iterates over the direct descendants only of this composite element, in order.
      Specified by:
      localIterator in interface IComposite
      Returns:
      interface to iterator object
      See Also:
    • globalIterator

      public Iterator<IComponent> globalIterator()
      Return an Iterator object that iterates over every IComponent object in this composite. For IComponent which are also composite the parent is returned first, then all its children. This would be in reverse order.
      Specified by:
      globalIterator in interface IComposite
      Returns:
      Iterator interface to iterator object
      See Also:
    • getChildCount

      public int getChildCount()
      Get the number of direct children in this sequence. Note that this is not the number of leaves in the sequence.
      Specified by:
      getChildCount in interface IComposite
      Returns:
      number of direct descendants
    • getChild

      public IComponent getChild(int indChild)
      Get the child IComponent interface at location specified by index.
      Specified by:
      getChild in interface IComposite
      Parameters:
      indChild - position index within the sequence list
      Returns:
      child at position indChild
    • addChild

      public void addChild(IComponent iComp)

      Add a component object at the tail of the sequence list and at the head of the reverse sequence list.

      NOTES: CKA
      · Added support for backward propagation February, 2009

      Specified by:
      addChild in interface IComposite
      Parameters:
      iComp - new component object
    • remove

      public boolean remove(IComponent iCmp)
      Remove an element from the entire tree. The element can be a single leaf node or a composite node.
      Specified by:
      remove in interface IComposite
      Parameters:
      iCmp - IComponent object to be removed
      Returns:
      return true if element was found and removed, false otherwise
    • setDirty

      public void setDirty(IComponent cmpCaller)
      Description copied from interface: IComposite

      Need only be called by implementing classes

      Indicates internally that the composite structure has been modified and any dependent parameters must be recomputed. This is needed if these parameters must be computed upon demand due to dynamic changes in the composite. In order to avoid expensive re-iteration through large composite structures, by employing this method a state condition can be set up so that the dependent parameters are only recomputed when the composite changes.

      • Implementing classes should call this method whenever the composite changes, in particular whenever IComposite.addChild(IComponent) and IComposite.remove(IComponent) are called.
      • They respond to this call by setting a dirty flag and calls the same method on their parent object.
      • If the dirty flag is set then all dependent parameters should be recomputed whenever one is requested (after which the flag can be cleared).

      Specified by:
      setDirty in interface IComposite
      Parameters:
      cmpCaller - the IComponent object calling this method, or null if the object is not a component
      Since:
      Dec 3, 2015, Christopher K. Allen
      See Also:
      • xal.model.IComposite#setDirty()
    • iterator

      public Iterator<IComponent> iterator()
      Returns a shallow iterator for the direct descendants of this composite modeling element. This is the same iterator returned by localIterator(). This method is needed by the Iterable interface to satisfy foreach language constructions.
      Specified by:
      iterator in interface Iterable<IComponent>
      Returns:
      a shallow iterator traversing the direct descendants of this container
      Since:
      Dec 2, 2015, Christopher K. Allen
    • toString

      public String toString()
      Writes out the modeling elements in this element sequence structure.
      Overrides:
      toString in class Object
      Since:
      Jan 5, 2015 by Christopher K. Allen
      See Also:
    • toStringLegacy

      public String toStringLegacy()
      Since:
      Feb 3, 2015 by Christopher K. Allen
      See Also:
    • print

      public void print(PrintWriter os)
      Dump contents to a text stream.
      Parameters:
      os - output stream
    • getForwardCompList

      protected List<IComponent> getForwardCompList()
      Return the internal list of components
    • getReverseCompList

      protected List<IComponent> getReverseCompList()

      Return the reverse component list (downstream to upstream)

      NOTES: CKA
      · Added support for backward propagation February, 2009

      Returns:
      List of sequence components in reverse order
      Since:
      Feb 27, 2009
    • setCompList

      protected void setCompList(List<? extends IComponent> elements)

      Set the comp list to the new list of elements.

      NOTES: CKA
      · Added support for backward propagation February, 2009

      Parameters:
      elements - the new list of elements
    • compDependParams

      protected void compDependParams()
      Recompute all the dependent parameters. Right now that is the sequence length and the position of this sequence within the parent sequence. The dirty flag is cleared once it's all done.
      Since:
      Dec 3, 2015, Christopher K. Allen