Skip to content

Commit

Permalink
Optionally set absolute convergence tolerance
Browse files Browse the repository at this point in the history
  • Loading branch information
Zachary Ferguson committed Nov 17, 2021
1 parent d65b0a4 commit 338599b
Show file tree
Hide file tree
Showing 5 changed files with 65 additions and 37 deletions.
49 changes: 32 additions & 17 deletions src/CollisionObject/MeshCO.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -783,10 +783,11 @@ void MeshCO<dim>::largestFeasibleStepSize_TightInclusion(
/*ms=*/std::min(TIGHT_INCLUSION_DIST_P * d_sqrt, TIGHT_INCLUSION_MIN_DIST),
toi,
tolerance,
stepSize,
/* max_itr=*/TIGHT_INCLUSION_MAX_ITER,
/*t_max=*/stepSize,
/*max_itr=*/TIGHT_INCLUSION_MAX_ITER,
output_tolerance,
/*CCD_TYPE=*/TIGHT_INCLUSION_MAX_ITER);
/*CCD_TYPE=*/TIGHT_INCLUSION_CCD_TYPE,
/*no_zero_toi=*/TIGHT_INCLUSION_NO_ZERO_TOI);

if (has_collision && toi < 1e-6) {
has_collision = inclusion_ccd::vertexFaceCCD_double(
Expand All @@ -805,7 +806,8 @@ void MeshCO<dim>::largestFeasibleStepSize_TightInclusion(
/*max_t=*/stepSize,
/* max_itr=*/-1,
output_tolerance,
/*CCD_TYPE=*/TIGHT_INCLUSION_MAX_ITER);
/*CCD_TYPE=*/TIGHT_INCLUSION_CCD_TYPE,
/*no_zero_toi=*/TIGHT_INCLUSION_NO_ZERO_TOI);
if (has_collision) {
toi *= 0.8;
}
Expand Down Expand Up @@ -851,7 +853,8 @@ void MeshCO<dim>::largestFeasibleStepSize_TightInclusion(
/*max_t=*/stepSize,
/* max_itr=*/TIGHT_INCLUSION_MAX_ITER,
output_tolerance,
/*CCD_TYPE=*/TIGHT_INCLUSION_MAX_ITER);
/*CCD_TYPE=*/TIGHT_INCLUSION_CCD_TYPE,
/*no_zero_toi=*/TIGHT_INCLUSION_NO_ZERO_TOI);

if (has_collision && toi < 1e-6) {
has_collision = inclusion_ccd::vertexFaceCCD_double(
Expand All @@ -870,7 +873,8 @@ void MeshCO<dim>::largestFeasibleStepSize_TightInclusion(
/*max_t=*/stepSize,
/* max_itr=*/-1,
output_tolerance,
/*CCD_TYPE=*/TIGHT_INCLUSION_MAX_ITER);
/*CCD_TYPE=*/TIGHT_INCLUSION_CCD_TYPE,
/*no_zero_toi=*/TIGHT_INCLUSION_NO_ZERO_TOI);
if (has_collision) {
toi *= 0.8;
}
Expand Down Expand Up @@ -917,7 +921,8 @@ void MeshCO<dim>::largestFeasibleStepSize_TightInclusion(
/*max_t=*/stepSize,
/* max_itr=*/TIGHT_INCLUSION_MAX_ITER,
output_tolerance,
/*CCD_TYPE=*/TIGHT_INCLUSION_MAX_ITER);
/*CCD_TYPE=*/TIGHT_INCLUSION_CCD_TYPE,
/*no_zero_toi=*/TIGHT_INCLUSION_NO_ZERO_TOI);

if (has_collision && toi < 1e-6) {
double output_tolerance;
Expand All @@ -937,7 +942,8 @@ void MeshCO<dim>::largestFeasibleStepSize_TightInclusion(
/*max_t=*/stepSize,
/* max_itr=*/-1,
output_tolerance,
/*CCD_TYPE=*/TIGHT_INCLUSION_MAX_ITER);
/*CCD_TYPE=*/TIGHT_INCLUSION_CCD_TYPE,
/*no_zero_toi=*/TIGHT_INCLUSION_NO_ZERO_TOI);

