From f0c95cbfba5f4039db5ea3a9a8fd23b13438a0be Mon Sep 17 00:00:00 2001 From: misi9170 Date: Wed, 27 Mar 2024 09:50:30 -0600 Subject: [PATCH] Allow different turbine models as well as different power_thrust_models for each turbine. --- floris/floris_model.py | 31 +++++++++++++++++++++----- tests/floris_model_integration_test.py | 5 +++++ 2 files changed, 30 insertions(+), 6 deletions(-) diff --git a/floris/floris_model.py b/floris/floris_model.py index 548f2e9f6..3df65a5e7 100644 --- a/floris/floris_model.py +++ b/floris/floris_model.py @@ -1293,17 +1293,36 @@ def get_power_thrust_model(self) -> str: Returns: str: The power_thrust_model. """ - return self.core.farm.turbine_definitions[0]["power_thrust_model"] + power_thrust_models = [ + self.core.farm.turbine_definitions[tindex]["power_thrust_model"] + for tindex in range(self.core.farm.n_turbines) + ] + if len(set(power_thrust_models)) == 1: + return power_thrust_models[0] + else: + return power_thrust_models - def set_power_thrust_model(self, power_thrust_model: str): - """Set the power thrust model of a FlorisModel. + def set_power_thrust_model(self, power_thrust_model: str | List[str]): + """Set the turbine power thrust model(s). Args: power_thrust_model (str): The power thrust model to set. """ - turbine_type = self.core.farm.turbine_definitions[0] - turbine_type["power_thrust_model"] = power_thrust_model - self.set(turbine_type=[turbine_type]) + if isinstance(power_thrust_model, str): + power_thrust_model = [power_thrust_model]*self.core.farm.n_turbines + elif len(power_thrust_model) != self.core.farm.n_turbines: + raise ValueError( + "The length of the power_thrust_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"]+"_"+power_thrust_model[tindex] + ) + turbine_type_list[tindex]["power_thrust_model"] = power_thrust_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 ae5f07558..a9174d942 100644 --- a/tests/floris_model_integration_test.py +++ b/tests/floris_model_integration_test.py @@ -586,3 +586,8 @@ def test_set_power_thrust_model(): fmodel = FlorisModel(configuration=YAML_INPUT) fmodel.set_power_thrust_model("simple-derating") assert fmodel.get_power_thrust_model() == "simple-derating" + + # Check multiple turbine types works + fmodel.set(layout_x=[0, 0], layout_y=[0, 1000]) + fmodel.set_power_thrust_model(["simple-derating", "cosine-loss"]) + assert fmodel.get_power_thrust_model() == ["simple-derating", "cosine-loss"]