public void refresh(final List<FluidParticle> particles) {
theGrid = new ArrayList[this.theWidth][this.theHeight];
theNeighboursIndex.clear();
final int numOfParticles = particles.size();
for (int i = 0; i < numOfParticles; ++i) {
final FluidParticle thisParticle = particles.get(i);
thisParticle.gridIndexX = GetGridIndexX(thisParticle);
thisParticle.gridIndexY = GetGridIndexY(thisParticle);
// Add particle to list
if (theGrid[thisParticle.gridIndexX][thisParticle.gridIndexY] == null) {
theGrid[thisParticle.gridIndexX][thisParticle.gridIndexY] = new ArrayList<Integer>();
}
theGrid[thisParticle.gridIndexX][thisParticle.gridIndexY].add(i);
}
// Build up the cache of neighbours for each fluid particle.
for (int i = 0; i < numOfParticles; ++i) {
final FluidParticle thisParticle = particles.get(i);
theNeighboursIndex.put(thisParticle, getNeighbourIndexForCache(thisParticle));
}
}