PhysSim

Systems ProgrammingJavaScript (ES Modules)three.jsViteWebGLRigid-Body PhysicsKinetic TheoryMatrix Exponential IntegrationFluid SimulationJacobi & Conjugate GradientTest Suites
physsim-seven.vercel.app
PhysSim interface

I built PhysSim around a rule I wanted to be able to defend: every number on screen should be measured by the simulation and shown next to the closed form it is supposed to agree with. That rule shaped the whole project. Pressure in the gas bench is not printed from n k T; it is counted from the momentum molecules hand to the walls, and if the two disagree, the simulation is wrong. The energy ledgers are shown live for the same reason: they make a mistake much harder to hide.

Each bench takes a different approach. Dynamics uses typed-array rigid bodies with impulse-based collisions and a uniform spatial hash, where every shape is both a signed distance field for the physics and a mesh for the eye, and mass comes from density times volume rather than a guessed constant. Thermo is a rarefied gas in real units, with walls that reflect, insulate, or hold a temperature through a flux-weighted Maxwellian, plus a pinhole that opens a real hole so effusion can be watched. Vibrations assembles the equations of motion into matrices once and advances them with a matrix exponential, so the trajectory on screen is the analytic response sampled, and the timestep changes how finely it is reported rather than how wrong it is.

I also wanted the project to be honest about what it does not model: fixed-step collision resolution, spherical molecules, a gas that is deliberately rarefied so its motion is watchable, and a picosecond slice of real time. Those compromises are printed in the panels instead of being left for someone to discover. Beneath the benches sits a stable-fluids solver with two interchangeable pressure solvers, Jacobi and Conjugate Gradient, and a benchmark that times both on the same problem.

The architecture follows from wanting to test the real thing. The simulation, geometry, solver, and profiling modules import nothing from the browser, so they run identically in Node and in the browser, and the three check suites exercise those modules rather than a reimplementation. There is no framework: Vite for the build, three.js for rendering, and plain ES modules everywhere else. Building PhysSim pushed me to think much more carefully about numerical accuracy, verification, and the difference between a result that looks plausible and one that actually holds up.