add profiling and code clean up
This commit is contained in:
@@ -17,15 +17,13 @@
|
|||||||
#include <cmath>
|
#include <cmath>
|
||||||
#include <LinearMath/btAlignedObjectArray.h>
|
#include <LinearMath/btAlignedObjectArray.h>
|
||||||
#include <LinearMath/btVector3.h>
|
#include <LinearMath/btVector3.h>
|
||||||
|
#include "LinearMath/btQuickprof.h"
|
||||||
template <class MatrixX>
|
template <class MatrixX>
|
||||||
class btConjugateGradient
|
class btConjugateGradient
|
||||||
{
|
{
|
||||||
// using TVStack = btAlignedObjectArray<btVector3>;
|
|
||||||
typedef btAlignedObjectArray<btVector3> TVStack;
|
typedef btAlignedObjectArray<btVector3> TVStack;
|
||||||
TVStack r,p,z,temp;
|
TVStack r,p,z,temp;
|
||||||
int max_iterations;
|
int max_iterations;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
btConjugateGradient(const int max_it_in)
|
btConjugateGradient(const int max_it_in)
|
||||||
: max_iterations(max_it_in)
|
: max_iterations(max_it_in)
|
||||||
@@ -37,6 +35,7 @@ public:
|
|||||||
// return the number of iterations taken
|
// return the number of iterations taken
|
||||||
int solve(MatrixX& A, TVStack& x, const TVStack& b, btScalar tolerance)
|
int solve(MatrixX& A, TVStack& x, const TVStack& b, btScalar tolerance)
|
||||||
{
|
{
|
||||||
|
BT_PROFILE("CGSolve");
|
||||||
btAssert(x.size() == b.size());
|
btAssert(x.size() == b.size());
|
||||||
reinitialize(b);
|
reinitialize(b);
|
||||||
|
|
||||||
|
|||||||
@@ -12,6 +12,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include "btDeformableBackwardEulerObjective.h"
|
#include "btDeformableBackwardEulerObjective.h"
|
||||||
|
#include "LinearMath/btQuickprof.h"
|
||||||
|
|
||||||
btDeformableBackwardEulerObjective::btDeformableBackwardEulerObjective(btAlignedObjectArray<btSoftBody *>& softBodies, const TVStack& backup_v)
|
btDeformableBackwardEulerObjective::btDeformableBackwardEulerObjective(btAlignedObjectArray<btSoftBody *>& softBodies, const TVStack& backup_v)
|
||||||
: m_softBodies(softBodies)
|
: m_softBodies(softBodies)
|
||||||
@@ -23,6 +24,7 @@ btDeformableBackwardEulerObjective::btDeformableBackwardEulerObjective(btAligned
|
|||||||
|
|
||||||
void btDeformableBackwardEulerObjective::reinitialize(bool nodeUpdated)
|
void btDeformableBackwardEulerObjective::reinitialize(bool nodeUpdated)
|
||||||
{
|
{
|
||||||
|
BT_PROFILE("reinitialize");
|
||||||
if(nodeUpdated)
|
if(nodeUpdated)
|
||||||
{
|
{
|
||||||
updateId();
|
updateId();
|
||||||
@@ -43,9 +45,7 @@ void btDeformableBackwardEulerObjective::setDt(btScalar dt)
|
|||||||
|
|
||||||
void btDeformableBackwardEulerObjective::multiply(const TVStack& x, TVStack& b) const
|
void btDeformableBackwardEulerObjective::multiply(const TVStack& x, TVStack& b) const
|
||||||
{
|
{
|
||||||
for (int i = 0; i < b.size(); ++i)
|
BT_PROFILE("multiply");
|
||||||
b[i].setZero();
|
|
||||||
|
|
||||||
// add in the mass term
|
// add in the mass term
|
||||||
size_t counter = 0;
|
size_t counter = 0;
|
||||||
for (int i = 0; i < m_softBodies.size(); ++i)
|
for (int i = 0; i < m_softBodies.size(); ++i)
|
||||||
@@ -54,7 +54,7 @@ void btDeformableBackwardEulerObjective::multiply(const TVStack& x, TVStack& b)
|
|||||||
for (int j = 0; j < psb->m_nodes.size(); ++j)
|
for (int j = 0; j < psb->m_nodes.size(); ++j)
|
||||||
{
|
{
|
||||||
const btSoftBody::Node& node = psb->m_nodes[j];
|
const btSoftBody::Node& node = psb->m_nodes[j];
|
||||||
b[counter] += (node.m_im == 0) ? btVector3(0,0,0) : x[counter] / node.m_im;
|
b[counter] = (node.m_im == 0) ? btVector3(0,0,0) : x[counter] / node.m_im;
|
||||||
++counter;
|
++counter;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -97,6 +97,7 @@ void btDeformableBackwardEulerObjective::applyForce(TVStack& force, bool setZero
|
|||||||
|
|
||||||
void btDeformableBackwardEulerObjective::computeResidual(btScalar dt, TVStack &residual) const
|
void btDeformableBackwardEulerObjective::computeResidual(btScalar dt, TVStack &residual) const
|
||||||
{
|
{
|
||||||
|
BT_PROFILE("computeResidual");
|
||||||
// add implicit force
|
// add implicit force
|
||||||
for (int i = 0; i < m_lf.size(); ++i)
|
for (int i = 0; i < m_lf.size(); ++i)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -13,7 +13,6 @@
|
|||||||
|
|
||||||
#ifndef BT_BACKWARD_EULER_OBJECTIVE_H
|
#ifndef BT_BACKWARD_EULER_OBJECTIVE_H
|
||||||
#define BT_BACKWARD_EULER_OBJECTIVE_H
|
#define BT_BACKWARD_EULER_OBJECTIVE_H
|
||||||
#include <functional>
|
|
||||||
#include "btConjugateGradient.h"
|
#include "btConjugateGradient.h"
|
||||||
#include "btDeformableLagrangianForce.h"
|
#include "btDeformableLagrangianForce.h"
|
||||||
#include "btDeformableMassSpringForce.h"
|
#include "btDeformableMassSpringForce.h"
|
||||||
@@ -21,6 +20,7 @@
|
|||||||
#include "btDeformableContactProjection.h"
|
#include "btDeformableContactProjection.h"
|
||||||
#include "btPreconditioner.h"
|
#include "btPreconditioner.h"
|
||||||
#include "btDeformableRigidDynamicsWorld.h"
|
#include "btDeformableRigidDynamicsWorld.h"
|
||||||
|
#include "LinearMath/btQuickprof.h"
|
||||||
|
|
||||||
class btDeformableRigidDynamicsWorld;
|
class btDeformableRigidDynamicsWorld;
|
||||||
class btDeformableBackwardEulerObjective
|
class btDeformableBackwardEulerObjective
|
||||||
@@ -36,7 +36,6 @@ public:
|
|||||||
btDeformableContactProjection projection;
|
btDeformableContactProjection projection;
|
||||||
const TVStack& m_backupVelocity;
|
const TVStack& m_backupVelocity;
|
||||||
btAlignedObjectArray<btSoftBody::Node* > m_nodes;
|
btAlignedObjectArray<btSoftBody::Node* > m_nodes;
|
||||||
|
|
||||||
btDeformableBackwardEulerObjective(btAlignedObjectArray<btSoftBody *>& softBodies, const TVStack& backup_v);
|
btDeformableBackwardEulerObjective(btAlignedObjectArray<btSoftBody *>& softBodies, const TVStack& backup_v);
|
||||||
|
|
||||||
virtual ~btDeformableBackwardEulerObjective() {}
|
virtual ~btDeformableBackwardEulerObjective() {}
|
||||||
@@ -72,6 +71,7 @@ public:
|
|||||||
// enforce constraints in CG solve
|
// enforce constraints in CG solve
|
||||||
void enforceConstraint(TVStack& x)
|
void enforceConstraint(TVStack& x)
|
||||||
{
|
{
|
||||||
|
BT_PROFILE("enforceConstraint");
|
||||||
projection.enforceConstraint(x);
|
projection.enforceConstraint(x);
|
||||||
updateVelocity(x);
|
updateVelocity(x);
|
||||||
}
|
}
|
||||||
@@ -85,6 +85,7 @@ public:
|
|||||||
// update the projections and project the residual
|
// update the projections and project the residual
|
||||||
void project(TVStack& r)
|
void project(TVStack& r)
|
||||||
{
|
{
|
||||||
|
BT_PROFILE("project");
|
||||||
projection.update();
|
projection.update();
|
||||||
projection.project(r);
|
projection.project(r);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -14,6 +14,7 @@
|
|||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <limits>
|
#include <limits>
|
||||||
#include "btDeformableBodySolver.h"
|
#include "btDeformableBodySolver.h"
|
||||||
|
#include "LinearMath/btQuickprof.h"
|
||||||
|
|
||||||
btDeformableBodySolver::btDeformableBodySolver()
|
btDeformableBodySolver::btDeformableBodySolver()
|
||||||
: m_numNodes(0)
|
: m_numNodes(0)
|
||||||
@@ -29,6 +30,7 @@ btDeformableBodySolver::~btDeformableBodySolver()
|
|||||||
|
|
||||||
void btDeformableBodySolver::solveConstraints(float solverdt)
|
void btDeformableBodySolver::solveConstraints(float solverdt)
|
||||||
{
|
{
|
||||||
|
BT_PROFILE("solveConstraints");
|
||||||
m_objective->setDt(solverdt);
|
m_objective->setDt(solverdt);
|
||||||
|
|
||||||
// add constraints to the solver
|
// add constraints to the solver
|
||||||
@@ -70,6 +72,7 @@ void btDeformableBodySolver::reinitialize(const btAlignedObjectArray<btSoftBody
|
|||||||
|
|
||||||
void btDeformableBodySolver::setConstraints()
|
void btDeformableBodySolver::setConstraints()
|
||||||
{
|
{
|
||||||
|
BT_PROFILE("setConstraint");
|
||||||
m_objective->setConstraints();
|
m_objective->setConstraints();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -224,6 +224,7 @@ void btDeformableContactProjection::update()
|
|||||||
|
|
||||||
void btDeformableContactProjection::setConstraints()
|
void btDeformableContactProjection::setConstraints()
|
||||||
{
|
{
|
||||||
|
BT_PROFILE("setConstraints");
|
||||||
// set Dirichlet constraint
|
// set Dirichlet constraint
|
||||||
for (int i = 0; i < m_softBodies.size(); ++i)
|
for (int i = 0; i < m_softBodies.size(); ++i)
|
||||||
{
|
{
|
||||||
@@ -233,12 +234,14 @@ void btDeformableContactProjection::setConstraints()
|
|||||||
if (psb->m_nodes[j].m_im == 0)
|
if (psb->m_nodes[j].m_im == 0)
|
||||||
{
|
{
|
||||||
btAlignedObjectArray<DeformableContactConstraint> c;
|
btAlignedObjectArray<DeformableContactConstraint> c;
|
||||||
|
c.reserve(3);
|
||||||
c.push_back(DeformableContactConstraint(btVector3(1,0,0)));
|
c.push_back(DeformableContactConstraint(btVector3(1,0,0)));
|
||||||
c.push_back(DeformableContactConstraint(btVector3(0,1,0)));
|
c.push_back(DeformableContactConstraint(btVector3(0,1,0)));
|
||||||
c.push_back(DeformableContactConstraint(btVector3(0,0,1)));
|
c.push_back(DeformableContactConstraint(btVector3(0,0,1)));
|
||||||
m_constraints.insert(psb->m_nodes[j].index, c);
|
m_constraints.insert(psb->m_nodes[j].index, c);
|
||||||
|
|
||||||
btAlignedObjectArray<DeformableFrictionConstraint> f;
|
btAlignedObjectArray<DeformableFrictionConstraint> f;
|
||||||
|
f.reserve(3);
|
||||||
f.push_back(DeformableFrictionConstraint());
|
f.push_back(DeformableFrictionConstraint());
|
||||||
f.push_back(DeformableFrictionConstraint());
|
f.push_back(DeformableFrictionConstraint());
|
||||||
f.push_back(DeformableFrictionConstraint());
|
f.push_back(DeformableFrictionConstraint());
|
||||||
@@ -246,13 +249,12 @@ void btDeformableContactProjection::setConstraints()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int i = 0; i < m_softBodies.size(); ++i)
|
for (int i = 0; i < m_softBodies.size(); ++i)
|
||||||
{
|
{
|
||||||
btSoftBody* psb = m_softBodies[i];
|
btSoftBody* psb = m_softBodies[i];
|
||||||
btMultiBodyJacobianData jacobianData_normal;
|
btMultiBodyJacobianData jacobianData_normal;
|
||||||
btMultiBodyJacobianData jacobianData_complementary;
|
btMultiBodyJacobianData jacobianData_complementary;
|
||||||
|
std::cout <<psb->m_rcontacts.size() << std::endl;
|
||||||
for (int j = 0; j < psb->m_rcontacts.size(); ++j)
|
for (int j = 0; j < psb->m_rcontacts.size(); ++j)
|
||||||
{
|
{
|
||||||
const btSoftBody::RContact& c = psb->m_rcontacts[j];
|
const btSoftBody::RContact& c = psb->m_rcontacts[j];
|
||||||
@@ -296,6 +298,7 @@ void btDeformableContactProjection::setConstraints()
|
|||||||
const btScalar dn = btDot(vr, cti.m_normal);
|
const btScalar dn = btDot(vr, cti.m_normal);
|
||||||
if (dn < SIMD_EPSILON)
|
if (dn < SIMD_EPSILON)
|
||||||
{
|
{
|
||||||
|
|
||||||
if (m_constraints.find(c.m_node->index) == NULL)
|
if (m_constraints.find(c.m_node->index) == NULL)
|
||||||
{
|
{
|
||||||
btAlignedObjectArray<DeformableContactConstraint> constraints;
|
btAlignedObjectArray<DeformableContactConstraint> constraints;
|
||||||
@@ -369,7 +372,6 @@ void btDeformableContactProjection::enforceConstraint(TVStack& x)
|
|||||||
x[i] += constraints[j].m_value[k] * constraints[j].m_direction[k];
|
x[i] += constraints[j].m_value[k] * constraints[j].m_direction[k];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -94,15 +94,15 @@ public:
|
|||||||
for (int i = 0; i < m_softBodies.size(); ++i)
|
for (int i = 0; i < m_softBodies.size(); ++i)
|
||||||
{
|
{
|
||||||
const btSoftBody* psb = m_softBodies[i];
|
const btSoftBody* psb = m_softBodies[i];
|
||||||
|
btScalar scaled_k_damp = psb->m_dampingCoefficient * scale;
|
||||||
for (int j = 0; j < psb->m_links.size(); ++j)
|
for (int j = 0; j < psb->m_links.size(); ++j)
|
||||||
{
|
{
|
||||||
const btSoftBody::Link& link = psb->m_links[j];
|
const btSoftBody::Link& link = psb->m_links[j];
|
||||||
btSoftBody::Node* node1 = link.m_n[0];
|
btSoftBody::Node* node1 = link.m_n[0];
|
||||||
btSoftBody::Node* node2 = link.m_n[1];
|
btSoftBody::Node* node2 = link.m_n[1];
|
||||||
btScalar k_damp = psb->m_dampingCoefficient;
|
|
||||||
size_t id1 = node1->index;
|
size_t id1 = node1->index;
|
||||||
size_t id2 = node2->index;
|
size_t id2 = node2->index;
|
||||||
btVector3 local_scaled_df = scale * k_damp * (dv[id2] - dv[id1]);
|
btVector3 local_scaled_df = scaled_k_damp * (dv[id2] - dv[id1]);
|
||||||
df[id1] += local_scaled_df;
|
df[id1] += local_scaled_df;
|
||||||
df[id2] -= local_scaled_df;
|
df[id2] -= local_scaled_df;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -14,10 +14,11 @@
|
|||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include "btDeformableRigidDynamicsWorld.h"
|
#include "btDeformableRigidDynamicsWorld.h"
|
||||||
#include "btDeformableBodySolver.h"
|
#include "btDeformableBodySolver.h"
|
||||||
|
#include "LinearMath/btQuickprof.h"
|
||||||
|
|
||||||
void btDeformableRigidDynamicsWorld::internalSingleStepSimulation(btScalar timeStep)
|
void btDeformableRigidDynamicsWorld::internalSingleStepSimulation(btScalar timeStep)
|
||||||
{
|
{
|
||||||
|
BT_PROFILE("internalSingleStepSimulation");
|
||||||
reinitialize(timeStep);
|
reinitialize(timeStep);
|
||||||
// add gravity to velocity of rigid and multi bodys
|
// add gravity to velocity of rigid and multi bodys
|
||||||
applyRigidBodyGravity(timeStep);
|
applyRigidBodyGravity(timeStep);
|
||||||
@@ -50,7 +51,7 @@ void btDeformableRigidDynamicsWorld::internalSingleStepSimulation(btScalar timeS
|
|||||||
void btDeformableRigidDynamicsWorld::positionCorrection(btScalar dt)
|
void btDeformableRigidDynamicsWorld::positionCorrection(btScalar dt)
|
||||||
{
|
{
|
||||||
// perform position correction for all constraints
|
// perform position correction for all constraints
|
||||||
// for (auto& it : m_deformableBodySolver->m_objective->projection.m_constraints)
|
BT_PROFILE("positionCorrection");
|
||||||
for (int index = 0; index < m_deformableBodySolver->m_objective->projection.m_constraints.size(); ++index)
|
for (int index = 0; index < m_deformableBodySolver->m_objective->projection.m_constraints.size(); ++index)
|
||||||
{
|
{
|
||||||
btAlignedObjectArray<DeformableFrictionConstraint>& frictions = *m_deformableBodySolver->m_objective->projection.m_frictions[m_deformableBodySolver->m_objective->projection.m_constraints.getKeyAtIndex(index)];
|
btAlignedObjectArray<DeformableFrictionConstraint>& frictions = *m_deformableBodySolver->m_objective->projection.m_frictions[m_deformableBodySolver->m_objective->projection.m_constraints.getKeyAtIndex(index)];
|
||||||
@@ -134,6 +135,7 @@ void btDeformableRigidDynamicsWorld::positionCorrection(btScalar dt)
|
|||||||
|
|
||||||
void btDeformableRigidDynamicsWorld::integrateTransforms(btScalar dt)
|
void btDeformableRigidDynamicsWorld::integrateTransforms(btScalar dt)
|
||||||
{
|
{
|
||||||
|
BT_PROFILE("integrateTransforms");
|
||||||
m_deformableBodySolver->backupVelocity();
|
m_deformableBodySolver->backupVelocity();
|
||||||
positionCorrection(dt);
|
positionCorrection(dt);
|
||||||
btMultiBodyDynamicsWorld::integrateTransforms(dt);
|
btMultiBodyDynamicsWorld::integrateTransforms(dt);
|
||||||
@@ -169,6 +171,7 @@ void btDeformableRigidDynamicsWorld::addSoftBody(btSoftBody* body, int collision
|
|||||||
|
|
||||||
void btDeformableRigidDynamicsWorld::predictUnconstraintMotion(btScalar timeStep)
|
void btDeformableRigidDynamicsWorld::predictUnconstraintMotion(btScalar timeStep)
|
||||||
{
|
{
|
||||||
|
BT_PROFILE("predictUnconstraintMotion");
|
||||||
btMultiBodyDynamicsWorld::predictUnconstraintMotion(timeStep);
|
btMultiBodyDynamicsWorld::predictUnconstraintMotion(timeStep);
|
||||||
m_deformableBodySolver->predictMotion(timeStep);
|
m_deformableBodySolver->predictMotion(timeStep);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -78,8 +78,6 @@ public:
|
|||||||
m_sbi.m_sparsesdf.Initialize();
|
m_sbi.m_sparsesdf.Initialize();
|
||||||
m_internalTime = 0.0;
|
m_internalTime = 0.0;
|
||||||
}
|
}
|
||||||
// btAlignedObjectArray<std::function<void(btScalar, btDeformableRigidDynamicsWorld*)> > m_beforeSolverCallbacks;
|
|
||||||
|
|
||||||
|
|
||||||
void setSolverCallback(btSolverCallback cb)
|
void setSolverCallback(btSolverCallback cb)
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user