Skip to content

Commit 4910756

Browse files
committed
Remove unused InflowWind DDTs from AWAE and do some cleanup
1 parent a8dd2ee commit 4910756

File tree

3 files changed

+194
-393
lines changed

3 files changed

+194
-393
lines changed

modules/awae/src/AWAE.f90

Lines changed: 83 additions & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -56,11 +56,6 @@ module AWAE
5656
public :: AWAE_TEST_CalcOutput
5757
public :: AWAE_TEST_Interp2D
5858

59-
real(ReKi), parameter, private :: I33(3,3) = &
60-
reshape([1.0_ReKi, 0.0_ReKi, 0.0_ReKi, &
61-
0.0_ReKi, 1.0_ReKi, 0.0_ReKi, &
62-
0.0_ReKi, 0.0_ReKi, 1.0_ReKi], [3,3])
63-
6459
contains
6560

6661

@@ -1033,13 +1028,18 @@ subroutine AWAE_Init( InitInp, u, p, x, xd, z, OtherState, y, m, Interval, InitO
10331028
character(*), intent( out) :: errMsg !< Error message if errStat /= ErrID_None
10341029

10351030
character(1024) :: rootDir, baseName, OutFileVTKDir ! Simulation root dir, basename for outputs
1036-
integer(IntKi) :: i,j,nt ! loop counter
1031+
integer(IntKi) :: i,j,nt,c ! loop counter
10371032
real(ReKi) :: gridLoc ! Location of requested output slice in grid coordinates [0,sz-1]
10381033
integer(IntKi) :: errStat2 ! temporary error status of the operation
10391034
character(ErrMsgLen) :: errMsg2 ! temporary error message
10401035
character(*), parameter :: RoutineName = 'AWAE_Init'
10411036
type(InflowWind_InitInputType) :: IfW_InitInp
10421037
type(InflowWind_InitOutputType) :: IfW_InitOut
1038+
type(InflowWind_ContinuousStateType) :: IfW_x
1039+
type(InflowWind_DiscreteStateType) :: IfW_xd
1040+
type(InflowWind_OtherStateType) :: IfW_OtherState
1041+
type(InflowWind_ConstraintStateType) :: IfW_z
1042+
type(InflowWind_MiscVarType) :: IfW_m
10431043

10441044
! Initialize variables for this routine
10451045
errStat = ErrID_None
@@ -1127,9 +1127,15 @@ subroutine AWAE_Init( InitInp, u, p, x, xd, z, OtherState, y, m, Interval, InitO
11271127
! --------------------------------------------------------------------------------
11281128
! --- Initialize states
11291129
! --------------------------------------------------------------------------------
1130+
1131+
allocate(m%u_IfW_High(p%NumTurbines), stat=errStat2); if (Failed0('InflowWind input data')) return;
1132+
allocate(m%y_IfW_High(p%NumTurbines), stat=errStat2); if (Failed0('InflowWind output data')) return;
1133+
11301134
! initialize tracer for WAT box location
11311135
xd%WAT_B_Box(1:3) = 0.0_ReKi
1132-
if ( p%Mod_AmbWind > 1 ) then
1136+
1137+
if (p%Mod_AmbWind > 1) then
1138+
11331139
! Using InflowWind, so initialize that module now
11341140
IfW_InitInp%Linearize = .false.
11351141
IfW_InitInp%RootName = TRIM(p%OutFileRoot)//'.IfW'
@@ -1141,85 +1147,81 @@ subroutine AWAE_Init( InitInp, u, p, x, xd, z, OtherState, y, m, Interval, InitO
11411147
IfW_InitInp%WtrDpth = 0.0_ReKi
11421148
IfW_InitInp%MSL2SWL = 0.0_ReKi
11431149

1144-
if ( p%Mod_AmbWind == 2 ) then ! one InflowWind module
1150+
if (p%Mod_AmbWind == 2) then ! one InflowWind module
11451151

1146-
ALLOCATE(p%IfW( 0:0),STAT=ErrStat2); if (Failed0('InflowWind parameter data' )) return;
1147-
ALLOCATE(x%IfW( 0:0),STAT=ErrStat2); if (Failed0('InflowWind continuous states data')) return;
1148-
ALLOCATE(xd%IfW( 0:0),STAT=ErrStat2); if (Failed0('InflowWind discrete states data' )) return;
1149-
ALLOCATE(z%IfW( 0:0),STAT=ErrStat2); if (Failed0('InflowWind constraint states data')) return;
1150-
ALLOCATE(OtherState%IfW(0:0),STAT=ErrStat2); if (Failed0('InflowWind other states data' )) return;
1151-
ALLOCATE(m%IfW( 0:0),STAT=ErrStat2); if (Failed0('InflowWind miscvar data' )) return;
1152+
allocate(p%IfW(0:0), stat=ErrStat2); if (Failed0('InflowWind parameter data')) return;
11521153

11531154
! Initialize InflowWind
11541155
IfW_InitInp%FixedWindFileRootName = .false.
11551156
IfW_InitInp%NumWindPoints = p%LowRes%nPoints
11561157
IfW_InitInp%RadAvg = 0.25 * p%LowRes%nXYZ(3) * p%LowRes%dXYZ(1) ! arbitrary garbage, just must be bigger than zero, but not bigger than grid (IfW will complain if this isn't set when it tries to calculate disk average vel)
1157-
IfW_InitInp%MHK = 0 ! not an MHK turbine setup
11581158

1159-
call InflowWind_Init( IfW_InitInp, m%u_IfW_Low, p%IfW(0), x%IfW(0), xd%IfW(0), z%IfW(0), OtherState%IfW(0), m%y_IfW_Low, m%IfW(0), Interval, IfW_InitOut, ErrStat2, ErrMsg2 ); if(Failed()) return;
1160-
p%IfW(0)%NumOuts = 0 ! override outputs that might be in the input file
1159+
call InflowWind_Init(IfW_InitInp, m%u_IfW_Low, p%IfW(0), IfW_x, IfW_xd, IfW_z, IfW_OtherState, &
1160+
m%y_IfW_Low, IfW_m, Interval, IfW_InitOut, ErrStat2, ErrMsg2)
1161+
if (Failed()) return
1162+
1163+
! Initialize InflowWind input/output for each high-resolution domain
1164+
do nt = 1,p%NumTurbines
1165+
call AllocAry(m%u_IfW_High(nt)%PositionXYZ, 3, p%HighRes(nt)%nPoints, "m%u_IfW_High(nt)%PositionXYZ", errStat2, errMsg2); if (Failed()) return
1166+
call AllocAry(m%y_IfW_High(nt)%VelocityUVW, 3, p%HighRes(nt)%nPoints, "m%y_IfW_High(nt)%VelocityUVW", errStat2, errMsg2); if (Failed()) return
1167+
m%u_IfW_High(nt)%PositionXYZ = p%HighRes(nt)%GridPoints
1168+
end do
11611169

1162-
else if ( p%Mod_AmbWind == 3 ) then ! multiple InflowWind modules
1170+
else if (p%Mod_AmbWind == 3) then ! multiple InflowWind modules
11631171

1164-
ALLOCATE(p%IfW( 0:p%NumTurbines),STAT=ErrStat2); if (Failed0('InflowWind parameter data' )) return;
1165-
ALLOCATE(x%IfW( 0:p%NumTurbines),STAT=ErrStat2); if (Failed0('InflowWind continuous states data')) return;
1166-
ALLOCATE(xd%IfW( 0:p%NumTurbines),STAT=ErrStat2); if (Failed0('InflowWind discrete states data' )) return;
1167-
ALLOCATE(z%IfW( 0:p%NumTurbines),STAT=ErrStat2); if (Failed0('InflowWind constraint states data')) return;
1168-
ALLOCATE(OtherState%IfW(0:p%NumTurbines),STAT=ErrStat2); if (Failed0('InflowWind other states data' )) return;
1169-
ALLOCATE(m%IfW( 0:p%NumTurbines),STAT=ErrStat2); if (Failed0('InflowWind miscvar data' )) return;
1172+
allocate(p%IfW(0:p%NumTurbines), stat=ErrStat2); if (Failed0('InflowWind parameter data')) return;
11701173

11711174
! Initialize InflowWind for the low-resolution domain
11721175
IfW_InitInp%FixedWindFileRootName = .true.
11731176
IfW_InitInp%NumWindPoints = p%LowRes%nPoints
11741177
IfW_InitInp%TurbineID = 0
11751178
IfW_InitInp%MHK = MHK_None
11761179

1177-
call InflowWind_Init( IfW_InitInp, m%u_IfW_Low, p%IfW(0), x%IfW(0), xd%IfW(0), z%IfW(0), OtherState%IfW(0), m%y_IfW_Low, m%IfW(0), Interval, IfW_InitOut, ErrStat2, ErrMsg2 ); if(Failed()) return;
1178-
p%IfW(0)%NumOuts = 0 ! override outputs that might be in the input file
1180+
call InflowWind_Init(IfW_InitInp, m%u_IfW_Low, p%IfW(0), IfW_x, IfW_xd, IfW_z, IfW_OtherState, &
1181+
m%y_IfW_Low, IfW_m, Interval, IfW_InitOut, ErrStat2, ErrMsg2)
1182+
if (Failed()) return
11791183

11801184
! Initialize InflowWind for each high-resolution domain
11811185
do nt = 1,p%NumTurbines
1186+
1187+
! Destroy any previous data in types used only for initialization
1188+
call InflowWind_DestroyContState(IfW_x, errStat2, errMsg2)
1189+
call InflowWind_DestroyDiscState(IfW_xd, errStat2, errMsg2)
1190+
call InflowWind_DestroyOtherState(IfW_OtherState, errStat2, errMsg2)
1191+
call InflowWind_DestroyConstrState(IfW_z, errStat2, errMsg2)
1192+
call InflowWind_DestroyMisc(IfW_m, errStat2, errMsg2)
1193+
1194+
! Update initialization inputs for this turbine
11821195
IfW_InitInp%TurbineID = nt
11831196
IfW_InitInp%NumWindPoints = p%HighRes(nt)%nPoints
1184-
call InflowWind_Init( IfW_InitInp, m%u_IfW_High, p%IfW(nt), x%IfW(nt), xd%IfW(nt), z%IfW(nt), OtherState%IfW(nt), m%y_IfW_High, m%IfW(nt), Interval, IfW_InitOut, ErrStat2, ErrMsg2 ); if(Failed()) return;
1185-
p%IfW(nt)%NumOuts = 0 ! override outputs that might be in the input file
1197+
1198+
call InflowWind_Init(IfW_InitInp, m%u_IfW_High(nt), p%IfW(nt), IfW_x, IfW_xd, IfW_z, IfW_OtherState, &
1199+
m%y_IfW_High(nt), IfW_m, Interval, IfW_InitOut, ErrStat2, ErrMsg2)
1200+
if (Failed()) return
11861201

11871202
! Check that the high resolution grid placement is correct
11881203
! The InflowWind grid location is exactly centered on the TurbPos location in the Y direction. The high resolution grid
11891204
! must exactly match the sizing and location of the InflowWind grid. We are only going to check the Y and Z locations
11901205
! for now and throw an error if these don't match appropriately.
1191-
call CheckModAmb3Boundaries()
1206+
call CheckModAmb3Boundaries(); if (Failed()) return
11921207

1193-
end do
1194-
if (errStat >= AbortErrLev) return
1208+
! Set the position of the high-resolution grid points relative to the turbine position
1209+
do c = 1, p%HighRes(nt)%nPoints
1210+
m%u_IfW_High(nt)%PositionXYZ(:,c) = p%HighRes(nt)%GridPoints(:,c) - p%HighRes(nt)%WT_Position
1211+
end do
11951212

1213+
end do
11961214
end if
11971215

11981216
! Set the position inputs once for the low-resolution grid
11991217
m%u_IfW_Low%PositionXYZ = p%LowRes%GridPoints
1200-
1201-
! Set the hub position and orientation to pass to IfW (FIXME: IfW always calculates hub and disk avg vel. Change this after IfW pointers fully enabled.)
1202-
m%u_IfW_Low%HubPosition = p%LowRes%oXYZ + 0.5_ReKi * p%LowRes%nXYZ * p%LowRes%dXYZ
1203-
m%u_IfW_Low%HubOrientation = I33
1204-
1205-
! Initialize the high-resolution grid inputs and outputs
1206-
IF ( .NOT. ALLOCATED( m%u_IfW_High%PositionXYZ ) ) THEN
1207-
call AllocAry(m%u_IfW_High%PositionXYZ, 3, p%HighRes(1)%nPoints, 'm%u_IfW_High%PositionXYZ', ErrStat2, ErrMsg2); if(Failed()) return;
1208-
call AllocAry(m%y_IfW_High%VelocityUVW, 3, p%HighRes(1)%nPoints, 'm%y_IfW_High%VelocityUVW', ErrStat2, ErrMsg2); if(Failed()) return;
1209-
call AllocAry(m%y_IfW_High%WriteOutput, size(m%y_IfW_Low%WriteOutput), 'm%y_IfW_High%WriteOutput', ErrStat2, ErrMsg2); if(Failed()) return;
1210-
if (allocated(m%y_IfW_Low%lidar%LidSpeed)) then
1211-
call AllocAry(m%y_IfW_High%lidar%LidSpeed, size(m%y_IfW_Low%lidar%LidSpeed ), 'm%y_IfW_High%lidar%LidSpeed', ErrStat2, ErrMsg2); if(Failed()) return;
1212-
endif
1213-
if (allocated(m%y_IfW_High%lidar%MsrPositionsX)) then
1214-
call AllocAry(m%y_IfW_High%lidar%MsrPositionsX, size(m%y_IfW_High%lidar%MsrPositionsX), 'm%y_IfW_High%lidar%MsrPositionsX', ErrStat2, ErrMsg2); if(Failed()) return;
1215-
endif
1216-
if (allocated(m%y_IfW_High%lidar%MsrPositionsY)) then
1217-
call AllocAry(m%y_IfW_High%lidar%MsrPositionsY, size(m%y_IfW_High%lidar%MsrPositionsY), 'm%y_IfW_High%lidar%MsrPositionsY', ErrStat2, ErrMsg2); if(Failed()) return;
1218-
endif
1219-
if (allocated(m%y_IfW_High%lidar%MsrPositionsZ)) then
1220-
call AllocAry(m%y_IfW_High%lidar%MsrPositionsZ, size(m%y_IfW_High%lidar%MsrPositionsZ), 'm%y_IfW_High%lidar%MsrPositionsZ', ErrStat2, ErrMsg2); if(Failed()) return;
1221-
endif
1222-
END IF
1218+
1219+
! Destroy any previous data in types used only for initialization
1220+
call InflowWind_DestroyInitInput(IfW_InitInp, errStat2, errMsg2)
1221+
call InflowWind_DestroyInitOutput(IfW_InitOut, errStat2, errMsg2)
1222+
call InflowWind_DestroyContState(IfW_x, errStat2, errMsg2)
1223+
call InflowWind_DestroyDiscState(IfW_xd, errStat2, errMsg2)
1224+
call InflowWind_DestroyMisc(IfW_m, errStat2, errMsg2)
12231225

12241226
end if
12251227

@@ -1498,14 +1500,20 @@ subroutine AWAE_End( u, p, x, xd, z, OtherState, y, m, errStat, errMsg )
14981500
errStat = ErrID_None
14991501
errMsg = ""
15001502

1501-
! End all instances of the InflowWind module
1502-
if ( p%Mod_AmbWind == 2 ) then
1503-
call InflowWind_End( m%u_IfW_Low, p%IfW(0 ), x%IfW(0 ), xd%IfW(0 ), z%IfW(0 ), OtherState%IfW(0 ), m%y_IfW_Low, m%IfW(0 ), errStat, errMsg )
1504-
else if ( p%Mod_AmbWind == 3 ) then
1505-
call InflowWind_End( m%u_IfW_Low, p%IfW(0 ), x%IfW(0 ), xd%IfW(0 ), z%IfW(0 ), OtherState%IfW(0 ), m%y_IfW_Low, m%IfW(0 ), errStat, errMsg )
1506-
do nt = 1,p%NumTurbines
1507-
call InflowWind_End( m%u_IfW_Low, p%IfW(nt), x%IfW(nt), xd%IfW(nt), z%IfW(nt), OtherState%IfW(nt), m%y_IfW_Low, m%IfW(nt), errStat, errMsg )
1508-
end do
1503+
! Destroy InflowWind data
1504+
if (p%Mod_AmbWind > 1) then
1505+
1506+
call InflowWind_DestroyInput(m%u_IfW_Low, errStat, errMsg)
1507+
call InflowWind_DestroyParam(p%IfW(0), errStat, errMsg)
1508+
call InflowWind_DestroyOutput(m%y_IfW_Low, errStat, errMsg)
1509+
1510+
if (p%Mod_AmbWind == 3) then
1511+
do nt = 1,p%NumTurbines
1512+
call InflowWind_DestroyInput(m%u_IfW_High(nt), errStat, errMsg)
1513+
call InflowWind_DestroyParam(p%IfW(nt), errStat, errMsg)
1514+
call InflowWind_DestroyOutput(m%y_IfW_High(nt), errStat, errMsg)
1515+
end do
1516+
end if
15091517
end if
15101518

15111519
! Destroy the input data:
@@ -1581,8 +1589,7 @@ subroutine AWAE_UpdateStates( t, n, u, p, x, xd, z, OtherState, m, errStat, errM
15811589
! InflowWind-based ambient wind (single or multiple instances)
15821590
case (2, 3)
15831591

1584-
! Set the hub position and orientation to pass to IfW (IfW always calculates hub and disk avg vel)
1585-
! Set low-resolution inflow wind velocities
1592+
! Calculate the low-resolution grid inflow velocities
15861593
call IfW_FlowField_GetVelAcc(p%IfW(0)%FlowField, 1, t+p%dt_low, p%LowRes%GridPoints, m%y_IfW_Low%VelocityUVW, AccUVW, errStat2, errMsg2)
15871594
if (Failed()) return
15881595

@@ -1632,15 +1639,15 @@ subroutine AWAE_UpdateStates( t, n, u, p, x, xd, z, OtherState, m, errStat, errM
16321639

16331640
! Calculate wind velocities at grid locations from InflowWind
16341641
call IfW_FlowField_GetVelAcc(p%IfW(0)%FlowField, 1, t+p%dt_low+i_hl*p%DT_high, &
1635-
p%HighRes(nt)%GridPoints(:,:), &
1636-
m%y_IfW_High%VelocityUVW, AccUVW, errStat2, errMsg2)
1642+
m%u_IfW_High(nt)%PositionXYZ, &
1643+
m%y_IfW_High(nt)%VelocityUVW, AccUVW, errStat2, errMsg2)
16371644
if (Failed()) return
16381645

16391646
! Transfer velocities to high resolution grid
1640-
V_Grid(1:size(m%Vamb_high(nt)%data,1),&
1641-
1:size(m%Vamb_high(nt)%data,2),&
1642-
1:size(m%Vamb_high(nt)%data,3),&
1643-
1:size(m%Vamb_high(nt)%data,4)) => m%y_IfW_High%VelocityUVW
1647+
V_Grid(lbound(m%Vamb_high(nt)%data,1):ubound(m%Vamb_high(nt)%data,1),&
1648+
lbound(m%Vamb_high(nt)%data,2):ubound(m%Vamb_high(nt)%data,2),&
1649+
lbound(m%Vamb_high(nt)%data,3):ubound(m%Vamb_high(nt)%data,3),&
1650+
lbound(m%Vamb_high(nt)%data,4):ubound(m%Vamb_high(nt)%data,4)) => m%y_IfW_High(nt)%VelocityUVW
16441651
m%Vamb_high(nt)%data(:,:,:,:,i_hl) = V_Grid
16451652
end do
16461653
end do
@@ -1651,25 +1658,20 @@ subroutine AWAE_UpdateStates( t, n, u, p, x, xd, z, OtherState, m, errStat, errM
16511658
! Loop through turbines
16521659
do nt = 1, p%NumTurbines
16531660

1654-
! Calculate high resolution grid position relative to turbine position
1655-
do c = 1, p%HighRes(nt)%nPoints
1656-
m%u_IfW_High%PositionXYZ(:,c) = p%HighRes(nt)%GridPoints(:,c) - p%HighRes(nt)%WT_Position
1657-
end do
1658-
16591661
! Loop through high resolution grids
16601662
do i_hl = 0, n_high_low
16611663

16621664
! Calculate wind velocities at grid locations from InflowWind
16631665
call IfW_FlowField_GetVelAcc(p%IfW(nt)%FlowField, 1, t+p%dt_low+i_hl*p%DT_high, &
1664-
m%u_IfW_High%PositionXYZ, &
1665-
m%y_IfW_High%VelocityUVW, AccUVW, errStat2, errMsg2)
1666+
m%u_IfW_High(nt)%PositionXYZ, &
1667+
m%y_IfW_High(nt)%VelocityUVW, AccUVW, errStat2, errMsg2)
16661668
if (Failed()) return
16671669

16681670
! Transfer velocities to high resolution grid
1669-
V_Grid(1:size(m%Vamb_high(nt)%data,1),&
1670-
1:size(m%Vamb_high(nt)%data,2),&
1671-
1:size(m%Vamb_high(nt)%data,3),&
1672-
1:size(m%Vamb_high(nt)%data,4)) => m%y_IfW_High%VelocityUVW
1671+
V_Grid(lbound(m%Vamb_high(nt)%data,1):ubound(m%Vamb_high(nt)%data,1),&
1672+
lbound(m%Vamb_high(nt)%data,2):ubound(m%Vamb_high(nt)%data,2),&
1673+
lbound(m%Vamb_high(nt)%data,3):ubound(m%Vamb_high(nt)%data,3),&
1674+
lbound(m%Vamb_high(nt)%data,4):ubound(m%Vamb_high(nt)%data,4)) => m%y_IfW_High(nt)%VelocityUVW
16731675
m%Vamb_high(nt)%data(:,:,:,:,i_hl) = V_Grid
16741676
end do
16751677
end do

0 commit comments

Comments
 (0)