Skip to content

Commit

Permalink
added anchors
Browse files Browse the repository at this point in the history
  • Loading branch information
liminchen committed May 14, 2024
1 parent e48740d commit d74d923
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 1 deletion.
2 changes: 2 additions & 0 deletions 8_self_friction/BarrierEnergy.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ def compute_mu_lambda(x, n, o, bp, be, contact_area, mu):
if d < dhat:
s = d / dhat
mu_lambda[i] = mu * -contact_area[i] * dhat * (kappa / 2 * (math.log(s) / dhat + (s - 1) / d))
# ANCHOR: fric_precomp
# self-contact
mu_lambda_self = []
dhat_sqr = dhat * dhat
Expand All @@ -161,4 +162,5 @@ def compute_mu_lambda(x, n, o, bp, be, contact_area, mu):
mu_lam = mu * -0.5 * contact_area[xI] * dhat * (kappa / 8 * (math.log(s) / dhat_sqr + (s - 1) / d_sqr)) * 2 * math.sqrt(d_sqr)
[n, r] = PE.tangent(x[xI], x[eI[0]], x[eI[1]]) # normal and closest point parameterization on the edge
mu_lambda_self.append([xI, eI[0], eI[1], mu_lam, n, r])
# ANCHOR_END: fric_precomp
return [mu_lambda, mu_lambda_self]
6 changes: 6 additions & 0 deletions 8_self_friction/FrictionEnergy.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,15 @@ def val(v, mu_lambda, mu_lambda_self, hhat, n):
if mu_lambda[i] > 0:
vbar = np.transpose(T).dot(v[i])
sum += mu_lambda[i] * f0(np.linalg.norm(vbar), epsv, hhat)
# ANCHOR: val
# self-contact:
for i in range(0, len(mu_lambda_self)):
[xI, eI0, eI1, mu_lam, n, r] = mu_lambda_self[i]
T = np.identity(2) - np.outer(n, n)
rel_v = v[xI] - ((1 - r) * v[eI0] + r * v[eI1])
vbar = np.transpose(T).dot(rel_v)
sum += mu_lam * f0(np.linalg.norm(vbar), epsv, hhat)
# ANCHOR_END: val
return sum

def grad(v, mu_lambda, mu_lambda_self, hhat, n):
Expand All @@ -48,6 +50,7 @@ def grad(v, mu_lambda, mu_lambda_self, hhat, n):
if mu_lambda[i] > 0:
vbar = np.transpose(T).dot(v[i])
g[i] = mu_lambda[i] * f1_div_vbarnorm(np.linalg.norm(vbar), epsv) * T.dot(vbar)
# ANCHOR: grad
# self-contact:
for i in range(0, len(mu_lambda_self)):
[xI, eI0, eI1, mu_lam, n, r] = mu_lambda_self[i]
Expand All @@ -58,6 +61,7 @@ def grad(v, mu_lambda, mu_lambda_self, hhat, n):
g[xI] += g_rel_v
g[eI0] += g_rel_v * -(1 - r)
g[eI1] += g_rel_v * -r
# ANCHOR_END: grad
return g

def hess(v, mu_lambda, mu_lambda_self, hhat, n):
Expand All @@ -77,6 +81,7 @@ def hess(v, mu_lambda, mu_lambda_self, hhat, n):
IJV[0].append(i * 2 + r)
IJV[1].append(i * 2 + c)
IJV[2] = np.append(IJV[2], local_hess[r, c])
# ANCHOR: hess
# self-contact:
for i in range(0, len(mu_lambda_self)):
[xI, eI0, eI1, mu_lam, n, r] = mu_lambda_self[i]
Expand All @@ -97,4 +102,5 @@ def hess(v, mu_lambda, mu_lambda_self, hhat, n):
IJV[0].append(index[nI] * 2 + r)
IJV[1].append(index[nJ] * 2 + c)
IJV[2] = np.append(IJV[2], d_rel_v_dv[nI] * d_rel_v_dv[nJ] * hess_rel_v[r, c])
# ANCHOR_END: hess
return IJV
4 changes: 3 additions & 1 deletion 8_self_friction/distance/PointEdgeDistance.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ def hess(p, e0, e1):
else: # point(p)-line(e0e1) expression
return PL.hess(p, e0, e1)

# ANCHOR: tangent
# compute normal and the parameterization of the closest point on the edge
def tangent(p, e0, e1):
e = e1 - e0
Expand All @@ -57,4 +58,5 @@ def tangent(p, e0, e1):
n = p - e1
else: # point(p)-line(e0e1) expression
n = p - ((1 - ratio) * e0 + ratio * e1)
return [n / np.linalg.norm(n), ratio]
return [n / np.linalg.norm(n), ratio]
# ANCHOR_END: tangent

0 comments on commit d74d923

Please sign in to comment.