-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplotMesh.py
executable file
·47 lines (40 loc) · 1.25 KB
/
plotMesh.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
import matplotlib.pyplot as plt
import numpy as np
import csv
import sys
for k in range(len(sys.argv)):
if k == 0:
continue
with open(str(sys.argv[k]), 'r') as mesh_file:
mesh = csv.reader(mesh_file, delimiter=',')
nodes = []
elements = []
elemFlag = False
line_count = 0
for row in mesh:
if line_count > 0:
if row[0]=="$elements":
elemFlag = True
continue
if elemFlag == False:
nodes.append(row)
else:
elements.append(row)
else:
line_count +=1
connectivity = [x[1:] for x in elements]
nodes = [x[1:] for x in nodes]
numRows = np.size(connectivity) / np.size(connectivity[0])
numCols = np.size(connectivity[0])
Xel = [0 for i in range(numCols+1)]
Yel = [0 for i in range(numCols+1)]
for i in range(numRows):
for j in range(numCols):
node = connectivity[i][j]
Xel[j] = float(nodes[int(node)-1][0])
Yel[j] = float(nodes[int(node)-1][1])
Xel[j+1] = Xel[0]
Yel[j+1] = Yel[0]
plt.plot(Xel,Yel, '-ko')
plt.title(sys.argv[k])
plt.show(block=True)