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.

Contents

High-level API

The primary entry points for visualization are writevtk and createvtk.

Gridap.Visualization.writevtkFunction
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::Dict or nodaldata::Dict: Dictionaries of arrays/fields to export as cell-wise or node-wise data.
  • cellfields::Dict: Dictionary of CellField objects 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 (using nsubcells per direction).
  • kwargs...: Additional keyword arguments (e.g., compress, append, ascii, vtkversion) are passed to the underlying vtk_grid function from WriteVTK.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])
source
Gridap.Visualization.createvtkFunction
createvtk(args...; kwargs...) -> vtkFile

Prepares 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.

source

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.createpvdFunction
createpvd(filebase) do pvd
  pvd[time] = vtk_file
end
createpvd(filebase) -> pvd

Creates 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
end
source

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_fileFunction
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.

source
Gridap.Visualization.write_vtk_fileFunction
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.

source
Gridap.Visualization.VisualizationDataType
struct VisualizationData

A 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.
source
Gridap.Visualization.visualization_dataFunction
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 (using nsubcells per direction).
source