66
77def 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
1624def 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
2543def 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
3871def 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
4686def compute_mu_lambda (x , n , o , contact_area , mu ):
0 commit comments