Many N-body simulation codes, including EXP, work most efficiently when the gravitational constant G is set to 1 in the simulation units. This directory provides tools and examples for converting physical data (e.g., in CGS or astronomical units) to a scaled unit system where G=1, which simplifies equations of motion and improves numerical stability.
| File | Contents |
|---|---|
| earth_sun_cgs.txt | two-particle file (Sun + Earth) in CGS units |
| earth_sun_scaled.txt | expected converted file in scaled units (AU, M_sun, v'=1) |
| expunits.py | conversion script (compute scales + optional conversion) |
| README.md | this file |
-
The Python3 script requires numpy (e.g. pip install numpy).
-
From this directory, run:
-
python3 expunits.py --old-length 1 --new-length 1.495978707e13 --old-mass 1 --new-mass 1.98847e33 --G_old 6.67430e-8 --G_new 1 --infile earth_sun_cgs.txt --outfile earth_sun_scaled_by_script.txt --print-scales --sci
- --old-length 1 and --new-length 1.495978707e13: Interpret old-length unit = 1 cm, new-length unit = 1 AU = 1.495978707e13 cm, so s_L = new_length / old_length = 1.495978707e13.
- --old-mass 1 and --new-mass 1.98847e33: Interpret old-mass unit = 1 g, new-mass unit = 1 M_sun = 1.98847e33 g, so s_M = 1.98847e33.
- --G_old 6.67430e-8 is the cgs gravitational constant (cm^3 g^-1 s^-2).
- --G_new 1 requests that numeric G in the new numeric units equals 1.
- The script computes s_V from the relation s_M = s_L * s_V^2 * (G_new/G_old). Thus V_new (the new velocity unit) is chosen so that v_earth_old / s_V = 1.0.
The script prints s_L, s_V, s_M.
Expected approximate values: s_L ≈ 1.4959787e13 s_M ≈ 1.98847e33 s_V ≈ 2.978e6 (cm/s per one new velocity unit)
After conversion, earth_sun_scaled_by_script.txt should match earth_sun_scaled.txt to within rounding:
Sun: m' ≈ 1.0, r' ≈ 0.0, v' ≈ -3.00349e-6
Earth: m' ≈ 3.00349e-6, r' ≈ 1.0, v' ≈ 1.0