Package xal.tools.math.r3
Class PoissonGrid
java.lang.Object
xal.tools.math.r3.Grid
xal.tools.math.r3.PoissonGrid
- All Implemented Interfaces:
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 manually.
- 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).
- Author:
- Christopher Allen
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final int
Grid point is a boundary point with Dirichlet boundary conditionsstatic final int
Grid point with Neumann boundary conditions, gradient in the first directionstatic final int
Grid point with Neumann boundary conditions, gradient in the second directionstatic final int
Grid point with Neumann boundary conditions, gradient in the third directionstatic final int
Grid point is in an open regionstatic final int
Grid point type is undefined -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected xal.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 xal.tools.math.r3.Grid.GridPt[][][]
allocatePts
(int n1, int n2, int n3) Override base class allocator in order to allocate modified grid point objects.fieldCartesian
(R3 pt) Compute and return the field in cartesian coordinates at point pt as generated by the potential values on the grid.fieldCylindrical
(R3 pt) Compute and return the field in cylindrical coordinates at point pt as generated by the potential values on the grid.fieldSpherical
(R3 pt) Compute and return the field in spherical coordinates at point pt as generated by the potential values on the grid.protected xal.tools.math.r3.PoissonGrid.Point
getPt
(int i, int j, int k) Return grid point object located with index (i,j,k)double
Compute and return interpolated potential at a point pt within grid definition.protected double[]
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 indexvoid
setPtSource
(int i, int j, int k, double dblSrc) Set the source value at grid point given by indexvoid
setPtType
(int i, int j, int k, int enmType) Set the type of the grid point given by indexdouble
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 xal.tools.math.r3.Grid
compCellContaining, compCellIndex, compPtCoords, compPtCoords, getGridCell, getGridCell, getGridDomain, getGridOrigin, getGridPt, getGridPt, getGridResolution, getGridSize, getPtValue, interpolateGradient, interpolateValue, main, membershipGrid, print, setGridDomain, setPtValue
-
Field Details
-
PT_UNDEFINED
public static final int PT_UNDEFINEDGrid point type is undefined- See Also:
-
PT_OPEN
public static final int PT_OPENGrid point is in an open region- See Also:
-
PT_DIRICHLET
public static final int PT_DIRICHLETGrid point is a boundary point with Dirichlet boundary conditions- See Also:
-
PT_NEUMANN1
public static final int PT_NEUMANN1Grid point with Neumann boundary conditions, gradient in the first direction- See Also:
-
PT_NEUMANN2
public static final int PT_NEUMANN2Grid point with Neumann boundary conditions, gradient in the second direction- See Also:
-
PT_NEUMANN3
public static final int PT_NEUMANN3Grid point with Neumann boundary conditions, gradient in the third direction- See Also:
-
-
Constructor Details
-
PoissonGrid
Allocate a new PotentialGrid- Parameters:
n1
- number of grid points in first dimensionn2
- number of grid points in second dimensionn3
- number of grid points in third dimension- Throws:
GridException
- invalid size vector encountered
-
-
Method Details
-
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 pointj
- y dimension index of grid pointk
- z dimension index of grid pointdblPot
- 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 pointj
- y dimension index of grid pointk
- z dimension index of grid pointenmType
- 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 pointj
- y dimension index of grid pointk
- z dimension index of grid pointdblSrc
- value of the driving source at grid point (i,j,k)
-
solveCartesian
Solve for the potential on the grid using a Gauss-Seidel relaxation technique.- Parameters:
intIterMax
- maximum number of iterationsdblErrMax
- maximum residual error- Returns:
- the residual error in the solution
- Throws:
GridException
- procedure did not converge to prescribed residual error
-
solveCylindrical
Solve for the potential on the grid using a Gauss-Seidel relaxation technique.- Parameters:
intIterMax
- maximum number of iterationsdblErrMax
- maximum residual error- Returns:
- the residual error in the solution
- Throws:
GridException
- procedure did not converge to prescribed residual error
-
potential
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
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
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
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 xal.tools.math.r3.PoissonGrid.Point getPt(int i, int j, int k) Return grid point object located with index (i,j,k) -
allocatePts
protected xal.tools.math.r3.Grid.GridPt[][][] allocatePts(int n1, int n2, int n3) Override base class allocator in order to allocate modified grid point objects. Allocates the array of grid points for the grid.- Overrides:
allocatePts
in classGrid
- Parameters:
n1
- size of the first dimensionn2
- size of the second dimensionn3
- size of the third dimension- Returns:
- array of grid point objects
- Throws:
GridException
- unable to allocate array
-
allocateCells
protected xal.tools.math.r3.Grid.GridCell[][][] allocateCells(int n1, int n2, int n3) Override base class allocator in order to allocate modified grid cell objects. Allocates the array of grid cells for the grid- Overrides:
allocateCells
in classGrid
- Parameters:
n1
- size of the first dimensionn2
- size of the second dimensionn3
- 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)
-