Class PDEGrid2D

  • All Implemented Interfaces:
    Grid2D, java.io.Serializable

    public class PDEGrid2D
    extends java.lang.Object
    implements Grid2D, java.io.Serializable
    PDEGrid2D class facilitates 2D diffusion with two arrays of doubles called fields the intended usage is that during a diffusion tick, the current values will be read, and the prev values will be written to after updates, Update is called to set the prev field as the current field.
    See Also:
    Serialized Form
    • Field Summary

      Fields 
      Modifier and Type Field Description
      int length  
      boolean wrapX  
      boolean wrapY  
      int xDim  
      int yDim  
    • Constructor Summary

      Constructors 
      Constructor Description
      PDEGrid2D​(int xDim, int yDim)  
      PDEGrid2D​(int xDim, int yDim, boolean wrapX, boolean wrapY)  
    • Method Summary

      Modifier and Type Method Description
      void Add​(double x, double y, double val)  
      void Add​(int i, double val)
      adds to the prev field value at the specified index
      void Add​(int x, int y, double val)
      sets the prev field value at the specified coordinates
      void AddAll​(double val)
      adds specified value to all entries of the delta field
      void Advection​(double[] xVels, double[] yVels)
      runs discontinuous advection
      void Advection​(double[] xVels, double[] yVels, Coords2DDouble BoundaryyConditionFn, Coords2DDouble BoundaryXvels, Coords2DDouble BoundaryYvels)
      runs discontinuous advection
      void Advection​(double xVel, double yVel)  
      void Advection​(double xVel, double yVel, double boundaryValue)
      runs advection as described above with a boundary value, meaning that the boundary value will advect in from the upwind direction, and the concentration will disappear in the downwind direction.
      void Advection​(double xVel, double yVel, Coords2DDouble BoundaryConditionFn)
      runs advection as described above with a boundary condition function, which will be evaluated with the out of bounds coordinates as arguments whenever a boundary value is needed, and should return the boundary value
      void Advection​(Grid2Ddouble xVels, Grid2Ddouble yVels)
      runs discontinuous advection
      void Advection​(Grid2Ddouble xVels, Grid2Ddouble yVels, Coords2DDouble BoundaryyConditionFn, Coords2DDouble BoundaryXvels, Coords2DDouble BoundaryYvels)
      runs discontinuous advection
      void Diffusion​(double diffCoef)
      runs diffusion on the current field, adding the deltas to the delta field.
      void Diffusion​(double[] diffRatesX, double[] diffRatesY)
      runs diffusion with discontinuous diffusion rates
      void Diffusion​(double[] diffRatesX, double[] diffRatesY, Coords2DDouble BoundaryConditionFn, Coords2DDouble BoundaryDiffusionRatesX, Coords2DDouble BoundaryDiffusionRatesY)
      runs diffusion with discontinuous diffusion rates
      void Diffusion​(double diffCoef, double boundaryValue)
      has the same effect as the above diffusion function without the boundary value argument, except rather than assuming zero flux, the boundary condition is set to either the boundaryValue, or wrap around
      void Diffusion​(double diffCoef, Coords2DDouble BoundaryConditionFn)
      has the same effect as the above diffusion function with a boundary condition function, which will be evaluated with the out of bounds coordinates as arguments whenever a boundary value is needed, and should return the boundary value
      void Diffusion​(Grid2Ddouble diffRatesX, Grid2Ddouble diffRatesY)
      runs diffusion with discontinuous diffusion rates
      void Diffusion​(Grid2Ddouble diffRatesX, Grid2Ddouble diffRatesY, Coords2DDouble BoundaryConditionFn, Coords2DDouble BoundaryDiffusionRatesX, Coords2DDouble BoundaryDiffusionRatesY)
      runs diffusion with discontinuous diffusion rates
      static void Diffusion2DADIBetweenAction​(double[] field, double[] scratch, double[] deltas, double diffRate, int xDim, int yDim, boolean wrapX, boolean wrapY, Coords2DDouble BC, TdmaSolver tdma, DoubleArrayToVoid BetweenAction)  
      void DiffusionADI​(double diffCoef)  
      void DiffusionADI​(double diffCoef, double boundaryCond)  
      void DiffusionADI​(double diffCoef, double boundaryCond, DoubleArrayToVoid BetweenAction)  
      double Get​(double x, double y)  
      double Get​(int i)
      gets the prev field value at the specified index
      double Get​(int x, int y)
      gets the prev field value at the specified coordinates
      double GetAvg()
      gets the average value of all squares in the current field
      double[] GetDeltas()  
      double[] GetField()  
      double GetMax()
      returns the max value in the grid
      double GetMin()
      returns the min value in the grid
      double GradientX​(double x, double y)  
      double GradientX​(double x, double y, double boundaryCond)  
      double GradientX​(int x, int y)
      returns the gradient of the diffusible in the X direction at the coordinates specified
      double GradientX​(int x, int y, double boundaryCond)
      returns the gradient of the diffusible in the X direction at the coordinates specified, will use the boundary condition value if computing the gradient next to the boundary
      double GradientY​(double x, double y)  
      double GradientY​(double x, double y, double boundaryCond)  
      double GradientY​(int x, int y)
      returns the gradient of the diffusible in the Y direction at the coordinates specified
      double GradientY​(int x, int y, double boundaryCond)
      returns the gradient of the diffusible in the Y direction at the coordinates specified, will use the boundary condition value if computing the gradient next to the boundary
      boolean IsWrapX()  
      boolean IsWrapY()  
      int Length()  
      double MaxDelta()
      returns the maximum difference as stored on the delta field, call right before calling Update()
      double MaxDeltaScaled​(double denomOffset)
      like MaxDelta only the differences are scaled relative to the value in the current field.
      void Mul​(double x, double y, double val)  
      void Mul​(int i, double val)
      multiplies a value in the “current field” and adds the change to the “delta field”
      void Mul​(int x, int y, double val)
      multiplies a value in the “current field” and adds the change to the “delta field”
      void MulAll​(double val)
      multiplies all values in the “current field” and puts the results into the “delta field”
      void Set​(double x, double y, double val)  
      void Set​(int i, double val)
      sets the prev field value at the specified index
      void Set​(int x, int y, double val)
      sets the prev field value at the specified coordinates
      void SetAll​(double val)
      sets all squares in the delta field to the specified value
      void SetAll​(double[] vals)
      sets all squares in the delta field using the vals array
      void SetNonNegative()
      ensures that all values will be non-negative on the next timestep, call before Update
      void Update()
      adds the delta field into the current field
      int UpdateCt()  
      int Xdim()  
      int Ydim()  
      • Methods inherited from class java.lang.Object

        equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • xDim

        public final int xDim
      • yDim

        public final int yDim
      • length

        public final int length
      • wrapX

        public boolean wrapX
      • wrapY

        public boolean wrapY
    • Constructor Detail

      • PDEGrid2D

        public PDEGrid2D​(int xDim,
                         int yDim)
      • PDEGrid2D

        public PDEGrid2D​(int xDim,
                         int yDim,
                         boolean wrapX,
                         boolean wrapY)
    • Method Detail

      • UpdateCt

        public int UpdateCt()
      • GetField

        public double[] GetField()
      • GetDeltas

        public double[] GetDeltas()
      • DiffusionADI

        public void DiffusionADI​(double diffCoef)
      • DiffusionADI

        public void DiffusionADI​(double diffCoef,
                                 double boundaryCond)
      • DiffusionADI

        public void DiffusionADI​(double diffCoef,
                                 double boundaryCond,
                                 DoubleArrayToVoid BetweenAction)
      • Diffusion2DADIBetweenAction

        public static void Diffusion2DADIBetweenAction​(double[] field,
                                                       double[] scratch,
                                                       double[] deltas,
                                                       double diffRate,
                                                       int xDim,
                                                       int yDim,
                                                       boolean wrapX,
                                                       boolean wrapY,
                                                       Coords2DDouble BC,
                                                       TdmaSolver tdma,
                                                       DoubleArrayToVoid BetweenAction)
      • Get

        public double Get​(int x,
                          int y)
        gets the prev field value at the specified coordinates
      • Get

        public double Get​(double x,
                          double y)
      • Get

        public double Get​(int i)
        gets the prev field value at the specified index
      • Set

        public void Set​(int x,
                        int y,
                        double val)
        sets the prev field value at the specified coordinates
      • Set

        public void Set​(double x,
                        double y,
                        double val)
      • Set

        public void Set​(int i,
                        double val)
        sets the prev field value at the specified index
      • Add

        public void Add​(int x,
                        int y,
                        double val)
        sets the prev field value at the specified coordinates
      • Add

        public void Add​(double x,
                        double y,
                        double val)
      • Add

        public void Add​(int i,
                        double val)
        adds to the prev field value at the specified index
      • Mul

        public void Mul​(int x,
                        int y,
                        double val)
        multiplies a value in the “current field” and adds the change to the “delta field”
      • Mul

        public void Mul​(double x,
                        double y,
                        double val)
      • Mul

        public void Mul​(int i,
                        double val)
        multiplies a value in the “current field” and adds the change to the “delta field”
      • GetMax

        public double GetMax()
        returns the max value in the grid
      • GetMin

        public double GetMin()
        returns the min value in the grid
      • Update

        public void Update()
        adds the delta field into the current field
      • Advection

        public void Advection​(double xVel,
                              double yVel)
      • Advection

        public void Advection​(double xVel,
                              double yVel,
                              double boundaryValue)
        runs advection as described above with a boundary value, meaning that the boundary value will advect in from the upwind direction, and the concentration will disappear in the downwind direction.
      • Advection

        public void Advection​(double xVel,
                              double yVel,
                              Coords2DDouble BoundaryConditionFn)
        runs advection as described above with a boundary condition function, which will be evaluated with the out of bounds coordinates as arguments whenever a boundary value is needed, and should return the boundary value
      • Advection

        public void Advection​(double[] xVels,
                              double[] yVels)
        runs discontinuous advection
      • Diffusion

        public void Diffusion​(double diffCoef)
        runs diffusion on the current field, adding the deltas to the delta field. This form of the function assumes either a reflective or wrapping boundary (depending on how the PDEGrid was specified). the diffCoef variable is the nondimensionalized diffusion conefficient. If the dimensionalized diffusion coefficient is x then diffCoef can be found by computing (x*SpaceStep)/TimeStep^2 Note that if the diffCoef exceeds 0.25, this diffusion method will become numerically unstable.
      • Diffusion

        public void Diffusion​(double diffCoef,
                              double boundaryValue)
        has the same effect as the above diffusion function without the boundary value argument, except rather than assuming zero flux, the boundary condition is set to either the boundaryValue, or wrap around
      • Diffusion

        public void Diffusion​(double diffCoef,
                              Coords2DDouble BoundaryConditionFn)
        has the same effect as the above diffusion function with a boundary condition function, which will be evaluated with the out of bounds coordinates as arguments whenever a boundary value is needed, and should return the boundary value
      • Diffusion

        public void Diffusion​(double[] diffRatesX,
                              double[] diffRatesY)
        runs diffusion with discontinuous diffusion rates
      • Diffusion

        public void Diffusion​(Grid2Ddouble diffRatesX,
                              Grid2Ddouble diffRatesY)
        runs diffusion with discontinuous diffusion rates
      • Diffusion

        public void Diffusion​(double[] diffRatesX,
                              double[] diffRatesY,
                              Coords2DDouble BoundaryConditionFn,
                              Coords2DDouble BoundaryDiffusionRatesX,
                              Coords2DDouble BoundaryDiffusionRatesY)
        runs diffusion with discontinuous diffusion rates
      • SetAll

        public void SetAll​(double val)
        sets all squares in the delta field to the specified value
      • MulAll

        public void MulAll​(double val)
        multiplies all values in the “current field” and puts the results into the “delta field”
      • SetAll

        public void SetAll​(double[] vals)
        sets all squares in the delta field using the vals array
      • AddAll

        public void AddAll​(double val)
        adds specified value to all entries of the delta field
      • GetAvg

        public double GetAvg()
        gets the average value of all squares in the current field
      • MaxDelta

        public double MaxDelta()
        returns the maximum difference as stored on the delta field, call right before calling Update()
      • MaxDeltaScaled

        public double MaxDeltaScaled​(double denomOffset)
        like MaxDelta only the differences are scaled relative to the value in the current field. the denomOffset is used to prevent a division by zero
      • GradientX

        public double GradientX​(int x,
                                int y)
        returns the gradient of the diffusible in the X direction at the coordinates specified
      • GradientX

        public double GradientX​(double x,
                                double y)
      • GradientY

        public double GradientY​(int x,
                                int y)
        returns the gradient of the diffusible in the Y direction at the coordinates specified
      • GradientY

        public double GradientY​(double x,
                                double y)
      • GradientX

        public double GradientX​(int x,
                                int y,
                                double boundaryCond)
        returns the gradient of the diffusible in the X direction at the coordinates specified, will use the boundary condition value if computing the gradient next to the boundary
      • GradientX

        public double GradientX​(double x,
                                double y,
                                double boundaryCond)
      • GradientY

        public double GradientY​(int x,
                                int y,
                                double boundaryCond)
        returns the gradient of the diffusible in the Y direction at the coordinates specified, will use the boundary condition value if computing the gradient next to the boundary
      • GradientY

        public double GradientY​(double x,
                                double y,
                                double boundaryCond)
      • SetNonNegative

        public void SetNonNegative()
        ensures that all values will be non-negative on the next timestep, call before Update
      • Xdim

        public int Xdim()
        Specified by:
        Xdim in interface Grid2D
      • Ydim

        public int Ydim()
        Specified by:
        Ydim in interface Grid2D
      • Length

        public int Length()
        Specified by:
        Length in interface Grid2D
      • IsWrapX

        public boolean IsWrapX()
        Specified by:
        IsWrapX in interface Grid2D
      • IsWrapY

        public boolean IsWrapY()
        Specified by:
        IsWrapY in interface Grid2D