@@ -17,17 +17,20 @@ def step_forward(x, e, v, m, l2, k, n, o, contact_area, mu, is_DBC, DBC, DBC_v,
1717 x_tilde = x + v * h # implicit Euler predictive position
1818 x_n = copy .deepcopy (x )
1919 mu_lambda = BarrierEnergy .compute_mu_lambda (x , n , o , contact_area , mu ) # compute mu * lambda for each node using x^n
20+ # ANCHOR: dbc_initialization
2021 DBC_target = [] # target position of each DBC in the current time step
2122 for i in range (0 , len (DBC )):
2223 if (DBC_limit [i ] - x_n [DBC [i ]]).dot (DBC_v [i ]) > 0 :
2324 DBC_target .append (x_n [DBC [i ]] + h * DBC_v [i ])
2425 else :
2526 DBC_target .append (x_n [DBC [i ]])
2627 DBC_stiff = 10 # initialize stiffness for DBC springs
28+ # ANCHOR_END: dbc_initialization
2729
2830 # Newton loop
2931 iter = 0
3032 E_last = IP_val (x , e , x_tilde , m , l2 , k , n , o , contact_area , (x - x_n ) / h , mu_lambda , DBC , DBC_target , DBC_stiff , h )
33+ # ANCHOR: convergence_criteria
3134 [p , DBC_satisfied ] = search_dir (x , e , x_tilde , m , l2 , k , n , o , contact_area , (x - x_n ) / h , mu_lambda , is_DBC , DBC , DBC_target , DBC_stiff , tol , h )
3235 while (LA .norm (p , inf ) / h > tol ) | (sum (DBC_satisfied ) != len (DBC )): # also check whether all DBCs are satisfied
3336 print ('Iteration' , iter , ':' )
@@ -37,6 +40,7 @@ def step_forward(x, e, v, m, l2, k, n, o, contact_area, mu, is_DBC, DBC, DBC_v,
3740 # increase DBC stiffness and recompute energy value record
3841 DBC_stiff *= 2
3942 E_last = IP_val (x , e , x_tilde , m , l2 , k , n , o , contact_area , (x - x_n ) / h , mu_lambda , DBC , DBC_target , DBC_stiff , h )
43+ # ANCHOR_END: convergence_criteria
4044
4145 # filter line search
4246 alpha = BarrierEnergy .init_step_size (x , n , o , p ) # avoid interpenetration and tunneling
@@ -87,16 +91,20 @@ def IP_hess(x, e, x_tilde, m, l2, k, n, o, contact_area, v, mu_lambda, DBC, DBC_
8791def search_dir (x , e , x_tilde , m , l2 , k , n , o , contact_area , v , mu_lambda , is_DBC , DBC , DBC_target , DBC_stiff , tol , h ):
8892 projected_hess = IP_hess (x , e , x_tilde , m , l2 , k , n , o , contact_area , v , mu_lambda , DBC , DBC_target , DBC_stiff , h )
8993 reshaped_grad = IP_grad (x , e , x_tilde , m , l2 , k , n , o , contact_area , v , mu_lambda , DBC , DBC_target , DBC_stiff , h ).reshape (len (x ) * 2 , 1 )
94+ # ANCHOR: dbc_check
9095 # check whether each DBC is satisfied
9196 DBC_satisfied = [False ] * len (x )
9297 for i in range (0 , len (DBC )):
9398 if LA .norm (x [DBC [i ]] - DBC_target [i ]) / h < tol :
9499 DBC_satisfied [DBC [i ]] = True
100+ # ANCHOR_END: dbc_check
101+ # ANCHOR: dof_elimination
95102 # eliminate DOF if it's a satisfied DBC by modifying gradient and Hessian for DBC:
96103 for i , j in zip (* projected_hess .nonzero ()):
97104 if (is_DBC [int (i / 2 )] & DBC_satisfied [int (i / 2 )]) | (is_DBC [int (j / 2 )] & DBC_satisfied [int (i / 2 )]):
98105 projected_hess [i , j ] = (i == j )
99106 for i in range (0 , len (x )):
100107 if is_DBC [i ] & DBC_satisfied [i ]:
101108 reshaped_grad [i * 2 ] = reshaped_grad [i * 2 + 1 ] = 0.0
102- return [spsolve (projected_hess , - reshaped_grad ).reshape (len (x ), 2 ), DBC_satisfied ]
109+ return [spsolve (projected_hess , - reshaped_grad ).reshape (len (x ), 2 ), DBC_satisfied ]
110+ # ANCHOR_END: dof_elimination
0 commit comments