Skip to content

Commit 891987b

Browse files
committed
ceil
1 parent 28d9d14 commit 891987b

2 files changed

Lines changed: 49 additions & 5 deletions

File tree

mov_dirichlet/BarrierEnergy.py

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,24 +6,43 @@
66

77
def val(x, n, o, contact_area):
88
sum = 0.0
9+
# floor:
910
for i in range(0, len(x)):
1011
d = n.dot(x[i] - o)
1112
if d < dhat:
1213
s = d / dhat
1314
sum += contact_area[i] * dhat * kappa / 2 * (s - 1) * math.log(s)
15+
# ceil:
16+
n = np.array([0.0, -1.0])
17+
for i in range(0, len(x) - 1):
18+
d = n.dot(x[i] - x[-1])
19+
if d < dhat:
20+
s = d / dhat
21+
sum += contact_area[i] * dhat * kappa / 2 * (s - 1) * math.log(s)
1422
return sum
1523

1624
def grad(x, n, o, contact_area):
1725
g = np.array([[0.0, 0.0]] * len(x))
26+
# floor:
1827
for i in range(0, len(x)):
1928
d = n.dot(x[i] - o)
2029
if d < dhat:
2130
s = d / dhat
2231
g[i] = contact_area[i] * dhat * (kappa / 2 * (math.log(s) / dhat + (s - 1) / d)) * n
32+
# ceil:
33+
n = np.array([0.0, -1.0])
34+
for i in range(0, len(x) - 1):
35+
d = n.dot(x[i] - x[-1])
36+
if d < dhat:
37+
s = d / dhat
38+
local_grad = contact_area[i] * dhat * (kappa / 2 * (math.log(s) / dhat + (s - 1) / d)) * n
39+
g[i] += local_grad
40+
g[-1] -= local_grad
2341
return g
2442

2543
def hess(x, n, o, contact_area):
2644
IJV = [[0] * 0, [0] * 0, np.array([0.0] * 0)]
45+
# floor:
2746
for i in range(0, len(x)):
2847
d = n.dot(x[i] - o)
2948
if d < dhat:
@@ -33,14 +52,35 @@ def hess(x, n, o, contact_area):
3352
IJV[0].append(i * 2 + r)
3453
IJV[1].append(i * 2 + c)
3554
IJV[2] = np.append(IJV[2], local_hess[r, c])
55+
# ceil:
56+
n = np.array([0.0, -1.0])
57+
for i in range(0, len(x) - 1):
58+
d = n.dot(x[i] - x[-1])
59+
if d < dhat:
60+
local_hess = contact_area[i] * dhat * kappa / (2 * d * d * dhat) * (d + dhat) * np.outer(n, n)
61+
index = [i, len(x) - 1]
62+
for nI in range(0, 2):
63+
for nJ in range(0, 2):
64+
for c in range(0, 2):
65+
for r in range(0, 2):
66+
IJV[0].append(index[nI] * 2 + r)
67+
IJV[1].append(index[nJ] * 2 + c)
68+
IJV[2] = np.append(IJV[2], ((-1) ** (nI != nJ)) * local_hess[r, c])
3669
return IJV
3770

3871
def init_step_size(x, n, o, p):
3972
alpha = 1
73+
# floor:
4074
for i in range(0, len(x)):
4175
p_n = p[i].dot(n)
4276
if p_n < 0:
4377
alpha = min(alpha, 0.9 * n.dot(x[i] - o) / -p_n)
78+
# ceil:
79+
n = np.array([0.0, -1.0])
80+
for i in range(0, len(x) - 1):
81+
p_n = (p[i] - p[-1]).dot(n)
82+
if p_n < 0:
83+
alpha = min(alpha, 0.9 * n.dot(x[i] - x[-1]) / -p_n)
4484
return alpha
4585

4686
def compute_mu_lambda(x, n, o, contact_area, mu):

mov_dirichlet/simulator.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,15 @@
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-
ground_n = np.array([0.1, 1.0]) # normal of the slope
17+
ground_n = np.array([0.0, 1.0]) # normal of the slope
1818
ground_n /= np.linalg.norm(ground_n) # normalize ground normal vector just in case
1919
ground_o = np.array([0.0, -1.0]) # a point on the slope
2020
mu = 0.11 # friction coefficient of the slope
2121

2222
# initialize simulation
23-
[x, e] = square_mesh.generate(side_len, n_seg) # node positions and edge node indices
24-
v = np.array([[0.0, 0.0]] * len(x)) # velocity
23+
[x, e] = square_mesh.generate(side_len, n_seg) # node positions and edge node indices
24+
x = np.append(x, [[0.0, side_len * 0.6]], axis=0) # ceil origin (with normal [0.0, -1.0])
25+
v = np.array([[0.0, 0.0]] * len(x)) # velocity
2526
m = [rho * side_len * side_len / ((n_seg + 1) * (n_seg + 1))] * len(x) # calculate node mass evenly
2627
# rest length squared
2728
l2 = []
@@ -56,10 +57,13 @@ def screen_projection(x):
5657
# fill the background and draw the square
5758
screen.fill((255, 255, 255))
5859
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]])) # slope
60+
screen_projection([ground_o[0] + 3.0 * ground_n[1], ground_o[1] - 3.0 * ground_n[0]])) # ground
61+
pygame.draw.aaline(screen, (0, 0, 255), screen_projection([x[-1][0] + 3.0, x[-1][1]]),
62+
screen_projection([x[-1][0] - 3.0, x[-1][1]])) # ceil
6063
for eI in e:
6164
pygame.draw.aaline(screen, (0, 0, 255), screen_projection(x[eI[0]]), screen_projection(x[eI[1]]))
62-
for xI in x:
65+
for xId in range(0, len(x) - 1):
66+
xI = x[xId]
6367
pygame.draw.circle(screen, (0, 0, 255), screen_projection(xI), 0.1 * side_len / n_seg * scale)
6468

6569
pygame.display.flip() # flip the display

0 commit comments

Comments
 (0)