|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectuchicago.src.sim.space.Diffuse2D
public class Diffuse2D
Discrete 2nd order approximation of 2d diffusion with evaporation. Essentialy a java implementation of Diffuse2d in the Swarm simulation toolkit. Toroidal in shape and works with number values. This space simulates concurency through the use of a read and write matrix. Any writes to the space, write to the write matrix, and any reads to the read matrix. The diffuse() method then diffuses the write matrix and copies the new values into the read matrix.
For an example of a Diffuse2d space see the heatBugs example. See
diffuse for a brief explanation of the diffusion
algorithm.
| Field Summary | |
|---|---|
protected double |
diffCon
|
protected double |
evapRate
|
static long |
MAX
|
static long |
MIN
|
protected int |
nextX
|
protected int |
nextY
|
protected int |
prevX
|
protected int |
prevY
|
protected DoubleMatrix |
readMatrix
|
protected DoubleMatrix |
writeMatrix
|
protected int |
x
|
protected int |
xSize
|
protected int |
y
|
protected int |
ySize
|
| Fields inherited from interface uchicago.src.sim.space.Discrete2DSpace |
|---|
MOORE, VON_NEUMANN |
| Constructor Summary | |
|---|---|
Diffuse2D(double diffusionConstant,
double evaporationRate,
int xSize,
int ySize)
Constructs a Diffuse2d space with the specified diffusion constant, evaporation rate, and dimensions |
|
Diffuse2D(int xSize,
int ySize)
Constructs a Diffuse2d space with the specificed dimensions |
|
| Method Summary | |
|---|---|
protected double[] |
compareMax(double[] array)
|
protected double[] |
compareMin(double[] array)
|
void |
diffuse()
Runs the diffusion with the current rates and values. |
double[] |
findMaximum(int x,
int y,
int range,
boolean includeOrigin,
int neighborhoodType)
Finds the maximum grid cell value within a specified range from the specified origin coordinate. |
double[] |
findMinimum(int x,
int y,
int range,
boolean includeOrigin,
int neighborhoodType)
Finds the minimum grid cell value within a specified range from the specified origin coordinate. |
BaseMatrix |
getMatrix()
Gets the matrix collection class that contains all the values. |
double[] |
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." |
double[] |
getMooreNeighbors(int x,
int y,
int xExtent,
int yExtent)
Gets the extended Moore neighbors of the specified coordinate. |
java.lang.Object |
getObjectAt(int x,
int y)
Gets the object (a Long) at the specified coordinate. |
java.awt.Dimension |
getSize()
Gets the dimension of the space |
int |
getSizeX()
Gets the size of the x dimension |
int |
getSizeY()
Gets the size of the y dimension |
double |
getValueAt(int x,
int y)
Gets the value at the specified coordinate. |
double[] |
getVonNeumannNeighbors(int x,
int y)
Gets the von Neumann neighbors of the specified coordinate. |
double[] |
getVonNeumannNeighbors(int x,
int y,
int xExtent,
int yExtent)
Gets the extended von Neumann neighbors of the specified coordinate. |
void |
putObjectAt(int x,
int y,
java.lang.Object object)
Puts the specified Object at the specified coordinate. |
void |
putValueAt(int x,
int y,
double value)
Puts the specified value at the specified coordinate. |
void |
setDiffusionConstant(double diffusionConstant)
Sets the diffusion constant for this Diffuse2d space |
void |
setEvaporationRate(double rate)
Sets the evaporation rate for this Diffuse2d space |
void |
update()
Copies the writeLattice to the readLattice |
protected int |
xnorm(int x)
Normalize the x value to the toroidal coordinates |
protected int |
ynorm(int y)
Normalize the y value to the toroidal coordinates |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
public static final long MAX
public static final long MIN
protected double diffCon
protected double evapRate
protected DoubleMatrix readMatrix
protected DoubleMatrix writeMatrix
protected int xSize
protected int ySize
protected int x
protected int prevX
protected int nextX
protected int y
protected int prevY
protected int nextY
| Constructor Detail |
|---|
public Diffuse2D(int xSize,
int ySize)
xSize - size of the x dimensionySize - size of the y dimension
public Diffuse2D(double diffusionConstant,
double evaporationRate,
int xSize,
int ySize)
diffusionConstant - the diffusion constantevaporationRate - the evaporation ratexSize - size of the x dimensionySize - size of the y dimension| Method Detail |
|---|
public void setDiffusionConstant(double diffusionConstant)
public void setEvaporationRate(double rate)
public void diffuse()
Values from the readMatrix are used to calculate diffusion. This value is then written to the writeMatrix. When this has been done for every cell in the grid, the writeMatrix is copied to the readMatrix.
public void update()
public double[] getVonNeumannNeighbors(int x,
int y)
x - the x coordinate of the objecty - the y coordinate of the object
public double[] getVonNeumannNeighbors(int x,
int y,
int xExtent,
int yExtent)
x - the x coordinate of the objecty - the y coordinate of the objectxExtent - the extension of the neighborhood in the x directionyExtent - the extension of the neighborhood in the y direction
public double[] getMooreNeighbors(int x,
int y)
x - the x coordinate of the objecty - the y coordinate of the object
public double[] getMooreNeighbors(int x,
int y,
int xExtent,
int yExtent)
x - the x coordinate of the objecty - the y coordinate of the objectxExtent - the extension of the neighborhood in the x directionyExtent - the extension of the neighborhood in the y direction
public double[] findMaximum(int x,
int y,
int range,
boolean includeOrigin,
int neighborhoodType)
x - the x origin coordinatey - the y origin coordinaterange - the range out from the coordinate to searchincludeOrigin - include object at origin in searchneighborhoodType - the type of neighborhood to search. Can be one
of Discrete2DSpace.VON_NEUMANN or Discrete2DSpace.MOORE.
protected double[] compareMax(double[] array)
public double[] findMinimum(int x,
int y,
int range,
boolean includeOrigin,
int neighborhoodType)
x - the x origin coordinatey - the y origin coordinaterange - the range out from the coordinate to searchincludeOrigin - include object at origin in searchneighborhoodType - the type of neighborhood to search. Can be one
of Discrete2DSpace.VON_NEUMANN or Discrete2DSpace.MOORE.
protected double[] compareMin(double[] array)
public int getSizeX()
getSizeX in interface Discrete2DSpacepublic int getSizeY()
getSizeY in interface Discrete2DSpacepublic java.awt.Dimension getSize()
getSize in interface Discrete2DSpace
public java.lang.Object getObjectAt(int x,
int y)
getObjectAt in interface Discrete2DSpacex - the x coordinatey - the y coordinate
public double getValueAt(int x,
int y)
getValueAt in interface Discrete2DSpacex - the x coordinatey - the y coordinate
public void putObjectAt(int x,
int y,
java.lang.Object object)
putObjectAt in interface Discrete2DSpacex - the x coordinatey - the y coordinateobject - the object to put
java.lang.IllegalArgumentException - if object is not an
instance of Number
public void putValueAt(int x,
int y,
double value)
putValueAt in interface Discrete2DSpacex - the x coordinatey - the y coordinatevalue - the value to putpublic BaseMatrix getMatrix()
getMatrix in interface Discrete2DSpaceprotected int xnorm(int x)
x - the value to normalize
protected int ynorm(int y)
y - the value to normalize
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||