Skip to content

Commit

Permalink
Merge pull request gridap#1016 from gridap/vtk-kwargs
Browse files Browse the repository at this point in the history
Add VTK encoding options
  • Loading branch information
JordiManyer authored Jul 24, 2024
2 parents a562811 + 307c1f7 commit 109cac8
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 25 deletions.
4 changes: 4 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -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).
Expand Down
52 changes: 37 additions & 15 deletions src/Visualization/Vtk.jl
Original file line number Diff line number Diff line change
@@ -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

"""
Expand Down Expand Up @@ -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

Expand All @@ -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
Expand All @@ -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
Expand Down
32 changes: 22 additions & 10 deletions test/VisualizationTests/VtkTests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,28 @@ 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],
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],
compress=compress, append=append, ascii=ascii, vtkversion=vtkversion
)
vtk_save(pvtk)
end
end
end
end

reffe = LagrangianRefFE(VectorValue{3,Float64},WEDGE,(3,3,4))
f = joinpath(d,"reffe")
Expand Down

0 comments on commit 109cac8

Please sign in to comment.