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

Improve error check for FlorisModel merge function #1044

Merged
merged 2 commits into from
Dec 9, 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
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)
Loading