Kamaelia docs : Kamaelia.Support.Particles.ParticleSystem

Discrete time particle physics simulation

A discrete time simulator of a system of bonded and unbonded particles, of multiple types.

The actual physics calculations are deferred to the particles themselves. You can have as many, or few, spatial dimensions as you like.

Example Usage

Create 3 particles, two of which are bonded and move noticeably closer after 5 cycles of simulation:

>>> laws = SimpleLaws(bondLength=5)
>>> sim = ParticleSystem(laws)
>>> sim.add( Particle(position=(10,10)) )
>>> sim.add( Particle(position=(10,20)) )
>>> sim.add( Particle(position=(30,40)) )
>>> sim.particles[0].makeBond(sim.particles, 1)   # bond 1st and 2nd particles
>>> for p in sim.particles: print p.getLoc()
(10, 10)
(10, 20)
(30, 40)
>>> sim.run(cycles=5)
>>> for p in sim.particles: print p.getLoc()
[10.0, 13.940067328]
[10.0, 16.059932671999999]
[30, 40]

How does it work?

Set up ParticleSystem by instantiating, specifying the laws to act between particles and an (optional) set of initial particles.

Particles should be derived from the Particle base class (or have equivalent functionality).

Particles can be added or removed from the system by reference, or removed by their ID.

ParticleSystem will work for particles in space with any number of dimensions - so long as all particles use the same!

Bonds between particles are up to the particles to manage for themselves.

The simulation runs in cycles when the run(...) method is called. Each cycle advances the 'tick' count by 1. The tick count starts at zero, unless otherwise specified during initialization.

The following attributes store the particles registered in ParticleSystem: - particles -- simple list - particleDict -- dictionary, indexed by particle.ID

ParticleSystem uses a SpatialIndexer object to speed up calculations. SpatialIndexer reduce the search space when determining what particles lie within a given region (radius of a point).

If your code changes the position of a particle, the simulator must be informed, so it can update its spatial indexing data, by calling updateLoc(...)

The actual interactions between particles are calculated by the particles themselves, not by ParticleSystem.

ParticleSystem calls the doInteractions(...) methods of all particles so they can influence each other. It then calls the update(...) methods of all particles so they can all update their positions and velocities ready for the next cycle.

This is a two stage process so that, in a given cycle, all particles see each other at the same positions, irrespective of which particle's doInteractions(...) method is called first. Particles should not apply their velocities to update their position until their update(...) method is called.


Got a problem with the documentation? Something unclear that could be clearer? Want to help improve it? Constructive criticism is very welcome - especially if you can suggest a better rewording!

Please leave you feedback here in reply to the documentation thread in the Kamaelia blog.

-- Automatic documentation generator, 05 Jun 2009 at 03:01:38 UTC/GMT

Kamaelia is an open source project originated from and guided by BBC Research. For more information browse the site or get in contact.

This is an ongoing community based development site. As a result the contents of this page is the opinions of the contributors of the pages involved not the organisations involved. Specificially, this page may contain personal views which are not the views of the BBC. (the site is powered by a wiki engine)

(C) Copyright 2008 Kamaelia Contributors, including the British Broadcasting Corporation, All Rights Reserved.

This web site is powered by the same code created for the bicker manor project. For more details, contact Michael Sparks at BBC Research directly (cf contact)