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

ExtLoads module: Use pointers for wind #2009

Merged
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
15 changes: 14 additions & 1 deletion modules/aerodyn/src/AeroDyn.f90
Original file line number Diff line number Diff line change
Expand Up @@ -227,8 +227,9 @@ subroutine AD_Init( InitInp, u, p, x, xd, z, OtherState, y, m, Interval, InitOut


! Local variables
integer(IntKi) :: i ! loop counter
integer(IntKi) :: i,k ! loop counter
integer(IntKi) :: iR ! loop on rotors
integer(IntKi) :: nNodesVelRot ! number of nodes associated with the rotor that need wind velocity (for CFD coupling)

integer(IntKi) :: errStat2 ! temporary error status of the operation
character(ErrMsgLen) :: errMsg2 ! temporary error message
Expand Down Expand Up @@ -500,6 +501,18 @@ subroutine AD_Init( InitInp, u, p, x, xd, z, OtherState, y, m, Interval, InitOut
end do
end if

! number of nodes velocity is required at (for coupling to cfd)
InitOut%nNodesVel = 0
do iR = 1, nRotors
if (u%rotors(iR)%HubMotion%committed) InitOut%nNodesVel = InitOut%nNodesVel + u%rotors(iR)%HubMotion%nNodes
do k = 1,size(u%rotors(iR)%BladeMotion)
if (u%rotors(iR)%BladeMotion(k)%committed) InitOut%nNodesVel = InitOut%nNodesVel + u%rotors(iR)%BladeMotion(k)%nNodes
enddo
if (u%rotors(iR)%TowerMotion%committed) InitOut%nNodesVel = InitOut%nNodesVel + u%rotors(iR)%TowerMotion%nNodes
if (u%rotors(iR)%NacelleMotion%committed) InitOut%nNodesVel = InitOut%nNodesVel + u%rotors(iR)%NacelleMotion%nNodes
if (u%rotors(iR)%TFinMotion%committed) InitOut%nNodesVel = InitOut%nNodesVel + u%rotors(iR)%TFinMotion%nNodes
enddo

!............................................................................................
! Initialize Jacobian:
!............................................................................................
Expand Down
1 change: 1 addition & 0 deletions modules/aerodyn/src/AeroDyn_Registry.txt
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@ typedef ^ RotInitOutputType ReKi TwrDiam {:} - - "Diameter of tower at node" m

typedef ^ InitOutputType RotInitOutputType rotors {:} - - "Rotor init output type" -
typedef ^ InitOutputType ProgDesc Ver - - - "This module's name, version, and date" -
typedef ^ InitOutputType IntKi nNodesVel - - - "number of nodes velocity values are needed at (for ExtLoads coupling)" -
# ..... Input file data ...........................................................................................................

# ..... Primary Input file data ...................................................................................................
Expand Down
4 changes: 4 additions & 0 deletions modules/aerodyn/src/AeroDyn_Types.f90
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,7 @@ MODULE AeroDyn_Types
TYPE, PUBLIC :: AD_InitOutputType
TYPE(RotInitOutputType) , DIMENSION(:), ALLOCATABLE :: rotors !< Rotor init output type [-]
TYPE(ProgDesc) :: Ver !< This module's name, version, and date [-]
INTEGER(IntKi) :: nNodesVel = 0_IntKi !< number of nodes velocity values are needed at (for ExtLoads coupling) [-]
END TYPE AD_InitOutputType
! =======================
! ========= RotInputFile =======
Expand Down Expand Up @@ -1673,6 +1674,7 @@ subroutine AD_CopyInitOutput(SrcInitOutputData, DstInitOutputData, CtrlCode, Err
call NWTC_Library_CopyProgDesc(SrcInitOutputData%Ver, DstInitOutputData%Ver, CtrlCode, ErrStat2, ErrMsg2)
call SetErrStat(ErrStat2, ErrMsg2, ErrStat, ErrMsg, RoutineName)
if (ErrStat >= AbortErrLev) return
DstInitOutputData%nNodesVel = SrcInitOutputData%nNodesVel
end subroutine

subroutine AD_DestroyInitOutput(InitOutputData, ErrStat, ErrMsg)
Expand Down Expand Up @@ -1716,6 +1718,7 @@ subroutine AD_PackInitOutput(RF, Indata)
end do
end if
call NWTC_Library_PackProgDesc(RF, InData%Ver)
call RegPack(RF, InData%nNodesVel)
if (RegCheckErr(RF, RoutineName)) return
end subroutine

Expand All @@ -1742,6 +1745,7 @@ subroutine AD_UnPackInitOutput(RF, OutData)
end do
end if
call NWTC_Library_UnpackProgDesc(RF, OutData%Ver) ! Ver
call RegUnpack(RF, OutData%nNodesVel); if (RegCheckErr(RF, RoutineName)) return
end subroutine

subroutine AD_CopyRotInputFile(SrcRotInputFileData, DstRotInputFileData, CtrlCode, ErrStat, ErrMsg)
Expand Down
2 changes: 1 addition & 1 deletion modules/extloads/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ add_library(extloadslib STATIC
target_include_directories(extloadslib PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/src>
)
target_link_libraries(extloadslib beamdynlib nwtclibs versioninfolib)
target_link_libraries(extloadslib beamdynlib nwtclibs versioninfolib ifwlib)
set_target_properties(extloadslib PROPERTIES PUBLIC_HEADER "src/ExtLoadsDX_Types.h")

install(TARGETS extloadslib
Expand Down
71 changes: 42 additions & 29 deletions modules/extloads/src/ExtLoads.f90
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,10 @@ module ExtLoads

use NWTC_Library
use ExtLoads_Types

use IfW_FlowField
use InflowWind_IO_Types
use InflowWind_IO

implicit none

private
Expand All @@ -40,7 +43,7 @@ module ExtLoads
public :: ExtLd_CalcOutput ! Routine for computing outputs
public :: ExtLd_ConvertOpDataForOpenFAST ! Routine to convert Output data for OpenFAST
public :: ExtLd_ConvertInpDataForExtProg ! Routine to convert Input data for external programs

contains
!----------------------------------------------------------------------------------------------------------------------------------
!> This subroutine sets the initialization output data structure, which contains data to be returned to the calling program (e.g.,
Expand Down Expand Up @@ -86,21 +89,21 @@ subroutine ExtLd_Init( InitInp, u, xd, p, y, m, interval, InitOut, ErrStat, ErrM
type(ExtLd_OutputType), intent( out) :: y !< Initial system outputs (outputs are not calculated;
type(ExtLd_MiscVarType), intent( out) :: m !< Miscellaneous variables
type(ExtLd_ParameterType), intent( out) :: p !< Parameter variables
!! only the output mesh is initialized)
real(DbKi), intent(inout) :: interval !< Coupling interval in seconds: the rate that
!! (1) ExtLd_UpdateStates() is called in loose coupling &
!! (2) ExtLd_UpdateDiscState() is called in tight coupling.
!! Input is the suggested time from the glue code;
!! Output is the actual coupling interval that will be used
!! by the glue code.
!! only the output mesh is initialized)
real(DbKi), intent(inout) :: interval !< Coupling interval in seconds: the rate that
!! (1) ExtLd_UpdateStates() is called in loose coupling &
!! (2) ExtLd_UpdateDiscState() is called in tight coupling.
!! Input is the suggested time from the glue code;
!! Output is the actual coupling interval that will be used
!! by the glue code.
type(ExtLd_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
integer(IntKi), intent( out) :: errStat !< Error status of the operation
character(*), intent( out) :: errMsg !< Error message if ErrStat /= ErrID_None


! Local variables
integer(IntKi) :: i ! loop counter

type(Points_InitInputType) :: Points_InitInput
integer(IntKi) :: errStat2 ! temporary error status of the operation
character(ErrMsgLen) :: errMsg2 ! temporary error message

Expand All @@ -118,10 +121,7 @@ subroutine ExtLd_Init( InitInp, u, xd, p, y, m, interval, InitOut, ErrStat, ErrM
p%NumBlds = InitInp%NumBlades
call AllocAry(p%NumBldNds, p%NumBlds, 'NumBldNds', ErrStat2,ErrMsg2)
call SetErrStat( ErrStat2, ErrMsg2, ErrStat, ErrMsg, RoutineName )
if (ErrStat >= AbortErrLev) then
call Cleanup()
return
end if
if (ErrStat >= AbortErrLev) return
p%NumBldNds(:) = InitInp%NumBldNodes(:)
p%nTotBldNds = sum(p%NumBldNds(:))
p%NumTwrNds = InitInp%NumTwrNds
Expand All @@ -142,10 +142,7 @@ subroutine ExtLd_Init( InitInp, u, xd, p, y, m, interval, InitOut, ErrStat, ErrM

call Init_u( u, p, InitInp, errStat2, errMsg2 )
call SetErrStat( ErrStat2, ErrMsg2, ErrStat, ErrMsg, RoutineName )
if (ErrStat >= AbortErrLev) then
call Cleanup()
return
end if
if (ErrStat >= AbortErrLev) return


! Initialize discrete states
Expand All @@ -159,11 +156,27 @@ subroutine ExtLd_Init( InitInp, u, xd, p, y, m, interval, InitOut, ErrStat, ErrM
!............................................................................................
call Init_y(y, u, m, p, errStat2, errMsg2) ! do this after input meshes have been initialized
call SetErrStat( ErrStat2, ErrMsg2, ErrStat, ErrMsg, RoutineName )
if (ErrStat >= AbortErrLev) then
call Cleanup()
return
end if
if (ErrStat >= AbortErrLev) return

!............................................................................................
! Initialize InflowWind FlowField
!............................................................................................
if (associated(m%FlowField)) deallocate(m%FlowField)
allocate(m%FlowField, stat=ErrStat2)
if (ErrStat2 /= 0) then
call SetErrStat( ErrID_Fatal, 'Error allocating m%FlowField', ErrStat, ErrMsg, RoutineName )
return
end if

! Initialize flowfield points type
m%FlowField%FieldType = Point_FieldType
Points_InitInput%NumWindPoints = InitInp%nNodesVel
call IfW_Points_Init(Points_InitInput, m%FlowField%Points, ErrStat2, ErrMsg2); if (Failed()) return

! Set pointer to flow field in InitOut
InitOut%FlowField => m%FlowField


write(*,*) 'Initializing InitOut '

!............................................................................................
Expand All @@ -172,13 +185,13 @@ subroutine ExtLd_Init( InitInp, u, xd, p, y, m, interval, InitOut, ErrStat, ErrM
call ExtLd_SetInitOut(p, InitOut, errStat2, errMsg2)
call SetErrStat( ErrStat2, ErrMsg2, ErrStat, ErrMsg, RoutineName )

call Cleanup()

contains
subroutine Cleanup()

end subroutine Cleanup

logical function Failed()
CALL SetErrStat( ErrStat2, ErrMsg2, ErrStat, ErrMsg, RoutineName )
Failed = ErrStat >= AbortErrLev
end function Failed

end subroutine ExtLd_Init
!----------------------------------------------------------------------------------------------------------------------------------
!> This routine initializes ExtLoads meshes and output array variables for use during the simulation.
Expand Down
8 changes: 6 additions & 2 deletions modules/extloads/src/ExtLoads_Registry.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
###################################################################################################################################
# ...... Include files (definitions from NWTC Library) ............................................................................
include Registry_NWTC_Library.txt
include IfW_FlowField.txt
usefrom ExtLoadsDX_Registry.txt

# ..... Initialization data .......................................................................................................
Expand Down Expand Up @@ -43,12 +44,14 @@ typedef ^ InitInputType ReKi BldChord {:}{:}
typedef ^ InitInputType ReKi BldRloc {:}{:} - - "Radial location of each node along the blade" m
typedef ^ InitInputType ReKi TwrDia {:} - - "Tower diameter (NumTwrNodes)" m
typedef ^ InitInputType ReKi TwrHloc {:} - - "Height location of each node along the tower" m
typedef ^ InitInputType IntKi nNodesVel - - - "Number of nodes velocity data is needed from (for sizing array)" -

# Define outputs from the initialization routine here:
typedef ^ InitOutputType CHARACTER(ChanLen) WriteOutputHdr {:} - - "Names of the output-to-file channels" -
typedef ^ InitOutputType CHARACTER(ChanLen) WriteOutputUnt {:} - - "Units of the output-to-file channels" -
typedef ^ InitOutputType ProgDesc Ver - - - "This module's name, version, and date" -
typedef ^ InitOutputType ReKi AirDens - - - "Air density" kg/m^3
typedef ^ InitOutputType FlowFieldType *FlowField - - - "Pointer of flow field data type" -

# ..... States ....................................................................................................................
# Define continuous (differentiable) states here:
Expand All @@ -58,8 +61,9 @@ typedef ^ ContinuousStateType ReKi blah - - - "Someth
typedef ^ DiscreteStateType ReKi blah - - - "Something" -

#Defin misc variables here
typedef ^ MiscVarType ReKi az - - - "Current azimuth" -
typedef ^ MiscVarType ReKi phi_cfd - - - "Blending ratio of load from external driver [0-1]" -
typedef ^ MiscVarType ReKi az - - - "Current azimuth" -
typedef ^ MiscVarType ReKi phi_cfd - - - "Blending ratio of load from external driver [0-1]" -
typedef ^ MiscVarType FlowFieldType &FlowField - - - "Flow field data type" -

# Define constraint states here:
typedef ^ ConstraintStateType ReKi blah - - - "Something" -
Expand Down
Loading