Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Abstraction layer around vtk export #692

Merged
merged 83 commits into from
May 19, 2024
Merged
Show file tree
Hide file tree
Changes from 73 commits
Commits
Show all changes
83 commits
Select commit Hold shift + click to select a range
ed4972d
Rename vtk_point_data to vtk_node_data
KnutAM Apr 29, 2023
999571f
Merge master
KnutAM Apr 29, 2023
6c03c70
First attempts on VTKStream
KnutAM May 1, 2023
9a89a1a
Fix deprecations, stage 1
KnutAM May 1, 2023
53c9875
Make tests pass without updates
KnutAM May 1, 2023
f0d1537
Revert previous rename to vtk_node_data
KnutAM May 1, 2023
90e273b
Remove exports and revert example changes
KnutAM May 1, 2023
fbc75b6
Better deprecation warning
KnutAM May 1, 2023
65eace9
Minor docstring fix
KnutAM May 1, 2023
9dbb1de
Merge branch 'master' into kam/VTKStream
KnutAM May 10, 2023
cbaf610
Merge master
KnutAM Jul 5, 2023
77337ee
Fix test (wrong show overload)
KnutAM Jul 5, 2023
50c7c25
Create write_cell_colors and deprecate vtk_cell_data_colors
KnutAM Jul 5, 2023
9bd7131
Merge again
KnutAM Jul 5, 2023
ae917df
Fix show and remove filename from type
KnutAM Jul 7, 2023
58538a2
Merge branch 'master' into kam/VTKStream
KnutAM Jul 18, 2023
b64df44
Apply suggestions from code review
KnutAM Jul 18, 2023
077cf58
Export new functions and update docs
KnutAM Jul 18, 2023
cd6091b
Update tests with new functions
KnutAM Jul 18, 2023
a17e024
Remove (at)example from pseudo-code block in docs
KnutAM Jul 18, 2023
699aec2
Try to fix docs
KnutAM Jul 18, 2023
cf82d1c
Improve docs
KnutAM Jul 18, 2023
69a002c
pin documenter
KnutAM Jul 19, 2023
bff63b0
Renames and unexports
KnutAM Jul 19, 2023
ee61c6e
Fix tests
KnutAM Jul 19, 2023
22937f0
Use qualified name for write_cell_colors
KnutAM Jul 19, 2023
ccaeca2
Error instead of deprecation warning
KnutAM Jul 19, 2023
c5b21f7
Don't reexport WriteVTK
KnutAM Jul 19, 2023
2fdb656
Merge master
KnutAM Jul 19, 2023
6451632
More export fixes
KnutAM Jul 19, 2023
e49e8ac
Export VTKFile
KnutAM Jul 20, 2023
2398490
Tryout PVDFile
KnutAM Jul 23, 2023
91b5e20
Add close of pvd
KnutAM Jul 23, 2023
dda42e3
Remove qualified name
KnutAM Jul 23, 2023
8781ec4
Merge branch 'master' into kam/VTKStream
KnutAM Sep 15, 2023
f7c52ec
Merge branch 'master' into kam/PVDFile
KnutAM Sep 15, 2023
5dd7d65
Merge branch 'kam/PVDFile' into kam/VTKStream
KnutAM Sep 15, 2023
1cb8f99
Replace VTK.paraview_collection with ParaviewCollection
KnutAM Sep 15, 2023
51aeaf3
Merge master
KnutAM Sep 16, 2023
8a4c084
dev Ferrite from docs env
KnutAM Sep 16, 2023
5beaf6c
Doc improvements
KnutAM Sep 16, 2023
6487031
Document addstep
KnutAM Sep 16, 2023
dbc1ac3
Allow dofhandler input as alternative to grid
KnutAM Sep 16, 2023
cd1e303
Remove unused grid input in write_celldata and write_nodedata
KnutAM Sep 16, 2023
9226fed
Remove doc output and files
KnutAM Sep 16, 2023
db226ce
Merge manifest from master
KnutAM Sep 19, 2023
1770c08
Merge branch 'master' into kam/VTKStream
KnutAM Sep 19, 2023
57f0f33
ParaviewCollection -> VTKFileCollection
KnutAM Sep 19, 2023
ba5fbb1
Allow VTKFile keywords to be given to VTKFileCollection
KnutAM Sep 19, 2023
0a90f09
Factor out create_vtk_griddata
KnutAM Sep 25, 2023
6ad6b45
Merge branch 'master' into kam/VTKStream
KnutAM Sep 30, 2023
4cc50c6
Allow more vtk file types in VTKFile, e.g. pvtk
KnutAM Sep 30, 2023
193a375
Fix test failure due to merge
KnutAM Sep 30, 2023
112c4c2
Remove addstep and use VTKFile
KnutAM Sep 30, 2023
2047ab0
Revert "Remove addstep and use VTKFile"
KnutAM Sep 30, 2023
0cfbd24
Fix formatting in docstring
KnutAM Oct 1, 2023
12b8ed7
Support and test addstep[bang](pvd, vtk, t)
KnutAM Oct 14, 2023
e36b6cc
Merge branch 'master' into kam/VTKStream
KnutAM Oct 14, 2023
3e8d454
Allow input to VTKFileCollection ending with .pvd and update porous m…
KnutAM Oct 14, 2023
68b5d13
Export write_nodedata
KnutAM Oct 21, 2023
5aa6cb5
Remove kwargs forwarding
KnutAM Oct 21, 2023
419ce90
Merge master
KnutAM Dec 21, 2023
431cf15
Merge branch 'master' into kam/VTKStream
KnutAM Jan 8, 2024
d1020fd
Update DG example to new syntax
KnutAM Jan 8, 2024
ea7f163
Merge branch 'master' into kam/VTKStream
KnutAM Feb 24, 2024
6a17dac
Merge branch 'master' into kam/VTKStream
KnutAM Feb 28, 2024
5f828ff
Merge branch 'master' into kam/VTKStream
KnutAM Mar 1, 2024
5301307
Fix docs
KnutAM Mar 1, 2024
2f42748
Merge branch 'master' into kam/VTKStream
KnutAM Apr 25, 2024
d6f2ede
using VTKCellTypes explicitly
KnutAM Apr 26, 2024
f55c932
Change to using WriteVTK: vtk_grid
KnutAM Apr 26, 2024
b3fd680
Merge branch 'master' into kam/VTKStream
KnutAM May 16, 2024
fff96ad
Merge branch 'master' into kam/VTKStream
KnutAM May 16, 2024
62fa313
Merge master
KnutAM May 19, 2024
692cf78
Apply suggestions from code review
KnutAM May 19, 2024
4e84b76
write_cell_colors -> write_cellcolors
KnutAM May 19, 2024
acad0da
write_dirichlet -> write_constraints
KnutAM May 19, 2024
819bef6
Add missing tests for vtk export
KnutAM May 19, 2024
e405b38
Test deprecation error
KnutAM May 19, 2024
20668ef
Format test file
KnutAM May 19, 2024
5a0b4fb
Add changelog entry
KnutAM May 19, 2024
c69b9c6
Remove old mentions of "stream" in docstrings
KnutAM May 19, 2024
d6a199e
Add underscores to some names
KnutAM May 19, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions docs/src/literate-gallery/helmholtz.jl
Original file line number Diff line number Diff line change
Expand Up @@ -162,9 +162,9 @@ K, f = doassemble(cellvalues, facevalues, K, dh);
apply!(K, f, dbcs)
u = Symmetric(K) \ f;

