From 8fa850c2f5f5d2ed3dd60b995b82831bb7f78ff3 Mon Sep 17 00:00:00 2001 From: cflag Date: Tue, 24 Jun 2025 12:49:05 +0200 Subject: [PATCH 1/6] Remove xdmf and add a vtk.xml file for ADIOS2 visualization. The ADIOS2 output also contains a warp field allowing to rescale the domain in case of streching. This extra field is present inside each instantaneous snapshot --- src/visu.f90 | 87 ++++++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 81 insertions(+), 6 deletions(-) diff --git a/src/visu.f90 b/src/visu.f90 index 0b68e722..780d9ab1 100644 --- a/src/visu.f90 +++ b/src/visu.f90 @@ -12,6 +12,8 @@ module visu ! True to activate the XDMF output logical, save :: use_xdmf = .true. + ! True to activate vtk.xml output + logical, save :: use_vtkxml = .false. ! True to use the new enumeration logical, save :: filenamedigits = .false. ! output2D is defined in the input.i3d file @@ -20,7 +22,10 @@ module visu ! 2 for 2D output with Y average ! 3 for 2D output with Z average integer, save :: output2D - integer :: ioxdmf + integer, save :: ioxdmf +#ifdef ADIOS2 + integer, save :: ioxml +#endif character(len=9) :: ifilenameformat = '(I3.3)' real, save :: tstart, tend @@ -40,7 +45,7 @@ subroutine visu_init() use MPI use param, only : ilmn, iscalar, ilast, ifirst, ioutput, istret use variables, only : numscalar, prec, nvisu - use param, only : dx, dy, dz + use param, only : dx, dy, dz, istret use decomp_2d_io, only : decomp_2d_init_io, decomp_2d_open_io, decomp_2d_append_mode use decomp_2d_io, only : decomp_2d_register_variable @@ -85,6 +90,12 @@ subroutine visu_init() stop endif + ! Use vtk.xml instead of xdmf when ADIOS2 is available +#ifdef ADIOS2 + use_xdmf = .false. + use_vtkxml = .true. +#endif + call decomp_2d_init_io(io_name) !! Register variables @@ -102,6 +113,12 @@ subroutine visu_init() call decomp_2d_register_variable(io_name, scname, 1, 0, output2D, mytype) enddo endif + +#ifdef ADIOS2 + ! The file vtk.xml is sufficient when the mesh is regular + ! In case of streching, the Paraview filter "warp_by_scalar" should be used + if (istret /= 0) call decomp_2d_register_variable(io_name, "warp", 1, 0, output2D, mytype) +#endif end subroutine visu_init @@ -113,8 +130,7 @@ end subroutine visu_init subroutine visu_ready () use decomp_2d_io, only : decomp_2d_open_io, decomp_2d_append_mode, decomp_2d_write_mode, gen_iodir_name - - use param, only : irestart + use param, only : irestart, dx, dy, dz implicit none @@ -147,6 +163,17 @@ subroutine visu_ready () end if call decomp_2d_open_io(io_name, "data", mode) + + ! Write the vtk.xml file + open(newunit=ioxml, file="./data.bp4/vtk.xml") + + ! Header for a uniform grid + write (ioxml, *) '' + write (ioxml, *) '' + ! Extent should be in reversed order + write (ioxml, *) ' ' + write (ioxml, *) ' ' + write (ioxml, *) ' ' #endif end subroutine visu_ready @@ -161,6 +188,9 @@ subroutine visu_finalise() implicit none + ! Write vtk.xml footer + if (use_vtkxml) call write_vtkxml_footer() + #ifdef ADIOS2 call decomp_2d_close_io(io_name, "data") #endif @@ -174,12 +204,12 @@ subroutine write_snapshot(rho1, ux1, uy1, uz1, pp3, phi1, ep1, itime, num) use decomp_2d_io, only : decomp_2d_start_io - use param, only : nrhotime, ilmn, iscalar, ioutput, irestart + use param, only : nrhotime, ilmn, iscalar, ioutput, irestart, istret, dy use variables, only : sx, cifip6, cisip6, ciwip6, cifx6, cisx6, ciwx6 use variables, only : sy, cifip6y, cisip6y, ciwip6y, cify6, cisy6, ciwy6 use variables, only : sz, cifip6z, cisip6z, ciwip6z, cifz6, cisz6, ciwz6 - use variables, only : numscalar + use variables, only : numscalar, yp use var, only : pp1, ta1, di1, nxmsize use var, only : pp2, ppi2, dip2, ph2, nymsize @@ -187,6 +217,9 @@ subroutine write_snapshot(rho1, ux1, uy1, uz1, pp3, phi1, ep1, itime, num) use var, only : npress use tools, only : rescale_pressure +#ifdef ADIOS2 + use utilities, only : gen_filename +#endif implicit none @@ -206,6 +239,9 @@ subroutine write_snapshot(rho1, ux1, uy1, uz1, pp3, phi1, ep1, itime, num) integer :: mode logical, save :: outloc_init = .false. logical :: dir_exists +#ifdef ADIOS2 + integer :: i, j, k, jglob +#endif ! Update log file if (nrank.eq.0) then @@ -270,6 +306,20 @@ subroutine write_snapshot(rho1, ux1, uy1, uz1, pp3, phi1, ep1, itime, num) enddo endif +#ifdef ADIOS2 + if (istret /= 0) then + do k = 1, xsize(3) + do j = 1, xsize(2) + jglob = j + xstart(2) - 1 + do i = 1, xsize(1) + ta1(i, j, k) = yp(jglob) - (jglob - 1) * dy + end do + end do + end do + call write_field(ta1, ".", "warp", num, .true., flush=.true.) + end if +#endif + end subroutine write_snapshot subroutine end_snapshot(itime, num) @@ -477,6 +527,25 @@ subroutine write_xdmf_footer() end subroutine write_xdmf_footer + ! + ! Write the footer of the vtk.xml file at the end of the simulation + ! + subroutine write_vtkxml_footer() + + implicit none + +#ifdef ADIOS2 + if (nrank.eq.0) then + write (ioxml, *) ' ' + write (ioxml, *) ' ' + write (ioxml, *) ' ' + write (ioxml, *) '' + close(ioxml) + endif +#endif + + end subroutine write_vtkxml_footer + ! ! Write the given field for visualization ! Adapted from https://github.com/fschuch/Xcompact3d/blob/master/src/visu.f90 @@ -562,6 +631,12 @@ subroutine write_field(f1, pathname, filename, num, skip_ibm, flush) endif endif + if (use_vtkxml) then + if (nrank.eq.0 .and. num.eq.0) then + write (ioxml, *) ' ' + end if + end if + if ((iibm == 2) .and. .not.present(skip_ibm)) then ta1(:,:,:) = (one - ep1(:,:,:)) * f1(:,:,:) else From bec9be52befb727e32183f6e71dda178416c1ae5 Mon Sep 17 00:00:00 2001 From: cflag Date: Tue, 24 Jun 2025 12:52:31 +0200 Subject: [PATCH 2/6] Only rank 0 should open and write to the vtk.xml file --- src/visu.f90 | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/src/visu.f90 b/src/visu.f90 index 780d9ab1..cbd2a1d9 100644 --- a/src/visu.f90 +++ b/src/visu.f90 @@ -165,15 +165,17 @@ subroutine visu_ready () call decomp_2d_open_io(io_name, "data", mode) ! Write the vtk.xml file - open(newunit=ioxml, file="./data.bp4/vtk.xml") - - ! Header for a uniform grid - write (ioxml, *) '' - write (ioxml, *) '' - ! Extent should be in reversed order - write (ioxml, *) ' ' - write (ioxml, *) ' ' - write (ioxml, *) ' ' + if (nrank.eq.0) then + open(newunit=ioxml, file="./data.bp4/vtk.xml") + + ! Header for a uniform grid + write (ioxml, *) '' + write (ioxml, *) '' + ! Extent should be in reversed order + write (ioxml, *) ' ' + write (ioxml, *) ' ' + write (ioxml, *) ' ' + end if #endif end subroutine visu_ready From d9627c84603ffef483c8b69ebdb47a27a3b015dc Mon Sep 17 00:00:00 2001 From: cflag Date: Tue, 24 Jun 2025 12:53:33 +0200 Subject: [PATCH 3/6] Minor cleaning --- src/visu.f90 | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/visu.f90 b/src/visu.f90 index cbd2a1d9..a15c4cce 100644 --- a/src/visu.f90 +++ b/src/visu.f90 @@ -219,9 +219,6 @@ subroutine write_snapshot(rho1, ux1, uy1, uz1, pp3, phi1, ep1, itime, num) use var, only : npress use tools, only : rescale_pressure -#ifdef ADIOS2 - use utilities, only : gen_filename -#endif implicit none From 77ae9fb2f5a7e854739621b2d7c01a38ed83526e Mon Sep 17 00:00:00 2001 From: cflag Date: Tue, 24 Jun 2025 13:04:53 +0200 Subject: [PATCH 4/6] Fix build without ADIOS2 --- src/visu.f90 | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/visu.f90 b/src/visu.f90 index a15c4cce..ba8a8f14 100644 --- a/src/visu.f90 +++ b/src/visu.f90 @@ -23,9 +23,7 @@ module visu ! 3 for 2D output with Z average integer, save :: output2D integer, save :: ioxdmf -#ifdef ADIOS2 integer, save :: ioxml -#endif character(len=9) :: ifilenameformat = '(I3.3)' real, save :: tstart, tend From b989fa44ecc1b1d7a1b8adca97df949d96284c65 Mon Sep 17 00:00:00 2001 From: cflag Date: Tue, 24 Jun 2025 16:35:31 +0200 Subject: [PATCH 5/6] Update visu to detect the time step for the first snapshot --- src/visu.f90 | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/visu.f90 b/src/visu.f90 index ba8a8f14..7168afdb 100644 --- a/src/visu.f90 +++ b/src/visu.f90 @@ -24,6 +24,8 @@ module visu integer, save :: output2D integer, save :: ioxdmf integer, save :: ioxml + ! Used for vtk.xml to detect the first snapshot + integer, save :: itime_first_snapshot character(len=9) :: ifilenameformat = '(I3.3)' real, save :: tstart, tend @@ -89,6 +91,7 @@ subroutine visu_init() endif ! Use vtk.xml instead of xdmf when ADIOS2 is available + itime_first_snapshot = ilast #ifdef ADIOS2 use_xdmf = .false. use_vtkxml = .true. @@ -628,9 +631,11 @@ subroutine write_field(f1, pathname, filename, num, skip_ibm, flush) endif endif + ! Add the field to vtk.xml if first snapshot if (use_vtkxml) then - if (nrank.eq.0 .and. num.eq.0) then + if (nrank.eq.0 .and. itime.le.itime_first_snapshot) then write (ioxml, *) ' ' + itime_first_snapshot = itime end if end if From ae8b4b8e541a6d557eeba20859500a2ad101d9b0 Mon Sep 17 00:00:00 2001 From: cflag Date: Tue, 24 Jun 2025 16:41:26 +0200 Subject: [PATCH 6/6] Fix previous commit --- src/visu.f90 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/visu.f90 b/src/visu.f90 index 7168afdb..529393c3 100644 --- a/src/visu.f90 +++ b/src/visu.f90 @@ -558,7 +558,7 @@ subroutine write_field(f1, pathname, filename, num, skip_ibm, flush) use var, only : zero, one use var, only : uvisu use var, only : ta1 - use param, only : iibm + use param, only : iibm, itime use utilities, only : gen_filename,gen_snapshotname,gen_h5path use decomp_2d_io, only : decomp_2d_write_one, decomp_2d_write_plane