Skip to content

Commit e48740d

Browse files
committed
added anchors
1 parent db4b005 commit e48740d

6 files changed

Lines changed: 21 additions & 1 deletion

File tree

7_self_contact/BarrierEnergy.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ def val(x, n, o, bp, be, contact_area):
2424
if d < dhat:
2525
s = d / dhat
2626
sum += contact_area[i] * dhat * kappa / 2 * (s - 1) * math.log(s)
27+
# ANCHOR: value
2728
# self-contact
2829
dhat_sqr = dhat * dhat
2930
for xI in bp:
@@ -34,6 +35,7 @@ def val(x, n, o, bp, be, contact_area):
3435
s = d_sqr / dhat_sqr
3536
# since d_sqr is used, need to divide by 8 not 2 here for consistency to linear elasticity:
3637
sum += 0.5 * contact_area[xI] * dhat * kappa / 8 * (s - 1) * math.log(s)
38+
# ANCHOR_END: value
3739
return sum
3840

3941
def grad(x, n, o, bp, be, contact_area):
@@ -53,6 +55,7 @@ def grad(x, n, o, bp, be, contact_area):
5355
local_grad = contact_area[i] * dhat * (kappa / 2 * (math.log(s) / dhat + (s - 1) / d)) * n
5456
g[i] += local_grad
5557
g[-1] -= local_grad
58+
# ANCHOR: gradient
5659
# self-contact
5760
dhat_sqr = dhat * dhat
5861
for xI in bp:
@@ -66,6 +69,7 @@ def grad(x, n, o, bp, be, contact_area):
6669
g[xI] += local_grad[0:2]
6770
g[eI[0]] += local_grad[2:4]
6871
g[eI[1]] += local_grad[4:6]
72+
# ANCHOR_END: gradient
6973
return g
7074

7175
def hess(x, n, o, bp, be, contact_area):
@@ -94,6 +98,7 @@ def hess(x, n, o, bp, be, contact_area):
9498
IJV[0].append(index[nI] * 2 + r)
9599
IJV[1].append(index[nJ] * 2 + c)
96100
IJV[2] = np.append(IJV[2], ((-1) ** (nI != nJ)) * local_hess[r, c])
101+
# ANCHOR: Hessian
97102
# self-contact
98103
dhat_sqr = dhat * dhat
99104
for xI in bp:
@@ -114,6 +119,7 @@ def hess(x, n, o, bp, be, contact_area):
114119
IJV[0].append(index[nI] * 2 + r)
115120
IJV[1].append(index[nJ] * 2 + c)
116121
IJV[2] = np.append(IJV[2], local_hess[nI * 2 + r, nJ * 2 + c])
122+
# ANCHOR_END: Hessian
117123
return IJV
118124

119125
def init_step_size(x, n, o, bp, be, p):
@@ -129,6 +135,7 @@ def init_step_size(x, n, o, bp, be, p):
129135
p_n = (p[i] - p[-1]).dot(n)
130136
if p_n < 0:
131137
alpha = min(alpha, 0.9 * n.dot(x[i] - x[-1]) / -p_n)
138+
# ANCHOR: line_search_filtering
132139
# self-contact
133140
for xI in bp:
134141
for eI in be:
@@ -137,6 +144,7 @@ def init_step_size(x, n, o, bp, be, p):
137144
toc = CCD.narrow_phase_CCD(x[xI], x[eI[0]], x[eI[1]], p[xI], p[eI[0]], p[eI[1]], alpha)
138145
if alpha > toc:
139146
alpha = toc
147+
# ANCHOR_END: line_search_filtering
140148
return alpha
141149

142150
def compute_mu_lambda(x, n, o, bp, be, contact_area, mu):

7_self_contact/distance/CCD.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
# ANCHOR: broad_phase
12
from copy import deepcopy
23
import numpy as np
34
import math
@@ -14,7 +15,9 @@ def bbox_overlap(p, e0, e1, dp, de0, de1, toc_upperbound):
1415
return False
1516
else:
1617
return True
18+
# ANCHOR_END: broad_phase
1719

20+
# ANCHOR: accd
1821
# compute the first "time" of contact, or toc,
1922
# return the computed toc only if it is smaller than the previously computed toc_upperbound
2023
def narrow_phase_CCD(_p, _e0, _e1, _dp, _de0, _de1, toc_upperbound):
@@ -56,4 +59,5 @@ def narrow_phase_CCD(_p, _e0, _e1, _dp, _de0, _de1, toc_upperbound):
5659
if toc > toc_upperbound:
5760
return toc_upperbound
5861

59-
return toc
62+
return toc
63+
# ANCHOR_END: accd

7_self_contact/distance/PointEdgeDistance.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
# ANCHOR: PE_val_grad
12
import numpy as np
23

34
import distance.PointPointDistance as PP
@@ -24,6 +25,7 @@ def grad(p, e0, e1):
2425
return np.reshape([g_PP[0:2], np.array([0.0, 0.0]), g_PP[2:4]], (1, 6))[0]
2526
else: # point(p)-line(e0e1) expression
2627
return PL.grad(p, e0, e1)
28+
# ANCHOR_END: PE_val_grad
2729

2830
def hess(p, e0, e1):
2931
e = e1 - e0

7_self_contact/distance/PointLineDistance.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
# ANCHOR: PL_val_grad
12
import numpy as np
23

34
def val(p, e0, e1):
@@ -23,6 +24,7 @@ def grad(p, e0, e1):
2324
g[4] = t27 + t24 * (p[1] - e0[1]) * 2.0
2425
g[5] = t26 - t24 * (p[0] - e0[0]) * 2.0
2526
return g
27+
# ANCHOR_END: PL_val_grad
2628

2729
def hess(p, e0, e1):
2830
H = np.array([0.0] * 36)

7_self_contact/simulator.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import square_mesh # square mesh
88
import time_integrator
99

10+
# ANCHOR: sim_setup
1011
# simulation setup
1112
side_len = 0.45
1213
rho = 1000 # density of square
@@ -26,6 +27,7 @@
2627
[x, e] = square_mesh.generate(side_len, n_seg) # node positions and triangle node indices of the top square
2728
e = np.append(e, np.array(e) + [len(x)] * 3, axis=0) # add triangle node indices of the bottom square
2829
x = np.append(x, x + [side_len * 0.1, -side_len * 1.1], axis=0) # add node positions of the bottom square
30+
# ANCHOR_END: sim_setup
2931
[bp, be] = square_mesh.find_boundary(e) # find boundary points and edges for self-contact
3032
x = np.append(x, [[0.0, side_len * 0.6]], axis=0) # ceil origin (with normal [0.0, -1.0])
3133
v = np.array([[0.0, 0.0]] * len(x)) # velocity

7_self_contact/square_mesh.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ def generate(side_length, n_seg):
2323

2424
return [x, e]
2525

26+
# ANCHOR: find_boundary
2627
def find_boundary(e):
2728
# index all half-edges for fast query
2829
edge_set = set()
@@ -41,6 +42,7 @@ def find_boundary(e):
4142
bp_set.add(eI[0])
4243
bp_set.add(eI[1])
4344
return [list(bp_set), be]
45+
# ANCHOR_END: find_boundary
4446

4547
def write_to_file(frameNum, x, e):
4648
# Check if 'output' directory exists; if not, create it

0 commit comments

Comments
 (0)