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

Add support for initializing InflowWind with string inputs #596

Merged
merged 1 commit into from
Nov 19, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions .github/actions/tests-module-inflowwind/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
name: 'InflowWind module tests'
description: 'Run tests specific to the InflowWind module'
author: 'Rafael Mudafort https://github.com/rafmudaf'
runs:
using: "composite"
steps:
- run: ctest -VV -R inflowwind_utest
working-directory: "/openfast/build"
shell: bash
2 changes: 2 additions & 0 deletions .github/workflows/automated-dev-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ jobs:
uses: ./.github/actions/tests-module-aerodyn
- name: 'Run BeamDyn tests'
uses: ./.github/actions/tests-module-beamdyn
- name: 'Run InflowWind tests'
uses: ./.github/actions/tests-module-inflowwind
- name: 'Run OpenFAST tests'
# if: contains(github.event.head_commit.message, 'Action - Test All') || contains(github.event.pull_request.labels.*.name, 'Action - Test All')
uses: ./.github/actions/tests-gluecode-openfast
Expand Down
350 changes: 200 additions & 150 deletions modules/inflowwind/src/IfW_UniformWind.f90

Large diffs are not rendered by default.

12 changes: 7 additions & 5 deletions modules/inflowwind/src/IfW_UniformWind.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,12 @@ include Registry_NWTC_Library.txt

#########################

typedef IfW_UniformWind/IfW_UniformWind InitInputType CHARACTER(1024) WindFileName - - - "Name of the wind file to use" -
typedef ^ ^ ReKi ReferenceHeight - - - "Hub height of the turbine" meters
typedef ^ ^ ReKi RefLength - - - "RefLength of the wind field to use" meters
typedef ^ ^ IntKi SumFileUnit - - - "Unit number for the summary file (-1 for none). Provided by IfW." -
typedef IfW_UniformWind/IfW_UniformWind InitInputType CHARACTER(1024) WindFileName - - - "Name of the wind file to use" -
typedef ^ ^ ReKi ReferenceHeight - - - "Hub height of the turbine" meters
typedef ^ ^ ReKi RefLength - - - "RefLength of the wind field to use" meters
typedef ^ ^ IntKi SumFileUnit - - - "Unit number for the summary file (-1 for none). Provided by IfW." -
typedef ^ ^ LOGICAL UseInputFile - .TRUE. - "Flag for toggling file based IO in wind type 2." -
typedef ^ ^ FileInfoType PassedFileData - - - "Optional slot for wind type 2 data if file IO is not used." -



Expand All @@ -30,7 +32,7 @@ typedef ^ ^ LOGICAL WindFileConsta
# ..... Misc/Optimization variables.................................................................................................
# Define any data that are used only for efficiency purposes (these variables are not associated with time):
# e.g. indices for searching in an array, large arrays that are local variables in any routine called multiple times, etc.
typedef ^ MiscVarType IntKi TimeIndex - - - "An Index into the TData array" -
typedef ^ MiscVarType IntKi TimeIndex - 0 - "An Index into the TData array" -


