Skip to content

Commit

Permalink
Merge pull request #12 from ebranlard/f/ff-openmp-vtk
Browse files Browse the repository at this point in the history
F/ff openmp vtk
  • Loading branch information
jjonkman committed Dec 8, 2020
2 parents 80d53e7 + 0e4d1d2 commit 7f8bf79
Show file tree
Hide file tree
Showing 6 changed files with 74 additions and 12 deletions.
8 changes: 7 additions & 1 deletion glue-codes/fast-farm/src/FAST_Farm.f90
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,13 @@ PROGRAM FAST_Farm
t = 0

InputFileName = "" ! make sure we don't think this is a "default" inputFileName if not specified on command line
CALL CheckArgs( InputFileName, Flag=FlagArg ) ! if ErrStat /= ErrID_None, we'll ignore and deal with the problem when we try to read the input file
CALL CheckArgs( InputFileName, ErrStat=ErrStat, Flag=FlagArg )

if (ErrStat/=0) then
call ProgAbort('', TrapErrors=.FALSE., TimeWait=3._ReKi )
else if ( len( trim(FlagArg) ) > 0 ) then ! Any other flag (-v,-h) end normally
call NormStop()
endif

CALL FAST_ProgStart( Farm_Ver ) ! put this after CheckArgs because CheckArgs assumes we haven't called this routine, yet.

