Package microsim.space
Class DoubleDiffuseSpace
- All Implemented Interfaces:
EventListener
Discrete 2nd order approximation of 2d diffusion with evaporation.
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic enum
static enum
-
Field Summary
Fields inherited from class microsim.space.DoubleSpace
m
Fields inherited from class microsim.space.AbstractSpace
modCount, xSize, ySize
-
Constructor Summary
ConstructorDescriptionDoubleDiffuseSpace
(int xSize, int ySize) Constructs a space with the specified dimensions.DoubleDiffuseSpace
(int xSize, int ySize, double diffusionConstant, double evaporationRate) Constructs a space with the specified diffusion constant, evaporation rate, and dimensions. -
Method Summary
Modifier and TypeMethodDescriptionvoid
diffuse()
Runs the diffusion with the current rates and values.double[]
findMaximum
(int x, int y, int range, boolean includeOrigin, @NonNull DoubleDiffuseSpace.NEIGHBOURHOOD_TYPE nt) Finds the maximum grid cell value within a specified range from the specified origin coordinate.double @NonNull []
findMinimum
(int x, int y, int range, boolean includeOrigin, @NonNull DoubleDiffuseSpace.NEIGHBOURHOOD_TYPE nt) Finds the minimum grid cell value within a specified range from the specified origin coordinate.double @NonNull []
Return the matrix of values representing the grid.double @NonNull []
getMooreNeighbors
(int x, int y) Gets the Moore neighbors of the specified coordinate.double @NonNull []
getMooreNeighbors
(int x, int y, int xExtent, int yExtent) Gets the extended Moore neighbors of the specified coordinate.double @NonNull []
getVonNeumannNeighbors
(int x, int y) Gets the von Neumann neighbors of the specified coordinate.double @NonNull []
getVonNeumannNeighbors
(int x, int y, int xExtent, int yExtent) Gets the extended von Neumann neighbors of the specified coordinate.void
void
print
(double @NonNull [] mtr) void
update()
Copies the writeMatrix to the readMatrixMethods inherited from class microsim.space.DoubleSpace
add, at, clear, copyGridTo, copyGridTo, countObjectsAt, get, getDbl, max, mean, min, multiply, resetTo, set, setDbl, size, sum, swapPositions, variance
Methods inherited from class microsim.space.AbstractSpace
boundX, boundY, equals, getMooreNeighborsPositions, getVonNeumannNeighborsPositions, reflectX, reflectY, torusX, torusY, toString
-
Field Details
-
MAX
public static final long MAX- See Also:
-
-
Constructor Details
-
DoubleDiffuseSpace
public DoubleDiffuseSpace(int xSize, int ySize) Constructs a space with the specified dimensions.- Parameters:
xSize
- The size of thex
dimension.ySize
- The size of they
dimension.
-
DoubleDiffuseSpace
public DoubleDiffuseSpace(int xSize, int ySize, double diffusionConstant, double evaporationRate) Constructs a space with the specified diffusion constant, evaporation rate, and dimensions.- Parameters:
diffusionConstant
- The diffusion constant.evaporationRate
- The evaporation rate.xSize
- The size of thex
dimension.ySize
- The size of they
dimension.
-
-
Method Details
-
diffuse
public void diffuse()Runs the diffusion with the current rates and values. Roughly follows this:newValue = evap(ownValue + diffusionConstant * (nghAvg - ownValue))
wherenghAvg
is the weighted average of a cells eight neighbors, and ownValue is the current value for the current cell. -
update
public void update()Copies the writeMatrix to the readMatrix -
print
public void print(double @NonNull [] mtr) -
getVonNeumannNeighbors
public double @NonNull [] getVonNeumannNeighbors(int x, int y) Gets the von Neumann neighbors of the specified coordinate. Doubles are returned in west, east, north, south order. The double at(x,y)
is not returned.- Parameters:
x
- Thex
coordinate of the object.y
- They
coordinate of the object.- Returns:
- an array of doubles in west, east, north, south order.
-
getVonNeumannNeighbors
public double @NonNull [] getVonNeumannNeighbors(int x, int y, int xExtent, int yExtent) Gets the extended von Neumann neighbors of the specified coordinate. The extension in thex
andy
direction are specified byxExtent
andyExtent
. Doubles are returned in west, east, north, south order with the most distant object first. The double at(x,y)
is not returned.- Parameters:
x
- Thex
coordinate of the object.y
- They
coordinate of the object.xExtent
- The extension of the neighborhood in thex
direction.yExtent
- The extension of the neighborhood in they
direction.- Returns:
- an array of doubles in west, east, north, south order with the most distant object first.
-
getMooreNeighbors
public double @NonNull [] getMooreNeighbors(int x, int y) Gets the Moore neighbors of the specified coordinate. Doubles are returned by row starting with the "NW corner" and ending with the "SE corner." The double at(x,y)
is not returned.- Parameters:
x
- Thex
coordinate of the object.y
- They
coordinate of the object.- Returns:
- an array of doubles ordered by row starting with the "NW corner" and ending with the "SE corner".
-
getMooreNeighbors
public double @NonNull [] getMooreNeighbors(int x, int y, int xExtent, int yExtent) Gets the extended Moore neighbors of the specified coordinate. The extension in thex
andy
direction are specified byxExtent
andyExtent
. Doubles are returned by row starting with the "NW corner" and ending with the "SE corner". The double at(x,y)
is not returned.- Parameters:
x
- Thex
coordinate of the object.y
- They
coordinate of the object.xExtent
- The extension of the neighborhood in thex
direction.yExtent
- The extension of the neighborhood in they
direction.- Returns:
- an array of doubles ordered by row starting with the "NW corner" and ending with the "SE corner".
-
findMaximum
public double[] findMaximum(int x, int y, int range, boolean includeOrigin, @NonNull @NonNull DoubleDiffuseSpace.NEIGHBOURHOOD_TYPE nt) Finds the maximum grid cell value within a specified range from the specified origin coordinate.- Parameters:
x
- Thex
origin coordinate.y
- They
origin coordinate.range
- The range out from the coordinate to search.includeOrigin
- Include object at origin in search.nt
- The type of neighborhood to search. Can be one ofDoubleDiffuseSpace.NEIGHBOURHOOD_TYPE.VON_NEUMANN
orDoubleDiffuseSpace.NEIGHBOURHOOD_TYPE.MOORE
.- Returns:
- the Objects determined to be the maximum.
-
findMinimum
public double @NonNull [] findMinimum(int x, int y, int range, boolean includeOrigin, @NonNull @NonNull DoubleDiffuseSpace.NEIGHBOURHOOD_TYPE nt) Finds the minimum grid cell value within a specified range from the specified origin coordinate.- Parameters:
x
- The x origin coordinate.y
- The y origin coordinate.range
- The range out from the coordinate to search.includeOrigin
- T include object at origin in search.nt
- The type of neighborhood to search. Can be one ofDoubleDiffuseSpace.NEIGHBOURHOOD_TYPE.VON_NEUMANN
orDoubleDiffuseSpace.NEIGHBOURHOOD_TYPE.MOORE
.- Returns:
- the Objects determined to be the maximum.
-
getMatrix
public double @NonNull [] getMatrix()Description copied from class:DoubleSpace
Return the matrix of values representing the grid.- Overrides:
getMatrix
in classDoubleSpace
- Returns:
- A matrix of double with the same dimensions of the grid.
-
onEvent
- Specified by:
onEvent
in interfaceEventListener
-