rapier2d/counters/
solver_counters.rs1use crate::counters::Timer;
2use std::fmt::{Display, Formatter, Result};
3
4#[derive(Default, Clone, Copy)]
6pub struct SolverCounters {
7 pub nconstraints: usize,
9 pub ncontacts: usize,
11 pub velocity_resolution_time: Timer,
13 pub velocity_assembly_time: Timer,
15 pub velocity_assembly_time_solver_bodies: Timer,
17 pub velocity_assembly_time_constraints_init: Timer,
19 pub velocity_update_time: Timer,
21 pub velocity_writeback_time: Timer,
23}
24
25impl SolverCounters {
26 pub fn new() -> Self {
28 SolverCounters {
29 nconstraints: 0,
30 ncontacts: 0,
31 velocity_assembly_time: Timer::new(),
32 velocity_assembly_time_solver_bodies: Timer::new(),
33 velocity_assembly_time_constraints_init: Timer::new(),
34 velocity_resolution_time: Timer::new(),
35 velocity_update_time: Timer::new(),
36 velocity_writeback_time: Timer::new(),
37 }
38 }
39
40 pub fn reset(&mut self) {
42 self.nconstraints = 0;
43 self.ncontacts = 0;
44 self.velocity_resolution_time.reset();
45 self.velocity_assembly_time.reset();
46 self.velocity_assembly_time_solver_bodies.reset();
47 self.velocity_assembly_time_constraints_init.reset();
48 self.velocity_update_time.reset();
49 self.velocity_writeback_time.reset();
50 }
51}
52
53impl Display for SolverCounters {
54 fn fmt(&self, f: &mut Formatter) -> Result {
55 writeln!(f, "Number of contacts: {}", self.ncontacts)?;
56 writeln!(f, "Number of constraints: {}", self.nconstraints)?;
57 writeln!(f, "Velocity assembly time: {}", self.velocity_assembly_time)?;
58 writeln!(
59 f,
60 "Velocity resolution time: {}",
61 self.velocity_resolution_time
62 )?;
63 writeln!(f, "Velocity update time: {}", self.velocity_update_time)?;
64 writeln!(
65 f,
66 "Velocity writeback time: {}",
67 self.velocity_writeback_time
68 )
69 }
70}