Input format¶
Two formats are accepted. The format is chosen by the file extension.
JSON (recommended)¶
{
"G": 1.0,
"dt": 0.01,
"final_time": 5,
"softening": 0.0,
"bodies": [
{"name": "Star", "mass": 1.0, "position": [0, 0], "velocity": [0, 0]},
{"name": "Planet", "mass": 0.001, "position": [1, 0], "velocity": [0, 1]}
]
}
Top-level fields:
Field |
Type |
Default |
Meaning |
|---|---|---|---|
|
list |
required |
The bodies (see below) |
|
number |
|
Gravitational constant, in your units |
|
number > 0 |
|
Time step |
|
number > 0 |
|
The simulation runs from 0 to this time |
|
number ≥ 0 |
|
Softening length to tame close encounters |
Each entry in bodies:
Field |
Type |
Required |
Meaning |
|---|---|---|---|
|
number > 0 |
yes |
Mass |
|
list of 2 (or 3) |
yes |
Initial position |
|
list of 2 (or 3) |
yes |
Initial velocity |
|
text |
no |
Label in the animation legend |
All bodies must have the same number of components. 3D systems are allowed and
are animated as seen from above (the x-y plane). Extra keys, such as
"description", are ignored, so you can use them for notes.
Text format (.txt)¶
This is the original Celestial Rhapsody format. It is still supported:
[Global]
G = 1.0
dt = 0.01
final_time = 5
[Planet]
name = P1
mass = 1.0
x_0 = 0.8083106230
y_0 = 0.0
vx_0 = 0.0
vy_0 = 0.9901979166
[Planet]
name = P2
...
Warning
The values are read in order, not by name. Keep the lines in exactly
this order: G, dt, final_time and then
name, mass, x_0, y_0, vx_0, vy_0 for every planet. The first line must
be [Global]. The text format is 2D only and has no softening option.
Units¶
The code uses no fixed units. Just be consistent. Two common choices:
Dimensionless:
G = 1, masses and distances of order 1.Astronomical: distances in AU, time in years, masses in solar masses. Then \(G = 4\pi^2 \approx 39.478\) and the Earth moves at \(2\pi\) AU/yr. See
examples/inner_solar_system.json.
Choosing dt¶
dt should be much smaller than the shortest orbital period in the system,
about 1/500 of it is a good start. Then look at the energy drift printed by
nbody run. If it is larger than about 1e-3, halve dt.
Checking a file¶
nbody check my_system.json
Errors say what is wrong, for example:
error: invalid input: Body 1 is missing: velocity