@@ -12,6 +12,8 @@ module visu
1212
1313 ! True to activate the XDMF output
1414 logical , save :: use_xdmf = .true.
15+ ! True to activate vtk.xml output
16+ logical , save :: use_vtkxml = .false.
1517 ! True to use the new enumeration
1618 logical , save :: filenamedigits = .false.
1719 ! output2D is defined in the input.i3d file
@@ -20,7 +22,10 @@ module visu
2022 ! 2 for 2D output with Y average
2123 ! 3 for 2D output with Z average
2224 integer , save :: output2D
23- integer :: ioxdmf
25+ integer , save :: ioxdmf
26+ integer , save :: ioxml
27+ ! Used for vtk.xml to detect the first snapshot
28+ integer , save :: itime_first_snapshot
2429 character (len= 9 ) :: ifilenameformat = ' (I3.3)'
2530 real , save :: tstart, tend
2631
@@ -40,7 +45,7 @@ subroutine visu_init()
4045 use MPI
4146 use param, only : ilmn, iscalar, ilast, ifirst, ioutput, istret
4247 use variables, only : numscalar, prec, nvisu
43- use param, only : dx, dy, dz
48+ use param, only : dx, dy, dz, istret
4449 use decomp_2d_io, only : decomp_2d_init_io, decomp_2d_open_io, decomp_2d_append_mode
4550 use decomp_2d_io, only : decomp_2d_register_variable
4651
@@ -85,6 +90,13 @@ subroutine visu_init()
8590 stop
8691 endif
8792
93+ ! Use vtk.xml instead of xdmf when ADIOS2 is available
94+ itime_first_snapshot = ilast
95+ #ifdef ADIOS2
96+ use_xdmf = .false.
97+ use_vtkxml = .true.
98+ #endif
99+
88100 call decomp_2d_init_io(io_name)
89101
90102 ! ! Register variables
@@ -102,6 +114,12 @@ subroutine visu_init()
102114 call decomp_2d_register_variable(io_name, scname, 1 , 0 , output2D, mytype)
103115 enddo
104116 endif
117+
118+ #ifdef ADIOS2
119+ ! The file vtk.xml is sufficient when the mesh is regular
120+ ! In case of streching, the Paraview filter "warp_by_scalar" should be used
121+ if (istret /= 0 ) call decomp_2d_register_variable(io_name, " warp" , 1 , 0 , output2D, mytype)
122+ #endif
105123
106124 end subroutine visu_init
107125
@@ -113,8 +131,7 @@ end subroutine visu_init
113131 subroutine visu_ready ()
114132
115133 use decomp_2d_io, only : decomp_2d_open_io, decomp_2d_append_mode, decomp_2d_write_mode, gen_iodir_name
116-
117- use param, only : irestart
134+ use param, only : irestart, dx, dy, dz
118135
119136 implicit none
120137
@@ -147,6 +164,19 @@ subroutine visu_ready ()
147164 end if
148165
149166 call decomp_2d_open_io(io_name, " data" , mode)
167+
168+ ! Write the vtk.xml file
169+ if (nrank.eq. 0 ) then
170+ open (newunit= ioxml, file= " ./data.bp4/vtk.xml" )
171+
172+ ! Header for a uniform grid
173+ write (ioxml, * ) ' <?xml version="1.0"?>'
174+ write (ioxml, * ) ' <VTKFile type="ImageData" version="0.1" byte_order="LittleEndian">'
175+ ! Extent should be in reversed order
176+ write (ioxml, * ) ' <ImageData WholeExtent="1 ' , zsize(3 ), ' 1 ' , ysize(2 ), ' 1 ' , xsize(1 ), ' " Origin="0 0 0" Spacing="' , dx, ' ' , dy, ' ' , dz, ' ">'
177+ write (ioxml, * ) ' <Piece Extent="1 ' , zsize(3 ), ' 1 ' , ysize(2 ), ' 1 ' , xsize(1 ), ' ">'
178+ write (ioxml, * ) ' <PointData>'
179+ end if
150180#endif
151181
152182 end subroutine visu_ready
@@ -161,6 +191,9 @@ subroutine visu_finalise()
161191
162192 implicit none
163193
194+ ! Write vtk.xml footer
195+ if (use_vtkxml) call write_vtkxml_footer()
196+
164197#ifdef ADIOS2
165198 call decomp_2d_close_io(io_name, " data" )
166199#endif
@@ -174,12 +207,12 @@ subroutine write_snapshot(rho1, ux1, uy1, uz1, pp3, phi1, ep1, itime, num)
174207
175208 use decomp_2d_io, only : decomp_2d_start_io
176209
177- use param, only : nrhotime, ilmn, iscalar, ioutput, irestart
210+ use param, only : nrhotime, ilmn, iscalar, ioutput, irestart, istret, dy
178211
179212 use variables, only : sx, cifip6, cisip6, ciwip6, cifx6, cisx6, ciwx6
180213 use variables, only : sy, cifip6y, cisip6y, ciwip6y, cify6, cisy6, ciwy6
181214 use variables, only : sz, cifip6z, cisip6z, ciwip6z, cifz6, cisz6, ciwz6
182- use variables, only : numscalar
215+ use variables, only : numscalar, yp
183216
184217 use var, only : pp1, ta1, di1, nxmsize
185218 use var, only : pp2, ppi2, dip2, ph2, nymsize
@@ -206,6 +239,9 @@ subroutine write_snapshot(rho1, ux1, uy1, uz1, pp3, phi1, ep1, itime, num)
206239 integer :: mode
207240 logical , save :: outloc_init = .false.
208241 logical :: dir_exists
242+ #ifdef ADIOS2
243+ integer :: i, j, k, jglob
244+ #endif
209245
210246 ! Update log file
211247 if (nrank.eq. 0 ) then
@@ -270,6 +306,20 @@ subroutine write_snapshot(rho1, ux1, uy1, uz1, pp3, phi1, ep1, itime, num)
270306 enddo
271307 endif
272308
309+ #ifdef ADIOS2
310+ if (istret /= 0 ) then
311+ do k = 1 , xsize(3 )
312+ do j = 1 , xsize(2 )
313+ jglob = j + xstart(2 ) - 1
314+ do i = 1 , xsize(1 )
315+ ta1(i, j, k) = yp(jglob) - (jglob - 1 ) * dy
316+ end do
317+ end do
318+ end do
319+ call write_field(ta1, " ." , " warp" , num, .true. , flush= .true. )
320+ end if
321+ #endif
322+
273323 end subroutine write_snapshot
274324
275325 subroutine end_snapshot (itime , num )
@@ -477,6 +527,25 @@ subroutine write_xdmf_footer()
477527
478528 end subroutine write_xdmf_footer
479529
530+ !
531+ ! Write the footer of the vtk.xml file at the end of the simulation
532+ !
533+ subroutine write_vtkxml_footer ()
534+
535+ implicit none
536+
537+ #ifdef ADIOS2
538+ if (nrank.eq. 0 ) then
539+ write (ioxml, * ) ' </PointData>'
540+ write (ioxml, * ) ' </Piece>'
541+ write (ioxml, * ) ' </ImageData>'
542+ write (ioxml, * ) ' </VTKFile>'
543+ close (ioxml)
544+ endif
545+ #endif
546+
547+ end subroutine write_vtkxml_footer
548+
480549 !
481550 ! Write the given field for visualization
482551 ! Adapted from https://github.com/fschuch/Xcompact3d/blob/master/src/visu.f90
@@ -489,7 +558,7 @@ subroutine write_field(f1, pathname, filename, num, skip_ibm, flush)
489558 use var, only : zero, one
490559 use var, only : uvisu
491560 use var, only : ta1
492- use param, only : iibm
561+ use param, only : iibm, itime
493562 use utilities, only : gen_filename,gen_snapshotname,gen_h5path
494563 use decomp_2d_io, only : decomp_2d_write_one, decomp_2d_write_plane
495564
@@ -562,6 +631,14 @@ subroutine write_field(f1, pathname, filename, num, skip_ibm, flush)
562631 endif
563632 endif
564633
634+ ! Add the field to vtk.xml if first snapshot
635+ if (use_vtkxml) then
636+ if (nrank.eq. 0 .and. itime.le. itime_first_snapshot) then
637+ write (ioxml, * ) ' <DataArray Name="' // filename// ' " />'
638+ itime_first_snapshot = itime
639+ end if
640+ end if
641+
565642 if ((iibm == 2 ) .and. .not. present (skip_ibm)) then
566643 ta1(:,:,:) = (one - ep1(:,:,:)) * f1(:,:,:)
567644 else
0 commit comments