Skip to content

Commit

Permalink
update line search
Browse files Browse the repository at this point in the history
  • Loading branch information
ryichando committed Jan 6, 2025
1 parent 3b21a25 commit 025a430
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 35 deletions.
4 changes: 3 additions & 1 deletion .github/workflows/vast/provision.sh
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,8 @@ while true; do

if [[ -z "$INSTANCE_ID" ]]; then
echo "No valid instance found"
exit 1
sleep $RETRY_INTERVAL
continue
fi

# create an instance
Expand All @@ -144,6 +145,7 @@ while true; do
else
echo "success: $success"
echo "instance creation failed."
sleep $RETRY_INTERVAL
continue
fi

Expand Down
2 changes: 1 addition & 1 deletion src/cpp/contact/accd.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ __device__ float ccd_helper(const Mat3x4f &x0, const Mat3x4f &dx, float u_max,
float toi = 0.0f;
float max_t = param.line_search_max_t;
float eps = param.ccd_reduction * (sqrtf(square_dist_func(x0)) - offset);
float target = 2.0f * eps + offset;
float target = 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) {
Expand Down
17 changes: 7 additions & 10 deletions src/cpp/contact/contact.cu
Original file line number Diff line number Diff line change
Expand Up @@ -1474,8 +1474,7 @@ vertex_constraint_line_search(const DataSet &data, const Kinematic &kinematic,
float r0 = (x0 - position).norm();
float r1 = (x1 - position).norm();
assert(r0 < param.constraint_ghat);
float r = param.constraint_ghat -
param.ccd_reduction * (param.constraint_ghat - r0);
float r = param.constraint_ghat;
if (r1 > r) {
// (1.0f - t) r0 + t r1 = r
// r0 - t r0 + t r1 = r
Expand Down Expand Up @@ -1510,7 +1509,6 @@ vertex_constraint_line_search(const DataSet &data, const Kinematic &kinematic,
} else {
assert(r0 > r);
}
r += param.ccd_reduction * (r0 - r);
bool intersected = (r0 - r) * (r1 - r) <= 0.0f;
if (intersected) {
// (1.0f - t) r0 + t r1 = r
Expand All @@ -1532,13 +1530,12 @@ vertex_constraint_line_search(const DataSet &data, const Kinematic &kinematic,
float h0 = up.dot(x0 - ground);
float h1 = up.dot(x1 - ground);
assert(h0 >= 0.0f);
float h = param.ccd_reduction * h0;
if (h1 < h) {
// (1.0f - t) h0 + t h1 = h
// h0 - t h0 + t h1 = h
// t (h1 - h0) = h - h0
// t = (h - h0) / (h1 - h0)
float t = (h - h0) / (h1 - h0);
if (h1 < 0.0f) {
// (1.0f - t) h0 + t h1 = 0
// h0 - t h0 + t h1 = 0
// t (h1 - h0) = - h0
// t = - h0 / (h1 - h0)
float t = -h0 / (h1 - h0);
toi_vert[i] =
fminf(toi_vert[i], param.line_search_max_t * t);
}
Expand Down
58 changes: 35 additions & 23 deletions src/cpp/main/main.cu
Original file line number Diff line number Diff line change
Expand Up @@ -574,20 +574,39 @@ StepResult advance() {
logging.push("line search");
contact::update_aabb(host_data, data, tmp_eval_x, eval_x,
tmp::kinematic.vertex, prm);
float SL_toi = 1.0f;
float toi =
contact::line_search(data, kinematic, tmp_eval_x, eval_x, prm);
if (strain_limit_sum && shell_face_count > 0) {
toi = fminf(toi, strainlimiting::line_search(data, kinematic,
eval_x, tmp_eval_x,
tmp_scalar, prm));
SL_toi = strainlimiting::line_search(
data, kinematic, eval_x, tmp_eval_x, tmp_scalar, prm);
toi = fminf(toi, SL_toi);
// Name: Strain Limiting Time of Impact
// Format: list[(vid_time,float)]
// Description:
// Time of impact (TOI) per Newton's step, encoding the
// maximal feasible step size without exceeding
// strain limits.
logging.mark("SL_toi", SL_toi);
}
logging.pop();

// Name: Time of Impact
// Format: list[(vid_time,float)]
// Description:
// Time of impact (TOI) per Newton's step, encoding the
// maximal feasible step size without collision or exceeding strain
// limits.
logging.mark("toi", toi);

if (toi <= std::numeric_limits<float>::epsilon()) {
if (param->enable_retry && dt > DT_MIN) {
retry = true;
} else {
logging.message("### ccd failed (toi: %.2e)", toi);
if (SL_toi < 1.0f) {
logging.message("strain limiting toi: %.2e", SL_toi);
}
result.ccd_success = false;
}
break;
Expand All @@ -597,14 +616,6 @@ StepResult advance() {
toi_advanced += fmaxf(0.0f, 1.0f - toi_advanced) * toi;
}

// Name: Time of Impact
// Format: list[(vid_time,float)]
// Description:
// Time of impact (TOI) per Newton's step, encoding the
// maximal feasible step size without collision or exceeding strain
// limits.
logging.mark("toi", toi);

DISPATCH_START(vertex_count)
[eval_x, tmp_eval_x, data, toi] __device__(unsigned i) mutable {
eval_x[i] = (1.0f - toi) * tmp_eval_x[i] + toi * eval_x[i];
Expand All @@ -625,19 +636,20 @@ StepResult advance() {
logging.message("**** retry requested. dt: %.2e", dt);
retry_count++;
} else {
// Name: Time to Check Intersection
// Format: list[(vid_time,ms)]
// Map: runtime_intersection_check
// Description:
// At the end of step, an explicit intersection check is performed.
// This number records the consumed time in milliseconds.
logging.push("check intersection");
if (!contact::check_intersection(data, kinematic, eval_x)) {
logging.message("### intersection detected");
result.intersection_free = false;
}
logging.pop();
if (result.success()) {
// Name: Time to Check Intersection
// Format: list[(vid_time,ms)]
// Map: runtime_intersection_check
// Description:
// At the end of step, an explicit intersection check is
// performed. This number records the consumed time in
// milliseconds.
logging.push("check intersection");
if (!contact::check_intersection(data, kinematic, eval_x)) {
logging.message("### intersection detected");
result.intersection_free = false;
}
logging.pop();
// Name: Advanced Fractional Step Size
// Format: list[(vid_time,float)]
// Description:
Expand Down

0 comments on commit 025a430

Please sign in to comment.