Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
dist_top = np.sqrt((coord.x1 - x_locations) ** 2 + ((coord.x2) - y_locations) ** 2 + (
z_locations - (turbine.hub_height + D / 2)) ** 2)
idx_top = np.where(dist_top == np.min(dist_top))
# bottom point of the rotor
dist_bottom = np.sqrt((coord.x1 - x_locations) ** 2 + ((coord.x2) - y_locations) ** 2 + (
z_locations - (turbine.hub_height - D / 2)) ** 2)
idx_bottom = np.where(dist_bottom == np.min(dist_bottom))
if len(idx_top) > 1:
idx_top = idx_top[0]
if len(idx_bottom) > 1:
idx_bottom = idx_bottom[0]
scale = 1.0
Gamma_top = scale * (np.pi / 8) * rho * D * turbine.average_velocity * Ct * sind(yaw) * cosd(yaw) ** 2
Gamma_bottom = scale*(np.pi/8) * rho * D * turbine.average_velocity * Ct * sind(yaw) * cosd(yaw)**2
Gamma_wake_rotation = 0.5 * 2 * np.pi * D * (aI - aI ** 2) * turbine.average_velocity / TSR
# compute the spanwise and vertical velocities induced by yaw
# Use set value
eps = self.eps_gain * D
# decay the vortices as they move downstream - using mixing length
lmda = D/8 #D/4 #D/4 #D/2
kappa = 0.41
lm = kappa * z_locations / (1 + kappa * z_locations / lmda)
z = np.linspace(np.min(z_locations),np.max(z_locations),np.shape(flow_field.u_initial)[2])
dudz_initial = np.gradient(flow_field.u_initial, z, axis=2)
nu = lm ** 2 * np.abs(dudz_initial[0, :, :])
# top vortex
velDef[x_locations < xR] = 0
velDef[x_locations > x0] = 0
# wake expansion in the lateral (y) and the vertical (z)
sigma_y = ky * (x_locations - x0) + sigma_y0
sigma_z = kz * (x_locations - x0) + sigma_z0
sigma_y[x_locations < x0] = sigma_y0[x_locations < x0]
sigma_z[x_locations < x0] = sigma_z0[x_locations < x0]
# velocity deficit outside the near wake
a = (cosd(veer)**2) / (2 * sigma_y**2) + \
(sind(veer)**2) / (2 * sigma_z**2)
b = -(sind(2 * veer)) / (4 * sigma_y**2) + \
(sind(2 * veer)) / (4 * sigma_z**2)
c = (sind(veer)**2) / (2 * sigma_y**2) + \
(cosd(veer)**2) / (2 * sigma_z**2)
totGauss = np.exp(-(a * ((y_locations - turbine_coord.x2) - delta)**2 \
- 2 * b * ((y_locations - turbine_coord.x2) - delta) \
* ((z_locations - HH)) + c * ((z_locations - HH))**2))
# compute velocities in the far wake
velDef1 = (U_local * (1 - np.sqrt(1 - ((Ct * cosd(yaw)) \
/ (8.0 * sigma_y * sigma_z / D**2)))) * totGauss)
velDef1[x_locations < x0] = 0
# TEMP HACK: Store some variables for inspection
# self.sigma_tilde = np.sqrt((sigma_y/D)**2 + (sigma_z/D)**2)
self.sigma_tilde = np.sqrt((sigma_y/D) * (sigma_z/D))
self.n = 2 * np.ones_like(self.sigma_tilde) # Always 2 for gauss
self.beta_out = np.ones_like(self.sigma_tilde) * sigma_y0 /D
for k in range(len(zt)):
x_grid[i, j, k] = xt[i]
y_grid[i, j, k] = yt[j]
z_grid[i, j, k] = zt[k]
xoffset = x_grid[i, j, k] - coord.x1
yoffset = y_grid[i, j, k] - coord.x2
x_grid[i, j, k] = (
xoffset * cosd(-1 * self.wind_map.turbine_wind_direction[i])
- yoffset * sind(-1 * self.wind_map.turbine_wind_direction[i])
+ coord.x1
)
y_grid[i, j, k] = (
yoffset * cosd(-1 * self.wind_map.turbine_wind_direction[i])
+ xoffset * sind(-1 * self.wind_map.turbine_wind_direction[i])
+ coord.x2
)
return x_grid, y_grid, z_grid
def _rotated_grid(self, angle, center_of_rotation):
"""
Rotate the discrete flow field grid.
"""
xoffset = self.x - center_of_rotation.x1
yoffset = self.y - center_of_rotation.x2
rotated_x = (
xoffset * cosd(angle) - yoffset * sind(angle) + center_of_rotation.x1
)
rotated_y = (
xoffset * sind(angle) + yoffset * cosd(angle) + center_of_rotation.x2
)
return rotated_x, rotated_y, self.z
yR = y_locations - turbine_coord.x2
xR = yR * tand(yaw) + turbine_coord.x1
# velocity deficit in the near wake
sigma_y = (((x0 - xR) - (x_locations - xR)) / (x0 - xR)) * 0.501 * \
D * np.sqrt(Ct / 2.) + ((x_locations - xR) / (x0 - xR)) * sigma_y0
sigma_z = (((x0 - xR) - (x_locations - xR)) / (x0 - xR)) * 0.501 * \
D * np.sqrt(Ct / 2.) + ((x_locations - xR) / (x0 - xR)) * sigma_z0
sigma_y[x_locations < xR] = 0.5 * D
sigma_z[x_locations < xR] = 0.5 * D
a = (cosd(veer)**2) / (2 * sigma_y**2) + \
(sind(veer)**2) / (2 * sigma_z**2)
b = -(sind(2 * veer)) / (4 * sigma_y**2) + \
(sind(2 * veer)) / (4 * sigma_z**2)
c = (sind(veer)**2) / (2 * sigma_y**2) + \
(cosd(veer)**2) / (2 * sigma_z**2)
totGauss = np.exp(-(a * ((y_locations - turbine_coord.x2) - delta)**2 \
- 2 * b * ((y_locations - turbine_coord.x2) - delta) \
* ((z_locations - HH)) + c * ((z_locations - HH))**2))
velDef = (U_local * (1 - np.sqrt(1 - ((Ct * cosd(yaw)) \
/ (8.0 * sigma_y * sigma_z / D**2)))) * totGauss)
velDef[x_locations < xR] = 0
velDef[x_locations > x0] = 0
# wake expansion in the lateral (y) and the vertical (z)
sigma_y = ky * (x_locations - x0) + sigma_y0
sigma_z = kz * (x_locations - x0) + sigma_z0
sigma_y[x_locations < x0] = sigma_y0[x_locations < x0]
)
+ turbine_coord.x1
)
# velocity deficit in the near wake
sigma_y = (((x0 - xR) - (x_locations - xR)) / (x0 - xR)) * 0.501 * D * np.sqrt(
Ct / 2.0
) + ((x_locations - xR) / (x0 - xR)) * sigma_y0
sigma_z = (((x0 - xR) - (x_locations - xR)) / (x0 - xR)) * 0.501 * D * np.sqrt(
Ct / 2.0
) + ((x_locations - xR) / (x0 - xR)) * sigma_z0
sigma_y[x_locations < xR] = 0.5 * D
sigma_z[x_locations < xR] = 0.5 * D
a = cosd(veer) ** 2 / (2 * sigma_y ** 2) + sind(veer) ** 2 / (2 * sigma_z ** 2)
b = -sind(2 * veer) / (4 * sigma_y ** 2) + sind(2 * veer) / (4 * sigma_z ** 2)
c = sind(veer) ** 2 / (2 * sigma_y ** 2) + cosd(veer) ** 2 / (2 * sigma_z ** 2)
r = (
a * ((y_locations - turbine_coord.x2) - delta) ** 2
- 2 * b * ((y_locations - turbine_coord.x2) - delta) * ((z_locations - HH))
+ c * ((z_locations - HH)) ** 2
)
C = 1 - np.sqrt(1 - (Ct * cosd(yaw) / (8.0 * sigma_y * sigma_z / D ** 2)))
velDef = GaussianModel.gaussian_function(U_local, C, r, 1, np.sqrt(0.5))
velDef[x_locations < xR] = 0
velDef[x_locations > x0] = 0
# wake expansion in the lateral (y) and the vertical (z)
ky = self.ka * TI + self.kb # wake expansion parameters
kz = self.ka * TI + self.kb # wake expansion parameters
sigma_y = ky * (x_locations - x0) + sigma_y0
velDef = GaussianModel.gaussian_function(U_local, C, r, 1, np.sqrt(0.5))
velDef[x_locations < xR] = 0
velDef[x_locations > x0] = 0
# wake expansion in the lateral (y) and the vertical (z)
ky = self.ka * TI + self.kb # wake expansion parameters
kz = self.ka * TI + self.kb # wake expansion parameters
sigma_y = ky * (x_locations - x0) + sigma_y0
sigma_z = kz * (x_locations - x0) + sigma_z0
sigma_y[x_locations < x0] = sigma_y0[x_locations < x0]
sigma_z[x_locations < x0] = sigma_z0[x_locations < x0]
# velocity deficit outside the near wake
a = cosd(veer) ** 2 / (2 * sigma_y ** 2) + sind(veer) ** 2 / (2 * sigma_z ** 2)
b = -sind(2 * veer) / (4 * sigma_y ** 2) + sind(2 * veer) / (4 * sigma_z ** 2)
c = sind(veer) ** 2 / (2 * sigma_y ** 2) + cosd(veer) ** 2 / (2 * sigma_z ** 2)
r = (
a * (y_locations - turbine_coord.x2 - delta) ** 2
- 2 * b * (y_locations - turbine_coord.x2 - delta) * (z_locations - HH)
+ c * (z_locations - HH) ** 2
)
C = 1 - np.sqrt(1 - (Ct * cosd(yaw) / (8.0 * sigma_y * sigma_z / D ** 2)))
# compute velocities in the far wake
velDef1 = GaussianModel.gaussian_function(U_local, C, r, 1, np.sqrt(0.5))
velDef1[x_locations < x0] = 0
U = np.sqrt(velDef ** 2 + velDef1 ** 2)
return U, np.zeros(np.shape(velDef1)), np.zeros(np.shape(velDef1))