Skip to content

Commit cfb5aae

Browse files
authored
Merge pull request #2787 from andrew-platt/f/HD_C_SS_fileHandle
HD-cbind: Add HydroDyn input files handle
2 parents 8425c28 + 3d20f95 commit cfb5aae

File tree

3 files changed

+71
-35
lines changed

3 files changed

+71
-35
lines changed

glue-codes/python/pyOpenFAST/hydrodyn.py

Lines changed: 30 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,9 @@ def __init__(self, library_path):
103103
self._initialize_routines()
104104
self.ended = False # For error handling at end
105105

106+
# Input file handling configuration
107+
self.seastate_inputs_passed_as_string: bool = True # Pass input file as string
108+
self.hydrodyn_inputs_passed_as_string: bool = True # Pass input file as string
106109

107110
# Create buffers for class data
108111
self.abort_error_level = 4
@@ -161,11 +164,13 @@ def __init__(self, library_path):
161164
# _initialize_routines() ------------------------------------------------------------------------------------------------------------
162165
def _initialize_routines(self):
163166
self.HydroDyn_C_Init.argtypes = [
164-
POINTER(c_char), # OutRootName
167+
POINTER(c_int), # SeaState input file passed as string
165168
POINTER(c_char_p), # SeaState input file string
166169
POINTER(c_int), # SeaState input file string length
170+
POINTER(c_int), # HydroDyn input file passed as string
167171
POINTER(c_char_p), # HydroDyn input file string
168172
POINTER(c_int), # HydroDyn input file string length
173+
POINTER(c_char), # OutRootName
169174
POINTER(c_float), # gravity
170175
POINTER(c_float), # defWtrDens
171176
POINTER(c_float), # defWtrDpth
@@ -281,28 +286,30 @@ def hydrodyn_init(self, seast_input_string_array, hd_input_string_array):
281286

282287
# call HydroDyn_C_Init
283288
self.HydroDyn_C_Init(
284-
_outRootName_c, # IN: rootname for HD file writing
285-
c_char_p(seast_input_string), # IN: SeaState input file string
286-
byref(c_int(seast_input_string_length)),# IN: SeaState input file string length
287-
c_char_p(hd_input_string), # IN: HydroDyn input file string
288-
byref(c_int(hd_input_string_length)), # IN: HydroDyn input file string length
289-
byref(c_float(self.gravity)), # IN: gravity
290-
byref(c_float(self.defWtrDens)), # IN: default water density
291-
byref(c_float(self.defWtrDpth)), # IN: default water depth
292-
byref(c_float(self.defMSL2SWL)), # IN: default offset between still-water level and mean sea level
293-
byref(c_float(self.ptfmRefPt_x)), # IN: Platform initial position (X)
294-
byref(c_float(self.ptfmRefPt_y)), # IN: Platform initial position (Y)
295-
byref(c_int(self.numNodePts)), # IN: number of attachment points expected (where motions are transferred into HD)
296-
nodeInitLoc_flat_c, # IN: initNodePos -- initial node positions in flat array of 6*numNodePts
297-
byref(c_int(self.InterpOrder)), # IN: InterpOrder (1: linear, 2: quadratic)
298-
byref(c_double(self.t_start)), # IN: time initial
299-
byref(c_double(self.dt)), # IN: time step (dt)
300-
byref(c_double(self.tmax)), # IN: tmax
301-
byref(self._numChannels_c), # OUT: number of channels
302-
self._channel_names_c, # OUT: output channel names
303-
self._channel_units_c, # OUT: output channel units
304-
byref(self.error_status_c), # OUT: ErrStat_C
305-
self.error_message_c # OUT: ErrMsg_C
289+
byref(c_int(self.seastate_inputs_passed_as_string)), # IN: SeaState input file is passed as string
290+
c_char_p(seast_input_string), # IN: SeaState input file string
291+
byref(c_int(seast_input_string_length)), # IN: SeaState input file string length
292+
byref(c_int(self.hydrodyn_inputs_passed_as_string)), # IN: HydroDyn input file is passed as string
293+
c_char_p(hd_input_string), # IN: HydroDyn input file string
294+
byref(c_int(hd_input_string_length)), # IN: HydroDyn input file string length
295+
_outRootName_c, # IN: rootname for HD file writing
296+
byref(c_float(self.gravity)), # IN: gravity
297+
byref(c_float(self.defWtrDens)), # IN: default water density
298+
byref(c_float(self.defWtrDpth)), # IN: default water depth
299+
byref(c_float(self.defMSL2SWL)), # IN: default offset between still-water level and mean sea level
300+
byref(c_float(self.ptfmRefPt_x)), # IN: Platform initial position (X)
301+
byref(c_float(self.ptfmRefPt_y)), # IN: Platform initial position (Y)
302+
byref(c_int(self.numNodePts)), # IN: number of attachment points expected (where motions are transferred into HD)
303+
nodeInitLoc_flat_c, # IN: initNodePos -- initial node positions in flat array of 6*numNodePts
304+
byref(c_int(self.InterpOrder)), # IN: InterpOrder (1: linear, 2: quadratic)
305+
byref(c_double(self.t_start)), # IN: time initial
306+
byref(c_double(self.dt)), # IN: time step (dt)
307+
byref(c_double(self.tmax)), # IN: tmax
308+
byref(self._numChannels_c), # OUT: number of channels
309+
self._channel_names_c, # OUT: output channel names
310+
self._channel_units_c, # OUT: output channel units
311+
byref(self.error_status_c), # OUT: ErrStat_C
312+
self.error_message_c # OUT: ErrMsg_C
306313
)
307314

308315
self.check_error()

modules/aerodyn/src/AeroDyn_Inflow_C_Binding.f90

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -420,10 +420,10 @@ SUBROUTINE ADI_C_Init( ADinputFilePassed, ADinputFileString_C, ADinputFileString
420420
!GCC$ ATTRIBUTES DLLEXPORT :: ADI_C_Init
421421
#endif
422422
! Input file info
423-
integer(c_int), intent(in ) :: ADinputFilePassed !< Write VTK outputs [0: none, 1: init only, 2: animation]
423+
integer(c_int), intent(in ) :: ADinputFilePassed !< 0: pass the input file name; 1: pass the input file content
424424
type(c_ptr), intent(in ) :: ADinputFileString_C !< Input file as a single string with lines deliniated by C_NULL_CHAR
425425
integer(c_int), intent(in ) :: ADinputFileStringLength_C !< lenght of the input file string
426-
integer(c_int), intent(in ) :: IfWinputFilePassed !< Write VTK outputs [0: none, 1: init only, 2: animation]
426+
integer(c_int), intent(in ) :: IfWinputFilePassed !< 0: pass the input file name; 1: pass the input file content
427427
type(c_ptr), intent(in ) :: IfWinputFileString_C !< Input file as a single string with lines deliniated by C_NULL_CHAR
428428
integer(c_int), intent(in ) :: IfWinputFileStringLength_C !< lenght of the input file string
429429
character(kind=c_char), intent(in ) :: OutRootName_C(IntfStrLen) !< Root name to use for echo files and other

modules/hydrodyn/src/HydroDyn_C_Binding.f90

Lines changed: 39 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -202,9 +202,12 @@ end subroutine SetErr
202202
!===============================================================================================================
203203
!--------------------------------------------- HydroDyn Init----------------------------------------------------
204204
!===============================================================================================================
205-
SUBROUTINE HydroDyn_C_Init( OutRootName_C, &
205+
SUBROUTINE HydroDyn_C_Init( &
206+
SeaSt_InputFilePassed, &
206207
SeaSt_InputFileString_C, SeaSt_InputFileStringLength_C, &
208+
HD_InputFilePassed, &
207209
HD_InputFileString_C, HD_InputFileStringLength_C, &
210+
OutRootName_C, &
208211
Gravity_C, defWtrDens_C, defWtrDpth_C, defMSL2SWL_C, &
209212
PtfmRefPtPositionX_C, PtfmRefPtPositionY_C, &
210213
NumNodePts_C, InitNodePositions_C, &
@@ -218,11 +221,13 @@ SUBROUTINE HydroDyn_C_Init( OutRootName_C,
218221
!GCC$ ATTRIBUTES DLLEXPORT :: HydroDyn_C_Init
219222
#endif
220223

221-
character(kind=c_char), intent(in ) :: OutRootName_C(IntfStrLen) !< Root name to use for echo files and other
224+
integer(c_int), intent(in ) :: SeaSt_InputFilePassed !< 0: pass the input file name; 1: pass the input file content
222225
type(c_ptr), intent(in ) :: SeaSt_InputFileString_C !< SeaSt input file as a single string with lines deliniated by C_NULL_CHAR
223226
integer(c_int), intent(in ) :: SeaSt_InputFileStringLength_C !< SeaSt length of the input file string
227+
integer(c_int), intent(in ) :: HD_InputFilePassed !< 0: pass the input file name; 1: pass the input file content
224228
type(c_ptr), intent(in ) :: HD_InputFileString_C !< HD input file as a single string with lines deliniated by C_NULL_CHAR
225229
integer(c_int), intent(in ) :: HD_InputFileStringLength_C !< HD length of the input file string
230+
character(kind=c_char), intent(in ) :: OutRootName_C(IntfStrLen) !< Root name to use for echo files and other
226231
real(c_float), intent(in ) :: Gravity_C !< Gravitational constant (set by calling code)
227232
real(c_float), intent(in ) :: defWtrDens_C !< Default value for water density (may be overridden by input file)
228233
real(c_float), intent(in ) :: defWtrDpth_C !< Default value for water density (may be overridden by input file)
@@ -248,6 +253,7 @@ SUBROUTINE HydroDyn_C_Init( OutRootName_C,
248253
character(IntfStrLen) :: OutRootName !< Root name to use for echo files and other
249254
character(kind=C_char, len=SeaSt_InputFileStringLength_C), pointer :: SeaSt_InputFileString !< Input file as a single string with NULL chracter separating lines
250255
character(kind=C_char, len=HD_InputFileStringLength_C), pointer :: HD_InputFileString !< Input file as a single string with NULL chracter separating lines
256+
character(IntfStrLen) :: TmpFileName !< Temporary file name if not passing HD or SS input file contents directly
251257

252258
real(DbKi) :: TimeInterval !< timestep for HD
253259
integer(IntKi) :: ErrStat !< aggregated error message
@@ -327,8 +333,21 @@ SUBROUTINE HydroDyn_C_Init( OutRootName_C,
327333
! Get fortran pointer to C_NULL_CHAR deliniated input file as a string
328334
call C_F_pointer(SeaSt_InputFileString_C, SeaSt_InputFileString)
329335

330-
! Get the data to pass to SeaSt%Init
331-
call InitFileInfo(SeaSt_InputFileString, SeaSt%InitInp%PassedFileData, ErrStat2, ErrMsg2); if (Failed()) return
336+
! Format SeaSt input file contents
337+
if (SeaSt_InputFilePassed==1_c_int) then
338+
! Get the data to pass to SeaSt%Init
339+
SeaSt%InitInp%InputFile = "passed_SeaSt_file" ! dummy
340+
SeaSt%InitInp%UseInputFile = .FALSE. ! this probably should be passed in
341+
call InitFileInfo(SeaSt_InputFileString, SeaSt%InitInp%PassedFileData, ErrStat2, ErrMsg2); if (Failed()) return
342+
else
343+
i = min(IntfStrLen,SeaSt_InputFileStringLength_C)
344+
TmpFileName = ''
345+
TmpFileName(1:i) = SeaSt_InputFileString(1:i)
346+
i = INDEX(TmpFileName,C_NULL_CHAR) - 1 ! if this has a c null character at the end...
347+
if ( i > 0 ) TmpFileName = TmpFileName(1:I) ! remove it
348+
SeaSt%InitInp%InputFile = TmpFileName
349+
SeaSt%InitInp%UseInputFile = .TRUE.
350+
endif
332351

333352
! For diagnostic purposes, the following can be used to display the contents
334353
! of the InFileInfo data structure.
@@ -337,8 +356,7 @@ SUBROUTINE HydroDyn_C_Init( OutRootName_C,
337356

338357
! Set other inputs for calling SeaState_Init
339358
SeaSt%InitInp%hasIce = .FALSE. ! Always keep at false unless interfacing to ice modules
340-
SeaSt%InitInp%InputFile = "passed_SeaSt_file" ! dummy
341-
SeaSt%InitInp%UseInputFile = .FALSE. ! this probably should be passed in
359+
342360
! Linearization
343361
! for now, set linearization to false. Pass this in later when interface supports it
344362
! Note: we may want to linearize at T=0 for added mass effects, but that might be
@@ -384,17 +402,28 @@ SUBROUTINE HydroDyn_C_Init( OutRootName_C,
384402
! Get fortran pointer to C_NULL_CHAR deliniated input file as a string
385403
call C_F_pointer(HD_InputFileString_C, HD_InputFileString)
386404

387-
! Get the data to pass to HD%Init
388-
call InitFileInfo(HD_InputFileString, HD%InitInp%PassedFileData, ErrStat2, ErrMsg2); if (Failed()) return
405+
! Format HD input file contents
406+
if (HD_InputFilePassed==1_c_int) then
407+
! Get the data to pass to HD%InitInp
408+
HD%InitInp%InputFile = "passed_hd_file" ! dummy
409+
HD%InitInp%UseInputFile = .FALSE. ! this probably should be passed in
410+
call InitFileInfo(HD_InputFileString, HD%InitInp%PassedFileData, ErrStat2, ErrMsg2); if (Failed()) return
411+
else
412+
i = min(IntfStrLen, HD_InputFileStringLength_C)
413+
TmpFileName = ''
414+
TmpFileName(1:i) = HD_InputFileString(1:i)
415+
i = INDEX(TmpFileName,C_NULL_CHAR) - 1 ! if this has a c null character at the end...
416+
if ( i > 0 ) TmpFileName = TmpFileName(1:I) ! remove it
417+
HD%InitInp%InputFile = TmpFileName
418+
HD%InitInp%UseInputFile = .TRUE.
419+
endif
389420

390421
! For diagnostic purposes, the following can be used to display the contents
391422
! of the InFileInfo data structure.
392423
! CU is the screen -- system dependent.
393424
!call Print_FileInfo_Struct( CU, HD%InitInp%PassedFileData )
394425

395426
! Set other inputs for calling HydroDyn_Init
396-
HD%InitInp%InputFile = "passed_hd_file" ! dummy
397-
HD%InitInp%UseInputFile = .FALSE. ! this probably should be passed in
398427
! Linearization
399428
! for now, set linearization to false. Pass this in later when interface supports it
400429
! Note: we may want to linearize at T=0 for added mass effects, but that might be

0 commit comments

Comments
 (0)