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

IfW: add VTK output of slice in XY to driver #2201

Merged
merged 10 commits into from
Dec 22, 2024
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,11 @@ InflowWind driver input file.
6,0,15 GridCtrCoord -- coordinate of center of grid (m)
1,1,0 GridDx,GridDY,GridDZ -- Step size of grid (m)
1,1,0 GridNx,GridNY,GridNZ -- number of grid points in X, Y and Z directions (-)
---- Output VTK slices ------------------------------------------------------
0 NOutWindXY -- Number of XY planes for output <RootName>.XY<loc>.t<n>.vtk (-) [0 to 9]
90 OutWindZ -- Z coordinates of XY planes for output (m) [1 to NOutWindXY] [unused for NOutWindXY=0]
0 NOutWindXZ -- Number of XZ planes for output <RootName>.YZ<loc>.t<n>.vtk (-) [0 to 9]
0 OutWindY -- Y coordinates of XZ planes for output (m) [1 to NOutWindXZ] [unused for NOutWindXZ=0]
0 NOutWindYZ -- Number of YZ planes for output <RootName>.YZ<loc>.t<n>.vtk (-) [0 to 9]
0 OutWindX -- X coordinates of YZ planes for output (m) [1 to NOutWindYZ] [unused for NOutWindYZ=0]
END of driver input file
1 change: 1 addition & 0 deletions modules/inflowwind/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ if (GENERATE_TYPES)
generate_f90_types(src/InflowWind_IO.txt ${CMAKE_CURRENT_LIST_DIR}/src/InflowWind_IO_Types.f90 -noextrap)
generate_f90_types(src/Lidar.txt ${CMAKE_CURRENT_LIST_DIR}/src/Lidar_Types.f90)
generate_f90_types(src/InflowWind.txt ${CMAKE_CURRENT_LIST_DIR}/src/InflowWind_Types.f90)
generate_f90_types(src/InflowWind_Driver_Registry.txt ${CMAKE_CURRENT_LIST_DIR}/src/InflowWind_Driver_Types.f90 -noextrap)
endif()

# InflowWind object library
Expand Down
133 changes: 68 additions & 65 deletions modules/inflowwind/src/InflowWind_Driver.f90
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ PROGRAM InflowWind_Driver
TYPE( ProgDesc ), PARAMETER :: ProgInfo = ProgDesc("InflowWind_Driver","","")
INTEGER(IntKi) :: IfWDriver_Verbose = 5 ! Verbose level. 0 = none, 5 = some, 10 = lots

! output paths hard coded
CHARACTER(*), PARAMETER :: VTKsliceDir = "vtk" ! Directory to place the output VTK slices

! Types needed here (from InflowWind module)
TYPE(InflowWind_InitInputType) :: InflowWind_InitInp ! Data for initialization -- this is where the input info goes
TYPE(InflowWind_InputType) :: InflowWind_u1 ! input -- contains xyz coords of interest -- set 1
Expand Down Expand Up @@ -116,8 +119,23 @@ PROGRAM InflowWind_Driver
CALL CPU_TIME( Timer(1) )

! Set some CLSettings to null/default values
CLSettings%ProgInfo = ProgInfo
Settings%ProgInfo = ProgInfo
CLSettings%ProgInfo = ProgInfo
Settings%ProgInfo = ProgInfo
! Set the filenames to empty strings -- otherwise prints garbage with the -vv option
CLSettings%DvrIptFileName = ''
CLSettings%IfWIptFileName = ''
CLSettings%SummaryFileName = ''
CLSettings%PointsFileName = ''
CLSettings%WindGridOutput%Name = ''
CLSettings%FFTOutput%Name = ''
CLSettings%PointsVelOutput%Name = ''
Settings%DvrIptFileName = ''
Settings%IfWIptFileName = ''
Settings%SummaryFileName = ''
Settings%PointsFileName = ''
Settings%WindGridOutput%Name = ''
Settings%FFTOutput%Name = ''
Settings%PointsVelOutput%Name = ''

!--------------------------------------------------------------------------------------------------------------------------------
!-=-=- Parse the command line inputs -=-=-
Expand Down Expand Up @@ -419,92 +437,61 @@ PROGRAM InflowWind_Driver
InflowWind_p%FlowField%Grid3D%BoxExceedAllowDrv = .true.
end if

