Package microsim.space
Class DoubleDiffuseSpace
- All Implemented Interfaces:
EventListener
Discrete 2nd order approximation of 2d diffusion with evaporation.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic enumstatic enum -
Field Summary
FieldsFields inherited from class microsim.space.DoubleSpace
mFields inherited from class microsim.space.AbstractSpace
modCount, xSize, ySize -
Constructor Summary
ConstructorsConstructorDescriptionDoubleDiffuseSpace(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 TypeMethodDescriptionvoiddiffuse()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.voidvoidprint(double @NonNull [] mtr) voidupdate()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, varianceMethods 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 thexdimension.ySize- The size of theydimension.
-
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 thexdimension.ySize- The size of theydimension.
-
-
Method Details
-
diffuse
public void diffuse()Runs the diffusion with the current rates and values. Roughly follows this:newValue = evap(ownValue + diffusionConstant * (nghAvg - ownValue))wherenghAvgis 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- Thexcoordinate of the object.y- Theycoordinate 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 thexandydirection are specified byxExtentandyExtent. 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- Thexcoordinate of the object.y- Theycoordinate of the object.xExtent- The extension of the neighborhood in thexdirection.yExtent- The extension of the neighborhood in theydirection.- 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- Thexcoordinate of the object.y- Theycoordinate 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 thexandydirection are specified byxExtentandyExtent. 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- Thexcoordinate of the object.y- Theycoordinate of the object.xExtent- The extension of the neighborhood in thexdirection.yExtent- The extension of the neighborhood in theydirection.- 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- Thexorigin coordinate.y- Theyorigin 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_NEUMANNorDoubleDiffuseSpace.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_NEUMANNorDoubleDiffuseSpace.NEIGHBOURHOOD_TYPE.MOORE.- Returns:
- the Objects determined to be the maximum.
-
getMatrix
public double @NonNull [] getMatrix()Description copied from class:DoubleSpaceReturn the matrix of values representing the grid.- Overrides:
getMatrixin classDoubleSpace- Returns:
- A matrix of double with the same dimensions of the grid.
-
onEvent
- Specified by:
onEventin interfaceEventListener
-