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.
Comments
Comments are pre-moderated. Please be patient and your comment will appear soon.
Anandaram Mandyam 1 year, 6 months ago
When I run this script thru Spyder in my PC under anaconda py3.7 I get this error message:
Link | ReplyFile "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
christian 1 year, 6 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 | ReplyAnandaram Mandyam 1 year, 6 months ago
Hi:
Link | ReplyWith 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
New Comment