address comment from ldowns

This commit is contained in:
Xuchen Han
2019-10-14 15:21:42 -07:00
parent a1afc66817
commit 05c25a27de
2 changed files with 14 additions and 9 deletions

View File

@@ -27,12 +27,12 @@ class btConjugateGradient
typedef btAlignedObjectArray<btVector3> TVStack; typedef btAlignedObjectArray<btVector3> TVStack;
TVStack r,p,z,temp; TVStack r,p,z,temp;
int max_iterations; int max_iterations;
btScalar tolerance; btScalar tolerance_squared;
public: public:
btConjugateGradient(const int max_it_in) btConjugateGradient(const int max_it_in)
: max_iterations(max_it_in) : max_iterations(max_it_in)
{ {
tolerance = 1e-5; tolerance_squared = 1e-5;
} }
virtual ~btConjugateGradient(){} virtual ~btConjugateGradient(){}
@@ -51,8 +51,7 @@ public:
A.precondition(r, z); A.precondition(r, z);
A.project(z); A.project(z);
btScalar r_dot_z = dot(z,r); btScalar r_dot_z = dot(z,r);
btScalar local_tolerance = tolerance; if (r_dot_z <= tolerance_squared) {
if (r_dot_z <= local_tolerance) {
if (verbose) if (verbose)
{ {
std::cout << "Iteration = 0" << std::endl; std::cout << "Iteration = 0" << std::endl;
@@ -86,7 +85,7 @@ public:
A.precondition(r, z); A.precondition(r, z);
r_dot_z = r_dot_z_new; r_dot_z = r_dot_z_new;
r_dot_z_new = dot(r,z); r_dot_z_new = dot(r,z);
if (r_dot_z_new < local_tolerance) { if (r_dot_z_new < tolerance_squared) {
if (verbose) if (verbose)
{ {
std::cout << "ConjugateGradient iterations " << k << std::endl; std::cout << "ConjugateGradient iterations " << k << std::endl;

View File

@@ -18,13 +18,13 @@
#include "btDeformableBodySolver.h" #include "btDeformableBodySolver.h"
#include "btSoftBodyInternals.h" #include "btSoftBodyInternals.h"
#include "LinearMath/btQuickprof.h" #include "LinearMath/btQuickprof.h"
static const int kMaxConjugateGradientIterations = 200;
btDeformableBodySolver::btDeformableBodySolver() btDeformableBodySolver::btDeformableBodySolver()
: m_numNodes(0) : m_numNodes(0)
, m_cg(200) , m_cg(kMaxConjugateGradientIterations)
, m_maxNewtonIterations(5) , m_maxNewtonIterations(5)
, m_newtonTolerance(1e-4) , m_newtonTolerance(1e-4)
, m_lineSearch(true) , m_lineSearch(false)
{ {
m_objective = new btDeformableBackwardEulerObjective(m_softBodies, m_backupVelocity); m_objective = new btDeformableBackwardEulerObjective(m_softBodies, m_backupVelocity);
} }
@@ -101,6 +101,7 @@ void btDeformableBodySolver::solveDeformableConstraints(btScalar solverdt)
m_residual[j].setZero(); m_residual[j].setZero();
} }
} }
updateVelocity();
} }
} }
@@ -298,8 +299,13 @@ void btDeformableBodySolver::setupDeformableSolve(bool implicit)
{ {
if (implicit) if (implicit)
{ {
if ((psb->m_nodes[j].m_v - m_backupVelocity[counter]).norm() < SIMD_EPSILON)
m_dv[counter] = psb->m_nodes[j].m_v - m_backupVelocity[counter];
else
m_dv[counter] = psb->m_nodes[j].m_v - psb->m_nodes[j].m_vn;
m_backupVelocity[counter] = psb->m_nodes[j].m_vn; m_backupVelocity[counter] = psb->m_nodes[j].m_vn;
} }
else
m_dv[counter] = psb->m_nodes[j].m_v - m_backupVelocity[counter]; m_dv[counter] = psb->m_nodes[j].m_v - m_backupVelocity[counter];
psb->m_nodes[j].m_v = m_backupVelocity[counter]; psb->m_nodes[j].m_v = m_backupVelocity[counter];
++counter; ++counter;