gov.sns.tools.beam
Class PhaseVector

java.lang.Object
  |
  +--gov.sns.tools.beam.PhaseVector
All Implemented Interfaces:
IArchive, java.io.Serializable

public class PhaseVector
extends java.lang.Object
implements java.io.Serializable, IArchive

Represents a vector of homogeneous phase space coordinates for three spatial dimensions. Thus, each phase vector is an element of R7, the set of real 7-tuples.

The coordinates are as follows: (x, xp, y, yp, z, zp, 1)' where the prime indicates transposition and x = x-plane position xp = x-plane momentum y = y-plane position yp = y-plane momentum z = z-plane position zp = z-plane momentum

Homogeneous coordinates are parameterizations of the projective spaces Pn. They are useful here to allow vector transpositions, normally produced by vector addition, to be represented as matrix multiplications. These operations can be embodied by the class PhaseMatrix. Thus, PhaseVector's are not intended to support vector addition.

See Also:
Matrix, Vector, PhaseMatrix, Serialized Form

Field Summary
static java.lang.String ATTR_DATA
          attribute marker for data
 
Constructor Summary
PhaseVector()
          Creates a new instance of PhaseVector with zero initial value.
PhaseVector(double[] arrVal)
          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(PhaseVector vecInit)
          Copy Constructor Creates new PhaseVector initialized to argument
PhaseVector(R3 vecPos, R3 vecMom)
          Create a new instance of PhaseVector with specified initial value.
PhaseVector(java.lang.String strTokens)
          Create a new instance of PhaseVector with specified initial value specified by the formatted string argument.
 
Method Summary
 boolean equals(java.lang.Object o)
          Return false - the object is not a PhaseVector.
 boolean equals(PhaseVector pv)
          Return true if the PhaseVectors are equal, false otherwise.
 double getElem(int i)
          Return the element at index.
 R3 getMomentum()
          Get momentum coordinate in R3.
 R3 getPosition()
          Get position coordinates in R3.
 double getx()
          Return the x position coordinate
 double getxp()
          Return the x momentum coordinate
 double gety()
          Return the y position coordinate
 double getyp()
          Return the y momentum coordinate
 double getz()
          Return the z momentum coordinate
 double getzp()
          Return the z momentum coordinate
 int hashCode()
          "Borrowed" implementation from AffineTransform, since it is based on double attribute values.
 double innerProd(PhaseVector vec)
          Vector inner product operation using ONLY the phase coordinates.
 void load(DataAdaptor daptArchive)
          Restore the value of the this PhaseVector from the contents of a data archive.
static void main(java.lang.String[] arrArgs)
           
 double norm1()
          Return the l1 norm of the vector's phase components.
 double norm2()
          Return the l2 norm of the vector.
 double normInf()
          Return the l-infinity norm of the vector.
 PhaseMatrix outerProd(PhaseVector vec)
          Vector outer product operation.
static PhaseVector parse(java.lang.String strTokens)
          Create a new instance of PhaseVector with initial value determined by the formatted string argument.
 PhaseVector plus(PhaseVector vec)
          Vector nondestructive addition.
 void plusEquals(PhaseVector vec)
          Vector in-place addition.
 void print(java.io.PrintWriter os)
          Print the vector contents to an output stream, does not add new line.
 void println(java.io.PrintWriter os)
          Print the vector contents to an output stream, add new line character.
 java.lang.String printString()
          Print the vector contents to a String.
 void save(DataAdaptor daptArchive)
          Save the value of this PhaseVector to disk.
 void setElem(int i, double dblVal)
          Set the element at index.
 void setVector(java.lang.String strValues)
          Create a new instance of PhaseVector with specified initial value specified by the formatted string argument.
 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
 PhaseVector times(double s)
          Nondestructive scalar multiplication
 PhaseVector times(PhaseMatrix mat)
          Premultiply PhaseVector by a PhaseMatrix.
 void timesEquals(double s)
          In-place scalar multiplication
 java.lang.String toString()
          Convert the vector contents to a string.
static PhaseVector zero()
          Create a new instance of a zero phase vector.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

ATTR_DATA

public static final java.lang.String ATTR_DATA
attribute marker for data

See Also:
Constant Field Values
Constructor Detail

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 initialized to argument

Parameters:
vecInit - initial value

PhaseVector

public PhaseVector(double[] arrVal)
Create a new instance of PhaseVector with specified initial value.

Parameters:
arrVal - length 6 array of initial values
Throws:
java.lang.ArrayIndexOutOfBoundsException - 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 - momemtum vector (xp, yp, zp) in R3

PhaseVector

public PhaseVector(java.lang.String strTokens)
            throws java.lang.NumberFormatException,
                   java.lang.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:
