Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
# Define the speed ups of the heterogeneous inflow, and their locations.
# For the 2-dimensional case, this requires x and y locations.
# The speed ups are multipliers of the ambient wind speed.
speed_ups = [[2.0, 1.0, 2.0, 1.0]]
speed_ups = [[[2.0, 1.0, 2.0, 1.0]]] # Has the shape (n_wind_directions, n_wind_speeds, n_points)
x_locs = [-300.0, -300.0, 2600.0, 2600.0]
y_locs = [ -300.0, 300.0, -300.0, 300.0]

Expand Down Expand Up @@ -58,27 +58,28 @@
print(f'T1: {turbine_powers[1]:.1f} kW')
print()

# Since het maps are assigned for each wind direciton, it's allowable to change
# the number of wind speeds
fi.reinitialize(wind_speeds=[4, 8])
fi.calculate_wake()
turbine_powers = np.round(fi.get_turbine_powers() / 1000.)
print('With wind speeds now set to 4 and 8 m/s')
print(f'T0: {turbine_powers[:, :, 0].flatten()} kW')
print(f'T1: {turbine_powers[:, :, 1].flatten()} kW')
print()

# To change the number of wind directions however it is necessary to make a matching
# change to the dimensions of the het map
speed_multipliers = [[2.0, 1.0, 2.0, 1.0], [2.0, 1.0, 2.0, 1.0]] # Expand to two wind directions
speed_multipliers = [
[
[2.0, 1.0, 2.0, 1.0], # Wind direction 270, Wind speed 7.0, four locations (x,y)
[2.0, 1.0, 2.0, 1.0], # Wind direction 270, Wind speed 8.0, four locations (x,y)
[2.0, 1.0, 2.0, 1.0], # Wind direction 270, Wind speed 9.0, four locations (x,y)
],
[
[2.0, 1.0, 2.0, 1.0], # Wind direction 275, Wind speed 7.0, four locations (x,y)
[2.0, 1.0, 2.0, 1.0], # Wind direction 275, Wind speed 8.0, four locations (x,y)
[2.0, 1.0, 2.0, 1.0], # Wind direction 275, Wind speed 9.0, four locations (x,y)
],
]
heterogenous_inflow_config = {
'speed_multipliers': speed_multipliers,
'x': x_locs,
'y': y_locs,
}
fi.reinitialize(
wind_directions=[270.0, 275.0],
wind_speeds=[8.0],
wind_speeds=[7.0, 8.0, 9.0],
heterogenous_inflow_config=heterogenous_inflow_config
)
fi.calculate_wake()
Expand Down
8 changes: 4 additions & 4 deletions examples/inputs/gch_heterogeneous_inflow.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,10 @@ flow_field:
air_density: 1.225
heterogenous_inflow_config:
speed_multipliers:
- - 2.0
- 1.0
- 2.0
- 1.0
- - - 2.0
- 1.0
- 2.0
- 1.0
x:
- -300.
- -300.
Expand Down
44 changes: 29 additions & 15 deletions floris/simulation/flow_field.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,11 @@ def het_map_validator(self, instance: attrs.Attribute, value: list | None) -> No
"The het_map's wind direction dimension not equal to number of wind directions."
)

if self.n_wind_speeds!= np.array(value).shape[1]:
raise ValueError(
"The het_map's wind speed dimension not equal to number of wind speeds."
)


def __attrs_post_init__(self) -> None:
if self.heterogenous_inflow_config is not None:
Expand Down Expand Up @@ -163,13 +168,13 @@ def initialize_velocity_field(self, grid: Grid) -> None:
"fully cover the calculated flow field area."
)

if len(self.het_map[0].points[0]) == 2:
if len(self.het_map[0][0].points[0]) == 2:
speed_ups = self.calculate_speed_ups(
self.het_map,
grid.x_sorted_inertial_frame,
grid.y_sorted_inertial_frame
)
elif len(self.het_map[0].points[0]) == 3:
elif len(self.het_map[0][0].points[0]) == 3:
speed_ups = self.calculate_speed_ups(
self.het_map,
grid.x_sorted_inertial_frame,
Expand Down Expand Up @@ -240,21 +245,24 @@ def finalize(self, unsorted_indices):
)

def calculate_speed_ups(self, het_map, x, y, z=None):
speed_ups = np.ones_like(x)
n_wind_directions = np.shape(x)[0]
n_wind_speeds = np.shape(x)[1]

if z is not None:
# Calculate the 3-dimensional speed ups; squeeze is needed as the generator
# adds an extra dimension
speed_ups = np.squeeze(
[het_map[i](x[i:i+1], y[i:i+1], z[i:i+1]) for i in range( len(het_map))],
axis=1,
)
for wdii in range(n_wind_directions):
for wsii in range(n_wind_speeds):
speed_ups[wdii, wsii] = \
het_map[wdii][wsii](x[wdii, wsii], y[wdii, wsii], z[wdii, wsii])

else:
# Calculate the 2-dimensional speed ups; squeeze is needed as the generator
# adds an extra dimension
speed_ups = np.squeeze(
[het_map[i](x[i:i+1], y[i:i+1]) for i in range(len(het_map))],
axis=1,
)
for wdii in range(n_wind_directions):
for wsii in range(n_wind_speeds):
speed_ups[wdii, wsii] = het_map[wdii][wsii](x[wdii, wsii], y[wdii, wsii])

return speed_ups

Expand All @@ -275,7 +283,7 @@ def generate_heterogeneous_wind_map(self):
- **y**: A list of y locations at which the speed up factors are defined.
- **z** (optional): A list of z locations at which the speed up factors are defined.
"""
speed_multipliers = self.heterogenous_inflow_config['speed_multipliers']
all_multipliers = self.heterogenous_inflow_config['speed_multipliers']
x = self.heterogenous_inflow_config['x']
y = self.heterogenous_inflow_config['y']
z = self.heterogenous_inflow_config['z']
Expand All @@ -285,16 +293,22 @@ def generate_heterogeneous_wind_map(self):
# Linear interpolation is used for points within the user-defined area of values,
# while the freestream wind speed is used for points outside that region
in_region = [
LinearNDInterpolator(list(zip(x, y, z)), multiplier, fill_value=1.0)
for multiplier in speed_multipliers
[
LinearNDInterpolator(list(zip(x, y, z)), multiplier, fill_value=1.0)
for multiplier in single_winddirection_multipliers
]
for single_winddirection_multipliers in all_multipliers
]
else:
# Compute the 2-dimensional interpolants for each wind direction
# Linear interpolation is used for points within the user-defined area of values,
# while the freestream wind speed is used for points outside that region
in_region = [
LinearNDInterpolator(list(zip(x, y)), multiplier, fill_value=1.0)
for multiplier in speed_multipliers
[
LinearNDInterpolator(list(zip(x, y)), multiplier, fill_value=1.0)
for multiplier in single_winddirection_multipliers
]
for single_winddirection_multipliers in all_multipliers
]

self.het_map = in_region