if (has_collision) {
toi *= 0.8;
Expand Down Expand Up @@ -1416,7 +1422,8 @@ void MeshCO<dim>::largestFeasibleStepSize_CCD_TightInclusion(
/*max_t=*/stepSize,
/* max_itr=*/TIGHT_INCLUSION_MAX_ITER,
output_tolerance,
/*CCD_TYPE=*/TIGHT_INCLUSION_MAX_ITER);
/*CCD_TYPE=*/TIGHT_INCLUSION_CCD_TYPE,
/*no_zero_toi=*/TIGHT_INCLUSION_NO_ZERO_TOI);

if (has_collision && toi < 1e-6) {
has_collision = inclusion_ccd::vertexFaceCCD_double(
Expand All @@ -1435,7 +1442,8 @@ void MeshCO<dim>::largestFeasibleStepSize_CCD_TightInclusion(
/*max_t=*/stepSize,
/* max_itr=*/-1,
output_tolerance,
/*CCD_TYPE=*/TIGHT_INCLUSION_MAX_ITER);
/*CCD_TYPE=*/TIGHT_INCLUSION_CCD_TYPE,
/*no_zero_toi=*/TIGHT_INCLUSION_NO_ZERO_TOI);
if (has_collision) {
toi *= 0.8;
}
Expand Down Expand Up @@ -1503,7 +1511,8 @@ void MeshCO<dim>::largestFeasibleStepSize_CCD_TightInclusion(
/*max_t=*/stepSize,
/* max_itr=*/TIGHT_INCLUSION_MAX_ITER,
output_tolerance,
/*CCD_TYPE=*/TIGHT_INCLUSION_MAX_ITER);
/*CCD_TYPE=*/TIGHT_INCLUSION_CCD_TYPE,
/*no_zero_toi=*/TIGHT_INCLUSION_NO_ZERO_TOI);

if (has_collision && toi < 1e-6) {
has_collision = inclusion_ccd::vertexFaceCCD_double(
Expand All @@ -1522,7 +1531,8 @@ void MeshCO<dim>::largestFeasibleStepSize_CCD_TightInclusion(
/*max_t=*/stepSize,
/* max_itr=*/-1,
output_tolerance,
/*CCD_TYPE=*/TIGHT_INCLUSION_MAX_ITER);
/*CCD_TYPE=*/TIGHT_INCLUSION_CCD_TYPE,
/*no_zero_toi=*/TIGHT_INCLUSION_NO_ZERO_TOI);
if (has_collision) {
toi *= 0.8;
}
Expand Down Expand Up @@ -1587,7 +1597,8 @@ void MeshCO<dim>::largestFeasibleStepSize_CCD_TightInclusion(
/*max_t=*/stepSize,
/* max_itr=*/TIGHT_INCLUSION_MAX_ITER,
output_tolerance,
/*CCD_TYPE=*/TIGHT_INCLUSION_MAX_ITER);
/*CCD_TYPE=*/TIGHT_INCLUSION_CCD_TYPE,
/*no_zero_toi=*/TIGHT_INCLUSION_NO_ZERO_TOI);