# ..... Parameters ................................................................................................................
Expand Down
100 changes: 99 additions & 1 deletion modules/inflowwind/src/IfW_UniformWind_Types.f90
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ MODULE IfW_UniformWind_Types
REAL(ReKi) :: ReferenceHeight !< Hub height of the turbine [meters]
REAL(ReKi) :: RefLength !< RefLength of the wind field to use [meters]
INTEGER(IntKi) :: SumFileUnit !< Unit number for the summary file (-1 for none). Provided by IfW. [-]
LOGICAL :: UseInputFile = .TRUE. !< Flag for toggling file based IO in wind type 2. [-]
TYPE(FileInfoType) :: PassedFileData !< Optional slot for wind type 2 data if file IO is not used. [-]
END TYPE IfW_UniformWind_InitInputType
! =======================
! ========= IfW_UniformWind_InitOutputType =======
Expand All @@ -52,7 +54,7 @@ MODULE IfW_UniformWind_Types
! =======================
! ========= IfW_UniformWind_MiscVarType =======
TYPE, PUBLIC :: IfW_UniformWind_MiscVarType
INTEGER(IntKi) :: TimeIndex !< An Index into the TData array [-]
INTEGER(IntKi) :: TimeIndex = 0 !< An Index into the TData array [-]
END TYPE IfW_UniformWind_MiscVarType
! =======================
! ========= IfW_UniformWind_ParameterType =======
Expand Down Expand Up @@ -101,6 +103,10 @@ SUBROUTINE IfW_UniformWind_CopyInitInput( SrcInitInputData, DstInitInputData, Ct
DstInitInputData%ReferenceHeight = SrcInitInputData%ReferenceHeight
DstInitInputData%RefLength = SrcInitInputData%RefLength
DstInitInputData%SumFileUnit = SrcInitInputData%SumFileUnit
DstInitInputData%UseInputFile = SrcInitInputData%UseInputFile
CALL NWTC_Library_Copyfileinfotype( SrcInitInputData%PassedFileData, DstInitInputData%PassedFileData, CtrlCode, ErrStat2, ErrMsg2 )
CALL SetErrStat(ErrStat2, ErrMsg2, ErrStat, ErrMsg,RoutineName)
IF (ErrStat>=AbortErrLev) RETURN
END SUBROUTINE IfW_UniformWind_CopyInitInput

SUBROUTINE IfW_UniformWind_DestroyInitInput( InitInputData, ErrStat, ErrMsg )
Expand All @@ -112,6 +118,7 @@ SUBROUTINE IfW_UniformWind_DestroyInitInput( InitInputData, ErrStat, ErrMsg )
!
ErrStat = ErrID_None
ErrMsg = ""
CALL NWTC_Library_Destroyfileinfotype( InitInputData%PassedFileData, ErrStat, ErrMsg )
END SUBROUTINE IfW_UniformWind_DestroyInitInput

SUBROUTINE IfW_UniformWind_PackInitInput( ReKiBuf, DbKiBuf, IntKiBuf, Indata, ErrStat, ErrMsg, SizeOnly )
Expand Down Expand Up @@ -153,6 +160,25 @@ SUBROUTINE IfW_UniformWind_PackInitInput( ReKiBuf, DbKiBuf, IntKiBuf, Indata, Er
Re_BufSz = Re_BufSz + 1 ! ReferenceHeight
Re_BufSz = Re_BufSz + 1 ! RefLength
Int_BufSz = Int_BufSz + 1 ! SumFileUnit
Int_BufSz = Int_BufSz + 1 ! UseInputFile
! Allocate buffers for subtypes, if any (we'll get sizes from these)
Int_BufSz = Int_BufSz + 3 ! PassedFileData: size of buffers for each call to pack subtype
CALL NWTC_Library_Packfileinfotype( Re_Buf, Db_Buf, Int_Buf, InData%PassedFileData, ErrStat2, ErrMsg2, .TRUE. ) ! PassedFileData
CALL SetErrStat(ErrStat2, ErrMsg2, ErrStat, ErrMsg, RoutineName)
IF (ErrStat >= AbortErrLev) RETURN

IF(ALLOCATED(Re_Buf)) THEN ! PassedFileData
Re_BufSz = Re_BufSz + SIZE( Re_Buf )
DEALLOCATE(Re_Buf)
END IF
IF(ALLOCATED(Db_Buf)) THEN ! PassedFileData
Db_BufSz = Db_BufSz + SIZE( Db_Buf )
DEALLOCATE(Db_Buf)
END IF
IF(ALLOCATED(Int_Buf)) THEN ! PassedFileData
Int_BufSz = Int_BufSz + SIZE( Int_Buf )
DEALLOCATE(Int_Buf)
END IF
IF ( Re_BufSz .GT. 0 ) THEN
ALLOCATE( ReKiBuf( Re_BufSz ), STAT=ErrStat2 )
IF (ErrStat2 /= 0) THEN
Expand Down Expand Up @@ -190,6 +216,36 @@ SUBROUTINE IfW_UniformWind_PackInitInput( ReKiBuf, DbKiBuf, IntKiBuf, Indata, Er
Re_Xferred = Re_Xferred + 1
IntKiBuf(Int_Xferred) = InData%SumFileUnit
Int_Xferred = Int_Xferred + 1
IntKiBuf(Int_Xferred) = TRANSFER(InData%UseInputFile, IntKiBuf(1))
Int_Xferred = Int_Xferred + 1
CALL NWTC_Library_Packfileinfotype( Re_Buf, Db_Buf, Int_Buf, InData%PassedFileData, ErrStat2, ErrMsg2, OnlySize ) ! PassedFileData
CALL SetErrStat(ErrStat2, ErrMsg2, ErrStat, ErrMsg, RoutineName)
IF (ErrStat >= AbortErrLev) RETURN

IF(ALLOCATED(Re_Buf)) THEN
IntKiBuf( Int_Xferred ) = SIZE(Re_Buf); Int_Xferred = Int_Xferred + 1
IF (SIZE(Re_Buf) > 0) ReKiBuf( Re_Xferred:Re_Xferred+SIZE(Re_Buf)-1 ) = Re_Buf
Re_Xferred = Re_Xferred + SIZE(Re_Buf)
DEALLOCATE(Re_Buf)
ELSE
IntKiBuf( Int_Xferred ) = 0; Int_Xferred = Int_Xferred + 1
ENDIF
IF(ALLOCATED(Db_Buf)) THEN
IntKiBuf( Int_Xferred ) = SIZE(Db_Buf); Int_Xferred = Int_Xferred + 1
IF (SIZE(Db_Buf) > 0) DbKiBuf( Db_Xferred:Db_Xferred+SIZE(Db_Buf)-1 ) = Db_Buf
Db_Xferred = Db_Xferred + SIZE(Db_Buf)
DEALLOCATE(Db_Buf)
ELSE
IntKiBuf( Int_Xferred ) = 0; Int_Xferred = Int_Xferred + 1
ENDIF
IF(ALLOCATED(Int_Buf)) THEN
IntKiBuf( Int_Xferred ) = SIZE(Int_Buf); Int_Xferred = Int_Xferred + 1
IF (SIZE(Int_Buf) > 0) IntKiBuf( Int_Xferred:Int_Xferred+SIZE(Int_Buf)-1 ) = Int_Buf
Int_Xferred = Int_Xferred + SIZE(Int_Buf)
DEALLOCATE(Int_Buf)
ELSE
IntKiBuf( Int_Xferred ) = 0; Int_Xferred = Int_Xferred + 1
ENDIF
END SUBROUTINE IfW_UniformWind_PackInitInput

SUBROUTINE IfW_UniformWind_UnPackInitInput( ReKiBuf, DbKiBuf, IntKiBuf, Outdata, ErrStat, ErrMsg )
Expand Down Expand Up @@ -229,6 +285,48 @@ SUBROUTINE IfW_UniformWind_UnPackInitInput( ReKiBuf, DbKiBuf, IntKiBuf, Outdata,
Re_Xferred = Re_Xferred + 1
OutData%SumFileUnit = IntKiBuf(Int_Xferred)
Int_Xferred = Int_Xferred + 1
OutData%UseInputFile = TRANSFER(IntKiBuf(Int_Xferred), OutData%UseInputFile)
Int_Xferred = Int_Xferred + 1
Buf_size=IntKiBuf( Int_Xferred )
Int_Xferred = Int_Xferred + 1
IF(Buf_size > 0) THEN
ALLOCATE(Re_Buf(Buf_size),STAT=ErrStat2)
IF (ErrStat2 /= 0) THEN
CALL SetErrStat(ErrID_Fatal, 'Error allocating Re_Buf.', ErrStat, ErrMsg,RoutineName)
RETURN
END IF
Re_Buf = ReKiBuf( Re_Xferred:Re_Xferred+Buf_size-1 )
Re_Xferred = Re_Xferred + Buf_size
END IF
Buf_size=IntKiBuf( Int_Xferred )
Int_Xferred = Int_Xferred + 1
IF(Buf_size > 0) THEN
ALLOCATE(Db_Buf(Buf_size),STAT=ErrStat2)
IF (ErrStat2 /= 0) THEN
CALL SetErrStat(ErrID_Fatal, 'Error allocating Db_Buf.', ErrStat, ErrMsg,RoutineName)
RETURN
END IF
Db_Buf = DbKiBuf( Db_Xferred:Db_Xferred+Buf_size-1 )
Db_Xferred = Db_Xferred + Buf_size
END IF
Buf_size=IntKiBuf( Int_Xferred )
Int_Xferred = Int_Xferred + 1
IF(Buf_size > 0) THEN
ALLOCATE(Int_Buf(Buf_size),STAT=ErrStat2)
IF (ErrStat2 /= 0) THEN
CALL SetErrStat(ErrID_Fatal, 'Error allocating Int_Buf.', ErrStat, ErrMsg,RoutineName)
RETURN
END IF
Int_Buf = IntKiBuf( Int_Xferred:Int_Xferred+Buf_size-1 )
Int_Xferred = Int_Xferred + Buf_size
END IF
CALL NWTC_Library_Unpackfileinfotype( Re_Buf, Db_Buf, Int_Buf, OutData%PassedFileData, ErrStat2, ErrMsg2 ) ! PassedFileData
CALL SetErrStat(ErrStat2, ErrMsg2, ErrStat, ErrMsg, RoutineName)
IF (ErrStat >= AbortErrLev) RETURN

IF(ALLOCATED(Re_Buf )) DEALLOCATE(Re_Buf )
IF(ALLOCATED(Db_Buf )) DEALLOCATE(Db_Buf )
IF(ALLOCATED(Int_Buf)) DEALLOCATE(Int_Buf)
END SUBROUTINE IfW_UniformWind_UnPackInitInput

SUBROUTINE IfW_UniformWind_CopyInitOutput( SrcInitOutputData, DstInitOutputData, CtrlCode, ErrStat, ErrMsg )
Expand Down
44 changes: 31 additions & 13 deletions modules/inflowwind/src/InflowWind.f90
Original file line number Diff line number Diff line change
Expand Up @@ -139,13 +139,14 @@ SUBROUTINE InflowWind_Init( InitInp, InputGuess, p, ContStates, DiscStates,

TYPE(IfW_4Dext_InitOutputType) :: FDext_InitOutData !< initialization info

TYPE(FileInfoType) :: InFileInfo !< The derived type for holding the full input file for parsing -- we may pass this in the future
!!! TYPE(CTBladed_Backgr) :: BackGrndValues


! Temporary variables for error handling
INTEGER(IntKi) :: TmpErrStat
CHARACTER(ErrMsgLen) :: TmpErrMsg !< temporary error message

CHARACTER(1024) :: PriPath

! Local Variables
INTEGER(IntKi) :: I, j !< Generic counter
Expand Down Expand Up @@ -182,37 +183,51 @@ SUBROUTINE InflowWind_Init( InitInp, InputGuess, p, ContStates, DiscStates,
EchoFileName = TRIM(p%RootFileName)//".ech"
SumFileName = TRIM(p%RootFileName)//".sum"

! these values (and others hard-coded in lidar_init) should be set in the input file, too
InputFileData%SensorType = InitInp%lidar%SensorType
InputFileData%NumPulseGate = InitInp%lidar%NumPulseGate
InputFileData%RotorApexOffsetPos = InitInp%lidar%RotorApexOffsetPos
InputFileData%LidRadialVel = InitInp%lidar%LidRadialVel

! Parse all the InflowWind related input files and populate the *_InitDataType derived types
CALL GetPath( InitInp%InputFileName, PriPath )

IF ( InitInp%UseInputFile ) THEN
CALL InflowWind_ReadInput( InitInp%InputFileName, EchoFileName, InputFileData, TmpErrStat, TmpErrMsg )
CALL ProcessComFile( InitInp%InputFileName, InFileInfo, TmpErrStat, TmpErrMsg )
! For diagnostic purposes, the following can be used to display the contents
! of the InFileInfo data structure.
! call Print_FileInfo_Struct( CU, InFileInfo ) ! CU is the screen -- different number on different systems.

CALL SetErrStat(TmpErrStat,TmpErrMsg,ErrStat,ErrMsg,RoutineName)
IF ( ErrStat >= AbortErrLev ) THEN
CALL Cleanup()
RETURN
ENDIF

! these values (and others hard-coded in lidar_init) should be set in the input file, too
InputFileData%SensorType = InitInp%lidar%SensorType
InputFileData%NumPulseGate = InitInp%lidar%NumPulseGate
InputFileData%RotorApexOffsetPos = InitInp%lidar%RotorApexOffsetPos
InputFileData%LidRadialVel = InitInp%lidar%LidRadialVel

ELSE

CALL InflowWind_CopyInputFile( InitInp%PassedFileData, InputFileData, MESH_NEWCOPY, TmpErrStat, TmpErrMsg )
CALL SetErrStat(TmpErrStat,TmpErrMsg,ErrStat,ErrMsg,RoutineName)
CALL NWTC_Library_CopyFileInfoType( InitInp%PassedFileData, InFileInfo, MESH_NEWCOPY, TmpErrStat, TmpErrMsg )
CALL SetErrStat(TmpErrStat,TmpErrMsg,ErrStat,ErrMsg,RoutineName)
IF ( ErrStat >= AbortErrLev ) THEN
CALL Cleanup()
RETURN
ENDIF

ENDIF

CALL InflowWind_ParseInputFileInfo( InputFileData, InFileInfo, PriPath, TmpErrStat, TmpErrMsg )
CALL SetErrStat(TmpErrStat,TmpErrMsg,ErrStat,ErrMsg,RoutineName)
IF ( ErrStat >= AbortErrLev ) THEN
CALL Cleanup()
CALL InflowWind_DestroyInputFile( InputFileData, TmpErrStat, TmpErrMsg )
RETURN
ENDIF
! let's tell InflowWind if an external module (e.g., FAST.Farm) is going to set the velocity grids.

IF ( InitInp%Use4Dext) then
InputFileData%WindType = FDext_WindNumber
InputFileData%PropagationDir = 0.0_ReKi ! wind is in XYZ coordinates (already rotated if necessary), so don't rotate it again
END IF



! initialize sensor data:
CALL Lidar_Init( InitInp, InputGuess, p, ContStates, DiscStates, ConstrStateGuess, OtherStates, &
y, m, TimeInterval, InitOutData, TmpErrStat, TmpErrMsg )
Expand Down Expand Up @@ -387,6 +402,9 @@ SUBROUTINE InflowWind_Init( InitInp, InputGuess, p, ContStates, DiscStates,
Uniform_InitData%WindFileName = InputFileData%Uniform_FileName
Uniform_InitData%SumFileUnit = SumFileUnit

Uniform_InitData%UseInputFile = InitInp%WindType2UseInputFile
Uniform_InitData%PassedFileData = InitInp%WindType2Data

! Initialize the UniformWind module
CALL IfW_UniformWind_Init(Uniform_InitData, p%UniformWind, &
m%UniformWind, TimeInterval, Uniform_InitOutData, TmpErrStat, TmpErrMsg)
Expand Down
6 changes: 4 additions & 2 deletions modules/inflowwind/src/InflowWind.txt
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ typedef ^ ^ ReKi Uniform_Ref
typedef ^ ^ CHARACTER(1024) TSFF_FileName - - - "TurbSim Full-Field -- filename" -
typedef ^ ^ CHARACTER(1024) BladedFF_FileName - - - "Bladed-style Full-Field -- filename" -
typedef ^ ^ LOGICAL BladedFF_TowerFile - - - "Bladed-style Full-Field -- tower file exists" -
typedef ^ ^ LOGICAL CTTS_CoherentTurb - - - "Coherent turbulence data exists" -
typedef ^ ^ LOGICAL CTTS_CoherentTurb - .FALSE. - "Coherent turbulence data exists" -
typedef ^ ^ CHARACTER(1024) CTTS_FileName - - - "Name of coherent turbulence file" -
typedef ^ ^ CHARACTER(1024) CTTS_Path - - - "Path to coherent turbulence binary data files" -
typedef ^ ^ CHARACTER(1024) HAWC_FileName_u - - - "HAWC -- u component binary data file name" -
Expand Down Expand Up @@ -116,7 +116,9 @@ typedef ^ ^ LOGICAL Use4Dext
typedef ^ ^ IntKi NumWindPoints - - - "Number of wind velocity points expected" -
typedef ^ ^ LOGICAL UseInputFile - .TRUE. - "Should we read everthing from an input file, or do we get it some other way" -
typedef ^ ^ CHARACTER(1024) RootName - - - "RootName for writing output files"
typedef ^ ^ InflowWind_InputFile PassedFileData - - - "If we don't use the input file, pass everything through this" -
typedef ^ ^ FileInfoType PassedFileData - - - "If we don't use the input file, pass everything through this" -
typedef ^ ^ LOGICAL WindType2UseInputFile - .TRUE. - "Flag for toggling file based IO in wind type 2." -
typedef ^ ^ FileInfoType WindType2Data - - - "Optional slot for wind type 2 data if file IO is not used." -
typedef ^ ^ Lidar_InitInputType lidar - - - "InitInput for lidar data" -
typedef ^ ^ IfW_4Dext_InitInputType FDext - - - "InitInput for lidar data" -

Expand Down
Loading