gov.sns.tools.math.r3
Class PoissonGrid

java.lang.Object
  |
  +--gov.sns.tools.math.r3.Grid
        |
        +--gov.sns.tools.math.r3.PoissonGrid
All Implemented Interfaces:
java.io.Serializable

public class PoissonGrid
extends Grid
implements java.io.Serializable

Solves Poisson's equation for a potential function defined on a grid in R3. The grid object then solved the discretized version of Div Grad Val = - Src where Val is potential value on the grid and Src is a source function. NOTES: - The vector field derived from the potential function is calculated by taking the gradient of the interpolated potential. - Potential values at grid points may be set manuallly. - Potential values at grid points can be determined by solving Poisson's equation. The values of the source term must be set at each grid point, along with the type of field point (open, dirichlet, neumann).

See Also:
Serialized Form

Field Summary
static int PT_DIRICHLET
          Grid point is a boundary point with Dirichlet boundary conditions
static int PT_NEUMANN1
          Grid point with Neumann boundary conditions, gradient in the first direction
static int PT_NEUMANN2
          Grid point with Neumann boundary conditions, gradient in the second direction
static int PT_NEUMANN3
          Grid point with Neumann boundary conditions, gradient in the third direction
static int PT_OPEN
          Grid point is in an open region
static int PT_UNDEFINED
          Grid point type is undefined
 
Constructor Summary
PoissonGrid(int n1, int n2, int n3)
          Allocate a new PotentialGrid
 
Method Summary
protected  gov.sns.tools.math.r3.Grid.GridCell[][][] allocateCells(int n1, int n2, int n3)
          Override base class allocator in order to allocate modified grid cell objects.
protected  gov.sns.tools.math.r3.Grid.GridPt[][][] allocatePts(int n1, int n2, int n3)
          Override base class allocator in order to allocate modified grid point objects.
 R3 fieldCartesian(R3 pt)
          Compute and return the field in cartesian coordinates at point pt as generated by the potential values on the grid.
 R3 fieldCylindrical(R3 pt)
          Compute and return the field in cylindrical coordinates at point pt as generated by the potential values on the grid.
 R3 fieldSpherical(R3 pt)
          Compute and return the field in spherical coordinates at point pt as generated by the potential values on the grid.
protected  gov.sns.tools.math.r3.PoissonGrid.Point getPt(int i, int j, int k)
          Return grid point object located with index (i,j,k)
 double potential(R3 pt)
          Compute and return interpolated potential at a point pt within grid definition.
protected  double[] relaxWeightsCartesian()
          Compute the weighting coefficients of this grid for a Gauss-Seidel relaxation solution technique for Poisson's equation.
protected  double[] relaxWeightsCylindrical(double r)
          Compute the weighting coefficients of this grid for a Gauss-Seidel relaxation solution technique for Poisson's equation.
 void setPtPotential(int i, int j, int k, double dblPot)
          Set the potential value at grid point given by index
 void setPtSource(int i, int j, int k, double dblSrc)
          Set the source value at grid point given by index
 void setPtType(int i, int j, int k, int enmType)
          Set the type of the grid point given by index
 double solveCartesian(int intIterMax, double dblErrMax)
          Solve for the potential on the grid using a gauss-seidel relaxation technique.
 double solveCylindrical(int intIterMax, double dblErrMax)
          Solve for the potential on the grid using a gauss-seidel relaxation technique.
 
Methods inherited from class gov.sns.tools.math.r3.Grid
compCellContaining, compCellIndex, compPtCoords, compPtCoords, getGridCell, getGridCell, getGridDomain, getGridOrigin, getGridPt, getGridPt, getGridResolution, getGridSize, getPtValue, interpolateGradient, interpolateValue, main, membershipGrid, print, setGridDomain, setPtValue
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

PT_UNDEFINED

public static final int PT_UNDEFINED
Grid point type is undefined

See Also:
Constant Field Values

PT_OPEN

public static final int PT_OPEN
Grid point is in an open region

See Also:
Constant Field Values

PT_DIRICHLET

public static final int PT_DIRICHLET
Grid point is a boundary point with Dirichlet boundary conditions

See Also:
Constant Field Values

PT_NEUMANN1

public static final int PT_NEUMANN1
Grid point with Neumann boundary conditions, gradient in the first direction

See Also:
Constant Field Values

PT_NEUMANN2

public static final int PT_NEUMANN2
Grid point with Neumann boundary conditions, gradient in the second direction

See Also:
Constant Field Values

PT_NEUMANN3

public static final int PT_NEUMANN3
Grid point with Neumann boundary conditions, gradient in the third direction

See Also:
Constant Field Values
Constructor Detail

PoissonGrid

public PoissonGrid(int n1,
                   int n2,
                   int n3)
            throws GridException
Allocate a new PotentialGrid

Parameters:
n1 - number of grid points in first dimension
n2 - number of grid points in second dimension
n3 - number of grid points in third dimension
Throws:
GridException - invalid size vector encountered
Method Detail

setPtPotential

public void setPtPotential(int i,
                           int j,
                           int k,
                           double dblPot)
Set the potential value at grid point given by index

Parameters:
i - x dimension index of grid point
j - y dimension index of grid point
k - z dimension index of grid point
dblPot - value of the potential at grid point (i,j,k)

setPtType

public void setPtType(int i,
                      int j,
                      int k,
                      int enmType)
