-
Notifications
You must be signed in to change notification settings - Fork 10
Description
I love your particle life GUI. In particular, the 1/r and 1/r^2 attractors are an incredibly intuitive way to simulate material properties like emergent crystal formation, etc.
However, certain regions of parameter space cause the simulation to become metastable or unstable for these attractors. I haven't taken the time to find the exact limits, but it seems to be a combination of:
- large number of particles
- high force multiplier
- low friction
- large timestep
As far as I can tell, this occurs because the inter-particle potential goes to infinity as the distance goes to zero, and because the force is assumed to be constant between timesteps (I assume--I'm not familiar enough with Java to know for sure, but Euler methods are usually associated with this kind of instability). For small distances, this will always underestimate the force between two approaching particles and overestimate the force between two diverging particles. In such a case, each interaction actually adds energy to the system.
This can still be stable as long as that extra energy is dissipated before the next interaction, which depends on both the particle density (mean free path) and the friction. Otherwise, it leads to a chain reaction (which is actually another interesting physics simulation).
The simplest fix to this would probably be to limit the interatomic potential function so that it doesn't actually go to infinity. However, while this would probably expand the stable region, it doesn't actually solve the problem entirely.
Alternatively, you could adjust the way the positions are calculated to use a Runge-Kutta method. This would be significantly more stable and would let you keep the inter-particle potentials true to their names. It would be more expensive per-step, but it would also be able to take larger (i.e. fewer) steps. In my experience, RK methods typically come out ahead on that tradeoff. It would also be more work for you, so there's that to consider :P
Once again, I love the project. Keep up the good work!