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

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, typically one VTK (.vtu) file is written for each time step. In order to connect the actual time with each of these files, the paraview_collection can function from WriteVTK.jl can be used. This will create one paraview datafile (.pvd) file and one VTKGridFile (.vtu) for each time step.

using WriteVTK
pvd = 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
    end
end
vtk_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"

See Transient heat equation for an example