Skip to content

Commit

Permalink
Merge pull request #1 from andrew-platt/feature/Environmental_Variables
Browse files Browse the repository at this point in the history
Move environment vars for HD init into InitInpType
  • Loading branch information
hkross authored May 18, 2021
2 parents 0f4c81c + 89c31f9 commit 478bec0
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 15 deletions.
7 changes: 2 additions & 5 deletions modules/hydrodyn/src/HydroDyn.f90
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ END SUBROUTINE WvStretch_Init
!> This routine is called at the start of the simulation to perform initialization steps.
!! The parameters are set here and not changed during the simulation.
!! The initial states and initial guess for the input are defined.
SUBROUTINE HydroDyn_Init( InitInp, u, p, x, xd, z, OtherState, y, m, Interval, defWtrDens, defWtrDpth, defMSL2SWL, InitOut, ErrStat, ErrMsg )
SUBROUTINE HydroDyn_Init( InitInp, u, p, x, xd, z, OtherState, y, m, Interval, InitOut, ErrStat, ErrMsg )
!..................................................................................................................................

TYPE(HydroDyn_InitInputType), INTENT(IN ) :: InitInp !< Input data for initialization routine.
Expand All @@ -241,9 +241,6 @@ SUBROUTINE HydroDyn_Init( InitInp, u, p, x, xd, z, OtherState, y, m, Interval, d
!! Input is the suggested time from the glue code;
!! Output is the actual coupling interval that will be used
!! by the glue code.
REAL(ReKi), INTENT(IN ) :: defWtrDens !< Default water density from the driver; may be overwritten
REAL(ReKi), INTENT(IN ) :: defWtrDpth !< Default water depth from the driver; may be overwritten
REAL(ReKi), INTENT(IN ) :: defMSL2SWL !< Default mean sea level to still water level from the driver; may be overwritten
TYPE(HydroDyn_InitOutputType), INTENT( OUT) :: InitOut !< Output for initialization routine
INTEGER(IntKi), INTENT( OUT) :: ErrStat !< Error status of the operation
CHARACTER(*), INTENT( OUT) :: ErrMsg !< Error message if ErrStat /= ErrID_None
Expand Down Expand Up @@ -364,7 +361,7 @@ SUBROUTINE HydroDyn_Init( InitInp, u, p, x, xd, z, OtherState, y, m, Interval, d

! Parse all HydroDyn-related input files and populate the *_InitInputType derived types

CALL HydroDynInput_GetInput( InitLocal, defWtrDens, defWtrDpth, defMSL2SWL, ErrStat2, ErrMsg2 )
CALL HydroDynInput_GetInput( InitLocal, ErrStat2, ErrMsg2 )
CALL SetErrStat(ErrStat2,ErrMsg2,ErrStat,ErrMsg,RoutineName)
IF ( ErrStat >= AbortErrLev ) THEN
CALL CleanUp()
Expand Down
3 changes: 3 additions & 0 deletions modules/hydrodyn/src/HydroDyn.txt
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ typedef ^ ^ CHARACTER(1
typedef ^ ^ Logical Linearize - .FALSE. - "Flag that tells this module if the glue code wants to linearize." -
typedef ^ ^ DbKi DT - - - "Supplied by Driver: Simulation time step" "(sec)"
typedef ^ ^ ReKi Gravity - - - "Supplied by Driver: Gravitational acceleration" "(m/s^2)"
typedef ^ ^ ReKi defWtrDens - - - "Default water density from the driver; may be overwritten " "(kg/m^3)"
typedef ^ ^ ReKi defWtrDpth - - - "Default water depth from the driver; may be overwritten " "m"
typedef ^ ^ ReKi defMSL2SWL - - - "Default mean sea level to still water level from the driver; may be overwritten" "m"
typedef ^ ^ DbKi TMax - - - "Supplied by Driver: The total simulation time" "(sec)"
typedef ^ ^ LOGICAL HasIce - - - "Supplied by Driver: Whether this simulation has ice loading (flag)" -
typedef ^ ^ SiKi WaveElevXY {:}{:} - - "Supplied by Driver: X-Y locations for WaveElevation output (for visualization). First dimension is the X (1) and Y (2) coordinate. Second dimension is the point number." "m,-"
Expand Down
5 changes: 4 additions & 1 deletion modules/hydrodyn/src/HydroDyn_DriverCode.f90
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,9 @@ PROGRAM HydroDynDriver
STOP
END IF
InitInData%Gravity = drvrInitInp%Gravity
InitInData%defWtrDens = drvrInitInp%WtrDens
InitInData%defWtrDpth = drvrInitInp%WtrDpth
InitInData%defMSL2SWL = drvrInitInp%MSL2SWL
InitInData%UseInputFile = .TRUE.
InitInData%InputFile = drvrInitInp%HDInputFile
InitInData%OutRootName = drvrInitInp%OutRootName
Expand Down Expand Up @@ -302,7 +305,7 @@ PROGRAM HydroDynDriver

! Initialize the module
Interval = drvrInitInp%TimeInterval
CALL HydroDyn_Init( InitInData, u(1), p, x, xd, z, OtherState, y, m, Interval, drvrInitInp%WtrDens, drvrInitInp%WtrDpth, drvrInitInp%MSL2SWL, InitOutData, ErrStat, ErrMsg )
CALL HydroDyn_Init( InitInData, u(1), p, x, xd, z, OtherState, y, m, Interval, InitOutData, ErrStat, ErrMsg )
if (errStat >= AbortErrLev) then
! Clean up and exit
call HD_DvrCleanup()
Expand Down
11 changes: 4 additions & 7 deletions modules/hydrodyn/src/HydroDyn_Input.f90
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ END SUBROUTINE CleanupEchoFile


!====================================================================================================
SUBROUTINE HydroDynInput_GetInput( InitInp, defWtrDens, defWtrDpth, defMSL2SWL, ErrStat, ErrMsg )
SUBROUTINE HydroDynInput_GetInput( InitInp, ErrStat, ErrMsg )
! This public subroutine reads the input required for HydroDyn from the file whose name is an
! input parameter.
!----------------------------------------------------------------------------------------------------
Expand All @@ -253,9 +253,6 @@ SUBROUTINE HydroDynInput_GetInput( InitInp, defWtrDens, defWtrDpth, defMSL2SWL,
! Passed variables

TYPE(HydroDyn_InitInputType), INTENT( INOUT ) :: InitInp ! the hydrodyn data
REAL(ReKi), INTENT(IN ) :: defWtrDens ! default water density from the driver; may be overwritten
REAL(ReKi), INTENT(IN ) :: defWtrDpth ! default water depth from the driver; may be overwritten
REAL(ReKi), INTENT(IN ) :: defMSL2SWL ! default mean sea level to still water level from the driver; may be overwritten
INTEGER, INTENT( OUT ) :: ErrStat ! returns a non-zero value when an error occurs
CHARACTER(*), INTENT( OUT ) :: ErrMsg ! Error message if ErrStat /= ErrID_None

Expand Down Expand Up @@ -376,7 +373,7 @@ SUBROUTINE HydroDynInput_GetInput( InitInp, defWtrDens, defWtrDpth, defMSL2SWL,

! WtrDens - Water density.

CALL ReadVarWDefault ( UnIn, FileName, InitInp%Waves%WtrDens, 'WtrDens', 'Water density', defWtrDens, ErrStat2, ErrMsg2, UnEchoLocal )
CALL ReadVarWDefault ( UnIn, FileName, InitInp%Waves%WtrDens, 'WtrDens', 'Water density', InitInp%defWtrDens, ErrStat2, ErrMsg2, UnEchoLocal )
CALL SetErrStat( ErrStat2, ErrMsg2, ErrStat, ErrMsg, 'HydroDynInput_GetInput' )
IF (ErrStat >= AbortErrLev) THEN
CALL CleanUp()
Expand All @@ -386,7 +383,7 @@ SUBROUTINE HydroDynInput_GetInput( InitInp, defWtrDens, defWtrDpth, defMSL2SWL,

! WtrDpth - Water depth

CALL ReadVarWDefault ( UnIn, FileName, InitInp%Morison%WtrDpth, 'WtrDpth', 'Water depth', defWtrDpth, ErrStat2, ErrMsg2, UnEchoLocal )
CALL ReadVarWDefault ( UnIn, FileName, InitInp%Morison%WtrDpth, 'WtrDpth', 'Water depth', InitInp%defWtrDpth, ErrStat2, ErrMsg2, UnEchoLocal )
CALL SetErrStat( ErrStat2, ErrMsg2, ErrStat, ErrMsg, 'HydroDynInput_GetInput' )
IF (ErrStat >= AbortErrLev) THEN
CALL CleanUp()
Expand All @@ -396,7 +393,7 @@ SUBROUTINE HydroDynInput_GetInput( InitInp, defWtrDens, defWtrDpth, defMSL2SWL,

! MSL2SWL

CALL ReadVarWDefault ( UnIn, FileName, InitInp%Morison%MSL2SWL, 'MSL2SWL', 'MSL to SWL offset', defMSL2SWL, ErrStat2, ErrMsg2, UnEchoLocal )
CALL ReadVarWDefault ( UnIn, FileName, InitInp%Morison%MSL2SWL, 'MSL2SWL', 'MSL to SWL offset', InitInp%defMSL2SWL, ErrStat2, ErrMsg2, UnEchoLocal )
CALL SetErrStat( ErrStat2, ErrMsg2, ErrStat, ErrMsg, 'HydroDynInput_GetInput' )
IF (ErrStat >= AbortErrLev) THEN
CALL CleanUp()
Expand Down
21 changes: 21 additions & 0 deletions modules/hydrodyn/src/HydroDyn_Types.f90
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@ MODULE HydroDyn_Types
LOGICAL :: Linearize = .FALSE. !< Flag that tells this module if the glue code wants to linearize. [-]
REAL(DbKi) :: DT !< Supplied by Driver: Simulation time step [(sec)]
REAL(ReKi) :: Gravity !< Supplied by Driver: Gravitational acceleration [(m/s^2)]
REAL(ReKi) :: defWtrDens !< Default water density from the driver; may be overwritten [(kg/m^3)]
REAL(ReKi) :: defWtrDpth !< Default water depth from the driver; may be overwritten [m]
REAL(ReKi) :: defMSL2SWL !< Default mean sea level to still water level from the driver; may be overwritten [m]
REAL(DbKi) :: TMax !< Supplied by Driver: The total simulation time [(sec)]
LOGICAL :: HasIce !< Supplied by Driver: Whether this simulation has ice loading (flag) [-]
REAL(SiKi) , DIMENSION(:,:), ALLOCATABLE :: WaveElevXY !< Supplied by Driver: X-Y locations for WaveElevation output (for visualization). First dimension is the X (1) and Y (2) coordinate. Second dimension is the point number. [m,-]
Expand Down Expand Up @@ -256,6 +259,9 @@ SUBROUTINE HydroDyn_CopyInitInput( SrcInitInputData, DstInitInputData, CtrlCode,
DstInitInputData%Linearize = SrcInitInputData%Linearize
DstInitInputData%DT = SrcInitInputData%DT
DstInitInputData%Gravity = SrcInitInputData%Gravity
DstInitInputData%defWtrDens = SrcInitInputData%defWtrDens
DstInitInputData%defWtrDpth = SrcInitInputData%defWtrDpth
DstInitInputData%defMSL2SWL = SrcInitInputData%defMSL2SWL
DstInitInputData%TMax = SrcInitInputData%TMax
DstInitInputData%HasIce = SrcInitInputData%HasIce
IF (ALLOCATED(SrcInitInputData%WaveElevXY)) THEN
Expand Down Expand Up @@ -609,6 +615,9 @@ SUBROUTINE HydroDyn_PackInitInput( ReKiBuf, DbKiBuf, IntKiBuf, Indata, ErrStat,
Int_BufSz = Int_BufSz + 1 ! Linearize
Db_BufSz = Db_BufSz + 1 ! DT
Re_BufSz = Re_BufSz + 1 ! Gravity
Re_BufSz = Re_BufSz + 1 ! defWtrDens
Re_BufSz = Re_BufSz + 1 ! defWtrDpth
Re_BufSz = Re_BufSz + 1 ! defMSL2SWL
Db_BufSz = Db_BufSz + 1 ! TMax
Int_BufSz = Int_BufSz + 1 ! HasIce
Int_BufSz = Int_BufSz + 1 ! WaveElevXY allocated yes/no
Expand Down Expand Up @@ -854,6 +863,12 @@ SUBROUTINE HydroDyn_PackInitInput( ReKiBuf, DbKiBuf, IntKiBuf, Indata, ErrStat,
Db_Xferred = Db_Xferred + 1
ReKiBuf(Re_Xferred) = InData%Gravity
Re_Xferred = Re_Xferred + 1
ReKiBuf(Re_Xferred) = InData%defWtrDens
Re_Xferred = Re_Xferred + 1
ReKiBuf(Re_Xferred) = InData%defWtrDpth
Re_Xferred = Re_Xferred + 1
ReKiBuf(Re_Xferred) = InData%defMSL2SWL
Re_Xferred = Re_Xferred + 1
DbKiBuf(Db_Xferred) = InData%TMax
Db_Xferred = Db_Xferred + 1
IntKiBuf(Int_Xferred) = TRANSFER(InData%HasIce, IntKiBuf(1))
Expand Down Expand Up @@ -1397,6 +1412,12 @@ SUBROUTINE HydroDyn_UnPackInitInput( ReKiBuf, DbKiBuf, IntKiBuf, Outdata, ErrSta
Db_Xferred = Db_Xferred + 1
OutData%Gravity = ReKiBuf(Re_Xferred)
Re_Xferred = Re_Xferred + 1
OutData%defWtrDens = ReKiBuf(Re_Xferred)
Re_Xferred = Re_Xferred + 1
OutData%defWtrDpth = ReKiBuf(Re_Xferred)
Re_Xferred = Re_Xferred + 1
OutData%defMSL2SWL = ReKiBuf(Re_Xferred)
Re_Xferred = Re_Xferred + 1
OutData%TMax = DbKiBuf(Db_Xferred)
Db_Xferred = Db_Xferred + 1
OutData%HasIce = TRANSFER(IntKiBuf(Int_Xferred), OutData%HasIce)
Expand Down
6 changes: 4 additions & 2 deletions modules/openfast-library/src/FAST_Subs.f90
Original file line number Diff line number Diff line change
Expand Up @@ -869,6 +869,9 @@ SUBROUTINE FAST_InitializeAll( t_initial, p_FAST, y_FAST, m_FAST, ED, BD, SrvD,
IF ( p_FAST%CompHydro == Module_HD ) THEN

Init%InData_HD%Gravity = p_FAST%Gravity
Init%InData_HD%defWtrDens = p_FAST%WtrDens
Init%InData_HD%defWtrDpth = p_FAST%WtrDpth
Init%InData_HD%defMSL2SWL = p_FAST%MSL2SWL
Init%InData_HD%UseInputFile = .TRUE.
Init%InData_HD%InputFile = p_FAST%HydroFile
Init%InData_HD%OutRootName = p_FAST%OutFileRoot
Expand All @@ -881,8 +884,7 @@ SUBROUTINE FAST_InitializeAll( t_initial, p_FAST, y_FAST, m_FAST, ED, BD, SrvD,
Init%InData_HD%PtfmLocationY = p_FAST%TurbinePos(2)

CALL HydroDyn_Init( Init%InData_HD, HD%Input(1), HD%p, HD%x(STATE_CURR), HD%xd(STATE_CURR), HD%z(STATE_CURR), &
HD%OtherSt(STATE_CURR), HD%y, HD%m, p_FAST%dt_module( MODULE_HD ), p_FAST%WtrDens, &
p_FAST%WtrDpth, p_FAST%MSL2SWL, Init%OutData_HD, ErrStat2, ErrMsg2 )
HD%OtherSt(STATE_CURR), HD%y, HD%m, p_FAST%dt_module( MODULE_HD ), Init%OutData_HD, ErrStat2, ErrMsg2 )
CALL SetErrStat(ErrStat2,ErrMsg2,ErrStat,ErrMsg,RoutineName)

p_FAST%ModuleInitialized(Module_HD) = .TRUE.
Expand Down

0 comments on commit 478bec0

Please sign in to comment.