Class PoissonGrid

java.lang.Object
xal.tools.math.r3.Grid
xal.tools.math.r3.PoissonGrid
All Implemented Interfaces:
Serializable

public class PoissonGrid extends Grid implements 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

    Fields
    Modifier and Type
    Field
    Description
    static final int
    Grid point is a boundary point with Dirichlet boundary conditions
    static final int
    Grid point with Neumann boundary conditions, gradient in the first direction
    static final int
    Grid point with Neumann boundary conditions, gradient in the second direction
    static final int
    Grid point with Neumann boundary conditions, gradient in the third direction
    static final int
    Grid point is in an open region
    static final int
    Grid point type is undefined
  • Constructor Summary

    Constructors
    Constructor
    Description
    PoissonGrid(int n1, int n2, int n3)
    Allocate a new PotentialGrid
  • Method Summary

    Modifier and Type
    Method
    Description
    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.
    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.
    Compute and return the field in cartesian coordinates at point pt as generated by the potential values on the grid.
    Compute and return the field in cylindrical coordinates at point pt as generated by the potential values on the grid.
    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[]
    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 java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • PT_UNDEFINED

      public static final int PT_UNDEFINED
      Grid point type is undefined
      See Also:
    • PT_OPEN

      public static final int PT_OPEN
      Grid point is in an open region
      See Also:
    • PT_DIRICHLET

      public static final int PT_DIRICHLET
      Grid point is a boundary point with Dirichlet boundary conditions
      See Also:
    • PT_NEUMANN1

      public static final int PT_NEUMANN1
      Grid point with Neumann boundary conditions, gradient in the first direction
      See Also:
    • PT_NEUMANN2

      public static final int PT_NEUMANN2
      Grid point with Neumann boundary conditions, gradient in the second direction
      See Also:
    • PT_NEUMANN3

      public static final int PT_NEUMANN3
      Grid point with Neumann boundary conditions, gradient in the third direction
      See Also:
  • Constructor Details

    • 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 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 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 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 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 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 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)