Simon Kerler

Projects - nparticles

Generic N-Body Simulation Engine With GPU Support logo

nparticles: Generic N-Body Simulation Engine With GPU Support

My bachelor thesis I have conducted at the University of Applied Sciences Augsburg. Particle and n-body systems have many use cases in scientific research and computer graphics. This thesis proposes a generic engine to model, update and render these systems. OpenGL compute shaders are used to perform computations on the highly parallel architecture of graphics cards to speed up the simulation.

C++OpenGL 4.3

Abstract

Simulation and visualisation of n-body systems have many use cases in scientific research and computer graphics. Recent developments of graphics hardware allow these simulations to be executed on the GPU due to the parallel nature of the n-body problem. Many of the available solutions are hard coded to a special purpose and do not grant much flexibility for the definition of particle attributes and behaviour. Most often, updating a simulation is done on CPU or by using deprecated ways of GPGPU.

This thesis proposes a simulation engine which negotiates these shortcomings. It is written in C++ using OpenGL 4.3 as render and modern GPGPU framework. Its object-oriented and generic API allows the modelling of all kinds of n-body systems with particle attributes stored in GPU buffers and behaviour encoded in compute shaders. The engine was designed to be cross-platform, independent of hardware vendors, extensible, flexible and easy to use. Shader source code can be reused and all resources are managed by the engine implicitly.

For the creation of the engine, different GPU architectures and GPGPU frameworks were analysed. Two modern game engines (Irrlicht3D, Ogre3D) and various particle and n-body simulations were examined to design the architecture of the engine.

To verify implementation, two gravitational simulations were created. Two benchmarks to profile the render and compute process were implemented, as well. They were executed on a NVIDIA GeForce GTX660, GeForce GTX780 Ti and Quadro 4000 with results being examined to show possible bottlenecks and compute shader optimisations.

The result of this thesis is a working n-body simulation engine with GPU support that fulfils all of the initial requirements. Only the usability cannot be assessed objectively at the moment.

Features

  • GPU-Computing: Updating particles is performed on highly parallel GPU.
  • Rendering: Due to OpenGL, particles can be rendered in realtime.
  • Generic design: All kinds of particle and n-body systems can be modelled.
  • Reusable GPU code: Similar to C++, an include directive is provided for OpenGL shader.
  • Flexibility and extensibility: Interfaces allow to adapt the engine to a specific use case.
  • Object oriented API.
  • Vendor independency: All OpenGL 4.3 compatible graphics cards are supported.
  • Cross-platform: Supports Linux (tested), Windows and Mac (untested).
  • Implicit resource management: No need to handle destruction of engine resources manually.
  • Hardware tessellation support.

Screenshots

Screenshot of 65k simulated particles.
Simulation of 65000 particles on a Nvidia GTX 970 and 10 FPS. Color encoding: Slow particles are blue, fast ones are red.
Screenshot of initial state of solar system simulation.
Initial state of the solar system simulation.
Screenshot of solar system simulation planet trajectories.
Planetary trajectories are painted to visualize movements.
Screenshot of solar system simulation after 29 in-simulatoin years.
Planetary trajectories of inner planets after approx. 29 in-simulation years.
Screenshot of solar system simulation after 2853 in-simulation years.
Planetary trajectories of outer planets after approx. 2853 in-simulation years.

© 2014 - 2025 Simon Kerler. This website was published under the Creative Commons Attribution-ShareAlike 3.0 Unported License and was created with astro and tailwindcss .