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

Convert core data structures and tools to use 4D arrays #764

Merged
merged 25 commits into from
Dec 18, 2023
Merged

Conversation

rafmudaf
Copy link
Collaborator

Convert core FLORIS to use 4D arrays as low-level data structures

As part of the ongoing effort to support a higher degree of wind farm controls, FLORIS is undergoing a major change from the current 5-dimensional data structures at the lowest level to 4-dimensional data structures. Currently, FLORIS relies heavily on Numpy arrays to do all computations. The shape and size of the arrays vary depending on the context, but they all always have the same first two dimensions (left most) that map to a wind direction and wind speed. Common array shapes are:

# For TurbineGrid-based calculations and data structures that require the full grid
(
    n wind directions,
    n wind speeds,
    n turbines,
    grid dimension 1,
    grid dimension 2
)

# For FlowFieldGrid, FlowFieldPlanarGrid, and PointsGrid calculations
(
    n wind directions,
    n wind speeds,
    grid dimension 1,
    grid dimension 2,
    grid dimension 3
)

# For data structures that contain a scalar value per turbine
(
    n wind directions,
    n wind speeds,
    n turbines
)

This was introduced during the v3 redesign in order to vectorize computations with Numpy broadcasting and SIMD instructions. While the new Structure of Arrays architecture was an improvement over the Array of Structures in FLORIS v2, it also introduced some unintended complexities including the default scenario of creating a product of all wind speeds and wind directions. The alternative to this has been to create a tuple of wind directions and wind speeds in the first dimension and use size 1 for the second dimension - this has been called time_series mode in FLORIS v3. Noting that this is the most explicit method to define a calculation, FLORIS v4 is adoption 4D arrays to directly support this use.

This pull request changes the floris.simulation package to support the 4D arrays. Where possible, dimensional constraints are removed entirely so that any future changes to the low level data structures are made easier. This change typically involves removing a : in array indexing and changing the axis for particular Numpy operations. For example, a typical changes is including below from solver.py.

- x_i = np.mean(grid.x_sorted[:, :, i:i+1], axis=(3, 4))
- x_i = x_i[:, :, :, None, None]
- y_i = np.mean(grid.y_sorted[:, :, i:i+1], axis=(3, 4))
- y_i = y_i[:, :, :, None, None]
- z_i = np.mean(grid.z_sorted[:, :, i:i+1], axis=(3, 4))
- z_i = z_i[:, :, :, None, None]
+ x_i = np.mean(grid.x_sorted[:, i:i+1], axis=(2, 3))
+ x_i = x_i[:, :, None, None]
+ y_i = np.mean(grid.y_sorted[:, i:i+1], axis=(2, 3))
+ y_i = y_i[:, :, None, None]
+ z_i = np.mean(grid.z_sorted[:, i:i+1], axis=(2, 3))
+ z_i = z_i[:, :, None, None]

Though this pull request focuses specifically on the floris.simulation package, portions of the floris.tools package have also been updated to reflect this change to facilitate testing. The test suite has also been updated to reflect this change. Most of the set of examples have been updated, but tests including the optimization routines are not updated since the floris.tools.optimization package is outside of the scope of this pull request.

Impacted areas of the software

This impacts nearly all of the floris.simulation package as well as FlorisInterface and floris.tools.visualization.

rafmudaf and others added 20 commits December 7, 2023 13:44
* Make changes such that test_ct passes in 4d

* Set axial_induction() and test to 4d

* fix test_rotor_velocity_yaw_correction to 4d

* test_rotor_velocity_tilt_correction to 4d

* test_compute_tilt_angles_for_floating_turbines 4d

* Add simple cubature test which passes in 5d

* Add test of cubit cubuture which passes in 4d

* Convert cubature functions to 4d

* Change sample to findex, n_findex

* add N_FINDEX to conftest

* convert farm and unit_tests to 4D

* Delete non-input from docstring

* Add test for 5d reverse rotation and ruff format

* convert utilties and tests to 4d

* Reset formatting

* rem N_WIND_D/S in favor of N_FINDEX in conftest.py

* Clean up some commented code

* Clean up commented code

* fix turbine_type_map in unit test

* fix turbine_type_map size

* revert wind speed and direction tests

* fix doubled code block

* Clean up comments

* Clean up typos

* A few more typos

---------

Co-authored-by: Rafael M Mudafort <[email protected]>
* update reg_tandem to mimic Jensen.

* Partway through solve; commiting to realign with 4d.

* Tandem reg test passing.

* Updated reg tests; all pass.

* Adding reg test for yaw_added_mixing; final values not yet in.

* Removing 5th dim

* Update print_test_values for 4d; add optional max findex to print.

* yaw_added_recovery test updated to include default 0 gain and nonzero gain.
# Conflicts:
#	floris/simulation/flow_field.py
#	tests/turbine_unit_test.py
* initial commit

* first pass edit of 01 example

* ruff formatting

* bugfix

* bugfix

* Convert to 4d

* correct docstrings

* fix docstring

* convert tests to 4d

* back to gch

* Update conditions to evaluate block to 4d

* fix floris_interface test and add power tests

* Add shape test

* Update example 04

* Convert 05

* Update 06 to 4d

* Update 09 to 4D

* Update 18 to 4d

* Update 21 to 4d

* Update 22 to 4d

* convert 24 to 4d

* remove wind speed from call to PointsGrid

* change PointsGrid to 4d

* change call to set_tilt to pass n_findex

* Update comment

* start fixing

* Remove todo

* Remove todo

* Clean up some comments

* More comment clean up

---------

Co-authored-by: Rafael M Mudafort <[email protected]>
* update turbopark solver for 4D

* update turbopark model for 4D

* update turbopark regression test for 4D

* Update regression test API

---------

Co-authored-by: Rafael M Mudafort <[email protected]>
@rafmudaf rafmudaf added enhancement An improvement of an existing feature floris.tools floris.simulation labels Dec 14, 2023
@rafmudaf rafmudaf added this to the v4.0 milestone Dec 14, 2023
@rafmudaf rafmudaf self-assigned this Dec 14, 2023
* Fix API in an example

* Fix index in rotor visualization method

* Fix inconsistent wind condition arrays

* Describe 4D arrays in Getting Started docs

* Clarify description of setting atmospheric conditions
* Update wind condition broadcast for turbine tests

The inputs changed in conftest but this wasn’t updated

* Update multidimensional turbine module for 4D arrays

* Update multidimensional example API’s

* Unit test bug fix

* Remove a few missed extra dimensions
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement An improvement of an existing feature floris.simulation floris.tools
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

4 participants