Skip to content

Commit

Permalink
[BUGFIX] Dimension update in LayoutOptimizationBase (#1067)
Browse files Browse the repository at this point in the history
* Add test for unusual limits

* Update index to reflect new 4D arrays in Floris v4.

* isort.

* Typo fix on axis labels.
  • Loading branch information
misi9170 authored Feb 21, 2025
1 parent a3a5b6e commit fd1b36d
Show file tree
Hide file tree
Showing 3 changed files with 72 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@
color="r",
marker="x",
)
ax.set_ylabel("Yaw Offset (deg")
ax.set_ylabel("Yaw Offset T{0:03d} (deg)".format(tindex))
ax.legend()
ax.grid(True)

Expand Down
10 changes: 5 additions & 5 deletions floris/optimization/yaw_optimization/yaw_optimization_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -260,14 +260,14 @@ def _reduce_control_problem(self):
# Find bounds closest to 0.0 deg
combined_bounds = np.concatenate(
(
np.expand_dims(minimum_yaw_angle_subset, axis=3),
np.expand_dims(maximum_yaw_angle_subset, axis=3)
np.expand_dims(minimum_yaw_angle_subset, axis=2),
np.expand_dims(maximum_yaw_angle_subset, axis=2)
),
axis=3
axis=2
)
# Overwrite all values that are not allowed to be 0.0 with bound value closest to zero
ids_closest = np.expand_dims(np.argmin(np.abs(combined_bounds), axis=3), axis=3)
yaw_mb = np.squeeze(np.take_along_axis(combined_bounds, ids_closest, axis=3))
ids_closest = np.expand_dims(np.argmin(np.abs(combined_bounds), axis=2), axis=2)
yaw_mb = np.squeeze(np.take_along_axis(combined_bounds, ids_closest, axis=2), axis=2)
yaw_angles_template_subset[idx] = yaw_mb[idx]

# Save all subset variables to self
Expand Down
66 changes: 66 additions & 0 deletions tests/yaw_optimization_integration_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
import numpy as np
import pandas as pd
import pytest

from floris import FlorisModel
from floris.optimization.yaw_optimization.yaw_optimizer_sr import YawOptimizationSR


DEBUG = False
VELOCITY_MODEL = "gauss"
DEFLECTION_MODEL = "gauss"

def test_yaw_optimization_limits(sample_inputs_fixture):
"""
The Serial Refine (SR) method optimizes yaw angles based on a sequential, iterative yaw
optimization scheme. This test compares the optimization results from the SR method for
a simple farm with a simple wind rose to stored baseline results.
"""
sample_inputs_fixture.core["wake"]["model_strings"]["velocity_model"] = VELOCITY_MODEL
sample_inputs_fixture.core["wake"]["model_strings"]["deflection_model"] = DEFLECTION_MODEL

fmodel = FlorisModel(sample_inputs_fixture.core)
wd_array = np.arange(0.0, 360.0, 90.0)
ws_array = 8.0 * np.ones_like(wd_array)
ti_array = 0.1 * np.ones_like(wd_array)

D = 126.0 # Rotor diameter for the NREL 5 MW
fmodel.set(
layout_x=[0.0, 5 * D, 10 * D],
layout_y=[0.0, 0.0, 0.0],
wind_directions=wd_array,
wind_speeds=ws_array,
turbulence_intensities=ti_array,
)

# Asymmetric limits
yaw_opt = YawOptimizationSR(
fmodel,
minimum_yaw_angle=-10.0,
maximum_yaw_angle=20.0,
)
yaw_opt.optimize()

# Strictly positive limits
yaw_opt = YawOptimizationSR(
fmodel,
minimum_yaw_angle=5.0,
maximum_yaw_angle=20.0,
)
yaw_opt.optimize()

# Strictly negative limits
yaw_opt = YawOptimizationSR(
fmodel,
minimum_yaw_angle=-20.0,
maximum_yaw_angle=-5.0,
)
yaw_opt.optimize()

# Infeasible limits
with pytest.raises(ValueError):
yaw_opt = YawOptimizationSR(
fmodel,
minimum_yaw_angle=20.0,
maximum_yaw_angle=5.0,
)

0 comments on commit fd1b36d

Please sign in to comment.