In my last post I touched on the question of data structures for particle systems. It boils down to the question of whether the basic data structure is an individual particle, or a system of particles.
The code you find scattered about the web from the graphics community prefers for the basic data structure to be a particle. I think I’ll find differently when I look at molecular dynamics codes. I’m compiling a list here of the design approach taken by several codes. They are all either production quality publicly available codes, or archetypal design patterns detailed in published work.
First up, NAMD. There is an atom data structure. However neither position or velocity appear to be contained in it. I have to say the comments are pretty bloody sparse!
Next, GADGET uses structures for particles, such that they are referenced in the form particle.position[dimension]. They copy the data (or pointers, not sure) before doing computations though – the force calculation for particle i goes something like
pos = particle(i).position
vel = particle(i).velocity
force = do_something_with(pos,vel)
Not sure why, there is probably a reason.
For now, the group of particles will be one object, with the arrays of various properties as vectors. This leaves scope to introduce multiple groups (e.g. for two mixing fluids). However some of the C functions I need to wrap take arrays of positions, masses etc as arguments, so some scattering will be required. If it turns out the scattering costs too much, I’ll move to a simple r,v type system.