CobaltXII / cosmos

An OpenCL accelerated n-body simulation

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Cosmos

Cosmos is an OpenCL accelerated n-body simulator. It can be used to render n-body simulations at a high speed.

Alt text

Usage

Using Cosmos is a two step process. First, you must output binary data of the results of a n-body simulation. Second, you render this to a high-resolution image sequence. Cosmos provides two tools for these purposes, cosmos_simulate and cosmos_render. Cosmos also provides cosmos_sketch, used to quickly render ugly videos for testing.

Unfortunately, the Cosmos toolchain does not provide an easy way to tweak initial conditions or parameters. However, it does come with a great set of pre-defined conditions and parameters. If you want to modify these, you will have to edit the source code before compiling. If you want to find places where you can edit parameters, search for the text PARAM in all source files.

cosmos_simulate

To compile, use the command

clang++ cosmos_simulate.cpp -o cosmos_simulate -std=c++11 -lOpenCL

To run, use the command

./cosmos_simulate <frames> [bodies=24576]

This will cause cosmos_simulate to output a bunch of frames to the directory that it was started in. These frames will be binary files, copied directly from OpenCL output.

cosmos_render

To compile, use the command

clang++ cosmos_render.cpp -o cosmos_render -std=c++11 -lOpenCL

To run, use the command

./cosmos_render <frames> [bodies=24576]

This will cause cosmos_render to output a bunch of rendered frames to the directory that it was started in. These rendered frames will be image files, produced by rendering the corresponding simulation frames generated by running cosmos_simulate.

cosmos_sketch

To compile, use the command

clang++ cosmos_sketch.cpp -o cosmos_sketch -std=c++11 -lOpenCL

To run, use the command

./cosmos_sketch <frames> [bodies=24576]

This will cause cosmos_sketch to output a bunch of ugly rendered frames to the directory that it was started in. These rendered frames will be image files, produced by rendering the corresponding simulation frames generated by running cosmos_simulate.

Even more speed

To speed up simulations and renders even more, compile with

clang++ cosmos_tool.cpp -o cosmos_tool -std=c++11 -lOpenCL -Ofast -march=native

Sample renders

Take a look at the image above. That should give you a general idea of what Cosmos can do. If you can only see in video, here's one.

Credits and licensing

Cosmos is licensed under the MIT License. Thanks to Sean Barrett for creating stb_image_write. Thanks to the Khronos Group for creating OpenCL, which in my experience was a very nice API to work with. Thanks to Stéfan van der Walt and Nathaniel Smith for creating the palette used in thermal_colormap.

About

An OpenCL accelerated n-body simulation

License:MIT License


Languages

Language:C 67.1%Language:C++ 19.6%Language:Objective-C 13.3%