-
Notifications
You must be signed in to change notification settings - Fork 9
/
save_vtk.jl
39 lines (37 loc) · 1.13 KB
/
save_vtk.jl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
"""
save_vtk(setup, u, filename = "output/solution"; fieldnames = [:velocity], psolver)
Save velocity and pressure field to a VTK file.
In the case of a 2D setup, the velocity field is saved as a 3D vector with a
z-component of zero, as this seems to be preferred by ParaView.
"""
function save_vtk(
setup,
u,
t,
filename = "output/solution";
fieldnames = [:velocity],
psolver = default_psolver(setup),
)
parts = split(filename, "/")
path = join(parts[1:end-1], "/")
isdir(path) || mkpath(path)
(; grid) = setup
(; dimension, xp) = grid
D = dimension()
xp = Array.(xp)
vtk_grid(filename, xp...) do vtk
up = interpolate_u_p(u, setup)
ωp = interpolate_ω_p(vorticity(u, setup), setup)
if D == 2
# ParaView prefers 3D vectors. Add zero z-component.
up3 = zero(up[1])
up = (up..., up3)
ωp = Array(ωp)
else
ωp = Array.(ωp)
end
vtk["velocity"] = Array.(up)
:pressure in fieldnames && (vtk["pressure"] = Array(pressure(u, t, setup; psolver)))
vtk["vorticity"] = ωp
end
end