r/Physics • Fluid dynamics and acoustics • 4h ago

I built an open-source Python physics sandbox where every solver is tested against an analytic result. What should I add next?

I've been building a free, MIT-licensed Python package called qplay for exploring physics by simulation. Each solver is tested against a known analytic result, so the pictures can be trusted.

Try it:

pip install quantum-playground

qplay run double-slit

I'd like feedback from people who actually do this. Which topics are missing, and where is the physics or numerics sloppy? I'd especially like to hear about anything I've got wrong.
docs : https://github.com/StativeSh/quantum-playground
try it live: https://stativesh.github.io/quantum-playground/

0 Upvotes

5 comments sorted by

10

u/No_Vermicelli_2170 3h ago • Bravo

Very cool simulation!

I don't know if the numerical results agree with the analytical results, since it's a nonlinear system with 8 degrees of freedom: two dimensions, two pendulums, and position & velocity. Chaos manifests, and you will have sensitive dependence on initial conditions, so all initial trajectories will eventually deviate from theoretical results, no matter how small your time step is.

0

u/ShreyasGameSwap Fluid dynamics and acoustics 2h ago

Fair point, and you're right that a chaotic system can't be validated by comparing trajectories: any error, however small, grows exponentially, so two runs diverge no matter what the step size is.

For the double pendulum I don't check against an analytic trajectory (there isn't one). I check invariants instead: total energy has to stay conserved over the run, and the Hamiltonian formulation (Legendre transform -> Hamilton's equations) has to reproduce the same dynamics as the Euler-Lagrange derivation. The chaos part is validated statistically, by checking that nearby initial conditions separate at the expected Lyapunov rate rather than by matching a path.

The "tested against analytic results" claim is really for the other solvers (Ising vs Onsager, hydrogen levels, tunnelling, etc.). The pendulum is the one place where the honest test is conservation laws, not a closed form. Thanks for raising it. I should be clearer about that distinction in the README.

1

u/No_Vermicelli_2170 1h ago

This sounds interesting and may work, but I haven't tried it myself. I am not certain that enforcing energy conservation at each time step will yield correct trajectories, as I would need to prove this analytically for this particular nonlinear ODE system. Perhaps there is a Hamiltonian value on this four-dimensional phase space for which two points have the same Hamiltonian value. Preserving the Hamiltonian in this case will still not guarantee path deviation. If you could reduce the phase space to just two coordinates via some symmetry, you could use the Poincaré- Bendixson theorem to prove that chaos will not occur. Noether's theorem states that every conservation law corresponds to a symmetry. Energy conservation corresponds to a symmetry that allows you to reduce the number of variables from four to three — but three variables still imply chaos.

1

u/ShreyasGameSwap Fluid dynamics and acoustics 1h ago

the code itself doesnt enforce the energy conservation.
it integrates the equations of motion with the adaptive solver this way the energy is checked later I hope this clarifies your concern
I aded a stronger test after you said that energy conservation alone wont prove trajectories are correct
this uses a small angle limit it has an exact soln two normal modes with known frequencies, $(g/l)(2 \pm \sqrt{2})$ for equal masses and lengths. The simulation matches that solution.

you are right on Poincaré–Bendixson point the energy surface is 3D, and three dimensions are enough for chaos.

2

u/ShreyasGameSwap Fluid dynamics and acoustics 3h ago

Some of what's checked against exact results, so you can judge the claim yourself:

- 2D Ising (Metropolis) vs Onsager's exact magnetisation and Tc = 2/ln(1+sqrt(2))

- Split-step Schrödinger solver: tunnelling and a double slit, fringes compared with the two-source prediction

- Hydrogen fine structure vs the Dirac energy; Zeeman from weak field up to Paschen-Back

- Hard-sphere gas: Maxwell-Boltzmann emerges from collisions, pV = N k_B T with the hard-sphere correction

One specific thing I'd like opinions on: the split-step solvers use a periodic box with an absorbing layer at the edges. Is there a cleaner approach people prefer for scattering problems, such as exterior complex scaling or a PML?