A simplified Python simulation of diffusion
Physicist Richard Feynman's teaching style is explored through Python simulations on diffusion. The tutorial simplifies physics concepts, emphasizing coding and optimization with Python modules like turtle, NumPy, and Matplotlib.
Read original articleThe article discusses the potential teaching approach of physicist Richard Feynman using Python simulations, focusing on diffusion. The author, a physicist, highlights the value of Feynman's teaching style in deepening understanding. The Python tutorial simplifies physics concepts, emphasizing coding and optimization. The simulation involves particles moving randomly in a closed container, colliding with each other and the container's sides. The tutorial uses the turtle module to create animations and plans to explore NumPy and Matplotlib in Part 2. It explains creating a 2D simulation area, defining particle attributes, setting positions and velocities, and animating particle movements. The tutorial also addresses handling collisions with container edges and between particles. The code snippets provided demonstrate creating the simulation area, particles, and animating their movements. The tutorial aims to make Python coding accessible and engaging, even for those not well-versed in physics.
Related
https://youtube.com/playlist?list=PLRqwX-V7Uu6ZiZxtDDRCi6uhf...
Though he uses https://p5js.org/ for most if not all of his challenges (at least the last time I watched his videos).
First ditch all the object orientation and encapsulation and stuff. Your data is a 2xN Numpy array. Your visualization is a scatter plot in Matplotlib. Voila, 80% of the code is gone.
For the position updates, you either use a repulsive potential to approximate the hard spheres and do molecular dynamics, showing how to integrate Newton's second law and the Verlet scheme and ergodicity and the whole shebang. Or you do Monte Carlo for the positional updates and keep the exact hard spheres. You discuss statistical mechanics concepts like ensembles and thermostats and stuff.
Then you produce results like the pair correlation function and compare it with the Carnahan-Starling equation, dig into the really cool stuff. Compute velocity autocorrelation functions, test what happens when you change density and temperature, talk about phase diagrams, etc.
This is actually an amazingly deep subject, yet very accessible and intuitive, that sits on the border between physics and chemistry. Sad to see it treated like this. Would suggest that people have a look at the book by Allen and Tildesley which is much much better. They have both Python and Fortran example code on Github.
edit: there's one called "#43 Diffusion (5/1/62)" here: https://www.feynmanlectures.caltech.edu/flptapes.html#restor... so I assume that