-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathfunctions_graphics.py
248 lines (201 loc) · 10.9 KB
/
functions_graphics.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
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
import os
import matplotlib.pyplot as plt
import numpy as np
# Global figure variable
# This is to make sure each plot is drawn in a new window, no matter which plotting methods are used
n_fig = 1
def basic_xy(x,y,color='b'):
global n_fig
figure = plt.figure(n_fig)
figure.add_subplot(1, 1, 1, axisbg='1') # Change background color here
plt.gca().set_aspect('equal')
plt.plot(x,y,color)
plt.show()
# time.sleep(5)
n_fig += 1
def body_wake_plot(Swimmers):
global n_fig
figure = plt.figure(n_fig)
plt.clf()
figure.add_subplot(1, 1, 1, axisbg='1') # Change background color here
plt.gca().set_aspect('equal')
maxpercentile = 95 # For truncating outliers
# Gather circulations of all swimmers into a color array
color = []
for Swim in Swimmers:
Swim.n_color = len(Swim.Wake.gamma[1:-1])
color = np.append(color, Swim.Wake.gamma[1:-1])
Swim.i_color = len(color)-Swim.n_color
# Make color map based on vorticity
# Take a look at positive and negative circulations separately
if np.min(color) < 0: # Check if negative circulations exist (in case of short simulations)
# Truncate any negative outliers
color[color < np.percentile(color[color < 0], 100-maxpercentile)] = np.percentile(color[color < 0], 100-maxpercentile)
# Normalize negative circulations to [-1,0)
color[color < 0] = -color[color < 0]/np.min(color)
if np.max(color) > 0: # Check if positive circulations exist (in case of short simulations)
# Truncate any positive outliers
color[color > np.percentile(color[color > 0], maxpercentile)] = np.percentile(color[color > 0], maxpercentile)
# Normalize positive circulations to (0,1]
color[color > 0] = color[color > 0]/np.max(color)
for Swim in Swimmers:
# Extract color map for the individual Swim
c = color[Swim.i_color:Swim.i_color+Swim.n_color]
# Scatter plot of wake points with red-white-blue colormap, as well as body outline and edge panel segment
plt.scatter(Swim.Wake.x[1:-1], Swim.Wake.z[1:-1], s=30, c=c, edgecolors='none', cmap=plt.get_cmap('bwr_r'))
plt.plot(Swim.Body.AF.x, Swim.Body.AF.z, 'k')
plt.plot(Swim.Edge.x, Swim.Edge.z, 'g')
plt.show()
n_fig += 1
def cp_plot(Swimmers, i, SW_PLOT_FIG):
global n_fig
if SW_PLOT_FIG:
cp_scale = 1000
figure = plt.figure(1)
figure.add_subplot(1, 1, 1, axisbg='1') # Change background color here
# plt.gca().set_aspect('equal')
plt.gca().invert_yaxis()
maxpercentile = 95 # For truncating outliers
if (i > 1):
# Gather circulations of all swimmers into a color array
color = []
for Swim in Swimmers:
Swim.n_color = len(Swim.Wake.gamma[1:i])
color = np.append(color, Swim.Wake.gamma[1:i])
Swim.i_color = len(color)-Swim.n_color
# Make color map based on vorticity
# Take a look at positive and negative circulations separately
if np.min(color) < 0: # Check if negative circulations exist (in case of short simulations)
# Truncate any negative outliers
color[color < np.percentile(color[color < 0], 100-maxpercentile)] = np.percentile(color[color < 0], 100-maxpercentile)
# Normalize negative circulations to [-1,0)
color[color < 0] = -color[color < 0]/np.min(color)
if np.max(color) > 0: # Check if positive circulations exist (in case of short simulations)
# Truncate any positive outliers
color[color > np.percentile(color[color > 0], maxpercentile)] = np.percentile(color[color > 0], maxpercentile)
# Normalize positive circulations to (0,1]
color[color > 0] = color[color > 0]/np.max(color)
for Swim in Swimmers:
# if (i > 1):
# # Extract color map for the individual Swim
# c = color[Swim.i_color:Swim.i_color+Swim.n_color]
# # Scatter plot of wake points with red-white-blue colormap, as well as body outline and edge panel segment
# # for idx in xrange(i):
# plt.scatter(Swim.Wake.x[1:i], Swim.Wake.z[1:i], s=30, c=c, edgecolors='none', cmap=plt.get_cmap('bwr_r'))
# # plt.scatter(Swim.Wake.x[1:-1], Swim.Wake.z[1:-1], s=30, c=c, edgecolors='none', cmap=plt.get_cmap('bwr_r'))
# plt.plot(Swim.Body.AF.x, Swim.Body.AF.z, 'k')
# plt.plot(Swim.Edge.x, Swim.Edge.z, 'g')
plt.plot(Swim.Body.BF.x_col[:Swim.Body.N/2], Swim.Body.cp[:Swim.Body.N/2]/cp_scale, 'g')
plt.plot(Swim.Body.BF.x_col[Swim.Body.N/2:], Swim.Body.cp[Swim.Body.N/2:]/cp_scale, 'b')
# plt.axis([np.min(Swim.Body.AF.x)-0.01, np.min(Swim.Body.AF.x)+0.13, -0.06, 0.06])
plt.axis([np.min(Swim.Body.BF.x)+0.108, np.min(Swim.Body.BF.x)+0.13, -0.2, 0.1])
plt.xlabel('$X$ $[m]$', fontsize=14)
plt.ylabel('$Z$ $[m]$ $or$ $C_p$ x$10^{-2}$ $[-]$', fontsize=14)
figure.savefig('./movies/%05i.png' % (n_fig), format='png')
plt.clf()
n_fig += 1
def drag_vs_period(Body,RHO,t):
global n_fig
figure = plt.figure(n_fig)
figure.add_subplot(1, 1, 1, axisbg='1') # Change background color here
plt.xlabel('tau')
plt.ylabel('Coefficent of drag')
plt.plot(t[4:]*Body.F, -Body.drag[3:]/(0.5*RHO*Body.V0**2), 'b')
n_fig += 1
def lift_vs_period(Body,RHO,t):
global n_fig
figure = plt.figure(n_fig)
figure.add_subplot(1, 1, 1, axisbg='1') # Change background color here
plt.xlabel('tau')
plt.ylabel('Coefficent of lift')
# plt.plot(t[4:]*Body.F, -Body.lift[3:]/(0.5*RHO*Body.V0**2), 'g')
plt.plot(t[4:], Body.Cl[3:] * (0.5 * RHO * np.abs(Body.V0)**2 * 0.1 * 1), 'g')
n_fig += 1
#def plot_n_go(Edge, Body, Solid, V0, T, HEAVE):
def plot_n_go(Swimmers, i, P):
global n_fig
if P['SW_PLOT_FIG']:
figure = plt.figure(1)
figure.add_subplot(1, 1, 1, axisbg='1') # Change background color here
figure.set_size_inches(16, 9)
plt.gca().set_aspect('equal')
plt.tick_params(labelsize=28)
plt.xticks(np.arange(P['X_TICKS'][0], P['X_TICKS'][1], P['X_TICKS'][2]))
maxpercentile = 95 # For truncating outliers
if (i > 1):
# Gather circulations of all swimmers into a color array
color = []
for Swim in Swimmers:
Swim.n_color = len(Swim.Wake.gamma[1:i])
color = np.append(color, Swim.Wake.gamma[1:i])
Swim.i_color = len(color)-Swim.n_color
# Make color map based on vorticity
# Take a look at positive and negative circulations separately
if np.min(color) < 0: # Check if negative circulations exist (in case of short simulations)
# Truncate any negative outliers
color[color < np.percentile(color[color < 0], 100-maxpercentile)] = np.percentile(color[color < 0], 100-maxpercentile)
# Normalize negative circulations to [-1,0)
color[color < 0] = -color[color < 0]/np.min(color)
if np.max(color) > 0: # Check if positive circulations exist (in case of short simulations)
# Truncate any positive outliers
color[color > np.percentile(color[color > 0], maxpercentile)] = np.percentile(color[color > 0], maxpercentile)
# Normalize positive circulations to (0,1]
color[color > 0] = color[color > 0]/np.max(color)
for Swim in Swimmers:
if (i > 1):
# Extract color map for the individual Swim
c = color[Swim.i_color:Swim.i_color+Swim.n_color]
# Scatter plot of wake points with red-white-blue colormap, as well as body outline and edge panel segment
plt.scatter(Swim.Wake.x[1:i], Swim.Wake.z[1:i], s=30, c=c, edgecolors='none', cmap=plt.get_cmap('bwr_r'))
plt.plot(Swim.Body.AF.x, Swim.Body.AF.z, 'k')
plt.plot(Swim.Edge.x, Swim.Edge.z, 'g')
# Determine if the output directory exists. If not, create the directory.
if not os.path.exists('./movies'):
os.makedirs('./movies')
plt.axis([np.min(Swim.Body.AF.x)+P['X_FIELD'][0], np.min(Swim.Body.AF.x)+P['X_FIELD'][1], P['Z_FIELD'][0], P['Z_FIELD'][1]])
plt.xlabel('$X$ $[m]$', fontsize=28)
plt.ylabel('$Z$ $[m]$', fontsize=28)
plt.axes([0.13, 0.677, 0.2, 0.2])
plt.gca().set_aspect('equal')
plt.gca().axes.get_xaxis().set_visible(False)
plt.gca().axes.get_yaxis().set_visible(False)
plt.axis([np.min(Swim.Body.AF.x)+P['X_BODY'][0], np.min(Swim.Body.AF.x)+P['X_BODY'][1], P['Z_BODY'][0], P['Z_BODY'][1]])
for Swim in Swimmers:
if (i > 1):
# Extract color map for the individual Swim
c = color[Swim.i_color:Swim.i_color+Swim.n_color]
# Scatter plot of wake points with red-white-blue colormap, as well as body outline and edge panel segment
plt.scatter(Swim.Wake.x[1:i], Swim.Wake.z[1:i], s=30, c=c, edgecolors='none', cmap=plt.get_cmap('bwr_r'))
plt.plot(Swim.Body.AF.x, Swim.Body.AF.z, 'k')
plt.plot(Swim.Edge.x, Swim.Edge.z, 'g')
figure.savefig('./movies/%05i.png' % (n_fig), format='png')
plt.clf()
n_fig += 1
def body_plot(Edge, Body):
global n_fig
# Determine if the output directory exists. If not, create the directory.
if not os.path.exists('./movies'):
os.makedirs('./movies')
figure = plt.figure(1)
figure.add_subplot(1, 1, 1, axisbg='1') # Change background color here
plt.gca().set_aspect('equal')
plt.gca().axes.get_xaxis().set_visible(False)
plt.gca().axes.get_yaxis().set_visible(False)
plt.box(on='off')
# plt.plot(Body.AF.x_col[:Body.N/2], Body.cp[:Body.N/2]/100, 'g')
# plt.plot(Body.AF.x_col[Body.N/2:], Body.cp[Body.N/2:]/100, 'b')
plt.plot(Body.AF.x, Body.AF.z, 'k')
plt.xlim((np.min(Body.AF.x)-0.125, np.min(Body.AF.x)+0.125))
plt.plot(Edge.x, Edge.z, 'g')
plt.ylim((-0.05, 0.05))
figure.savefig('./movies/%05i.png' % (n_fig), format='png')
plt.clf()
n_fig += 1
def body(x,y,color='b'):
figure = plt.figure(2)
figure.add_subplot(1, 1, 1, axisbg='1') # Change background color here
plt.gca().set_aspect('equal')
plt.plot(x,y,color)
plt.xlim((np.min(x)-0.02, np.min(x)+0.22))
plt.ylim((-0.05, 0.05))
plt.show()