You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: self_contact/time_integrator.py
+16-16Lines changed: 16 additions & 16 deletions
Original file line number
Diff line number
Diff line change
@@ -16,7 +16,7 @@
16
16
defstep_forward(x, e, v, m, vol, IB, mu_lame, lam, n, o, bp, be, contact_area, mu, is_DBC, DBC, DBC_v, DBC_limit, h, tol):
17
17
x_tilde=x+v*h# implicit Euler predictive position
18
18
x_n=copy.deepcopy(x)
19
-
[mu_lambda, mu_lambda_self]=BarrierEnergy.compute_mu_lambda(x, n, o, bp, be, contact_area, mu) # compute mu * lambda for each node using x^n
19
+
mu_lambda=BarrierEnergy.compute_mu_lambda(x, n, o, bp, be, contact_area, mu) # compute mu * lambda for each node using x^n
20
20
DBC_target= [] # target position of each DBC in the current time step
21
21
foriinrange(0, len(DBC)):
22
22
if (DBC_limit[i] -x_n[DBC[i]]).dot(DBC_v[i]) >0:
@@ -27,52 +27,52 @@ def step_forward(x, e, v, m, vol, IB, mu_lame, lam, n, o, bp, be, contact_area,
27
27
28
28
# Newton loop
29
29
iter=0
30
-
E_last=IP_val(x, e, x_tilde, m, vol, IB, mu_lame, lam, n, o, bp, be, contact_area, (x-x_n) /h, mu_lambda, mu_lambda_self, DBC, DBC_target, DBC_stiff, h)
31
-
[p, DBC_satisfied] =search_dir(x, e, x_tilde, m, vol, IB, mu_lame, lam, n, o, bp, be, contact_area, (x-x_n) /h, mu_lambda, mu_lambda_self, is_DBC, DBC, DBC_target, DBC_stiff, tol, h)
30
+
E_last=IP_val(x, e, x_tilde, m, vol, IB, mu_lame, lam, n, o, bp, be, contact_area, (x-x_n) /h, mu_lambda, DBC, DBC_target, DBC_stiff, h)
31
+
[p, DBC_satisfied] =search_dir(x, e, x_tilde, m, vol, IB, mu_lame, lam, n, o, bp, be, contact_area, (x-x_n) /h, mu_lambda, is_DBC, DBC, DBC_target, DBC_stiff, tol, h)
32
32
while (LA.norm(p, inf) /h>tol) | (sum(DBC_satisfied) !=len(DBC)): # also check whether all DBCs are satisfied
33
33
print('Iteration', iter, ':')
34
34
print('residual =', LA.norm(p, inf) /h)
35
35
36
36
if (LA.norm(p, inf) /h<=tol) & (sum(DBC_satisfied) !=len(DBC)):
37
37
# increase DBC stiffness and recompute energy value record
38
38
DBC_stiff*=2
39
-
E_last=IP_val(x, e, x_tilde, m, vol, IB, mu_lame, lam, n, o, bp, be, contact_area, (x-x_n) /h, mu_lambda, mu_lambda_self, DBC, DBC_target, DBC_stiff, h)
39
+
E_last=IP_val(x, e, x_tilde, m, vol, IB, mu_lame, lam, n, o, bp, be, contact_area, (x-x_n) /h, mu_lambda, DBC, DBC_target, DBC_stiff, h)
40
40
41
41
# filter line search
42
42
alpha=min(BarrierEnergy.init_step_size(x, n, o, bp, be, p), NeoHookeanEnergy.init_step_size(x, e, p)) # avoid interpenetration, tunneling, and inversion
43
-
whileIP_val(x+alpha*p, e, x_tilde, m, vol, IB, mu_lame, lam, n, o, bp, be, contact_area, (x+alpha*p-x_n) /h, mu_lambda, mu_lambda_self, DBC, DBC_target, DBC_stiff, h) >E_last:
43
+
whileIP_val(x+alpha*p, e, x_tilde, m, vol, IB, mu_lame, lam, n, o, bp, be, contact_area, (x+alpha*p-x_n) /h, mu_lambda, DBC, DBC_target, DBC_stiff, h) >E_last:
44
44
alpha/=2
45
45
print('step size =', alpha)
46
46
47
47
x+=alpha*p
48
-
E_last=IP_val(x, e, x_tilde, m, vol, IB, mu_lame, lam, n, o, bp, be, contact_area, (x-x_n) /h, mu_lambda, mu_lambda_self, DBC, DBC_target, DBC_stiff, h)
49
-
[p, DBC_satisfied] =search_dir(x, e, x_tilde, m, vol, IB, mu_lame, lam, n, o, bp, be, contact_area, (x-x_n) /h, mu_lambda, mu_lambda_self, is_DBC, DBC, DBC_target, DBC_stiff, tol, h)
48
+
E_last=IP_val(x, e, x_tilde, m, vol, IB, mu_lame, lam, n, o, bp, be, contact_area, (x-x_n) /h, mu_lambda, DBC, DBC_target, DBC_stiff, h)
49
+
[p, DBC_satisfied] =search_dir(x, e, x_tilde, m, vol, IB, mu_lame, lam, n, o, bp, be, contact_area, (x-x_n) /h, mu_lambda, is_DBC, DBC, DBC_target, DBC_stiff, tol, h)
50
50
iter+=1
51
51
52
52
v= (x-x_n) /h# implicit Euler velocity update
53
53
return [x, v]
54
54
55
-
defIP_val(x, e, x_tilde, m, vol, IB, mu_lame, lam, n, o, bp, be, contact_area, v, mu_lambda, mu_lambda_self, DBC, DBC_target, DBC_stiff, h):
55
+
defIP_val(x, e, x_tilde, m, vol, IB, mu_lame, lam, n, o, bp, be, contact_area, v, mu_lambda, DBC, DBC_target, DBC_stiff, h):
56
56
returnInertiaEnergy.val(x, x_tilde, m) +h*h* ( # implicit Euler
57
57
NeoHookeanEnergy.val(x, e, vol, IB, mu_lame, lam) +
58
58
GravityEnergy.val(x, m) +
59
59
BarrierEnergy.val(x, n, o, bp, be, contact_area) +
defsearch_dir(x, e, x_tilde, m, vol, IB, mu_lame, lam, n, o, bp, be, contact_area, v, mu_lambda, mu_lambda_self, is_DBC, DBC, DBC_target, DBC_stiff, tol, h):
88
-
projected_hess=IP_hess(x, e, x_tilde, m, vol, IB, mu_lame, lam, n, o, bp, be, contact_area, v, mu_lambda, mu_lambda_self, DBC, DBC_target, DBC_stiff, h)
89
-
reshaped_grad=IP_grad(x, e, x_tilde, m, vol, IB, mu_lame, lam, n, o, bp, be, contact_area, v, mu_lambda, mu_lambda_self, DBC, DBC_target, DBC_stiff, h).reshape(len(x) *2, 1)
87
+
defsearch_dir(x, e, x_tilde, m, vol, IB, mu_lame, lam, n, o, bp, be, contact_area, v, mu_lambda, is_DBC, DBC, DBC_target, DBC_stiff, tol, h):
88
+
projected_hess=IP_hess(x, e, x_tilde, m, vol, IB, mu_lame, lam, n, o, bp, be, contact_area, v, mu_lambda, DBC, DBC_target, DBC_stiff, h)
89
+
reshaped_grad=IP_grad(x, e, x_tilde, m, vol, IB, mu_lame, lam, n, o, bp, be, contact_area, v, mu_lambda, DBC, DBC_target, DBC_stiff, h).reshape(len(x) *2, 1)
0 commit comments