A simple two-dimensional Brownian motion animation

(7 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.8

Comments

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

Anandaram Mandyam 5 years, 5 months 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
Current rating: 1

christian 5 years, 5 months 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
Current rating: 1

Anandaram Mandyam 5 years, 5 months 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
Current rating: 5

Chenghung 3 years, 8 months ago

Hi

I want to thank you for your contribution and this does help my course final project. I Will definitely cite this course and recommend it to my classmates.

Link | Reply
Currently unrated

Chenghung 3 years, 8 months ago

I notice in the end the particles will overlap.

Link | Reply
Currently unrated

Sam 3 years, 3 months ago

Thanks for providing this. I have two concerns that I could use help with. First, as another commenter pointed out, the particles will overlap and "bind" after some time. Second, s there a way to speed up the frame rate of the animation while still keeping the precision of a lower dt?

Link | Reply
Currently unrated

christian 3 years, 2 months ago

I think the easiest way to avoid the particles binding would be to decrease the time-step. If the animation is then too slow, it might be necessary to pre-compute the frames or implement some kind of quadtree structure to reduce the number of collision checks per step.

Link | Reply
Currently unrated

New Comment

required

required (not published)

optional

required