-
Notifications
You must be signed in to change notification settings - Fork 509
C binding interface improvements #2735
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
Conversation
62ac9d6 to
a712957
Compare
This allows for doing the geometric offset for MHK turbines; otherwise, the IC are set in Init but the geometric offsets must happen in preinit
71ad1c8 to
efe3c4a
Compare
Enables loading in LabVIEW
Calculates velocities and accelerations from the previous three positions Calls MD UpdateStates and CalcOutput
efe3c4a to
fbff4b2
Compare
# Conflicts: # reg_tests/r-test
|
@rafmudaf Could you update the documentation for running the regression tests that use the |
7a21c0b to
c98d7a4
Compare
Co-authored-by: Andy Platt <andrew-platt@users.noreply.github.com>
dd8388e to
36c02bc
Compare
|
@andrew-platt I've updated the NWTC C Bindings module and added tests for each included subroutine. It would be great if you could review it again. |
009e13b to
3a65dbf
Compare
3a65dbf to
42a180c
Compare
# Conflicts: # modules/nwtc-library/tests/test_NWTC_C_Binding.F90
db270ab to
de37045
Compare
|
Postponing this update to 5.0
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR refactors and enhances the C‐binding interfaces across multiple modules by standardizing error handling, improving C/Fortran string utilities, and adding new capabilities (e.g., exposing the SeaState wave field pointer and MHK support in AeroDynInflow).
- Introduce
SetErrStat_F2C,SetErrStat_C, and robust string conversion routines inNWTC_C_Binding - Migrate SeaState, MoorDyn, HydroDyn, InflowWind, and AeroDynInflow C bindings to use the new error and string utilities
- Extend Python and LabVIEW glue code to match updated interfaces and add MHK/environment parameter support
Reviewed Changes
Copilot reviewed 18 out of 18 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| vs-build/_c_binding/.vfproj | Add NWTC_C_Binding.f90 to all Fortran‐binding project files |
| modules/nwtc-library/src/NWTC_C_Binding.f90 | Add error‐stat conversion and C/Fortran string helper routines |
| modules/seastate/src/SeaState_C_Binding.f90 | Switch to SetErrStat_F2C, remove old SetErr, export wave field pointer |
| modules/moordyn/src/MoorDyn_C_Binding.f90 | Update error variables, add MD_C_SetWaveFieldData subroutine |
| modules/aerodyn/src/AeroDyn_Inflow_C_Binding.f90 | Switch to new error APIs, remove deprecated SetErr, add MHK flags |
| glue-codes/python/pyOpenFAST/*.py | Update error‐message lengths and function signatures for new C bindings |
| glue-codes/labview/src/WaveTank.f90 | Use SetErrStat_C instead of old SetErr |
Comments suppressed due to low confidence (3)
modules/aerodyn/src/AeroDyn_Inflow_C_Binding.f90:59
- [nitpick] Remove the commented-out
SetErrsubroutine block; the newSetErrStat_F2CAPI is in use and the old code is dead and misleading.
!------------------------------------------------------------------------------------
modules/nwtc-library/tests/test_NWTC_C_Binding.F90:38
- Extend
test_SetErrStat_F2Cto also verify thaterror_message_ccontains the correct null-terminated C string (e.g., by checking each character up to the C_NULL_CHAR), ensuring the Fortran-to-C string conversion is validated.
character(ErrMsgLen) :: error_message_f = "Error message"
modules/seastate/src/SeaState_C_Binding.f90:298
- This function uses C_LOC and C_PTR but the module does not
USE ISO_C_BINDING. AddUSE ISO_C_BINDINGat the top of the module so that C_LOC and C_PTR are available.
FUNCTION SeaSt_GetWaveFieldPointer_C() BIND (C, NAME='SeaSt_GetWaveFieldPointer_C')
|
We can't reproduce the overflow bug in |
C binding interface utilities and improvements
This pull request initially focused on the development of a module for driving a wave tank experimental setup (see rafmudaf#28). It has since been descoped to focus only on improvements to the C binding interfaces, coupling the WaveField pointer from SeaState to MoorDyn, and initializing the MHK capabilities in AeroDynInflow correctly. I've also extended the new
NWTC_C_Bindingmodule (see #2720) with utilities for working with C and Fortran strings plus error handling.This pull request depends on #2719 and #2720, and both have been merged.
C Bindings
Dealing with strings through the C interfaces is nuances, so I've introduced some tooling and patterns to make this more clear and consistent.
For context, a C-style string is represented in Fortran as
CHARACTER(KIND=C_CHAR) :: ErrMsg_c(IntfStrLen). This is a character array of kindC_CHARfrom the ISO_C_BINDING intrinsic module with one dimension of lengthIntfStrLen. This representation is different from the Fortran string,CHARACTER(IntfStrLen) :: ErrMsg, which is a string of lengthIntfStrLen(not an array). Importantly, C strings in Fortran must be terminated withC_NULL_CHARfromISO_C_BINDINGbefore being used by a function or subroutine expecting C-style strings:ErrMsg = " "//C_NULL_CHAR.Since the C binding interfaces operate on both Fortran and C style strings, I've introduced the
_Cand_Fsuffix to the error message buffer variables and most other strings crossing the interface for any subroutines that have C bindings. The variable mapping and function is as follows:ErrStat_F2should hold errors from individual commands, and then it should be incorporated into the module-global error withCALL SetErrStat( ErrStat_F2, ErrMsg_F2, ErrStat_F, ErrMsg_F, RoutineName ). Prior to returning control to the calling code, the_Ferror variables should be transferred to the_Cvariables withCALL SetErrStat_F2C(ErrStat_F,ErrMsg_F,ErrStat_C,ErrMsg_C).An additional error handing utility is added,
SetErrStat_C2C, to support glue code modules written in Fortran and combining C binding interfaces such as theWaveTankmodule. This subroutine expects a C-style error message string for both the local and global error message.