Computation and Astrophysics of The N-Body Problem
Computation and Astrophysics of The N-Body Problem
problem
Douglas Heggie
School of Mathematics
University of Edinburgh
[email protected]
2
Equations of motion
r
3 r
2
r
1
Softening
Initial Conditions
(It is best to give the file a new name, such as cc.in, and keep the
old file intest. The changes are in boldface, and lines are here
delimited by “/” to save space, but you should keep the format of
intest.)
1. Run the code (“../Real8/nbody1 < cc.in”)
2. Watch the numbers fly past until the job completes or you
have to kill it (“Ctrl-c”)1
3. To save the output, rerun it with redirection of output
(“../Real8/nbody1 < cc.in > cc.out”)
1
If the run fails or fails to complete in a few minutes, kill it. Then edit cc.in to
change the third number in line 2 of cc.in to some other positive integer, and try
again.
14
Cold collapse: the output - p1
(Corresponds to slightly different input file.)
15
Cold collapse: the output - p2
16
Initial conditions:
◮ All velocities are zero
◮ Particles are distributed uniformly in a sphere
17
Dynamic Equilibrium
17
Dynamic Equilibrium
Dynamic Equilibrium
Virial Equilibrium
2T + V ≃ 0.
T +E ≃0⇒T ≃ −E
and similarly V ≃ 2E .
20
Mass, length and time scales
20
Mass, length and time scales
◮ Total mass
N
X
M= mi
i =1
20
Mass, length and time scales
◮ Total mass
N
X
M= mi
i =1
G = 1
M = 1
R = 1
Example
GM
We have v 2 = .
2R
Suppose a star cluster has M = 105 M⊙ , R = 5pc. To r convert a
GM
velocity from the N -body code to km/s, multiply by , where G
R
is expressed in the same units (i.e. km/s, M⊙ , pc), i.e. G ≃ 0.0043.
23
We have
G = 1
M = 1
R = 1
In these units:
GM 1
◮ The characteristic speed v 2 = =
2R 2
2R √
◮ The crossing time tcr = =2 2
v
1 1
◮ The total energy E = − Mv 2 = −
2 4
24
Line 2: 25 1 200 1
1. N Total particle number.
2. NFIX Output frequency of data save or binaries (option 3 & 6
– see below).
Comment: There is a basic output interval. You need not
output the data or information on binaries at all such output
times.
3. NRAND Random number sequence skip.
Comment: initialises the random number generator
4. NRUN Run identification index.
27
Line 4: 1 0 1 0 0 1 0 0 0 0 0 0 0 0 0
Note: This is the line of options. In general, a zero value indicates
that the option is not selected
1. 1 COMMON save on unit 1 if TCOMP > CPU or if TIME >
TCRIT.
Comment: COMMON is a block of variables which are
enough to restart the run, if desired.
2. 2 COMMON save on unit 2 at output (=1); restart if DE/E >
5*QE (=2).
Comment: if this value is 1, the COMMON variables are saved
every output time; if 2, and the accuracy of the run has
deteriorated, the code attempts to repeat the most recent part
of the run with higher accuracy (and carry on)
29
The code NBODY1: input line 4 (continued)
Line 4: 1 0 1 0 0 1 0 0 0 0 0 0 0 0 0
3 Basic data written to unit 3 at output time (frequency NFIX).
Comment: if this is positive, complete information on the
particles is saved in a binary file OUT3 at each output time.
4 Initial conditions on unit 4 (=1: output; =2: input).
Comment: if this value is 1 the code dumps the initial
conditions on a file called fort.4; if 2, the initial conditions are
read in from this file (usually called fort.4)
5 Initial conditions (=0: uniform & isotropic; =1: Plummer).
Comment: we used 0. The Plummer model is explained in
Lecture 2
6 Output of significant binaries.
7 Output of movie frames on unit 7.
Comment: you can experiment with this!
8 Generation of two subsystems (merger experiment).
30
The code NBODY1: input line 4 (continued)
Line 4: 1 0 1 0 0 1 0 0 0 0 0 0 0 0 0
9 Individual bodies printed at output time (MIN(5**KZ9,N)).
Comment: the value is referred to as KZ9, and can be used to
control how many particles are listed
10 No scaling of initial conditions.
Comment: i.e. use units of the input file fort.4, and do not
scale to N -body units
11 Modification of ETA by tolerance QE.
Comment: ETA controls the accuracy of the integration (see
above), and this option lets the code attempt to adjust this by
monitoring the relative change in energy.
12 Initial parameters for binary orbit.
Comment: if non-zero, the code reads the semi-major axis
and eccentricity of a binary formed by the first two particles
13 Escaper removal (R > 2*RTIDE; RTIDE = 10*RSCALE).
Comment: here RSCALE is the virial radius.
31
Line 4: 1 0 1 0 0 1 0 0 0 0 0 0 0 0 0
14 Adjustment of coordinates & velocities to c.m. condition.
Comment: uses a barycentric coordinate system
15 Ignored
32
First rerun the code but collect the output in a text file cc.out.
(Again the run may have to be killed after a short time). The
command is
../Real8/nbody1 < cc.in > cc.out
Then awk is run with
awk -f q.awk cc.out > cc.q
which means that awk is to pick up its instructions from the file
q.awk, act on the file cc.out, and direct its output to a new file cc.q.
Here is an example of cc.q (a table of T , Q values)
0.0 0.00
0.3 0.01
0.6 0.02
0.9 0.05
1.1 0.11
1.4 0.23
41
Start gnuplot (“gnuplot”), and then plot the file just produced:
gnuplot> plot ’cc.q’ w l
Note: “w l” means “with lines”; otherwise you just get points.
This produces a window with the following graph:
0.8
’cc.q’
0.7
0.6
0.5
0.4
0.3
0.2
0.1
0
0 5 10 15 20 25 30
42
(swapping i and j ).
44
N X
N X X mi mj
X ri − rj
−G mi mj (ri − rj ). = −G ,
i =1 j =1,,i
|ri − rj |3 |ri − rj |
the sum being over all distinct i , j between 1 and N . This is twice
the potential energy, because each pair is counted twice.
Hence Ï = 4T + 2V .
45