I'm currently writing a 3D $n$-body simulator (similar to what you see here to simulate the evolution of a system of n particles under the force of gravity.
It works fine for "smaller" scale simulations (small galaxies and other random scenarios), but as I scale up to bigger things ($100$ kly diameter galaxies, cosmic clusters, etc) there is a problem. I'm not accounting for any other force other than the force of gravity, so when trying to simulate large-scale scenarios with many particles, the entire system just "collapses" on itself because I'm not accounting for any repulsive force.
I can sort of fake it by using a trig formula when I calculate gravitational attraction, thereby making gravity more localized and having a finite range, but the problem here is that if the distance between two particles is greater than the specified range, there is no attraction. This results in particles just being shot out of the system never to return.
I am wondering, just as there is a formula to determine the force of attraction under gravity of two bodies of mass, is there a formula to determine the repulsive force (due to dark energy maybe?) between two bodies of mass at some distance r?
If not, how can I "fake it" better so that my simulations don't just collapse, and so that particles aren't lost due to my artificially induced "finite range" of the gravitational field?