Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make set_operation method public #869

Merged
merged 2 commits into from
Apr 5, 2024
Merged
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
20 changes: 18 additions & 2 deletions floris/floris_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ def _reinitialize(
# Create a new instance of floris and attach to self
self.core = Core.from_dict(floris_dict)

def _set_operation(
def set_operation(
self,
yaw_angles: NDArrayFloat | list[float] | None = None,
power_setpoints: NDArrayFloat | list[float] | list[float, None] | None = None,
Expand All @@ -238,6 +238,9 @@ def _set_operation(
"""
Apply operating setpoints to the floris object.

This function is not meant to be called directly by most users---users should instead call
the set() method.

Args:
yaw_angles (NDArrayFloat | list[float] | None, optional): Turbine yaw angles. Defaults
to None.
Expand All @@ -248,9 +251,19 @@ def _set_operation(
"""
# Add operating conditions to the floris object
if yaw_angles is not None:
if np.array(yaw_angles).shape[1] != self.core.farm.n_turbines:
raise ValueError(
f"yaw_angles has a size of {np.array(yaw_angles).shape[1]} in the 1st "
f"dimension, must be equal to n_turbines={self.core.farm.n_turbines}"
)
self.core.farm.set_yaw_angles(yaw_angles)

if power_setpoints is not None:
if np.array(power_setpoints).shape[1] != self.core.farm.n_turbines:
raise ValueError(
f"power_setpoints has a size of {np.array(power_setpoints).shape[1]} in the 1st"
f" dimension, must be equal to n_turbines={self.core.farm.n_turbines}"
)
power_setpoints = np.array(power_setpoints)

# Convert any None values to the default power setpoint
Expand Down Expand Up @@ -288,6 +301,9 @@ def _set_operation(
self.core.farm.yaw_angles[disable_turbines] = 0.0
self.core.farm.power_setpoints[disable_turbines] = POWER_SETPOINT_DISABLED

if any([yaw_angles is not None, power_setpoints is not None, disable_turbines is not None]):
self.core.state = State.UNINITIALIZED

def set(
self,
wind_speeds: list[float] | NDArrayFloat | None = None,
Expand Down Expand Up @@ -372,7 +388,7 @@ def set(
self.core.farm.set_power_setpoints(_power_setpoints)

# Set the operation
self._set_operation(
self.set_operation(
yaw_angles=yaw_angles,
power_setpoints=power_setpoints,
disable_turbines=disable_turbines,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ def _obj_func(self, locs):
self._change_coordinates(locs_unnorm)
# Compute turbine yaw angles using PJ's geometric code (if enabled)
yaw_angles = self._get_geoyaw_angles()
self.fmodel.set(yaw_angles=yaw_angles)
self.fmodel.set_operation(yaw_angles=yaw_angles)
self.fmodel.run()

if self.use_value:
Expand Down
23 changes: 23 additions & 0 deletions tests/floris_model_integration_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -682,3 +682,26 @@ def test_set_operation_model():
fmodel.set(layout_x=[0, 0], layout_y=[0, 1000])
with pytest.raises(ValueError):
fmodel.set(layout_x=[0, 0, 0], layout_y=[0, 1000, 2000])

def test_set_operation():
fmodel = FlorisModel(configuration=YAML_INPUT)
fmodel.set(layout_x=[0, 0], layout_y=[0, 1000])

# Check that not allowed to run(), then set_operation, then collect powers
fmodel.run()
fmodel.set_operation(yaw_angles=np.array([[25.0, 0.0]]))
with pytest.raises(RuntimeError):
fmodel.get_turbine_powers()

# Check that no issue if run is called first
fmodel.run()
fmodel.get_turbine_powers()

# Check that if arguments do not match number of turbines, raises error
with pytest.raises(ValueError):
fmodel.set_operation(yaw_angles=np.array([[25.0, 0.0, 20.0]]))

# Check that if arguments do not match n_findex, raises error
with pytest.raises(ValueError):
fmodel.set_operation(yaw_angles=np.array([[25.0, 0.0], [25.0, 0.0]]))
fmodel.run()
Loading