Boltzmann Distribution & H-Theorem Simulation

Simulation Controls

Explanation & Mathematical Details

This simulation models an ideal gas of \(N\) particles confined in a 2D box. The particles are initialized with velocities sampled from a Maxwell–Boltzmann distribution corresponding to a user-defined temperature \(T\). With \(k_B=1\) and unit mass, the kinetic energy per particle is given by: \[ \langle E_{\text{kin}} \rangle = \frac{1}{2}\langle v_x^2 + v_y^2 \rangle = T. \]

Maxwell–Boltzmann Distribution: In equilibrium, the probability of finding a particle with speed \(v\) is given by: \[ P(v) \propto v \, e^{-v^2/(2T)}, \] which results from the independent Gaussian distributions of \(v_x\) and \(v_y\).

Boltzmann Entropy and the H–Theorem: The entropy is calculated from the speed histogram as: \[ S = -\sum_{i} p_i \ln(p_i), \] where \(p_i\) is the probability in the \(i\)th speed bin. In kinetic theory, the H–function, \[ H = \int f \ln f \, dv, \] (with \(S = -H\)) is non–increasing over time, illustrating that the system evolves irreversibly toward equilibrium.

Dynamic Temperature Control: A velocity–rescaling thermostat is implemented so that if you change the temperature slider, the particles’ velocities are adjusted in real time. Specifically, after each update the current temperature, \[ T_{\text{current}} = \frac{1}{2N} \sum_{i=1}^{N}(v_{x,i}^2 + v_{y,i}^2), \] is computed and all velocities are rescaled by a factor \[ \text{factor} = \sqrt{\frac{T_{\text{desired}}}{T_{\text{current}}}}, \] ensuring the average kinetic energy matches the user–specified \(T_{\text{desired}}\).

Use the controls above to adjust the parameters live and observe how the speed distribution (blue histogram) and entropy (green line) evolve over time.