From 397d93c38942a9b7630d05e413051742b28af1a4 Mon Sep 17 00:00:00 2001 From: misi9170 <39596329+misi9170@users.noreply.github.com> Date: Thu, 4 Apr 2024 11:39:37 -0400 Subject: [PATCH] Allow different turbine models as well as different power_thrust_models for each turbine. (#856) --- floris/floris_model.py | 35 ++++++++++++++++++++------ tests/floris_model_integration_test.py | 5 ++++ 2 files changed, 32 insertions(+), 8 deletions(-) diff --git a/floris/floris_model.py b/floris/floris_model.py index 7d964b84e..157c99ac2 100644 --- a/floris/floris_model.py +++ b/floris/floris_model.py @@ -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""" diff --git a/tests/floris_model_integration_test.py b/tests/floris_model_integration_test.py index 8975cdd07..7d4fcbc12 100644 --- a/tests/floris_model_integration_test.py +++ b/tests/floris_model_integration_test.py @@ -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"]