Class KineticsModel
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
ConstructorsConstructorDescriptionKineticsModel(int count, float length, float volumeFraction, float initialTemp) Initializes the simulation. -
Method Summary
Modifier and TypeMethodDescriptionfloatComputes the Shannon entropy of the system based on a coarse 3D occupancy histogram.Get an optimized snapshot of the most recently completed simulation state.voidreset(int count, float length, float volumeFraction, float initialTemp) Reinitialize the simulation with a new particle count and starting conditions, discarding any in-progress state.voidsetEntropyEvery(int every) Optional rate-limit for entropy computation.voidsetTemperature(float newTemp) Adjust the temperature (scales particle velocities).voidsetTimeStep(float dt) Set the simulation time step.intsize()Returns the number of particles.voidupdate()Advance the simulation by one step.
-
Constructor Details
-
KineticsModel
public KineticsModel(int count, float length, float volumeFraction, float initialTemp) Initializes the simulation.- Parameters:
count- number of particleslength- side length of the bounding cubevolumeFraction- 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
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 toinitialTemp.Unlike the constructor,
countandlengthhere need not match the values originally passed to the constructor: the coordinate buffers are reallocated to the newcount, and the newlengthbecomes the elastic-wall bounding box used byupdate()and the occupancy histogram used bycomputeEntropy(), exactly as if a newKineticsModelhad been constructed.Must not be called concurrently with
update()from another thread; neither method synchronizes against the other.- Parameters:
count- number of particles to createlength- new side length of the bounding cube, used both for the initial confined sub-region and as the elastic-wall box for subsequent updatesvolumeFraction- fraction oflengthdefining the initial confined sub-region, in(0, 1]initialTemp- initial temperature, used to set the standard deviation of the initial velocity distribution
-