if (has_collision && toi < 1e-6) {
has_collision = inclusion_ccd::vertexFaceCCD_double(
Expand All @@ -1606,7 +1617,8 @@ void MeshCO<dim>::largestFeasibleStepSize_CCD_TightInclusion(
/*max_t=*/stepSize,
/* max_itr=*/-1,
output_tolerance,
/*CCD_TYPE=*/TIGHT_INCLUSION_MAX_ITER);
/*CCD_TYPE=*/TIGHT_INCLUSION_CCD_TYPE,
/*no_zero_toi=*/TIGHT_INCLUSION_NO_ZERO_TOI);
if (has_collision) {
toi *= 0.8;
}
Expand Down Expand Up @@ -2855,7 +2867,8 @@ bool MeshCO<dim>::updateActiveSet_QP(
/*max_t=*/1,
/* max_itr=*/TIGHT_INCLUSION_MAX_ITER,
output_tolerance,
/*CCD_TYPE=*/TIGHT_INCLUSION_MAX_ITER);
/*CCD_TYPE=*/TIGHT_INCLUSION_CCD_TYPE,
/*no_zero_toi=*/TIGHT_INCLUSION_NO_ZERO_TOI);
break;
#else
spdlog::error("Tight Inclusion CCD is disabled in CMake (CCD_WRAPPER_WITH_TIGHT_INCLUSION=OFF)!");
Expand Down Expand Up @@ -2941,7 +2954,8 @@ bool MeshCO<dim>::updateActiveSet_QP(
/*max_t=*/1,
/* max_itr=*/TIGHT_INCLUSION_MAX_ITER,
output_tolerance,
/*CCD_TYPE=*/TIGHT_INCLUSION_MAX_ITER);
/*CCD_TYPE=*/TIGHT_INCLUSION_CCD_TYPE,
/*no_zero_toi=*/TIGHT_INCLUSION_NO_ZERO_TOI);
break;
#else
spdlog::error("Tight Inclusion CCD is disabled in CMake (CCD_WRAPPER_WITH_TIGHT_INCLUSION=OFF)!");
Expand Down Expand Up @@ -3062,7 +3076,8 @@ bool MeshCO<dim>::updateActiveSet_QP(
/*max_t=*/1,
/* max_itr=*/TIGHT_INCLUSION_MAX_ITER,
output_tolerance,
/*CCD_TYPE=*/TIGHT_INCLUSION_MAX_ITER);
/*CCD_TYPE=*/TIGHT_INCLUSION_CCD_TYPE,
/*no_zero_toi=*/TIGHT_INCLUSION_NO_ZERO_TOI);
break;
#else
spdlog::error("Tight Inclusion CCD is disabled in CMake (CCD_WRAPPER_WITH_TIGHT_INCLUSION=OFF)!");
Expand Down
30 changes: 20 additions & 10 deletions src/CollisionObject/SelfCollisionHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -749,7 +749,8 @@ void SelfCollisionHandler<dim>::largestFeasibleStepSize_TightInclusion(
/*max_t=*/stepSize,
/* max_itr=*/TIGHT_INCLUSION_MAX_ITER,
output_tolerance,
/*CCD_TYPE=*/TIGHT_INCLUSION_CCD_TYPE);
/*CCD_TYPE=*/TIGHT_INCLUSION_CCD_TYPE,
/*no_zero_toi=*/TIGHT_INCLUSION_NO_ZERO_TOI);

if (has_collision && toi < 1e-6) {
has_collision = inclusion_ccd::edgeEdgeCCD_double(
Expand All @@ -768,7 +769,8 @@ void SelfCollisionHandler<dim>::largestFeasibleStepSize_TightInclusion(
/*max_t=*/stepSize,
/* max_itr=*/TIGHT_INCLUSION_MAX_ITER,
output_tolerance,
/*CCD_TYPE=*/TIGHT_INCLUSION_CCD_TYPE);
/*CCD_TYPE=*/TIGHT_INCLUSION_CCD_TYPE,
/*no_zero_toi=*/TIGHT_INCLUSION_NO_ZERO_TOI);
if (has_collision) {
toi *= 0.8;
}
Expand Down Expand Up @@ -812,7 +814,8 @@ void SelfCollisionHandler<dim>::largestFeasibleStepSize_TightInclusion(
/*max_t=*/stepSize,
/* max_itr=*/TIGHT_INCLUSION_MAX_ITER,
output_tolerance,
/*CCD_TYPE=*/TIGHT_INCLUSION_CCD_TYPE);
/*CCD_TYPE=*/TIGHT_INCLUSION_CCD_TYPE,
/*no_zero_toi=*/TIGHT_INCLUSION_NO_ZERO_TOI);

