Package HAL.GridsAndAgents
Class PDEGrid2D
- java.lang.Object
-
- HAL.GridsAndAgents.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
-
-
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 indexvoid
Add(int x, int y, double val)
sets the prev field value at the specified coordinatesvoid
AddAll(double val)
adds specified value to all entries of the delta fieldvoid
Advection(double[] xVels, double[] yVels)
runs discontinuous advectionvoid
Advection(double[] xVels, double[] yVels, Coords2DDouble BoundaryyConditionFn, Coords2DDouble BoundaryXvels, Coords2DDouble BoundaryYvels)
runs discontinuous advectionvoid
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 valuevoid
Advection(Grid2Ddouble xVels, Grid2Ddouble yVels)
runs discontinuous advectionvoid
Advection(Grid2Ddouble xVels, Grid2Ddouble yVels, Coords2DDouble BoundaryyConditionFn, Coords2DDouble BoundaryXvels, Coords2DDouble BoundaryYvels)
runs discontinuous advectionvoid
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 ratesvoid
Diffusion(double[] diffRatesX, double[] diffRatesY, Coords2DDouble BoundaryConditionFn, Coords2DDouble BoundaryDiffusionRatesX, Coords2DDouble BoundaryDiffusionRatesY)
runs diffusion with discontinuous diffusion ratesvoid
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 aroundvoid
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 valuevoid
Diffusion(Grid2Ddouble diffRatesX, Grid2Ddouble diffRatesY)
runs diffusion with discontinuous diffusion ratesvoid
Diffusion(Grid2Ddouble diffRatesX, Grid2Ddouble diffRatesY, Coords2DDouble BoundaryConditionFn, Coords2DDouble BoundaryDiffusionRatesX, Coords2DDouble BoundaryDiffusionRatesY)
runs diffusion with discontinuous diffusion ratesstatic 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 indexdouble
Get(int x, int y)
gets the prev field value at the specified coordinatesdouble
GetAvg()
gets the average value of all squares in the current fielddouble[]
GetDeltas()
double[]
GetField()
double
GetMax()
returns the max value in the griddouble
GetMin()
returns the min value in the griddouble
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 specifieddouble
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 boundarydouble
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 specifieddouble
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 boundaryboolean
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 indexvoid
Set(int x, int y, double val)
sets the prev field value at the specified coordinatesvoid
SetAll(double val)
sets all squares in the delta field to the specified valuevoid
SetAll(double[] vals)
sets all squares in the delta field using the vals arrayvoid
SetNonNegative()
ensures that all values will be non-negative on the next timestep, call before Updatevoid
Update()
adds the delta field into the current fieldint
UpdateCt()
int
Xdim()
int
Ydim()
-
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface HAL.Interfaces.Grid2D
AlongLineIs, ApplyHood, ApplyHood, ApplyHoodMapped, ApplyRectangle, BoundaryIs, ContainsValidI, ContainsValidI, DispX, DispY, Dist, DistSquared, GetHoodI, I, I, In, In, InWrap, ItoX, ItoY, MapHood, MapHood, MapHood, MapHood, MapI, MapXpt, MapXsq, MapYpt, MapYsq, RandomHoodI, WrapI
-
-
-
-
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
-
Advection
public void Advection(Grid2Ddouble xVels, Grid2Ddouble yVels)
runs discontinuous advection
-
Advection
public void Advection(double[] xVels, double[] yVels, Coords2DDouble BoundaryyConditionFn, Coords2DDouble BoundaryXvels, Coords2DDouble BoundaryYvels)
runs discontinuous advection
-
Advection
public void Advection(Grid2Ddouble xVels, Grid2Ddouble yVels, Coords2DDouble BoundaryyConditionFn, Coords2DDouble BoundaryXvels, Coords2DDouble BoundaryYvels)
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
-
Diffusion
public void Diffusion(Grid2Ddouble diffRatesX, Grid2Ddouble 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
-
-