44import pygame # pygame for visualization
55pygame .init ()
66
7+ import math
78import utils
89import square_mesh # square mesh
910import time_integrator
1011
1112# simulation setup
1213side_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
4143contact_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
4752resolution = 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 ]]))
0 commit comments