vtkfile = vtk_grid("helmholtz", dh)
vtk_point_data(vtkfile, dh, u)
vtk_save(vtkfile)
vtk = VTKFile("helmholtz", dh)
write_solution(vtk, dh, u)
close(vtk)
using Test #src
#src this test catches unexpected changes in the result over time.
#src the true maximum is slightly bigger then 1.0
Expand Down
12 changes: 6 additions & 6 deletions docs/src/literate-gallery/landau.jl
Original file line number Diff line number Diff line change
Expand Up @@ -113,10 +113,10 @@ function LandauModel(α, G, gridsize, left::Vec{DIM, T}, right::Vec{DIM, T}, elp
end

# utility to quickly save a model
function Ferrite.vtk_save(path, model, dofs=model.dofs)
vtkfile = vtk_grid(path, model.dofhandler)
vtk_point_data(vtkfile, model.dofhandler, dofs)
vtk_save(vtkfile)
function save_landau(path, model, dofs=model.dofs)
VTKFile(path, model.dofhandler) do vtk
write_solution(vtk, model.dofhandler, dofs)
end
end

# ## Assembly
Expand Down Expand Up @@ -253,9 +253,9 @@ left = Vec{3}((-75.,-25.,-2.))
right = Vec{3}((75.,25.,2.))
model = LandauModel(α, G, (50, 50, 2), left, right, element_potential)

vtk_save("landauorig", model)
save_landau("landauorig", model)
@time minimize!(model)
vtk_save("landaufinal", model)
save_landau("landaufinal", model)

# as we can see this runs very quickly even for relatively large gridsizes.
# The key to get high performance like this is to minimize the allocations inside the threaded loops,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,7 @@ function solve(interpolation_u, interpolation_p)
Δt = 0.1;
NEWTON_TOL = 1e-8

pvd = paraview_collection("hyperelasticity_incomp_mixed.pvd");
pvd = VTKFileCollection("hyperelasticity_incomp_mixed", grid);
for t ∈ 0.0:Δt:Tf
## Perform Newton iterations
Ferrite.update!(dbc, t)
Expand Down Expand Up @@ -334,13 +334,11 @@ function solve(interpolation_u, interpolation_p)
end;

## Save the solution fields
vtk_grid("hyperelasticity_incomp_mixed_$t.vtu", dh) do vtkfile
vtk_point_data(vtkfile, dh, w)
vtk_save(vtkfile)
pvd[t] = vtkfile
addstep!(pvd, t) do io
write_solution(io, dh, w)
end
end;
vtk_save(pvd);
close(pvd);
vol_def = calculate_volume_deformed_mesh(w, dh, cellvalues_u);
print("Deformed volume is $vol_def")
return vol_def;
Expand Down
8 changes: 4 additions & 4 deletions docs/src/literate-gallery/topology_optimization.jl
Original file line number Diff line number Diff line change
Expand Up @@ -492,16 +492,16 @@ function topopt(ra,ρ,n,filename; output=:false)
i = @sprintf("%3.3i", it)
filename_it = string(filename, "_", i)

vtk_grid(filename_it, grid) do vtk
vtk_cell_data(vtk, χ, "density")
VTKFile(filename_it, grid) do vtk
write_celldata(vtk, χ, "density")
end
end
end

## export converged results
if(!output)
vtk_grid(filename, grid) do vtk
vtk_cell_data(vtk, χ, "density")
VTKFile(filename, grid) do vtk
write_celldata(vtk, χ, "density")
end
end
@printf "Rel. stiffness: %.4f \n" compliance^(-1)/compliance_0^(-1)
Expand Down
4 changes: 2 additions & 2 deletions docs/src/literate-howto/postprocessing.jl
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,8 @@ q_projected = project(projector, q_gp, qr);
# To visualize the heat flux, we export the projected field `q_projected`
# to a VTK-file, which can be viewed in e.g. [ParaView](https://www.paraview.org/).
# The result is also visualized in *Figure 1*.
vtk_grid("heat_equation_flux", grid) do vtk
vtk_point_data(vtk, projector, q_projected, "q")
VTKFile("heat_equation_flux", grid) do vtk
write_projection(vtk, projector, q_projected, "q")
end;

# ## Point Evaluation
Expand Down
6 changes: 3 additions & 3 deletions docs/src/literate-howto/threaded_assembly.jl
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ function create_example_2d_grid()
grid = generate_grid(Quadrilateral, (10, 10), Vec{2}((0.0, 0.0)), Vec{2}((10.0, 10.0)))
colors_workstream = create_coloring(grid; alg=ColoringAlgorithm.WorkStream)
colors_greedy = create_coloring(grid; alg=ColoringAlgorithm.Greedy)
vtk_grid("colored", grid) do vtk
vtk_cell_data_colors(vtk, colors_workstream, "workstream-coloring")
vtk_cell_data_colors(vtk, colors_greedy, "greedy-coloring")
VTKFile("colored", grid) do vtk
Ferrite.write_cell_colors(vtk, grid, colors_workstream, "workstream-coloring")
Ferrite.write_cell_colors(vtk, grid, colors_greedy, "greedy-coloring")
end
end

Expand Down
10 changes: 5 additions & 5 deletions docs/src/literate-tutorials/computational_homogenization.jl
Original file line number Diff line number Diff line change
Expand Up @@ -518,16 +518,16 @@ round.(ev; digits=-8)

uM = zeros(ndofs(dh))

vtk_grid("homogenization", dh) do vtk
VTKFile("homogenization", dh) do vtk
for i in 1:3
## Compute macroscopic solution
apply_analytical!(uM, dh, :u, x -> εᴹ[i] ⋅ x)
## Dirichlet
vtk_point_data(vtk, dh, uM + u.dirichlet[i], "_dirichlet_$i")
vtk_point_data(vtk, projector, σ.dirichlet[i], "σvM_dirichlet_$i")
write_solution(vtk, dh, uM + u.dirichlet[i], "_dirichlet_$i")
write_projection(vtk, projector, σ.dirichlet[i], "σvM_dirichlet_$i")
## Periodic
vtk_point_data(vtk, dh, uM + u.periodic[i], "_periodic_$i")
vtk_point_data(vtk, projector, σ.periodic[i], "σvM_periodic_$i")
write_solution(vtk, dh, uM + u.periodic[i], "_periodic_$i")
write_projection(vtk, projector, σ.periodic[i], "σvM_periodic_$i")
end
end;

Expand Down
4 changes: 2 additions & 2 deletions docs/src/literate-tutorials/dg_heat_equation.jl
Original file line number Diff line number Diff line change
Expand Up @@ -334,8 +334,8 @@ K, f = assemble_global(cellvalues, facevalues, interfacevalues, K, dh, order, di

apply!(K, f, ch)
u = K \ f;
vtk_grid("dg_heat_equation", dh) do vtk
vtk_point_data(vtk, dh, u)
VTKFile("dg_heat_equation", dh) do vtk
write_solution(vtk, dh, u)
end;

## test the result #src
Expand Down
4 changes: 2 additions & 2 deletions docs/src/literate-tutorials/heat_equation.jl
Original file line number Diff line number Diff line change
Expand Up @@ -213,8 +213,8 @@ u = K \ f;
# ### Exporting to VTK
# To visualize the result we export the grid and our field `u`
# to a VTK-file, which can be viewed in e.g. [ParaView](https://www.paraview.org/).
vtk_grid("heat_equation", dh) do vtk
vtk_point_data(vtk, dh, u)
VTKFile("heat_equation", dh) do vtk
write_solution(vtk, dh, u)
end

## test the result #src
Expand Down
4 changes: 2 additions & 2 deletions docs/src/literate-tutorials/hyperelasticity.jl
Original file line number Diff line number Diff line change
Expand Up @@ -408,8 +408,8 @@ function solve()

## Save the solution
@timeit "export" begin
vtk_grid("hyperelasticity", dh) do vtkfile
vtk_point_data(vtkfile, dh, u)
VTKFile("hyperelasticity", dh) do vtk
write_solution(vtk, dh, u)
end
end

Expand Down
9 changes: 5 additions & 4 deletions docs/src/literate-tutorials/incompressible_elasticity.jl
Original file line number Diff line number Diff line change
Expand Up @@ -270,13 +270,14 @@ function solve(ν, interpolation_u, interpolation_p)
## Export the solution and the stress
filename = "cook_" * (interpolation_u == Lagrange{RefTriangle, 1}()^2 ? "linear" : "quadratic") *
"_linear"
vtk_grid(filename, dh) do vtkfile
vtk_point_data(vtkfile, dh, u)

VTKFile(filename, grid) do vtk
write_solution(vtk, dh, u)
for i in 1:3, j in 1:3
σij = [x[i, j] for x in σ]
vtk_cell_data(vtkfile, σij, "sigma_$(i)$(j)")
write_celldata(vtk, σij, "sigma_$(i)$(j)")
end
vtk_cell_data(vtkfile, σvM, "sigma von Mise")
write_celldata(vtk, σvM, "sigma von Mises")
end
return u
end
Expand Down
4 changes: 2 additions & 2 deletions docs/src/literate-tutorials/linear_shell.jl
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,8 @@ a = K\f

# Output results.
#+
vtk_grid("linear_shell", dh) do vtk
vtk_point_data(vtk, dh, a)
VTKFile("linear_shell", dh) do vtk
write_solution(vtk, dh, a)
end

end; #end main functions
Expand Down
10 changes: 4 additions & 6 deletions docs/src/literate-tutorials/ns_vs_diffeq.jl
Original file line number Diff line number Diff line change
Expand Up @@ -431,7 +431,7 @@ integrator = init(
progress=true, progress_steps=1,
saveat=Δt_save);

pvd = paraview_collection("vortex-street.pvd");
pvd = VTKFileCollection("vortex-street", grid);
integrator = TimeChoiceIterator(integrator, 0.0:Δt_save:T)
for (u_uc,t) in integrator
# We ignored the Dirichlet constraints in the solution vector up to now,
Expand All @@ -440,13 +440,11 @@ for (u_uc,t) in integrator
update!(ch, t)
u = copy(u_uc)
apply!(u, ch)
vtk_grid("vortex-street-$t.vtu", dh) do vtk
vtk_point_data(vtk,dh,u)
vtk_save(vtk)
pvd[t] = vtk
addstep!(pvd, t) do io
write_solution(io, dh, u)
end
end
vtk_save(pvd);
close(pvd);

# Test the result for full proper development of the flow #src
using Test #hide
Expand Down
8 changes: 4 additions & 4 deletions docs/src/literate-tutorials/plasticity.jl
Original file line number Diff line number Diff line change
Expand Up @@ -344,10 +344,10 @@ function solve()
mises_values[el] /= length(cell_states) # average von Mises stress
κ_values[el] /= length(cell_states) # average drag stress
end
vtk_grid("plasticity", dh) do vtkfile
vtk_point_data(vtkfile, dh, u) # displacement field
vtk_cell_data(vtkfile, mises_values, "von Mises [Pa]")
vtk_cell_data(vtkfile, κ_values, "Drag stress [Pa]")
VTKFile("plasticity", dh) do vtk
write_solution(vtk, dh, u) # displacement field
write_celldata(vtk, mises_values, "von Mises [Pa]")
write_celldata(vtk, κ_values, "Drag stress [Pa]")
end

return u_max, traction_magnitude
Expand Down
12 changes: 5 additions & 7 deletions docs/src/literate-tutorials/porous_media.jl
Original file line number Diff line number Diff line change
Expand Up @@ -335,8 +335,8 @@ function solve(dh, ch, domains; Δt=0.025, t_total=1.0)
r = zeros(ndofs(dh))
a = zeros(ndofs(dh))
a_old = copy(a)
pvd = paraview_collection("porous_media.pvd");
for (step, t) in enumerate(0:Δt:t_total)
pvd = VTKFileCollection("porous_media.pvd", dh);
for t in 0:Δt:t_total
if t>0
update!(ch, t)
apply!(a, ch)
Expand All @@ -347,13 +347,11 @@ function solve(dh, ch, domains; Δt=0.025, t_total=1.0)
a .+= Δa
copyto!(a_old, a)
end
vtk_grid("porous_media-$step", dh) do vtk
vtk_point_data(vtk, dh, a)
vtk_save(vtk)
pvd[step] = vtk
addstep!(pvd, t) do io
write_solution(io, dh, a)
end
end
vtk_save(pvd);
close(pvd);
end;

# Finally we call the functions to actually run the code
Expand Down
4 changes: 2 additions & 2 deletions docs/src/literate-tutorials/stokes-flow.jl
Original file line number Diff line number Diff line change
Expand Up @@ -506,8 +506,8 @@ function main()
u = K \ f
apply!(u, ch)
## Export the solution
vtk_grid("stokes-flow", grid) do vtk
vtk_point_data(vtk, dh, u)
VTKFile("stokes-flow", grid) do vtk
write_solution(vtk, dh, u)
end

## Check the result #src
Expand Down
18 changes: 7 additions & 11 deletions docs/src/literate-tutorials/transient_heat_equation.jl
Original file line number Diff line number Diff line change
Expand Up @@ -189,13 +189,11 @@ apply_analytical!(uₙ, dh, :u, x -> (x[1]^2 - 1) * (x[2]^2 - 1) * max_temp);
# Here, we apply **once** the boundary conditions to the system matrix `A`.
apply!(A, ch);

# To store the solution, we initialize a `paraview_collection` (.pvd) file.
pvd = paraview_collection("transient-heat.pvd");
# To store the solution, we initialize a `VTKFileCollection` (.pvd) file.
pvd = VTKFileCollection("transient-heat", grid);
t = 0
vtk_grid("transient-heat-$t", dh) do vtk
vtk_point_data(vtk, dh, uₙ)
vtk_save(vtk)
pvd[t] = vtk
addstep!(pvd, t) do io
write_solution(io, dh, uₙ)
end

# At this point everything is set up and we can finally approach the time loop.
Expand All @@ -211,16 +209,14 @@ for t in Δt:Δt:T
#Finally, we can solve the time step and save the solution afterwards.
u = A \ b

vtk_grid("transient-heat-$t", dh) do vtk
vtk_point_data(vtk, dh, u)
vtk_save(vtk)
pvd[t] = vtk
addstep!(pvd, t) do io
write_solution(io, dh, u)
end
#At the end of the time loop, we set the previous solution to the current one and go to the next time step.
uₙ .= u
end
# In order to use the .pvd file we need to store it to the disk, which is done by:
vtk_save(pvd);
close(pvd);

#md # ## [Plain program](@id transient_heat_equation-plain-program)
#md #
Expand Down
16 changes: 11 additions & 5 deletions docs/src/reference/export.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,16 @@ evaluate_at_grid_nodes
```

## VTK Export

```@docs
vtk_grid(filename::AbstractString, grid::Grid{dim,C,T}; compress::Bool) where {dim,C,T}
vtk_point_data
vtk_cellset
vtk_cell_data_colors
VTKFile
VTKFileCollection
KnutAM marked this conversation as resolved.
Show resolved Hide resolved
addstep!
write_solution
write_projection
write_celldata
write_nodedata
Ferrite.write_cellset
Ferrite.write_nodeset
Ferrite.write_dirichlet
Ferrite.write_cell_colors
KnutAM marked this conversation as resolved.
Show resolved Hide resolved
```
Loading
Loading