! Make sure no errors occured that give us reason to terminate now.
IF ( ErrStat >= AbortErrLev ) THEN
CALL DriverCleanup()
CALL ProgAbort( ErrMsg )
ELSEIF ( ErrStat /= ErrID_None ) THEN
IF ( IfWDriver_Verbose >= 7_IntKi ) THEN
CALL WrScr(NewLine//' InflowWind_Init returned: ErrStat: '//TRIM(Num2LStr(ErrStat))// &
NewLine//' ErrMsg: '//TRIM(ErrMsg)//NewLine)
ELSEIF ( ErrStat >= ErrID_Warn ) THEN
CALL ProgWarn( ErrMsg )
ELSE
CALL WrScr(TRIM(ErrMsg))
ENDIF
ENDIF

call CheckCallErr('InflowWind_Init')


! Let user know we returned from the InflowWind code if verbose
IF ( IfWDriver_Verbose >= 5_IntKi ) CALL WrScr(NewLine//'InflowWind_Init CALL returned without errors.'//NewLine)


! Convert InflowWind file to HAWC format
IF (SettingsFlags%WrHAWC) THEN
CALL IfW_WriteHAWC( InflowWind_p%FlowField, InflowWind_InitInp%RootName, ErrStat, ErrMsg )
IF (ErrStat > ErrID_None) THEN
CALL WrScr( TRIM(ErrMsg) )
IF ( ErrStat >= AbortErrLev ) THEN
CALL DriverCleanup()
CALL ProgAbort( ErrMsg )
ELSEIF ( IfWDriver_Verbose >= 7_IntKi ) THEN
CALL WrScr(NewLine//' IfW_WriteHAWC returned: ErrStat: '//TRIM(Num2LStr(ErrStat)))
END IF
ELSE IF ( IfWDriver_Verbose >= 5_IntKi ) THEN
CALL WrScr(NewLine//'IfW_WriteHAWC CALL returned without errors.'//NewLine)
END IF
call CheckCallErr('IfW_WriteHAWC')
END IF


! Convert InflowWind file to Native Bladed format
IF (SettingsFlags%WrBladed) THEN
CALL IfW_WriteBladed( InflowWind_p%FlowField, InflowWind_InitInp%RootName, ErrStat, ErrMsg )
IF (ErrStat > ErrID_None) THEN
CALL WrScr( TRIM(ErrMsg) )
IF ( ErrStat >= AbortErrLev ) THEN
CALL DriverCleanup()
CALL ProgAbort( ErrMsg )
ELSEIF ( IfWDriver_Verbose >= 7_IntKi ) THEN
CALL WrScr(NewLine//' InflowWind_Convert2Bladed returned: ErrStat: '//TRIM(Num2LStr(ErrStat)))
END IF
ELSE IF ( IfWDriver_Verbose >= 5_IntKi ) THEN
CALL WrScr(NewLine//'InflowWind_Convert2Bladed CALL returned without errors.'//NewLine)
END IF
call CheckCallErr('IfW_WriteBladed')
END IF


IF (SettingsFlags%WrVTK) THEN
CALL IfW_WriteVTK( InflowWind_p%FlowField, InflowWind_InitInp%RootName, ErrStat, ErrMsg )
IF (ErrStat > ErrID_None) THEN
CALL WrScr( TRIM(ErrMsg) )
IF ( ErrStat >= AbortErrLev ) THEN
CALL DriverCleanup()
CALL ProgAbort( ErrMsg )
ELSEIF ( IfWDriver_Verbose >= 7_IntKi ) THEN
CALL WrScr(NewLine//' IfW_WriteVTK returned: ErrStat: '//TRIM(Num2LStr(ErrStat)))
END IF
ELSE IF ( IfWDriver_Verbose >= 5_IntKi ) THEN
CALL WrScr(NewLine//'IfW_WriteVTK CALL returned without errors.'//NewLine)
END IF

call CheckCallErr('IfW_WriteVTK')
END IF


IF (SettingsFlags%WrUniform) THEN
CALL IfW_WriteUniform( InflowWind_p%FlowField, InflowWind_InitInp%RootName, ErrStat, ErrMsg )
IF (ErrStat > ErrID_None) THEN
CALL WrScr( TRIM(ErrMsg) )
IF ( ErrStat >= AbortErrLev ) THEN
CALL DriverCleanup()
CALL ProgAbort( ErrMsg )
ELSEIF ( IfWDriver_Verbose >= 7_IntKi ) THEN
CALL WrScr(NewLine//' IfW_WriteUniform returned: ErrStat: '//TRIM(Num2LStr(ErrStat)))
END IF
ELSE IF ( IfWDriver_Verbose >= 5_IntKi ) THEN
CALL WrScr(NewLine//'IfW_WriteUniform CALL returned without errors.'//NewLine)
END IF
call CheckCallErr('IfW_WriteUniform')
END IF


IF (Settings%NOutWindXY>0) THEN
do i=1,Settings%NOutWindXY
CALL IfW_WriteXYslice( InflowWind_p%FlowField, InflowWind_InitInp%RootName, VTKsliceDir, Settings%OutWindZ(i), ErrStat, ErrMsg )
call CheckCallErr('IfW_WriteXYslice'//trim(Num2LStr(i)))
enddo
END IF


!FIXME: future developent
! IF (Settings%NOutWindXZ>0) THEN
! do i=1,Settings%NOutWindXZ
! CALL IfW_WriteXZslice( InflowWind_p%FlowField, InflowWind_InitInp%RootName, VTKsliceDir, Settings%OutWindY(i), ErrStat, ErrMsg )
! call CheckCallErr('IfW_WriteXZslice'//trim(Num2LStr(i)))
! enddo
! END IF


! IF (Settings%NOutWindYZ>0) THEN
! do i=1,Settings%NOutWindYZ
! CALL IfW_WriteYZslice( InflowWind_p%FlowField, InflowWind_InitInp%RootName, VTKsliceDir, Settings%OutWindX(i), ErrStat, ErrMsg )
! call CheckCallErr('IfW_WriteYZslice'//trim(Num2LStr(i)))
! enddo
! END IF


!--------------------------------------------------------------------------------------------------------------------------------
!-=-=- Other Setup -=-=-
!--------------------------------------------------------------------------------------------------------------------------------
Expand Down Expand Up @@ -942,6 +929,22 @@ SUBROUTINE DriverCleanup()

END SUBROUTINE DriverCleanup

subroutine CheckCallErr(RoutineName)
character(*), intent(in) :: RoutineName
if (ErrStat > ErrID_None) then
call WrScr( trim(ErrMsg) )
if ( ErrStat >= AbortErrLev ) then
call DriverCleanup()
call ProgAbort( ErrMsg )
elseif ( IfWDriver_Verbose >= 7_IntKi ) then
call WrScr(NewLine//' '//trim(RoutineName)//' returned: ErrStat: '//TRIM(Num2LStr(ErrStat)))
endif
elseif ( IfWDriver_Verbose >= 5_IntKi ) then
CALL WrScr(NewLine//trim(RoutineName)//' CALL returned without errors.'//NewLine)
endif
end subroutine CheckCallErr


END PROGRAM InflowWind_Driver


Expand Down
91 changes: 91 additions & 0 deletions modules/inflowwind/src/InflowWind_Driver_Registry.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
#----------------------------------------------------------------------------------------------------------------------------------
# Registry for IfW_Interp, creates MODULE IfW_Interp_Types
# Module IfW_Interp_Types contains all of the user-defined types needed in IfW_FF. It also contains copy, destroy, pack, and
# unpack routines associated with each defined data types.
#----------------------------------------------------------------------------------------------------------------------------------
# keyword <Module> <TypeName> <FieldType> <FieldName> <Dims> <Ctrl> <DNA ME> <DESCRIP> <UNITS>
#----------------------------------------------------------------------------------------------------------------------------------

include Registry_NWTC_Library.txt

#----------------------------------------------------------------------------------------------------------------------------------
typedef InflowWind_Driver OutputFile character(1024) Name - "" - "Filename for output from points read in from points file" -
typedef ^ ^ integer Unit - -1 - "Unit number for the output file for the Points file output" -
typedef ^ ^ logical Initialized - .false. - "Flag indicating that file has been initialized" -

# This contains flags to note if the settings were made. This same data structure is
# used both during the driver input file and the command line options.
#
# NOTE: The WindFileType is only set if it is given as a command line option. Otherwise
# it is handled internally by InflowWInd.
#
# NOTE: The wind direction is specified by the InflowWind input file.
#----------------------------------------------------------------------------------------------------------------------------------
typedef InflowWind_Driver IfWDriver_Flags logical DvrIptFile - .false. - "Was an input file name given on the command line?" -
typedef ^ ^ logical IfWIptFile - .false. - "Was an InflowWind input file requested?" -
typedef ^ ^ logical Summary - .false. - "create a summary at command line? (data extents in the wind file)" -
typedef ^ ^ logical SummaryFile - .false. - "create a summary file of the output?" -
typedef ^ ^ logical TStart - .false. - "specified a start time" -
typedef ^ ^ logical NumTimeSteps - .false. - "specified a number of timesteps to process" -
typedef ^ ^ logical NumTimeStepsDefault - .false. - "specified a 'DEFAULT' for number of timesteps to process" -
typedef ^ ^ logical DT - .false. - "specified a resolution in time" -
typedef ^ ^ logical DTDefault - .false. - "specified a 'DEFAULT' for the time resolution" -

typedef ^ ^ logical FFTcalc - .false. - "do an FFT" -

typedef ^ ^ logical WindGrid - .false. - "Requested output of wind data on a grid -- input file option only" -
typedef ^ ^ logical XRange - .false. - "specified a range of x -- command line option only -- stored as GridCtrCoord and GridDelta" -
typedef ^ ^ logical YRange - .false. - "specified a range of y -- command line option only -- stored as GridCtrCoord and GridDelta" -
typedef ^ ^ logical ZRange - .false. - "specified a range of z -- command line option only -- stored as GridCtrCoord and GridDelta" -
typedef ^ ^ logical Dx - .false. - "specified a resolution in x -- command line option only, 0.0 otherwise" -
typedef ^ ^ logical Dy - .false. - "speficied a resolution in y" -
typedef ^ ^ logical Dz - .false. - "specified a resolution in z" -

typedef ^ ^ logical PointsFile - .false. - "points filename to read in" -
typedef ^ ^ logical OutputAccel - .false. - "flag to calculate and output wind acceleration in addition to velocity" -

typedef ^ ^ logical Verbose - .false. - "Verbose error reporting" -
typedef ^ ^ logical VVerbose - .false. - "Very Verbose error reporting" -
typedef ^ ^ logical BoxExceedAllowF - .false. - "set flag to allow exceeding wind box boundaries for FF files (for diagnostic purposes)" -

typedef ^ ^ logical WrHAWC - .false. - "Requested file conversion to HAWC2 format?" -
typedef ^ ^ logical WrBladed - .false. - "Requested file conversion to Bladed format?" -
typedef ^ ^ logical WrVTK - .false. - "Requested file output as VTK?" -
typedef ^ ^ logical WrUniform - .false. - "Requested file output as Uniform wind format?" -

typedef ^ ^ logical XYslice - .false. - "Take XY slice at one elevation" -



# This contains all the settings (possible passed in arguments).
#----------------------------------------------------------------------------------------------------------------------------------
typedef InflowWind_Driver IfWDriver_Settings character(1024) DvrIptFileName - "" - "Driver input file name" -
typedef ^ ^ character(1024) IfWIptFileName - "" - "Filename of InflowWind input file to read (if no driver input file)" -
typedef ^ ^ character(1024) SummaryFileName - "" - "Filename for the summary information output" -

typedef ^ ^ character(1024) PointsFileName - "" - "Filename of points file to read in" -

typedef ^ ^ IntKi NumTimeSteps - 0 - "Number of timesteps" -
typedef ^ ^ DbKi DT - 0.0_DbKi - "resolution of time" s
typedef ^ ^ DbKi TStart - 0.0_DbKi - "range of time -- end time converted from TRange (command line option only)" s

typedef ^ ^ ReKi FFTcoord(1:3) - 0.0_ReKi - "(x,y,z) coordinate to do an FFT at" (m)

typedef ^ ^ ReKi GridDelta(1:3) - 0.0_ReKi - "(GridDx,GridDy,GridDz) -- grid point spacing" (m)
typedef ^ ^ IntKi GridN(1:3) - 1_IntKi - "(GridNx,GridNy,GridNz) -- number of grid points" -

typedef ^ ^ ReKi XRange(1:2) - 0.0_ReKi - "Range in the x-direction for the gridded data" (m)
typedef ^ ^ ReKi YRange(1:2) - 0.0_ReKi - "Range in the y-direction for the gridded data" (m)
typedef ^ ^ ReKi ZRange(1:2) - 0.0_ReKi - "Range in the z-direction for the gridded data" (m)

typedef ^ ^ ProgDesc ProgInfo - - - "Program info" -
typedef ^ ^ OutputFile WindGridOutput - - - "Wind grid file handling" -
typedef ^ ^ OutputFile FFTOutput - - - "FFT file handling" -
typedef ^ ^ OutputFile PointsVelOutput - - - "Points output velocity file handling" -

typedef ^ ^ IntKi NOutWindXY - 0 - "Number of XY planes for output <RootName>.XY<loc>.t<n>.vtk [0 to 9]" -
typedef ^ ^ ReKi OutWindZ : - - "Z coordinates of XY planes for output [1 to NOutWindXY] [unused for NOutWindXY=0]" (m)
typedef ^ ^ IntKi NOutWindXZ - 0 - "Number of YZ planes for output <RootName>.YZ<loc>.t<n>.vtk [0 to 9]" -
typedef ^ ^ ReKi OutWindY : - - "Y coordinates of YZ planes for output [1 to NOutWindYZ] [unused for NOutWindYZ=0]" (m)
typedef ^ ^ IntKi NOutWindYZ - 0 - "Number of YZ planes for output <RootName>.YZ<loc>.t<n>.vtk [0 to 9]" -
typedef ^ ^ ReKi OutWindX : - - "X coordinates of YZ planes for output [1 to NOutWindYZ] [unused for NOutWindYZ=0]" (m)
Loading