diff --git a/src/args.rs b/src/args.rs index 51251ff..3bf70fe 100644 --- a/src/args.rs +++ b/src/args.rs @@ -49,7 +49,7 @@ pub struct Args { #[clap(long, default_value_t = 0.025)] pub strain_limit_eps: f32, - #[clap(long, default_value_t = 1024)] + #[clap(long, default_value_t = 64)] pub binary_search_max_iter: u32, #[clap(long)] @@ -76,9 +76,6 @@ pub struct Args { #[clap(long, default_value_t = 0.01)] pub ccd_reduction: f32, - #[clap(long, default_value_t = 0.0025)] - pub ccd_reduction_eps: f32, - #[clap(long, default_value_t = 1e-2)] pub eiganalysis_eps: f32, diff --git a/src/builder.rs b/src/builder.rs index c5896c3..e7e3096 100644 --- a/src/builder.rs +++ b/src/builder.rs @@ -352,7 +352,6 @@ pub fn make_param(args: &Args) -> data::ParamSet { line_search_max_t: args.line_search_max_t, ccd_tol: args.contact_ghat, ccd_reduction: args.ccd_reduction, - ccd_reduction_eps: args.ccd_reduction_eps, ccd_max_iters: args.ccd_max_iters, eiganalysis_eps: args.eiganalysis_eps, friction: args.friction, diff --git a/src/cpp/common.hpp b/src/cpp/common.hpp index 69a3da2..9fbde46 100644 --- a/src/cpp/common.hpp +++ b/src/cpp/common.hpp @@ -25,9 +25,9 @@ #define __host__ #endif -#define EPSILON 1e-8f -#define FLT_MAX 1e8f -#define FLT_MIN -1e8f +#define EPSILON 1.0e-8f +#define FLT_MAX 1.0e8f +#define FLT_MIN -1.0e8f #define DT_MIN 1e-5f #define PI 3.14159265358979323846f #define DEBUG_MODE 0 diff --git a/src/cpp/contact/accd.hpp b/src/cpp/contact/accd.hpp index a1d2dbd..2842e14 100644 --- a/src/cpp/contact/accd.hpp +++ b/src/cpp/contact/accd.hpp @@ -23,9 +23,8 @@ __device__ float ccd_helper(const Mat3x4f &x0, const Mat3x4f &dx, float u_max, const ParamSet ¶m) { float toi = 0.0f; float max_t = param.line_search_max_t; - float gap = sqrtf(square_dist_func(x0)) - offset; - float eps = param.ccd_reduction_eps * gap; - float target = param.ccd_reduction * gap + offset; + float eps = param.ccd_reduction * (sqrtf(square_dist_func(x0)) - offset); + float target = 2.0f * eps + offset; float eps_sqr = eps * eps; float inv_u_max = 1.0f / u_max; for (unsigned k = 0; k < param.ccd_max_iters; ++k) { diff --git a/src/cpp/data.hpp b/src/cpp/data.hpp index cfd00ae..03a0733 100644 --- a/src/cpp/data.hpp +++ b/src/cpp/data.hpp @@ -230,7 +230,6 @@ struct ParamSet { float line_search_max_t; float ccd_tol; float ccd_reduction; - float ccd_reduction_eps; unsigned ccd_max_iters; float eiganalysis_eps; float friction; diff --git a/src/cpp/strainlimiting/strainlimiting.cu b/src/cpp/strainlimiting/strainlimiting.cu index eeeeeb4..2b7e26a 100644 --- a/src/cpp/strainlimiting/strainlimiting.cu +++ b/src/cpp/strainlimiting/strainlimiting.cu @@ -10,7 +10,6 @@ #include "../utility/dispatcher.hpp" #include "../utility/utility.hpp" #include "strainlimiting.hpp" -#include namespace strainlimiting { @@ -109,31 +108,28 @@ float line_search(const DataSet &data, const Kinematic &kinematic, const Mat3x2f F1 = utility::compute_deformation_grad(x1, inv_rest2x2[i]); const Mat3x2f dF = F1 - F0; - float gap = max_sigma - utility::svd3x2(F0).S.maxCoeff(); - float target = max_sigma - param.ccd_reduction * gap; - if (utility::svd3x2(F0 + t * dF).S.maxCoeff() > target) { + if (utility::svd3x2(F0 + t * dF).S.maxCoeff() >= max_sigma) { + float tol = param.ccd_reduction * + (max_sigma - utility::svd3x2(F0).S.maxCoeff()); + float target = max_sigma - 2.0f * tol; float upper_t = t; float lower_t = 0.0f; - unsigned iter(0); - while (true) { + for (unsigned k = 0; k < param.binary_search_max_iter; ++k) { t = 0.5f * (upper_t + lower_t); Svd3x2 svd = utility::svd3x2(F0 + t * dF); float diff = svd.S.maxCoeff() - target; - if (diff < 0.0f) { + if (fabs(diff) < tol) { + break; + } else if (diff < 0.0f) { lower_t = t; } else { upper_t = t; } - if (lower_t > 0.0f) { - if (upper_t - lower_t < param.ccd_reduction * lower_t) { - break; - } - } - assert(t > std::numeric_limits::epsilon()); } - t = lower_t; + while (utility::svd3x2(F0 + t * dF).S.maxCoeff() >= target) { + t *= param.dt_decrease_factor; + } } - assert(utility::svd3x2(F0 + t * dF).S.maxCoeff() <= target); } toi[i] = t; } DISPATCH_END; diff --git a/src/data.rs b/src/data.rs index 1a49c61..fb81583 100644 --- a/src/data.rs +++ b/src/data.rs @@ -304,7 +304,6 @@ pub struct ParamSet { pub line_search_max_t: f32, pub ccd_tol: f32, pub ccd_reduction: f32, - pub ccd_reduction_eps: f32, pub ccd_max_iters: u32, pub eiganalysis_eps: f32, pub friction: f32,