Skip to content

Commit d3880af

Browse files
Add ABD embedding mesh visualization (#6)
* [add] add a draw abd embedding mesh option for the reduced dof sim script * added separator and method checks --------- Co-authored-by: Minchen Li <minchernl@gmail.com>
1 parent f9d4811 commit d3880af

2 files changed

Lines changed: 38 additions & 8 deletions

File tree

9_reduced_DOF/simulator.py

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,21 @@
44
import pygame # pygame for visualization
55
pygame.init()
66

7+
import math
78
import utils
89
import square_mesh # square mesh
910
import time_integrator
1011

1112
# simulation setup
1213
side_len = 1
13-
rho = 1000 # density of square
14-
E = 2e4 # Young's modulus
15-
nu = 0.4 # Poisson's ratio
16-
n_seg = 10 # num of segments per side of the square
17-
h = 0.01 # time step size in s
18-
DBC = [] # no nodes need to be fixed
19-
y_ground = -1 # height of the planar ground
14+
rho = 1000 # density of square
15+
E = 2e4 # Young's modulus
16+
nu = 0.4 # Poisson's ratio
17+
n_seg = 10 # num of segments per side of the square
18+
h = 0.01 # time step size in s
19+
DBC = [] # no nodes need to be fixed
20+
y_ground = -1 # height of the planar ground
21+
draw_abd = True # whether to draw the embedding mesh for ABD
2022

2123
# initialize simulation
2224
[x, e] = square_mesh.generate(side_len, n_seg) # node positions and edge node indices
@@ -41,7 +43,10 @@
4143
contact_area = [side_len / n_seg] * len(x) # perimeter split to each node
4244
# ANCHOR_END: contact_area
4345
# compute reduced basis using 0: no reduction; 1: polynomial functions; 2: modal reduction
44-
reduced_basis = utils.compute_reduced_basis(x, e, vol, IB, mu_lame, lam, method=1, order=2)
46+
method = 1
47+
order = 1
48+
reduced_basis = utils.compute_reduced_basis(x, e, vol, IB, mu_lame, lam, method, order)
49+
abd_anchor_basis = utils.compute_abd_anchor_basis(x)
4550

4651
# simulation with visualization
4752
resolution = np.array([900, 900])
@@ -65,6 +70,15 @@ def screen_projection(x):
6570
# fill the background and draw the square
6671
screen.fill((255, 255, 255))
6772
pygame.draw.aaline(screen, (0, 0, 255), screen_projection([-2, y_ground]), screen_projection([2, y_ground])) # ground
73+
# draw abd
74+
if draw_abd and method == 1 and order == 1:
75+
for i in range(3):
76+
reduced_vars = np.linalg.solve(np.transpose(reduced_basis) @ reduced_basis, np.transpose(reduced_basis) @ x.reshape(-1))
77+
abd_anchors = abd_anchor_basis @ reduced_vars
78+
pygame.draw.circle(screen, (255, 0, 0), screen_projection(abd_anchors[2 * i: 2 * i + 2]), 0.1 * side_len / n_seg * scale)
79+
pygame.draw.aaline(screen, (255, 0, 0), screen_projection(abd_anchors[0:2]), screen_projection(abd_anchors[2:4]))
80+
pygame.draw.aaline(screen, (255, 0, 0), screen_projection(abd_anchors[2:4]), screen_projection(abd_anchors[4:6]))
81+
pygame.draw.aaline(screen, (255, 0, 0), screen_projection(abd_anchors[4:6]), screen_projection(abd_anchors[0:2]))
6882
for eI in e:
6983
# ANCHOR: draw_tri
7084
pygame.draw.aaline(screen, (0, 0, 255), screen_projection(x[eI[0]]), screen_projection(x[eI[1]]))

9_reduced_DOF/utils.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import math
12
import numpy as np
23
import numpy.linalg as LA
34

@@ -33,6 +34,21 @@ def smallest_positive_real_root_quad(a, b, c, tol = 1e-6):
3334
return t
3435
# ANCHOR_END: find_positive_real_root
3536

37+
def compute_abd_anchor_basis(x):
38+
c = x.mean(axis=0)
39+
diag = np.linalg.norm(x.max(axis=0) - x.min(axis=0))
40+
scale = diag / math.sqrt(2)
41+
c -= 1/3 * scale
42+
anchors = np.stack([c, c + np.asarray([scale, 0]), c + np.asarray([0, scale])], axis=0)
43+
44+
basis = np.zeros((len(anchors) * 2, 6)) # 1, x, y for both x- and y-displacements
45+
for i in range(len(anchors)):
46+
for d in range(2):
47+
basis[i * 2 + d][d * 3] = 1
48+
basis[i * 2 + d][d * 3 + 1] = anchors[i][0]
49+
basis[i * 2 + d][d * 3 + 2] = anchors[i][1]
50+
return basis
51+
3652
def compute_reduced_basis(x, e, vol, IB, mu_lame, lam, method, order):
3753
if method == 0: # full basis, no reduction
3854
basis = np.zeros((len(x) * 2, len(x) * 2))

0 commit comments

Comments
 (0)