Export
When the problem is solved, and the solution vector u is known we typically want to visualize it. The simplest way to do this is to write the solution to a VTK-file, which can be viewed in e.g. Paraview. To write VTK-files, Ferrite comes with an export interface with a WriteVTK.jl backend to simplify the exporting.
The following structure can be used to write various output to a vtk-file:
VTKGridFile("my_solution", grid) do vtk write_solution(vtk, dh, u)end;VTKGridFile for the closed file "my_solution.vtu".where write_solution is just one example of the following functions that can be used
write_solutionwrite_cell_datawrite_node_datawrite_projectionFerrite.write_cellsetFerrite.write_nodesetFerrite.write_facetsetFerrite.write_constraintsFerrite.write_cell_colors
Instead of using the do-block, it is also possible to do
vtk = VTKGridFile("my_solution", grid)write_solution(vtk, dh, u)# etc.close(vtk);VTKGridFile for the closed file "my_solution.vtu".The data written by write_solution, write_cell_data, write_node_data, and write_projection may be either scalar (Vector{<:Number}) or tensor (Vector{<:AbstractTensor}) data.
For simulations with multiple time steps there are two options.
Time series with VTKHDF (recommended)
A VTKHDFGridFile — the HDF5-based VTKHDF format — can hold a whole time series in a single file, with the grid stored only once, no matter how many steps are saved. This requires VTKHDF.jl to be loaded. Open the file with temporal = true and write each step with write_timestep:
using VTKHDFvtkhdf = VTKHDFGridFile("my_results.vtkhdf", dh; temporal = true)for t in range(0, 1, 5) # Do calculations to update u write_timestep(vtkhdf, t) do vtk write_solution(vtk, dh, u) endendclose(vtkhdf);The same data functions as above are supported. See Transient heat equation for an example.
Time series with a Paraview collection (.pvd)
Alternatively, with the XML-based formats one VTK (.vtu) file is written for each time step. To connect the actual time with each of these files, the paraview_collection function from WriteVTK.jl can be used. This creates one paraview datafile (.pvd) and one VTKGridFile (.vtu) for each time step.
using WriteVTKpvd = paraview_collection("my_results")for (step, t) in enumerate(range(0, 1, 5)) # Do calculations to update u VTKGridFile("my_results_$step", dh) do vtk write_solution(vtk, dh, u) pvd[t] = vtk endendvtk_save(pvd);6-element Vector{String}:
"my_results.pvd"
"my_results_1.vtu"
"my_results_2.vtu"
"my_results_3.vtu"
"my_results_4.vtu"
"my_results_5.vtu"