pure-cpp 1.0.0
A C++ physics simulation benchmark comparing performance with Python implementations
Model::Bodies Class Reference

Structure-of-Arrays (SoA) container for all bodies in the simulation. More...

#include <body.hpp>

Collaboration diagram for Model::Bodies:
Collaboration graph

Public Member Functions

void reserve (std::size_t n)
 Reserve memory space for the data structure. More...
 
void emplaceBack (double in_m, double in_r, const Vector3d &in_x0, const Vector3d &in_v0, const Vector3d &in_omega0)
 Add a new body at the back of the data structure. More...
 
void integratePart1 (double dt, double dt_pos)
 Vectorized Velocity Verlet: Part 1. More...
 
void integratePart2 (double dt)
 Vectorized Velocity Verlet: Part 2. More...
 
std::size_t size () const
 Get number of bodies in the simulation. More...
 
BodyProxy operator[] (std::size_t index)
 A proxy to access a given body. More...
 
ConstBodyProxy operator[] (std::size_t index) const
 Array like access to given body. More...
 

Private Member Functions

void updateRotationsRK2 (double dt)
 Vectorized update of orientations for all bodies using a 2nd-order Runge-Kutta method (RK2). More...
 

Static Private Member Functions

static Vector4d getQuaternionDerivative (const Vector3d &omega, const Vector4d &q_coeffs)
 Calculates the time derivative of a quaternion. More...
 

Private Attributes

std::vector< double > m_
 Bodies’ masses. More...
 
std::vector< double > invM_
 Bodies inverse masses. More...
 
std::vector< double > r_
 Bodies radii. More...
 
std::vector< double > iInv_
 Bodies inverse moments of inertia. More...
 
std::vector< Vector3d > x_
 Bodies' positions. More...
 
std::vector< Vector3d > v_
 Bodies' velocities. More...
 
std::vector< Vector3d > a_
 Bodies' accelerations. More...
 
std::vector< Quaterniond > q_
 Bodies' orientations (quaternions). More...
 
std::vector< Vector3d > omega_
 Bodies' angular velocities. More...
 
std::vector< Vector3d > alpha_
 Bodies' angular accelerations. More...
 
std::vector< Vector3d > torque_
 Net torque applied to each body in a frame. More...
 

Friends

template<typename T >
class BodyProxyBase
 
class BodyProxy
 
class Space
 
class ConstBodyProxy
 
class BodiesAdaptor
 

Detailed Description

Structure-of-Arrays (SoA) container for all bodies in the simulation.

This layout improves cache performance by storing related data contiguously.

Structure of Arrays container for all simulation bodies.

Definition at line 274 of file body.hpp.

Member Function Documentation

◆ emplaceBack()

void Model::Bodies::emplaceBack ( double  in_m,
double  in_r,
const Vector3d &  in_x0,
const Vector3d &  in_v0,
const Vector3d &  in_omega0 
)
inline

Add a new body at the back of the data structure.

Parameters
in_mNew body mass.
in_rNew body radius.
in_x0New body initial position.
in_v0New body initial velocity.

Definition at line 311 of file body.hpp.

◆ getQuaternionDerivative()

static Vector4d Model::Bodies::getQuaternionDerivative ( const Vector3d &  omega,
const Vector4d &  q_coeffs 
)
inlinestaticprivate

Calculates the time derivative of a quaternion.

Parameters
omegaThe angular velocity vector.
q_coeffsThe quaternion coefficients [x, y, z, w].
Returns
The quaternion derivative multiplied by 2.

Definition at line 406 of file body.hpp.

Here is the caller graph for this function:

◆ integratePart1()

void Model::Bodies::integratePart1 ( double  dt,
double  dt_pos 
)
inline

Vectorized Velocity Verlet: Part 1.

Parameters
dtThe time step for the current frame's velocity update.
dt_posThe time step from the previous frame for the position update.

Definition at line 337 of file body.hpp.

Here is the call graph for this function:

◆ integratePart2()

