Class DoubleDiffuseSpace

All Implemented Interfaces:
EventListener

public class DoubleDiffuseSpace extends DoubleSpace implements EventListener
Discrete 2nd order approximation of 2d diffusion with evaporation.
  • Field Details

  • Constructor Details

    • DoubleDiffuseSpace

      public DoubleDiffuseSpace(int xSize, int ySize)
      Constructs a space with the specified dimensions.
      Parameters:
      xSize - The size of the x dimension.
      ySize - The size of the y 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 the x dimension.
      ySize - The size of the y 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)) where nghAvg 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 - The x coordinate of the object.
      y - The y 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 the x and y direction are specified by xExtent and yExtent. 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 - The x coordinate of the object.
      y - The y coordinate of the object.
      xExtent - The extension of the neighborhood in the x direction.
      yExtent - The extension of the neighborhood in the y 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 - The x coordinate of the object.
      y - The y 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 the x and y direction are specified by xExtent and yExtent. 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 - The x coordinate of the object.
      y - The y coordinate of the object.
      xExtent - The extension of the neighborhood in the x direction.
      yExtent - The extension of the neighborhood in the y 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 - The x origin coordinate.
      y - The y 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 of DoubleDiffuseSpace.NEIGHBOURHOOD_TYPE.VON_NEUMANN or DoubleDiffuseSpace.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 of DoubleDiffuseSpace.NEIGHBOURHOOD_TYPE.VON_NEUMANN or DoubleDiffuseSpace.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 class DoubleSpace
      Returns:
      A matrix of double with the same dimensions of the grid.
    • onEvent

      public void onEvent(@NonNull @NonNull Enum<?> type)
      Specified by:
      onEvent in interface EventListener