Skip to content

Commit

Permalink
Bug fix: Finalize Farm attributes (NREL#665)
Browse files Browse the repository at this point in the history
* Arrange attribute declarations by shape and sort

* Add missing attribute declarations

* Remove unused attribute

* Add comments requesting more info

* Bug fix: unsort arrays

Update version to v3.4.1
  • Loading branch information
rafmudaf committed Jul 27, 2023
1 parent 5e5bb7f commit 59e53a6
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 7 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
FLORIS is a controls-focused wind farm simulation software incorporating
steady-state engineering wake models into a performance-focused Python
framework. It has been in active development at NREL since 2013 and the latest
release is [FLORIS v3.4](https://github.com/NREL/floris/releases/latest).
release is [FLORIS v3.4.1](https://github.com/NREL/floris/releases/latest).
Online documentation is available at https://nrel.github.io/floris.

The software is in active development and engagement with the development team
Expand Down
40 changes: 35 additions & 5 deletions floris/simulation/farm.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,26 +62,39 @@ class Farm(BaseClass):
)

turbine_definitions: list = field(init=False, validator=iter_validator(list, dict))
coordinates: List[Vec3] = field(init=False)
turbine_fCts: tuple = field(init=False, default=[])
turbine_fTilts: list = field(init=False, default=[])

yaw_angles: NDArrayFloat = field(init=False)
yaw_angles_sorted: NDArrayFloat = field(init=False)

tilt_angles: NDArrayFloat = field(init=False)
tilt_angles_sorted: NDArrayFloat = field(init=False)
coordinates: List[Vec3] = field(init=False)

hub_heights: NDArrayFloat = field(init=False)
hub_heights_sorted: NDArrayFloat = field(init=False, default=[])
turbine_fCts: tuple = field(init=False, default=[])

turbine_type_map: NDArrayObject = field(init=False, default=[])
turbine_type_map_sorted: NDArrayObject = field(init=False, default=[])

rotor_diameters: NDArrayFloat = field(init=False, default=[])
rotor_diameters_sorted: NDArrayFloat = field(init=False, default=[])

TSRs: NDArrayFloat = field(init=False, default=[])
TSRs_sorted: NDArrayFloat = field(init=False, default=[])

pPs: NDArrayFloat = field(init=False, default=[])
pPs_sorted: NDArrayFloat = field(init=False, default=[])

pTs: NDArrayFloat = field(init=False, default=[])
pTs_sorted: NDArrayFloat = field(init=False, default=[])

ref_tilt_cp_cts: NDArrayFloat = field(init=False, default=[])
ref_tilt_cp_cts_sorted: NDArrayFloat = field(init=False, default=[])

correct_cp_ct_for_tilt: NDArrayFloat = field(init=False, default=[])
correct_cp_ct_for_tilt_sorted: NDArrayFloat = field(init=False, default=[])
turbine_fTilts: list = field(init=False, default=[])

def __attrs_post_init__(self) -> None:
# Turbine definitions can be supplied in three ways:
Expand Down Expand Up @@ -301,15 +314,16 @@ def expand_farm_properties(
sorted_coord_indices,
axis=2
)

# NOTE: Tilt angles are sorted twice - here and in initialize()
self.tilt_angles_sorted = np.take_along_axis(
self.tilt_angles * template_shape,
sorted_coord_indices,
axis=2
)
self.turbine_type_names_sorted = [turb["turbine_type"] for turb in self.turbine_definitions]
self.turbine_type_map_sorted = np.take_along_axis(
np.reshape(
self.turbine_type_names_sorted * n_wind_directions,
[turb["turbine_type"] for turb in self.turbine_definitions] * n_wind_directions,
np.shape(sorted_coord_indices)
),
sorted_coord_indices,
Expand Down Expand Up @@ -366,6 +380,22 @@ def finalize(self, unsorted_indices):
unsorted_indices[:,:,:,0,0],
axis=2
)
# TODO: do these need to be unsorted? Maybe we should just for completeness...
self.ref_density_cp_cts = np.take_along_axis(
self.ref_density_cp_cts_sorted,
unsorted_indices[:,:,:,0,0],
axis=2
)
self.ref_tilt_cp_cts = np.take_along_axis(
self.ref_tilt_cp_cts_sorted,
unsorted_indices[:,:,:,0,0],
axis=2
)
self.correct_cp_ct_for_tilt = np.take_along_axis(
self.correct_cp_ct_for_tilt_sorted,
unsorted_indices[:,:,:,0,0],
axis=2
)
self.pPs = np.take_along_axis(
self.pPs_sorted,
unsorted_indices[:,:,:,0,0],
Expand Down
2 changes: 1 addition & 1 deletion floris/version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
3.4
3.4.1

0 comments on commit 59e53a6

Please sign in to comment.