remove CG printf outputs

This commit is contained in:
Xuchen Han
2019-08-19 17:28:22 -07:00
parent 5cdfbf3313
commit ef65d6422b

View File

@@ -35,7 +35,7 @@ public:
virtual ~btConjugateGradient(){} virtual ~btConjugateGradient(){}
// 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, bool verbose = false)
{ {
BT_PROFILE("CGSolve"); BT_PROFILE("CGSolve");
btAssert(x.size() == b.size()); btAssert(x.size() == b.size());
@@ -49,8 +49,11 @@ public:
A.project(z); A.project(z);
btScalar r_dot_z = dot(z,r); btScalar r_dot_z = dot(z,r);
if (r_dot_z < tolerance) { if (r_dot_z < tolerance) {
if (verbose)
{
std::cout << "Iteration = 0" << std::endl; std::cout << "Iteration = 0" << std::endl;
std::cout << "Two norm of the residual = " << r_dot_z << std::endl; std::cout << "Two norm of the residual = " << r_dot_z << std::endl;
}
return 0; return 0;
} }
p = z; p = z;
@@ -70,13 +73,19 @@ public:
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 < tolerance) { if (r_dot_z_new < tolerance) {
if (verbose)
{
std::cout << "ConjugateGradient iterations " << k << std::endl; std::cout << "ConjugateGradient iterations " << k << std::endl;
}
return k; return k;
} }
btScalar beta = r_dot_z_new/ r_dot_z; btScalar beta = r_dot_z_new/ r_dot_z;
p = multAndAdd(beta, p, z); p = multAndAdd(beta, p, z);
} }
if (verbose)
{
std::cout << "ConjugateGradient max iterations reached " << max_iterations << std::endl; std::cout << "ConjugateGradient max iterations reached " << max_iterations << std::endl;
}
return max_iterations; return max_iterations;
} }