This is a simple, made-from-scratch n-body simulator written in C++ for an ASTR 513 midterm project. It utilizes the computational efficiency of the Barnes-Hut algorithm (Barnes & Hut, 1986) to create simulations that can support hundreds to
(it's possible we could do more, but that hasn't been tested yet. stay tuned!)
I'll probably be back in the future to play around with this more and add features + updates, but for now, enjoy and feel free to explore!
devnote >> globr has only been built and run on M3 Mac and Ubuntu. It requires at minimum C++11, but uses no libraries outside of the standards you'd expect with a base installation.
-
compile the code! globr has a Makefile ready to go, so compilation should be as easy as
cd path/to/globr mkdir data cd src make clean; make; lsafter you list your directory you should see an executable called
globr. if so, congrats! compilation worked and you're ready to make cool clusters.devnote >> you might get some warnings about deprecation if you're on a Mac depending on your version of C/C++; ignore those.
-
choose your starting conditions. globr has a simple set of command line flags that you can set when running the main executable:
-
-N: number of particles (REQUIRED) -
--size: starting size of physical simulation space, in parsecs (REQUIRED) -
--step: size of timestep in years (default: 1) -
--nstep: number of timesteps (default: 5000) -
--freq: how often data is output, in timesteps (default: 5) -
--theta: barnes-hut criterion (default: 0.5) -
--run: name of your simulation run (and data directory) (REQUIRED) -
--init: initial conditions file (REQUIRED)
so if we wanted to run
- a cluster of
$10^4$ stars, - made from the Salpeter initial condtions (salpeter.txt)
- for 5000 timesteps,
- with a step size of 100 years (or 500,000 years)
- and output data files every 10 timesteps,
then we would run globr from
globr/srcas follows:
./globr -N 10000 --size 100 --step 15 --nstep 5000 --freq 10 --run salpeter --init salpeter.txt & -
-
run globr and wait... Put together what you've learned in the previous steps and make some clusters!
devnote. If you try to run globr and immediately get a segfault error, try making your simulation size larger. I haven't added dynamic rescaling when the first tree is being constructed yet; if a particle is outside of that domain, the program will crash.
-
time for pretty pictures! So now you've made a cluster. What next? Visualization, of course! In
globr/vizthere's a simple Jupyter Notebook calledviz.ipynb. Before you get started, create a new directory calledframes:cd globr/viz mkdir framesNow you're ready to go. In the notebook, there's two variables:
datadirandrad_multiplier.datadirshould be set to whatever you named your run (i.e.--run) when creating your simulation; that will find the output data.rad_multipliercontrols how zoomed in your final visualization will be. The default value is 2; make it lower (~0.5) for more dense or smaller clusters.Run the cells! You'll need to have
pyvistainstalled on your kernel, and also will needffmpeginstalled on your laptop or computing tool of choice. Both of these are publicly available and pretty easy to acquire and install on most operating systems through common command line tools (pip,brew, etc.)Now that you have images (so. many.), go to the new directory (
globr/viz/frames/datadir) and run the following:ffmpeg -framerate 20 -i frame_%05d.png -c:v libx264 -pix_fmt yuv420p NAME.mp4where NAME is the filename you want for the visualization. make sure you have
ffmpeginstalled by runningffmpeg -versionin your terminal beforehand.Enjoy your new cool movie of your cluster(s)!
-
do science? You now know how to use and operate globr, congrats! There are a variety of initial conditions files in
globr/initthat can be used to- test scaling (
globr/init/scaling_N*.txt); - explore different initial mass functions, or IMFs (
globr/init/*; Salpeter, Kroppa, top-heavy, bottom-heavy...); - watch two clusters collide (
globr/init/initialConditions_2cluster*.txt); - or even just look at a random cluster (
globr/init/initialConditions_10*.txt).
Enjoy!
- test scaling (
Questions, comments, and suggestions are more than welcome. Reach out to the developer (hi, I'm Logan) at lawhite [at] arizona [dot] edu.