From ed7b45d17ae1561e04a2ec1894c594607cd7adb8 Mon Sep 17 00:00:00 2001 From: JordiManyer Date: Wed, 24 Jul 2024 12:37:48 +1000 Subject: [PATCH 1/3] Added vtk kwargs to control output encoding --- src/Visualization/Vtk.jl | 52 ++++++++++++++++++++--------- test/VisualizationTests/VtkTests.jl | 30 +++++++++++------ 2 files changed, 57 insertions(+), 25 deletions(-) diff --git a/src/Visualization/Vtk.jl b/src/Visualization/Vtk.jl index 560319ac6..fa9b2f9d8 100644 --- a/src/Visualization/Vtk.jl +++ b/src/Visualization/Vtk.jl @@ -1,20 +1,24 @@ """ """ -function writevtk(args...;kwargs...) +function writevtk(args...;compress=false,append=true,ascii=false,vtkversion=:default,kwargs...) map(visualization_data(args...;kwargs...)) do visdata write_vtk_file( - visdata.grid,visdata.filebase,celldata=visdata.celldata,nodaldata=visdata.nodaldata) + visdata.grid,visdata.filebase,celldata=visdata.celldata,nodaldata=visdata.nodaldata, + compress=compress, append=append, ascii=ascii, vtkversion=vtkversion + ) end end """ """ -function createvtk(args...;kwargs...) +function createvtk(args...;compress=false,append=true,ascii=false,vtkversion=:default,kwargs...) v = visualization_data(args...;kwargs...) @notimplementedif length(v) != 1 visdata = first(v) create_vtk_file( - visdata.grid,visdata.filebase,celldata=visdata.celldata,nodaldata=visdata.nodaldata) + visdata.grid,visdata.filebase,celldata=visdata.celldata,nodaldata=visdata.nodaldata, + compress=compress, append=append, ascii=ascii, vtkversion=vtkversion + ) end """ @@ -43,14 +47,21 @@ end trian::Grid, filebase; celldata=Dict(), - nodaldata=Dict()) + nodaldata=Dict(), + vtk_kwargs... + ) Low level entry point to vtk. Other vtk-related routines in Gridap eventually call this one. - +The optional WriteVTK kwargs `vtk_kwargs` are passed to the `vtk_grid` constructor. """ function write_vtk_file( - trian::Grid, filebase; celldata=Dict(), nodaldata=Dict()) - vtkfile = create_vtk_file(trian, filebase, celldata=celldata, nodaldata=nodaldata) + trian::Grid, filebase; celldata=Dict(), nodaldata=Dict(), + compress=false, append=true, ascii=false, vtkversion=:default +) + vtkfile = create_vtk_file( + trian, filebase, celldata=celldata, nodaldata=nodaldata, + compress=compress, append=append, ascii=ascii, vtkversion=vtkversion + ) outfiles = vtk_save(vtkfile) end @@ -60,18 +71,26 @@ end trian::Grid, filebase; celldata=Dict(), - nodaldata=Dict()) + nodaldata=Dict(), + vtk_kwargs... + ) Low level entry point to vtk. Other vtk-related routines in Gridap eventually call this one. This function only creates the vtkFile, without writing to disk. +The optional WriteVTK kwargs `vtk_kwargs` are passed to the `vtk_grid` constructor. """ function create_vtk_file( - trian::Grid, filebase; celldata=Dict(), nodaldata=Dict()) + trian::Grid, filebase; celldata=Dict(), nodaldata=Dict(), + compress=false, append=true, ascii=false, vtkversion=:default +) points = _vtkpoints(trian) cells = _vtkcells(trian) - vtkfile = vtk_grid(filebase, points, cells, compress=false) + vtkfile = vtk_grid( + filebase, points, cells, + compress=compress, append=append, ascii=ascii, vtkversion=vtkversion + ) if num_cells(trian)>0 for (k,v) in celldata @@ -86,13 +105,16 @@ function create_vtk_file( end function create_pvtk_file( - trian::Grid, filebase; - part, nparts, ismain=(part==1), celldata=Dict(), nodaldata=Dict()) + trian::Grid, filebase; part, nparts, ismain=(part==1), celldata=Dict(), nodaldata=Dict(), + compress=false, append=true, ascii=false, vtkversion=:default +) points = _vtkpoints(trian) cells = _vtkcells(trian) - vtkfile = pvtk_grid(filebase, points, cells, compress=false; - part=part, nparts=nparts, ismain=ismain) + vtkfile = pvtk_grid( + filebase, points, cells;part=part, nparts=nparts, ismain=ismain, + compress=compress, append=append, ascii=ascii, vtkversion=vtkversion + ) if num_cells(trian) > 0 for (k, v) in celldata diff --git a/test/VisualizationTests/VtkTests.jl b/test/VisualizationTests/VtkTests.jl index 6e33b5082..34cdf232f 100644 --- a/test/VisualizationTests/VtkTests.jl +++ b/test/VisualizationTests/VtkTests.jl @@ -25,16 +25,26 @@ mean(x) = sum(x)/length(x) cell_center = lazy_map(mean, get_cell_coordinates(trian) ) -write_vtk_file( - trian,f, - nodaldata=["nodeid"=>node_ids], - celldata=["cellid"=>cell_ids,"centers"=>cell_center]) - -pvtk = Visualization.create_pvtk_file( - trian,f; part=1, nparts=1, - nodaldata=["nodeid"=>node_ids], - celldata=["cellid"=>cell_ids,"centers"=>cell_center]) -vtk_save(pvtk) +for compress in [true,false] + for append in [true,false] + for ascii in [true,false] + for vtkversion in [:default,:latest] + write_vtk_file( + trian,f, + nodaldata=["nodeid"=>node_ids], + celldata=["cellid"=>cell_ids,"centers"=>cell_center] + ) + + pvtk = Visualization.create_pvtk_file( + trian,f; part=1, nparts=1, + nodaldata=["nodeid"=>node_ids], + celldata=["cellid"=>cell_ids,"centers"=>cell_center] + ) + vtk_save(pvtk) + end + end + end +end reffe = LagrangianRefFE(VectorValue{3,Float64},WEDGE,(3,3,4)) f = joinpath(d,"reffe") From d080224c692b61847b7bb7e1dc0c8e4231a4eeb2 Mon Sep 17 00:00:00 2001 From: JordiManyer Date: Wed, 24 Jul 2024 12:39:50 +1000 Subject: [PATCH 2/3] Added tests --- test/VisualizationTests/VtkTests.jl | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/test/VisualizationTests/VtkTests.jl b/test/VisualizationTests/VtkTests.jl index 34cdf232f..055da65eb 100644 --- a/test/VisualizationTests/VtkTests.jl +++ b/test/VisualizationTests/VtkTests.jl @@ -32,13 +32,15 @@ for compress in [true,false] write_vtk_file( trian,f, nodaldata=["nodeid"=>node_ids], - celldata=["cellid"=>cell_ids,"centers"=>cell_center] + celldata=["cellid"=>cell_ids,"centers"=>cell_center], + compress=compress, append=append, ascii=ascii, vtkversion=vtkversion ) pvtk = Visualization.create_pvtk_file( trian,f; part=1, nparts=1, nodaldata=["nodeid"=>node_ids], - celldata=["cellid"=>cell_ids,"centers"=>cell_center] + celldata=["cellid"=>cell_ids,"centers"=>cell_center], + compress=compress, append=append, ascii=ascii, vtkversion=vtkversion ) vtk_save(pvtk) end From 307c1f725232a74d141e0e15a560ad471b677c30 Mon Sep 17 00:00:00 2001 From: JordiManyer Date: Wed, 24 Jul 2024 13:03:51 +1000 Subject: [PATCH 3/3] Added NEWS.md --- NEWS.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/NEWS.md b/NEWS.md index f66e55551..c38d12a72 100644 --- a/NEWS.md +++ b/NEWS.md @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## Unreleased +### Changed + +- Added WriteVTK kwargs to control the output encoding for vtk files. Since PR[#1016](https://github.com/gridap/Gridap.jl/pull/1016). + ### Fixed - Passing `kwargs` from `refine` to `simplexify` functions in Adaptivity. Since PR[#1015](https://github.com/gridap/Gridap.jl/pull/1015).