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

[BUGFIX] hardcoded reset to first turbine type in set_operation_model #856

Merged
merged 2 commits into from
Apr 4, 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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
35 changes: 27 additions & 8 deletions floris/floris_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -1288,22 +1288,41 @@ def assign_hub_height_to_ref_height(self):
self.core.flow_field.reference_wind_height = unique_heights[0]

def get_operation_model(self) -> str:
"""Get the power thrust model of a FlorisModel.
"""Get the operation model of a FlorisModel.

Returns:
str: The operation_model.
"""
return self.core.farm.turbine_definitions[0]["operation_model"]
operation_models = [
self.core.farm.turbine_definitions[tindex]["operation_model"]
for tindex in range(self.core.farm.n_turbines)
]
if len(set(operation_models)) == 1:
return operation_models[0]
else:
return operation_models

def set_operation_model(self, operation_model: str):
"""Set the power thrust model of a FlorisModel.
def set_operation_model(self, operation_model: str | List[str]):
"""Set the turbine operation model(s).

Args:
operation_model (str): The power thrust model to set.
operation_model (str): The operation model to set.
"""
turbine_type = self.core.farm.turbine_definitions[0]
turbine_type["operation_model"] = operation_model
self.set(turbine_type=[turbine_type])
if isinstance(operation_model, str):
operation_model = [operation_model]*self.core.farm.n_turbines
elif len(operation_model) != self.core.farm.n_turbines:
raise ValueError(
"The length of the operation_model list must be equal to the number of turbines."
)

turbine_type_list = self.core.farm.turbine_definitions
for tindex in range(self.core.farm.n_turbines):
turbine_type_list[tindex]["turbine_type"] = (
turbine_type_list[tindex]["turbine_type"]+"_"+operation_model[tindex]
)
turbine_type_list[tindex]["operation_model"] = operation_model[tindex]

self.set(turbine_type=turbine_type_list)

def copy(self):
"""Create an independent copy of the current FlorisModel object"""
Expand Down
5 changes: 5 additions & 0 deletions tests/floris_model_integration_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -586,3 +586,8 @@ def test_set_operation_model():
fmodel = FlorisModel(configuration=YAML_INPUT)
fmodel.set_operation_model("simple-derating")
assert fmodel.get_operation_model() == "simple-derating"

# Check multiple turbine types works
fmodel.set(layout_x=[0, 0], layout_y=[0, 1000])
fmodel.set_operation_model(["simple-derating", "cosine-loss"])
assert fmodel.get_operation_model() == ["simple-derating", "cosine-loss"]