1
0
Fork 0
forked from jojers/Zorya
N body simulation
  • C++ 70.7%
  • C 29.2%
Find a file
mkryss bdd0010bd3 feat: add -b flag for default backend
- Made `current_backend` a reference to a `BackendEntry` instead of an
  index into the backends array.
- Changed `BackendEntry::get` to return a pointer, so it avoids making a
  copy (and avoids a dangling reference later on in the code).
2026-05-05 19:24:15 +02:00
lib/imgui chore: Removed ImGui as submodule. Keep only relevant files 2026-04-19 14:38:32 +02:00
src feat: add -b flag for default backend 2026-05-05 19:24:15 +02:00
test fix: bad broadcasting of masses in tail loop 2026-05-05 00:16:45 +02:00
.gitignore fix: bad broadcasting of masses in tail loop 2026-05-05 00:16:45 +02:00
CMakeLists.txt fix: bad broadcasting of masses in tail loop 2026-05-05 00:16:45 +02:00
README.md feat: add avx512 backend 2026-05-03 21:24:42 +02:00
zorya.supp Added valgrind suppression file to suppress leaks coming from glfw, gtk and fontconfig (not my fault) 2026-03-01 18:59:09 +01:00

Zorya - C++26 Newtonian gravity engine with hotswappable backends

Zorya is a (soon to be) high performance modular N body newtonian gravity engine built in C++26. It (will) feature runtime switchable compute backends. The rendering is handled using OpenGL 4.5 with an ImGui overlay. It serves as a study piece in HPC, heterogeneous computing and GPGPU computing. As such, a conscious decision to implement the naive O(N²) method was made. Keeping a computationally heavy yet highly parallel algorithm as the baseline allows Zorya to properly showcase the throughput difference between a purely scalar implementation, SIMD on CPU and GPGPU. Of course, this also means that optimisations are left on the table in the spirit of fair benchmarking. Finally, Zorya also supports runtime precision swappning to showcase the advantages and disadvantages of float and double for throughput and numerical stability.

Build and run

Dependencies

  • CMake 3.31+
  • C++26
  • glfw
  • glew

Build instructions

Start by cloning the repo

git clone https://dawn.wine/jojers/Zorya.git

Set up cmake and compile

cd Zorya
cmake -B build && cmake --build build -j $(nproc)

Run the application with ./build/zorya [args]. If compiled with tests, run them with ./build/zorya_tests

Runtime arguments

Zorya supports several arguments to control the way the engine generates the system. It makes the distinction between a major body and a minor body. They can be interpreted as either planets and asteroids or solar systems and lone stars. It depends on what scale you want to imagine.

Toggle Type Default Effects
-c, --count Number 10 Number of major bodies
-r, --ratio Number 5 Number of minor bodies per major body
-O, --orbit Range 50:500 Width of the acceptable spawning area
-Mm, --major-mass Range 0.1:50 Range of masses that a major body can be
-mm, --minor-mass Range 0.01:0.1 Range of masses that a minor body can be

A range must be formatted as from:to. Each side of the range is optional and omitting it will infer the default value. Please note that only positive values are accepted for both numbers and ranges.

For reference, the central star object has a mass of 1000.

Compile options

Zorya also has a some options passed at the CMake initialisation step like so cmake -B build [args]

Option Type Default Effects
ZORYA_TESTS ON,OFF ON Toggle the build of the test executable
ZORYA_ENABLE_SIMD ON,OFF ON Toggle SIMD capabilities (avx2, avx-512)