Skip to content

Commit

Permalink
Minor updates to UA driver (#22)
Browse files Browse the repository at this point in the history
* UA driver: vs build

- vs project didn't like a `UA_OUTS` as both a preprocessor directive and value inside a type
- vs project needed LinDyn added to it
- moved override of UA_OUTS to UA driver and added initialization in BEMT & FVW so people could override the value before compiling if they wanted to debug UA inside of AeroDyn.

* LinDyn: states should be reals, not logicals

This would have caused issues when merging with the dev-unstable branch of OpenFAST

* fix typo in RoutineName parameter

* UA: minor updates

- update extension of UA output files
- explicitly initialize `d_34_to_ac`
  • Loading branch information
bjonkman authored Nov 30, 2023
1 parent 4bbb466 commit defd8b7
Show file tree
Hide file tree
Showing 9 changed files with 103 additions and 67 deletions.
5 changes: 4 additions & 1 deletion modules/aerodyn/src/BEMT.f90
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ subroutine BEMT_Set_UA_InitData( InitInp, interval, Init_UA_Data, errStat, errMs
call move_alloc(InitInp%UAOff_outerNode, Init_UA_Data%UAOff_outerNode)

Init_UA_Data%dt = interval
Init_UA_Data%OutRootName = InitInp%RootName ! was 'Debug.UA'
Init_UA_Data%OutRootName = trim(InitInp%RootName)//'.UA'

Init_UA_Data%numBlades = InitInp%numBlades
Init_UA_Data%nNodesPerBlade = InitInp%numBladeNodes
Expand All @@ -137,6 +137,9 @@ subroutine BEMT_Set_UA_InitData( InitInp, interval, Init_UA_Data, errStat, errMs
Init_UA_Data%ShedEffect = .true. ! This should be true when coupled to BEM
Init_UA_Data%WrSum = InitInp%SumPrint

Init_UA_Data%UA_OUTS = 0
Init_UA_Data%d_34_to_ac = 0.5_ReKi

end subroutine BEMT_Set_UA_InitData


Expand Down
5 changes: 4 additions & 1 deletion modules/aerodyn/src/FVW.f90
Original file line number Diff line number Diff line change
Expand Up @@ -1591,7 +1591,7 @@ subroutine UA_Init_Wrapper(AFInfo, InitInp, interval, p, x, xd, OtherState, m, E
Init_UA_Data%c(i,1) = p%W(iW)%chord_LL(i) ! NOTE: InitInp chord move-allocd to p
end do
Init_UA_Data%dt = interval
Init_UA_Data%OutRootName = trim(InitInp%RootName)//'W'//num2lstr(iW)
Init_UA_Data%OutRootName = trim(InitInp%RootName)//'W'//num2lstr(iW)//'.UA'
Init_UA_Data%numBlades = 1
Init_UA_Data%nNodesPerBlade = InitInp%numBladeNodes ! At AeroDyn ndoes, not CP

Expand All @@ -1600,6 +1600,9 @@ subroutine UA_Init_Wrapper(AFInfo, InitInp, interval, p, x, xd, OtherState, m, E
Init_UA_Data%a_s = InitInp%a_s ! Speed of sound, m/s
Init_UA_Data%ShedEffect = .False. ! Important, when coupling UA wih vortex code, shed vorticity is inherently accounted for
Init_UA_Data%WrSum = InitInp%SumPrint
Init_UA_Data%UA_OUTS = 0
Init_UA_Data%d_34_to_ac = 0.5_ReKi

allocate(Init_UA_Data%UAOff_innerNode(1), stat=errStat2)
allocate(Init_UA_Data%UAOff_outerNode(1), stat=errStat2)
Init_UA_Data%UAOff_innerNode(1) = InitInp%W(iW)%UAOff_innerNode
Expand Down
68 changes: 36 additions & 32 deletions modules/aerodyn/src/UA_Dvr_Subs.f90
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ subroutine ReadDriverInputFile( FileName, InitInp, ErrStat, ErrMsg )
type(FileInfoType) :: FI !< The derived type for holding the file information.
integer(IntKi) :: errStat2 ! Status of error message
character(1024) :: errMsg2 ! Error message if ErrStat /= ErrID_None
character(*), parameter :: RoutineName = 'ReadDriverfilename'
character(*), parameter :: RoutineName = 'ReadDriverInputFile'
! Initialize the echo file unit to -1 which is the default to prevent echoing, we will alter this based on user input
UnEcho = -1
ErrStat = ErrID_None
Expand Down Expand Up @@ -401,6 +401,10 @@ subroutine driverInputsToUAInitData(p, InitInData, AFI_Params, AFIndx, errStat,
errStat = ErrID_None
errMsg = ''
InitInData%UA_OUTS = 1 ! 0=None, 1=Write Outputs, 2=Separate File
#ifdef ADD_UA_OUTS
InitInData%UA_OUTS = 2 ! Compiler Flag Override, 2=Write a separate file
#endif


! -- UA Init Input Data
InitInData%nNodesPerBlade = 1
Expand All @@ -416,7 +420,7 @@ subroutine driverInputsToUAInitData(p, InitInData, AFI_Params, AFIndx, errStat,
InitInData%c(1,1) = p%Chord
InitInData%UAMod = p%UAMod
InitInData%Flookup = p%Flookup
InitInData%OutRootName = p%OutRootName
InitInData%OutRootName = trim(p%OutRootName)//'.UA'
InitInData%WrSum = p%SumPrint
InitInData%d_34_to_ac = p%d_34_to_ac ! d_34_to_ac = d_QT ~0.5 [-], Approximated using y coordinate

Expand Down Expand Up @@ -959,36 +963,36 @@ subroutine Dvr_WriteOutputs(nt, t, dvr, out, errStat, errMsg)
! Driver outputs
j = 1
if (dvr%p%SimMod==3) then
! TODO harmonization
out%outLine(j) = dvr%U0(1, 1) ; j=j+1 ! Ux
out%outLine(j) = dvr%U0(1, 2) ; j=j+1 ! Uy
out%outLine(j) = dvr%m%Vst_Q(1) ; j=j+1 ! VSTx_Q
out%outLine(j) = dvr%m%Vst_Q(2) ; j=j+1 ! VSTy_Q
out%outLine(j) = dvr%m%Vst_T(1) ; j=j+1 ! VSTx_T
out%outLine(j) = dvr%m%Vst_T(2) ; j=j+1 ! VSTy_T
out%outLine(j) = dvr%m%Vrel_Q(1) ; j=j+1 ! Vrelx_Q
out%outLine(j) = dvr%m%Vrel_Q(2) ; j=j+1 ! Vrely_Q
out%outLine(j) = dvr%m%Vrel_T(1) ; j=j+1 ! Vrelx_T
out%outLine(j) = dvr%m%Vrel_T(2) ; j=j+1 ! Vrely_T
out%outLine(j) = sqrt(dvr%m%Vrel_norm2_Q) ; j=j+1 ! Vrel_Q
out%outLine(j) = sqrt(dvr%m%Vrel_norm2_T) ; j=j+1 ! Vrel_T
out%outLine(j) = dvr%m%alpha_Q*R2D ; j=j+1 ! alpha_Q
out%outLine(j) = dvr%m%alpha_T*R2D ; j=j+1 ! alpha_T
out%outLine(j) = dvr%m%phi_Q *R2D ; j=j+1 ! phi_Q
out%outLine(j) = dvr%m%phi_T *R2D ; j=j+1 ! phi_T
out%outLine(j) = dvr%m%twist_full*R2D ; j=j+1 ! twist_full
out%outLine(j) = dvr%m%Re ; j=j+1 ! Re_T
out%outLine(j) = dvr%m%L ; j=j+1 ! L
out%outLine(j) = dvr%m%D ; j=j+1 ! D
out%outLine(j) = dvr%m%tau_Q ; j=j+1 ! M
out%outLine(j) = dvr%m%FxA ; j=j+1 ! Fx_A
out%outLine(j) = dvr%m%FyA ; j=j+1 ! Fy_A
out%outLine(j) = dvr%m%tau_A ; j=j+1 ! M_A
out%outLine(j) = dvr%m%GF(1) ; j=j+1 ! GFx
out%outLine(j) = dvr%m%GF(2) ; j=j+1 ! GFy
out%outLine(j) = dvr%m%GF(3) ; j=j+1 ! GFM
! LD Outputs
out%outLine(nDV+1:nDV+nLD) = dvr%LD_y%WriteOutput(1:nLD)
! TODO harmonization
out%outLine(j) = dvr%U0(1, 1) ; j=j+1 ! Ux
out%outLine(j) = dvr%U0(1, 2) ; j=j+1 ! Uy
out%outLine(j) = dvr%m%Vst_Q(1) ; j=j+1 ! VSTx_Q
out%outLine(j) = dvr%m%Vst_Q(2) ; j=j+1 ! VSTy_Q
out%outLine(j) = dvr%m%Vst_T(1) ; j=j+1 ! VSTx_T
out%outLine(j) = dvr%m%Vst_T(2) ; j=j+1 ! VSTy_T
out%outLine(j) = dvr%m%Vrel_Q(1) ; j=j+1 ! Vrelx_Q
out%outLine(j) = dvr%m%Vrel_Q(2) ; j=j+1 ! Vrely_Q
out%outLine(j) = dvr%m%Vrel_T(1) ; j=j+1 ! Vrelx_T
out%outLine(j) = dvr%m%Vrel_T(2) ; j=j+1 ! Vrely_T
out%outLine(j) = sqrt(dvr%m%Vrel_norm2_Q) ; j=j+1 ! Vrel_Q
out%outLine(j) = sqrt(dvr%m%Vrel_norm2_T) ; j=j+1 ! Vrel_T
out%outLine(j) = dvr%m%alpha_Q*R2D ; j=j+1 ! alpha_Q
out%outLine(j) = dvr%m%alpha_T*R2D ; j=j+1 ! alpha_T
out%outLine(j) = dvr%m%phi_Q *R2D ; j=j+1 ! phi_Q
out%outLine(j) = dvr%m%phi_T *R2D ; j=j+1 ! phi_T
out%outLine(j) = dvr%m%twist_full*R2D ; j=j+1 ! twist_full
out%outLine(j) = dvr%m%Re ; j=j+1 ! Re_T
out%outLine(j) = dvr%m%L ; j=j+1 ! L
out%outLine(j) = dvr%m%D ; j=j+1 ! D
out%outLine(j) = dvr%m%tau_Q ; j=j+1 ! M
out%outLine(j) = dvr%m%FxA ; j=j+1 ! Fx_A
out%outLine(j) = dvr%m%FyA ; j=j+1 ! Fy_A
out%outLine(j) = dvr%m%tau_A ; j=j+1 ! M_A
out%outLine(j) = dvr%m%GF(1) ; j=j+1 ! GFx
out%outLine(j) = dvr%m%GF(2) ; j=j+1 ! GFy
out%outLine(j) = dvr%m%GF(3) ; j=j+1 ! GFM
! LD Outputs
out%outLine(nDV+1:nDV+nLD) = dvr%LD_y%WriteOutput(1:nLD)
endif
! UA Outputs
out%outLine(nDV+nLD+1:nDV+nLD+nUA) = dvr%UA_y%WriteOutput(1:nUA)
Expand Down
17 changes: 7 additions & 10 deletions modules/aerodyn/src/UnsteadyAero.f90
Original file line number Diff line number Diff line change
Expand Up @@ -522,7 +522,7 @@ subroutine ComputeKelvinChain( i, j, u, p, xd, OtherState, misc, AFInfo, KC, BL_

KC%Cn_q_circ = KC%C_nalpha_circ*KC%q_f_cur/2.0 - KC%X3 - KC%X4 ! Eqn 1.16

else ! these aren't used (they are possibly output to UA output file (when UA_OUTS defined) file, though)
else ! these aren't used (they are possibly output to UA output file when UA_OUTS is > 0 file, though)
KC%X3 = 0.0_ReKi
KC%X4 = 0.0_ReKi
KC%Cn_q_circ = 0.0_ReKi
Expand Down Expand Up @@ -748,9 +748,6 @@ subroutine UA_SetParameters( dt, InitInp, p, AFInfo, AFIndx, ErrStat, ErrMsg )
p%Flookup = InitInp%Flookup
p%ShedEffect = InitInp%ShedEffect
p%UA_OUTS = InitInp%UA_OUTS
#ifdef UA_OUTS
p%UA_OUTS = 2 ! Compiler Flag Override, 2=Write a separate file
#endif

if (p%UAMod==UA_HGM .or. p%UAMod==UA_HGMV) then
UA_NumLinStates = 4
Expand Down Expand Up @@ -1419,11 +1416,11 @@ subroutine UA_Init_Outputs(InitInp, p, y, InitOut, errStat, errMsg)

! --- Write to File
if ((p%NumOuts > 0) .and. p%UA_OUTS==2) then
call WrScr(' UA: Writing separate output file: '//trim((InitInp%OutRootName)//'.UA.out'))
call WrScr(' UA: Writing separate output file: '//trim((InitInp%OutRootName)//'.out'))
CALL GetNewUnit( p%unOutFile, ErrStat2, ErrMsg2 )
call SetErrStat(ErrStat2, ErrMsg2, ErrStat, ErrMsg, RoutineName)
if (ErrStat >= AbortErrLev) return
CALL OpenFOutFile ( p%unOutFile, trim(InitInp%OutRootName)//'.UA.out', ErrStat2, ErrMsg2 )
CALL OpenFOutFile ( p%unOutFile, trim(InitInp%OutRootName)//'.out', ErrStat2, ErrMsg2 )
call SetErrStat(ErrStat2, ErrMsg2, ErrStat, ErrMsg, RoutineName)
if (ErrStat >= AbortErrLev) return

Expand All @@ -1443,7 +1440,7 @@ subroutine UA_Init_Outputs(InitInp, p, y, InitOut, errStat, errMsg)
WRITE (p%unOutFile,'(:,A,'//trim( p%OutSFmt )//')', ADVANCE='no' ) p%Delim, trim(InitOut%WriteOutputUnt(i))
end do
WRITE (p%unOutFile,'()', IOSTAT=ErrStat2) ! write the line return
elseif ((p%NumOuts > 0) .and. p%UA_OUTS==2) then
else

call WrScr(' UA: saving write outputs')

Expand Down Expand Up @@ -3844,9 +3841,9 @@ subroutine BV_CalcOutput()
! --- Recompute variables, for temporary output to file only
! Calculate deltas to negative and positive stall angle (delN, and delP)
if (p%UA_OUTS>0) then
call BV_delNP(adotnorm, alpha_34, alphaLag_D, BL_p, OtherState%activeD(i,j), delN, delP)
call BV_getGammas(tc=AFInfo%RelThickness, umach=0.0_ReKi, gammaL=gammaL, gammaD=gammaD)
TransA = BV_TransA(BL_p)
call BV_delNP(adotnorm, alpha_34, alphaLag_D, BL_p, OtherState%activeD(i,j), delN, delP)
call BV_getGammas(tc=AFInfo%RelThickness, umach=0.0_ReKi, gammaL=gammaL, gammaD=gammaD)
TransA = BV_TransA(BL_p)
endif

! --- Cl, _, at effective angle of attack alphaE
Expand Down
4 changes: 2 additions & 2 deletions modules/lindyn/src/LinDyn_Registry.txt
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,10 @@ typedef ^ ^ IntKi
typedef ^ ContinuousStateType ReKi q {:} - - "Continuous states q =(x,xdot)" "-"

# Discrete (non-differentiable) states:
typedef ^ DiscreteStateType Logical Dummy - - - "" -
typedef ^ DiscreteStateType SiKi Dummy - - - "" -

# Constraint states:
typedef ^ ConstraintStateType Logical Dummy - - - "" -
typedef ^ ConstraintStateType SiKi Dummy - - - "" -

# Other states:
typedef ^ OtherStateType LD_ContinuousStateType xdot {:} - - "Previous state derivs for m-step time integrator"
Expand Down
24 changes: 12 additions & 12 deletions modules/lindyn/src/LinDyn_Types.f90
Original file line number Diff line number Diff line change
Expand Up @@ -72,12 +72,12 @@ MODULE LinDyn_Types
! =======================
! ========= LD_DiscreteStateType =======
TYPE, PUBLIC :: LD_DiscreteStateType
LOGICAL :: Dummy !< [-]
REAL(SiKi) :: Dummy !< [-]
END TYPE LD_DiscreteStateType
! =======================
! ========= LD_ConstraintStateType =======
TYPE, PUBLIC :: LD_ConstraintStateType
LOGICAL :: Dummy !< [-]
REAL(SiKi) :: Dummy !< [-]
END TYPE LD_ConstraintStateType
! =======================
! ========= LD_OtherStateType =======
Expand Down Expand Up @@ -1800,7 +1800,7 @@ SUBROUTINE LD_PackDiscState( ReKiBuf, DbKiBuf, IntKiBuf, Indata, ErrStat, ErrMsg
Re_BufSz = 0
Db_BufSz = 0
Int_BufSz = 0
Int_BufSz = Int_BufSz + 1 ! Dummy
Re_BufSz = Re_BufSz + 1 ! Dummy
IF ( Re_BufSz .GT. 0 ) THEN
ALLOCATE( ReKiBuf( Re_BufSz ), STAT=ErrStat2 )
IF (ErrStat2 /= 0) THEN
Expand Down Expand Up @@ -1828,8 +1828,8 @@ SUBROUTINE LD_PackDiscState( ReKiBuf, DbKiBuf, IntKiBuf, Indata, ErrStat, ErrMsg
Db_Xferred = 1
Int_Xferred = 1

IntKiBuf(Int_Xferred) = TRANSFER(InData%Dummy, IntKiBuf(1))
Int_Xferred = Int_Xferred + 1
ReKiBuf(Re_Xferred) = InData%Dummy
Re_Xferred = Re_Xferred + 1
END SUBROUTINE LD_PackDiscState

SUBROUTINE LD_UnPackDiscState( ReKiBuf, DbKiBuf, IntKiBuf, Outdata, ErrStat, ErrMsg )
Expand Down Expand Up @@ -1858,8 +1858,8 @@ SUBROUTINE LD_UnPackDiscState( ReKiBuf, DbKiBuf, IntKiBuf, Outdata, ErrStat, Err
Re_Xferred = 1
Db_Xferred = 1
Int_Xferred = 1
OutData%Dummy = TRANSFER(IntKiBuf(Int_Xferred), OutData%Dummy)
Int_Xferred = Int_Xferred + 1
OutData%Dummy = REAL(ReKiBuf(Re_Xferred), SiKi)
Re_Xferred = Re_Xferred + 1
END SUBROUTINE LD_UnPackDiscState

SUBROUTINE LD_CopyConstrState( SrcConstrStateData, DstConstrStateData, CtrlCode, ErrStat, ErrMsg )
Expand Down Expand Up @@ -1937,7 +1937,7 @@ SUBROUTINE LD_PackConstrState( ReKiBuf, DbKiBuf, IntKiBuf, Indata, ErrStat, ErrM
Re_BufSz = 0
Db_BufSz = 0
Int_BufSz = 0
Int_BufSz = Int_BufSz + 1 ! Dummy
Re_BufSz = Re_BufSz + 1 ! Dummy
IF ( Re_BufSz .GT. 0 ) THEN
ALLOCATE( ReKiBuf( Re_BufSz ), STAT=ErrStat2 )
IF (ErrStat2 /= 0) THEN
Expand Down Expand Up @@ -1965,8 +1965,8 @@ SUBROUTINE LD_PackConstrState( ReKiBuf, DbKiBuf, IntKiBuf, Indata, ErrStat, ErrM
Db_Xferred = 1
Int_Xferred = 1

IntKiBuf(Int_Xferred) = TRANSFER(InData%Dummy, IntKiBuf(1))
Int_Xferred = Int_Xferred + 1
ReKiBuf(Re_Xferred) = InData%Dummy
Re_Xferred = Re_Xferred + 1
END SUBROUTINE LD_PackConstrState

SUBROUTINE LD_UnPackConstrState( ReKiBuf, DbKiBuf, IntKiBuf, Outdata, ErrStat, ErrMsg )
Expand Down Expand Up @@ -1995,8 +1995,8 @@ SUBROUTINE LD_UnPackConstrState( ReKiBuf, DbKiBuf, IntKiBuf, Outdata, ErrStat, E
Re_Xferred = 1
Db_Xferred = 1
Int_Xferred = 1
OutData%Dummy = TRANSFER(IntKiBuf(Int_Xferred), OutData%Dummy)
Int_Xferred = Int_Xferred + 1
OutData%Dummy = REAL(ReKiBuf(Re_Xferred), SiKi)
Re_Xferred = Re_Xferred + 1
END SUBROUTINE LD_UnPackConstrState

SUBROUTINE LD_CopyOtherState( SrcOtherStateData, DstOtherStateData, CtrlCode, ErrStat, ErrMsg )
Expand Down
2 changes: 1 addition & 1 deletion modules/nwtc-library/src/NWTC_Num.f90
Original file line number Diff line number Diff line change
Expand Up @@ -4984,7 +4984,7 @@ FUNCTION RegCubicSplineInterpM ( X, XAry, YAry, DelX, Coef, ErrStat, ErrMsg ) RE
RETURN
END FUNCTION RegCubicSplineInterpM ! ( X, XAry, YAry, DelX, Coef, ErrStat, ErrMsg )
!=======================================================================
!> This routine is used to integrate funciton f over the interval [a, b]. This routine
!> This routine is used to integrate function f over the interval [a, b]. This routine
!! is useful for sufficiently smooth (e.g., analytic) integrands, integrated over
!! intervals which contain no singularities, and where the endpoints are also nonsingular.
!!
Expand Down
8 changes: 8 additions & 0 deletions vs-build/RunRegistry.bat
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ SET SrvD_Loc=%Modules_Loc%\servodyn\src
SET BD_Loc=%Modules_Loc%\beamdyn\src
SET SC_Loc=%Modules_Loc%\supercontroller\src

SET LD_Loc=%Modules_Loc%\lindyn\src

SET AWAE_Loc=%Modules_Loc%\awae\src
SET WD_Loc=%Modules_Loc%\wakedynamics\src
SET Farm_Loc=%Root_Loc%\glue-codes\fast-farm\src
Expand Down Expand Up @@ -165,6 +167,12 @@ SET Output_Loc=%CURR_LOC%
%REGISTRY% "%CURR_LOC%\UnsteadyAero_Registry.txt" -I "%NWTC_Lib_Loc%" -I "%CURR_LOC%" -O "%Output_Loc%"
GOTO checkError

:LD
SET CURR_LOC=%LD_Loc%
SET Output_Loc=%CURR_LOC%
%REGISTRY% "%CURR_LOC%\LinDyn_Registry.txt" -I "%NWTC_Lib_Loc%" -I "%CURR_LOC%" -O "%Output_Loc%"
GOTO checkError

:FVW
SET CURR_LOC=%AD_Loc%
SET Output_Loc=%CURR_LOC%
Expand Down
Loading

0 comments on commit defd8b7

Please sign in to comment.