Skip to content

Commit

Permalink
FAST_Subs: reorder initialization
Browse files Browse the repository at this point in the history
Swap ordering from
   - AD14
   - AD15
   - ExtLoads
   - InflowWind
   - SuperController
   - SeaState
to
   - AD14
   - InflowWind
   - SeaState
   - AD15
   - ExtLoads
   - SuperController
  • Loading branch information
andrew-platt committed Jan 29, 2024
1 parent 617c39e commit fd168cb
Showing 1 changed file with 180 additions and 165 deletions.
345 changes: 180 additions & 165 deletions modules/openfast-library/src/FAST_Subs.f90
Original file line number Diff line number Diff line change
Expand Up @@ -439,7 +439,7 @@ SUBROUTINE FAST_InitializeAll( t_initial, p_FAST, y_FAST, m_FAST, ED, BD, SrvD,


! ........................
! initialize AeroDyn
! initialize AeroDyn14
! ........................
ALLOCATE( AD14%Input( p_FAST%InterpOrder+1 ), AD14%InputTimes( p_FAST%InterpOrder+1 ), STAT = ErrStat2 )
IF (ErrStat2 /= 0) THEN
Expand All @@ -455,20 +455,6 @@ SUBROUTINE FAST_InitializeAll( t_initial, p_FAST, y_FAST, m_FAST, ED, BD, SrvD,
RETURN
END IF

ALLOCATE( AD%Input( p_FAST%InterpOrder+1 ), AD%InputTimes( p_FAST%InterpOrder+1 ), STAT = ErrStat2 )
IF (ErrStat2 /= 0) THEN
CALL SetErrStat(ErrID_Fatal,"Error allocating AD%Input and AD%InputTimes.",ErrStat,ErrMsg,RoutineName)
CALL Cleanup()
RETURN
END IF

ALLOCATE( AD%Input_Saved( p_FAST%InterpOrder+1 ), AD%InputTimes_Saved( p_FAST%InterpOrder+1 ), STAT = ErrStat2 )
IF (ErrStat2 /= 0) THEN
CALL SetErrStat(ErrID_Fatal,"Error allocating AD%Input and AD%InputTimes.",ErrStat,ErrMsg,RoutineName)
CALL Cleanup()
RETURN
END IF

IF ( p_FAST%CompAero == Module_AD14 ) THEN

CALL AD_SetInitInput(Init%InData_AD14, Init%OutData_ED, ED%y, p_FAST, ErrStat2, ErrMsg2) ! set the values in Init%InData_AD14
Expand All @@ -488,134 +474,8 @@ SUBROUTINE FAST_InitializeAll( t_initial, p_FAST, y_FAST, m_FAST, ED, BD, SrvD,
CALL Cleanup()
RETURN
END IF
ENDIF

ELSEIF ( (p_FAST%CompAero == Module_AD) .OR. (p_FAST%CompAero == Module_ExtLd) ) THEN

allocate(Init%InData_AD%rotors(1), stat=ErrStat2)
if (ErrStat2 /= 0 ) then
call SetErrStat( ErrID_Fatal, 'Allocating rotors', errStat, errMsg, RoutineName )
call Cleanup()
return
end if

Init%InData_AD%rotors(1)%NumBlades = NumBl

if (p_FAST%CompAeroMaps) then
CALL AllocAry( MeshMapData%HubOrient, 3, 3, Init%InData_AD%rotors(1)%NumBlades, 'Hub orientation matrix', ErrStat2, ErrMsg2 )
CALL SetErrStat( ErrStat2, ErrMsg2, ErrStat, ErrMsg, RoutineName )
IF (ErrStat >= AbortErrLev) THEN
CALL Cleanup()
RETURN
END IF

theta = 0.0_R8Ki
do k=1,Init%InData_AD%rotors(1)%NumBlades
theta(1) = TwoPi_R8 * (k-1) / Init%InData_AD%rotors(1)%NumBlades
MeshMapData%HubOrient(:,:,k) = EulerConstruct( theta )
end do
end if


! set initialization data for AD
CALL AllocAry( Init%InData_AD%rotors(1)%BladeRootPosition, 3, Init%InData_AD%rotors(1)%NumBlades, 'Init%InData_AD%rotors(1)%BladeRootPosition', errStat2, ErrMsg2)
CALL SetErrStat(ErrStat2,ErrMsg2,ErrStat,ErrMsg,RoutineName)
CALL AllocAry( Init%InData_AD%rotors(1)%BladeRootOrientation,3, 3, Init%InData_AD%rotors(1)%NumBlades, 'Init%InData_AD%rotors(1)%BladeRootOrientation', errStat2, ErrMsg2)
CALL SetErrStat(ErrStat2,ErrMsg2,ErrStat,ErrMsg,RoutineName)
IF (ErrStat >= AbortErrLev) THEN
CALL Cleanup()
RETURN
END IF

Init%InData_AD%Gravity = p_FAST%Gravity
Init%InData_AD%Linearize = p_FAST%Linearize
Init%InData_AD%CompAeroMaps = p_FAST%CompAeroMaps
Init%InData_AD%rotors(1)%RotSpeed = p_FAST%RotSpeedInit ! used only for aeromaps
Init%InData_AD%InputFile = p_FAST%AeroFile
Init%InData_AD%RootName = p_FAST%OutFileRoot
Init%InData_AD%MHK = p_FAST%MHK
if ( p_FAST%MHK == MHK_None ) then
Init%InData_AD%defFldDens = p_FAST%AirDens
else
Init%InData_AD%defFldDens = p_FAST%WtrDens
end if
Init%InData_AD%defKinVisc = p_FAST%KinVisc
Init%InData_AD%defSpdSound = p_FAST%SpdSound
Init%InData_AD%defPatm = p_FAST%Patm
Init%InData_AD%defPvap = p_FAST%Pvap
Init%InData_AD%WtrDpth = p_FAST%WtrDpth
Init%InData_AD%MSL2SWL = p_FAST%MSL2SWL


Init%InData_AD%rotors(1)%HubPosition = ED%y%HubPtMotion%Position(:,1)
Init%InData_AD%rotors(1)%HubOrientation = ED%y%HubPtMotion%RefOrientation(:,:,1)
Init%InData_AD%rotors(1)%NacellePosition = ED%y%NacelleMotion%Position(:,1)
Init%InData_AD%rotors(1)%NacelleOrientation = ED%y%NacelleMotion%RefOrientation(:,:,1)
! Note: not passing tailfin position and orientation at init
Init%InData_AD%rotors(1)%AeroProjMod = APM_BEM_NoSweepPitchTwist

do k=1,NumBl
Init%InData_AD%rotors(1)%BladeRootPosition(:,k) = ED%y%BladeRootMotion(k)%Position(:,1)
Init%InData_AD%rotors(1)%BladeRootOrientation(:,:,k) = ED%y%BladeRootMotion(k)%RefOrientation(:,:,1)
end do

CALL AD_Init( Init%InData_AD, AD%Input(1), AD%p, AD%x(STATE_CURR), AD%xd(STATE_CURR), AD%z(STATE_CURR), &
AD%OtherSt(STATE_CURR), AD%y, AD%m, p_FAST%dt_module( MODULE_AD ), Init%OutData_AD, ErrStat2, ErrMsg2 )
CALL SetErrStat(ErrStat2,ErrMsg2,ErrStat,ErrMsg,RoutineName)

p_FAST%ModuleInitialized(Module_AD) = .TRUE.
CALL SetModuleSubstepTime(Module_AD, p_FAST, y_FAST, ErrStat2, ErrMsg2)
CALL SetErrStat(ErrStat2,ErrMsg2,ErrStat,ErrMsg,RoutineName)

allocate( y_FAST%Lin%Modules(MODULE_AD)%Instance(1), stat=ErrStat2)
if (ErrStat2 /= 0 ) then
call SetErrStat(ErrID_Fatal, "Error allocating Lin%Modules(AD).", ErrStat, ErrMsg, RoutineName )
else
if (allocated(Init%OutData_AD%rotors(1)%LinNames_u )) call move_alloc(Init%OutData_AD%rotors(1)%LinNames_u ,y_FAST%Lin%Modules(MODULE_AD)%Instance(1)%Names_u )
if (allocated(Init%OutData_AD%rotors(1)%LinNames_y )) call move_alloc(Init%OutData_AD%rotors(1)%LinNames_y ,y_FAST%Lin%Modules(MODULE_AD)%Instance(1)%Names_y )
if (allocated(Init%OutData_AD%rotors(1)%LinNames_x )) call move_alloc(Init%OutData_AD%rotors(1)%LinNames_x ,y_FAST%Lin%Modules(MODULE_AD)%Instance(1)%Names_x )
if (allocated(Init%OutData_AD%rotors(1)%RotFrame_u )) call move_alloc(Init%OutData_AD%rotors(1)%RotFrame_u ,y_FAST%Lin%Modules(MODULE_AD)%Instance(1)%RotFrame_u )
if (allocated(Init%OutData_AD%rotors(1)%RotFrame_y )) call move_alloc(Init%OutData_AD%rotors(1)%RotFrame_y ,y_FAST%Lin%Modules(MODULE_AD)%Instance(1)%RotFrame_y )
if (allocated(Init%OutData_AD%rotors(1)%RotFrame_x )) call move_alloc(Init%OutData_AD%rotors(1)%RotFrame_x ,y_FAST%Lin%Modules(MODULE_AD)%Instance(1)%RotFrame_x )
if (allocated(Init%OutData_AD%rotors(1)%IsLoad_u )) call move_alloc(Init%OutData_AD%rotors(1)%IsLoad_u ,y_FAST%Lin%Modules(MODULE_AD)%Instance(1)%IsLoad_u )
if (allocated(Init%OutData_AD%rotors(1)%DerivOrder_x)) call move_alloc(Init%OutData_AD%rotors(1)%DerivOrder_x,y_FAST%Lin%Modules(MODULE_AD)%Instance(1)%DerivOrder_x )

if (allocated(Init%OutData_AD%rotors(1)%WriteOutputHdr)) y_FAST%Lin%Modules(MODULE_AD)%Instance(1)%NumOutputs = size(Init%OutData_AD%rotors(1)%WriteOutputHdr)
end if

IF (ErrStat >= AbortErrLev) THEN
CALL Cleanup()
RETURN
END IF

AirDens = Init%OutData_AD%rotors(1)%AirDens

ELSE
AirDens = 0.0_ReKi
END IF ! CompAero

IF ( p_FAST%CompAero == Module_ExtLd ) THEN

IF ( PRESENT(ExternInitData) ) THEN

! set initialization data for ExtLoads
CALL ExtLd_SetInitInput(Init%InData_ExtLd, Init%OutData_ED, ED%y, Init%OutData_BD, BD%y(:), Init%OutData_AD, p_FAST, ExternInitData, ErrStat2, ErrMsg2)
CALL ExtLd_Init( Init%InData_ExtLd, ExtLd%u, ExtLd%xd(1), ExtLd%p, ExtLd%y, ExtLd%m, p_FAST%dt_module( MODULE_ExtLd ), Init%OutData_ExtLd, ErrStat2, ErrMsg2 )
CALL SetErrStat(ErrStat2,ErrMsg2,ErrStat,ErrMsg,RoutineName)

p_FAST%ModuleInitialized(Module_ExtLd) = .TRUE.
CALL SetModuleSubstepTime(Module_ExtLd, p_FAST, y_FAST, ErrStat2, ErrMsg2)
CALL SetErrStat(ErrStat2,ErrMsg2,ErrStat,ErrMsg,RoutineName)

IF (ErrStat >= AbortErrLev) THEN
CALL Cleanup()
RETURN
END IF

AirDens = Init%OutData_ExtLd%AirDens

END IF

END IF

! ........................
! initialize InflowWind
Expand Down Expand Up @@ -795,29 +655,6 @@ SUBROUTINE FAST_InitializeAll( t_initial, p_FAST, y_FAST, m_FAST, ED, BD, SrvD,
Init%OutData_IfW%WindFileInfo%MWS = 0.0_ReKi
END IF ! CompInflow

! ........................
! initialize SuperController
! ........................
IF ( PRESENT(ExternInitData) ) THEN
! set up the data structures for integration with supercontroller
IF ( p_FAST%UseSC ) THEN
CALL SC_DX_Init( ExternInitData%NumSC2CtrlGlob, ExternInitData%NumSC2Ctrl, ExternInitData%NumCtrl2SC, SC_DX, ErrStat2, ErrMsg2 )
CALL SetErrStat(ErrStat2, ErrMsg2, ErrStat, ErrMsg, RoutineName )
ELSE
SC_DX%u%c_obj%toSC_Len = 0
SC_DX%u%c_obj%toSC = C_NULL_PTR
SC_DX%y%c_obj%fromSC_Len = 0
SC_DX%y%c_obj%fromSC = C_NULL_PTR
SC_DX%y%c_obj%fromSCglob_Len = 0
SC_DX%y%c_obj%fromSCglob = C_NULL_PTR
END IF
END IF

IF (ErrStat >= AbortErrLev) THEN
CALL Cleanup()
RETURN
END IF

! ........................
! some checks for AeroDyn14's Dynamic Inflow with Mean Wind Speed from InflowWind:
! (DO NOT COPY THIS CODE!)
Expand Down Expand Up @@ -896,6 +733,184 @@ SUBROUTINE FAST_InitializeAll( t_initial, p_FAST, y_FAST, m_FAST, ED, BD, SrvD,

end if


! ........................
! initialize AeroDyn15
! ........................
ALLOCATE( AD%Input( p_FAST%InterpOrder+1 ), AD%InputTimes( p_FAST%InterpOrder+1 ), STAT = ErrStat2 )
IF (ErrStat2 /= 0) THEN
CALL SetErrStat(ErrID_Fatal,"Error allocating AD%Input and AD%InputTimes.",ErrStat,ErrMsg,RoutineName)
CALL Cleanup()
RETURN
END IF

ALLOCATE( AD%Input_Saved( p_FAST%InterpOrder+1 ), AD%InputTimes_Saved( p_FAST%InterpOrder+1 ), STAT = ErrStat2 )
IF (ErrStat2 /= 0) THEN
CALL SetErrStat(ErrID_Fatal,"Error allocating AD%Input and AD%InputTimes.",ErrStat,ErrMsg,RoutineName)
CALL Cleanup()
RETURN
END IF

IF ( (p_FAST%CompAero == Module_AD) .OR. (p_FAST%CompAero == Module_ExtLd) ) THEN

allocate(Init%InData_AD%rotors(1), stat=ErrStat2)
if (ErrStat2 /= 0 ) then
call SetErrStat( ErrID_Fatal, 'Allocating rotors', errStat, errMsg, RoutineName )
call Cleanup()
return
end if

Init%InData_AD%rotors(1)%NumBlades = NumBl

if (p_FAST%CompAeroMaps) then
CALL AllocAry( MeshMapData%HubOrient, 3, 3, Init%InData_AD%rotors(1)%NumBlades, 'Hub orientation matrix', ErrStat2, ErrMsg2 )
CALL SetErrStat( ErrStat2, ErrMsg2, ErrStat, ErrMsg, RoutineName )
IF (ErrStat >= AbortErrLev) THEN
CALL Cleanup()
RETURN
END IF

theta = 0.0_R8Ki
do k=1,Init%InData_AD%rotors(1)%NumBlades
theta(1) = TwoPi_R8 * (k-1) / Init%InData_AD%rotors(1)%NumBlades
MeshMapData%HubOrient(:,:,k) = EulerConstruct( theta )
end do
end if


! set initialization data for AD
CALL AllocAry( Init%InData_AD%rotors(1)%BladeRootPosition, 3, Init%InData_AD%rotors(1)%NumBlades, 'Init%InData_AD%rotors(1)%BladeRootPosition', errStat2, ErrMsg2)
CALL SetErrStat(ErrStat2,ErrMsg2,ErrStat,ErrMsg,RoutineName)
CALL AllocAry( Init%InData_AD%rotors(1)%BladeRootOrientation,3, 3, Init%InData_AD%rotors(1)%NumBlades, 'Init%InData_AD%rotors(1)%BladeRootOrientation', errStat2, ErrMsg2)
CALL SetErrStat(ErrStat2,ErrMsg2,ErrStat,ErrMsg,RoutineName)
IF (ErrStat >= AbortErrLev) THEN
CALL Cleanup()
RETURN
END IF

Init%InData_AD%Gravity = p_FAST%Gravity
Init%InData_AD%Linearize = p_FAST%Linearize
Init%InData_AD%CompAeroMaps = p_FAST%CompAeroMaps
Init%InData_AD%rotors(1)%RotSpeed = p_FAST%RotSpeedInit ! used only for aeromaps
Init%InData_AD%InputFile = p_FAST%AeroFile
Init%InData_AD%RootName = p_FAST%OutFileRoot
Init%InData_AD%MHK = p_FAST%MHK
if ( p_FAST%MHK == MHK_None ) then
Init%InData_AD%defFldDens = p_FAST%AirDens
else
Init%InData_AD%defFldDens = p_FAST%WtrDens
end if
Init%InData_AD%defKinVisc = p_FAST%KinVisc
Init%InData_AD%defSpdSound = p_FAST%SpdSound
Init%InData_AD%defPatm = p_FAST%Patm
Init%InData_AD%defPvap = p_FAST%Pvap
Init%InData_AD%WtrDpth = p_FAST%WtrDpth
Init%InData_AD%MSL2SWL = p_FAST%MSL2SWL


Init%InData_AD%rotors(1)%HubPosition = ED%y%HubPtMotion%Position(:,1)
Init%InData_AD%rotors(1)%HubOrientation = ED%y%HubPtMotion%RefOrientation(:,:,1)
Init%InData_AD%rotors(1)%NacellePosition = ED%y%NacelleMotion%Position(:,1)
Init%InData_AD%rotors(1)%NacelleOrientation = ED%y%NacelleMotion%RefOrientation(:,:,1)
! Note: not passing tailfin position and orientation at init
Init%InData_AD%rotors(1)%AeroProjMod = APM_BEM_NoSweepPitchTwist

do k=1,NumBl
Init%InData_AD%rotors(1)%BladeRootPosition(:,k) = ED%y%BladeRootMotion(k)%Position(:,1)
Init%InData_AD%rotors(1)%BladeRootOrientation(:,:,k) = ED%y%BladeRootMotion(k)%RefOrientation(:,:,1)
end do

CALL AD_Init( Init%InData_AD, AD%Input(1), AD%p, AD%x(STATE_CURR), AD%xd(STATE_CURR), AD%z(STATE_CURR), &
AD%OtherSt(STATE_CURR), AD%y, AD%m, p_FAST%dt_module( MODULE_AD ), Init%OutData_AD, ErrStat2, ErrMsg2 )
CALL SetErrStat(ErrStat2,ErrMsg2,ErrStat,ErrMsg,RoutineName)

p_FAST%ModuleInitialized(Module_AD) = .TRUE.
CALL SetModuleSubstepTime(Module_AD, p_FAST, y_FAST, ErrStat2, ErrMsg2)
CALL SetErrStat(ErrStat2,ErrMsg2,ErrStat,ErrMsg,RoutineName)

allocate( y_FAST%Lin%Modules(MODULE_AD)%Instance(1), stat=ErrStat2)
if (ErrStat2 /= 0 ) then
call SetErrStat(ErrID_Fatal, "Error allocating Lin%Modules(AD).", ErrStat, ErrMsg, RoutineName )
else
if (allocated(Init%OutData_AD%rotors(1)%LinNames_u )) call move_alloc(Init%OutData_AD%rotors(1)%LinNames_u ,y_FAST%Lin%Modules(MODULE_AD)%Instance(1)%Names_u )
if (allocated(Init%OutData_AD%rotors(1)%LinNames_y )) call move_alloc(Init%OutData_AD%rotors(1)%LinNames_y ,y_FAST%Lin%Modules(MODULE_AD)%Instance(1)%Names_y )
if (allocated(Init%OutData_AD%rotors(1)%LinNames_x )) call move_alloc(Init%OutData_AD%rotors(1)%LinNames_x ,y_FAST%Lin%Modules(MODULE_AD)%Instance(1)%Names_x )
if (allocated(Init%OutData_AD%rotors(1)%RotFrame_u )) call move_alloc(Init%OutData_AD%rotors(1)%RotFrame_u ,y_FAST%Lin%Modules(MODULE_AD)%Instance(1)%RotFrame_u )
if (allocated(Init%OutData_AD%rotors(1)%RotFrame_y )) call move_alloc(Init%OutData_AD%rotors(1)%RotFrame_y ,y_FAST%Lin%Modules(MODULE_AD)%Instance(1)%RotFrame_y )
if (allocated(Init%OutData_AD%rotors(1)%RotFrame_x )) call move_alloc(Init%OutData_AD%rotors(1)%RotFrame_x ,y_FAST%Lin%Modules(MODULE_AD)%Instance(1)%RotFrame_x )
if (allocated(Init%OutData_AD%rotors(1)%IsLoad_u )) call move_alloc(Init%OutData_AD%rotors(1)%IsLoad_u ,y_FAST%Lin%Modules(MODULE_AD)%Instance(1)%IsLoad_u )
if (allocated(Init%OutData_AD%rotors(1)%DerivOrder_x)) call move_alloc(Init%OutData_AD%rotors(1)%DerivOrder_x,y_FAST%Lin%Modules(MODULE_AD)%Instance(1)%DerivOrder_x )

if (allocated(Init%OutData_AD%rotors(1)%WriteOutputHdr)) y_FAST%Lin%Modules(MODULE_AD)%Instance(1)%NumOutputs = size(Init%OutData_AD%rotors(1)%WriteOutputHdr)
end if

IF (ErrStat >= AbortErrLev) THEN
CALL Cleanup()
RETURN
END IF

AirDens = Init%OutData_AD%rotors(1)%AirDens

END IF ! CompAero

IF ( p_FAST%CompAero == Module_ExtLd ) THEN

IF ( PRESENT(ExternInitData) ) THEN

! set initialization data for ExtLoads
CALL ExtLd_SetInitInput(Init%InData_ExtLd, Init%OutData_ED, ED%y, Init%OutData_BD, BD%y(:), Init%OutData_AD, p_FAST, ExternInitData, ErrStat2, ErrMsg2)
CALL ExtLd_Init( Init%InData_ExtLd, ExtLd%u, ExtLd%xd(1), ExtLd%p, ExtLd%y, ExtLd%m, p_FAST%dt_module( MODULE_ExtLd ), Init%OutData_ExtLd, ErrStat2, ErrMsg2 )
CALL SetErrStat(ErrStat2,ErrMsg2,ErrStat,ErrMsg,RoutineName)

p_FAST%ModuleInitialized(Module_ExtLd) = .TRUE.
CALL SetModuleSubstepTime(Module_ExtLd, p_FAST, y_FAST, ErrStat2, ErrMsg2)
CALL SetErrStat(ErrStat2,ErrMsg2,ErrStat,ErrMsg,RoutineName)

IF (ErrStat >= AbortErrLev) THEN
CALL Cleanup()
RETURN
END IF

AirDens = Init%OutData_ExtLd%AirDens

END IF

END IF

! ........................
! No aero of any sort
! ........................
IF ( (p_FAST%CompAero /= Module_AD14) .and. (p_FAST%CompAero /= Module_AD) .and. (p_FAST%CompAero /= Module_ExtLd) ) THEN
ELSE
AirDens = 0.0_ReKi
ENDIF



! ........................
! initialize SuperController
! ........................
IF ( PRESENT(ExternInitData) ) THEN
! set up the data structures for integration with supercontroller
IF ( p_FAST%UseSC ) THEN
CALL SC_DX_Init( ExternInitData%NumSC2CtrlGlob, ExternInitData%NumSC2Ctrl, ExternInitData%NumCtrl2SC, SC_DX, ErrStat2, ErrMsg2 )
CALL SetErrStat(ErrStat2, ErrMsg2, ErrStat, ErrMsg, RoutineName )
ELSE
SC_DX%u%c_obj%toSC_Len = 0
SC_DX%u%c_obj%toSC = C_NULL_PTR
SC_DX%y%c_obj%fromSC_Len = 0
SC_DX%y%c_obj%fromSC = C_NULL_PTR
SC_DX%y%c_obj%fromSCglob_Len = 0
SC_DX%y%c_obj%fromSCglob = C_NULL_PTR
END IF
END IF

IF (ErrStat >= AbortErrLev) THEN
CALL Cleanup()
RETURN
END IF


! ........................
! initialize HydroDyn
! ........................
Expand Down

0 comments on commit fd168cb

Please sign in to comment.