Skip to content

Commit

Permalink
still a draft, nbody0 is almost done now.
Browse files Browse the repository at this point in the history
  • Loading branch information
teuben committed Jan 20, 2025
1 parent 4f59089 commit 590b0d2
Showing 1 changed file with 132 additions and 5 deletions.
137 changes: 132 additions & 5 deletions scripts/notebooks/aarseth.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@
"id": "0b0acc08-6ce4-4c7a-abec-966e5abdf370",
"metadata": {},
"source": [
"# The Aarseth NBODY family of codes\n",
"# The Aarseth NBODY family of codes (*draft*)\n",
"\n",
"With the \n",
"[passing of Sverre Aarseth on Dec 28, 2024](https://ascl.net/wordpress/2025/01/07/sverre-aarseth-father-of-open-source-stellar-dynamics-has-passed-on-to-a-higher-orbit/),\n",
"we wanted to remember him by showcasing some examples of some of his legacy in NEMO, in the process cleaning up some of NEMO's code.\n",
"we remember him by showcasing some examples of some of his legacy codes in NEMO.\n",
"\n",
"Sverre has always made his code available for anybody to use. His current body of work can be found at https://people.ast.cam.ac.uk/~sverre/web/pages/nbody.htm\n",
"Sverre has always made his code available for anybody to use. His current body of work can still be found at https://people.ast.cam.ac.uk/~sverre/web/pages/nbody.htm as well as an [entry in ASCL](https://ascl.net/1102.006).\n",
"\n",
"\n",
"The following programs are avaiilable in NEMO:\n",
Expand All @@ -27,6 +27,10 @@
"* u4tos, stou4 - conversion programs of Sverre's \"UNIT4\" files to and from NEMO snapshot's\n",
"* u3tos - conversion program of Sverre's \"UNIT3\" file to a NEMO snapshot\n",
"\n",
"and Sverre's 1999 paper [\"From NBODY1 to NBODY6: The Growth of an Industry\"](https://ui.adsabs.harvard.edu/abs/1999PASP..111.1333A) \n",
"outlines the history behind this series.\n",
"\n",
"\n",
"\n",
"# Loading NEMO\n",
"\n",
Expand Down Expand Up @@ -55,11 +59,11 @@
"id": "4f6c80e3-688b-4b95-be5b-d8cbf8fb0d98",
"metadata": {},
"source": [
"# nbody0, nbody00\n",
"# nbody0, nbody00, nbody0_ff, nbody0h4\n",
"\n",
"This code was published in the Appendix of the 1987 (first) edition of Binney & Tremaine's *Galactic Dynamics*. The code\n",
"can be found in \n",
"**$NEMO/src/nbody/evolve/aarseth/nbody0**. The FORTRAN version reads input from \n"
"**$NEMO/src/nbody/evolve/aarseth/nbody0**, where several derivatives of this *Micky Mouse* version are available."
]
},
{
Expand All @@ -72,6 +76,110 @@
"man nbody0"
]
},
{
"cell_type": "markdown",
"id": "76d7e27d-c05b-47ae-8ad1-3be1597c6fc4",
"metadata": {},
"source": [
"### Creating initial conditions\n",
"\n",
"By default the FORTRAN code is compiled with space for a maximum of 2048 particles. We thus create a Plummer (1911) sphere with 2048 particles. We fix the seed to have reproducable results, and integrate a few crossing times to keep the CPU loaded for a few seconds."
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "47a0a006-b7ac-4c9e-88c3-64e9f99a5f62",
"metadata": {},
"outputs": [],
"source": [
"rm -f p2048\n",
"mkplummer p2048 2048 seed=123\n",
"tsf p2048"
]
},
{
"cell_type": "markdown",
"id": "06ff1c6d-5a36-4182-9624-95e7ba744193",
"metadata": {},
"source": [
"### Comparing FORTRAN and C\n",
"\n",
"We now compare the performance of the FORTRAN and C versions. We use **out=.** to not have to write an output file, saving some overhead.\n",
"The default integration time **tcrit=2** is used."
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "c9609d60-5891-4cb0-a239-0c6972cbbae2",
"metadata": {
"scrolled": true
},
"outputs": [],
"source": [
"/usr/bin/time nbody0 p2048 . tcrit=2\n",
"/usr/bin/time nbody00 p2048 . tcrit=2"
]
},
{
"cell_type": "markdown",
"id": "86ef0f50-6344-491d-8578-a4e13c14eecc",
"metadata": {},
"source": [
"### Reproducability\n",
"\n",
"If NEMO's random number generator is working correctly, the number of steps and energy at time=2 should be identical to\n",
"```\n",
" time = 2 steps = 161238 energy = -0.244397\n",
"```\n",
"and although the CPU time varies per machine, my 2023 \"Ultra 7 155H\" laptop CPU took about 1.7sec for **nbody0** and 2.0sec for **nbody00**. Also notable is that the C version does use a small amount (4%) of system time, whereas FORTRAN took 0. "
]
},
{
"cell_type": "markdown",
"id": "14849a05-f74a-49f3-b915-9cc55f9069bb",
"metadata": {},
"source": [
"### nbody00_ff\n",
"\n",
"The pure FORTRAN version does not have a NEMO CLI. It reads a one line header from stdin, followed by N (the number of bodies) lines containing the mass, position and velocity. The header contains **n,eta,deltat,tcrit,eps2,reset**. Such an input file can be easily created using basic NEMO tools."
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "30e65f69-09c2-4ece-8e23-eef25839859f",
"metadata": {},
"outputs": [],
"source": [
"rm -f p5\n",
"mkplummer p5 5 seed=123\n",
"\n",
"# convert the snapsshot to the input file that nbody0_ff needs\n",
"echo \"5,0.02,1.0,10,0.0001,1\" > input5\n",
"snapprint p5 m,x,y,z,vx,vy,vz format=%.15g >> input5\n",
"\n",
"# run nbody0_ff\n",
"nbody0_ff < input5 \n",
"\n",
"# run nbody0, and compare the phase space coordinated at times=10\n",
"nbody0 p5 - deltat=1 eps=0.01 tcrit=10 | snaptrim - - times=10 | snapprint -"
]
},
{
"cell_type": "markdown",
"id": "82c27183-5e94-43d2-b4c2-2b44a93c610e",
"metadata": {},
"source": [
"### Comparing nbody0 and nbody0_ff\n",
"\n",
"Apart from the limited accuracy that nbody0_ff shows, the comparison is excellent, as well as number of steps taken and the energy in the final snapshot:\n",
"```\n",
" time = 10 steps = 2351 energy = -0.181269\n",
"```"
]
},
{
"cell_type": "markdown",
"id": "6fc2c8ee-6e47-4d5e-9988-195a1307fb1c",
Expand All @@ -84,6 +192,14 @@
"This version also introduces the more formal *run* interface in NEMO to allow one to run legacy codes with a NEMO command line interface. It also includes conversion between NEMO's snapshots and NBODYx files (unit3, unit4)."
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "340163de-36bd-4a5c-9f47-0bebf26b4047",
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
Expand Down Expand Up @@ -120,6 +236,7 @@
"metadata": {},
"outputs": [],
"source": [
"rm -f p128 \n",
"mkplummer p128 128"
]
},
Expand Down Expand Up @@ -253,6 +370,16 @@
"id": "63d9eff9-c644-4c6d-8df7-8efcaf74ca31",
"metadata": {},
"outputs": [],
"source": [
"man runbody6"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "18d6be8d-8a5c-4591-8600-a77b919b91cc",
"metadata": {},
"outputs": [],
"source": []
}
],
Expand Down

0 comments on commit 590b0d2

Please sign in to comment.