Set the type of the grid point given by index

Parameters:
i - x dimension index of grid point
j - y dimension index of grid point
k - z dimension index of grid point
enmType - type enumeration of grid point (i,j,k)

setPtSource

public void setPtSource(int i,
                        int j,
                        int k,
                        double dblSrc)
Set the source value at grid point given by index

Parameters:
i - x dimension index of grid point
j - y dimension index of grid point
k - z dimension index of grid point
dblSrc - value of the driving source at grid point (i,j,k)

solveCartesian

public double solveCartesian(int intIterMax,
                             double dblErrMax)
                      throws GridException
Solve for the potential on the grid using a gauss-seidel relaxation technique.

Parameters:
intIterMax - maximum number of iterations
dblErrMax - maximum residual error
Returns:
the residual error in the solution
Throws:
GridException - procedure did not converge to prescribed residual error

solveCylindrical

public double solveCylindrical(int intIterMax,
                               double dblErrMax)
                        throws GridException
Solve for the potential on the grid using a gauss-seidel relaxation technique.

Parameters:
intIterMax - maximum number of iterations
dblErrMax - maximum residual error
Returns:
the residual error in the solution
Throws:
GridException - procedure did not converge to prescribed residual error

potential

public double potential(R3 pt)
                 throws GridException
Compute and return interpolated potential at a point pt within grid definition. The potential is calculated by linear interpolation of the potential values at each vertex of the cell containing point pt. NOTES: - The grid may be in any coordinate system - The potential V must be determined for all points on the grid.

Parameters:
pt - coordinates of field point within grid
Returns:
interpolated potential at pt
Throws:
GridException - point pt is outside grid domain

fieldCartesian

public R3 fieldCartesian(R3 pt)
                  throws GridException
Compute and return the field in cartesian coordinates at point pt as generated by the potential values on the grid. NOTES: - The coordinates of the grid are assumed to be (x1,x2,x3)=(x,y,z) - The potential V must be determined for all points on the grid. - The generated field is given by F=-grad V where V is the potential on the grid.

Parameters:
pt - field point to compute field
Returns:
vector field at point pt in cartesian (Fx,Fy,Fz)
Throws:
GridException - field undefined or pt is outside grid

fieldCylindrical

public R3 fieldCylindrical(R3 pt)
                    throws GridException
Compute and return the field in cylindrical coordinates at point pt as generated by the potential values on the grid. NOTES: - The grid coordinates are assumed to be (x1,x2,x3)=(r,theta,z) - The potential V must be determined for all points on the grid. - The generated field is given by F=-grad V where V is the potential on the grid.

Parameters:
pt - field point to compute field
Returns:
vector field at point pt in cylindrical (Fr,Ftheta,Fz)
Throws:
GridException - field undefined or pt is outside grid

fieldSpherical

public R3 fieldSpherical(R3 pt)
                  throws GridException
Compute and return the field in spherical coordinates at point pt as generated by the potential values on the grid. NOTES: - The grid coordinates are assumed to be (x1,x2,x3)=(R,theta,phi) - The potential V must be determined for all points on the grid. - The generated field is given by F=-grad V where V is the potential on the grid.

Parameters:
pt - field point to compute field
Returns:
vector field at point pt in spherical (FR,Ftheta,Fphi)
Throws:
GridException - field undefined or pt is outside grid

getPt

protected gov.sns.tools.math.r3.PoissonGrid.Point getPt(int i,
                                                        int j,
                                                        int k)
Return grid point object located with index (i,j,k)


allocatePts

protected gov.sns.tools.math.r3.Grid.GridPt[][][] allocatePts(int n1,
                                                              int n2,
                                                              int n3)
                                                       throws GridException
Override base class allocator in order to allocate modified grid point objects. Allocates the array of grid points for the grid.

Overrides:
allocatePts in class Grid
Parameters:
n1 - size of the first dimension
n2 - size of the second dimension
n3 - size of the third dimension
Returns:
array of grid point objects
Throws:
GridException - unable to allocate array

allocateCells

protected gov.sns.tools.math.r3.Grid.GridCell[][][] allocateCells(int n1,
                                                                  int n2,
                                                                  int n3)
                                                           throws GridException
Override base class allocator in order to allocate modified grid cell objects. Allocates the array of grid cells for the grid

Overrides:
allocateCells in class Grid
Parameters:
n1 - size of the first dimension
n2 - size of the second dimension
n3 - size of the third dimension
Returns:
array of grid cell objects
Throws:
GridException - unable to allocate array

relaxWeightsCartesian

protected double[] relaxWeightsCartesian()
Compute the weighting coefficients of this grid for a Gauss-Seidel relaxation solution technique for Poisson's equation. The coefficients are determined for a cartesian coordinate system where the grid dimensions are assumed (x1,x2,x3)=(x,y,z).

Returns:
vector (ws,w1,w2,w3) of weights in the 1st, 2nd, 3rd dimensions and source term weight

relaxWeightsCylindrical

protected double[] relaxWeightsCylindrical(double r)
Compute the weighting coefficients of this grid for a Gauss-Seidel relaxation solution technique for Poisson's equation. The coefficients are determined for a cylindrical coordinate system where the grid dimensions are assumed (x1,x2,x3)=(r,theta,z).

Parameters:
r - the radius at which the weights are determined
Returns:
vector (ws,w1,w1p,w2,w3)