-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPlot Code For The Shape Mesh.py
More file actions
50 lines (48 loc) · 1.87 KB
/
Copy pathPlot Code For The Shape Mesh.py
File metadata and controls
50 lines (48 loc) · 1.87 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
import numpy as np
import matplotlib.pyplot as plt
#The main purpose of this code is to parse and visualize a mesh.
def parse_inp_file(file_path):
nodes = []
elements = []
with open(file_path, 'r') as file:
lines = file.readlines()
node_section = False
element_section = False
for line in lines:
if '*Node' in line:
node_section = True
element_section = False
continue
if '*Element' in line:
node_section = False
element_section = True
continue
if '*Nset' in line or '*Elset' in line or line.startswith('*'):
continue
if node_section:
parts = line.strip().split(',')
if len(parts) > 1:
nodes.append([float(part) for part in parts[1:]])
if element_section:
parts = line.strip().split(',')
if len(parts) > 1 and all(part.strip().isdigit() for part in parts[1:]):
elements.append([int(part) for part in parts[1:]])
return np.array(nodes), elements
def plot_mesh(nodes, elements):
fig, ax = plt.subplots()
num_nodes = nodes.shape[0]
for element in elements:
if all(1 <= idx <= num_nodes for idx in element):
polygon = plt.Polygon(nodes[np.array(element) - 1], edgecolor='black', facecolor='none')
ax.add_patch(polygon)
ax.plot(nodes[:, 0], nodes[:, 1], 'o', markersize=2)
ax.set_aspect('equal')
plt.xlabel('X')
plt.ylabel('Y')
plt.title('Mesh Plot')
plt.show()
# مسیر فایل Mesh
file_path = 'final_2.inp'
nodes, elements = parse_inp_file(file_path)
plot_mesh(nodes, elements)
#Fazel Mohammad Ali Pour - 7/15/2024 - Python Code For Drawing the shape based on the mesh file