-
Notifications
You must be signed in to change notification settings - Fork 0
/
second_stage.py
154 lines (129 loc) · 3.74 KB
/
second_stage.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
"""
Demonstrates the behavior for following time steps.
"""
import numpy as np
from contact import MeshBody, GlobalMesh
import matplotlib.pyplot as plt
dt = 0.5
mesh1_data = np.float64([
[-0.5, -0.5, 0],
[-0.5, -0.25, 0],
[-0.5, 0.5, 1],
[-0.5, -0.5, 1],
[0.5, -0.5, 0],
[0.5, -0.25, 0],
[0.5, 0.5, 1],
[0.5, -0.5, 1]
])
mesh2_data = np.float64([
[-0.25, 0.2, 0.6],
[-0.25, 0.7, 0.6],
[-0.25, 0.7, 0.1],
[-0.25, 0.2, 0.1],
[0.25, 0.2, 0.6],
[0.25, 0.7, 0.6],
[0.25, 0.7, 0.1],
[0.25, 0.2, 0.1]
])
mesh3_data = np.float64([
[-0.5, -0.5, 1],
[-0.5, 0.5, 1],
[-0.5, 0.5, 2],
[-0.5, -0.5, 2],
[0.5, -0.5, 1],
[0.5, 0.5, 1],
[0.5, 0.5, 2],
[0.5, -0.5, 2]
])
mesh4_data = np.float64([
[-0.6, -0.6, 1],
[-0.6, 0.6, 1],
[-0.6, 0.6, 2],
[-0.6, -0.6, 2],
[0.6, -0.6, 1],
[0.6, 0.6, 1],
[0.6, 0.6, 2],
[0.6, -0.6, 2]
])
mesh1_cells_dict = {
'hexahedron': np.array([
[0, 1, 2, 3, 4, 5, 6, 7]
])
}
mesh2_cells_dict = {
'hexahedron': np.array([
[0, 1, 2, 3, 4, 5, 6, 7]
])
}
mesh3_cells_dict = {
'hexahedron': np.array([
[0, 1, 2, 3, 4, 5, 6, 7]
])
}
mesh4_cells_dict = {
'hexahedron': np.array([
[0, 1, 2, 3, 4, 5, 6, 7]
])
}
mesh1 = MeshBody(mesh1_data, mesh1_cells_dict)
mesh1.color = 'black'
mesh2 = MeshBody(mesh2_data, mesh2_cells_dict, velocity=np.float64([0, -0.25, 0.25]))
mesh2.color = 'navy'
mesh3 = MeshBody(mesh3_data, mesh3_cells_dict)
mesh3.color = 'seagreen'
mesh4 = MeshBody(mesh4_data, mesh4_cells_dict)
mesh4.color = 'darkred'
# glob_mesh = GlobalMesh(mesh1, mesh2, mesh3, bs=0.49)
glob_mesh = GlobalMesh(mesh1, mesh2, mesh4, bs=0.49)
fig, (ax1, ax2, ax3) = plt.subplots(nrows=1, ncols=3, subplot_kw=dict(projection='3d', proj_type='ortho'))
ax1.set_title('At $t$')
ax2.set_title(r'At $t + \Delta t$')
ax3.set_title(r'At $t + 2\cdot\Delta t$')
for ax in (ax1, ax2, ax3):
ax.set_xlabel('x')
ax.set_ylabel('y')
ax.set_zlabel('z')
for mesh in glob_mesh.mesh_bodies:
for surf in mesh.surfaces:
surf.project_surface(ax1, 0, N=2, color=mesh.color, ls='-', alpha=1)
x, y, z = np.mean(surf.points, axis=0)
ax1.text(x, y, z, f'{surf.label}', color=mesh.color)
for node in glob_mesh.nodes: ax1.text(*node.pos, f'{node.label}', color='lime')
contact_pairs = glob_mesh.get_contact_pairs(dt)
print('Contact Pairs at t = 0:')
for pair in contact_pairs: print(pair)
print()
print('Total Iterations:', glob_mesh.normal_increments(dt, multi_stage=True))
print()
glob_mesh.remove_pairs(dt)
glob_mesh.update_nodes(dt)
for patch_obj in glob_mesh.surfaces:
patch_obj.zero_contact()
for mesh in glob_mesh.mesh_bodies:
for surf in mesh.surfaces:
patch_obj = glob_mesh.surfaces[surf.label]
patch_obj.project_surface(ax2, 0, N=2, color=mesh.color, ls='-', alpha=1)
for node in glob_mesh.nodes: ax2.text(*node.pos, f'{node.label}', color='lime')
# Corner force calculated here. Need to perform detection again.
glob_mesh.sort()
contact_pairs = glob_mesh.get_contact_pairs(dt)
print('Contact Pairs at t = dt:')
for pair in glob_mesh.contact_pairs: print(pair)
print()
print('Total Iterations:', glob_mesh.normal_increments(dt, multi_stage=True))
print()
glob_mesh.remove_pairs(dt)
glob_mesh.update_nodes(dt)
for patch_obj in glob_mesh.surfaces:
patch_obj.zero_contact()
print('Contact Pairs at t = 2*dt:')
for pair in glob_mesh.contact_pairs: print(pair)
print()
for mesh in glob_mesh.mesh_bodies:
for surf in mesh.surfaces:
patch_obj = glob_mesh.surfaces[surf.label]
patch_obj.project_surface(ax3, 0, N=2, color=mesh.color, ls='-', alpha=1)
for ax in (ax1, ax2, ax3):
ax.set_aspect('equal')
ax.view_init(elev=25, azim=25)
plt.show()