Expand Down
29 changes: 23 additions & 6 deletions modules/awae/src/AWAE.f90
Original file line number Diff line number Diff line change
Expand Up @@ -693,6 +693,7 @@ subroutine AWAE_Init( InitInp, u, p, x, xd, z, OtherState, y, m, Interval, InitO


! Local variables
character(1024) :: rootDir, baseName, OutFileVTKDir ! Simulation root dir, basename for outputs
integer(IntKi) :: i,j,nt ! loop counter
integer(IntKi) :: maxN_wake
real(ReKi) :: gridLoc ! Location of requested output slice in grid coordinates [0,sz-1]
Expand All @@ -718,6 +719,7 @@ subroutine AWAE_Init( InitInp, u, p, x, xd, z, OtherState, y, m, Interval, InitO




! Validate the initialization inputs
call ValidateInitInputData( InitInp%InputFileData, ErrStat2, ErrMsg2 )
call SetErrStat( ErrStat2, ErrMsg2, errStat, errMsg, RoutineName )
Expand Down Expand Up @@ -780,6 +782,16 @@ subroutine AWAE_Init( InitInp, u, p, x, xd, z, OtherState, y, m, Interval, InitO
p%OutDisWindX = InitInp%InputFileData%OutDisWindX
p%OutDisWindY = InitInp%InputFileData%OutDisWindY

! --- Vtk Outputs
call GetPath( p%OutFileRoot, rootDir, baseName )
OutFileVTKDir = trim(rootDir) // 'vtk_ff' ! Directory for VTK outputs
p%OutFileVTKRoot = trim(rootDir) // 'vtk_ff' // PathSep // trim(baseName) ! Basename for VTK files
p%VTK_tWidth = CEILING( log10( real(p%NumDT, ReKi)/real(p%WrDisSkp1, ReKi) ) + 1) ! Length for time stamp
if (p%WrDisWind .or. p%NOutDisWindXY>0 .or. p%NOutDisWindYZ>0 .or. p%NOutDisWindXZ>0) then
call MKDIR(OutFileVTKDir) ! creating output directory
end if


allocate( p%r(0:p%NumRadii-1),stat=errStat2)
if (errStat2 /= 0) then
call SetErrStat ( ErrID_Fatal, 'Could not allocate memory for p%r.', errStat, errMsg, RoutineName )
Expand Down Expand Up @@ -1346,6 +1358,7 @@ subroutine AWAE_CalcOutput( t, u, p, x, xd, z, OtherState, y, m, errStat, errMsg


integer, parameter :: indx = 1
character(p%VTK_tWidth) :: Tstr ! string for current VTK write-out step (padded with zeros)
integer(intKi) :: i, j, k
integer(intKi) :: errStat2
character(ErrMsgLen) :: errMsg2
Expand Down Expand Up @@ -1380,20 +1393,24 @@ subroutine AWAE_CalcOutput( t, u, p, x, xd, z, OtherState, y, m, errStat, errMsg
end if

if (mod(n,p%WrDisSkp1) == 0) then

if ( p%WrDisWind ) then
call WriteDisWindFiles( n, p%WrDisSkp1, p, y, m, ErrStat2, ErrMsg2 )
end if

! TimeStamp
write(Tstr, '(i' // trim(Num2LStr(p%VTK_tWidth)) //'.'// trim(Num2LStr(p%VTK_tWidth)) // ')') n/p%WrDisSkp1 ! TODO use n instead..

! XY plane slices
do k = 1,p%NOutDisWindXY

call ExtractSlice( XYSlice, p%OutDisWindZ(k), p%Z0_low, p%nZ_low, p%nX_low, p%nY_low, p%dZ_low, m%Vdist_low, m%outVizXYPlane(:,:,:,1))
! Create the output vtk file with naming <WindFilePath>/Low/DisXY<k>.t<n/p%WrDisSkp1>.vtk
FileName = trim(p%OutFileRoot)//".Low.DisXY"//trim(num2lstr(k))//".t"//trim(num2lstr(n/p%WrDisSkp1))//".vtk"
FileName = trim(p%OutFileVTKRoot)//".Low.DisXY"//trim(num2lstr(k))//"."//trim(Tstr)//".vtk"
call WrVTK_SP_header( FileName, "Low resolution, disturbed wind of XY Slice at time = "//trim(num2lstr(t))//" seconds.", Un, ErrStat2, ErrMsg2 )
call SetErrStat(ErrStat2, ErrMsg2, ErrStat, ErrMsg, RoutineName)
if (ErrStat >= AbortErrLev) return
call WrVTK_SP_vectors3D( Un, "DisXY", (/p%nX_low,p%nY_low,1_IntKi/), (/p%X0_low,p%Y0_low,p%OutDisWindZ(k)/), (/p%dX_low,p%dY_low,p%dZ_low/), m%outVizXYPlane, ErrStat2, ErrMsg2 )
call WrVTK_SP_vectors3D( Un, "Velocity", (/p%nX_low,p%nY_low,1_IntKi/), (/p%X0_low,p%Y0_low,p%OutDisWindZ(k)/), (/p%dX_low,p%dY_low,p%dZ_low/), m%outVizXYPlane, ErrStat2, ErrMsg2 )
call SetErrStat(ErrStat2, ErrMsg2, ErrStat, ErrMsg, RoutineName)
if (ErrStat >= AbortErrLev) return
end do
Expand All @@ -1403,11 +1420,11 @@ subroutine AWAE_CalcOutput( t, u, p, x, xd, z, OtherState, y, m, errStat, errMsg
do k = 1,p%NOutDisWindYZ
call ExtractSlice( YZSlice, p%OutDisWindX(k), p%X0_low, p%nX_low, p%nY_low, p%nZ_low, p%dX_low, m%Vdist_low, m%outVizYZPlane(:,:,:,1))
! Create the output vtk file with naming <WindFilePath>/Low/DisYZ<k>.t<n/p%WrDisSkp1>.vtk
FileName = trim(p%OutFileRoot)//".Low.DisYZ"//trim(num2lstr(k))//".t"//trim(num2lstr(n/p%WrDisSkp1))//".vtk"
FileName = trim(p%OutFileVTKRoot)//".Low.DisYZ"//trim(num2lstr(k))//"."//trim(Tstr)//".vtk"
call WrVTK_SP_header( FileName, "Low resolution, disturbed wind of YZ Slice at time = "//trim(num2lstr(t))//" seconds.", Un, ErrStat2, ErrMsg2 )
call SetErrStat(ErrStat2, ErrMsg2, ErrStat, ErrMsg, RoutineName)
if (ErrStat >= AbortErrLev) return
call WrVTK_SP_vectors3D( Un, "DisYZ", (/1,p%nY_low,p%nZ_low/), (/p%OutDisWindX(k),p%Y0_low,p%Z0_low/), (/p%dX_low,p%dY_low,p%dZ_low/), m%outVizYZPlane, ErrStat2, ErrMsg2 )
call WrVTK_SP_vectors3D( Un, "Velocity", (/1,p%nY_low,p%nZ_low/), (/p%OutDisWindX(k),p%Y0_low,p%Z0_low/), (/p%dX_low,p%dY_low,p%dZ_low/), m%outVizYZPlane, ErrStat2, ErrMsg2 )
call SetErrStat(ErrStat2, ErrMsg2, ErrStat, ErrMsg, RoutineName)
if (ErrStat >= AbortErrLev) return
end do
Expand All @@ -1416,11 +1433,11 @@ subroutine AWAE_CalcOutput( t, u, p, x, xd, z, OtherState, y, m, errStat, errMsg
do k = 1,p%NOutDisWindXZ
call ExtractSlice( XZSlice, p%OutDisWindY(k), p%Y0_low, p%nY_low, p%nX_low, p%nZ_low, p%dY_low, m%Vdist_low, m%outVizXZPlane(:,:,:,1))
! Create the output vtk file with naming <WindFilePath>/Low/DisXZ<k>.t<n/p%WrDisSkp1>.vtk
FileName = trim(p%OutFileRoot)//".Low.DisXZ"//trim(num2lstr(k))//".t"//trim(num2lstr(n/p%WrDisSkp1))//".vtk"
FileName = trim(p%OutFileRoot)//".Low.DisXZ"//trim(num2lstr(k))//"."//trim(Tstr)//".vtk"
call WrVTK_SP_header( FileName, "Low resolution, disturbed wind of XZ Slice at time = "//trim(num2lstr(t))//" seconds.", Un, ErrStat2, ErrMsg2 )
call SetErrStat(ErrStat2, ErrMsg2, ErrStat, ErrMsg, RoutineName)
if (ErrStat >= AbortErrLev) return
call WrVTK_SP_vectors3D( Un, "DisXZ", (/p%nX_low,1,p%nZ_low/), (/p%X0_low,p%OutDisWindY(k),p%Z0_low/), (/p%dX_low,p%dY_low,p%dZ_low/), m%outVizXZPlane, ErrStat2, ErrMsg2 )
call WrVTK_SP_vectors3D( Un, "Velocity", (/p%nX_low,1,p%nZ_low/), (/p%X0_low,p%OutDisWindY(k),p%Z0_low/), (/p%dX_low,p%dY_low,p%dZ_low/), m%outVizXZPlane, ErrStat2, ErrMsg2 )
call SetErrStat(ErrStat2, ErrMsg2, ErrStat, ErrMsg, RoutineName)
if (ErrStat >= AbortErrLev) return
end do
Expand Down
13 changes: 9 additions & 4 deletions modules/awae/src/AWAE_IO.f90
Original file line number Diff line number Diff line change
Expand Up @@ -98,25 +98,30 @@ subroutine WriteDisWindFiles( n, WrDisSkp1, p, y, m, errStat, errMsg )
CHARACTER(*), PARAMETER :: RoutineName = 'WriteDisWindFiles'
INTEGER(IntKi) :: nt, n_out
REAL(ReKi) :: t_out
character(p%VTK_tWidth) :: Tstr ! string for current VTK write-out step (padded with zeros)

n_out = n/WrDisSkp1
t_out = n*p%DT_low
FileName = trim(p%OutFileRoot)//".Low.Dis.t"//trim(num2lstr(n_out))//".vtk"

! TimeStamp
write(Tstr, '(i' // trim(Num2LStr(p%VTK_tWidth)) //'.'// trim(Num2LStr(p%VTK_tWidth)) // ')') n_out ! TODO use n instead..

FileName = trim(p%OutFileVTKRoot)//".Low.Dis."//trim(Tstr)//".vtk"
call WrVTK_SP_header( FileName, "Low resolution disturbed wind for time = "//trim(num2lstr(t_out))//" seconds.", Un, errStat2, errMsg2 )
call SetErrStat(errStat2, errMsg2, ErrStat, ErrMsg, RoutineName)
if (ErrStat >= AbortErrLev) return
call WrVTK_SP_vectors3D( Un, "LowDis", (/p%nX_low,p%nY_low,p%nZ_low/), (/p%X0_low,p%Y0_low,p%Z0_low/), (/p%dX_low,p%dY_low,p%dZ_low/), m%Vdist_low, errStat2, errMsg2 )
call WrVTK_SP_vectors3D( Un, "Velocity", (/p%nX_low,p%nY_low,p%nZ_low/), (/p%X0_low,p%Y0_low,p%Z0_low/), (/p%dX_low,p%dY_low,p%dZ_low/), m%Vdist_low, errStat2, errMsg2 )
call SetErrStat(errStat2, errMsg2, ErrStat, ErrMsg, RoutineName)
if (ErrStat >= AbortErrLev) return

do nt= 1,p%NumTurbines
! We are only writing out the first of the high res data for a given low res time step

FileName = trim(p%OutFileRoot)//".HighT"//trim(num2lstr(nt))//".Dis.t"//trim(num2lstr(n_out))//".vtk"
FileName = trim(p%OutFileVTKRoot)//".HighT"//trim(num2lstr(nt))//".Dis."//trim(Tstr)//".vtk"
call WrVTK_SP_header( FileName, "High resolution disturbed wind for time = "//trim(num2lstr(t_out))//" seconds.", Un, errStat2, errMsg2 )
call SetErrStat(errStat2, errMsg2, ErrStat, ErrMsg, RoutineName)
if (ErrStat >= AbortErrLev) return
call WrVTK_SP_vectors3D( Un, "HighDis", (/p%nX_high,p%nY_high,p%nZ_high/), (/p%X0_high(nt),p%Y0_high(nt),p%Z0_high(nt)/), (/p%dX_high(nt),p%dY_high(nt),p%dZ_high(nt)/), y%Vdist_high(nt)%data(:,:,:,:,0), errStat2, errMsg2 )
call WrVTK_SP_vectors3D( Un, "Velocity", (/p%nX_high,p%nY_high,p%nZ_high/), (/p%X0_high(nt),p%Y0_high(nt),p%Z0_high(nt)/), (/p%dX_high(nt),p%dY_high(nt),p%dZ_high(nt)/), y%Vdist_high(nt)%data(:,:,:,:,0), errStat2, errMsg2 )
call SetErrStat(ErrStat2, errMsg2, ErrStat, ErrMsg, RoutineName)
if (ErrStat >= AbortErrLev) return

Expand Down
4 changes: 3 additions & 1 deletion modules/awae/src/AWAE_Registry.txt
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,9 @@ typedef ^ ParameterType IntKi NOutDisWindYZ - - - "Number
typedef ^ ParameterType ReKi OutDisWindX {:} - - "X coordinates of YZ planes for output of disturbed wind data across the low-resolution domain [1 to NOutDisWindYZ]" meters
typedef ^ ParameterType IntKi NOutDisWindXZ - - - "Number of XZ planes for output of disturbed wind data across the low-resolution domain to <WindFilePath>/Low/DisXZ.<n_out>.t<n>.vtk [0 to 9]" -
typedef ^ ParameterType ReKi OutDisWindY {:} - - "Y coordinates of XZ planes for output of disturbed wind data across the low-resolution domain [1 to NOutDisWindXZ]" meters
typedef ^ ParameterType CHARACTER(1024) OutFileRoot - - - "The root name derived from the primary FAST.Farm input file" -
typedef ^ ParameterType CHARACTER(1024) OutFileRoot - - - "The root name derived from the primary FAST.Farm input file" -
typedef ^ ParameterType CHARACTER(1024) OutFileVTKRoot - - - "The root name for VTK outputs" -
typedef ^ ParameterType IntKi VTK_tWidth - - - "Number of characters for VTK timestamp outputs" -
#typedef ^ ParameterType OutParmType OutParam {:} - - "Names and units (and other characteristics) of all requested output parameters" -


Expand Down
18 changes: 18 additions & 0 deletions modules/awae/src/AWAE_Types.f90
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,8 @@ MODULE AWAE_Types
INTEGER(IntKi) :: NOutDisWindXZ !< Number of XZ planes for output of disturbed wind data across the low-resolution domain to <WindFilePath>/Low/DisXZ.<n_out>.t<n>.vtk [0 to 9] [-]
REAL(ReKi) , DIMENSION(:), ALLOCATABLE :: OutDisWindY !< Y coordinates of XZ planes for output of disturbed wind data across the low-resolution domain [1 to NOutDisWindXZ] [meters]
CHARACTER(1024) :: OutFileRoot !< The root name derived from the primary FAST.Farm input file [-]
CHARACTER(1024) :: OutFileVTKRoot !< The root name for VTK outputs [-]
INTEGER(IntKi) :: VTK_tWidth !< Number of characters for VTK timestamp outputs [-]
END TYPE AWAE_ParameterType
! =======================
! ========= AWAE_OutputType =======
Expand Down Expand Up @@ -5456,6 +5458,8 @@ SUBROUTINE AWAE_CopyParam( SrcParamData, DstParamData, CtrlCode, ErrStat, ErrMsg
DstParamData%OutDisWindY = SrcParamData%OutDisWindY
ENDIF
DstParamData%OutFileRoot = SrcParamData%OutFileRoot
DstParamData%OutFileVTKRoot = SrcParamData%OutFileVTKRoot
DstParamData%VTK_tWidth = SrcParamData%VTK_tWidth
END SUBROUTINE AWAE_CopyParam

SUBROUTINE AWAE_DestroyParam( ParamData, ErrStat, ErrMsg )
Expand Down Expand Up @@ -5672,6 +5676,8 @@ SUBROUTINE AWAE_PackParam( ReKiBuf, DbKiBuf, IntKiBuf, Indata, ErrStat, ErrMsg,
Re_BufSz = Re_BufSz + SIZE(InData%OutDisWindY) ! OutDisWindY
END IF
Int_BufSz = Int_BufSz + 1*LEN(InData%OutFileRoot) ! OutFileRoot
Int_BufSz = Int_BufSz + 1*LEN(InData%OutFileVTKRoot) ! OutFileVTKRoot
Int_BufSz = Int_BufSz + 1 ! VTK_tWidth
IF ( Re_BufSz .GT. 0 ) THEN
ALLOCATE( ReKiBuf( Re_BufSz ), STAT=ErrStat2 )
IF (ErrStat2 /= 0) THEN
Expand Down Expand Up @@ -6029,6 +6035,12 @@ SUBROUTINE AWAE_PackParam( ReKiBuf, DbKiBuf, IntKiBuf, Indata, ErrStat, ErrMsg,
IntKiBuf(Int_Xferred) = ICHAR(InData%OutFileRoot(I:I), IntKi)
Int_Xferred = Int_Xferred + 1
END DO ! I
DO I = 1, LEN(InData%OutFileVTKRoot)
IntKiBuf(Int_Xferred) = ICHAR(InData%OutFileVTKRoot(I:I), IntKi)
Int_Xferred = Int_Xferred + 1
END DO ! I
IntKiBuf(Int_Xferred) = InData%VTK_tWidth
Int_Xferred = Int_Xferred + 1
END SUBROUTINE AWAE_PackParam

SUBROUTINE AWAE_UnPackParam( ReKiBuf, DbKiBuf, IntKiBuf, Outdata, ErrStat, ErrMsg )
Expand Down Expand Up @@ -6446,6 +6458,12 @@ SUBROUTINE AWAE_UnPackParam( ReKiBuf, DbKiBuf, IntKiBuf, Outdata, ErrStat, ErrMs
OutData%OutFileRoot(I:I) = CHAR(IntKiBuf(Int_Xferred))
Int_Xferred = Int_Xferred + 1
END DO ! I
DO I = 1, LEN(OutData%OutFileVTKRoot)
OutData%OutFileVTKRoot(I:I) = CHAR(IntKiBuf(Int_Xferred))
Int_Xferred = Int_Xferred + 1
END DO ! I
OutData%VTK_tWidth = IntKiBuf(Int_Xferred)
Int_Xferred = Int_Xferred + 1
END SUBROUTINE AWAE_UnPackParam

SUBROUTINE AWAE_CopyOutput( SrcOutputData, DstOutputData, CtrlCode, ErrStat, ErrMsg )
Expand Down
14 changes: 14 additions & 0 deletions modules/nwtc-library/src/NWTC_IO.f90
Original file line number Diff line number Diff line change
Expand Up @@ -2249,6 +2249,9 @@ END SUBROUTINE DLLTypeUnPack
!=======================================================================
!>
SUBROUTINE DispCompileRuntimeInfo()
#ifdef _OPENMP
USE OMP_LIB
#endif
#ifdef HAS_FORTRAN2008_FEATURES
USE iso_fortran_env, ONLY: compiler_version
#endif
Expand Down Expand Up @@ -2279,6 +2282,17 @@ SUBROUTINE DispCompileRuntimeInfo()
call wrscr(' - Compiler: '//trim(compiler_version_str))
CALL WrScr(' - Architecture: '//trim(architecture))
CALL WrScr(' - Precision: '//trim(compiled_precision))
#ifdef _OPENMP
!$OMP PARALLEL default(shared)
if (omp_get_thread_num()==0) then
call WrScr(' - OpenMP: Yes, number of threads: '//trim(Num2LStr(omp_get_num_threads()))//'/'//trim(Num2LStr(omp_get_max_threads())))
else
call WrScr(' - OpenMP: Yes, number of threads cannot be retrieved.') ! will likely never happen
endif
!$OMP END PARALLEL
#else
call WrScr(' - OpenMP: No')
#endif
CALL WrScr(' - Date: '//__DATE__)
CALL WrScr(' - Time: '//__TIME__)
! call wrscr(' - Options: '//trim(compiler_options()))
Expand Down

0 comments on commit 7f8bf79

Please sign in to comment.