pure-cpp 1.0.0
A C++ physics simulation benchmark comparing performance with Python implementations
space.hpp File Reference

N-body simulation space with gravitational interaction and collision response. More...

#include <omp.h>
#include <chrono>
#include <cstddef>
#include <memory>
#include <optional>
#include <stdexcept>
#include <vector>
#include "body.hpp"
#include "config.hpp"
#include "constants.hpp"
#include "kdtree.hpp"
Include dependency graph for space.hpp:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  Model::CollisionContext
 A data container to hold all relevant information for a single collision event. More...
 
class  Model::Space
 Class describing a space in which move several bodies. More...
 

Detailed Description

N-body simulation space with gravitational interaction and collision response.

Author
Le Bars, Yoann

This file defines the Space class, which manages the state and dynamics of all bodies in the simulation. The physics model includes:

  • Gravitational Interaction: All bodies exert a gravitational force on each other, calculated using Newton's law of universal gravitation.
  • Collision Response: Collisions between spherical bodies are handled using an impulse-based method that accounts for both linear and rotational motion, including friction.
  • Integration: The simulation state (position and velocity) is advanced using the Velocity Verlet algorithm, a time-reversible and energy-conserving semi-implicit Euler integration scheme.
  • Broad-Phase Detection: A k-d tree is used to efficiently find potentially colliding pairs of bodies, avoiding an O(N²) check.

This file is part of the pure C++ benchmark.

This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program. If not, see https://www.gnu.org/licenses/.

Definition in file space.hpp.