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

Use pointers to couple InflowWind and FAST.Farm #1624

Merged
merged 1 commit into from
Jun 14, 2023
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
13 changes: 3 additions & 10 deletions glue-codes/fast-farm/src/FASTWrapper.f90
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,7 @@ SUBROUTINE FWrap_Init( InitInp, u, p, x, xd, z, OtherState, y, m, Interval, Init
ExternInitData%windGrid_delta(4) = InitInp%dt_high

ExternInitData%windGrid_pZero = InitInp%p_ref_high - InitInp%p_ref_Turbine
ExternInitData%windGrid_data => InitInp%Vdist_High


CALL FAST_InitializeAll_T( t_initial, InitInp%TurbNum, m%Turbine, ErrStat2, ErrMsg2, InitInp%FASTInFile, ExternInitData )
Expand All @@ -183,10 +184,7 @@ SUBROUTINE FWrap_Init( InitInp, u, p, x, xd, z, OtherState, y, m, Interval, Init
call cleanup()
return
end if

call move_alloc(m%Turbine%IfW%p%FlowField%Grid4D%Vel, u%Vdist_High)



!.................
! Define parameters here:
!.................
Expand Down Expand Up @@ -555,10 +553,6 @@ SUBROUTINE FWrap_CalcOutput(p, u, y, m, ErrStat, ErrMsg)
ErrStat = ErrID_None
ErrMsg = ''

! put this back!
call move_alloc(m%Turbine%IfW%p%FlowField%Grid4D%Vel, u%Vdist_High)


! Turbine-dependent commands to the super controller:
if (m%Turbine%p_FAST%UseSC) then
y%toSC = m%Turbine%SC_DX%u%toSC
Expand Down Expand Up @@ -712,8 +706,7 @@ SUBROUTINE FWrap_SetInputs(u, m, t)
REAL(DbKi), INTENT(IN ) :: t !< current simulation time

! set the 4d-wind-inflow input array (a bit of a hack [simplification] so that we don't have large amounts of data copied in multiple data structures):
call move_alloc(u%Vdist_High, m%Turbine%IfW%p%FlowField%Grid4D%Vel)
m%Turbine%IfW%p%FlowField%Grid4D%TimeStart = t
m%Turbine%IfW%p%FlowField%Grid4D%TimeStart = t

! do something with the inputs from the super-controller:
if ( m%Turbine%p_FAST%UseSC ) then
Expand Down
2 changes: 1 addition & 1 deletion glue-codes/fast-farm/src/FASTWrapper_Registry.txt
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ typedef ^ InitInputType IntKi NumCtrl2SC
typedef ^ InitInputType Logical UseSC - - - "Use the SuperController? (flag)" -
typedef ^ InitInputType SiKi fromSCGlob {:} - - "Global outputs from SuperController" -
typedef ^ InitInputType SiKi fromSC {:} - - "Turbine-specific outputs from SuperController" -
typedef ^ InitInputType SiKi *Vdist_High {:}{:}{:}{:}{:} - - "Pointer to UVW components of disturbed wind [nx^high, ny^high, nz^high, n^high/low] (ambient + deficits) across the high-resolution domain around the turbine for each high-resolution time step within a low-resolution time step" "(m/s)"

# Define outputs from the initialization routine here:
#typedef ^ InitOutputType CHARACTER(ChanLen) WriteOutputHdr {:} - - "Names of the output-to-file channels" -
Expand Down Expand Up @@ -85,7 +86,6 @@ typedef ^ ParameterType ReKi p_ref_Turbine
# Define inputs that are contained on the mesh here:
typedef ^ InputType SiKi fromSCglob {:} - - "Global (turbine-independent) commands from the super controller" "(various units)"
typedef ^ InputType SiKi fromSC {:} - - "Turbine-dependent commands from the super controller from the super controller" "(various units)"
typedef ^ InputType SiKi Vdist_High {:}{:}{:}{:}{:} - - "UVW components of disturbed wind [nx^high, ny^high, nz^high, n^high/low] (ambient + deficits) across the high-resolution domain around the turbine for each high-resolution time step within a low-resolution time step" "(m/s)"

# ..... Outputs ...................................................................................................................
# Define outputs that are contained on the mesh here:
Expand Down
122 changes: 12 additions & 110 deletions glue-codes/fast-farm/src/FASTWrapper_Types.f90
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ MODULE FASTWrapper_Types
LOGICAL :: UseSC !< Use the SuperController? (flag) [-]
REAL(SiKi) , DIMENSION(:), ALLOCATABLE :: fromSCGlob !< Global outputs from SuperController [-]
REAL(SiKi) , DIMENSION(:), ALLOCATABLE :: fromSC !< Turbine-specific outputs from SuperController [-]
REAL(SiKi) , DIMENSION(:,:,:,:,:), POINTER :: Vdist_High => NULL() !< Pointer to UVW components of disturbed wind [nx^high, ny^high, nz^high, n^high/low] (ambient + deficits) across the high-resolution domain around the turbine for each high-resolution time step within a low-resolution time step [(m/s)]
END TYPE FWrap_InitInputType
! =======================
! ========= FWrap_InitOutputType =======
Expand Down Expand Up @@ -108,7 +109,6 @@ MODULE FASTWrapper_Types
TYPE, PUBLIC :: FWrap_InputType
REAL(SiKi) , DIMENSION(:), ALLOCATABLE :: fromSCglob !< Global (turbine-independent) commands from the super controller [(various units)]
REAL(SiKi) , DIMENSION(:), ALLOCATABLE :: fromSC !< Turbine-dependent commands from the super controller from the super controller [(various units)]
REAL(SiKi) , DIMENSION(:,:,:,:,:), ALLOCATABLE :: Vdist_High !< UVW components of disturbed wind [nx^high, ny^high, nz^high, n^high/low] (ambient + deficits) across the high-resolution domain around the turbine for each high-resolution time step within a low-resolution time step [(m/s)]
END TYPE FWrap_InputType
! =======================
! ========= FWrap_OutputType =======
Expand All @@ -135,6 +135,10 @@ SUBROUTINE FWrap_CopyInitInput( SrcInitInputData, DstInitInputData, CtrlCode, Er
! Local
INTEGER(IntKi) :: i,j,k
INTEGER(IntKi) :: i1, i1_l, i1_u ! bounds (upper/lower) for an array dimension 1
INTEGER(IntKi) :: i2, i2_l, i2_u ! bounds (upper/lower) for an array dimension 2
INTEGER(IntKi) :: i3, i3_l, i3_u ! bounds (upper/lower) for an array dimension 3
INTEGER(IntKi) :: i4, i4_l, i4_u ! bounds (upper/lower) for an array dimension 4
INTEGER(IntKi) :: i5, i5_l, i5_u ! bounds (upper/lower) for an array dimension 5
INTEGER(IntKi) :: ErrStat2
CHARACTER(ErrMsgLen) :: ErrMsg2
CHARACTER(*), PARAMETER :: RoutineName = 'FWrap_CopyInitInput'
Expand Down Expand Up @@ -186,6 +190,7 @@ SUBROUTINE FWrap_CopyInitInput( SrcInitInputData, DstInitInputData, CtrlCode, Er
END IF
DstInitInputData%fromSC = SrcInitInputData%fromSC
ENDIF
DstInitInputData%Vdist_High => SrcInitInputData%Vdist_High
END SUBROUTINE FWrap_CopyInitInput

SUBROUTINE FWrap_DestroyInitInput( InitInputData, ErrStat, ErrMsg )
Expand All @@ -207,6 +212,7 @@ SUBROUTINE FWrap_DestroyInitInput( InitInputData, ErrStat, ErrMsg )
IF (ALLOCATED(InitInputData%fromSC)) THEN
DEALLOCATE(InitInputData%fromSC)
ENDIF
NULLIFY(InitInputData%Vdist_High)
END SUBROUTINE FWrap_DestroyInitInput

SUBROUTINE FWrap_PackInitInput( ReKiBuf, DbKiBuf, IntKiBuf, Indata, ErrStat, ErrMsg, SizeOnly )
Expand Down Expand Up @@ -398,6 +404,10 @@ SUBROUTINE FWrap_UnPackInitInput( ReKiBuf, DbKiBuf, IntKiBuf, Outdata, ErrStat,
INTEGER(IntKi) :: Int_Xferred
INTEGER(IntKi) :: i
INTEGER(IntKi) :: i1, i1_l, i1_u ! bounds (upper/lower) for an array dimension 1
INTEGER(IntKi) :: i2, i2_l, i2_u ! bounds (upper/lower) for an array dimension 2
INTEGER(IntKi) :: i3, i3_l, i3_u ! bounds (upper/lower) for an array dimension 3
INTEGER(IntKi) :: i4, i4_l, i4_u ! bounds (upper/lower) for an array dimension 4
INTEGER(IntKi) :: i5, i5_l, i5_u ! bounds (upper/lower) for an array dimension 5
INTEGER(IntKi) :: ErrStat2
CHARACTER(ErrMsgLen) :: ErrMsg2
CHARACTER(*), PARAMETER :: RoutineName = 'FWrap_UnPackInitInput'
Expand Down Expand Up @@ -501,6 +511,7 @@ SUBROUTINE FWrap_UnPackInitInput( ReKiBuf, DbKiBuf, IntKiBuf, Outdata, ErrStat,
Re_Xferred = Re_Xferred + 1
END DO
END IF
NULLIFY(OutData%Vdist_High)
END SUBROUTINE FWrap_UnPackInitInput

SUBROUTINE FWrap_CopyInitOutput( SrcInitOutputData, DstInitOutputData, CtrlCode, ErrStat, ErrMsg )
Expand Down Expand Up @@ -2246,10 +2257,6 @@ SUBROUTINE FWrap_CopyInput( SrcInputData, DstInputData, CtrlCode, ErrStat, ErrMs
! Local
INTEGER(IntKi) :: i,j,k
INTEGER(IntKi) :: i1, i1_l, i1_u ! bounds (upper/lower) for an array dimension 1
INTEGER(IntKi) :: i2, i2_l, i2_u ! bounds (upper/lower) for an array dimension 2
INTEGER(IntKi) :: i3, i3_l, i3_u ! bounds (upper/lower) for an array dimension 3
INTEGER(IntKi) :: i4, i4_l, i4_u ! bounds (upper/lower) for an array dimension 4
INTEGER(IntKi) :: i5, i5_l, i5_u ! bounds (upper/lower) for an array dimension 5
INTEGER(IntKi) :: ErrStat2
CHARACTER(ErrMsgLen) :: ErrMsg2
CHARACTER(*), PARAMETER :: RoutineName = 'FWrap_CopyInput'
Expand Down Expand Up @@ -2279,26 +2286,6 @@ SUBROUTINE FWrap_CopyInput( SrcInputData, DstInputData, CtrlCode, ErrStat, ErrMs
END IF
END IF
DstInputData%fromSC = SrcInputData%fromSC
ENDIF
IF (ALLOCATED(SrcInputData%Vdist_High)) THEN
i1_l = LBOUND(SrcInputData%Vdist_High,1)
i1_u = UBOUND(SrcInputData%Vdist_High,1)
i2_l = LBOUND(SrcInputData%Vdist_High,2)
i2_u = UBOUND(SrcInputData%Vdist_High,2)
i3_l = LBOUND(SrcInputData%Vdist_High,3)
i3_u = UBOUND(SrcInputData%Vdist_High,3)
i4_l = LBOUND(SrcInputData%Vdist_High,4)
i4_u = UBOUND(SrcInputData%Vdist_High,4)
i5_l = LBOUND(SrcInputData%Vdist_High,5)
i5_u = UBOUND(SrcInputData%Vdist_High,5)
IF (.NOT. ALLOCATED(DstInputData%Vdist_High)) THEN
ALLOCATE(DstInputData%Vdist_High(i1_l:i1_u,i2_l:i2_u,i3_l:i3_u,i4_l:i4_u,i5_l:i5_u),STAT=ErrStat2)
IF (ErrStat2 /= 0) THEN
CALL SetErrStat(ErrID_Fatal, 'Error allocating DstInputData%Vdist_High.', ErrStat, ErrMsg,RoutineName)
RETURN
END IF
END IF
DstInputData%Vdist_High = SrcInputData%Vdist_High
ENDIF
END SUBROUTINE FWrap_CopyInput

Expand All @@ -2320,9 +2307,6 @@ SUBROUTINE FWrap_DestroyInput( InputData, ErrStat, ErrMsg )
ENDIF
IF (ALLOCATED(InputData%fromSC)) THEN
DEALLOCATE(InputData%fromSC)
ENDIF
IF (ALLOCATED(InputData%Vdist_High)) THEN
DEALLOCATE(InputData%Vdist_High)
ENDIF
END SUBROUTINE FWrap_DestroyInput

Expand Down Expand Up @@ -2371,11 +2355,6 @@ SUBROUTINE FWrap_PackInput( ReKiBuf, DbKiBuf, IntKiBuf, Indata, ErrStat, ErrMsg,
Int_BufSz = Int_BufSz + 2*1 ! fromSC upper/lower bounds for each dimension
Re_BufSz = Re_BufSz + SIZE(InData%fromSC) ! fromSC
END IF
Int_BufSz = Int_BufSz + 1 ! Vdist_High allocated yes/no
IF ( ALLOCATED(InData%Vdist_High) ) THEN
Int_BufSz = Int_BufSz + 2*5 ! Vdist_High upper/lower bounds for each dimension
Re_BufSz = Re_BufSz + SIZE(InData%Vdist_High) ! Vdist_High
END IF
IF ( Re_BufSz .GT. 0 ) THEN
ALLOCATE( ReKiBuf( Re_BufSz ), STAT=ErrStat2 )
IF (ErrStat2 /= 0) THEN
Expand Down Expand Up @@ -2433,41 +2412,6 @@ SUBROUTINE FWrap_PackInput( ReKiBuf, DbKiBuf, IntKiBuf, Indata, ErrStat, ErrMsg,
Re_Xferred = Re_Xferred + 1
END DO
END IF
IF ( .NOT. ALLOCATED(InData%Vdist_High) ) THEN
IntKiBuf( Int_Xferred ) = 0
Int_Xferred = Int_Xferred + 1
ELSE
IntKiBuf( Int_Xferred ) = 1
Int_Xferred = Int_Xferred + 1
IntKiBuf( Int_Xferred ) = LBOUND(InData%Vdist_High,1)
IntKiBuf( Int_Xferred + 1) = UBOUND(InData%Vdist_High,1)
Int_Xferred = Int_Xferred + 2
IntKiBuf( Int_Xferred ) = LBOUND(InData%Vdist_High,2)
IntKiBuf( Int_Xferred + 1) = UBOUND(InData%Vdist_High,2)
Int_Xferred = Int_Xferred + 2
IntKiBuf( Int_Xferred ) = LBOUND(InData%Vdist_High,3)
IntKiBuf( Int_Xferred + 1) = UBOUND(InData%Vdist_High,3)
Int_Xferred = Int_Xferred + 2
IntKiBuf( Int_Xferred ) = LBOUND(InData%Vdist_High,4)
IntKiBuf( Int_Xferred + 1) = UBOUND(InData%Vdist_High,4)
Int_Xferred = Int_Xferred + 2
IntKiBuf( Int_Xferred ) = LBOUND(InData%Vdist_High,5)
IntKiBuf( Int_Xferred + 1) = UBOUND(InData%Vdist_High,5)
Int_Xferred = Int_Xferred + 2

DO i5 = LBOUND(InData%Vdist_High,5), UBOUND(InData%Vdist_High,5)
DO i4 = LBOUND(InData%Vdist_High,4), UBOUND(InData%Vdist_High,4)
DO i3 = LBOUND(InData%Vdist_High,3), UBOUND(InData%Vdist_High,3)
DO i2 = LBOUND(InData%Vdist_High,2), UBOUND(InData%Vdist_High,2)
DO i1 = LBOUND(InData%Vdist_High,1), UBOUND(InData%Vdist_High,1)
ReKiBuf(Re_Xferred) = InData%Vdist_High(i1,i2,i3,i4,i5)
Re_Xferred = Re_Xferred + 1
END DO
END DO
END DO
END DO
END DO
END IF
END SUBROUTINE FWrap_PackInput

SUBROUTINE FWrap_UnPackInput( ReKiBuf, DbKiBuf, IntKiBuf, Outdata, ErrStat, ErrMsg )
Expand All @@ -2484,10 +2428,6 @@ SUBROUTINE FWrap_UnPackInput( ReKiBuf, DbKiBuf, IntKiBuf, Outdata, ErrStat, ErrM
INTEGER(IntKi) :: Int_Xferred
INTEGER(IntKi) :: i
INTEGER(IntKi) :: i1, i1_l, i1_u ! bounds (upper/lower) for an array dimension 1
INTEGER(IntKi) :: i2, i2_l, i2_u ! bounds (upper/lower) for an array dimension 2
INTEGER(IntKi) :: i3, i3_l, i3_u ! bounds (upper/lower) for an array dimension 3
INTEGER(IntKi) :: i4, i4_l, i4_u ! bounds (upper/lower) for an array dimension 4
INTEGER(IntKi) :: i5, i5_l, i5_u ! bounds (upper/lower) for an array dimension 5
INTEGER(IntKi) :: ErrStat2
CHARACTER(ErrMsgLen) :: ErrMsg2
CHARACTER(*), PARAMETER :: RoutineName = 'FWrap_UnPackInput'
Expand Down Expand Up @@ -2537,44 +2477,6 @@ SUBROUTINE FWrap_UnPackInput( ReKiBuf, DbKiBuf, IntKiBuf, Outdata, ErrStat, ErrM
Re_Xferred = Re_Xferred + 1
END DO
END IF
IF ( IntKiBuf( Int_Xferred ) == 0 ) THEN ! Vdist_High not allocated
Int_Xferred = Int_Xferred + 1
ELSE
Int_Xferred = Int_Xferred + 1
i1_l = IntKiBuf( Int_Xferred )
i1_u = IntKiBuf( Int_Xferred + 1)
Int_Xferred = Int_Xferred + 2
i2_l = IntKiBuf( Int_Xferred )
i2_u = IntKiBuf( Int_Xferred + 1)
Int_Xferred = Int_Xferred + 2
i3_l = IntKiBuf( Int_Xferred )
i3_u = IntKiBuf( Int_Xferred + 1)
Int_Xferred = Int_Xferred + 2
i4_l = IntKiBuf( Int_Xferred )
i4_u = IntKiBuf( Int_Xferred + 1)
Int_Xferred = Int_Xferred + 2
i5_l = IntKiBuf( Int_Xferred )
i5_u = IntKiBuf( Int_Xferred + 1)
Int_Xferred = Int_Xferred + 2
IF (ALLOCATED(OutData%Vdist_High)) DEALLOCATE(OutData%Vdist_High)
ALLOCATE(OutData%Vdist_High(i1_l:i1_u,i2_l:i2_u,i3_l:i3_u,i4_l:i4_u,i5_l:i5_u),STAT=ErrStat2)
IF (ErrStat2 /= 0) THEN
CALL SetErrStat(ErrID_Fatal, 'Error allocating OutData%Vdist_High.', ErrStat, ErrMsg,RoutineName)
RETURN
END IF
DO i5 = LBOUND(OutData%Vdist_High,5), UBOUND(OutData%Vdist_High,5)
DO i4 = LBOUND(OutData%Vdist_High,4), UBOUND(OutData%Vdist_High,4)
DO i3 = LBOUND(OutData%Vdist_High,3), UBOUND(OutData%Vdist_High,3)
DO i2 = LBOUND(OutData%Vdist_High,2), UBOUND(OutData%Vdist_High,2)
DO i1 = LBOUND(OutData%Vdist_High,1), UBOUND(OutData%Vdist_High,1)
OutData%Vdist_High(i1,i2,i3,i4,i5) = REAL(ReKiBuf(Re_Xferred), SiKi)
Re_Xferred = Re_Xferred + 1
END DO
END DO
END DO
END DO
END DO
END IF
END SUBROUTINE FWrap_UnPackInput

SUBROUTINE FWrap_CopyOutput( SrcOutputData, DstOutputData, CtrlCode, ErrStat, ErrMsg )
Expand Down
20 changes: 4 additions & 16 deletions glue-codes/fast-farm/src/FAST_Farm_Subs.f90
Original file line number Diff line number Diff line change
Expand Up @@ -1736,6 +1736,9 @@ SUBROUTINE Farm_InitFAST( farm, WD_InitInp, AWAE_InitOutput, SC_InitOutput, SC_y
FWrap_InitInp%dX_high = AWAE_InitOutput%dX_high(nt)
FWrap_InitInp%dY_high = AWAE_InitOutput%dY_high(nt)
FWrap_InitInp%dZ_high = AWAE_InitOutput%dZ_high(nt)

FWrap_InitInp%Vdist_High => AWAE_InitOutput%Vdist_High(nt)%data

if (SC_InitOutput%NumSC2Ctrl>0) then
FWrap_InitInp%fromSC = SC_y%fromSC((nt-1)*SC_InitOutput%NumSC2Ctrl+1:nt*SC_InitOutput%NumSC2Ctrl)
end if
Expand Down Expand Up @@ -2063,7 +2066,6 @@ subroutine FARM_InitialCO(farm, ErrStat, ErrMsg)
!--------------------
! 1c. transfer y_AWAE to u_F and u_WD

call Transfer_AWAE_to_FAST(farm)
call Transfer_AWAE_to_WD(farm)

if (farm%p%UseSC) then
Expand Down Expand Up @@ -2155,8 +2157,7 @@ subroutine FARM_InitialCO(farm, ErrStat, ErrMsg)
!.......................................................................................
! Transfer y_AWAE to u_F and u_WD
!.......................................................................................

call Transfer_AWAE_to_FAST(farm)

call Transfer_AWAE_to_WD(farm)

!.......................................................................................
Expand Down Expand Up @@ -2732,7 +2733,6 @@ subroutine FARM_CalcOutput(t, farm, ErrStat, ErrMsg)

!--------------------
! 2. Transfer y_AWAE to u_F and u_WD
call Transfer_AWAE_to_FAST(farm)
call Transfer_AWAE_to_WD(farm)


Expand Down Expand Up @@ -2879,18 +2879,6 @@ SUBROUTINE Transfer_AWAE_to_WD(farm)

END SUBROUTINE Transfer_AWAE_to_WD
!----------------------------------------------------------------------------------------------------------------------------------
SUBROUTINE Transfer_AWAE_to_FAST(farm)
type(All_FastFarm_Data), INTENT(INOUT) :: farm !< FAST.Farm data

integer(intKi) :: nt

DO nt = 1,farm%p%NumTurbines
! allocated in FAST's IfW initialization as 3,x,y,z,t
farm%FWrap(nt)%u%Vdist_High = farm%AWAE%y%Vdist_High(nt)%data
END DO

END SUBROUTINE Transfer_AWAE_to_FAST
!----------------------------------------------------------------------------------------------------------------------------------
SUBROUTINE Transfer_WD_to_AWAE(farm)
type(All_FastFarm_Data), INTENT(INOUT) :: farm !< FAST.Farm data

Expand Down
7 changes: 7 additions & 0 deletions modules/awae/src/AWAE.f90
Original file line number Diff line number Diff line change
Expand Up @@ -1176,6 +1176,13 @@ subroutine AWAE_Init( InitInp, u, p, x, xd, z, OtherState, y, m, Interval, InitO
if (errStat2 /= 0) call SetErrStat ( ErrID_Fatal, 'Could not allocate memory for y%TI_amb.', errStat, errMsg, RoutineName )
if (errStat >= AbortErrLev) return

! Set pointers to high resolution wind in InitOutput
allocate(InitOut%Vdist_High(1:p%NumTurbines), STAT=ErrStat2 )
if (errStat2 /= 0) call SetErrStat ( ErrID_Fatal, 'Could not allocate memory for y%Vdist_High.', errStat, errMsg, RoutineName )
do i = 1, p%NumTurbines
InitOut%Vdist_High(i)%data => y%Vdist_High(i)%data
end do

! This next step is not strictly necessary
y%V_plane = 0.0_Reki
y%Vx_wind_disk = 0.0_Reki
Expand Down
Loading