Skip to content

Commit

Permalink
Improve error check for FlorisModel merge function (#1044)
Browse files Browse the repository at this point in the history
* Add test showing missing error

* Fix error handling
  • Loading branch information
rafmudaf authored Dec 9, 2024
1 parent cf05538 commit a3620f5
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 4 deletions.
15 changes: 11 additions & 4 deletions floris/floris_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -1745,9 +1745,16 @@ def reinitialize(self, **_):

@staticmethod
def merge_floris_models(fmodel_list, reference_wind_height=None):
"""Merge a list of FlorisModel objects into a single FlorisModel object. Note that it uses
the very first object specified in fmodel_list to build upon,
"""Merge a list of FlorisModel objects into a single FlorisModel object.
Note that it uses the first object specified in fmodel_list to build upon,
so it uses those wake model parameters, air density, and so on.
Currently, this function supports merging the following components of the FLORIS inputs:
- farm
- layout_x
- layout_y
- turbine_type
- flow_field
- reference_wind_height
Args:
fmodel_list (list): Array-like of FlorisModel objects.
Expand All @@ -1764,8 +1771,8 @@ def merge_floris_models(fmodel_list, reference_wind_height=None):
or general solver settings.
"""

if not isinstance(fmodel_list[0], FlorisModel):
raise ValueError(
if not all( type(fm) == FlorisModel for fm in fmodel_list ):
raise TypeError(
"Incompatible input specified. fmodel_list must be a list of FlorisModel objects."
)

Expand Down
27 changes: 27 additions & 0 deletions tests/floris_model_integration_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -827,3 +827,30 @@ def test_reference_wind_height_methods(caplog):
turbine_type=["nrel_5MW", "iea_15MW"]
)
fmodel.assign_hub_height_to_ref_height() # Shouldn't allow due to multiple turbine types

def test_merge_floris_models():

# Check that the merge function extends the data as expected
fmodel1 = FlorisModel(configuration=YAML_INPUT)
fmodel1.set(
layout_x=[0, 1000],
layout_y=[0, 0]
)
fmodel2 = FlorisModel(configuration=YAML_INPUT)
fmodel2.set(
layout_x=[2000, 3000],
layout_y=[0, 0]
)

merged_fmodel = FlorisModel.merge_floris_models([fmodel1, fmodel2])
assert merged_fmodel.n_turbines == 4

# Check that this model will run without error
merged_fmodel.run()

# Verify error handling

## Input list with incorrect types
fmodel_list = [fmodel1, "not a floris model"]
with pytest.raises(TypeError):
merged_fmodel = FlorisModel.merge_floris_models(fmodel_list)

0 comments on commit a3620f5

Please sign in to comment.