nphysics3d/counters/
solver_counters.rs

1use crate::counters::Timer;
2use std::fmt::{Display, Formatter, Result};
3
4/// Performance counters related to constraints resolution.
5#[derive(Default, Clone, Copy)]
6pub struct SolverCounters {
7    /// Number of constraints generated.
8    pub nconstraints: usize,
9    /// Number of contacts found.
10    pub ncontacts: usize,
11    /// Time spent for the resolution of the constraints (force computation).
12    pub velocity_resolution_time: Timer,
13    /// Time spent for the assembly of all the constraints into a linear complentarity problem.
14    pub assembly_time: Timer,
15    /// Time spent for the update of the velocity of the bodies.
16    pub velocity_update_time: Timer,
17    /// Time spent for the update of the position of the bodies.
18    pub position_resolution_time: Timer,
19}
20
21impl SolverCounters {
22    /// Creates a new counter initialized to zero.
23    pub fn new() -> Self {
24        SolverCounters {
25            nconstraints: 0,
26            ncontacts: 0,
27            assembly_time: Timer::new(),
28            velocity_resolution_time: Timer::new(),
29            velocity_update_time: Timer::new(),
30            position_resolution_time: Timer::new(),
31        }
32    }
33}
34
35impl Display for SolverCounters {
36    fn fmt(&self, f: &mut Formatter) -> Result {
37        writeln!(f, "Number of contacts: {}", self.ncontacts)?;
38        writeln!(f, "Number of constraints: {}", self.nconstraints)?;
39        writeln!(f, "Assembly time: {}", self.assembly_time)?;
40        writeln!(
41            f,
42            "Velocity resolution time: {}",
43            self.velocity_resolution_time
44        )?;
45        writeln!(f, "Velocity update time: {}", self.velocity_update_time)?;
46        writeln!(
47            f,
48            "Position resolution time: {}",
49            self.position_resolution_time
50        )
51    }
52}