-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinterfere.py
More file actions
52 lines (44 loc) · 1.43 KB
/
interfere.py
File metadata and controls
52 lines (44 loc) · 1.43 KB
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
import matplotlib.pyplot as plt
import numpy as np
# 读取生成的网格文件
def read_mesh(filename='TEXT_20250211.txt'):
nodes = []
faces = []
reading_nodes = False
reading_faces = False
with open(filename, 'r') as f:
lines = f.readlines()
for line in lines:
if 'Number of Nodes' in line:
reading_nodes = True
reading_faces = False
continue
elif 'Number of Face' in line:
reading_nodes = False
reading_faces = True
continue
if reading_nodes:
if len(line.strip().split()) == 2:
x, y = map(float, line.strip().split())
nodes.append([x, y])
elif reading_faces:
if len(line.strip().split()) == 4:
left, right, n1, n2 = map(int, line.strip().split())
faces.append([n1, n2])
return np.array(nodes), np.array(faces)
# 读取网格数据
nodes, faces = read_mesh()
# 绘制网格
plt.figure(figsize=(10, 10))
# 绘制所有网格边
for face in faces:
n1, n2 = face
plt.plot([nodes[n1-1][0], nodes[n2-1][0]],
[nodes[n1-1][1], nodes[n2-1][1]], 'b-')
# 绘制所有节点
plt.plot(nodes[:,0], nodes[:,1], 'r.')
# 设置坐标轴
plt.axis('equal')
plt.grid(True)
plt.title('Generated Mesh')
plt.show()