Skip to content

Commit 8fa850c

Browse files
committed
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
1 parent de0e287 commit 8fa850c

1 file changed

Lines changed: 81 additions & 6 deletions

File tree

src/visu.f90

Lines changed: 81 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -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+
#ifdef ADIOS2
27+
integer, save :: ioxml
28+
#endif
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,12 @@ subroutine visu_init()
8590
stop
8691
endif
8792

93+
! Use vtk.xml instead of xdmf when ADIOS2 is available
94+
#ifdef ADIOS2
95+
use_xdmf = .false.
96+
use_vtkxml = .true.
97+
#endif
98+
8899
call decomp_2d_init_io(io_name)
89100

90101
!! Register variables
@@ -102,6 +113,12 @@ subroutine visu_init()
102113
call decomp_2d_register_variable(io_name, scname, 1, 0, output2D, mytype)
103114
enddo
104115
endif
116+
117+
#ifdef ADIOS2
118+
! The file vtk.xml is sufficient when the mesh is regular
119+
! In case of streching, the Paraview filter "warp_by_scalar" should be used
120+
if (istret /= 0) call decomp_2d_register_variable(io_name, "warp", 1, 0, output2D, mytype)
121+
#endif
105122

106123
end subroutine visu_init
107124

@@ -113,8 +130,7 @@ end subroutine visu_init
113130
subroutine visu_ready ()
114131

115132
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
133+
use param, only : irestart, dx, dy, dz
118134

119135
implicit none
120136

@@ -147,6 +163,17 @@ subroutine visu_ready ()
147163
end if
148164

149165
call decomp_2d_open_io(io_name, "data", mode)
166+
167+
! Write the vtk.xml file
168+
open(newunit=ioxml, file="./data.bp4/vtk.xml")
169+
170+
! Header for a uniform grid
171+
write (ioxml, *) '<?xml version="1.0"?>'
172+
write (ioxml, *) '<VTKFile type="ImageData" version="0.1" byte_order="LittleEndian">'
173+
! Extent should be in reversed order
174+
write (ioxml, *) ' <ImageData WholeExtent="1 ', zsize(3), ' 1 ', ysize(2), ' 1 ', xsize(1), '" Origin="0 0 0" Spacing="', dx, ' ', dy, ' ', dz, '">'
175+
write (ioxml, *) ' <Piece Extent="1 ', zsize(3), ' 1 ', ysize(2), ' 1 ', xsize(1), '">'
176+
write (ioxml, *) ' <PointData>'
150177
#endif
151178

152179
end subroutine visu_ready
@@ -161,6 +188,9 @@ subroutine visu_finalise()
161188

162189
implicit none
163190

191+
! Write vtk.xml footer
192+
if (use_vtkxml) call write_vtkxml_footer()
193+
164194
#ifdef ADIOS2
165195
call decomp_2d_close_io(io_name, "data")
166196
#endif
@@ -174,19 +204,22 @@ subroutine write_snapshot(rho1, ux1, uy1, uz1, pp3, phi1, ep1, itime, num)
174204

175205
use decomp_2d_io, only : decomp_2d_start_io
176206

177-
use param, only : nrhotime, ilmn, iscalar, ioutput, irestart
207+
use param, only : nrhotime, ilmn, iscalar, ioutput, irestart, istret, dy
178208

179209
use variables, only : sx, cifip6, cisip6, ciwip6, cifx6, cisx6, ciwx6
180210
use variables, only : sy, cifip6y, cisip6y, ciwip6y, cify6, cisy6, ciwy6
181211
use variables, only : sz, cifip6z, cisip6z, ciwip6z, cifz6, cisz6, ciwz6
182-
use variables, only : numscalar
212+
use variables, only : numscalar, yp
183213

184214
use var, only : pp1, ta1, di1, nxmsize
185215
use var, only : pp2, ppi2, dip2, ph2, nymsize
186216
use var, only : ppi3, dip3, ph3, nzmsize
187217
use var, only : npress
188218

189219
use tools, only : rescale_pressure
220+
#ifdef ADIOS2
221+
use utilities, only : gen_filename
222+
#endif
190223

191224
implicit none
192225

@@ -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
@@ -562,6 +631,12 @@ subroutine write_field(f1, pathname, filename, num, skip_ibm, flush)
562631
endif
563632
endif
564633

634+
if (use_vtkxml) then
635+
if (nrank.eq.0 .and. num.eq.0) then
636+
write (ioxml, *) ' <DataArray Name="'//filename//'" />'
637+
end if
638+
end if
639+
565640
if ((iibm == 2) .and. .not.present(skip_ibm)) then
566641
ta1(:,:,:) = (one - ep1(:,:,:)) * f1(:,:,:)
567642
else

0 commit comments

Comments
 (0)