Class FluidSolver2D

java.lang.Object
toxi.sim.fluids.FluidSolver2D

public class FluidSolver2D extends Object
Optimized Jos Stam style fluid solver with vorticity confinement and buoyancy force.
Author:
Alexander McKenzie, Karsten Schmidt

optimized by toxi 2006-02-09

  • reduced nesting level of loops
  • removed need for I() util method by unrolling all index calculations
  • renamed variables for better legibility

  • Constructor Details

    • FluidSolver2D

      public FluidSolver2D(int w, int h, float timeStep)
      Creates a new instance of the given dimension uses the specified time step.
      Parameters:
      w - matrix width
      h - matrix height
      timeStep -
  • Method Details

    • decay

      public final void decay(float decay)
    • densitySolver

      public void densitySolver()
      The basic density solving routine.
    • getBuoyancyA

      public float getBuoyancyA()
      Returns:
      the buoyancyA
    • getBuoyancyB

      public float getBuoyancyB()
      Returns:
      the buoyancyB
    • getCurl

      public float[] getCurl()
      Returns:
      the curl
    • getDensityField

      public float[] getDensityField()
      Returns:
      the d
    • getDiffusion

      public float getDiffusion()
      Returns:
      the diffusion
    • getNumIterations

      public int getNumIterations()
      Returns:
      the numIterations
    • getTimeStep

      public float getTimeStep()
      Returns:
      the timeStep
    • getTotalHeight

      public int getTotalHeight()
      Returns:
      the totalHeight
    • getTotalWidth

      public int getTotalWidth()
      Returns:
      the totalWidth
    • getVelocityFieldU

      public float[] getVelocityFieldU()
      Returns:
      the u
    • getVelocityFieldV

      public float[] getVelocityFieldV()
      Returns:
      the v
    • getViscosity

      public float getViscosity()
      Returns:
      the viscosity
    • reset

      public void reset()
      Reset the datastructures. We use 1d arrays for speed.
    • setBuoyancyA

      public void setBuoyancyA(float buoyancyA)
      Parameters:
      buoyancyA - the buoyancyA to set
    • setBuoyancyB

      public void setBuoyancyB(float buoyancyB)
      Parameters:
      buoyancyB - the buoyancyB to set
    • setCurl

      public void setCurl(float[] curl)
      Parameters:
      curl - the curl to set
    • setDiffusion

      public void setDiffusion(float diffusion)
      Parameters:
      diffusion - the diffusion to set
    • setNumIterations

      public void setNumIterations(int numIterations)
      Parameters:
      numIterations - the numIterations to set
    • setTimeStep

      public void setTimeStep(float timeStep)
      Parameters:
      timeStep - the timeStep to set
    • setViscosity

      public void setViscosity(float viscosity)
      Parameters:
      viscosity - the viscosity to set
    • velocitySolver

      public void velocitySolver()
      The basic velocity solving routine as described by Stam.
    • vorticityConfinement

      public void vorticityConfinement(float[] Fvc_x, float[] Fvc_y)
      Calculate the vorticity confinement force for each cell in the fluid grid. At a point (i,j), Fvc = N x width where width is the curl at (i,j) and N = del |width| / |del |width||. N is the vector pointing to the vortex center, hence we add force perpendicular to N.
      Parameters:
      Fvc_x - The array to store the x component of the vorticity confinement force for each cell.
      Fvc_y - The array to store the y component of the vorticity confinement force for each cell.