Skip to content

Commit 1af750b

Browse files
committed
minor
1 parent 981217f commit 1af750b

2 files changed

Lines changed: 23 additions & 23 deletions

File tree

friction/FrictionEnergy.py

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -3,23 +3,23 @@
33

44
epsv = 1e-3
55

6-
def f0(vhatnorm, epsv, hhat):
7-
if vhatnorm >= epsv:
8-
return vhatnorm * hhat
6+
def f0(vbarnorm, epsv, hhat):
7+
if vbarnorm >= epsv:
8+
return vbarnorm * hhat
99
else:
10-
vhatnormhhat = vhatnorm * hhat
10+
vbarnormhhat = vbarnorm * hhat
1111
epsvhhat = epsv * hhat
12-
return vhatnormhhat * vhatnormhhat * (-vhatnormhhat / 3.0 + epsvhhat) / (epsvhhat * epsvhhat) + epsvhhat / 3.0
12+
return vbarnormhhat * vbarnormhhat * (-vbarnormhhat / 3.0 + epsvhhat) / (epsvhhat * epsvhhat) + epsvhhat / 3.0
1313

14-
def f1_div_vhatnorm(vhatnorm, epsv):
15-
if vhatnorm >= epsv:
16-
return 1.0 / vhatnorm
14+
def f1_div_vbarnorm(vbarnorm, epsv):
15+
if vbarnorm >= epsv:
16+
return 1.0 / vbarnorm
1717
else:
18-
return (-vhatnorm + 2.0 * epsv) / (epsv * epsv)
18+
return (-vbarnorm + 2.0 * epsv) / (epsv * epsv)
1919

20-
def f_hess_term(vhatnorm, epsv):
21-
if vhatnorm >= epsv:
22-
return -1.0 / (vhatnorm * vhatnorm)
20+
def f_hess_term(vbarnorm, epsv):
21+
if vbarnorm >= epsv:
22+
return -1.0 / (vbarnorm * vbarnorm)
2323
else:
2424
return -1.0 / (epsv * epsv)
2525

@@ -28,29 +28,29 @@ def val(v, mu_lambda, hhat, n):
2828
T = np.identity(2) - np.outer(n, n) # tangent of slope is constant
2929
for i in range(0, len(v)):
3030
if mu_lambda[i] > 0:
31-
vhat = np.transpose(T).dot(v[i])
32-
sum += mu_lambda[i] * f0(np.linalg.norm(vhat), epsv, hhat)
31+
vbar = np.transpose(T).dot(v[i])
32+
sum += mu_lambda[i] * f0(np.linalg.norm(vbar), epsv, hhat)
3333
return sum
3434

3535
def grad(v, mu_lambda, hhat, n):
3636
g = np.array([[0.0, 0.0]] * len(v))
3737
T = np.identity(2) - np.outer(n, n) # tangent of slope is constant
3838
for i in range(0, len(v)):
3939
if mu_lambda[i] > 0:
40-
vhat = np.transpose(T).dot(v[i])
41-
g[i] = mu_lambda[i] * f1_div_vhatnorm(np.linalg.norm(vhat), epsv) * T.dot(vhat)
40+
vbar = np.transpose(T).dot(v[i])
41+
g[i] = mu_lambda[i] * f1_div_vbarnorm(np.linalg.norm(vbar), epsv) * T.dot(vbar)
4242
return g
4343

4444
def hess(v, mu_lambda, hhat, n):
4545
IJV = [[0] * 0, [0] * 0, np.array([0.0] * 0)]
4646
T = np.identity(2) - np.outer(n, n) # tangent of slope is constant
4747
for i in range(0, len(v)):
4848
if mu_lambda[i] > 0:
49-
vhat = np.transpose(T).dot(v[i])
50-
vhatnorm = np.linalg.norm(vhat)
51-
inner_term = f1_div_vhatnorm(vhatnorm, epsv) * np.identity(2)
52-
if vhatnorm != 0:
53-
inner_term += f_hess_term(vhatnorm, epsv) / vhatnorm * np.outer(vhat, vhat)
49+
vbar = np.transpose(T).dot(v[i])
50+
vbarnorm = np.linalg.norm(vbar)
51+
inner_term = f1_div_vbarnorm(vbarnorm, epsv) * np.identity(2)
52+
if vbarnorm != 0:
53+
inner_term += f_hess_term(vbarnorm, epsv) / vbarnorm * np.outer(vbar, vbar)
5454
local_hess = mu_lambda[i] * T.dot(utils.make_PD(inner_term)).dot(np.transpose(T)) / hhat
5555
for c in range(0, 2):
5656
for r in range(0, 2):

friction/simulator.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
h = 0.01 # time step size in s
1616
DBC = [] # no nodes need to be fixed
1717
ground_n = np.array([0.1, 1.0]) # normal of the slope
18+
ground_n /= np.linalg.norm(ground_n) # normalize ground normal vector just in case
1819
ground_o = np.array([0.0, -1.0]) # a point on the slope
1920
mu = 0.11 # friction coefficient of the slope
2021

@@ -33,7 +34,6 @@
3334
for i in DBC:
3435
is_DBC[i] = True
3536
contact_area = [side_len / n_seg] * len(x) # perimeter split to each node
36-
ground_n /= np.linalg.norm(ground_n) # normalize ground normal vector just in case
3737

3838
# simulation with visualization
3939
resolution = np.array([900, 900])
@@ -56,7 +56,7 @@ def screen_projection(x):
5656
# fill the background and draw the square
5757
screen.fill((255, 255, 255))
5858
pygame.draw.aaline(screen, (0, 0, 255), screen_projection([ground_o[0] - 3.0 * ground_n[1], ground_o[1] + 3.0 * ground_n[0]]),
59-
screen_projection([ground_o[0] + 3.0 * ground_n[1], ground_o[1] - 3.0 * ground_n[0]])) # ground
59+
screen_projection([ground_o[0] + 3.0 * ground_n[1], ground_o[1] - 3.0 * ground_n[0]])) # slope
6060
for eI in e:
6161
pygame.draw.aaline(screen, (0, 0, 255), screen_projection(x[eI[0]]), screen_projection(x[eI[1]]))
6262
for xI in x:

0 commit comments

Comments
 (0)