Class Grid

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

public class Grid extends Object implements Serializable

Represents a regular grid in three dimensions. Grid resolution may vary in each dimension, however, no uneven mesh spacing is permitted. Consequently, operations on this grid are less general but faster.

This class was originally meant to be used in a multi-particle probe for multi-particle simulations. I don't believe it is being used for anything right now.

Since:
Jan 24, 2003
Author:
Christopher Allen
See Also:
  • Constructor Summary

    Constructors
    Constructor
    Description
    Grid(int n1, int n2, int n3)
    Allocate a new Grid
    Grid(int n1, int n2, int n3, ClosedBox boxDom)
    Allocate a new instance of GridR3 and set the domain.
  • Method Summary

    Modifier and Type
    Method
    Description
    protected xal.tools.math.r3.Grid.GridCell[][][]
    allocateCells(int n1, int n2, int n3)
    Allocates the array of grid cell objects.
    protected xal.tools.math.r3.Grid.GridPt[][][]
    allocatePts(int n1, int n2, int n3)
    Allocates the array of grid point objects.
    xal.tools.math.r3.Grid.GridCell
    Return the grid cell containing this point.
    Compute the base vertex index of grid cell containing this point.
    compPtCoords(int i, int j, int k)
    Return the coordinates in R3 of the grid point at index (i,j,k)
    compPtCoords(Z3 vecIndex)
    Return the coordinates in R3 of the grid point at index (i,j,k)
    protected xal.tools.math.r3.Grid.GridCell
    getGridCell(int i, int j, int k)
    Return the grid cell object located at grid point index.
    protected xal.tools.math.r3.Grid.GridCell
    getGridCell(Z3 vecInd)
    Return the grid cell object located at grid cell index.
    Get the domain of the grid in R3.
    Get the coordinates of the grid origin, i.e., the first grid vertex.
    protected xal.tools.math.r3.Grid.GridPt
    getGridPt(int i, int j, int k)
    Return the grid point object located at grid point index.
    protected xal.tools.math.r3.Grid.GridPt
    getGridPt(Z3 vecInd)
    Return the grid point object located at grid point index.
    Get grid resolution.
    Get the size of the supporting object array.
    double
    getPtValue(int i, int j, int k)
    Get the function value at the grid point indexed by (i,j,k)
    Compute and return the interpolated function gradient at the point pt.
    double
    Compute and return the interpolated function value at the point pt
    static void
    main(String[] args)
    Testing engine
    boolean
    Determine whether a point is an element of the domain of definition for this grid.
    void
    Print out grid parameters on an output stream
    void
    Set the domain in R3 which the grid occupies.
    void
    setPtValue(int i, int j, int k, double dblVal)
    Set the function value at grid point given by index

    Methods inherited from class java.lang.Object

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

    • Grid

      public Grid(int n1, int n2, int n3) throws GridException
      Allocate a new Grid
      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 - unable to allocate grid objects
    • Grid

      public Grid(int n1, int n2, int n3, ClosedBox boxDom) throws GridException
      Allocate a new instance of GridR3 and set the domain.
      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
      boxDom - descriptor of grid domain in R3
      Throws:
      GridException - invalid size vector encountered
  • Method Details

    • setGridDomain

      public void setGridDomain(ClosedBox boxDom) throws GridException
      Set the domain in R3 which the grid occupies. All grid point locations are determined by this descriptor.
      Parameters:
      boxDom - description of the grid position and size in R3
      Throws:
      GridException
    • setPtValue

      public void setPtValue(int i, int j, int k, double dblVal)
      Set the function value at grid point given by index
      Parameters:
      i - first dimension index of grid point
      j - second dimension index of grid point
      k - third dimension index of grid point
      dblVal - value of the function at grid point (i,j,k)
    • getGridSize

      public Z3 getGridSize()
      Get the size of the supporting object array.
      Returns:
      vector of array dimensions (nx, ny, nz)
    • getGridDomain

      public ClosedBox getGridDomain()
      Get the domain of the grid in R3.
      Returns:
      a ClosedBox object describing the domain of definition for this grid
    • getGridResolution

      public R3 getGridResolution()
      Get grid resolution.
      Returns:
      vector (dx,dy,dz) of spacing between grid points
    • getGridOrigin

      public R3 getGridOrigin()
      Get the coordinates of the grid origin, i.e., the first grid vertex.
      Returns:
      (x,y,z) coordinates of grid origin
    • getPtValue

      public double getPtValue(int i, int j, int k)
      Get the function value at the grid point indexed by (i,j,k)
      Parameters:
      i - index of the first grid dimension
      j - index of the second grid dimension
      k - index of the third grid dimension
      Returns:
      function value stored at grid point (i,j,k)
    • membershipGrid

      public boolean membershipGrid(R3 pt)
      Determine whether a point is an element of the domain of definition for this grid.
      Parameters:
      pt - point in R3 to check membership
      Returns:
      true if pt is in domain of definition
    • compCellIndex

      public Z3 compCellIndex(R3 pt)
      Compute the base vertex index of grid cell containing this point. The base vertex is the vertex of the grid cell with smallest l1 norm. Grid cells are assigned by this index.
      Parameters:
      pt - pt in R3 (within the grid's domain of definition)
      Returns:
      index of grid cell owning pt
    • compPtCoords

      public R3 compPtCoords(int i, int j, int k)
      Return the coordinates in R3 of the grid point at index (i,j,k)
      Parameters:
      i - x-dimension index of grid point
      j - y-dimension index of grid point
      k - k-dimension index of grid point
      Returns:
      (x,y,z) coordinate of grid point at (i,j,k)
    • compPtCoords

      public R3 compPtCoords(Z3 vecIndex)
      Return the coordinates in R3 of the grid point at index (i,j,k)
      Parameters:
      vecIndex - (i,j,k) index vector of grid point
      Returns:
      (x,y,z) coordinate of grid point at (i,j,k)
    • compCellContaining

      public xal.tools.math.r3.Grid.GridCell compCellContaining(R3 pt)
      Return the grid cell containing this point.
      Parameters:
      pt - pt in R3 (within the grid's domain of definition)
      Returns:
      grid cell object contain pt
    • interpolateValue

      public double interpolateValue(R3 pt)
      Compute and return the interpolated function value at the point pt
      Parameters:
      pt - interpolation point
      Returns:
      interpolated function value
    • interpolateGradient

      public R3 interpolateGradient(R3 pt)
      Compute and return the interpolated function gradient at the point pt. The gradient is taken with respect to the local coordinates of a grid cell. Thus, the true gradient must be scaled by the grid resolution and any other differential element particular to the coordinate system being used.
      Parameters:
      pt - interpolation point
      Returns:
      gradient (w.r.t. local cell coords) of function
    • print

      public void print(PrintWriter os)
      Print out grid parameters on an output stream
      Parameters:
      os - output stream to receive text description of grid
    • main

      public static void main(String[] args)
      Testing engine
    • getGridPt

      protected xal.tools.math.r3.Grid.GridPt getGridPt(int i, int j, int k)
      Return the grid point object located at grid point index.
      Parameters:
      i - 1st dimension grid point index
      j - 2nd dimension grid point index
      k - 3rd dimension grid point index
      Returns:
      object located at grid point (i,j,k)
    • getGridPt

      protected xal.tools.math.r3.Grid.GridPt getGridPt(Z3 vecInd)
      Return the grid point object located at grid point index.
      Parameters:
      vecInd - vector index (i,j,k) of grid point
      Returns:
      object located at grid point (i,j,k)
    • getGridCell

      protected xal.tools.math.r3.Grid.GridCell getGridCell(int i, int j, int k)
      Return the grid cell object located at grid point index.
      Parameters:
      i - 1st dimension grid cell index
      j - 2nd dimension grid cell index
      k - 3rd dimension grid cell index
      Returns:
      object located at grid cell (i,j,k)
    • getGridCell

      protected xal.tools.math.r3.Grid.GridCell getGridCell(Z3 vecInd)
      Return the grid cell object located at grid cell index.
      Parameters:
      vecInd - vector index (i,j,k) of grid cell
      Returns:
      object located at grid cell (i,j,k)
    • allocatePts

      protected xal.tools.math.r3.Grid.GridPt[][][] allocatePts(int n1, int n2, int n3)
      Allocates the array of grid point objects. Derived classes may create grid point objects derived from GridPt to perform specific tasks. Derived classes must override this method if the GridPt class also sub-classed. The array of appropriate child class of GridPt should be returned.
      Parameters:
      n1 - , n2, n3 dimensions of the array (n1, n2, n3)
      Returns:
      array of objects living at grid points
    • allocateCells

      protected xal.tools.math.r3.Grid.GridCell[][][] allocateCells(int n1, int n2, int n3)
      Allocates the array of grid cell objects. Derived classes may create grid cell objects derived from GridCell to perform specific tasks. Derived classes must override this method if the GridCell class also subclassed. The array of appropriate child class of GridCell should be returned.
      Parameters:
      n1 - , n2, n3 dimensions of the array (nx, ny, nz)
      Returns:
      array of objects composing grid cells