A simple two-dimensional Brownian motion animation

(3 comments)

This code continues the previous blog post on two-dimensional collisions to model Brownian motion. The code is on my GitHub page.

The core classes, PeriodicParticle and PeriodicSimulation are derived from the original Particle and Simulation classes to allow periodic boundary conditions: instead of bouncing off the walls, the particles move through them and reappear at the other side of the domain.

In the example given here, the mass of the large particle is set to be equal to that of the small ones, so that it gains enough momentum quickly to be seen to move in the animation. This can be altered by setting the mass property of the PeriodicParticle class.

enter image description here

Current rating: 3.7

Comments

Comments are pre-moderated. Please be patient and your comment will appear soon.

Anandaram Mandyam 2 months, 2 weeks ago

When I run this script thru Spyder in my PC under anaconda py3.7 I get this error message:
File "D:/PyScripts_01/ChristianHill_SciPython/Brownian2D.py", line 58, in init_particles
while not self.place_particle(radius, styles):
AttributeError: 'PeriodicSimulation' object has no attribute 'place_particle'
Pl suggest remedy.
Thanks in advance
Anandaram

Link | Reply
Currently unrated

christian 2 months, 2 weeks ago

Sorry! This is my fault completely: I forgot to commit the updated collision.py file to my repo. It should be there now – can you try again and let me know if you have any more problems?

Link | Reply
Currently unrated

Anandaram Mandyam 2 months, 2 weeks ago

Hi:
With the revised collision.py script the 2D brownian file is working fine although the animation appears to freeze after some time. I am trying to tweak some parameters to avoid it from happening.
Thanks anyway.
Cheers

Link | Reply
Currently unrated

New Comment

required

required (not published)

optional

required