From 464b01ef69900f55b21ab43f551ba1abf8ca9f82 Mon Sep 17 00:00:00 2001 From: andrew-platt Date: Mon, 11 Nov 2024 17:42:41 -0700 Subject: [PATCH] IfW: add path handling for xyslice output (hardcoded for now) --- modules/inflowwind/src/InflowWind_Driver.f90 | 9 +++-- .../inflowwind/src/InflowWind_Driver_Subs.f90 | 29 +++++++------- modules/inflowwind/src/InflowWind_IO.f90 | 39 +++++++++++-------- 3 files changed, 43 insertions(+), 34 deletions(-) diff --git a/modules/inflowwind/src/InflowWind_Driver.f90 b/modules/inflowwind/src/InflowWind_Driver.f90 index ab7278f85..0a4413d02 100644 --- a/modules/inflowwind/src/InflowWind_Driver.f90 +++ b/modules/inflowwind/src/InflowWind_Driver.f90 @@ -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 @@ -466,7 +469,7 @@ PROGRAM InflowWind_Driver IF (Settings%NOutWindXY>0) THEN do i=1,Settings%NOutWindXY - CALL IfW_WriteXYslice( InflowWind_p%FlowField, InflowWind_InitInp%RootName, Settings%OutWindZ(i), ErrStat, ErrMsg ) + 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 @@ -474,7 +477,7 @@ PROGRAM InflowWind_Driver IF (Settings%NOutWindXZ>0) THEN do i=1,Settings%NOutWindXZ -! CALL IfW_WriteXZslice( InflowWind_p%FlowField, InflowWind_InitInp%RootName, Settings%OutWindY(i), ErrStat, ErrMsg ) +! 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 @@ -482,7 +485,7 @@ PROGRAM InflowWind_Driver IF (Settings%NOutWindYZ>0) THEN do i=1,Settings%NOutWindYZ -! CALL IfW_WriteYZslice( InflowWind_p%FlowField, InflowWind_InitInp%RootName, Settings%OutWindX(i), ErrStat, ErrMsg ) +! 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 diff --git a/modules/inflowwind/src/InflowWind_Driver_Subs.f90 b/modules/inflowwind/src/InflowWind_Driver_Subs.f90 index 6bc47eeae..041fb3096 100644 --- a/modules/inflowwind/src/InflowWind_Driver_Subs.f90 +++ b/modules/inflowwind/src/InflowWind_Driver_Subs.f90 @@ -2376,18 +2376,19 @@ subroutine IfW_WriteVTK(FF, FileRootName, ErrStat, ErrMsg) end subroutine IfW_WriteVTK -subroutine IfW_WriteXYslice(FF, FileRootName, XYslice_height, ErrStat, ErrMsg) - type(FlowFieldType), intent(in) :: FF !< Parameters - character(*), intent(in) :: FileRootName !< RootName for output files - real(ReKi), intent(in) :: XYslice_height - integer(IntKi), intent(out) :: ErrStat !< Error status of the operation - character(*), intent(out) :: ErrMsg !< Error message if ErrStat /= ErrID_None - - character(*), parameter :: RoutineName = "IfW_WriteXYslice" - type(Grid3DFieldType) :: G3D - integer(IntKi) :: unit - integer(IntKi) :: ErrStat2 - character(ErrMsgLen) :: ErrMsg2 +subroutine IfW_WriteXYslice(FF, FileRootName, vtk_dir, XYslice_height, ErrStat, ErrMsg) + type(FlowFieldType), intent(in ) :: FF !< Parameters + character(*), intent(in ) :: FileRootName !< RootName for output files + character(*), intent(in ) :: vtk_dir !< Directory for vtk slice outputs + real(ReKi), intent(in ) :: XYslice_height + integer(IntKi), intent( out) :: ErrStat !< Error status of the operation + character(*), intent( out) :: ErrMsg !< Error message if ErrStat /= ErrID_None + + character(*), parameter :: RoutineName = "IfW_WriteXYslice" + type(Grid3DFieldType) :: G3D + integer(IntKi) :: unit + integer(IntKi) :: ErrStat2 + character(ErrMsgLen) :: ErrMsg2 ErrStat = ErrID_None ErrMsg = "" @@ -2404,12 +2405,12 @@ subroutine IfW_WriteXYslice(FF, FileRootName, XYslice_height, ErrStat, ErrMsg) call Uniform_to_Grid3D(FF%Uniform, FF%VelInterpCubic, G3D, ErrStat2, ErrMsg2) call SetErrStat(ErrStat2, ErrMsg2, ErrStat, ErrMsg, RoutineName) if (ErrStat < AbortErrLev) then - call Grid3D_WriteVTKsliceXY(G3D, FileRootName, XYslice_height, unit, ErrStat2, ErrMsg2) + call Grid3D_WriteVTKsliceXY(G3D, FileRootName, vtk_dir, XYslice_height, unit, ErrStat2, ErrMsg2) call SetErrStat(ErrStat2, ErrMsg2, ErrStat, ErrMsg, RoutineName) end if case (Grid3D_FieldType) - call Grid3D_WriteVTKsliceXY(FF%Grid3D, FileRootName, XYslice_height, unit, ErrStat, ErrMsg) + call Grid3D_WriteVTKsliceXY(FF%Grid3D, FileRootName, vtk_dir, XYslice_height, unit, ErrStat, ErrMsg) case default ErrStat = ErrID_Warn diff --git a/modules/inflowwind/src/InflowWind_IO.f90 b/modules/inflowwind/src/InflowWind_IO.f90 index 8b813628b..4c30d9d2e 100644 --- a/modules/inflowwind/src/InflowWind_IO.f90 +++ b/modules/inflowwind/src/InflowWind_IO.f90 @@ -2945,23 +2945,23 @@ subroutine Grid3D_WriteHAWC(G3D, FileRootName, unit, ErrStat, ErrMsg) end subroutine Grid3D_WriteHAWC -subroutine Grid3D_WriteVTKsliceXY(G3D, FileRootName, XYslice_height, unit, ErrStat, ErrMsg) - - type(Grid3DFieldType), intent(in) :: G3D !< Parameters - character(*), intent(in) :: FileRootName !< RootName for output files - real(ReKi), intent(in) :: XYslice_height - integer(IntKi), intent(in) :: unit !< Error status of the operation - integer(IntKi), intent(out) :: ErrStat !< Error status of the operation - character(*), intent(out) :: ErrMsg !< Error message if ErrStat /= ErrID_None +!> This subroutine writes a VTK slice in the XY plane at a designated height (rounds to nearest point) +!! This feature is mostly useful for testing when a grid is needed for comparison elsewhere +subroutine Grid3D_WriteVTKsliceXY(G3D, FileRootName, vtk_dir, XYslice_height, unit, ErrStat, ErrMsg) + type(Grid3DFieldType), intent(in ) :: G3D !< Parameters + character(*), intent(in ) :: FileRootName !< RootName for output files + character(*), intent(in ) :: vtk_dir !< directory for vtk file for output files + real(ReKi), intent(in ) :: XYslice_height + integer(IntKi), intent(in ) :: unit !< Error status of the operation + integer(IntKi), intent( out) :: ErrStat !< Error status of the operation + character(*), intent( out) :: ErrMsg !< Error message if ErrStat /= ErrID_None character(*), parameter :: RoutineName = 'Grid3D_WriteVTKsliceXY' character(1024) :: RootPathName character(1024) :: FileName character(3) :: ht_str - integer :: it !< time index for slice - integer :: ix - integer :: iy - integer :: iz + character(8) :: t_str, t_fmt + integer :: it, ix, iy, iz, twidth real(ReKi) :: time !< time for this slice real(ReKi) :: ht !< nearest grid slice elevation integer(IntKi) :: ErrStat2 @@ -2971,13 +2971,17 @@ subroutine Grid3D_WriteVTKsliceXY(G3D, FileRootName, XYslice_height, unit, ErrSt ErrMsg = "" call GetPath(FileRootName, RootPathName) - RootPathName = trim(RootPathName)//PathSep//"vtk" + RootPathName = trim(RootPathName)//PathSep//vtk_dir call MkDir(trim(RootPathName)) ! make this directory if it doesn't already exist ! get indices for this slice iz = nint((G3D%GridBase + XYslice_height)*G3D%InvDZ) ht = real(iz,ReKi) / G3D%InvDZ + G3D%GridBase ! nearest height index - write(ht_str,'(i3)') nint(ht) + write(ht_str,'(i0.3)') nint(ht) + + ! get width of string for time + twidth=ceiling(log10(real(G3D%NSteps))) + t_fmt='(i0.'//trim(Num2LStr(twidth))//')' ! check for errors in slice height if (iz <= 0_IntKi .or. iz > G3D%NZGrids) then @@ -2987,11 +2991,13 @@ subroutine Grid3D_WriteVTKsliceXY(G3D, FileRootName, XYslice_height, unit, ErrSt ! Loop through time steps do it = 1, G3D%NSteps - time = real(it - 1, ReKi)*G3D%DTime + ! time string + write(t_str,t_fmt) it + ! Create the output vtk file with naming /vtk/DisYZ.t.vtk - FileName = trim(RootPathName)//PathSep//"DisXY.Z"//ht_str//".t"//trim(num2lstr(it))//".vtp" + FileName = trim(RootPathName)//PathSep//"DisXY.Z"//ht_str//".t"//trim(t_str)//".vtp" ! see WrVTK_SP_header call OpenFOutFile(unit, TRIM(FileName), ErrStat2, ErrMsg2) @@ -3019,7 +3025,6 @@ subroutine Grid3D_WriteVTKsliceXY(G3D, FileRootName, XYslice_height, unit, ErrSt close (unit) enddo - end subroutine Grid3D_WriteVTKsliceXY end module InflowWind_IO