-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplottools.py
177 lines (136 loc) · 6.06 KB
/
plottools.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
#!/bin/python3
"""
Created by Jeffrey Johnston. Jun, 2023.
"""
import logging
from pathlib import Path
import numpy as np
import matplotlib.pyplot as plt
import utils
import waketools
def check_power(case_dir: Path, convergence_dir: Path) -> None:
plt.ioff()
plt.rc('font', size=11)
fig, ax = plt.subplots(figsize=(7,2.6), dpi=200, layout='constrained')
colors = iter([plt.cm.Set2(i) for i in range(8)])
ax.plot(data[:,1], data[:,3]/1e6, alpha=0.3, c=(next(colors)))
ax.plot(data[:,1], average/1e6, c=(next(colors)))
for tolerance in tolerances:
ymin = average[-1]/1e6*(1-tolerance/100)
ymax = average[-1]/1e6*(1+tolerance/100)
solid_color = next(colors)
trans_color = list(solid_color)
trans_color[-1] = 0.5
ax.axhspan(ymin, ymax, edgecolor=solid_color, facecolor=trans_color, linewidth=0.3)
#plt.xlim(left=60000)
#plt.ylim([0.1,0.3])
#plt.yticks(np.arange(0,3,1))
plt.xlabel("Time (s)")
plt.ylabel("Aerodynamic Power (MW)")
ax.spines['top'].set_visible(False)
ax.spines['right'].set_visible(False)
legend_labels = ["Raw Power", "Time-average"]
for tolerance in tolerances:
legend_labels.append(f'{tolerance}% tolerance band')
ax.legend(labels=legend_labels, bbox_to_anchor=(1,0.5), loc="center left")
#for i, tolerance in enumerate(tolerances):
# plt.annotate(f'{tolerance}%', (*tolerance_xy[i,:],))
plt.grid()
plt.savefig(str(convergence_dir/"power.png"))
if __name__=='__main__':
#utils.configure_logger(filename=f'log.{__name__}')
logger = logging.getLogger(__name__)
logger.setLevel(logging.INFO)
TURBINE_CASE = 't007'
PRECURSOR_CASE = 'p005'
CASES_DIR = Path('/mnt/scratch2/users/40146600')
TURBINE_CASE_DIR = CASES_DIR / TURBINE_CASE
PRECURSOR_CASE_DIR = CASES_DIR / PRECURSOR_CASE
TURBINE_CASE_FILE = TURBINE_CASE_DIR/f'{TURBINE_CASE}.foam'
SOWFATOOLS_DIR = TURBINE_CASE_DIR / 'postProcessing/sowfatools'
SOWFAPLOTS_DIR = TURBINE_CASE_DIR / 'postProcessing/sowfaplots'
logger.debug(f'Creating directory {SOWFAPLOTS_DIR}')
SOWFAPLOTS_DIR.mkdir(parents=True, exist_ok=True)
TURBINE_TIP_RADIUS = 63.0
TURBINE_DIAMETER = 2 * TURBINE_TIP_RADIUS
TURBINE_HUB_HEIGHT = 90.0
TURBINE_BASE_COORDINATES = (1118.0, 1280.0)
# incoming wind direction in degrees clockwise from North
WIND_DIRECTION = np.radians(240)
DOMAIN_HEIGHT = 1000
CELLARRAYS = [
'U', 'UAvg',
'Uprime', 'uRMS', 'uuPrime2',
'p_rgh', 'p_rghAvg',
'T', 'TAvg',
'Tprime', 'TRMS', 'TTPrime2', 'uTPrime2',
'Rmean', 'qmean',
'kResolved', 'kSGS', 'kSGSmean',
'bodyForce',
'Rwall', 'qwall',
'SourceT', 'SourceU',
'T_0', 'U_0',
'epsilonSGSmean', 'kappat', 'nuSGSmean', 'nuSgs',
'omega', 'omegaAvg',
'Q'
]
turbine_origin = np.array([*TURBINE_BASE_COORDINATES, TURBINE_HUB_HEIGHT])
turbine_radius = TURBINE_TIP_RADIUS
wind_vector = np.array([-np.sin(WIND_DIRECTION),
-np.cos(WIND_DIRECTION),
0])
rangetoplot = range(-5,8)
plt.ioff()
plt.rc('font', size=11)
fig, axes = plt.subplots(1, 13, squeeze=True, sharey=True, sharex=True,
layout="constrained", figsize=[20,5], dpi=600)
for ax in axes:
ax.spines['top'].set_visible(False)
ax.spines['right'].set_visible(False)
ax.tick_params(bottom=False, labelbottom=False)
for ax in axes[1:]:
ax.spines['left'].set_visible(False)
ax.tick_params(left=False)
a, u0, ur = waketools.calculate_induction((SOWFATOOLS_DIR
/ f'{TURBINE_CASE}_turbineInte gratedWake-5D'),
(SOWFATOOLS_DIR
/ f'{TURBINE_CASE}_turbineInte gratedWake0D'),
wind_vector)
a = 1 - ur/8
u0 = 8
for i in range(-5,8):
label = f"{i}D"
data = np.genfromtxt((SOWFATOOLS_DIR
/f'{TURBINE_CASE}_verticaLineSample_{label}.csv'), dtype=float, delimiter=',',
names=True)
velocity = np.column_stack((data['UAvg0'], data['UAvg1'], data['UAvg2']))
#import pdb; pdb.set_trace()
sw_velocity = []
for vel in velocity:
sw_velocity.append(np.linalg.norm(np.dot(vel, wind_vector)))
sw_velocity = np.array(sw_velocity)
#sw_velocity = np.apply_along_axis(np.dot, 1, velocity, wind_vector)
axes[i+5].plot(sw_velocity, data['Points2'])
top = TURBINE_HUB_HEIGHT + TURBINE_TIP_RADIUS
bottom = TURBINE_HUB_HEIGHT - TURBINE_TIP_RADIUS
axes[i+5].vlines(ur, bottom, top, color='red')
axes[i+5].text(ur, top, f'{ur:.1f}', ha='right', va='bottom',
color='red')
alpha = 0.05
if i >= 1:
jensenvelocity = (u0 * (1 - (2*a) / (1 + 2*alpha*i)**2))
import pdb; pdb.set_trace()
rw = TURBINE_DIAMETER * (1 + 2*alpha*i) / 2
jensenbottom = TURBINE_HUB_HEIGHT - rw
jensentop = TURBINE_HUB_HEIGHT + rw
axes[i+5].vlines(jensenvelocity, jensenbottom, jensentop, color='green')
axes[i+5].text(jensenvelocity, 60, f'{jensenvelocity:.1f}', ha='left',
va='top', color='green')
plt.ylim(0,250)
# plt.xlabel("Vel (s)")
# plt.ylabel("Aerodynamic Power (MW)")
# legend_labels = ["Raw Power", "Time-average"]
# ax.legend(labels=legend_labels, bbox_to_anchor=(1,0.5), loc="center left")
# plt.savefig(SOWFAPLOTS_DIR/f'{TURBINE_CASE}_horizontalwakeprofile.png')
plt.savefig(SOWFAPLOTS_DIR/f'{TURBINE_CASE}_verticalwakeprofile.png')
logger.info("Finished")