Skip to content

Commit 814874e

Browse files
committed
add anchors
1 parent 4def8da commit 814874e

4 files changed

Lines changed: 20 additions & 2 deletions

File tree

4_friction/BarrierEnergy.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
# ANCHOR: slope_barrier
12
import math
23
import numpy as np
34

@@ -34,20 +35,25 @@ def hess(x, n, o, contact_area):
3435
IJV[1].append(i * 2 + c)
3536
IJV[2] = np.append(IJV[2], local_hess[r, c])
3637
return IJV
38+
# ANCHOR_END: slope_barrier
3739

40+
# ANCHOR: init_step_size
3841
def init_step_size(x, n, o, p):
3942
alpha = 1
4043
for i in range(0, len(x)):
4144
p_n = p[i].dot(n)
4245
if p_n < 0:
4346
alpha = min(alpha, 0.9 * n.dot(x[i] - o) / -p_n)
4447
return alpha
48+
# ANCHOR_END: init_step_size
4549

50+
# ANCHOR: compute_mu_lambda
4651
def compute_mu_lambda(x, n, o, contact_area, mu):
4752
mu_lambda = np.array([0.0] * len(x))
4853
for i in range(0, len(x)):
4954
d = n.dot(x[i] - o)
5055
if d < dhat:
5156
s = d / dhat
5257
mu_lambda[i] = mu * -contact_area[i] * dhat * (kappa / 2 * (math.log(s) / dhat + (s - 1) / d))
53-
return mu_lambda
58+
return mu_lambda
59+
# ANCHOR_END: compute_mu_lambda

4_friction/FrictionEnergy.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
# ANCHOR: f_terms
12
import numpy as np
23
import utils
34

@@ -22,7 +23,9 @@ def f_hess_term(vbarnorm, epsv):
2223
return -1.0 / (vbarnorm * vbarnorm)
2324
else:
2425
return -1.0 / (epsv * epsv)
26+
# ANCHOR_END: f_terms
2527

28+
# ANCHOR: val_grad_hess
2629
def val(v, mu_lambda, hhat, n):
2730
sum = 0.0
2831
T = np.identity(2) - np.outer(n, n) # tangent of slope is constant
@@ -57,4 +60,5 @@ def hess(v, mu_lambda, hhat, n):
5760
IJV[0].append(i * 2 + r)
5861
IJV[1].append(i * 2 + c)
5962
IJV[2] = np.append(IJV[2], local_hess[r, c])
60-
return IJV
63+
return IJV
64+
# ANCHOR_END: val_grad_hess

4_friction/simulator.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,14 @@
1414
n_seg = 4 # num of segments per side of the square
1515
h = 0.01 # time step size in s
1616
DBC = [] # no nodes need to be fixed
17+
# ANCHOR: slope_setup
1718
ground_n = np.array([0.1, 1.0]) # normal of the slope
1819
ground_n /= np.linalg.norm(ground_n) # normalize ground normal vector just in case
1920
ground_o = np.array([0.0, -1.0]) # a point on the slope
21+
# ANCHOR_END: slope_setup
22+
# ANCHOR: set_mu
2023
mu = 0.11 # friction coefficient of the slope
24+
# ANCHOR_END: set_mu
2125

2226
# initialize simulation
2327
[x, e] = square_mesh.generate(side_len, n_seg) # node positions and edge node indices
@@ -56,8 +60,10 @@ def screen_projection(x):
5660

5761
# fill the background and draw the square
5862
screen.fill((255, 255, 255))
63+
# ANCHOR: slope_vis
5964
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]]),
6065
screen_projection([ground_o[0] + 3.0 * ground_n[1], ground_o[1] - 3.0 * ground_n[0]])) # slope
66+
# ANCHOR_END: slope_vis
6167
for eI in e:
6268
pygame.draw.aaline(screen, (0, 0, 255), screen_projection(x[eI[0]]), screen_projection(x[eI[1]]))
6369
for xI in x:

4_friction/time_integrator.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,14 @@
1212
import BarrierEnergy
1313
import FrictionEnergy
1414

15+
# ANCHOR: mu_lambda
1516
def step_forward(x, e, v, m, l2, k, n, o, contact_area, mu, is_DBC, h, tol):
1617
x_tilde = x + v * h # implicit Euler predictive position
1718
x_n = copy.deepcopy(x)
1819
mu_lambda = BarrierEnergy.compute_mu_lambda(x, n, o, contact_area, mu) # compute mu * lambda for each node using x^n
1920

2021
# Newton loop
22+
# ANCHOR_END: mu_lambda
2123
iter = 0
2224
E_last = IP_val(x, e, x_tilde, m, l2, k, n, o, contact_area, (x - x_n) / h, mu_lambda, h)
2325
p = search_dir(x, e, x_tilde, m, l2, k, n, o, contact_area, (x - x_n) / h, mu_lambda, is_DBC, h)

0 commit comments

Comments
 (0)