-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathpltmsh.py
118 lines (99 loc) · 3.77 KB
/
pltmsh.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
import os
import sys
import numpy as np
import matplotlib.pyplot as plt
from matplotlib.pyplot import figure
#-------------------------------------------------------
# INPUT PARAMETERS
#-------------------------------------------------------
scale = float(sys.argv[1]) #parameter that scales the plot
show_mesh = int(sys.argv[2])
v = 3
while (v < len(sys.argv)):
var = sys.argv[v]
#-------------------------------------------------------
# CREATING A PATH DIRECTORY TO EXPORT PICS
#-------------------------------------------------------
path = "sim/out/"+var+"_jpg"
try:
os.mkdir(path)
except OSError:
print ("Creation of the directory %s failed" % path)
else:
print ("Successfully created the directory %s " % path)
#-------------------------------------------------------
# SETTING FIGURE SIZE AND LIMITS
#-------------------------------------------------------
pltctrl = 'sim/out/pltctrl.txt'
pltctrltype = [int, int, float, float, float, float]
pltctrlnames = ["A", "B", "C", "D", "E", "F"]
ary1 = np.genfromtxt(pltctrl, names=pltctrlnames, dtype=pltctrltype)
print(ary1)
nt = ary1['A']
inc = ary1['B']
num = inc
xmin = ary1['C']
xmax = ary1['D']
ymin = ary1['E']
ymax = ary1['F']
L = 1.25 * scale * abs(xmax - xmin)
W = scale * abs(ymax - ymin)
figure(figsize=(L, W), dpi=80)
#-------------------------------------------------------
# READING ELEMENTS
#-------------------------------------------------------
fname = 'sim/out/elems.txt'
ndtype = [int, int, int]
names = ["A", "B", "C"]
ary = np.genfromtxt(fname, names=names, dtype=ndtype)
p1 = ary['A']
p2 = ary['B']
p3 = ary['C']
elements = np.vstack((p1, p2, p3)).T
#-------------------------------------------------------
# PLOTTING DATA AND EXPORTING TO JPG
#-------------------------------------------------------
n = 1
while (num <= nt):
if num < 10:
fname = 'sim/out/'+var+'_txt/'+var+'00'+str(num)+'.txt'
if num < 100 and num >= 10:
fname = 'sim/out/'+var+'_txt/'+var+'0'+str(num)+'.txt'
if num >= 100:
fname = 'sim/out/'+var+'_txt/'+var+str(num)+'.txt'
ndtype = [float, float, float, float]
names = ["A", "B", "V", "D"]
ary = np.genfromtxt(fname, names=names, dtype=ndtype)
x = ary['A']
y = ary['B']
val = ary['D']
Nx = np.size(ary['A'])
if show_mesh == 1:
for element in elements:
px = [x[element[i]] for i in range(len(element))]
py = [y[element[i]] for i in range(len(element))]
plt.fill(px, py, edgecolor='black', fill=False)
tcf = plt.tricontourf(x, y, elements, val, cmap='jet')
#tcf = plt.tricontour(x, y, elements, val, cmap='RdBu_r', levels=[0.5])
plt.colorbar()
plt.title(var)
# OPTION 2.
#fig = plt.figure(figsize=plt.figaspect(1))
#ax = fig.add_subplot(projection='3d')
#ax.plot_trisurf(x, y, val, triangles=elements, cmap='RdBu_r')
#ax.view_init(90, -90)
plt.savefig('sim/out/'+var+'_jpg/'+var+str(n)+".jpg")
#if n < 10:
# plt.savefig('pictures/'+var+'_jpg/'+var+'0000'+str(n)+".jpg")
#if n < 100 and n >= 10:
# plt.savefig('pictures/'+var+'_jpg/'+var+'000'+str(n)+".jpg")
#if n < 1000 and n >= 100:
# plt.savefig('pictures/'+var+'_jpg/'+var+'00'+str(n)+".jpg")
#if n < 10000 and n >= 1000:
# plt.savefig('pictures/'+var+'_jpg/'+var+'0'+str(n)+".jpg")
#if n >= 10000:
# plt.savefig('pictures/'+var+'_jpg/'+var+str(n)+".jpg")
plt.clf()
n = n + 1
num = num + inc
v = v + 1