Class PhaseVector

All Implemented Interfaces:
Serializable, IArchive

public class PhaseVector extends BaseVector<PhaseVector> implements Serializable, IArchive
Class .
Since:
Oct 11, 2013
Author:
Christopher K. Allen
See Also:
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    static enum 
    Enumeration for the element position indices for homogeneous phase space objects.
  • Field Summary

    Fields inherited from class xal.tools.math.BaseVector

    ATTR_DATA
  • Constructor Summary

    Constructors
    Constructor
    Description
    Creates a new instance of PhaseVector with zero initial value.
    PhaseVector(double[] arrVals)
    Create a new instance of PhaseVector with specified initial value.
    PhaseVector(double x, double xp, double y, double yp, double z, double zp)
    Create a new instance of PhaseVector with specified initial value.
    PhaseVector(String strTokens)
    Create a new instance of PhaseVector with specified initial value specified by the formatted string argument.
    Copy Constructor Creates new PhaseVector object which is a deep copy of the given argument.
    Create a new PhaseVector object and initialize it with the data behind the DataAdaptor data source.
    PhaseVector(R3 vecPos, R3 vecMom)
    Create a new instance of PhaseVector with specified initial value.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    We need to redefine this method in order to set the homogeneous coordinate back to unity.
    Creates and returns a deep copy of this vector.
    copy(PhaseVector vecParent)
    Creates a deep copy of the given PhaseVector object.
    embed(R4 vecCoords)
    Embeds the given vector zR4 into homogeneous phase space.
    embed(R6 vecCoords)
    Embeds the given vector zR6 into homogeneous phase space.
    Get momentum coordinate in R3.
    Get position coordinates in R3.
    double
    Return the x position coordinate
    double
    Return the x momentum coordinate
    double
    Return the y position coordinate
    double
    Return the y momentum coordinate
    double
    Return the z momentum coordinate
    double
    Return the z momentum coordinate
    double
    Must override to account for the homogeneous coordinate.
    Create a new PhaseVector object and initialize with the data source behind the given DataAdaptor interface.
    static void
    main(String[] arrArgs)
    Test driver
    Must override to protect the homogeneous coordinate.
    void
    Must override to protect the homogeneous coordinate.
    Must override to protect the homogeneous coordinate.
    void
    Must override to protect the homogeneous coordinate.
    protected PhaseVector
    newInstance(double[] arrVecInt)
    Creates a new instance of this vector type with the given Java array as the internal representation.
    protected PhaseVector
    newInstance(int size)
    Handles object creation required by the base class.
    Create a new instance of a zero phase vector.
    double
    Return the l1 norm of the vector.
    double
    Return the l2 norm of the vector.
    double
    Return the l∞ norm of the vector.
    Vector outer product operation.
    parse(String strTokens)
    Create a new instance of PhaseVector with initial value determined by the formatted string argument.
    plus(PhaseVector vecAdd)
    Must override to protect the homogeneous coordinate.
    void
    Must override to protect the homogeneous coordinate.
    void
    Print the vector contents to an output stream, does not add new line.
    void
    Print the vector contents to an output stream, add new line character.
    Print the vector contents to a String.
    void
    setVector(double[] arrVector)
    Must override this method to ignore any missing homogeneous coordinate since it is understood that this value is always there and unchanging.
    void
    setVector(String strValues)
    Must override this method to ignore any missing homogeneous coordinate since it is understood that this value is always there and unchanging.
    void
    setx(double dblVal)
    Set the x position coordinate
    void
    setxp(double dblVal)
    Set the x momentum coordinate
    void
    sety(double dblVal)
    Set the y position coordinate
    void
    setyp(double dblVal)
    Set the y momentum coordinate
    void
    setz(double dblVal)
    Set the z position coordinate
    void
    setzp(double dblVal)
    Set the z momentum coordinate
    times(double s)
    Must override to protect the homogeneous coordinate.
    void
    timesEquals(double s)
    Must override to protect the homogeneous coordinate.

    Methods inherited from class java.lang.Object

    finalize, getClass, notify, notifyAll, wait, wait, wait

    Methods inherited from interface xal.tools.data.IArchive

    load, save
  • Constructor Details

    • PhaseVector

      public PhaseVector()
      Creates a new instance of PhaseVector with zero initial value.
    • PhaseVector

      public PhaseVector(double x, double xp, double y, double yp, double z, double zp)
      Create a new instance of PhaseVector with specified initial value.
      Parameters:
      x - x-plane position
      xp - x-plane momentum
      y - y-plane position
      yp - y-plane momentum
      z - z-plane position
      zp - z-plane momentum
    • PhaseVector

      public PhaseVector(PhaseVector vecInit)
      Copy Constructor Creates new PhaseVector object which is a deep copy of the given argument.
      Parameters:
      vecInit - initial value
    • PhaseVector

      public PhaseVector(double[] arrVals)
      Create a new instance of PhaseVector with specified initial value.
      Parameters:
      arrVals - length 6 array of initial values
      Throws:
      IllegalArgumentException - argument must be a length-six array
    • PhaseVector

      public PhaseVector(R3 vecPos, R3 vecMom)
      Create a new instance of PhaseVector with specified initial value.
      Parameters:
      vecPos - position vector (x,y,z) in R3
      vecMom - momentum vector (xp, yp, zp) in R3
    • PhaseVector

      public PhaseVector(DataAdaptor daSource) throws DataFormatException
      Create a new PhaseVector object and initialize it with the data behind the DataAdaptor data source.
      Parameters:
      daSource - data source containing initialization data
      Throws:
      DataFormatException - malformed data
      See Also:
    • PhaseVector

      public PhaseVector(String strTokens) throws NumberFormatException, IllegalArgumentException
      Create a new instance of PhaseVector with specified initial value specified by the formatted string argument. The input string may or may not contain the final coordinate which always has value 1. The string should be formatted as "(x,x',y,y',z,zp')" where x, x', y, y', z, z' are floating point representations.
      Parameters:
      strTokens - token string representing values phase coordinates
      Throws:
      IllegalArgumentException - wrong number of tokens in argument (must be 6 or 7)
      NumberFormatException - bad numeric value, un-parseable
      See Also:
  • Method Details

    • newZero

      public static PhaseVector newZero()
      Create a new instance of a zero phase vector.
      Returns:
      zero vector
    • copy

      public static PhaseVector copy(PhaseVector vecParent)
      Creates a deep copy of the given PhaseVector object. Thus, the argument is unmodified and unreferenced.
      Parameters:
      vecParent - vector object to clone
      Returns:
      deep copy of the argument
    • parse

      public static PhaseVector parse(String strTokens) throws NumberFormatException, IllegalArgumentException
      Create a new instance of PhaseVector with initial value determined by the formatted string argument. The string should be formatted as "(x,x',y,y',z,zp')" where x, x', y, y', z, z' are floating point representations.
      Parameters:
      strTokens - six-token string representing values phase coordinates
      Throws:
      IllegalArgumentException - wrong number of tokens in argument (must be 6)
      NumberFormatException - bad numeric value, unparseable
    • loadFrom

      public static PhaseVector loadFrom(DataAdaptor daSource) throws DataFormatException
      Create a new PhaseVector object and initialize with the data source behind the given DataAdaptor interface.
      Parameters:
      daSource - data source containing initialization data
      Throws:
      DataFormatException - malformed data
      Since:
      Jan 4, 2016, Christopher K. Allen
      See Also:
    • embed

      public static PhaseVector embed(R6 vecCoords)
      Embeds the given vector zR6 into homogeneous phase space. The given vector is treated like a vector of phase space coordinates corresponding to the first 6 elements of a PhaseVector object. The last element of the returned phase vector has value 1, as do all phase vectors.
      Parameters:
      vecCoords - vector z containing the first 6 element values of the returned phase vector
      Returns:
      the augmented vector (z,1)
      Since:
      Oct 16, 2013
    • embed

      public static PhaseVector embed(R4 vecCoords)
      Embeds the given vector zR4 into homogeneous phase space. The given vector is treated like a vector of transverse phase space coordinates corresponding to the first 4 elements of a PhaseVector object. The vector elements corresponding to the longitudinal phase space coordinates z and z' are both set to zero. The last element of the returned phase vector has value 1, as do all phase vectors.
      Parameters:
      vecCoords - vector z containing the first 6 element values of the returned phase vector
      Returns:
      the augmented vector (z,1)
      Since:
      Oct 16, 2013
    • setVector

      public void setVector(String strValues)
      Must override this method to ignore any missing homogeneous coordinate since it is understood that this value is always there and unchanging.
      Overrides:
      setVector in class BaseVector<PhaseVector>
      Parameters:
      strValues - token vector of SIZE2 numeric values
      Since:
      Sep 6, 2014
      See Also:
    • setVector

      public void setVector(double[] arrVector) throws IllegalArgumentException
      Must override this method to ignore any missing homogeneous coordinate since it is understood that this value is always there and unchanging.
      Overrides:
      setVector in class BaseVector<PhaseVector>
      Parameters:
      arrVector - Java primitive array containing new vector values
      Throws:
      IllegalArgumentException - the argument must have the same dimensions as this matrix
      Since:
      Sep 6, 2014
      See Also:
    • setx

      public void setx(double dblVal)
      Set the x position coordinate
    • setxp

      public void setxp(double dblVal)
      Set the x momentum coordinate
    • sety

      public void sety(double dblVal)
      Set the y position coordinate
    • setyp

      public void setyp(double dblVal)
      Set the y momentum coordinate
    • setz

      public void setz(double dblVal)
      Set the z position coordinate
    • setzp

      public void setzp(double dblVal)
      Set the z momentum coordinate
    • getx

      public double getx()
      Return the x position coordinate
    • getxp

      public double getxp()
      Return the x momentum coordinate
    • gety

      public double gety()
      Return the y position coordinate
    • getyp

      public double getyp()
      Return the y momentum coordinate
    • getz

      public double getz()
      Return the z momentum coordinate
    • getzp

      public double getzp()
      Return the z momentum coordinate
    • getPosition

      public R3 getPosition()
      Get position coordinates in R3.
      Returns:
      (x,y,z)
    • getMomentum

      public R3 getMomentum()
      Get momentum coordinate in R3.
      Returns:
      (xp,yp,zp)
    • outerProd

      public PhaseMatrix outerProd(PhaseVector vec)
      Vector outer product operation. Returns the tensor outer product as a PhaseMatrix object
      Parameters:
      vec - second argument to tensor product
      Returns:
      outer product = [ this_i*vec_j ]
    • newInstance

      protected PhaseVector newInstance(int size)
      Handles object creation required by the base class.
      Specified by:
      newInstance in class BaseVector<PhaseVector>
      Returns:
      uninitialized vector object of type V
      Since:
      Jun 17, 2014
      See Also:
      • xal.tools.math.BaseVector#newInstance()
    • newInstance

      protected PhaseVector newInstance(double[] arrVecInt)
      Description copied from class: BaseVector
      Creates a new instance of this vector type with the given Java array as the internal representation.
      Specified by:
      newInstance in class BaseVector<PhaseVector>
      Parameters:
      arrVecInt - new vector's guts
      Returns:
      new instance of this vector type with the internal representation
      Since:
      Jul 24, 2015 by Christopher K. Allen
      See Also:
    • assignZero

      public void assignZero()
      We need to redefine this method in order to set the homogeneous coordinate back to unity.
      Overrides:
      assignZero in class BaseVector<PhaseVector>
      Since:
      Nov 6, 2014
      See Also:
    • negate

      public PhaseVector negate()
      Must override to protect the homogeneous coordinate.
      Overrides:
      negate in class BaseVector<PhaseVector>
      Returns:
      antipodal vector of the current object
      Since:
      Jan 7, 2015 by Christopher K. Allen
      See Also:
    • negateEquals

      public void negateEquals()
      Must override to protect the homogeneous coordinate.
      Overrides:
      negateEquals in class BaseVector<PhaseVector>
      Since:
      Jan 7, 2015 by Christopher K. Allen
      See Also:
    • plusEquals

      public void plusEquals(PhaseVector vecAdd)
      Must override to protect the homogeneous coordinate.
      Overrides:
      plusEquals in class BaseVector<PhaseVector>
      Parameters:
      vecAdd - Vector to add to this vector (addend)
      Since:
      Jan 7, 2015 by Christopher K. Allen
      See Also:
    • plus

      public PhaseVector plus(PhaseVector vecAdd)
      Must override to protect the homogeneous coordinate.
      Overrides:
      plus in class BaseVector<PhaseVector>
      Parameters:
      vecAdd - vector added to this one (addend)
      Returns:
      sum of this vector and given vector,
      Since:
      Jan 7, 2015 by Christopher K. Allen
      See Also:
    • minusEquals

      public void minusEquals(PhaseVector vecSub)
      Must override to protect the homogeneous coordinate.
      Overrides:
      minusEquals in class BaseVector<PhaseVector>
      Parameters:
      vecSub - Vector to subtract from this vector (subtrahend)
      Since:
      Jan 7, 2015 by Christopher K. Allen
      See Also:
    • minus

      public PhaseVector minus(PhaseVector vecSub)
      Must override to protect the homogeneous coordinate.
      Overrides:
      minus in class BaseVector<PhaseVector>
      Parameters:
      vecSub - vector subtracted from this one (subtrahend)
      Returns:
      difference of this vector and the given vector,
      Since:
      Jan 7, 2015 by Christopher K. Allen
      See Also:
    • times

      public PhaseVector times(double s)
      Must override to protect the homogeneous coordinate.
      Overrides:
      times in class BaseVector<PhaseVector>
      Parameters:
      s - scalar value
      Returns:
      result of scalar multiplication
      Since:
      Jan 7, 2015 by Christopher K. Allen
      See Also:
    • timesEquals

      public void timesEquals(double s)
      Must override to protect the homogeneous coordinate.
      Overrides:
      timesEquals in class BaseVector<PhaseVector>
      Parameters:
      s - scalar
      Since:
      Jan 7, 2015 by Christopher K. Allen
      See Also:
    • innerProd

      public double innerProd(PhaseVector v) throws IllegalArgumentException
      Must override to account for the homogeneous coordinate.
      Overrides:
      innerProd in class BaseVector<PhaseVector>
      Parameters:
      v - second vector
      Returns:
      inner product of this vector and argument
      Throws:
      IllegalArgumentException
      Since:
      Jan 7, 2015 by Christopher K. Allen
      See Also:
    • norm1

      public double norm1()
      Return the l1 norm of the vector. Must override to account for the projective coordinate.
      Overrides:
      norm1 in class BaseVector<PhaseVector>
      Returns:
      ||z||1 = Σi≠6 |zi|
      Since:
      Oct 11, 2013
      See Also:
    • norm2

      public double norm2()
      Return the l2 norm of the vector. Must override to account for the projective coordinate.
      Overrides:
      norm2 in class BaseVector<PhaseVector>
      Returns:
      ||z||2 = [ Σi≠6 zi2 ]1/2
      Since:
      Oct 11, 2013
      See Also:
    • normInf

      public double normInf()
      Return the l∞ norm of the vector. Must override to account for the projective coordinate.
      Overrides:
      normInf in class BaseVector<PhaseVector>
      Returns:
      ||z|| = supi≠6 |zi|
      Since:
      Oct 11, 2013
      See Also:
    • clone

      public PhaseVector clone()
      Creates and returns a deep copy of this vector.
      Specified by:
      clone in class BaseVector<PhaseVector>
      Since:
      Jul 3, 2014
      See Also:
    • print

      public void print(PrintWriter os)
      Print the vector contents to an output stream, does not add new line.
      Overrides:
      print in class BaseVector<PhaseVector>
      Parameters:
      os - output stream object
    • println

      public void println(PrintWriter os)
      Print the vector contents to an output stream, add new line character.
      Overrides:
      println in class BaseVector<PhaseVector>
      Parameters:
      os - output stream object
    • printString

      public String printString()
      Print the vector contents to a String.
    • main

      public static void main(String[] arrArgs)
      Test driver