<s>
In	O
physics	O
and	O
astronomy	O
,	O
an	O
N-body	B-Algorithm
simulation	I-Algorithm
is	O
a	O
simulation	O
of	O
a	O
dynamical	O
system	O
of	O
particles	O
,	O
usually	O
under	O
the	O
influence	O
of	O
physical	O
forces	O
,	O
such	O
as	O
gravity	O
(	O
see	O
n-body	B-Algorithm
problem	O
for	O
other	O
applications	O
)	O
.	O
</s>
<s>
N-body	B-Algorithm
simulations	I-Algorithm
are	O
widely	O
used	O
tools	O
in	O
astrophysics	O
,	O
from	O
investigating	O
the	O
dynamics	O
of	O
few-body	O
systems	O
like	O
the	O
Earth-Moon-Sun	O
system	O
to	O
understanding	O
the	O
evolution	O
of	O
the	O
large-scale	O
structure	O
of	O
the	O
universe	O
.	O
</s>
<s>
In	O
physical	O
cosmology	O
,	O
N-body	B-Algorithm
simulations	I-Algorithm
are	O
used	O
to	O
study	O
processes	O
of	O
non-linear	O
structure	O
formation	O
such	O
as	O
galaxy	O
filaments	O
and	O
galaxy	O
halos	O
from	O
the	O
influence	O
of	O
dark	B-Application
matter	I-Application
.	O
</s>
<s>
Direct	O
N-body	B-Algorithm
simulations	I-Algorithm
are	O
used	O
to	O
study	O
the	O
dynamical	O
evolution	O
of	O
star	O
clusters	O
.	O
</s>
<s>
For	O
example	O
,	O
an	O
N-body	B-Algorithm
simulation	I-Algorithm
of	O
a	O
star	O
cluster	O
might	O
have	O
a	O
particle	O
per	O
star	O
,	O
so	O
each	O
particle	O
has	O
some	O
physical	O
significance	O
.	O
</s>
<s>
On	O
the	O
other	O
hand	O
,	O
a	O
simulation	O
of	O
a	O
gas	O
cloud	O
cannot	O
afford	O
to	O
have	O
a	O
particle	O
for	O
each	O
atom	O
or	O
molecule	O
of	O
gas	O
as	O
this	O
would	O
require	O
on	O
the	O
order	O
of	O
particles	O
for	O
each	O
mole	O
of	O
material	O
(	O
see	O
Avogadro	O
constant	O
)	O
,	O
so	O
a	O
single	O
'	O
particle	O
 '	O
