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

Feature: External Turbine Library #568

Merged
merged 14 commits into from
Feb 27, 2023

Conversation

RHammond2
Copy link
Collaborator

@RHammond2 RHammond2 commented Feb 6, 2023

Feature or improvement description
This PR is a new copy of #521, with the latest changes on develop, and adds support for using external turbine libraries for turbine defintions to floris.tools.FlorisInterface and floris.simulation.Farm.

Related issue, if one exists

This would bump up the priority of #345 and likely close it.
Closes #521 because it's outdated and got bungled in a merge resolution.
Addresses part of #513 by only loading a file once, logging the appropriate warning, and creating a deepcopy of the loaded turbine file for each turbine in the layout. The core issue raise there stems from the set up of the examples, upon closer inspection, so will not be closing the issue.

Impacted areas of the software

floris.simulation.Farm now has a turbine_library attribute that defaults to the currently assumed "floris/turbine_library" folder that ensures the input file path exists prior to loading in the data. Additionally this input was added to the floris.tools.FlorisInterface.reinitialize() method to ensure usage is consistent with the rest of the inputs. I've also added a few other tests and some test data to ensure this is working as expected.

Additional supporting information

I saw in #345 that this was marked as v3.3/v3.4 issue, however, in a separate project I'm running into an issue where the current workaround is a little bit clunky in practice, and am proposing the implemented solution here as a starting point.

Test results, if applicable

All previously existing and newly added tests pass.

Example Usage
The below demonstration shows how a user can define a separate turbine_library_path in their input YAML file:

...  # definitions before the farm inputs
farm:
  layout_x: 
    - 0
    - 500
    - 1000
  layout_y: 
    - 0
    - 0
    - 0
  turbine_type:
    - nrel_5MW  # included in FLORIS
    - nrel_5MW  # included in FLORIS
    - nrel_5MW_custom   # External turbine library; note that there is no overlap in turbine naming
  turbine_library_path: /path/to/custom/user/library/folder  # folder where nrel_5MW_custom is located
...  # definitions after the farm inputs

An alternative usage for this feature is available through the FlorisInterface.reinitialize() method, as seen in the example below.

from floris.tools import FlorisInterface


# Define an interface, assuming this uses the default internal turbine library
fi = FlorisInterface("path/to/input.yaml")

# Now, redefine, and add in a custom turbine model from an external library
fi.reinitialize(
    # 2 internally defined, and 1 externally defined turbines, just like file example above
    turbine_type=["nrel_5MW", "nrel_5MW", "nrel_5MW_custom"],
    turbine_library_path="/path/to/custom/library/folder",  # folder where "nrel_5MW_custom" is located
)

@RHammond2 RHammond2 added enhancement An improvement of an existing feature v3.3 labels Feb 6, 2023
@RHammond2 RHammond2 changed the title Feature/turbine library Feature: External Turbine Library Feb 6, 2023
@RHammond2 RHammond2 linked an issue Feb 8, 2023 that may be closed by this pull request
@rafmudaf
Copy link
Collaborator

rafmudaf commented Feb 9, 2023

The last comment I have is a request to add a simple example usage in the pull request description above. This will ultimately be included in the documentation, but it's good enough to include here initially.

Is this a feature that can only be used through a script or is there a way to set an external turbine library through the input file? If so, please provide the relevant blocks of the input file that would be used.

@RHammond2
Copy link
Collaborator Author

Good call on the example part, I'll add something that calls more attention to it, so users know it's available. As an aside, it was added to the documentation PR in the input reference sheet, so I'll leave that component alone.

@rafmudaf rafmudaf self-requested a review February 14, 2023 13:25
Copy link
Collaborator

@paulf81 paulf81 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you @RHammond2 , I think this is a really nice and general solution

Copy link
Collaborator

@bayc bayc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great!

