Class KineticsModel

java.lang.Object
edu.cnu.mdi.mdi3D.view3D.kineticsDemo.KineticsModel

public class KineticsModel extends Object
A physics model simulating particles in a 3D box with elastic collisions.

The model maintains an internal mutable state (positions + velocities) and exposes an optimized, UI-friendly SimulationSnapshot containing only a reference to a packed float[] coordinate buffer.

Double buffering (front/back)

  • The simulation thread writes new positions into the back buffer.
  • After the update, buffers are swapped so the front buffer is always the most recently completed frame.
  • getSnapshot() is side-effect free and simply returns the current front buffer.
  • Constructor Summary

    Constructors
    Constructor
    Description
    KineticsModel(int count, float length, float volumeFraction, float initialTemp)
    Initializes the simulation.
  • Method Summary

    Modifier and Type
    Method
    Description
    float
    Computes the Shannon entropy of the system based on a coarse 3D occupancy histogram.
    Get an optimized snapshot of the most recently completed simulation state.
    void
    reset(int count, float length, float volumeFraction, float initialTemp)
    Reinitialize the simulation with a new particle count and starting conditions, discarding any in-progress state.
    void
    setEntropyEvery(int every)
    Optional rate-limit for entropy computation.
    void
    setTemperature(float newTemp)
    Adjust the temperature (scales particle velocities).
    void
    setTimeStep(float dt)
    Set the simulation time step.
    int
    Returns the number of particles.
    void
    Advance the simulation by one step.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • KineticsModel

      public KineticsModel(int count, float length, float volumeFraction, float initialTemp)
      Initializes the simulation.
      Parameters:
      count - number of particles
      length - side length of the bounding cube
      volumeFraction - fraction of the cube to populate initially (e.g. 0.25)
      initialTemp - initial "temperature" (sets RMS speed; sigma = sqrt(T))
  • Method Details

    • size

      public int size()
      Returns the number of particles.
      Returns:
      particle count
    • setTimeStep

      public void setTimeStep(float dt)
      Set the simulation time step.
      Parameters:
      dt - time step (seconds in simulation units)
    • setEntropyEvery

      public void setEntropyEvery(int every)
      Optional rate-limit for entropy computation.
      Parameters:
      every - compute entropy every N updates (>=1)
    • update

      public void update()
      Advance the simulation by one step.

      This method is intended to run on the simulation thread.

    • getSnapshot

      public SimulationSnapshot<Particle> getSnapshot()
      Get an optimized snapshot of the most recently completed simulation state.

      This method is side-effect free and safe to call from the EDT.

      Returns:
      snapshot containing a reference to the current front buffer
    • computeEntropy

      public float computeEntropy()
      Computes the Shannon entropy of the system based on a coarse 3D occupancy histogram.

      This is O(N) in the number of particles and is intended to run on the simulation thread.

      Returns:
      entropy in nats
    • setTemperature

      public void setTemperature(float newTemp)
      Adjust the temperature (scales particle velocities).
      Parameters:
      newTemp - new temperature (>0)
    • reset

      public void reset(int count, float length, float volumeFraction, float initialTemp)
      Reinitialize the simulation with a new particle count and starting conditions, discarding any in-progress state.

      Particles are placed at random positions within a cubic sub-region of side length * volumeFraction (so the gas starts confined to one corner of the box) and given Maxwell–Boltzmann-distributed velocities corresponding to initialTemp.

      Unlike the constructor, count and length here need not match the values originally passed to the constructor: the coordinate buffers are reallocated to the new count, and the new length becomes the elastic-wall bounding box used by update() and the occupancy histogram used by computeEntropy(), exactly as if a new KineticsModel had been constructed.

      Must not be called concurrently with update() from another thread; neither method synchronizes against the other.

      Parameters:
      count - number of particles to create
      length - new side length of the bounding cube, used both for the initial confined sub-region and as the elastic-wall box for subsequent updates
      volumeFraction - fraction of length defining the initial confined sub-region, in (0, 1]
      initialTemp - initial temperature, used to set the standard deviation of the initial velocity distribution