# How to model Solar System formation accurately and realistically, Part 2

I've been working on a crude N-body simulator which allows N bodies of equal masse​s to interact gravitationally in 2 dimensions. My goal is to model the formation of Solar System.

Each body is modeled as a circle with a radius as a function of its mass, in such a way that all bodies have the same density.

When two bodies collide, i.e their radii overlap, they stick together inelastically (but momentum is conserved).

I have initialized the simulation with N=300 particles, and initial positions and velocties randomized (all positions bounded to a certain rectangular window, all velocties of the same modulus).

As the simulation progresses, particles move about, collide and form larger particles, and after some time the system appears to reach a stable state in which the number of particles is very few, usually between 2-5 (the most common case is a planet-sun system)

I've taken care of the efficiency of the code (by implementing Barnes-Hut). However I am now concerning myself with the accuracy/realism, especially with respect to two issues:

I.

Please see this question: How to model Solar System formation accurately and realistically, Part 1

(I've broken up this post into two separate SE questions because it was too long.)

II.

I've read online about "gravitational softening" whereby Newton's law $F=\frac{Gm_1m_2}{r^2}$ is replaced by $F=\frac{Gm_1m_2}{r^2+\epsilon^2}$ for some constant $\epsilon$ which is small compared to the distances involved in the simulation.

As I understand it, the purpose is to bound errors in the simulation due to close encounters between bodies: if $r$ is small, the accelerations are large, but since the time resolution is finite, the error grows.

I've tested the effect of softening for $N=3$ particles intialized at the vertices of an equilateral triangle with equal speeds (Lagrange's peridic solution to the N-body problem). The configuration is supposed to be symmetric, with the particles moving on ellipses which form $120$ degree angles with eachother and share a common focus. But since all three particles come very close together at their perigees, errors grow and eventually the symmetry collapses and the planets go haywire.

Introducing softening didn't seem to make much of a difference. It seems to prevent large-angle scattering, but it leads to errors which grow overtime and destroy the symmetry of the Lagrange configuration anyways.

Now I'm not sure relevant this test is for my solar system sim because it is almost impossible to have close encounter of three particles simultaneously.

My question is thus:

-What is the advantage of gravitational softening? Doesn't it create errors which grow overtime? Should I be using it in my simulation?

1. If your particles do not collide/aggregate then they could pass arbitrarily closely to each other and thus the forces could become arbitrarily large (due to the $r^{-2}$) which can then break the integrator.
In both cases this problem can be overcome by simply using a smaller integration time-step. In fact, a common optimisation is to dynamically update the time-step based on the magnitude of the largest force/velocity present in the system. For example, one might choose a time-step that ensures that no particle moves more than some distance $\delta$ during a single time-step. And if you advance to very large particle systems and parallel processing, you might use a method like RESPA integration to apply different integration time-steps at different scales or in separate domains.