← back

Show HN: 2D Coulomb Gas Simulator

swesnow | 2026-02-16 19:17 UTC | source

Each dot represents an electron experiencing pairwise Coulomb repulsion with every other electron while being confined by an external potential $Q$. The energy of a configuration $z_1, \dots, z_n$ is given by the 2D log-gas Hamiltonian $$H(z_1,\ldots,z_n) = -\sum_{i \neq j} \log\lvert z_i - z_j \rvert + n\sum_{j=1}^n Q(z_j).$$ The 2D Coulomb gas is interesting because this type of Hamiltonian shows up in many different places across mathematics / mathematical physics:

  • Eigenvalues of a random matrix with Gaussian random entries
  • Zeroes of a polynomial with Gaussian random coefficient
  • Fractional quantum hall effect
  • Hele-Shaw/Laplacian growth
  • Vortices in superconductors

Consequently, there is a large body of research devoted to deducing properties of this family of systems. For example, in 2017 in was

shown

that the density of particles near the boundary follows an

erfc

distribution by means of a remarkably long proof. Of course, with this simulator we minimize the Hamiltonion, not sample from it in a temperature dependent way. We therefore approximate the minimum-energy state which is known as a

Fekete configuration

.

For more on the background and context of these systems, I implore you to look into my

bachelor thesis

or this

blog post

.

39 points | 9 comments | original link
A pretty simple but fun to play with simulator for a concept from mathematical physics called the "2D Coulomb gas". I originally made this for my Bachelor's thesis to create pretty pictures and build intuition but have recently gotten it a fresh coat of paint and better performance curtesy of WebGPU acceleration (ported with liberal help from Codex to get through all of the boilerplate).

Play around with it - hopefully read up more on the 2D Coulomb gas because it is an incredibly deep topic research wise.

Comments

bizzyskillet | 2026-02-16 20:25 UTC
Awesome! Beautiful work. Mesmerizing, even
swesnow | 2026-02-17 09:20 UTC
Thanks I agree it is mesmerizing!
zeitgeistcowboy | 2026-02-16 20:56 UTC
Warning: if you increase the steps per frame it will break your phone. At least with my iPhone and Safari it stalls the entire phone.
xattt | 2026-02-16 21:07 UTC
Yes, the web page persists through reboots.

You have to painfully force quit Safari by going through the motions of the gestures, wait for the phone to respond, and then quit Safari from the card task switcher.

klysm | 2026-02-16 21:45 UTC
Quick submit a level 10 CVE DOS vuln!
swesnow | 2026-02-17 09:20 UTC
True, you'd think Safari wouldn't let websites go so crazy with WebGPU :)
gus_massa | 2026-02-16 23:19 UTC
Note 1: I had to go to the middle and reduce the number of particles to 1000 to be able to run it in my phone.

Note 2: In this case, 2D means that the force is proportional to distance^-1 instead of the usual distance^-2. It's not a 3D word projected into a plane, it's a real 2D word that lives inside a plane. It would be nice to have an option to switch and compare. I have no intuition about the difference.

Note 3: Somewhere in the middle, it's possible to switch the external potencial from z^2 to z^4 to z^20, where z is the distance from the center.

z^2 "Ginibre" is a nice round surface, like a wok. Electrons get evenly distributed.

z^20 "Mittag-Leffler lambda=10" is flat in the center and then goes up quickly, like a saucepan. Electrons escape from each other, a few of them remain in the center but most get squashed against the circular wall.

z^4 "Mittag-Leffler lambda=2" Something in between

swesnow | 2026-02-17 09:19 UTC
1: Sorry about that, the default 20,000 is to make it look nice on computers but I should probably drop it a bit for phones, that's reasonable. 2: Yeah this part is important and cool and not entirely obvious until you solve the differential equation. I did a 3D simulation of a somewhat related situation (Thompson problem) once. But it would be very interesting to figure out if there is a 3D potential function that gives uniform density in the same way as the Ginibri (Q(z) = |z|^2) potential. Good idea for future work :) 3: Make sure you try the lemniscate potentials as well which are not rotationally symmetric. I want to try adding even more potentials in the future but these two families are those which has been subject to the most research.

Thanks for playing around with the tool!

gus_massa | 2026-02-17 11:59 UTC
I got better results with N=100, and the time and frames bars at the top in the middle. It reach the equilibrium in ~5 seconds, so it's easy to test and compare the different potentials. #ResearchInTheTikTokEra :)

With z^20, the problem is that when you change the number of particles, the ones are distributed randomly and the ones near the corners have a huge gradient and probably overflow and the inifinites/nans are viral and kill all the other particles. The trick is to switch to z^2, change N wait a moment and then change to z^20. Perhaps you can clip some values or try some trick like in stiff equations.

In 3D, I expected a z^2 potencial with a 1/z^2 force to generate an uniform distribution, for something something Gauss. (It's just bad hand-waving, I didn't have anything close to a proof.) It's interesting that it is so easy.