Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add VTK encoding options #1016

Merged
merged 3 commits into from
Jul 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading