Input format ============ Two formats are accepted. The format is chosen by the file extension. JSON (recommended) ------------------ .. code-block:: json { "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 =============== ============== ========= ============================================== ``bodies`` list required The bodies (see below) ``G`` number ``1.0`` Gravitational constant, in your units ``dt`` number > 0 ``0.01`` Time step ``final_time`` number > 0 ``5`` The simulation runs from 0 to this time ``softening`` number ≥ 0 ``0`` Softening length to tame close encounters =============== ============== ========= ============================================== Each entry in ``bodies``: =============== ===================== ========= ========================================== Field Type Required Meaning =============== ===================== ========= ========================================== ``mass`` number > 0 yes Mass ``position`` list of 2 (or 3) yes Initial position ``[x, y]`` ``velocity`` list of 2 (or 3) yes Initial velocity ``[vx, vy]`` ``name`` 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: .. code-block:: ini [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 :math:`G = 4\pi^2 \approx 39.478` and the Earth moves at :math:`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 --------------- .. code-block:: bash nbody check my_system.json Errors say what is wrong, for example: .. code-block:: text error: invalid input: Body 1 is missing: velocity