Skip to content

Commit 780a1ec

Browse files
Add code anchors for reduced DOF dropping block example (#9)
* [add] add a draw abd embedding mesh option for the reduced dof sim script * added separator and method checks * [add] add anchors for the reduced dof example --------- Co-authored-by: Minchen Li <[email protected]>
1 parent 5d868ab commit 780a1ec

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

9_reduced_DOF/time_integrator.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ def IP_hess(x, e, x_tilde, m, vol, IB, mu_lame, lam, y_ground, contact_area, h):
5656
H = sparse.coo_matrix((IJV[2], (IJV[0], IJV[1])), shape=(len(x) * 2, len(x) * 2)).tocsr()
5757
return H
5858

59+
# ANCHOR: search_dir
5960
def search_dir(x, e, x_tilde, m, vol, IB, mu_lame, lam, y_ground, contact_area, is_DBC, reduced_basis, h):
6061
projected_hess = IP_hess(x, e, x_tilde, m, vol, IB, mu_lame, lam, y_ground, contact_area, h)
6162
reshaped_grad = IP_grad(x, e, x_tilde, m, vol, IB, mu_lame, lam, y_ground, contact_area, h).reshape(len(x) * 2, 1)
@@ -68,4 +69,5 @@ def search_dir(x, e, x_tilde, m, vol, IB, mu_lame, lam, y_ground, contact_area,
6869
reshaped_grad[i * 2] = reshaped_grad[i * 2 + 1] = 0.0
6970
reduced_hess = reduced_basis.T.dot(projected_hess.dot(reduced_basis)) # applying chain rule
7071
reduced_grad = reduced_basis.T.dot(reshaped_grad) # applying chain rule
71-
return (reduced_basis.dot(spsolve(reduced_hess, -reduced_grad))).reshape(len(x), 2) # transform to full space after the solve
72+
return (reduced_basis.dot(spsolve(reduced_hess, -reduced_grad))).reshape(len(x), 2) # transform to full space after the solve
73+
# ANCHOR_END: search_dir

9_reduced_DOF/utils.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ def compute_abd_anchor_basis(x):
5050
basis[i * 2 + d][d * 3 + 2] = anchors[i][1]
5151
return basis
5252

53+
# ANCHOR: compute_reduced_basis
5354
def compute_reduced_basis(x, e, vol, IB, mu_lame, lam, method, order):
5455
if method == 0: # full basis, no reduction
5556
basis = np.zeros((len(x) * 2, len(x) * 2))
@@ -99,4 +100,5 @@ def compute_reduced_basis(x, e, vol, IB, mu_lame, lam, method, order):
99100
IJV = NeoHookeanEnergy.hess(x, e, vol, IB, mu_lame, lam, project_PSD=False)
100101
H = sparse.coo_matrix((IJV[2], (IJV[0], IJV[1])), shape=(len(x) * 2, len(x) * 2)).tocsr()
101102
eigenvalues, eigenvectors = eigsh(H, k=order, which='SM') # get 'order' eigenvectors with smallest eigenvalues
102-
return eigenvectors
103+
return eigenvectors
104+
# ANCHOR_END: compute_reduced_basis

0 commit comments

Comments
 (0)