@rafmudaf rafmudaf merged commit 8c637b3 into NREL:develop Feb 27, 2023
rafmudaf added a commit that referenced this pull request Mar 7, 2023
* Speed up angle wrap functions and improve API (#505)

* replace wrap functions with faster implementations

* slight change to unit test as 180 -> -180

* Update doc string to reflect accurate return type

* Use executable book project for documentation

* Add a gh-pages deploy action

* Add more content

* Add a logo

* Add a brief description of each example

List examples in numeric order

Small cleanup to Examples listing

* Add initial API documentation

* Add input file reference

* Use autodoc and autosummary instead of autoapi

Remove TOC from intro page

* Locally install the current repo

* Configure autodocs better

Include undocumented objects as well as all members of an object

Add all default autodoc options to config

* Link to API docs in references to Python objects

* Git-ignore docs build

* Add instructions for building documentation

And other minor changes

* Add Google Analytics tracker

* Update README with documentation links

* List floris packages in API docs

* Enforce building docs from the develop branch

* Add a method to show mpl plots

This means users don’t have to also import matplotlib.pyplot as plt only to run plt.show()

* Update documentation references list (#519)

* initial entry for cumulative curl

* copy in v2 references

* add cc references

* add cc refs

* replace references to zrefs with references.bib

* API improvements

* Add a subtract overload to CutPlane

Also replaces another method CutPlane.subtract to do something similar. That one made assumptions about the order and expected operations. The new subtract method expects all preprocessing to be down outside of the class.

* Fix incorrect yaw angles in fi.calculate_wake

In subsequent function calls, the yaw angles are not reset when they are all zeros. This means that if initially the yaw angles are non-zero and then they’re all-zero, the non-zero yaw settings are retained.

* Remove requirement to use codecov token to upload reports (#532)

* remove potentially error causing line

* Update codecov upload action to v3

Co-authored-by: Rafael M Mudafort <rafael.mudafort@nrel.gov>

* Update API in examples

And clean up examples imports

* Use standard conventions in argument case

minSpeed, maxSpeed => min_speed, max_speed

* Add function to label turbines on CutPlane plots

* Rotate turbine lines and ID annotations with wind

* Configure isort and apply rules (#535)

* Configure isort and apply to floris.simulation

* Apply isort to floris.tools

* Apply isort to shared modules

* Apple isort to examples and tests

* Increase line length to 100

* Add isort description in docs

* Add weights to AEP wind rose function (#541)

* Add weights to get_farm_AEP_wind_rose_class

* updating layout passed to floris_interface in example

* Remove typecast to int for turbine weighting

---------

Co-authored-by: bayc <christopher.j.bay@gmail.com>
Co-authored-by: Rafael M Mudafort <rafael.mudafort@nrel.gov>

* Add parallel computing interface for farm simulation and yaw optimization (#555)

* Add parallel computing class

* Simplify and lighten the way floris information is passed to single-core functions

* Remove unc_options and only pass unc_pmfs internally: all information already contained in that variable.

* Update how wind directions are split up

* Add example for parallel computing

* Introduce separate variable for number of workers

* Expand PCI capabilities with reinitialize, copy. This is needed for some FLASC functionalities like precalculating table of floris solutions

* Allow user to reinitialize atmospheric conditions but then also reload how atmospheric conditions are divided by cores

* Add toggle to silence print statements from Serial Refine and set default in parallel computing. Namely, with 16 workers, you will see 16 times these print statements. This only becomes more with more workers and quickly clutters up the log file.

* Add the option to propagate flow field information from workers to main florisinterface object

* Add parallel processing example

* Remove duplicate example listing

---------

Co-authored-by: Rafael M Mudafort <rafael.mudafort@nrel.gov>

* Feature/update layout vis (#496)

* Update layout visualization functions

* Provide an example of layout visualization

* list 23_visaluze_layout in examples.md

---------

Co-authored-by: Rafael M Mudafort <rafmudaf@gmail.com>

* Add ruff configuration

* Fix all E and F codes

F are pyflakes
E are pycodestyle
https://github.com/charliermarsh/ruff#pyflakes-f

Note: line length errors are not excluded here

* Line length corrections - floris.simulation

Max line length setting is 100

* Line length corrections - floris.tools

* Line length corrections - floris/

* Line length corrections - tests

* Line length corrections - examples

* Line length corrections - profiling

* Fix W codes

Here, it’s only adding a blank line at the end

* Fix C4-comprehensions codes

* Fix I codes

Import formatting. Ruff is not yet at parity with isort, but it is pretty close.

* Include Ruff in CI

Use pre-commit with Actions

Also update the developer dependencies

* Add Ruff usage documentation in developer guide

* Enable and fix pre-commit formatting hooks (#567)

* Enable and fix pre-commit formatting hooks

* Add pre-commit instructions to developer documentation

* Support heterogeneous wind direction definition via FlorisInterface.reinitialize (#453)

* Provide ability to pass het_map to reinitialize

* re-order reinitialize inputs

* Add a new example

* Add an error if het map doesnt match on dimensions to wd

* Add error example to example

* updating format of example

* Add indication final error is on purpose

* line length check

* Comment out forced error

* Add example 16b to docs

* use n directions instead of x

* Add comment

---------

Co-authored-by: Paul <paul.fleming@nrel.gov>
Co-authored-by: bayc <christopher.j.bay@gmail.com>

* Infrastructure improvements (#569)

* Preserve isort formatting - run it last

Also enables splitting imports on trailing comma. If a multi-line import statement is short and includes a trailing comma, it will not be refactored into a single line.

* Use token for codecov upload

* Reduce computational load in an example

Initially, this example slowed the Actions workflow by 2x. This commit reduces the amount of work in the example to speed up the Actions workflow.

* Restrict PyPI deploy workflow to NREL/floris

* Run tests regardless of linting results

* Fail the linter

* Revert "Fail the linter"

This reverts commit d7bfa62.

* Add virtual turbine plotting method (#418)

* Add func calculate_horizontal_plane_with_turbines

* Add demo example

* Correct sort order

* Improve resolution and force matching range

* fix append

* Remove calculate with turbine from floris interfa

* Delete turbine scan example

* Add calc with turbines to visualizations.py

* Add vis with turbine to visualization example

* Support for yaw angles

* Fix handling of yaw angles

* fix outdated layout keyword

* ruff linting

* test pre-commit

* test pre-commit

* Pre-commit fixes

* Fixed doc errors

* Clean out commented code

* Preserve isort formatting - run it last

Also enables splitting imports on trailing comma. If a multi-line import statement is short and includes a trailing comma, it will not be refactored into a single line.

* Use token for codecov upload

* Reduce computational load in an example

Initially, this example slowed the Actions workflow by 2x. This commit reduces the amount of work in the example to speed up the Actions workflow.

* Restrict PyPI deploy workflow to NREL/floris

* Add info on plotting method

* Use coarse mesh for turbine plotting

---------

Co-authored-by: Rafael M Mudafort <rafmudaf@gmail.com>

* Add linear wind condition upsampling method to WindRose (#544)

* Add LinearNDInterpolant to wind_rose

* Change from returning interpolant to immediately interpolating to values

* Add example to docstring

---------

Co-authored-by: Paul <paul.fleming@nrel.gov>
Co-authored-by: Rafael M Mudafort <rafmudaf@gmail.com>

* Improve the documentation navigation menu and organization (#570)

* minor formatting updates

* start overhaul of docuemntation structure

* convert input reference to markdown for consistency

* add a serious placeholder for theory and update the example input file

* remove my notes

* add top-level workflow description for getting started

* add missing period

* Add intro notebook

* Add developer section to menu

* Bug fix: fix toc reference to placeholder page

* Warning fix: use alternate cross reference form

---------

Co-authored-by: Rafael M Mudafort <rafmudaf@gmail.com>

* Feature: External Turbine Library (#568)

* add the external library functionality

* update tests for new functionality

* enable future typing

* fix extra white space

* remove extra parameters

* add missing test file

* fix name bug and address #513

* get tests passing and ensure dictionary entries still work

* address Raf's comment

* add _path to turbine library references

* update typo, FI, and tests for _path

* fix error on case of using turbine dictionary and missing air density

* add additional test for the unique turbine check

* Specify coverage file in Codecov upload action

* Add a link to Discussions from Issues

* Add helpful info to GitHub Issue and PR templates (#597)

---------

Co-authored-by: paulf81 <paul.fleming@nrel.gov>
Co-authored-by: Rob Hammond <13874373+RHammond2@users.noreply.github.com>
Co-authored-by: bayc <christopher.j.bay@gmail.com>
Co-authored-by: Bart Doekemeijer <bart.doekemeijer@shell.com>
Co-authored-by: pjireland <pireland@windesco.com>
@scottryn
Copy link
Contributor

Hi all, I have an issue with this feature where turbines in /path/to/custom/user/library/folder raise the turbines exist in internal and external library error. Specifically check_turbine_type() in farm.py is saying my custom turbine file exists where it shouldn't. I've verified the location and contents of both directories as well as re-installed from source but the issue persists. Any help would be appreciated!

@rafmudaf
Copy link
Collaborator

@scottryn thanks for the info. Could you please open an issue and include a minimal script to reproduce the error?

@scottryn
Copy link
Contributor

Hi @rafmudaf, thanks for getting back to me so quickly! I installed in a clean Conda environment and everything works as intended. I'll hold off on raising an issue since it appears I have ghosts in my other environment.

@RHammond2 RHammond2 deleted the feature/turbine-library branch May 8, 2023 15:53
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
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Write warnings once and then silence
5 participants