Skip to content

Commit

Permalink
Fix HAWC periodic wind exhausted in IfW
Browse files Browse the repository at this point in the history
There was a bug where the modulo operation to wrap back to the beginning
of the wind file didn't work correctly, previously noted in issue OpenFAST#471.
This seemed to come back due to some changes in the IfW refactor.
The ifw_HAWC regression test was added to catch this and other IfW
changes in the future.
  • Loading branch information
deslaughter committed Jul 14, 2023
1 parent 17c8cbe commit baf1f81
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 22 deletions.
31 changes: 12 additions & 19 deletions modules/inflowwind/src/IfW_FlowField.f90
Original file line number Diff line number Diff line change
Expand Up @@ -261,11 +261,11 @@ subroutine IfW_FlowField_GetVelAcc(FF, IStart, Time, PositionXYZ, VelocityUVW, A
cycle
end if

call Grid4DField_GetVel(FF%Grid4D, Time, Position(:, i), VelocityUVW(:, i), TmpErrStat, TmpErrMsg)
if (TmpErrStat >= AbortErrLev) then
call SetErrStat(TmpErrStat, TmpErrMsg, ErrStat, ErrMsg, RoutineName)
return
end if
call Grid4DField_GetVel(FF%Grid4D, Time, Position(:, i), VelocityUVW(:, i), TmpErrStat, TmpErrMsg)
if (TmpErrStat >= AbortErrLev) then
call SetErrStat(TmpErrStat, TmpErrMsg, ErrStat, ErrMsg, RoutineName)
return
end if
end do

case (Point_FieldType)
Expand Down Expand Up @@ -1232,34 +1232,28 @@ subroutine GetBoundsT(PosX, DT)
! In distance, X: InputInfo%PosX - p%InitXPosition - TIME*p%MeanWS
TimeShifted = real(Time, ReKi) + (G3D%InitXPosition - PosX)*G3D%InvMWS

! Get position on T grid
T_GRID = TimeShifted*G3D%Rate

! If field is periodic
if (G3D%Periodic) then
TimeShifted = MODULO(TimeShifted, G3D%TotalTime)
! If TimeShifted is a very small negative number,
! modulo returns the incorrect value due to internal rounding errors.
! See bug report #471
if (TimeShifted == G3D%TotalTime) TimeShifted = 0.0_ReKi
T_GRID = MODULO(T_GRID, real(G3D%NSteps, ReKi))
end if

! Get position on T grid
T_GRID = TimeShifted*G3D%Rate + 1

! Calculate bounding grid indices
IT_LO = floor(T_GRID, IntKi)
IT_HI = ceiling(T_GRID, IntKi)
IT_LO = floor(T_GRID, IntKi) + 1
IT_HI = IT_LO + 1

! Position location within interval [0,1]
DT = T_GRID - aint(T_GRID)
DT = 2.0_ReKi*(T_GRID - aint(T_GRID)) - 1.0_ReKi

! Adjust indices and interpolant
if (IT_LO >= 1 .and. IT_HI <= G3D%NSteps) then
! Point is within grid
DT = 2.0_ReKi*DT - 1.0_ReKi
else if (IT_LO == G3D%NSteps) then
if (G3D%Periodic) then
! Time wraps back to beginning
IT_HI = 1
DT = 2.0_ReKi*DT - 1.0_ReKi
else if (DT <= GridTol) then
! Within tolerance of last time
IT_HI = IT_LO
Expand All @@ -1268,7 +1262,6 @@ subroutine GetBoundsT(PosX, DT)
! Extrapolate
IT_LO = G3D%NSteps - 1
IT_HI = G3D%NSteps
DT = DT + 1.0_ReKi
end if
else
! Time exceeds array bounds
Expand Down
4 changes: 2 additions & 2 deletions modules/inflowwind/src/InflowWind_IO.f90
Original file line number Diff line number Diff line change
Expand Up @@ -2540,8 +2540,8 @@ subroutine Grid3D_ScaleTurbulence(InitInp, Vel, ScaleFactors, ErrStat, ErrMsg)
iy = (ny + 1)/2 ! integer division

! compute the actual sigma at the point specified by (iy,iz). (This sigma should be close to 1.)
vSum = sum(Vel(:, iy, iz, :), dim=2)
vSum2 = sum(Vel(:, iy, iz, :)**2, dim=2)
vSum = sum(real(Vel(:, iy, iz, :),R8Ki), dim=2)
vSum2 = sum(real(Vel(:, iy, iz, :),R8Ki)**2, dim=2)
vMean = vSum/nt
ActualSigma = real(SQRT(ABS((vSum2/nt) - vMean**2)), ReKi)

Expand Down
1 change: 1 addition & 0 deletions reg_tests/CTestList.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -387,6 +387,7 @@ ifw_regression("ifw_uniform" "inflowwind")
ifw_regression("ifw_nativeBladed" "inflowwind")
ifw_regression("ifw_BoxExceed" "inflowwind")
ifw_regression("ifw_BoxExceedTwr" "inflowwind")
ifw_regression("ifw_HAWC" "inflowwind")

# Py-InflowWind regression tests
py_ifw_regression("py_ifw_turbsimff" "inflowwind;python")
Expand Down
1 change: 1 addition & 0 deletions reg_tests/executeInflowwindRegressionCase.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@
os.makedirs(testBuildDirectory)
for file in (glob.glob(os.path.join(inputsDirectory,"*.inp")) +
glob.glob(os.path.join(inputsDirectory,"*.bts"))+
glob.glob(os.path.join(inputsDirectory,"*.bin"))+
glob.glob(os.path.join(inputsDirectory,"*.wnd"))+
glob.glob(os.path.join(inputsDirectory,"*.hh"))+
glob.glob(os.path.join(inputsDirectory,"*.sum"))):
Expand Down

0 comments on commit baf1f81

Please sign in to comment.