Skip to content

Commit 0b1b564

Browse files
committed
slope
1 parent 32645a1 commit 0b1b564

2 files changed

Lines changed: 18 additions & 13 deletions

File tree

friction/BarrierEnergy.py

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,13 @@
33

44
dhat = 0.01
55
kappa = 1e5
6+
n = np.array([0.0, 1.0]) #TODO: make as parameter
7+
o = np.array([0.0, -1.0])
68

79
def val(x, y_ground, contact_area):
810
sum = 0.0
911
for i in range(0, len(x)):
10-
d = x[i][1] - y_ground
12+
d = n.dot(x[i] - o)
1113
if d < dhat:
1214
s = d / dhat
1315
sum += contact_area[i] * dhat * kappa / 2 * (s - 1) * math.log(s)
@@ -16,27 +18,29 @@ def val(x, y_ground, contact_area):
1618
def grad(x, y_ground, contact_area):
1719
g = np.array([[0.0, 0.0]] * len(x))
1820
for i in range(0, len(x)):
19-
d = x[i][1] - y_ground
21+
d = n.dot(x[i] - o)
2022
if d < dhat:
2123
s = d / dhat
22-
g[i][1] = contact_area[i] * dhat * (kappa / 2 * (math.log(s) / dhat + (s - 1) / d))
24+
g[i] = contact_area[i] * dhat * (kappa / 2 * (math.log(s) / dhat + (s - 1) / d)) * n
2325
return g
2426

2527
def hess(x, y_ground, contact_area):
26-
IJV = [[0] * len(x), [0] * len(x), np.array([0.0] * len(x))]
28+
IJV = [[0] * 0, [0] * 0, np.array([0.0] * 0)]
2729
for i in range(0, len(x)):
28-
IJV[0][i] = i * 2 + 1
29-
IJV[1][i] = i * 2 + 1
30-
d = x[i][1] - y_ground
30+
d = n.dot(x[i] - o)
3131
if d < dhat:
32-
IJV[2][i] = contact_area[i] * dhat * kappa / (2 * d * d * dhat) * (d + dhat)
33-
else:
34-
IJV[2][i] = 0.0
32+
local_hess = contact_area[i] * dhat * kappa / (2 * d * d * dhat) * (d + dhat) * np.outer(n, n)
33+
for c in range(0, 2):
34+
for r in range(0, 2):
35+
IJV[0].append(i * 2 + r)
36+
IJV[1].append(i * 2 + c)
37+
IJV[2] = np.append(IJV[2], local_hess[r, c])
3538
return IJV
3639

3740
def init_step_size(x, y_ground, p):
3841
alpha = 1
3942
for i in range(0, len(x)):
40-
if p[i][1] < 0:
41-
alpha = min(alpha, 0.9 * (y_ground - x[i][1]) / p[i][1])
43+
p_n = p[i].dot(n)
44+
if p_n < 0:
45+
alpha = min(alpha, 0.9 * n.dot(x[i] - o) / -p_n)
4246
return alpha

friction/simulator.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@
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-
y_ground = -1 # height of the planar ground
17+
ground_n = np.array([0.0, 1.0]) # height of the planar ground
18+
ground_o = np.array([0.0, -1.0])
1819

1920
# initialize simulation
2021
[x, e] = square_mesh.generate(side_len, n_seg) # node positions and edge node indices

0 commit comments

Comments
 (0)