[HN Gopher] A simplified Python simulation of diffusion
       ___________________________________________________________________
        
       A simplified Python simulation of diffusion
        
       Author : rbanffy
       Score  : 57 points
       Date   : 2024-06-30 18:24 UTC (4 hours ago)
        
 (HTM) web link (www.thepythoncodingstack.com)
 (TXT) w3m dump (www.thepythoncodingstack.com)
        
       | forgotpwd16 wrote:
       | An excellently presented article. Impressed by the usage of
       | `turtle` module. Didn't knew it was that capable.
        
       | SushiHippie wrote:
       | This somehow reminds me of the Coding Challenges from The Coding
       | Train:
       | 
       | 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).
        
       | semi-extrinsic wrote:
       | I'm sorry, but this is not good code for teaching anyone about
       | anything to do with physics. It manages to be both verbose, non-
       | idiomatic, slow and wrong. Feynman would not touch this with a
       | ten foot pole.
       | 
       | 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.
        
       ___________________________________________________________________
       (page generated 2024-06-30 23:00 UTC)