Gridap.Visualization
The Gridap.Visualization module provides tools to export Gridap grids (such as Triangulation, DiscreteModel) and objects defined on those grids (such as Function and CellField) into VTK format. These files can then be opened and visualized in external software like ParaView.
Gridap.Visualization — Module
Exported names
VisualizationData, createpvd, createvtk, savepvd, visualization_data, write_vtk_file, writevtk,
Contents
High-level API
The primary entry points for visualization are writevtk and createvtk.
Gridap.Visualization.writevtk — Function
writevtk(object, filebase; kwargs...)Exports a Triangulation, DiscreteModel, or other Gridap objects to a VTK file.
Available Constructors
writevtk(grid::Grid, filebase; celldata=Dict(), nodaldata=Dict())writevtk(trian::Triangulation, filebase; order=-1, nsubcells=-1, celldata=Dict(), cellfields=Dict())writevtk(model::DiscreteModel, filebase; labels=get_face_labeling(model))writevtk(polytope::Polytope, filebase)writevtk(reffe::LagrangianRefFE, filebase)writevtk(cell_point::CellPoint, filebase; cellfields=Dict())
Keyword Arguments
celldata::Dictornodaldata::Dict: Dictionaries of arrays/fields to export as cell-wise or node-wise data.cellfields::Dict: Dictionary ofCellFieldobjects to export.order::Int=-1: Interpolates the object into high-order Lagrangian nodes.nsubcells::Int=-1: Interpolates the object into a piecewise-order space within each cell (usingnsubcellsper direction).kwargs...: Additional keyword arguments (e.g.,compress,append,ascii,vtkversion) are passed to the underlyingvtk_gridfunction fromWriteVTK.jl.
Examples
# Visualize a triangulation with cell data
writevtk(trian, "results", celldata=["err" => e], nodaldata=["uh" => uh])
# Visualize a high-order field using sub-cells
writevtk(trian, "results", nsubcells=10, cellfields=["uh" => uh])Gridap.Visualization.createvtk — Function
createvtk(args...; kwargs...) -> vtkFilePrepares a VTK object without immediately writing it to disk.
This is useful for advanced customization before calling vtk_save. The arguments are the same as for writevtk. Keyword arguments (e.g., compress, append, ascii, vtkversion) are passed to the underlying vtk_grid function from WriteVTK.jl.
For simulations that change over time, Gridap provides the PVD (ParaView Data) format to group multiple VTK files into a single time series.
Gridap.Visualization.createpvd — Function
createpvd(filebase) do pvd
pvd[time] = vtk_file
end
createpvd(filebase) -> pvdCreates a ParaView Data (PVD) collection for time-dependent visualization.
Can be used as a context manager (with do block) to automatically save the collection, or manually by calling savepvd.
Examples
createpvd("timeseries") do pvd
for (t, uh) in simulation_steps
pvd[t] = createvtk(trian, "results_$t", cellfields=["uh" => uh])
end
endGridap.Visualization.savepvd — Function
savepvd(pvd)Manually saves a ParaView Data (PVD) collection to disk.
Advanced & Low-level API
For more control over the visualization process, you can use createvtk to prepare a VTK object without writing it immediately, or work directly with VisualizationData.
Gridap.Visualization.create_vtk_file — Function
create_vtk_file(
trian::Grid,
filebase;
celldata=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.
Gridap.Visualization.write_vtk_file — Function
write_vtk_file(
trian::Grid,
filebase;
celldata=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.
Gridap.Visualization.VisualizationData — Type
struct VisualizationDataA structured representation of visualization data for a Grid. See also visualization_data.
Fields
grid::Grid: The grid to visualize.filebase::AbstractString: The name of the output file.celldata: Dictionary of cell-wise data.nodaldata: Dictionary of node-wise data.
Gridap.Visualization.visualization_data — Function
visualization_data(object, filebase; kwargs...) -> Vector{VisualizationData}Internal function that converts a Gridap object into a standardized representation for visualization.
Available Constructors
visualization_data(grid::Grid, filebase; celldata=Dict(), nodaldata=Dict())visualization_data(trian::Triangulation, filebase; order=-1, nsubcells=-1, celldata=Dict(), cellfields=Dict())visualization_data(model::DiscreteModel, filebase; labels=get_face_labeling(model))visualization_data(polytope::Polytope, filebase)visualization_data(reffe::LagrangianRefFE, filebase)visualization_data(cell_point::CellPoint, filebase; cellfields=Dict())
Keyword Arguments
order::Int=-1: Interpolates the object into high-order Lagrangian nodes.nsubcells::Int=-1: Interpolates the object into a piecewise-order space within each cell (usingnsubcellsper direction).
Gridap.Visualization.VisualizationGrid — Type
struct VisualizationGrid{Dc,Dp} <: Grid{Dc,Dp}A grid specialized for visualization purposes, often representing a refined version of a physical grid. See also visualization_grid.
Gridap.Visualization.visualization_grid — Function
visualization_grid(args...; kwargs...) -> VisualizationGridConstructs a VisualizationGrid. This is an internal function used to generate the underlying grid structure for VTK export, handling sub-cell refinement and point evaluation.