From 9761b2790f806702943e98632f089d451b0422f7 Mon Sep 17 00:00:00 2001 From: andrew-platt Date: Thu, 18 Nov 2021 10:44:47 -0700 Subject: [PATCH] AWAE: fix some broken error handling --- glue-codes/fast-farm/src/FAST_Farm_Subs.f90 | 7 ++- modules/awae/src/AWAE.f90 | 62 +++++++++------------ modules/awae/src/AWAE_IO.f90 | 27 ++++++--- 3 files changed, 52 insertions(+), 44 deletions(-) diff --git a/glue-codes/fast-farm/src/FAST_Farm_Subs.f90 b/glue-codes/fast-farm/src/FAST_Farm_Subs.f90 index c9213424e6..218f2b3017 100644 --- a/glue-codes/fast-farm/src/FAST_Farm_Subs.f90 +++ b/glue-codes/fast-farm/src/FAST_Farm_Subs.f90 @@ -332,7 +332,12 @@ SUBROUTINE Farm_Initialize( farm, InputFile, ErrStat, ErrMsg ) RETURN END IF - call Farm_InitOutput( farm, ErrStat, ErrMsg ) + call Farm_InitOutput( farm, ErrStat2, ErrMsg2 ) + CALL SetErrStat(ErrStat2, ErrMsg2, ErrStat, ErrMsg, RoutineName ) + IF (ErrStat >= AbortErrLev) THEN + CALL Cleanup() + RETURN + END IF ! Print the summary file if requested: IF (farm%p%SumPrint) THEN diff --git a/modules/awae/src/AWAE.f90 b/modules/awae/src/AWAE.f90 index 140ee9b25b..d6137766f3 100644 --- a/modules/awae/src/AWAE.f90 +++ b/modules/awae/src/AWAE.f90 @@ -987,9 +987,7 @@ subroutine AWAE_Init( InitInp, u, p, x, xd, z, OtherState, y, m, Interval, InitO call SetErrStat(ErrID_Fatal, "The requested low-resolution YZ output slice location, X="//TRIM(Num2LStr(p%OutDisWindX(i)))//", is outside of the low-resolution grid.", errStat, errMsg, RoutineName ) end if end do - if (errStat2 >= AbortErrLev) then - return - end if + if (errStat >= AbortErrLev) return !interval = InitOut%dt_low @@ -1008,7 +1006,7 @@ 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 u%Vr_wake.', errStat, errMsg, RoutineName ) allocate ( u%D_wake (0:p%NumPlanes-1,1:p%NumTurbines), STAT=ErrStat2 ) if (errStat2 /= 0) call SetErrStat ( ErrID_Fatal, 'Could not allocate memory for u%D_wake.', errStat, errMsg, RoutineName ) - if (errStat /= ErrID_None) return + if (errStat >= AbortErrLev) return @@ -1031,7 +1029,7 @@ 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%Vx_rel_disk.', errStat, errMsg, RoutineName ) allocate ( y%TI_amb (1:p%NumTurbines), STAT=ErrStat2 ) if (errStat2 /= 0) call SetErrStat ( ErrID_Fatal, 'Could not allocate memory for y%TI_amb.', errStat, errMsg, RoutineName ) - if (errStat /= ErrID_None) return + if (errStat >= AbortErrLev) return ! This next step is not strictly necessary y%V_plane = 0.0_Reki @@ -1040,24 +1038,24 @@ subroutine AWAE_Init( InitInp, u, p, x, xd, z, OtherState, y, m, Interval, InitO if ( p%NOutDisWindXY > 0 ) then - ALLOCATE ( m%OutVizXYPlane(3,p%nX_low, p%nY_low,1) , STAT=ErrStat ) - IF ( ErrStat /= 0 ) THEN + ALLOCATE ( m%OutVizXYPlane(3,p%nX_low, p%nY_low,1) , STAT=ErrStat2 ) + IF ( ErrStat2 /= 0 ) THEN ErrStat = ErrID_Fatal ErrMsg = ' Error allocating memory for the Fast.Farm OutVizXYPlane arrays.' RETURN ENDIF end if if ( p%NOutDisWindYZ > 0 ) then - ALLOCATE ( m%OutVizYZPlane(3,p%nY_low, p%nZ_low,1) , STAT=ErrStat ) - IF ( ErrStat /= 0 ) THEN + ALLOCATE ( m%OutVizYZPlane(3,p%nY_low, p%nZ_low,1) , STAT=ErrStat2 ) + IF ( ErrStat2 /= 0 ) THEN ErrStat = ErrID_Fatal ErrMsg = ' Error allocating memory for the Fast.Farm OutVizYZPlane arrays.' RETURN ENDIF end if if ( p%NOutDisWindXZ > 0 ) then - ALLOCATE ( m%OutVizXZPlane(3,p%nX_low, p%nZ_low,1) , STAT=ErrStat ) - IF ( ErrStat /= 0 ) THEN + ALLOCATE ( m%OutVizXZPlane(3,p%nX_low, p%nZ_low,1) , STAT=ErrStat2 ) + IF ( ErrStat2 /= 0 ) THEN ErrStat = ErrID_Fatal ErrMsg = ' Error allocating memory for the Fast.Farm OutVizXZPlane arrays.' RETURN @@ -1112,12 +1110,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 m%pvec_cs.', errStat, errMsg, RoutineName ) allocate ( m%pvec_ce( 3,0:p%NumPlanes-2,1:p%NumTurbines ), STAT=errStat2 ) if (errStat2 /= 0) call SetErrStat ( ErrID_Fatal, 'Could not allocate memory for m%pvec_ce.', errStat, errMsg, RoutineName ) - if (errStat /= ErrID_None) return + if (errStat >= AbortErrLev) return ! Read-in the ambient wind data for the initial calculate output - call AWAE_UpdateStates( 0.0_DbKi, -1, u, p, x, xd, z, OtherState, m, errStat, errMsg ) + call AWAE_UpdateStates( 0.0_DbKi, -1, u, p, x, xd, z, OtherState, m, errStat2, errMsg2 ) + call SetErrStat( ErrStat2, ErrMsg2, errStat, errMsg, RoutineName ) @@ -1241,10 +1240,9 @@ subroutine AWAE_UpdateStates( t, n, u, p, x, xd, z, OtherState, m, errStat, errM if ( p%Mod_AmbWind == 1 ) then ! read from file the ambient flow for the n+1 time step - call ReadLowResWindFile(n+1, p, m%Vamb_Low, errStat, errMsg) - if ( errStat >= AbortErrLev ) then - return - end if + call ReadLowResWindFile(n+1, p, m%Vamb_Low, errStat2, errMsg2) + call SetErrStat( ErrStat2, ErrMsg2, errStat, errMsg, RoutineName ) + if (errStat >= AbortErrLev) return !#ifdef _OPENMP ! t2 = omp_get_wtime() ! write(*,*) ' AWAE_UpdateStates: Time spent reading Low Res data : '//trim(num2lstr(t2-t1))//' seconds' @@ -1253,20 +1251,18 @@ subroutine AWAE_UpdateStates( t, n, u, p, x, xd, z, OtherState, m, errStat, errM do nt = 1,p%NumTurbines do n_hl=0, n_high_low ! read from file the ambient flow for the current time step - call ReadHighResWindFile(nt, (n+1)*p%n_high_low + n_hl, p, m%Vamb_high(nt)%data(:,:,:,:,n_hl), errStat, errMsg) - if ( errStat >= AbortErrLev ) then - return - end if + call ReadHighResWindFile(nt, (n+1)*p%n_high_low + n_hl, p, m%Vamb_high(nt)%data(:,:,:,:,n_hl), errStat2, errMsg2) + call SetErrStat( ErrStat2, ErrMsg2, errStat, errMsg, RoutineName ) + if (errStat >= AbortErrLev) return end do end do else ! p%Mod_AmbWind == 2 .or. 3 ! Set low-resolution inflow wind velocities - call InflowWind_CalcOutput(t+p%dt_low, 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) - if ( errStat >= AbortErrLev ) then - return - end if + call InflowWind_CalcOutput(t+p%dt_low, 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), errStat2, errMsg2) + call SetErrStat( ErrStat2, ErrMsg2, errStat, errMsg, RoutineName ) + if (errStat >= AbortErrLev) return c = 1 do k = 0,p%nZ_low-1 do j = 0,p%nY_low-1 @@ -1281,10 +1277,9 @@ subroutine AWAE_UpdateStates( t, n, u, p, x, xd, z, OtherState, m, errStat, errM do nt = 1,p%NumTurbines m%u_IfW_High%PositionXYZ = p%Grid_high(:,:,nt) do n_hl=0, n_high_low - call InflowWind_CalcOutput(t+p%dt_low+n_hl*p%DT_high, m%u_IfW_High, p%IfW(0), x%IfW(0), xd%IfW(0), z%IfW(0), OtherState%IfW(0), m%y_IfW_High, m%IfW(0), errStat, errMsg) - if ( errStat >= AbortErrLev ) then - return - end if + call InflowWind_CalcOutput(t+p%dt_low+n_hl*p%DT_high, m%u_IfW_High, p%IfW(0), x%IfW(0), xd%IfW(0), z%IfW(0), OtherState%IfW(0), m%y_IfW_High, m%IfW(0), errStat2, errMsg2) + call SetErrStat( ErrStat2, ErrMsg2, errStat, errMsg, RoutineName ) + if (errStat >= AbortErrLev) return c = 1 do k = 0,p%nZ_high-1 do j = 0,p%nY_high-1 @@ -1309,10 +1304,9 @@ subroutine AWAE_UpdateStates( t, n, u, p, x, xd, z, OtherState, m, errStat, errM end do end do do n_hl=0, n_high_low - call InflowWind_CalcOutput(t+p%dt_low+n_hl*p%DT_high, 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), errStat, errMsg) - if ( errStat >= AbortErrLev ) then - return - end if + call InflowWind_CalcOutput(t+p%dt_low+n_hl*p%DT_high, 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), errStat2, errMsg2) + call SetErrStat( ErrStat2, ErrMsg2, errStat, errMsg, RoutineName ) + if (errStat >= AbortErrLev) return c = 1 do k = 0,p%nZ_high-1 do j = 0,p%nY_high-1 @@ -1381,8 +1375,6 @@ subroutine AWAE_CalcOutput( t, u, p, x, xd, z, OtherState, y, m, errStat, errMsg return end if call LowResGridCalcOutput(n, u, p, y, m, errStat2, errMsg2) - - call SetErrStat ( errStat2, errMsg2, errStat, errMsg, RoutineName ) if (errStat2 >= AbortErrLev) then return diff --git a/modules/awae/src/AWAE_IO.f90 b/modules/awae/src/AWAE_IO.f90 index 2f9645adcc..9722d9376c 100644 --- a/modules/awae/src/AWAE_IO.f90 +++ b/modules/awae/src/AWAE_IO.f90 @@ -257,6 +257,7 @@ subroutine AWAE_IO_InitGridInfo(InitInp, p, InitOut, errStat, errMsg) if ( (gridSpacing(1) <= 0.0_ReKi) .or. (gridSpacing(2) <= 0.0_ReKi) .or. (gridSpacing(3) <= 0.0_ReKi) ) & call SetErrStat ( ErrID_Fatal, 'The low resolution spatial resolution for Turbine 1 must be greater than zero in each spatial direction. ', errStat, errMsg, RoutineName ) + if (ErrStat >= AbortErrLev) return p%X0_low = origin(1) p%Y0_low = origin(2) @@ -351,7 +352,8 @@ subroutine AWAE_IO_InitGridInfo(InitInp, p, InitOut, errStat, errMsg) FileName = trim(p%WindFilePath)//trim(PathSep)//"HighT1"//trim(PathSep)//"Amb.t0.vtk" Un = -1 ! Set to force closing of file on return - call ReadVTK_SP_info( FileName, descr, dims, origin, gridSpacing, vecLabel, Un, errStat, errMsg ) + call ReadVTK_SP_info( FileName, descr, dims, origin, gridSpacing, vecLabel, Un, errStat2, errMsg2 ) + call SetErrStat( ErrStat2, ErrMsg2, errStat, errMsg, RoutineName ) if (errStat >= AbortErrLev) return else @@ -371,6 +373,7 @@ subroutine AWAE_IO_InitGridInfo(InitInp, p, InitOut, errStat, errMsg) if ( (gridSpacing(1) <= 0.0_ReKi) .or. (gridSpacing(2) <= 0.0_ReKi) .or. (gridSpacing(3) <= 0.0_ReKi) ) & call SetErrStat ( ErrID_Fatal, 'The high resolution spatial resolution for Turbine 1 must be greater than zero in each spatial direction. ', errStat, errMsg, RoutineName ) + if (errStat >= AbortErrLev ) return p%nX_high = dims(1) p%nY_high = dims(2) @@ -392,8 +395,9 @@ subroutine AWAE_IO_InitGridInfo(InitInp, p, InitOut, errStat, errMsg) if ( p%Mod_AmbWind == 1 ) then ! Just using this to make sure dims are >=2 points in each direction - call HiResWindCheck(0, 1, p%nX_high, p%nY_high, p%nZ_high, p%dX_high(1), p%dY_high(1), p%dZ_high(1), p%X0_high(1), p%Y0_high(1), p%Z0_high(1), dims, gridSpacing, origin, RoutineName, errMsg, errStat) - if (errStat >= AbortErrLev ) return + call HiResWindCheck(0, 1, p%nX_high, p%nY_high, p%nZ_high, p%dX_high(1), p%dY_high(1), p%dZ_high(1), p%X0_high(1), p%Y0_high(1), p%Z0_high(1), dims, gridSpacing, origin, RoutineName, errMsg2, errStat2) + call SetErrStat( ErrStat2, ErrMsg2, errStat, errMsg, RoutineName ) + if (errStat >= AbortErrLev) return end if allocate( p%Grid_high(3,NumGrid_high,p%NumTurbines ),stat=errStat2) @@ -424,7 +428,8 @@ subroutine AWAE_IO_InitGridInfo(InitInp, p, InitOut, errStat, errMsg) if ( p%Mod_AmbWind == 1 ) then FileName = trim(p%WindFilePath)//trim(PathSep)//"HighT"//trim(num2lstr(nt))//trim(PathSep)//"Amb.t0.vtk" Un = -1 ! Set to force closing of file on return - call ReadVTK_SP_info( FileName, descr, dims, origin, gridSpacing, vecLabel, Un, ErrStat, ErrMsg ) + call ReadVTK_SP_info( FileName, descr, dims, origin, gridSpacing, vecLabel, Un, ErrStat2, ErrMsg2 ) + call SetErrStat( ErrStat2, ErrMsg2, errStat, errMsg, RoutineName ) if (ErrStat >= AbortErrLev) return else ! Using InflowWind, so data has been passed in via the InitInp data structure @@ -456,8 +461,9 @@ subroutine AWAE_IO_InitGridInfo(InitInp, p, InitOut, errStat, errMsg) if ( p%Mod_AmbWind == 1 ) then ! Using this to make sure dims are >=2 points in each direction, and number of grid points in each direction matches turbine 1 - call HiResWindCheck(0, nt, p%nX_high, p%nY_high, p%nZ_high, p%dX_high(nt), p%dY_high(nt), p%dZ_high(nt), p%X0_high(nt), p%Y0_high(nt), p%Z0_high(nt), dims, gridSpacing, origin, RoutineName, errMsg, errStat) - if (errStat >= AbortErrLev ) return + call HiResWindCheck(0, nt, p%nX_high, p%nY_high, p%nZ_high, p%dX_high(nt), p%dY_high(nt), p%dZ_high(nt), p%X0_high(nt), p%Y0_high(nt), p%Z0_high(nt), dims, gridSpacing, origin, RoutineName, errMsg2, errStat2) + call SetErrStat( ErrStat2, ErrMsg2, errStat, errMsg, RoutineName ) + if (ErrStat >= AbortErrLev) return end if nXYZ_high = 0 @@ -494,10 +500,12 @@ subroutine AWAE_IO_InitGridInfo(InitInp, p, InitOut, errStat, errMsg) nhigh = nh+n*p%n_high_low-1 FileName = trim(p%WindFilePath)//trim(PathSep)//"HighT"//trim(num2lstr(nt))//trim(PathSep)//"Amb.t"//trim(num2lstr(nhigh))//".vtk" !TODO: Should the turbine numbers be padding with leading zero(es)? Un = -1 ! Set to force closing of file on return - call ReadVTK_SP_info( FileName, descr, dims, origin, gridSpacing, vecLabel, Un, ErrStat, ErrMsg ) + call ReadVTK_SP_info( FileName, descr, dims, origin, gridSpacing, vecLabel, Un, ErrStat2, ErrMsg2 ) + call SetErrStat( ErrStat2, ErrMsg2, errStat, errMsg, RoutineName ) if (ErrStat >= AbortErrLev) return - call HiResWindCheck(nhigh, nt, p%nX_high, p%nY_high, p%nZ_high, p%dX_high(nt), p%dY_high(nt), p%dZ_high(nt), p%X0_high(nt), p%Y0_high(nt), p%Z0_high(nt), dims, gridSpacing, origin, RoutineName, errMsg, errStat) + call HiResWindCheck(nhigh, nt, p%nX_high, p%nY_high, p%nZ_high, p%dX_high(nt), p%dY_high(nt), p%dZ_high(nt), p%X0_high(nt), p%Y0_high(nt), p%Z0_high(nt), dims, gridSpacing, origin, RoutineName, errMsg2, errStat2) + call SetErrStat( ErrStat2, ErrMsg2, errStat, errMsg, RoutineName ) if (errStat >= AbortErrLev ) return end do @@ -534,6 +542,9 @@ SUBROUTINE AWAE_PrintSum( p, u, y, ErrStat, ErrMsg ) CHARACTER(30) :: OutPFmt ! Format to print list of selected output channels to summary file CHARACTER(100) :: Msg ! temporary string for writing appropriate text to summary file + errStat = ErrID_None + errMsg = "" + ! Open the summary file and give it a heading. CALL GetNewUnit( UnSu, ErrStat, ErrMsg )