would	O
represent	O
some	O
much	O
larger	O
quantity	O
of	O
gas	O
(	O
often	O
implemented	O
using	O
Smoothed	B-Application
Particle	I-Application
Hydrodynamics	I-Application
)	O
.	O
</s>
<s>
In	O
direct	O
gravitational	O
N-body	B-Algorithm
simulations	I-Algorithm
,	O
the	O
equations	O
of	O
motion	O
of	O
a	O
system	O
of	O
N	O
particles	O
under	O
the	O
influence	O
of	O
their	O
mutual	O
gravitational	O
forces	O
are	O
integrated	O
numerically	O
without	O
any	O
simplifying	O
approximations	O
.	O
</s>
<s>
The	O
first	O
direct	O
gravitational	O
N-body	B-Algorithm
simulations	I-Algorithm
were	O
carried	O
out	O
by	O
Erik	O
Holmberg	O
at	O
the	O
Lund	O
Observatory	O
in	O
1941	O
,	O
determining	O
the	O
forces	O
between	O
stars	O
in	O
encountering	O
galaxies	O
via	O
the	O
mathematical	O
equivalence	O
between	O
light	O
propagation	O
and	O
gravitational	O
interaction	O
:	O
putting	O
light	O
bulbs	O
at	O
the	O
positions	O
of	O
the	O
stars	O
and	O
measuring	O
the	O
directional	O
light	O
fluxes	O
at	O
the	O
positions	O
of	O
the	O
stars	O
by	O
a	O
photo	O
cell	O
,	O
the	O
equations	O
of	O
motion	O
can	O
be	O
integrated	O
with	O
effort	O
.	O
</s>
<s>
Sverre	O
Aarseth	O
at	O
the	O
University	O
of	O
Cambridge	O
(	O
UK	O
)	O
has	O
dedicated	O
his	O
entire	O
scientific	O
life	O
to	O
the	O
development	O
of	O
a	O
series	O
of	O
highly	O
efficient	O
N-body	B-Algorithm
codes	O
for	O
astrophysical	O
applications	O
which	O
use	O
adaptive	O
(	O
hierarchical	O
)	O
time	O
steps	O
,	O
an	O
Ahmad-Cohen	O
neighbour	O
scheme	O
and	O
regularization	O
of	O
close	O
encounters	O
.	O
</s>
<s>
N-body	B-Algorithm
simulations	I-Algorithm
are	O
simple	O
in	O
principle	O
,	O
because	O
they	O
involve	O
merely	O
integrating	O
the	O
6N	O
ordinary	O
differential	O
equations	O
defining	O
the	O
particle	O
motions	O
in	O
Newtonian	O
gravity	O
.	O
</s>
<s>
Numerical	O
integration	O
is	O
usually	O
performed	O
over	O
small	O
timesteps	O
using	O
a	O
method	O
such	O
as	O
leapfrog	B-Algorithm
integration	I-Algorithm
.	O
</s>
<s>
Leapfrog	B-Algorithm
integration	I-Algorithm
is	O
roughly	O
2nd	O
order	O
on	O
the	O
timestep	O
,	O
other	O
integrators	O
such	O
as	O
Runge	B-Algorithm
–	I-Algorithm
Kutta	I-Algorithm
methods	I-Algorithm
can	O
have	O
4th	O
order	O
accuracy	O
or	O
much	O
higher	O
.	O
</s>
<s>
In	O
tree	O
methods	O
,	O
such	O
as	O
a	O
Barnes	O
–	O
Hut	O
simulation	O
,	O
an	O
octree	B-Data_Structure
is	O
usually	O
used	O
to	O
divide	O
the	O
volume	O
into	O
cubic	O
cells	O
and	O
only	O
interactions	O
between	O
particles	O
from	O
nearby	O
cells	O
need	O
to	O
be	O
treated	O
individually	O
;	O
particles	O
in	O
distant	O
cells	O
can	O
be	O
treated	O
collectively	O
as	O
a	O
single	O
large	O
particle	O
centered	O
at	O
the	O
distant	O
cell	O
's	O
center	O
of	O
mass	O
(	O
or	O
as	O
a	O
low-order	O
multipole	O
expansion	O
)	O
.	O
</s>
<s>
Another	O
possibility	O
is	O
the	O
particle	B-Algorithm
mesh	I-Algorithm
method	I-Algorithm
in	O
which	O
space	O
is	O
discretised	O
on	O
a	O
mesh	O
and	O
,	O
for	O
the	O
purposes	O
of	O
computing	O
the	O
gravitational	O
potential	O
,	O
particles	O
are	O
assumed	O
to	O
be	O
divided	O
between	O
the	O
surrounding	O
2x2	O
vertices	O
of	O
the	O
mesh	O
.	O
</s>
<s>
As	O
the	O
particles	O
are	O
meant	O
to	O
represent	O
large	O
numbers	O
of	O
dark	B-Application
matter	I-Application
particles	O
or	O
groups	O
of	O
stars	O
,	O
these	O
binaries	O
are	O
unphysical	O
.	O
</s>
<s>
To	O
prevent	O
this	O
,	O
a	O
softened	B-Algorithm
Newtonian	O
force	O
law	O
is	O
used	O
,	O
which	O
does	O
not	O
diverge	O
as	O
the	O
inverse-square	O
radius	O
at	O
short	O
distances	O
.	O
</s>
<s>
Softening	B-Algorithm
is	O
a	O
numerical	O
trick	O
used	O
in	O
N-body	B-Algorithm
techniques	O
to	O
prevent	O
numerical	O
divergences	B-Application
when	O
a	O
particle	O
comes	O
too	O
close	O
to	O
another	O
(	O
and	O
the	O
force	O
goes	O
to	O
infinity	O
)	O
.	O
</s>
<s>
(	O
rather	O
than	O
1/r	O
)	O
where	O
is	O
the	O
softening	B-Algorithm
parameter	O
.	O
</s>
<s>
The	O
value	O
of	O
the	O
softening	B-Algorithm
parameter	O
should	O
be	O
set	O
small	O
enough	O
to	O
keep	O
simulations	O
realistic	O
.	O
</s>
<s>
Many	O
simulations	O
simulate	O
only	O
cold	O
dark	B-Application
matter	I-Application
,	O
and	O
thus	O
include	O
only	O
the	O
gravitational	O
force	O
.	O
</s>
<s>
Incorporating	O
baryons	O
,	O
leptons	O
and	O
photons	B-Application
into	O
the	O
simulations	O
dramatically	O
increases	O
their	O
complexity	O
and	O
often	O
radical	O
simplifications	O
of	O
the	O
underlying	O
physics	O
must	O
be	O
made	O
.	O
</s>
<s>
Reif	O
and	O
Tate	O
prove	O
that	O
if	O
the	O
n-body	B-Algorithm
reachability	O
problem	O
is	O
defined	O
as	O
follows	O
–	O
given	O
n	O
bodies	O
satisfying	O
a	O
fixed	O
electrostatic	O
potential	O
law	O
,	O
determining	O
if	O
a	O
body	O
reaches	O
a	O
destination	O
ball	O
in	O
a	O
given	O
time	O
bound	O
where	O
we	O
require	O
a	O
poly(n )	O
bits	O
of	O
accuracy	O
and	O
the	O
target	O
time	O
is	O
poly(n )	O
is	O
in	O
PSPACE	O
.	O
</s>
<s>
These	O
bounds	O
are	O
based	O
on	O
similar	O
complexity	O
bounds	O
obtained	O
for	O
ray	B-Algorithm
tracing	I-Algorithm
.	O
</s>
<s>
The	O
simplest	O
implementation	O
of	O
N-body	B-Algorithm
simulations	I-Algorithm
where	O
is	O
a	O
naive	O
propagation	O
of	O
orbiting	O
bodies	O
;	O
naive	O
implying	O
that	O
the	O
only	O
forces	O
acting	O
on	O
the	O
orbiting	O
bodies	O
is	O
the	O
gravitational	O
force	O
which	O
they	O
exert	O
on	O
each	O
other	O
.	O
</s>
<s>
In	O
object-oriented	B-Language
programming	I-Language
languages	I-Language
,	O
such	O
as	O
C++	B-Language
,	O
some	O
boilerplate	O
code	O
is	O
useful	O
for	O
establishing	O
the	O
fundamental	O
mathematical	O
structures	O
as	O
well	O
as	O
data	O
containers	O
required	O
for	O
propagation	O
;	O
namely	O
state	O
vectors	O
,	O
and	O
thus	O
vectors	O
,	O
and	O
some	O
fundamental	O
object	O
containing	O
this	O
data	O
,	O
as	O
well	O
as	O
the	O
mass	O
of	O
an	O
orbiting	O
body	O
.	O
</s>
<s>
This	O
method	O
is	O
applicable	O
to	O
other	O
types	O
of	O
N-body	B-Algorithm
simulations	I-Algorithm
as	O
well	O
;	O
a	O
simulation	O
of	O
point	O
masses	O
with	O
charges	O
would	O
use	O
a	O
similar	O
method	O
,	O
however	O
the	O
force	O
would	O
be	O
due	O
to	O
attraction	O
or	O
repulsion	O
by	O
interaction	O
of	O
electric	O
fields	O
.	O
</s>
<s>
An	O
example	O
of	O
a	O
programmatically	O
stable	O
and	O
scalable	B-Architecture
method	O
for	O
containing	O
kinematic	O
data	O
for	O
a	O
particle	O
is	O
the	O
use	O
of	O
fixed	O
length	O
arrays	O
,	O
which	O
in	O
optimised	O
code	O
allows	O
for	O
easy	O
memory	B-General_Concept
allocation	I-General_Concept
and	O
prediction	O
of	O
consumed	O
resources	O
;	O
as	O
seen	O
in	O
the	O
following	O
C++	B-Language
code	I-Language
:	O
</s>
<s>
Commonly	O
,	O
N-body	B-Algorithm
simulations	I-Algorithm
will	O
be	O
systems	O
based	O
of	O
some	O
type	O
of	O
equations	O
of	O
motion	O
;	O
of	O
these	O
,	O
most	O
will	O
be	O
dependent	O
on	O
some	O
initial	O
configuration	O
to	O
"	O
seed	O
"	O
the	O
simulation	O
.	O
</s>
<s>
Memory	B-Architecture
space	I-Architecture
for	O
these	O
bodies	O
must	O
be	O
reserved	O
before	O
the	O
bodies	O
are	O
configured	O
;	O
to	O
allow	O
for	O
scalability	B-Architecture
,	O
a	O
malloc	B-General_Concept
command	O
may	O
be	O
used	O
:	O
</s>