void Model::Bodies::integratePart2 ( double  dt)
inline

Vectorized Velocity Verlet: Part 2.

Parameters
dtThe time step for the current frame.

Definition at line 357 of file body.hpp.

Here is the call graph for this function:

◆ operator[]() [1/2]

BodyProxy Model::Bodies::operator[] ( std::size_t  index)
inline

A proxy to access a given body.

Parameters
indexIndex of the body to be accessed.
Returns
A mutable proxy to the specified body.

Definition at line 380 of file body.hpp.

Here is the call graph for this function:

◆ operator[]() [2/2]

ConstBodyProxy Model::Bodies::operator[] ( std::size_t  index) const
inline

Array like access to given body.

Parameters
indexIndex of the body to be accessed.
Returns
A const proxy to the specified body.

Definition at line 392 of file body.hpp.

Here is the call graph for this function:

◆ reserve()

void Model::Bodies::reserve ( std::size_t  n)
inline

Reserve memory space for the data structure.

Parameters
nNumber of bodies in the simulation.

Definition at line 289 of file body.hpp.

◆ size()

std::size_t Model::Bodies::size ( ) const
inline

Get number of bodies in the simulation.

Returns
The total number of bodies.

Definition at line 371 of file body.hpp.

Here is the caller graph for this function:

◆ updateRotationsRK2()

void Model::Bodies::updateRotationsRK2 ( double  dt)
inlineprivate

Vectorized update of orientations for all bodies using a 2nd-order Runge-Kutta method (RK2).

This method mirrors the efficient, vectorized approach of the Python implementation, operating on all bodies at once.

Parameters
dtThe time step for the integration.

Definition at line 427 of file body.hpp.

Here is the call graph for this function:
Here is the caller graph for this function:

Friends And Related Function Documentation

◆ BodiesAdaptor

friend class BodiesAdaptor
friend

Definition at line 282 of file body.hpp.

◆ BodyProxy

friend class BodyProxy
friend

Definition at line 279 of file body.hpp.

◆ BodyProxyBase

template<typename T >
friend class BodyProxyBase
friend

Definition at line 278 of file body.hpp.

◆ ConstBodyProxy

friend class ConstBodyProxy
friend

Definition at line 281 of file body.hpp.

◆ Space

friend class Space
friend

Definition at line 280 of file body.hpp.

Member Data Documentation

◆ a_

std::vector<Vector3d> Model::Bodies::a_
private

Bodies' accelerations.

Definition at line 476 of file body.hpp.

◆ alpha_

std::vector<Vector3d> Model::Bodies::alpha_
private

Bodies' angular accelerations.

Definition at line 485 of file body.hpp.

◆ iInv_

std::vector<double> Model::Bodies::iInv_
private

Bodies inverse moments of inertia.

Definition at line 467 of file body.hpp.

◆ invM_

std::vector<double> Model::Bodies::invM_
private

Bodies inverse masses.

Definition at line 461 of file body.hpp.

◆ m_

std::vector<double> Model::Bodies::m_
private

Bodies’ masses.

Definition at line 458 of file body.hpp.

◆ omega_

std::vector<Vector3d> Model::Bodies::omega_
private

Bodies' angular velocities.

Definition at line 482 of file body.hpp.

◆ q_

std::vector<Quaterniond> Model::Bodies::q_
private

Bodies' orientations (quaternions).

Definition at line 479 of file body.hpp.

◆ r_

std::vector<double> Model::Bodies::r_
private

Bodies radii.

Definition at line 464 of file body.hpp.

◆ torque_

std::vector<Vector3d> Model::Bodies::torque_
private

Net torque applied to each body in a frame.

Definition at line 488 of file body.hpp.

◆ v_

std::vector<Vector3d> Model::Bodies::v_
private

Bodies' velocities.

Definition at line 473 of file body.hpp.

◆ x_

std::vector<Vector3d> Model::Bodies::x_
private

Bodies' positions.

Definition at line 470 of file body.hpp.


The documentation for this class was generated from the following file: