Implementation of the Barnes Hut algorithm to simulate the evolution of a galaxy. This code has been compiled under Cygwin.
I learned about the Barnes Hut Algorithm from the Simulation and modeling of natural processes from the University of Geneva.
I am grateful to the following people who have geneously made code available the the world at large:
- Jason Blevins for his version of the Mersenne Twister by Mutsuo Saito and Makoto Matsumoto;
- Martin Hořeňovský for the Catch2 Unit testing framework;
- Gabi Melman for the spdlog Fast C++ Logging Library;
- Lee Thomason for the TinyXML2 XML Parser.
NB Their source code is available under whichever licences the authors have used. It is not covered by the license for the galaxy package.
| File | Purpose |
|---|---|
| csrc | C++ source |
| scripts | Python scripts |
| bolzmann.png | Image used by README.md |
| energy00200.png | Image used by README.md |
| energy05400.png | Image used by README.md |
| kill.bat | Use to stop main program gracefully |
| Date | Remarks |
|---|---|
| 31 Jan 18 | Program segfaults. Turn off Barnes-Hut and try some easy test cases, e.g. Kepler, Lagrange points, and a resonance |
| 4 Feb 18 | Traced problem to acceleration calcs: when we figure out force on a particular particle we included the particle itself. This has been corrected, but the fix is a kludge, so some work still needs to be done. Particles are diverging, is the initial velocity too high? |
| 6 Feb 18 | Reset centre of mass and linear momentum to (0,0,0) at start of run, and checked code. Configuration still drifts. Need to construct simplest possible case that exhibits error. |
| 7 Feb 18 | I have done some more checking by adding tracing statements, and code appears to be working, albeit with large error. I am studying Error analysis of a tree code by Barnes and Hut. Do errors decrease for very many particles? What if we soften gravitational potential? Another thought: what is error in Geneva code? |
| 8 Feb 18 | Downloaded Geneva version and modified to display energy. At present this does not appear to be conserved |
| 13 Feb 18 | I am logging parameters, so can now investigate dependence of energy anomaly on dt, softening, and theta. I'm also doing some long runs to study long-term behaviour. |
| 26 Feb 18 | The kinetic energy and potential energy aren't following Virial theorem very well. I will check mass distribution first. |
| 17 Mar 18 | After a week of development I now have a multithreaded version. I don't think I'd have started if I'd realized how much work it was. Just doing a few time comparisons. Later: very disappointing - multi-threaded is slower than single threaded. |
| 18 Mar 18 | What if there many more than 1000 bodies? We possibly need the acceleration calculation to be much longer to see the benefit of threads? No: I have just tested, with 100000 bodies, 10 iterations. 4 threads, 448 seconds; 2 threads, 448; unthreaded, 165 |
| I have created a factory to allow more complex simulations, e.g. colliding galaxies. I decided to use XML rather than CSV, and used Lee Thomason's TinyXML-2, following the discussion here. XML is more than I require at present, but I expect the complexity of the input files weill increase, so this is by way of future proofing. | |
| 25 Mar 18 | I'm curious to see whether the configuration eventually becomes thermalized--see Debarshee Bagchi and Constantino Tsallis: Fermi-Pasta-Ulam-Tsingou problems: Passage from Boltzmann to qq-statistics. Since we were throwing away the momentum when we write the configuration, I've raised Issue #32 to fix this. This is also a good time to simplify the code by removing energy calcs, so we use c++ for heavy lifting, but do as much as possible in Python. |
| 26 Mar 18 | This shows the distribution after 5400 iterations, compared with the Bolzmann Distribution. |
| 2 Apr 18 | Revisit Virial Theorem - what is the effect of the softening length? |