Add midphase and broadphase statistics to mjData.

PiperOrigin-RevId: 521387641
Change-Id: Id50f2549d119e364216491a23b107e04d9ebb5b6
This commit is contained in:
Alessio Quaglino
2023-04-03 00:59:18 -07:00
committed by Copybara-Service
parent c29f32657c
commit 5f132af625
8 changed files with 96 additions and 25 deletions
+16
View File
@@ -31,6 +31,8 @@ mjData* d[maxthread];
// per-thread statistics
double accuracy_broad[maxthread];
double accuracy_mid[maxthread];
int contacts[maxthread];
int constraints[maxthread];
double simtime[maxthread];
@@ -83,6 +85,8 @@ void simulate(int id, int nstep, mjtNum* ctrl) {
// clear statistics
contacts[id] = 0;
constraints[id] = 0;
accuracy_broad[id] = 0;
accuracy_mid[id] = 0;
// run and time
double start = gettm();
@@ -96,6 +100,16 @@ void simulate(int id, int nstep, mjtNum* ctrl) {
// accumulate statistics
contacts[id] += d[id]->ncon;
constraints[id] += d[id]->nefc;
if (d[id]->nbodypair_broad) {
accuracy_broad[id] += (100.0*d[id]->nbodypair_narrow)/d[id]->nbodypair_broad;
} else {
accuracy_broad[id] += 100;
}
if (d[id]->ngeompair_mid) {
accuracy_mid[id] += (100.0*d[id]->nbodypair_narrow)/d[id]->ngeompair_mid;
} else {
accuracy_mid[id] += 100;
}
}
simtime[id] = gettm() - start;
}
@@ -210,6 +224,8 @@ int main(int argc, char** argv) {
std::printf(" Steps per second : %.0f\n", nstep/simtime[0]);
std::printf(" Realtime factor : %.2f x\n", nstep*m->opt.timestep/simtime[0]);
std::printf(" Time per step : %.4f ms\n\n", 1000*simtime[0]/nstep);
std::printf(" Broadphase accuracy : %.2f%%\n", accuracy_broad[0]/nstep);
std::printf(" Midphase accuracy : %.2f%%\n", accuracy_mid[0]/nstep);
std::printf(" Contacts per step : %.2f\n", static_cast<float>(contacts[0])/nstep);
std::printf(" Constraints per step : %.2f\n", static_cast<float>(constraints[0])/nstep);
std::printf(" Degrees of freedom : %d\n\n", m->nv);