java.lang.IllegalArgumentException - wrong number of tokens in argument (must be 6 or 7)
java.lang.NumberFormatException - bad numeric value, unparseable
See Also:
setVector(java.lang.String)
Method Detail

zero

public static PhaseVector zero()
Create a new instance of a zero phase vector.

Returns:
zero vector

parse

public static PhaseVector parse(java.lang.String strTokens)
                         throws java.lang.NumberFormatException,
                                java.lang.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:
java.lang.IllegalArgumentException - wrong number of tokens in argument (must be 6)
java.lang.NumberFormatException - bad numeric value, unparseable

setVector

public void setVector(java.lang.String strValues)
               throws DataFormatException,
                      java.lang.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:
strValues - token string representing values phase coordinates
Throws:
java.lang.IllegalArgumentException - wrong number of tokens in argument (must be 6 or 7)
java.lang.NumberFormatException - bad numeric value, unparseable
DataFormatException

setElem

public void setElem(int i,
                    double dblVal)
             throws java.lang.ArrayIndexOutOfBoundsException
Set the element at index. Note that you cannot change the last element value, it must remain 1.

Parameters:
i - index of new element value
Throws:
java.lang.ArrayIndexOutOfBoundsException - index must be in {0,1,2,3,4,5}

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


getElem

public double getElem(int i)
               throws java.lang.ArrayIndexOutOfBoundsException
Return the element at index.

Returns:
the ith element of the phase vector
Throws:
java.lang.ArrayIndexOutOfBoundsException - index must be in {0,1,2,3,4,5,6}

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)

save

public void save(DataAdaptor daptArchive)
Save the value of this PhaseVector to disk.

Specified by:
save in interface IArchive
Parameters:
daptArchive - interface to data sink
See Also:
IArchive.save(gov.sns.tools.data.DataAdaptor)

load

public void load(DataAdaptor daptArchive)
          throws DataFormatException
Restore the value of the this PhaseVector from the contents of a data archive.

Specified by:
load in interface IArchive
Parameters:
daptArchive - interface to data source
Throws:
DataFormatException - malformed data
java.lang.IllegalArgumentException - wrong number of string tokens
See Also:
IArchive.load(gov.sns.tools.data.DataAdaptor)

toString

public java.lang.String toString()
Convert the vector contents to a string.

Overrides:
toString in class java.lang.Object
Returns:
vector value as a string (v0, v1, ..., v5)

equals

public boolean equals(java.lang.Object o)
Return false - the object is not a PhaseVector.

Overrides:
equals in class java.lang.Object

equals

public boolean equals(PhaseVector pv)
Return true if the PhaseVectors are equal, false otherwise.

Returns:
true if the PhaseVectors are equal, false otherwise

hashCode

public int hashCode()
"Borrowed" implementation from AffineTransform, since it is based on double attribute values. Must implement hashCode to be consistent with equals as specified by contract of hashCode in Object.

Overrides:
hashCode in class java.lang.Object
Returns:
a hashCode for this object

plus

public PhaseVector plus(PhaseVector vec)
Vector nondestructive addition. Note only the phase coordinates are added.

Parameters:
vec - vector to be added
Returns:
vector sum (componentwise)

plusEquals

public void plusEquals(PhaseVector vec)
Vector in-place addition. Note only the phase coordinates are added.

Parameters:
vec - vector to be added

times

public PhaseVector times(double s)
Nondestructive scalar multiplication

Parameters:
s - scalar
Returns:
result of scalar multiplication

timesEquals

public void timesEquals(double s)
In-place scalar multiplication

Parameters:
s - scalar

times

public PhaseVector times(PhaseMatrix mat)
Premultiply PhaseVector by a PhaseMatrix.

Parameters:
mat - matrix operator
Returns:
result of matrix-vector product

innerProd

public double innerProd(PhaseVector vec)
Vector inner product operation using ONLY the phase coordinates.

Parameters:
vec - second argument to inner product operation
Returns:
inner product (this,vec)

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 ]

norm1

public double norm1()
Return the l1 norm of the vector's phase components.

Returns:
||z||_1 = Sum |z_i|

norm2

public double norm2()
Return the l2 norm of the vector.

Returns:
||z||_2 = [ Sum |z_i| ]^1/2

normInf

public double normInf()
Return the l-infinity norm of the vector.

Returns:
||z||_inf = Sup_i |z_i|

print

public void print(java.io.PrintWriter os)
Print the vector contents to an output stream, does not add new line.

Parameters:
os - output stream object

println

public void println(java.io.PrintWriter os)
Print the vector contents to an output stream, add new line character.

Parameters:
os - output stream object

printString

public java.lang.String printString()
Print the vector contents to a String.


main

public static void main(java.lang.String[] arrArgs)