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

Use dt_out when storing OpenFAST outputs in Python interface #1211

Merged
merged 7 commits into from
Sep 6, 2022

Conversation

deslaughter
Copy link
Collaborator

This pull request is ready for merging.

All regression tests are passing and development is complete. No additional documentation is required.

Feature or improvement description
This pull request resolves an issue where the openfast_library.py file was allocating too much memory on large simulations.

Related issue, if one exists
None

Impacted areas of the software

  • glue-codes/openfast/src/FastLibAPI.cpp
  • glue-codes/openfast/src/FastLibAPI.h
  • glue-codes/python/openfast_library.py
  • glue-codes/simulink/src/FAST_SFunc.c
  • modules/openfast-library/src/FAST_Library.f90
  • modules/openfast-library/src/FAST_Library.h

Additional supporting information
The existing versions of openfast_library.py and FastLibAPI allocate an output array with a size NUM_OUTPUTS*(T_MAX/DT). This size is inconsistent with the output files which contain data written every DT_OUT seconds. The code changes in this PR cause the output data to be collected on the DT_OUT interval which reduces memory usage and matches current output files. DT_OUT was exposed to these libraries by adding it to the FAST_Sizes arguments which required changes to the Fortran, C, C++, Python, and Simulink libraries.

These changes also resolve a potential memory leak in FastLibAPI where the output data array was not freed by the parent class destructor. This was fixed by changing the output array to a vector of vectors which is automatically destroyed.

Test results, if applicable
Developer testing showed a reduction is memory use due to allocation of smaller output arrays.

DT_Out is needed to determine the frequency at which results should be
captured from FAST_Update in the programs that use openfast-library.
This change exposes the DT_out by adding it the arguments of FAST_Sizes.
The corresponding function prototype was updated in FAST_Library.h.
For long simulations openfast_library.py would allocate a large array to
hold output values for every step based on DT. This array could consume
a significant amount of memory and was inconsistent with the data stored
in output files which is based on DT_Out. This commit bases the output
array size on DT_Out and changes the data collection to match, which
can significantly reduce memory usage. In addition, the output_values
array is passed directory to FAST_Update to reduce copying data. Lastly,
the channel name processing is moved to fast_init to avoid a memory leak
The C++ interface to openfast-library was updated to match the changes
to openfast_library.py - basing output on DT_Out instead of DT. Also,
the output_array variable was removed and output_values changed to
a vector of vectors so the memory will be freed when FastLibAPI is
destroyed. This change also removes the copying of data between arrays.
Updates FAST_SFunc.c for the new FAST_Sizes function signature which
exposes DT_Out.
This change was requested to so WEIS, which uses this library,
doesn't have to change.
Class member was renamed for consistency with openfast_library.py.
Renaming the class member channel_names to output_channel_names
created a conflict with a class function prototype which was designed to
return a string of channel names. To make FastLibAPI consistent with
openfast_library.py, this commit changes output_channel_names to be
a vector of strings which is populated by the fast_init method.
@andrew-platt
Copy link
Collaborator

Will the addition of the dt_out variable passing require updates to SOWFA / AMR-Wind or the Simulink interfaces?

@rafmudaf
Copy link
Collaborator

The Simulink interface is updated here, and the SOWFA / AMR-Wind interface aren't changed. Those use the OpFM routines that are separately defined in FAST Library.

@rafmudaf rafmudaf changed the title Bug/pythonlib Use dt_out when storing OpenFAST outputs in Python interface Aug 16, 2022
@andrew-platt
Copy link
Collaborator

Is there any reason to wait on merging this?

@andrew-platt andrew-platt merged commit 83b5f9a into OpenFAST:dev Sep 6, 2022
@rafmudaf rafmudaf mentioned this pull request Oct 27, 2022
10 tasks
@deslaughter deslaughter deleted the bug/pythonlib branch April 18, 2023 19:14
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.

3 participants