if (has_collision && toi < 1e-6) {
has_collision = inclusion_ccd::vertexFaceCCD_double(
Expand All @@ -831,7 +834,8 @@ void SelfCollisionHandler<dim>::largestFeasibleStepSize_TightInclusion(
/*max_t=*/stepSize,
/* max_itr=*/TIGHT_INCLUSION_MAX_ITER,
output_tolerance,
/*CCD_TYPE=*/TIGHT_INCLUSION_CCD_TYPE);
/*CCD_TYPE=*/TIGHT_INCLUSION_CCD_TYPE,
/*no_zero_toi=*/TIGHT_INCLUSION_NO_ZERO_TOI);
if (has_collision) {
toi *= 0.8;
}
Expand Down Expand Up @@ -1427,7 +1431,8 @@ void SelfCollisionHandler<dim>::largestFeasibleStepSize_CCD_TightInclusion(
/*max_t=*/stepSize,
/* max_itr=*/TIGHT_INCLUSION_MAX_ITER,
output_tolerance,
/*CCD_TYPE=*/TIGHT_INCLUSION_CCD_TYPE);
/*CCD_TYPE=*/TIGHT_INCLUSION_CCD_TYPE,
/*no_zero_toi=*/TIGHT_INCLUSION_NO_ZERO_TOI);

if (has_collision && toi < 1e-6) {
has_collision = inclusion_ccd::vertexFaceCCD_double(
Expand All @@ -1446,7 +1451,8 @@ void SelfCollisionHandler<dim>::largestFeasibleStepSize_CCD_TightInclusion(
/*max_t=*/stepSize,
/* max_itr=*/TIGHT_INCLUSION_MAX_ITER,
output_tolerance,
/*CCD_TYPE=*/TIGHT_INCLUSION_CCD_TYPE);
/*CCD_TYPE=*/TIGHT_INCLUSION_CCD_TYPE,
/*no_zero_toi=*/TIGHT_INCLUSION_NO_ZERO_TOI);
if (has_collision) {
toi *= 0.8;
}
Expand Down Expand Up @@ -1544,7 +1550,8 @@ void SelfCollisionHandler<dim>::largestFeasibleStepSize_CCD_TightInclusion(
/*max_t=*/stepSize,
/* max_itr=*/TIGHT_INCLUSION_MAX_ITER,
output_tolerance,
/*CCD_TYPE=*/TIGHT_INCLUSION_CCD_TYPE);
/*CCD_TYPE=*/TIGHT_INCLUSION_CCD_TYPE,
/*no_zero_toi=*/TIGHT_INCLUSION_NO_ZERO_TOI);

if (has_collision && toi < 1e-6) {
has_collision = inclusion_ccd::edgeEdgeCCD_double(
Expand All @@ -1563,7 +1570,8 @@ void SelfCollisionHandler<dim>::largestFeasibleStepSize_CCD_TightInclusion(
/*max_t=*/stepSize,
/* max_itr=*/TIGHT_INCLUSION_MAX_ITER,
output_tolerance,
/*CCD_TYPE=*/TIGHT_INCLUSION_CCD_TYPE);
/*CCD_TYPE=*/TIGHT_INCLUSION_CCD_TYPE,
/*no_zero_toi=*/TIGHT_INCLUSION_NO_ZERO_TOI);
if (has_collision) {
toi *= 0.8;
}
Expand Down Expand Up @@ -1954,7 +1962,8 @@ bool SelfCollisionHandler<dim>::updateActiveSet_QP(
/*max_t=*/1,
/* max_itr=*/TIGHT_INCLUSION_MAX_ITER,
output_tolerance,
/*CCD_TYPE=*/TIGHT_INCLUSION_CCD_TYPE);
/*CCD_TYPE=*/TIGHT_INCLUSION_CCD_TYPE,
/*no_zero_toi=*/TIGHT_INCLUSION_NO_ZERO_TOI);
break;
#else
spdlog::error("Tight Inclusion CCD is disabled in CMake (CCD_WRAPPER_WITH_TIGHT_INCLUSION=OFF)!");
Expand Down Expand Up @@ -2054,7 +2063,8 @@ bool SelfCollisionHandler<dim>::updateActiveSet_QP(
/*max_t=*/1,
/* max_itr=*/TIGHT_INCLUSION_MAX_ITER,
output_tolerance,
/*CCD_TYPE=*/TIGHT_INCLUSION_CCD_TYPE);
/*CCD_TYPE=*/TIGHT_INCLUSION_CCD_TYPE,
/*no_zero_toi=*/TIGHT_INCLUSION_NO_ZERO_TOI);
break;
#else
spdlog::error("Tight Inclusion CCD is disabled in CMake (CCD_WRAPPER_WITH_TIGHT_INCLUSION=OFF)!");
Expand Down
4 changes: 2 additions & 2 deletions src/Config.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
#include "CollisionObject.h"
#include "CollisionConstraints.hpp"
#include "LinSysSolver.hpp"
#include <ccd.hpp>
#include "CCDUtils.hpp"

#include <iostream>
#include <map>
Expand Down Expand Up @@ -142,7 +142,7 @@ class Config {
// like initial velocity, position, etc

ccd::CCDMethod ccdMethod = ccd::CCDMethod::FLOATING_POINT_ROOT_FINDER;
double ccdTolerance = 1e-6;
double ccdTolerance = DEFAULT_CCD_TOLERANCE;

/// @brief Constraint type for SQP method of handling collisions.
CollisionConstraintType constraintType = CollisionConstraintType::VOLUME;
Expand Down
5 changes: 3 additions & 2 deletions src/TimeStepper/Optimizer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2940,13 +2940,14 @@ void Optimizer<dim>::stepForward(const Eigen::MatrixXd& dataV0,
template <int dim>
void Optimizer<dim>::updateTargetGRes(void)
{
targetGRes = std::sqrt(relGL2Tol * bboxDiagSize2 * dtSq);
targetGRes = std::sqrt(
relGL2Tol * (animConfig.useAbsParameters ? 1 : bboxDiagSize2 * dtSq));
}

template <int dim>
void Optimizer<dim>::getFaceFieldForVis(Eigen::VectorXd& field)
{
// field = Eigen::VectorXd::Zero(result.F.rows());
// field = Eigen::VectorXd::Zero(result.F.rows());
field = result.u;
}

Expand Down
14 changes: 8 additions & 6 deletions src/Utils/CCDUtils.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,17 @@
#include <CollisionObject/CollisionObject.h>
#include <Mesh.hpp>

namespace IPC {

static constexpr double DEFAULT_CCD_TOLERANCE = 1e-6;
#ifdef IPC_WITH_TIGHT_INCLUSION
#define TIGHT_INCLUSION_MAX_ITER 1e6
#define TIGHT_INCLUSION_CCD_TYPE 1
#define TIGHT_INCLUSION_DIST_P 0.2
#define TIGHT_INCLUSION_MIN_DIST tolerance
static constexpr int TIGHT_INCLUSION_MAX_ITER = 1e6;
static constexpr int TIGHT_INCLUSION_CCD_TYPE = 1;
static constexpr bool TIGHT_INCLUSION_NO_ZERO_TOI = true;
static constexpr double TIGHT_INCLUSION_DIST_P = 0.2;
static constexpr double TIGHT_INCLUSION_MIN_DIST = DEFAULT_CCD_TOLERANCE;
#endif

namespace IPC {

#ifdef IPC_WITH_TIGHT_INCLUSION
extern std::array<double, 3> tight_inclusion_vf_err, tight_inclusion_ee_err;
#endif
Expand Down

0 comments on commit 338599b

Please sign in to comment.