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

Consistent use of turbine indexing when coupled to c/c++ #2097

Merged
merged 6 commits into from
Mar 20, 2024

Conversation

andrew-platt
Copy link
Collaborator

This is ready to merge, pending discussion.

Feature or improvement description
There has been an ambiguous usage of turbine indexing. In C and C++ codes, arrays start with index 0, but Fortran starts with index 1. In coupling OpenFAST to AMR-Wind, an array of Turbine data structures was created spanning from index 0:NumTurbines-1. Indexing into this array has been handled by the iTurb variable passed into all routines in FAST_Library.f90 that include a c-bindings interface. However, inside the FAST_Subs.f90 file, this turbine index is assumed to run from 1:NumTurbines for compatibility with FAST.Farm.

This PR corrects the following:

  1. Change the variable ExternInitData%TurbineID to ExternInitData%TurbIDforName to more accurately reflect the usage of this variable. This variable is only ever used to set the name of the output file (i.e. SimName.T0.out). This variable must be 0 or larger (new error handling added).
  2. FAST_AllocateTurbines now allocates the Turbine data structure to the range (1:NumTurbines).
  3. All routines in FAST_Library.f90 that include a c-bindings interface now take the argument iTurb_c instead of iTurb. This is the index to the turbine using the c-style array indexing starting at 0. Internally this shifted by 1 and stored as iTurb, a Fortran index starting at 1.

Since the output names are set using the TurbIDforName variable, the name is completely independent of the internal numbering.

Related issue, if one exists
Exawind/amr-wind#984
#2096

Impacted areas of the software
This will affect any codes calling OpenFAST using the FAST_Library interface using 1 as starting index for the first turbine -- these codes will need updating to use 0 as the index to the first turbine. This might affect NALU-Wind, and potentially SOWFA (I'm uncertain what interfaces those codes use, or what assumptions on indexing are made).

Additional supporting information
The only place this ambiguity of indexing appeared is when a checkpoint file was written or read. It doesn't appear that anything else was affected.

Test results, if applicable
This will require testing by @marchdf and possibly others.

All code in FAST_Subs.f90 and other modules assumes Fortran style indexing (index start at 1) to the Turbine data structure.
This more accurately reflects what it is used for.
- `iTurb_c` is the new variable name for the turbine index passed into a FAST_Library.f90 routine.  This is assumed to start at 0 for the first turbine.
- `iTurb = iTurb_c + 1` shifts this index to the indexing used internally in OpenFAST.
@marchdf
Copy link

marchdf commented Mar 18, 2024

@andrew-platt thanks for working on this. I had to rebuild this whole amr-wind stack because they've changed the way we do builds on our end. Running into some snags with this new method and then I will be off the rest of the week. So realistically I won't be testing this until next week.

@andrew-platt andrew-platt merged commit 3e029ef into OpenFAST:rc-3.5.3 Mar 20, 2024
19 checks passed
@andrew-platt andrew-platt deleted the b/FASTlib_TurbineIndex_1 branch March 26, 2024 15:08
@marchdf
Copy link

marchdf commented Mar 26, 2024

I can confirm that the files are closed with these changes and interfacing with amr-wind. Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants