-
Notifications
You must be signed in to change notification settings - Fork 6
/
Animation.py
150 lines (106 loc) · 3.9 KB
/
Animation.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
import numpy as np,os,copy,sys
from functions import *
from contour import *
import matplotlib.pyplot as plt
import matplotlib.animation as animation
# def isfloat(value):
# try:
# float(value)
# return True
# except ValueError:
# return False
def Animation(Scalar_name,grid='no'):
def gridder(Scalar,Points,grid='no'):
if grid=='no':
Points=copy.deepcopy(Point_average(Points))
if Scalar_name=='U':
Scalar=copy.deepcopy(averaging(Scalar,1))
elif Scalar_name=='V':
Scalar=copy.deepcopy(averaging(Scalar,0))
else:
Scalar = copy.deepcopy(Scalar[1:-1,1:-1])
else:
if Scalar_name=='U':
Scalar=copy.deepcopy(averaging_grid(Scalar,1))
elif Scalar_name=='V':
Scalar=copy.deepcopy(averaging_grid(Scalar,0))
else:
Scalar = copy.deepcopy(average_scalar(Scalar))
return Scalar,Points
times=[]
times.append('0/')
files=os.listdir('Results')
counts=[]
for i in files:
if isfloat(i):
counts.append(float(i))
counts.sort()
k=0
for i in counts:
if k%10==0:
times.append('Results/'+'%.6f'%i)
# break
k+=1
# times.append('Results/'+i)
Scalars=[None]*len(times)
# print(times)
for t in range(len(times)):
Scalars[t]=read_scalar(times[t]+'/'+Scalar_name+'.txt')
# sys.exit()
# ax = plt.axes(xlim=(-15, 40), ylim=(-20,40))
# ax = plt.axes()
# ax.set(ylim=(0, 1), xlim=(0, 10))
contour_opts = {'levels': np.linspace(-9, 9, 10),
'cmap':'RdBu', 'lw': 2}
# cax = ax.contour([], [], [], **contour_opts)
# initialization function
def init():
# creating an empty plot/frame
ax.collections = []
# plt.ylabel(r'$y \longrightarrow$')
# plt.xlabel(r'$x \longrightarrow$')
ax.contour(Points[0], Points[1],np.zeros(Scalars[0].shape))
# return ax
# lists to store x and y axis points
# animation function
Points=read_points('Constant/Points.txt')
# i=5
# Scalar,Point=gridder(Scalars[i],Points,grid)
# print(Scalar,Point)
# print(Scalar.shape,Point.shape)
# fig=plt.figure()
# plt.contourf(Point[0],Point[1],Scalar)
# plt.show()
# plt.close()
# sys.exit()
fig = plt.figure()
xmin,xmax=min(Points[0][:,0]),max(Points[0][:,0])
ymin,ymax=np.min(Points[1][0,:]),np.max(Points[1][0,:])
ax = plt.axes(xlim=(xmin,xmax), ylim=(ymin,ymax))
#contour_opts = {'levels': np.linspace(-9, 9, 10),
# 'cmap':'RdBu', 'lw': 2}
Scalar,Point=gridder(Scalars[0],Points,grid)
# cax=ax.contourf(Point[0],Point[1],Scalar,cmap='coolwarm',vmin=np.min(Scalars),vmax=np.max(Scalars))
cmapp='gist_yarg'
cmapp='hot'
cax=ax.contourf(Point[0],Point[1],Scalar,100,cmap=cmapp,vmin=np.min(Scalars),vmax=np.max(Scalars))
def animate(i):
ax.collections=[]
#cbar=[],cax=[]
Scalar,Point=gridder(Scalars[i+1],Points,grid)
plt.gca().set_aspect('equal')
print(i)
cax=ax.contourf(Point[0], Point[1],Scalar,100,cmap=cmapp,vmin=np.min(Scalars),vmax=np.max(Scalars))#, **contour_opts)
anim = animation.FuncAnimation(fig, animate,frames=len(times)-1, interval=1)
# cbar = fig.colorbar(cax,orientation='horizontal')
plt.draw()
plt.show()
save={'bbox_inches=':'tight'}
# anim.save('%s.gif'%Scalar_name,savefig_kwargs=save,dpi=600)
#anim.save('%s.mp4'%Scalar_name,fps=10)
plt.close()
# plt.figure(figsize=(10,10))
#Animation('T','yes')
# Animation('U','yes')
# Animation('phi','yes')
# Animation('T','yes')