From ed4972dbac42f5d520ee8ead9dbc0a81013f6d1c Mon Sep 17 00:00:00 2001 From: Knut Andreas Meyer Date: Sat, 29 Apr 2023 15:44:00 +0200 Subject: [PATCH 01/67] Rename vtk_point_data to vtk_node_data --- .../literate/computational_homogenization.jl | 8 +++---- docs/src/literate/heat_equation.jl | 2 +- docs/src/literate/helmholtz.jl | 2 +- docs/src/literate/hyperelasticity.jl | 2 +- .../src/literate/incompressible_elasticity.jl | 2 +- docs/src/literate/landau.jl | 2 +- docs/src/literate/linear_shell.jl | 2 +- docs/src/literate/ns_vs_diffeq.jl | 2 +- docs/src/literate/plasticity.jl | 2 +- docs/src/literate/postprocessing.jl | 2 +- .../quasi_incompressible_hyperelasticity.jl | 2 +- docs/src/literate/stokes-flow.jl | 2 +- docs/src/literate/transient_heat_equation.jl | 4 ++-- docs/src/manual/export.md | 10 ++++---- src/Dofs/ConstraintHandler.jl | 2 +- src/Export/VTK.jl | 23 ++++++++++++++++--- src/L2_projection.jl | 2 +- src/exports.jl | 1 + test/test_grid_dofhandler_vtk.jl | 4 ++-- test/test_l2_projection.jl | 8 +++---- test/test_mixeddofhandler.jl | 2 +- 21 files changed, 52 insertions(+), 34 deletions(-) diff --git a/docs/src/literate/computational_homogenization.jl b/docs/src/literate/computational_homogenization.jl index eafdc35ee1..1fbe3c5f12 100644 --- a/docs/src/literate/computational_homogenization.jl +++ b/docs/src/literate/computational_homogenization.jl @@ -523,11 +523,11 @@ vtk_grid("homogenization", dh) do vtk ## 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") + vtk_node_data(vtk, dh, uM + u.dirichlet[i], "_dirichlet_$i") + vtk_node_data(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") + vtk_node_data(vtk, dh, uM + u.periodic[i], "_periodic_$i") + vtk_node_data(vtk, projector, σ.periodic[i], "σvM_periodic_$i") end end; diff --git a/docs/src/literate/heat_equation.jl b/docs/src/literate/heat_equation.jl index 927060738e..240448ad1c 100644 --- a/docs/src/literate/heat_equation.jl +++ b/docs/src/literate/heat_equation.jl @@ -215,7 +215,7 @@ u = K \ f; # 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) + vtk_node_data(vtk, dh, u) end ## test the result #src diff --git a/docs/src/literate/helmholtz.jl b/docs/src/literate/helmholtz.jl index 7b1ab7eb11..4c604548b3 100644 --- a/docs/src/literate/helmholtz.jl +++ b/docs/src/literate/helmholtz.jl @@ -164,7 +164,7 @@ apply!(K, f, dbcs) u = Symmetric(K) \ f; vtkfile = vtk_grid("helmholtz", dh) -vtk_point_data(vtkfile, dh, u) +vtk_node_data(vtkfile, dh, u) vtk_save(vtkfile) using Test #src #src this test catches unexpected changes in the result over time. diff --git a/docs/src/literate/hyperelasticity.jl b/docs/src/literate/hyperelasticity.jl index 9cfc2da750..87a5d2745b 100644 --- a/docs/src/literate/hyperelasticity.jl +++ b/docs/src/literate/hyperelasticity.jl @@ -398,7 +398,7 @@ function solve() ## Save the solution @timeit "export" begin vtk_grid("hyperelasticity", dh) do vtkfile - vtk_point_data(vtkfile, dh, u) + vtk_node_data(vtkfile, dh, u) end end diff --git a/docs/src/literate/incompressible_elasticity.jl b/docs/src/literate/incompressible_elasticity.jl index 0cc44012c3..453c7c7146 100644 --- a/docs/src/literate/incompressible_elasticity.jl +++ b/docs/src/literate/incompressible_elasticity.jl @@ -210,7 +210,7 @@ function solve(ν, interpolation_u, interpolation_p) filename = "cook_" * (isa(interpolation_u, Lagrange{2,RefTetrahedron,1}) ? "linear" : "quadratic") * "_linear" vtk_grid(filename, dh) do vtkfile - vtk_point_data(vtkfile, dh, u) + vtk_node_data(vtkfile, dh, u) end return u end diff --git a/docs/src/literate/landau.jl b/docs/src/literate/landau.jl index f628ee0c52..59f7dff396 100644 --- a/docs/src/literate/landau.jl +++ b/docs/src/literate/landau.jl @@ -114,7 +114,7 @@ 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_node_data(vtkfile, model.dofhandler, dofs) vtk_save(vtkfile) end diff --git a/docs/src/literate/linear_shell.jl b/docs/src/literate/linear_shell.jl index 7fa3b51938..5d0eca922e 100644 --- a/docs/src/literate/linear_shell.jl +++ b/docs/src/literate/linear_shell.jl @@ -114,7 +114,7 @@ a = K\f # Output results. #+ vtk_grid("linear_shell", dh) do vtk - vtk_point_data(vtk, dh, a) + vtk_node_data(vtk, dh, a) end end; #end main functions diff --git a/docs/src/literate/ns_vs_diffeq.jl b/docs/src/literate/ns_vs_diffeq.jl index c31247eb8e..519508efca 100644 --- a/docs/src/literate/ns_vs_diffeq.jl +++ b/docs/src/literate/ns_vs_diffeq.jl @@ -442,7 +442,7 @@ for (u_uc,t) in integrator u = copy(u_uc) apply!(u, ch) vtk_grid("vortex-street-$t.vtu", dh) do vtk - vtk_point_data(vtk,dh,u) + vtk_node_data(vtk, dh,u) vtk_save(vtk) pvd[t] = vtk end diff --git a/docs/src/literate/plasticity.jl b/docs/src/literate/plasticity.jl index 243322744a..440f3e0e2c 100644 --- a/docs/src/literate/plasticity.jl +++ b/docs/src/literate/plasticity.jl @@ -346,7 +346,7 @@ function solve() κ_values[el] /= length(cell_states) # average drag stress end vtk_grid("plasticity", dh) do vtkfile - vtk_point_data(vtkfile, dh, u) # displacement field + vtk_node_data(vtkfile, dh, u) # displacement field vtk_cell_data(vtkfile, mises_values, "von Mises [Pa]") vtk_cell_data(vtkfile, κ_values, "Drag stress [Pa]") end diff --git a/docs/src/literate/postprocessing.jl b/docs/src/literate/postprocessing.jl index 3c3afc184f..0e5428c1c6 100644 --- a/docs/src/literate/postprocessing.jl +++ b/docs/src/literate/postprocessing.jl @@ -88,7 +88,7 @@ q_projected = project(projector, q_gp, qr; project_to_nodes=false); # TODO: this # 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") + vtk_node_data(vtk, projector, q_projected, "q") end; # ## Point Evaluation diff --git a/docs/src/literate/quasi_incompressible_hyperelasticity.jl b/docs/src/literate/quasi_incompressible_hyperelasticity.jl index dda1e87f70..748a03abbb 100644 --- a/docs/src/literate/quasi_incompressible_hyperelasticity.jl +++ b/docs/src/literate/quasi_incompressible_hyperelasticity.jl @@ -338,7 +338,7 @@ function solve(interpolation_u, interpolation_p) ## Save the solution fields vtk_grid("hyperelasticity_incomp_mixed_$t.vtu", dh) do vtkfile - vtk_point_data(vtkfile, dh, w) + vtk_node_data(vtkfile, dh, w) vtk_save(vtkfile) pvd[t] = vtkfile end diff --git a/docs/src/literate/stokes-flow.jl b/docs/src/literate/stokes-flow.jl index 5744146e70..5b64439805 100644 --- a/docs/src/literate/stokes-flow.jl +++ b/docs/src/literate/stokes-flow.jl @@ -505,7 +505,7 @@ function main() apply!(u, ch) ## Export the solution vtk_grid("stokes-flow", grid) do vtk - vtk_point_data(vtk, dh, u) + vtk_node_data(vtk, dh, u) end ## Check the result #src diff --git a/docs/src/literate/transient_heat_equation.jl b/docs/src/literate/transient_heat_equation.jl index 42a4956cf5..50679481f9 100644 --- a/docs/src/literate/transient_heat_equation.jl +++ b/docs/src/literate/transient_heat_equation.jl @@ -194,7 +194,7 @@ apply!(A, ch); pvd = paraview_collection("transient-heat.pvd"); t = 0 vtk_grid("transient-heat-$t", dh) do vtk - vtk_point_data(vtk, dh, uₙ) + vtk_node_data(vtk, dh, uₙ) vtk_save(vtk) pvd[t] = vtk end @@ -213,7 +213,7 @@ for t in Δt:Δt:T u = A \ b vtk_grid("transient-heat-$t", dh) do vtk - vtk_point_data(vtk, dh, u) + vtk_node_data(vtk, dh, u) vtk_save(vtk) pvd[t] = vtk end diff --git a/docs/src/manual/export.md b/docs/src/manual/export.md index 46af5b8c20..bf8bed7b1c 100644 --- a/docs/src/manual/export.md +++ b/docs/src/manual/export.md @@ -71,7 +71,7 @@ vector `u`: ```@example export vtk = vtk_grid("my-solution", dh) -vtk_point_data(vtk, dh, u) +vtk_node_data(vtk, dh, u) vtk_save(vtk) rm("my-solution.vtu") # hide ``` @@ -80,26 +80,26 @@ or with a `do`-block: ```@example export vtk_grid("my-solution", dh) do vtk - vtk_point_data(vtk, dh, u) + vtk_node_data(vtk, dh, u) vtk_cell_data(vtk, σ, "my-cell-data") end rm("my-solution.vtu") # hide ``` -When `vtk_point_data` is used with a `DofHandler` all of the fields will be +When `vtk_node_data` is used with a `DofHandler` all of the fields will be written to the VTK file, and the names will be determined by the fieldname symbol that was used when the field was added to the `DofHandler`. ## Exporting Boundary Conditions -There is also a `vtk_point_data` which accepts a `ConstraintHandler`. +There is also a `vtk_node_data` which accepts a `ConstraintHandler`. This method is useful to verify that the boundary conditions are applied where they are supposed to. For a `ConstraintHandler` `ch` we can export the boundary conditions as ```julia vtk_grid("boundary-conditions", grid) do vtk - vtk_point_data(vtk, ch) + vtk_node_data(vtk, ch) end ``` diff --git a/src/Dofs/ConstraintHandler.jl b/src/Dofs/ConstraintHandler.jl index 14eb3664a0..706fca8f84 100644 --- a/src/Dofs/ConstraintHandler.jl +++ b/src/Dofs/ConstraintHandler.jl @@ -468,7 +468,7 @@ end # Saves the dirichlet boundary conditions to a vtkfile. # Values will have a 1 where bcs are active and 0 otherwise -function WriteVTK.vtk_point_data(vtkfile, ch::ConstraintHandler) +function vtk_node_data(vtkfile, ch::ConstraintHandler) unique_fields = [] for dbc in ch.dbcs push!(unique_fields, dbc.field_name) diff --git a/src/Export/VTK.jl b/src/Export/VTK.jl index 9a1cf6de6e..395b72c12b 100644 --- a/src/Export/VTK.jl +++ b/src/Export/VTK.jl @@ -22,7 +22,7 @@ nodes_to_vtkorder(cell::AbstractCell) = collect(cell.nodes) vtk_grid(filename::AbstractString, grid::Grid) Create a unstructured VTK grid from a `Grid`. Return a `DatasetFile` -which data can be appended to, see `vtk_point_data` and `vtk_cell_data`. +which data can be appended to, see [`vtk_node_data`](@ref) and [`vtk_cell_data`](@ref). """ function WriteVTK.vtk_grid(filename::AbstractString, grid::Grid{dim,C,T}; compress::Bool=true) where {dim,C,T} cls = MeshCell[] @@ -44,10 +44,15 @@ end """ vtk_point_data(vtk, data::Vector{<:AbstractTensor}, name) -Write the tensor field `data` to the vtk file. Two-dimensional tensors are padded with zeros. +Write the `data` that is ordered by the nodes in the grid to the vtk file, +with one entry for each component. +The components of two-dimensional tensors are padded with zeros. For second order tensors the following indexing ordering is used: `[11, 22, 33, 23, 13, 12, 32, 31, 21]`. This is the default Voigt order in Tensors.jl. + +(Note that `WriteVTK.jl` already defines this function for scalar elements in `data`, +and this is reexported by `Ferrite.jl`.) """ function WriteVTK.vtk_point_data( vtk::WriteVTK.DatasetFile, @@ -112,8 +117,20 @@ function WriteVTK.vtk_grid(filename::AbstractString, dh::AbstractDofHandler; com vtk_grid(filename, dh.grid; compress=compress) end -function WriteVTK.vtk_point_data(vtkfile, dh::AbstractDofHandler, u::Vector, suffix="") +""" + vtk_node_data(vtkfile, dh::AbstractDofHandler, u::Vector, suffix="") + +Save the values at the nodes in the degree of freedom vector `u` to a +the `vtkfile` for each field in `dh`. `suffix` can be used to append to the fieldname. +The `vtkfile` is typically created by the [`vtk_grid`](@ref) function. + +`u` can also contain tensorial values, but each entry in `u` must correspond to a degree of freedom in `dh`, +see [`vtk_point_data`](@ref) for details. This function should be used directly when exporting values already +sorted by the nodes in the grid. +""" +function vtk_node_data(vtkfile, dh::AbstractDofHandler, u::Vector, suffix="") + fieldnames = Ferrite.getfieldnames(dh) # all primary fields for name in fieldnames diff --git a/src/L2_projection.jl b/src/L2_projection.jl index d65bfd0180..7cae68bcdc 100644 --- a/src/L2_projection.jl +++ b/src/L2_projection.jl @@ -277,7 +277,7 @@ function _project(vars, proj::L2Projector, fe_values::Values, M::Integer, ::Type return T[make_T(x) for x in eachrow(projected_vals)] end -function WriteVTK.vtk_point_data(vtk::WriteVTK.DatasetFile, proj::L2Projector, vals::Vector{T}, name::AbstractString) where T +function vtk_node_data(vtk::WriteVTK.DatasetFile, proj::L2Projector, vals::Vector{T}, name::AbstractString) where T data = reshape_to_nodes(proj, vals) @assert size(data, 2) == getnnodes(proj.dh.grid) vtk_point_data(vtk, data, name; component_names=component_names(T)) diff --git a/src/exports.jl b/src/exports.jl index 8933912339..dbc808628b 100644 --- a/src/exports.jl +++ b/src/exports.jl @@ -148,6 +148,7 @@ export # VTK export vtk_grid, vtk_point_data, + vtk_node_data, vtk_cell_data, vtk_nodeset, vtk_cellset, diff --git a/test/test_grid_dofhandler_vtk.jl b/test/test_grid_dofhandler_vtk.jl index 67c7e12d1c..ebfb9fcdb9 100644 --- a/test/test_grid_dofhandler_vtk.jl +++ b/test/test_grid_dofhandler_vtk.jl @@ -75,8 +75,8 @@ end dofhandlerfilename = "dofhandler-$(repr(celltype))" vtk_grid(dofhandlerfilename, dofhandler) do vtk - vtk_point_data(vtk, ch) - vtk_point_data(vtk, dofhandler, u) + vtk_node_data(vtk, ch) + vtk_node_data(vtk, dofhandler, u) end # test the sha of the file diff --git a/test/test_l2_projection.jl b/test/test_l2_projection.jl index 6c19a39c29..9923626d35 100644 --- a/test/test_l2_projection.jl +++ b/test/test_l2_projection.jl @@ -301,10 +301,10 @@ function test_export(;subset::Bool) mktempdir() do tmp fname = vtk_grid(joinpath(tmp, "projected"), grid) do vtk - vtk_point_data(vtk, p, p_scalar, "p_scalar") - vtk_point_data(vtk, p, p_vec, "p_vec") - vtk_point_data(vtk, p, p_tens, "p_tens") - vtk_point_data(vtk, p, p_stens, "p_stens") + vtk_node_data(vtk, p, p_scalar, "p_scalar") + vtk_node_data(vtk, p, p_vec, "p_vec") + vtk_node_data(vtk, p, p_tens, "p_tens") + vtk_node_data(vtk, p, p_stens, "p_stens") end @test bytes2hex(open(SHA.sha1, fname[1], "r")) in ( subset ? ("261cfe21de7a478e14f455e783694651a91eeb60", "b3fef3de9f38ca9ddd92f2f67a1606d07ca56d67") : diff --git a/test/test_mixeddofhandler.jl b/test/test_mixeddofhandler.jl index f6158def50..e72eecd035 100644 --- a/test/test_mixeddofhandler.jl +++ b/test/test_mixeddofhandler.jl @@ -370,7 +370,7 @@ function test_2_element_heat_eq() vtk_grid(gridfilename, grid) do vtk vtk_cellset(vtk, grid, "cell-1") vtk_cellset(vtk, grid, "cell-2") - vtk_point_data(vtk, dh, u) + vtk_node_data(vtk, dh, u) # vtk_point_data(vtk, ch) #FIXME end sha = bytes2hex(open(SHA.sha1, gridfilename*".vtu")) From 6c03c70b5b9c76db7c3f077f7db235e0d6769dd0 Mon Sep 17 00:00:00 2001 From: Knut Andreas Meyer Date: Mon, 1 May 2023 11:21:47 +0200 Subject: [PATCH 02/67] First attempts on VTKStream --- docs/src/literate/heat_equation.jl | 4 +- src/Dofs/ConstraintHandler.jl | 36 ---- src/Export/VTK.jl | 257 ++++++++++++++++++++++------- 3 files changed, 195 insertions(+), 102 deletions(-) diff --git a/docs/src/literate/heat_equation.jl b/docs/src/literate/heat_equation.jl index 240448ad1c..95c2e66c05 100644 --- a/docs/src/literate/heat_equation.jl +++ b/docs/src/literate/heat_equation.jl @@ -214,8 +214,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_node_data(vtk, dh, u) +Ferrite.open_vtk("heat_equation_new", dh) do vtk + Ferrite.write_solution(vtk, u) end ## test the result #src diff --git a/src/Dofs/ConstraintHandler.jl b/src/Dofs/ConstraintHandler.jl index 706fca8f84..ac8c0b24c4 100644 --- a/src/Dofs/ConstraintHandler.jl +++ b/src/Dofs/ConstraintHandler.jl @@ -466,42 +466,6 @@ function _update!(inhomogeneities::Vector{Float64}, f::Function, ::Set{Int}, fie end end -# Saves the dirichlet boundary conditions to a vtkfile. -# Values will have a 1 where bcs are active and 0 otherwise -function vtk_node_data(vtkfile, ch::ConstraintHandler) - unique_fields = [] - for dbc in ch.dbcs - push!(unique_fields, dbc.field_name) - end - unique!(unique_fields) - - for field in unique_fields - nd = getfielddim(ch.dh, field) - data = zeros(Float64, nd, getnnodes(ch.dh.grid)) - for dbc in ch.dbcs - dbc.field_name != field && continue - if eltype(dbc.faces) <: BoundaryIndex - functype = boundaryfunction(eltype(dbc.faces)) - for (cellidx, faceidx) in dbc.faces - for facenode in functype(ch.dh.grid.cells[cellidx])[faceidx] - for component in dbc.components - data[component, facenode] = 1 - end - end - end - else - for nodeidx in dbc.faces - for component in dbc.components - data[component, nodeidx] = 1 - end - end - end - end - vtk_point_data(vtkfile, data, string(field, "_bc")) - end - return vtkfile -end - """ apply!(K::SparseMatrixCSC, rhs::AbstractVector, ch::ConstraintHandler) diff --git a/src/Export/VTK.jl b/src/Export/VTK.jl index 7110df0731..1517887746 100644 --- a/src/Export/VTK.jl +++ b/src/Export/VTK.jl @@ -1,3 +1,71 @@ +struct VTKStream{VTK<:WriteVTK.DatasetFile, DH<:Union{DofHandler,Grid}} + filename::String # Just to allow easy printing + vtk::VTK + grid_or_dh::DH +end +""" + Base.close(vtks::VTKStream) + +Close the vtk stream and save the data to disk. +""" +Base.close(vtks::VTKStream) = WriteVTK.vtk_save(vtks.vtk) + +""" + open_vtk(filename::AbstractString, dh::Union{DofHandler,Grid}; kwargs...) + +Create a `Ferrite.VTKStream` that contains an unstructured VTK grid from +a `DofHandler` (limited functionality if only a `Grid` is given). +This stream can be used to to write data with +[`write_solution`](@ref), [`write_celldata`](@ref), [`write_nodedata`](@ref), +[`write_cellset`](@ref), [`write_nodeset`](@ref), and [`write_constraints`](@ref). + +The keyword arguments are forwarded to `WriteVTK.vtk_grid`, see +[Data Formatting Options](https://juliavtk.github.io/WriteVTK.jl/stable/grids/syntax/#Data-formatting-options) + +It is necessary to call [`close`](@ref) to save the data after writing to the stream, +or alternatively use the `do`-block syntax which does this implicitly, e.g., +```julia +open_vtk(filename, dh) do vtk + write_solution(vtk, u) + write_celldata(vtk, celldata) +end +""" +function open_vtk(filename::String, grid_or_dh; kwargs...) + vtk = create_vtk_grid(filename, grid_or_dh; kwargs...) + return VTKStream(filename, vtk, grid_or_dh) +end +# Makes it possible to use the `do`-block syntax +function open_vtk(f::Function, args...; kwargs...) + vtks = open_vtk(args...; kwargs...) + try + f(vtks) + finally + close(vtks) + end +end + +isopen(vtks::VTKStream) = WriteVTK.isopen(vtks.vtk) + +function show(io::IO, ::MIME"text/plain", vtks::VTKStream) + open_str = isopen(vtk) ? "open" : "closed" + if isa(vtks.grid_or_dh, DofHandler) + dh_string = "DofHandler" + elseif isa(vtks.grid_or_dh, Grid) + dh_string = "Grid" + else + dh_string = string(typeof(vtks.grid_or_dh)) + end + print(io, "VTKStream for the $open_str file \"$(vtk.path)\" based on a $dh_string") +end + +getgrid(vtks::VTKStream{<:Any,<:DofHandler}) = vtks.grid_or_dh.grid +getgrid(vtks::VTKStream{<:Any,<:Grid}) = vtks.grid_or_dh + +# Support ParaviewCollection +function WriteVTK.collection_add_timestep(pvd::WriteVTK.CollectionFile, vtks::VTKStream, time::Real) + WriteVTK.collection_add_timestep(pvd, vtks.vtk, time) +end + cell_to_vtkcell(::Type{Line}) = VTKCellTypes.VTK_LINE cell_to_vtkcell(::Type{QuadraticLine}) = VTKCellTypes.VTK_QUADRATIC_EDGE @@ -15,17 +83,7 @@ cell_to_vtkcell(::Type{Wedge}) = VTKCellTypes.VTK_WEDGE nodes_to_vtkorder(cell::AbstractCell) = collect(cell.nodes) -""" - vtk_grid(filename::AbstractString, grid::Grid; kwargs...) - vtk_grid(filename::AbstractString, dh::DofHandler; kwargs...) - -Create a unstructured VTK grid from `grid` (alternatively from the `grid` stored in `dh`). -Return a `DatasetFile` that data can be appended to, see -[`vtk_node_data`](@ref), [`vtk_point_data`](@ref), and [`vtk_cell_data`](@ref). -The keyword arguments are forwarded to `WriteVTK.vtk_grid`, see -[Data Formatting Options](https://juliavtk.github.io/WriteVTK.jl/stable/grids/syntax/#Data-formatting-options) -""" -function WriteVTK.vtk_grid(filename::AbstractString, grid::Grid{dim,C,T}; kwargs...) where {dim,C,T} +function create_vtk_grid(filename::AbstractString, grid::Grid{dim,C,T}; kwargs...) where {dim,C,T} cls = MeshCell[] for cell in grid.cells celltype = Ferrite.cell_to_vtkcell(typeof(cell)) @@ -34,8 +92,8 @@ function WriteVTK.vtk_grid(filename::AbstractString, grid::Grid{dim,C,T}; kwargs coords = reshape(reinterpret(T, getnodes(grid)), (dim, getnnodes(grid))) return vtk_grid(filename, coords, cls; kwargs...) end -function WriteVTK.vtk_grid(filename::AbstractString, dh::AbstractDofHandler; kwargs...) - vtk_grid(filename, dh.grid; kwargs...) +function create_vtk_grid(filename::AbstractString, dh::AbstractDofHandler; kwargs...) + create_vtk_grid(filename, dh.grid; kwargs...) end function toparaview!(v, x::Vec{D}) where D @@ -45,31 +103,24 @@ function toparaview!(v, x::SecondOrderTensor{D}) where D tovoigt!(v, x) end -""" - vtk_point_data(vtk, data::Vector{<:AbstractTensor}, name) - -Write the `data` that is ordered by the nodes in the grid to the vtk file, -with one entry for each component. -The components of two-dimensional tensors are padded with zeros. - -For second order tensors the following indexing ordering is used: -`[11, 22, 33, 23, 13, 12, 32, 31, 21]`. This is the default Voigt order in Tensors.jl. - -(Note that `WriteVTK.jl` already defines this function for scalar elements in `data`, -and this is reexported by `Ferrite.jl`.) -""" -function WriteVTK.vtk_point_data( +function _vtk_write_nodedata( vtk::WriteVTK.DatasetFile, - data::Vector{S}, + nodedata::Vector{S}, name::AbstractString ) where {O, D, T, M, S <: Union{Tensor{O, D, T, M}, SymmetricTensor{O, D, T, M}}} noutputs = S <: Vec{2} ? 3 : M # Pad 2D Vec to 3D - npoints = length(data) + npoints = length(nodedata) out = zeros(T, noutputs, npoints) for i in 1:npoints - toparaview!(@view(out[:, i]), data[i]) + toparaview!(@view(out[:, i]), nodedata[i]) end - return vtk_point_data(vtk, out, name; component_names=component_names(S)) + return WriteVTK.vtk_point_data(vtk, out, name; component_names=component_names(S)) +end +function _vtk_write_nodedata(vtk::WriteVTK.DatasetFile, nodedata::Vector{<:Real}, name::AbstractString) + return WriteVTK.vtk_point_data(vtk, nodedata, name) +end +function _vtk_write_nodedata(vtk::WriteVTK.DatasetFile, nodedata::Matrix{<:Real}, name::AbstractString) + return WriteVTK.vtk_point_data(vtk, nodedata, name) end function component_names(::Type{S}) where S @@ -86,58 +137,136 @@ function component_names(::Type{S}) where S return names end -function vtk_nodeset(vtk::WriteVTK.DatasetFile, grid::Grid{dim}, nodeset::String) where {dim} - z = zeros(getnnodes(grid)) - z[collect(getnodeset(grid, nodeset))] .= 1.0 - vtk_point_data(vtk, z, nodeset) + +function _vtk_write_solution(vtkfile, dh, u::Vector, suffix) + fieldnames = Ferrite.getfieldnames(dh) # all primary fields + + for name in fieldnames + data = reshape_to_nodes(dh, u, name) + _vtk_write_nodedata(vtkfile, data, string(name, suffix)) + end + return nothing end """ - vtk_cellset(vtk, grid::Grid) + write_solution(vtks::VTKStream, u::Vector, suffix="") + +Save the values at the nodes in the degree of freedom vector `u` to a +the `vtkfile` for each field in `DofHandler` in `vtks`. +`suffix` can be used to append to the fieldname. +`vtks` is typically created by the [`open_vtk`](@ref) function. -Export all cell sets in the grid. Each cell set is exported with -`vtk_cell_data` with value 1 if the cell is in the set, and 0 otherwise. +`u` can also contain tensorial values, but each entry in `u` must correspond to a degree of freedom in `dh`, +see [`write_nodedata`](@ref) for details. This function should be used directly when exporting values already +sorted by the nodes in the grid. """ -function vtk_cellset(vtk::WriteVTK.DatasetFile, grid::AbstractGrid, cellsets=keys(grid.cellsets)) - z = zeros(getncells(grid)) - for cellset in cellsets - z .= 0.0 - z[collect(getcellset(grid, cellset))] .= 1.0 - vtk_cell_data(vtk, z, cellset) - end - return vtk +function write_solution(vtks::VTKStream, u, suffix="") + _vtk_write_solution(vtks.vtk, vtks.grid_or_dh, u, suffix) + return vtks end """ - vtk_cellset(vtk, grid::Grid, cellset::String) + write_celldata(vtks::VTKStream, celldata, name) -Export the cell set specified by `cellset` as cell data with value 1 if -the cell is in the set and 0 otherwise. +Write the `celldata` that is ordered by the cells in the grid to the vtk file. """ -vtk_cellset(vtk::WriteVTK.DatasetFile, grid::AbstractGrid, cellset::String) = - vtk_cellset(vtk, grid, [cellset]) +function write_celldata(vtks::VTKStream, celldata, name) + WriteVTK.vtk_cell_data(vtks.vtk, celldata, name) +end +""" + write_nodedata(vtks::VTKStream, nodedata::Vector{Real}, name) + write_nodedata(vtks::VTKStream, nodedata::Vector{<:AbstractTensor}, name) + +Write the `nodedata` that is ordered by the nodes in the grid to the vtk file. +When `nodedata` contains `Tensors.Vec`s, each component is exported. +Two-dimensional vectors are padded with zeros. +When `nodedata` contains second order tensors, the index order, +`[11, 22, 33, 23, 13, 12, 32, 31, 21]`, follows the default Voigt order in Tensors.jl. """ - vtk_node_data(vtkfile, dh::AbstractDofHandler, u::Vector, suffix="") +function write_nodedata(vtks::VTKStream, nodedata, name) + _vtk_write_nodedata(vtks.vtk, nodedata, name) +end -Save the values at the nodes in the degree of freedom vector `u` to a -the `vtkfile` for each field in `dh`. `suffix` can be used to append to the fieldname. -The `vtkfile` is typically created by the [`vtk_grid`](@ref) function. -`u` can also contain tensorial values, but each entry in `u` must correspond to a degree of freedom in `dh`, -see [`vtk_point_data`](@ref) for details. This function should be used directly when exporting values already -sorted by the nodes in the grid. """ -function vtk_node_data(vtkfile, dh::AbstractDofHandler, u::Vector, suffix="") + write_nodeset(vtks::VTKStream, nodeset::String) + +Export nodal values of 1 for nodes in `nodeset`, and 0 otherwise +""" +function write_nodeset(vtks::VTKStream, nodeset::String) + grid = getgrid(vtks) + z = zeros(getnnodes(grid)) + z[collect(getnodeset(grid, nodeset))] .= 1.0 + WriteVTK.vtk_point_data(vtks.vtk, z, nodeset) + return vtks +end + +""" + write_cellset(vtk) + write_cellset(vtk, cellset::String) + write_cellset(vtk, cellsets::Union{AbstractVector{String},AbstractSet{String}) + +Export all cell sets in the grid with name according to their keys and +celldata 1 if the cell is in the set, and 0 otherwise. It is also possible to +only export a single `cellset`, or multiple `cellsets`. +""" +function write_cellset(vtks::VTKStream, cellsets=keys(grid.cellsets)) + grid = getgrid(vtks) + z = zeros(getncells(grid)) + for cellset in cellsets + z .= 0.0 + z[collect(getcellset(grid, cellset))] .= 1.0 + vtk_cell_data(vtks.vtk, z, cellset) + end + return vtks +end +write_cellset(vtks::VTKStream, cellset::String) = vtk_cellset(vtks, [cellset]) + +""" + write_dirichlet(vtks::VTKStream, ch::ConstraintHandler) + +Saves the dirichlet boundary conditions to a vtkfile. +Values will have a 1 where bcs are active and 0 otherwise +""" +function write_dirichlet(vtks::VTKStream, ch::ConstraintHandler) - fieldnames = Ferrite.getfieldnames(dh) # all primary fields + if getgrid(vtks) !== ch.dh.grid + @warn("The grid saved in VTKStream and ConstraintHandler are not aliased, no checks are performed to ensure that they are equal") + end + vtkfile = vtks.vtk - for name in fieldnames - data = reshape_to_nodes(dh, u, name) - vtk_point_data(vtkfile, data, string(name, suffix)) + unique_fields = [] + for dbc in ch.dbcs + push!(unique_fields, dbc.field_name) end + unique!(unique_fields) + for field in unique_fields + nd = getfielddim(ch.dh, field) + data = zeros(Float64, nd, getnnodes(ch.dh.grid)) + for dbc in ch.dbcs + dbc.field_name != field && continue + if eltype(dbc.faces) <: BoundaryIndex + functype = boundaryfunction(eltype(dbc.faces)) + for (cellidx, faceidx) in dbc.faces + for facenode in functype(ch.dh.grid.cells[cellidx])[faceidx] + for component in dbc.components + data[component, facenode] = 1 + end + end + end + else + for nodeidx in dbc.faces + for component in dbc.components + data[component, nodeidx] = 1 + end + end + end + end + WriteVTK.vtk_point_data(vtkfile, data, string(field, "_bc")) + end return vtkfile -end +end \ No newline at end of file From 9a89a1a435cbbca317c426911c54881a0dc1494d Mon Sep 17 00:00:00 2001 From: Knut Andreas Meyer Date: Mon, 1 May 2023 13:15:32 +0200 Subject: [PATCH 03/67] Fix deprecations, stage 1 --- docs/src/literate/heat_equation.jl | 3 +++ src/Export/VTK.jl | 24 ++++++++++++++++++------ src/L2_projection.jl | 7 ------- src/deprecations.jl | 16 ++++++++++++++++ 4 files changed, 37 insertions(+), 13 deletions(-) diff --git a/docs/src/literate/heat_equation.jl b/docs/src/literate/heat_equation.jl index 95c2e66c05..8807c1cbd0 100644 --- a/docs/src/literate/heat_equation.jl +++ b/docs/src/literate/heat_equation.jl @@ -217,6 +217,9 @@ u = K \ f; Ferrite.open_vtk("heat_equation_new", dh) do vtk Ferrite.write_solution(vtk, u) end +vtk_grid("heat_equation_old", dh) do vtk + vtk_point_data(vtk, dh, u) +end ## test the result #src using Test #src diff --git a/src/Export/VTK.jl b/src/Export/VTK.jl index 1517887746..9744980aed 100644 --- a/src/Export/VTK.jl +++ b/src/Export/VTK.jl @@ -116,10 +116,7 @@ function _vtk_write_nodedata( end return WriteVTK.vtk_point_data(vtk, out, name; component_names=component_names(S)) end -function _vtk_write_nodedata(vtk::WriteVTK.DatasetFile, nodedata::Vector{<:Real}, name::AbstractString) - return WriteVTK.vtk_point_data(vtk, nodedata, name) -end -function _vtk_write_nodedata(vtk::WriteVTK.DatasetFile, nodedata::Matrix{<:Real}, name::AbstractString) +function _vtk_write_nodedata(vtk::WriteVTK.DatasetFile, nodedata::Union{Vector{<:Real},Matrix{<:Real}}, name::AbstractString) return WriteVTK.vtk_point_data(vtk, nodedata, name) end @@ -152,7 +149,7 @@ end write_solution(vtks::VTKStream, u::Vector, suffix="") Save the values at the nodes in the degree of freedom vector `u` to a -the `vtkfile` for each field in `DofHandler` in `vtks`. +the a vtk file for each field in `DofHandler` in `vtks`. `suffix` can be used to append to the fieldname. `vtks` is typically created by the [`open_vtk`](@ref) function. @@ -165,6 +162,21 @@ function write_solution(vtks::VTKStream, u, suffix="") return vtks end +""" + write_projection(vtks::VTKStream, proj::L2Projector, vals::Vector, name::AbstractString) + +Write `vals` that have been projected with `proj` to the vtk file in `vtks` +""" +function write_projection(vtks::VTKStream, proj::L2Projector, vals, name) + if getgrid(vtks) !== proj.dh.grid + @warn("The grid saved in VTKStream and L2Projector are not aliased, no checks are performed to ensure that they are equal") + end + nodedata = reshape_to_nodes(proj, vals) + @assert size(nodedata, 2) == getnnodes(proj.dh.grid) + _vtk_write_nodedata(vtks.vtk, nodedata, name) + return vtks +end + """ write_celldata(vtks::VTKStream, celldata, name) @@ -223,7 +235,7 @@ function write_cellset(vtks::VTKStream, cellsets=keys(grid.cellsets)) end return vtks end -write_cellset(vtks::VTKStream, cellset::String) = vtk_cellset(vtks, [cellset]) +write_cellset(vtks::VTKStream, cellset::String) = write_cellset(vtks, [cellset]) """ write_dirichlet(vtks::VTKStream, ch::ConstraintHandler) diff --git a/src/L2_projection.jl b/src/L2_projection.jl index 7cae68bcdc..7b4ea3c39b 100644 --- a/src/L2_projection.jl +++ b/src/L2_projection.jl @@ -277,13 +277,6 @@ function _project(vars, proj::L2Projector, fe_values::Values, M::Integer, ::Type return T[make_T(x) for x in eachrow(projected_vals)] end -function vtk_node_data(vtk::WriteVTK.DatasetFile, proj::L2Projector, vals::Vector{T}, name::AbstractString) where T - data = reshape_to_nodes(proj, vals) - @assert size(data, 2) == getnnodes(proj.dh.grid) - vtk_point_data(vtk, data, name; component_names=component_names(T)) - return vtk -end - # Numbers can be handled by the method for DofHandler reshape_to_nodes(proj::L2Projector, vals::AbstractVector{<:Number}) = reshape_to_nodes(proj.dh, vals, only(getfieldnames(proj.dh))) diff --git a/src/deprecations.jl b/src/deprecations.jl index 9214c9abb4..4acc0986e4 100644 --- a/src/deprecations.jl +++ b/src/deprecations.jl @@ -57,3 +57,19 @@ Base.@deprecate_binding Line2D Line Base.@deprecate_binding Line3D Line Base.@deprecate_binding Quadrilateral3D Quadrilateral export Line2D, Line3D, Quadrilateral3D + +# REMOVE ME! (the following is just to avoid renaming back to vtk_point_data before new renaming again) +@deprecate vtk_node_data(args...; kwargs...) vtk_point_data(args...; kwargs...) + +import WriteVTK: vtk_grid, vtk_cell_data, vtk_point_data, vtk_save + +@deprecate vtk_grid(filename::String, grid::AbstractGrid; kwargs...) open_vtk(filename, grid; kwargs...) +@deprecate vtk_grid(filename::String, dh::DofHandler; kwargs...) open_vtk(filename, dh; kwargs...) +@deprecate vtk_cell_data(vtks::VTKStream, args...) write_celldata(vtks, args...) +@deprecate vtk_point_data(vtks::VTKStream, dh::DofHandler, u, suffix="") (_vtk_write_solution(vtks.vtk, dh, u, suffix); vtks) +@deprecate vtk_point_data(vtks::VTKStream, data::Vector, args...) write_nodedata(vtks, data, args...) +@deprecate vtk_point_data(vtks::VTKStream, proj::L2Projector, args...) write_projection(vtks, proj, args...) +@deprecate vtk_point_data(vtks::VTKStream, ch::ConstraintHandler) write_dirichlet(vtks, ch) +@deprecate vtk_cellset(vtks::VTKStream, grid::AbstractGrid, args...) write_cellset(vtks, args...) +@deprecate vtk_nodeset(vtks::VTKStream, grid::AbstractGrid, args...) write_nodeset(vtks, args...) +@deprecate vtk_save(vtks::VTKStream) close(vtks) \ No newline at end of file From 53c9875f83e392ea20e51195c264049b05d88f72 Mon Sep 17 00:00:00 2001 From: Knut Andreas Meyer Date: Mon, 1 May 2023 14:10:27 +0200 Subject: [PATCH 04/67] Make tests pass without updates --- src/Export/VTK.jl | 18 ++++++++++++------ src/deprecations.jl | 6 ++++-- 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/src/Export/VTK.jl b/src/Export/VTK.jl index 9744980aed..f520a6a4b5 100644 --- a/src/Export/VTK.jl +++ b/src/Export/VTK.jl @@ -62,6 +62,9 @@ getgrid(vtks::VTKStream{<:Any,<:DofHandler}) = vtks.grid_or_dh.grid getgrid(vtks::VTKStream{<:Any,<:Grid}) = vtks.grid_or_dh # Support ParaviewCollection +function Base.setindex!(pvd::WriteVTK.CollectionFile, vtks::VTKStream, time::Real) + WriteVTK.collection_add_timestep(pvd, vtks, time) +end function WriteVTK.collection_add_timestep(pvd::WriteVTK.CollectionFile, vtks::VTKStream, time::Real) WriteVTK.collection_add_timestep(pvd, vtks.vtk, time) end @@ -114,13 +117,16 @@ function _vtk_write_nodedata( for i in 1:npoints toparaview!(@view(out[:, i]), nodedata[i]) end - return WriteVTK.vtk_point_data(vtk, out, name; component_names=component_names(S)) + return WriteVTK.vtk_point_data(vtk, out, name; component_names=get_component_names(S)) end -function _vtk_write_nodedata(vtk::WriteVTK.DatasetFile, nodedata::Union{Vector{<:Real},Matrix{<:Real}}, name::AbstractString) +function _vtk_write_nodedata(vtk::WriteVTK.DatasetFile, nodedata::Vector{<:Real}, name::AbstractString) return WriteVTK.vtk_point_data(vtk, nodedata, name) end +function _vtk_write_nodedata(vtk::WriteVTK.DatasetFile, nodedata::Matrix{<:Real}, name::AbstractString; component_names=nothing) + return WriteVTK.vtk_point_data(vtk, nodedata, name; component_names=component_names) +end -function component_names(::Type{S}) where S +function get_component_names(::Type{S}) where S names = S <: Vec{1} ? ["x"] : S <: Vec ? ["x", "y", "z"] : # Pad 2D Vec to 3D @@ -163,17 +169,17 @@ function write_solution(vtks::VTKStream, u, suffix="") end """ - write_projection(vtks::VTKStream, proj::L2Projector, vals::Vector, name::AbstractString) + write_projected(vtks::VTKStream, proj::L2Projector, vals::Vector, name::AbstractString) Write `vals` that have been projected with `proj` to the vtk file in `vtks` """ -function write_projection(vtks::VTKStream, proj::L2Projector, vals, name) +function write_projected(vtks::VTKStream, proj::L2Projector, vals, name) if getgrid(vtks) !== proj.dh.grid @warn("The grid saved in VTKStream and L2Projector are not aliased, no checks are performed to ensure that they are equal") end nodedata = reshape_to_nodes(proj, vals) @assert size(nodedata, 2) == getnnodes(proj.dh.grid) - _vtk_write_nodedata(vtks.vtk, nodedata, name) + _vtk_write_nodedata(vtks.vtk, nodedata, name; component_names=get_component_names(eltype(vals))) return vtks end diff --git a/src/deprecations.jl b/src/deprecations.jl index 4acc0986e4..2c756836c4 100644 --- a/src/deprecations.jl +++ b/src/deprecations.jl @@ -68,8 +68,10 @@ import WriteVTK: vtk_grid, vtk_cell_data, vtk_point_data, vtk_save @deprecate vtk_cell_data(vtks::VTKStream, args...) write_celldata(vtks, args...) @deprecate vtk_point_data(vtks::VTKStream, dh::DofHandler, u, suffix="") (_vtk_write_solution(vtks.vtk, dh, u, suffix); vtks) @deprecate vtk_point_data(vtks::VTKStream, data::Vector, args...) write_nodedata(vtks, data, args...) -@deprecate vtk_point_data(vtks::VTKStream, proj::L2Projector, args...) write_projection(vtks, proj, args...) +@deprecate vtk_point_data(vtks::VTKStream, proj::L2Projector, args...) write_projected(vtks, proj, args...) @deprecate vtk_point_data(vtks::VTKStream, ch::ConstraintHandler) write_dirichlet(vtks, ch) @deprecate vtk_cellset(vtks::VTKStream, grid::AbstractGrid, args...) write_cellset(vtks, args...) @deprecate vtk_nodeset(vtks::VTKStream, grid::AbstractGrid, args...) write_nodeset(vtks, args...) -@deprecate vtk_save(vtks::VTKStream) close(vtks) \ No newline at end of file +@deprecate vtk_save(vtks::VTKStream) close(vtks) + +@deprecate component_names(T) get_component_names(T) false # Internal function \ No newline at end of file From f0d153764c6c5241d0d7d4440cd89253d6bbd2e3 Mon Sep 17 00:00:00 2001 From: Knut Andreas Meyer Date: Mon, 1 May 2023 14:11:16 +0200 Subject: [PATCH 05/67] Revert previous rename to vtk_node_data --- docs/src/literate/computational_homogenization.jl | 8 ++++---- docs/src/literate/helmholtz.jl | 2 +- docs/src/literate/hyperelasticity.jl | 2 +- docs/src/literate/incompressible_elasticity.jl | 2 +- docs/src/literate/landau.jl | 2 +- docs/src/literate/linear_shell.jl | 2 +- docs/src/literate/ns_vs_diffeq.jl | 2 +- docs/src/literate/plasticity.jl | 2 +- docs/src/literate/postprocessing.jl | 2 +- .../literate/quasi_incompressible_hyperelasticity.jl | 2 +- docs/src/literate/stokes-flow.jl | 2 +- docs/src/literate/transient_heat_equation.jl | 4 ++-- docs/src/manual/export.md | 10 +++++----- src/exports.jl | 2 +- test/test_grid_dofhandler_vtk.jl | 4 ++-- test/test_l2_projection.jl | 8 ++++---- test/test_mixeddofhandler.jl | 2 +- 17 files changed, 29 insertions(+), 29 deletions(-) diff --git a/docs/src/literate/computational_homogenization.jl b/docs/src/literate/computational_homogenization.jl index 1fbe3c5f12..eafdc35ee1 100644 --- a/docs/src/literate/computational_homogenization.jl +++ b/docs/src/literate/computational_homogenization.jl @@ -523,11 +523,11 @@ vtk_grid("homogenization", dh) do vtk ## Compute macroscopic solution apply_analytical!(uM, dh, :u, x -> εᴹ[i] ⋅ x) ## Dirichlet - vtk_node_data(vtk, dh, uM + u.dirichlet[i], "_dirichlet_$i") - vtk_node_data(vtk, projector, σ.dirichlet[i], "σvM_dirichlet_$i") + vtk_point_data(vtk, dh, uM + u.dirichlet[i], "_dirichlet_$i") + vtk_point_data(vtk, projector, σ.dirichlet[i], "σvM_dirichlet_$i") ## Periodic - vtk_node_data(vtk, dh, uM + u.periodic[i], "_periodic_$i") - vtk_node_data(vtk, projector, σ.periodic[i], "σvM_periodic_$i") + vtk_point_data(vtk, dh, uM + u.periodic[i], "_periodic_$i") + vtk_point_data(vtk, projector, σ.periodic[i], "σvM_periodic_$i") end end; diff --git a/docs/src/literate/helmholtz.jl b/docs/src/literate/helmholtz.jl index 4c604548b3..7b1ab7eb11 100644 --- a/docs/src/literate/helmholtz.jl +++ b/docs/src/literate/helmholtz.jl @@ -164,7 +164,7 @@ apply!(K, f, dbcs) u = Symmetric(K) \ f; vtkfile = vtk_grid("helmholtz", dh) -vtk_node_data(vtkfile, dh, u) +vtk_point_data(vtkfile, dh, u) vtk_save(vtkfile) using Test #src #src this test catches unexpected changes in the result over time. diff --git a/docs/src/literate/hyperelasticity.jl b/docs/src/literate/hyperelasticity.jl index 87a5d2745b..9cfc2da750 100644 --- a/docs/src/literate/hyperelasticity.jl +++ b/docs/src/literate/hyperelasticity.jl @@ -398,7 +398,7 @@ function solve() ## Save the solution @timeit "export" begin vtk_grid("hyperelasticity", dh) do vtkfile - vtk_node_data(vtkfile, dh, u) + vtk_point_data(vtkfile, dh, u) end end diff --git a/docs/src/literate/incompressible_elasticity.jl b/docs/src/literate/incompressible_elasticity.jl index 453c7c7146..0cc44012c3 100644 --- a/docs/src/literate/incompressible_elasticity.jl +++ b/docs/src/literate/incompressible_elasticity.jl @@ -210,7 +210,7 @@ function solve(ν, interpolation_u, interpolation_p) filename = "cook_" * (isa(interpolation_u, Lagrange{2,RefTetrahedron,1}) ? "linear" : "quadratic") * "_linear" vtk_grid(filename, dh) do vtkfile - vtk_node_data(vtkfile, dh, u) + vtk_point_data(vtkfile, dh, u) end return u end diff --git a/docs/src/literate/landau.jl b/docs/src/literate/landau.jl index 59f7dff396..f628ee0c52 100644 --- a/docs/src/literate/landau.jl +++ b/docs/src/literate/landau.jl @@ -114,7 +114,7 @@ end # utility to quickly save a model function Ferrite.vtk_save(path, model, dofs=model.dofs) vtkfile = vtk_grid(path, model.dofhandler) - vtk_node_data(vtkfile, model.dofhandler, dofs) + vtk_point_data(vtkfile, model.dofhandler, dofs) vtk_save(vtkfile) end diff --git a/docs/src/literate/linear_shell.jl b/docs/src/literate/linear_shell.jl index 5d0eca922e..7fa3b51938 100644 --- a/docs/src/literate/linear_shell.jl +++ b/docs/src/literate/linear_shell.jl @@ -114,7 +114,7 @@ a = K\f # Output results. #+ vtk_grid("linear_shell", dh) do vtk - vtk_node_data(vtk, dh, a) + vtk_point_data(vtk, dh, a) end end; #end main functions diff --git a/docs/src/literate/ns_vs_diffeq.jl b/docs/src/literate/ns_vs_diffeq.jl index 519508efca..8fe6c19d2f 100644 --- a/docs/src/literate/ns_vs_diffeq.jl +++ b/docs/src/literate/ns_vs_diffeq.jl @@ -442,7 +442,7 @@ for (u_uc,t) in integrator u = copy(u_uc) apply!(u, ch) vtk_grid("vortex-street-$t.vtu", dh) do vtk - vtk_node_data(vtk, dh,u) + vtk_point_data(vtk, dh,u) vtk_save(vtk) pvd[t] = vtk end diff --git a/docs/src/literate/plasticity.jl b/docs/src/literate/plasticity.jl index 440f3e0e2c..243322744a 100644 --- a/docs/src/literate/plasticity.jl +++ b/docs/src/literate/plasticity.jl @@ -346,7 +346,7 @@ function solve() κ_values[el] /= length(cell_states) # average drag stress end vtk_grid("plasticity", dh) do vtkfile - vtk_node_data(vtkfile, dh, u) # displacement field + 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]") end diff --git a/docs/src/literate/postprocessing.jl b/docs/src/literate/postprocessing.jl index 0e5428c1c6..3c3afc184f 100644 --- a/docs/src/literate/postprocessing.jl +++ b/docs/src/literate/postprocessing.jl @@ -88,7 +88,7 @@ q_projected = project(projector, q_gp, qr; project_to_nodes=false); # TODO: this # 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_node_data(vtk, projector, q_projected, "q") + vtk_point_data(vtk, projector, q_projected, "q") end; # ## Point Evaluation diff --git a/docs/src/literate/quasi_incompressible_hyperelasticity.jl b/docs/src/literate/quasi_incompressible_hyperelasticity.jl index 748a03abbb..dda1e87f70 100644 --- a/docs/src/literate/quasi_incompressible_hyperelasticity.jl +++ b/docs/src/literate/quasi_incompressible_hyperelasticity.jl @@ -338,7 +338,7 @@ function solve(interpolation_u, interpolation_p) ## Save the solution fields vtk_grid("hyperelasticity_incomp_mixed_$t.vtu", dh) do vtkfile - vtk_node_data(vtkfile, dh, w) + vtk_point_data(vtkfile, dh, w) vtk_save(vtkfile) pvd[t] = vtkfile end diff --git a/docs/src/literate/stokes-flow.jl b/docs/src/literate/stokes-flow.jl index 5b64439805..5744146e70 100644 --- a/docs/src/literate/stokes-flow.jl +++ b/docs/src/literate/stokes-flow.jl @@ -505,7 +505,7 @@ function main() apply!(u, ch) ## Export the solution vtk_grid("stokes-flow", grid) do vtk - vtk_node_data(vtk, dh, u) + vtk_point_data(vtk, dh, u) end ## Check the result #src diff --git a/docs/src/literate/transient_heat_equation.jl b/docs/src/literate/transient_heat_equation.jl index 50679481f9..42a4956cf5 100644 --- a/docs/src/literate/transient_heat_equation.jl +++ b/docs/src/literate/transient_heat_equation.jl @@ -194,7 +194,7 @@ apply!(A, ch); pvd = paraview_collection("transient-heat.pvd"); t = 0 vtk_grid("transient-heat-$t", dh) do vtk - vtk_node_data(vtk, dh, uₙ) + vtk_point_data(vtk, dh, uₙ) vtk_save(vtk) pvd[t] = vtk end @@ -213,7 +213,7 @@ for t in Δt:Δt:T u = A \ b vtk_grid("transient-heat-$t", dh) do vtk - vtk_node_data(vtk, dh, u) + vtk_point_data(vtk, dh, u) vtk_save(vtk) pvd[t] = vtk end diff --git a/docs/src/manual/export.md b/docs/src/manual/export.md index bf8bed7b1c..46af5b8c20 100644 --- a/docs/src/manual/export.md +++ b/docs/src/manual/export.md @@ -71,7 +71,7 @@ vector `u`: ```@example export vtk = vtk_grid("my-solution", dh) -vtk_node_data(vtk, dh, u) +vtk_point_data(vtk, dh, u) vtk_save(vtk) rm("my-solution.vtu") # hide ``` @@ -80,26 +80,26 @@ or with a `do`-block: ```@example export vtk_grid("my-solution", dh) do vtk - vtk_node_data(vtk, dh, u) + vtk_point_data(vtk, dh, u) vtk_cell_data(vtk, σ, "my-cell-data") end rm("my-solution.vtu") # hide ``` -When `vtk_node_data` is used with a `DofHandler` all of the fields will be +When `vtk_point_data` is used with a `DofHandler` all of the fields will be written to the VTK file, and the names will be determined by the fieldname symbol that was used when the field was added to the `DofHandler`. ## Exporting Boundary Conditions -There is also a `vtk_node_data` which accepts a `ConstraintHandler`. +There is also a `vtk_point_data` which accepts a `ConstraintHandler`. This method is useful to verify that the boundary conditions are applied where they are supposed to. For a `ConstraintHandler` `ch` we can export the boundary conditions as ```julia vtk_grid("boundary-conditions", grid) do vtk - vtk_node_data(vtk, ch) + vtk_point_data(vtk, ch) end ``` diff --git a/src/exports.jl b/src/exports.jl index ab02d50035..bc64c8a4e4 100644 --- a/src/exports.jl +++ b/src/exports.jl @@ -146,7 +146,7 @@ export # VTK export vtk_grid, vtk_point_data, - vtk_node_data, + vtk_point_data, vtk_cell_data, vtk_nodeset, vtk_cellset, diff --git a/test/test_grid_dofhandler_vtk.jl b/test/test_grid_dofhandler_vtk.jl index e5d71a1539..f44c156fc8 100644 --- a/test/test_grid_dofhandler_vtk.jl +++ b/test/test_grid_dofhandler_vtk.jl @@ -75,8 +75,8 @@ end dofhandlerfilename = "dofhandler-$(repr(celltype))" vtk_grid(dofhandlerfilename, dofhandler) do vtk - vtk_node_data(vtk, ch) - vtk_node_data(vtk, dofhandler, u) + vtk_point_data(vtk, ch) + vtk_point_data(vtk, dofhandler, u) end # test the sha of the file diff --git a/test/test_l2_projection.jl b/test/test_l2_projection.jl index 9923626d35..6c19a39c29 100644 --- a/test/test_l2_projection.jl +++ b/test/test_l2_projection.jl @@ -301,10 +301,10 @@ function test_export(;subset::Bool) mktempdir() do tmp fname = vtk_grid(joinpath(tmp, "projected"), grid) do vtk - vtk_node_data(vtk, p, p_scalar, "p_scalar") - vtk_node_data(vtk, p, p_vec, "p_vec") - vtk_node_data(vtk, p, p_tens, "p_tens") - vtk_node_data(vtk, p, p_stens, "p_stens") + vtk_point_data(vtk, p, p_scalar, "p_scalar") + vtk_point_data(vtk, p, p_vec, "p_vec") + vtk_point_data(vtk, p, p_tens, "p_tens") + vtk_point_data(vtk, p, p_stens, "p_stens") end @test bytes2hex(open(SHA.sha1, fname[1], "r")) in ( subset ? ("261cfe21de7a478e14f455e783694651a91eeb60", "b3fef3de9f38ca9ddd92f2f67a1606d07ca56d67") : diff --git a/test/test_mixeddofhandler.jl b/test/test_mixeddofhandler.jl index e72eecd035..f6158def50 100644 --- a/test/test_mixeddofhandler.jl +++ b/test/test_mixeddofhandler.jl @@ -370,7 +370,7 @@ function test_2_element_heat_eq() vtk_grid(gridfilename, grid) do vtk vtk_cellset(vtk, grid, "cell-1") vtk_cellset(vtk, grid, "cell-2") - vtk_node_data(vtk, dh, u) + vtk_point_data(vtk, dh, u) # vtk_point_data(vtk, ch) #FIXME end sha = bytes2hex(open(SHA.sha1, gridfilename*".vtu")) From 90e273b3c0e2efe0ef479b69ebf170c39ac4f7f2 Mon Sep 17 00:00:00 2001 From: Knut Andreas Meyer Date: Mon, 1 May 2023 14:16:32 +0200 Subject: [PATCH 06/67] Remove exports and revert example changes --- docs/src/literate/heat_equation.jl | 5 +---- docs/src/literate/ns_vs_diffeq.jl | 2 +- src/deprecations.jl | 2 -- src/exports.jl | 7 ------- 4 files changed, 2 insertions(+), 14 deletions(-) diff --git a/docs/src/literate/heat_equation.jl b/docs/src/literate/heat_equation.jl index 8807c1cbd0..927060738e 100644 --- a/docs/src/literate/heat_equation.jl +++ b/docs/src/literate/heat_equation.jl @@ -214,10 +214,7 @@ 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/). -Ferrite.open_vtk("heat_equation_new", dh) do vtk - Ferrite.write_solution(vtk, u) -end -vtk_grid("heat_equation_old", dh) do vtk +vtk_grid("heat_equation", dh) do vtk vtk_point_data(vtk, dh, u) end diff --git a/docs/src/literate/ns_vs_diffeq.jl b/docs/src/literate/ns_vs_diffeq.jl index 8fe6c19d2f..c31247eb8e 100644 --- a/docs/src/literate/ns_vs_diffeq.jl +++ b/docs/src/literate/ns_vs_diffeq.jl @@ -442,7 +442,7 @@ for (u_uc,t) in integrator u = copy(u_uc) apply!(u, ch) vtk_grid("vortex-street-$t.vtu", dh) do vtk - vtk_point_data(vtk, dh,u) + vtk_point_data(vtk,dh,u) vtk_save(vtk) pvd[t] = vtk end diff --git a/src/deprecations.jl b/src/deprecations.jl index 2c756836c4..2dc956ab81 100644 --- a/src/deprecations.jl +++ b/src/deprecations.jl @@ -58,8 +58,6 @@ Base.@deprecate_binding Line3D Line Base.@deprecate_binding Quadrilateral3D Quadrilateral export Line2D, Line3D, Quadrilateral3D -# REMOVE ME! (the following is just to avoid renaming back to vtk_point_data before new renaming again) -@deprecate vtk_node_data(args...; kwargs...) vtk_point_data(args...; kwargs...) import WriteVTK: vtk_grid, vtk_cell_data, vtk_point_data, vtk_save diff --git a/src/exports.jl b/src/exports.jl index bc64c8a4e4..36e4d568f3 100644 --- a/src/exports.jl +++ b/src/exports.jl @@ -144,13 +144,6 @@ export end_assemble, # VTK export - vtk_grid, - vtk_point_data, - vtk_point_data, - vtk_cell_data, - vtk_nodeset, - vtk_cellset, - vtk_save, # L2 Projection project, From fbc75b6400d69c66cb6d3f37323291d7e5787732 Mon Sep 17 00:00:00 2001 From: Knut Andreas Meyer Date: Mon, 1 May 2023 14:41:10 +0200 Subject: [PATCH 07/67] Better deprecation warning --- src/deprecations.jl | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/deprecations.jl b/src/deprecations.jl index 2dc956ab81..6419cb0344 100644 --- a/src/deprecations.jl +++ b/src/deprecations.jl @@ -64,7 +64,6 @@ import WriteVTK: vtk_grid, vtk_cell_data, vtk_point_data, vtk_save @deprecate vtk_grid(filename::String, grid::AbstractGrid; kwargs...) open_vtk(filename, grid; kwargs...) @deprecate vtk_grid(filename::String, dh::DofHandler; kwargs...) open_vtk(filename, dh; kwargs...) @deprecate vtk_cell_data(vtks::VTKStream, args...) write_celldata(vtks, args...) -@deprecate vtk_point_data(vtks::VTKStream, dh::DofHandler, u, suffix="") (_vtk_write_solution(vtks.vtk, dh, u, suffix); vtks) @deprecate vtk_point_data(vtks::VTKStream, data::Vector, args...) write_nodedata(vtks, data, args...) @deprecate vtk_point_data(vtks::VTKStream, proj::L2Projector, args...) write_projected(vtks, proj, args...) @deprecate vtk_point_data(vtks::VTKStream, ch::ConstraintHandler) write_dirichlet(vtks, ch) @@ -72,4 +71,13 @@ import WriteVTK: vtk_grid, vtk_cell_data, vtk_point_data, vtk_save @deprecate vtk_nodeset(vtks::VTKStream, grid::AbstractGrid, args...) write_nodeset(vtks, args...) @deprecate vtk_save(vtks::VTKStream) close(vtks) +# Give better warning than produced by the @deprecate alternative +# @deprecate vtk_point_data(vtks::VTKStream, dh::DofHandler, u, suffix="") (_vtk_write_solution(vtks.vtk, dh, u, suffix); vtks) +function vtk_point_data(vtks::VTKStream, dh::DofHandler, u, suffix="") + msg = "vtk_point_data(vtk, dh::DofHandler, args...) is deprecated. Use write_solution(::VTKStream, args...) instead" + Base.depwarn(msg, :vtk_point_data) + _vtk_write_solution(vtks.vtk, dh, u, suffix) + return vtks +end + @deprecate component_names(T) get_component_names(T) false # Internal function \ No newline at end of file From 65eace96b2fae1549514459bd64ed46bd16d1693 Mon Sep 17 00:00:00 2001 From: Knut Andreas Meyer Date: Mon, 1 May 2023 15:14:28 +0200 Subject: [PATCH 08/67] Minor docstring fix --- src/Export/VTK.jl | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Export/VTK.jl b/src/Export/VTK.jl index f520a6a4b5..ffb123e5a0 100644 --- a/src/Export/VTK.jl +++ b/src/Export/VTK.jl @@ -17,6 +17,7 @@ Create a `Ferrite.VTKStream` that contains an unstructured VTK grid from a `DofHandler` (limited functionality if only a `Grid` is given). This stream can be used to to write data with [`write_solution`](@ref), [`write_celldata`](@ref), [`write_nodedata`](@ref), +[`write_projected`](@ref), [`write_cellset`](@ref), [`write_nodeset`](@ref), and [`write_constraints`](@ref). The keyword arguments are forwarded to `WriteVTK.vtk_grid`, see From 77337ee1c05146b44a71da054530ae30fd1b21bd Mon Sep 17 00:00:00 2001 From: Knut Andreas Meyer Date: Wed, 5 Jul 2023 13:37:45 +0200 Subject: [PATCH 09/67] Fix test (wrong show overload) --- src/Export/VTK.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Export/VTK.jl b/src/Export/VTK.jl index e897693685..eca22d6eb4 100644 --- a/src/Export/VTK.jl +++ b/src/Export/VTK.jl @@ -47,7 +47,7 @@ end isopen(vtks::VTKStream) = WriteVTK.isopen(vtks.vtk) -function show(io::IO, ::MIME"text/plain", vtks::VTKStream) +function Base.show(io::IO, ::MIME"text/plain", vtks::VTKStream) open_str = isopen(vtk) ? "open" : "closed" if isa(vtks.grid_or_dh, DofHandler) dh_string = "DofHandler" From 50c7c25fa1451d96d276b456fe622d5df210ddf4 Mon Sep 17 00:00:00 2001 From: Knut Andreas Meyer Date: Wed, 5 Jul 2023 14:01:49 +0200 Subject: [PATCH 10/67] Create write_cell_colors and deprecate vtk_cell_data_colors --- src/Export/VTK.jl | 38 +++++++++++++++++++++++++++----------- src/Grid/coloring.jl | 17 ----------------- src/deprecations.jl | 1 + 3 files changed, 28 insertions(+), 28 deletions(-) diff --git a/src/Export/VTK.jl b/src/Export/VTK.jl index eca22d6eb4..31f69ea74a 100644 --- a/src/Export/VTK.jl +++ b/src/Export/VTK.jl @@ -254,21 +254,21 @@ function write_nodeset(vtks::VTKStream, nodeset::String) end """ - write_cellset(vtk) - write_cellset(vtk, cellset::String) - write_cellset(vtk, cellsets::Union{AbstractVector{String},AbstractSet{String}) + write_cellset(vtks) + write_cellset(vtks, cellset::String) + write_cellset(vtks, cellsets::Union{AbstractVector{String},AbstractSet{String}) Export all cell sets in the grid with name according to their keys and celldata 1 if the cell is in the set, and 0 otherwise. It is also possible to only export a single `cellset`, or multiple `cellsets`. """ -function write_cellset(vtks::VTKStream, cellsets=keys(grid.cellsets)) +function write_cellset(vtks, cellsets=keys(getcellsets(getgrid(vtks)))) grid = getgrid(vtks) z = zeros(getncells(grid)) for cellset in cellsets z .= 0.0 z[collect(getcellset(grid, cellset))] .= 1.0 - vtk_cell_data(vtks.vtk, z, cellset) + write_celldata(vtks, z, cellset) end return vtks end @@ -280,13 +280,12 @@ write_cellset(vtks::VTKStream, cellset::String) = write_cellset(vtks, [cellset]) Saves the dirichlet boundary conditions to a vtkfile. Values will have a 1 where bcs are active and 0 otherwise """ -function write_dirichlet(vtks::VTKStream, ch::ConstraintHandler) +function write_dirichlet(vtks, ch::ConstraintHandler) if getgrid(vtks) !== ch.dh.grid - @warn("The grid saved in VTKStream and ConstraintHandler are not aliased, no checks are performed to ensure that they are equal") + @warn("The grid saved in $(typeof(vtks)) and ConstraintHandler are not aliased, no checks are performed to ensure that they are equal") end - vtkfile = vtks.vtk - + unique_fields = [] for dbc in ch.dbcs push!(unique_fields, dbc.field_name) @@ -315,7 +314,24 @@ function write_dirichlet(vtks::VTKStream, ch::ConstraintHandler) end end end - WriteVTK.vtk_point_data(vtkfile, data, string(field, "_bc")) + write_nodedata(vtks, data, string(field, "_bc")) end return vtks -end \ No newline at end of file +end + +""" + write_cell_colors(vtks::VTKStream, cell_colors, name="coloring") + +Write cell colors (see [`create_coloring`](@ref)) to a VTK file for visualization. + +In case of coloring a subset, the cells which are not part of the subset are represented as color 0. +""" +function write_cell_colors(vtks, cell_colors::AbstractVector{<:AbstractVector{<:Integer}}, name="coloring") + color_vector = zeros(Int, getncells(getgrid(vtks))) + for (i, cells_color) in enumerate(cell_colors) + for cell in cells_color + color_vector[cell] = i + end + end + write_celldata(vtks, color_vector, name) +end diff --git a/src/Grid/coloring.jl b/src/Grid/coloring.jl index 628d9d7d1b..8368dc1629 100644 --- a/src/Grid/coloring.jl +++ b/src/Grid/coloring.jl @@ -203,20 +203,3 @@ function create_coloring(g::AbstractGrid, cellset=1:getncells(g); alg::ColoringA error("impossible") end end - -""" - vtk_cell_data_colors(vtkfile, cell_colors, name="coloring") - -Write cell colors (see [`create_coloring`](@ref)) to a VTK file for visualization. - -In case of coloring a subset, the cells which are not part of the subset are represented as color 0. -""" -function vtk_cell_data_colors(vtkfile, cell_colors::AbstractVector{<:AbstractVector{<:Integer}}, name="coloring") - color_vector = zeros(Int, vtkfile.Ncls) - for (i, cells_color) in enumerate(cell_colors) - for cell in cells_color - color_vector[cell] = i - end - end - vtk_cell_data(vtkfile, color_vector, name) -end diff --git a/src/deprecations.jl b/src/deprecations.jl index 2ea238e952..fc5f338569 100644 --- a/src/deprecations.jl +++ b/src/deprecations.jl @@ -71,6 +71,7 @@ import WriteVTK: vtk_grid, vtk_cell_data, vtk_point_data, vtk_save @deprecate vtk_point_data(vtks::VTKStream, ch::ConstraintHandler) write_dirichlet(vtks, ch) @deprecate vtk_cellset(vtks::VTKStream, grid::AbstractGrid, args...) write_cellset(vtks, args...) @deprecate vtk_nodeset(vtks::VTKStream, grid::AbstractGrid, args...) write_nodeset(vtks, args...) +@deprecate vtk_cell_data_colors(vtks::VTKStream, args...) write_cell_colors(vtks, args...) @deprecate vtk_save(vtks::VTKStream) close(vtks) # Give better warning than produced by the @deprecate alternative From ae917dfc42a65e33b0356809f68099b45702acba Mon Sep 17 00:00:00 2001 From: Knut Andreas Meyer Date: Fri, 7 Jul 2023 12:07:57 +0200 Subject: [PATCH 11/67] Fix show and remove filename from type --- src/Export/VTK.jl | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Export/VTK.jl b/src/Export/VTK.jl index 31f69ea74a..e915bd77b8 100644 --- a/src/Export/VTK.jl +++ b/src/Export/VTK.jl @@ -1,5 +1,4 @@ struct VTKStream{VTK<:WriteVTK.DatasetFile, DH<:Union{DofHandler,Grid}} - filename::String # Just to allow easy printing vtk::VTK grid_or_dh::DH end @@ -33,7 +32,7 @@ end """ function open_vtk(filename::String, grid_or_dh; kwargs...) vtk = create_vtk_grid(filename, grid_or_dh; kwargs...) - return VTKStream(filename, vtk, grid_or_dh) + return VTKStream(vtk, grid_or_dh) end # Makes it possible to use the `do`-block syntax function open_vtk(f::Function, args...; kwargs...) @@ -48,7 +47,7 @@ end isopen(vtks::VTKStream) = WriteVTK.isopen(vtks.vtk) function Base.show(io::IO, ::MIME"text/plain", vtks::VTKStream) - open_str = isopen(vtk) ? "open" : "closed" + open_str = isopen(vtks) ? "open" : "closed" if isa(vtks.grid_or_dh, DofHandler) dh_string = "DofHandler" elseif isa(vtks.grid_or_dh, Grid) @@ -56,7 +55,8 @@ function Base.show(io::IO, ::MIME"text/plain", vtks::VTKStream) else dh_string = string(typeof(vtks.grid_or_dh)) end - print(io, "VTKStream for the $open_str file \"$(vtk.path)\" based on a $dh_string") + filename = vtks.vtk.path + print(io, "VTKStream for the $open_str file \"$(filename)\" based on a $dh_string") end getgrid(vtks::VTKStream{<:Any,<:DofHandler}) = vtks.grid_or_dh.grid From b64df4439be009fee79ba75d2873940303360d7b Mon Sep 17 00:00:00 2001 From: Knut Andreas Meyer Date: Tue, 18 Jul 2023 19:20:18 +0200 Subject: [PATCH 12/67] Apply suggestions from code review --- src/Export/VTK.jl | 127 ++++++++++++++++---------------------------- src/deprecations.jl | 32 +++++------ test/runtests.jl | 6 +-- 3 files changed, 64 insertions(+), 101 deletions(-) diff --git a/src/Export/VTK.jl b/src/Export/VTK.jl index e915bd77b8..11a6345ca6 100644 --- a/src/Export/VTK.jl +++ b/src/Export/VTK.jl @@ -1,16 +1,9 @@ -struct VTKStream{VTK<:WriteVTK.DatasetFile, DH<:Union{DofHandler,Grid}} +struct VTKStream{VTK<:WriteVTK.DatasetFile} vtk::VTK - grid_or_dh::DH end -""" - Base.close(vtks::VTKStream) - -Close the vtk stream and save the data to disk. -""" -Base.close(vtks::VTKStream) = WriteVTK.vtk_save(vtks.vtk) """ - open_vtk(filename::AbstractString, dh::Union{DofHandler,Grid}; kwargs...) + VTKStream(filename::AbstractString, grid::AbstractGrid; kwargs...) Create a `Ferrite.VTKStream` that contains an unstructured VTK grid from a `DofHandler` (limited functionality if only a `Grid` is given). @@ -25,18 +18,18 @@ The keyword arguments are forwarded to `WriteVTK.vtk_grid`, see It is necessary to call [`close`](@ref) to save the data after writing to the stream, or alternatively use the `do`-block syntax which does this implicitly, e.g., ```julia -open_vtk(filename, dh) do vtk - write_solution(vtk, u) - write_celldata(vtk, celldata) +VTKStream(filename, grid) do vtks + write_solution(vtks, dh, u) + write_celldata(vtks, grid, celldata) end """ -function open_vtk(filename::String, grid_or_dh; kwargs...) - vtk = create_vtk_grid(filename, grid_or_dh; kwargs...) - return VTKStream(vtk, grid_or_dh) +function VTKStream(filename::String, grid::AbstractGrid; kwargs...) + vtk = create_vtk_grid(filename, grid; kwargs...) + return VTKStream(vtk) end # Makes it possible to use the `do`-block syntax -function open_vtk(f::Function, args...; kwargs...) - vtks = open_vtk(args...; kwargs...) +function VTKStream(f::Function, args...; kwargs...) + vtks = VTKStream(args...; kwargs...) try f(vtks) finally @@ -44,24 +37,19 @@ function open_vtk(f::Function, args...; kwargs...) end end -isopen(vtks::VTKStream) = WriteVTK.isopen(vtks.vtk) +""" + Base.close(vtks::VTKStream) + +Close the vtk stream and save the data to disk. +""" +Base.close(vtks::VTKStream) = WriteVTK.vtk_save(vtks.vtk) function Base.show(io::IO, ::MIME"text/plain", vtks::VTKStream) - open_str = isopen(vtks) ? "open" : "closed" - if isa(vtks.grid_or_dh, DofHandler) - dh_string = "DofHandler" - elseif isa(vtks.grid_or_dh, Grid) - dh_string = "Grid" - else - dh_string = string(typeof(vtks.grid_or_dh)) - end + open_str = WriteVTK.isopen(vtks.vtk) ? "open" : "closed" filename = vtks.vtk.path - print(io, "VTKStream for the $open_str file \"$(filename)\" based on a $dh_string") + print(io, "VTKStream for the $open_str file \"$(filename)\".") end -getgrid(vtks::VTKStream{<:Any,<:DofHandler}) = vtks.grid_or_dh.grid -getgrid(vtks::VTKStream{<:Any,<:Grid}) = vtks.grid_or_dh - # Support ParaviewCollection function Base.setindex!(pvd::WriteVTK.CollectionFile, vtks::VTKStream, time::Real) WriteVTK.collection_add_timestep(pvd, vtks, time) @@ -126,14 +114,11 @@ function create_vtk_grid(filename::AbstractString, grid::Grid{dim,C,T}; kwargs.. coords = reshape(reinterpret(T, getnodes(grid)), (dim, getnnodes(grid))) return vtk_grid(filename, coords, cls; kwargs...) end -function create_vtk_grid(filename::AbstractString, dh::AbstractDofHandler; kwargs...) - create_vtk_grid(filename, get_grid(dh); kwargs...) -end function toparaview!(v, x::Vec{D}) where D v[1:D] .= x end -function toparaview!(v, x::SecondOrderTensor{D}) where D +function toparaview!(v, x::SecondOrderTensor) tovoigt!(v, x) end @@ -148,7 +133,7 @@ function _vtk_write_nodedata( for i in 1:npoints toparaview!(@view(out[:, i]), nodedata[i]) end - return WriteVTK.vtk_point_data(vtk, out, name; component_names=get_component_names(S)) + return WriteVTK.vtk_point_data(vtk, out, name; component_names=component_names(S)) end function _vtk_write_nodedata(vtk::WriteVTK.DatasetFile, nodedata::Vector{<:Real}, name::AbstractString) return WriteVTK.vtk_point_data(vtk, nodedata, name) @@ -157,7 +142,7 @@ function _vtk_write_nodedata(vtk::WriteVTK.DatasetFile, nodedata::Matrix{<:Real} return WriteVTK.vtk_point_data(vtk, nodedata, name; component_names=component_names) end -function get_component_names(::Type{S}) where S +function component_names(::Type{S}) where S names = S <: Vec{1} ? ["x"] : S <: Vec ? ["x", "y", "z"] : # Pad 2D Vec to 3D @@ -171,31 +156,23 @@ function get_component_names(::Type{S}) where S return names end - -function _vtk_write_solution(vtkfile, dh, u::Vector, suffix) - fieldnames = Ferrite.getfieldnames(dh) # all primary fields - - for name in fieldnames - data = _evaluate_at_grid_nodes(dh, u, name, #=vtk=# Val(true)) - _vtk_write_nodedata(vtkfile, data, string(name, suffix)) - end - return nothing -end - """ - write_solution(vtks::VTKStream, u::Vector, suffix="") + write_solution(vtks::VTKStream, dh::AbstractDofHandler, u::Vector, suffix="") Save the values at the nodes in the degree of freedom vector `u` to a the a vtk file for each field in `DofHandler` in `vtks`. `suffix` can be used to append to the fieldname. -`vtks` is typically created by the [`open_vtk`](@ref) function. `u` can also contain tensorial values, but each entry in `u` must correspond to a degree of freedom in `dh`, see [`write_nodedata`](@ref) for details. This function should be used directly when exporting values already sorted by the nodes in the grid. """ -function write_solution(vtks::VTKStream, u, suffix="") - _vtk_write_solution(vtks.vtk, vtks.grid_or_dh, u, suffix) +function write_solution(vtks::VTKStream, dh::AbstractDofHandler, u::Vector, suffix="") + fieldnames = Ferrite.getfieldnames(dh) # all primary fields + for name in fieldnames + data = _evaluate_at_grid_nodes(dh, u, name, #=vtk=# Val(true)) + _vtk_write_nodedata(vtks.vtk, data, string(name, suffix)) + end return vtks end @@ -205,12 +182,9 @@ end Write `vals` that have been projected with `proj` to the vtk file in `vtks` """ function write_projected(vtks::VTKStream, proj::L2Projector, vals, name) - if getgrid(vtks) !== get_grid(proj.dh) - @warn("The grid saved in VTKStream and L2Projector are not aliased, no checks are performed to ensure that they are equal") - end data = _evaluate_at_grid_nodes(proj, vals, #=vtk=# Val(true))::Matrix @assert size(data, 2) == getnnodes(get_grid(proj.dh)) - _vtk_write_nodedata(vtks.vtk, data, name; component_names=get_component_names(eltype(vals))) + _vtk_write_nodedata(vtks.vtk, data, name; component_names=component_names(eltype(vals))) return vtks end @@ -219,7 +193,7 @@ end Write the `celldata` that is ordered by the cells in the grid to the vtk file. """ -function write_celldata(vtks::VTKStream, celldata, name) +function write_celldata(vtks::VTKStream, ::AbstractGrid, celldata, name) WriteVTK.vtk_cell_data(vtks.vtk, celldata, name) end @@ -235,44 +209,42 @@ Two-dimensional vectors are padded with zeros. When `nodedata` contains second order tensors, the index order, `[11, 22, 33, 23, 13, 12, 32, 31, 21]`, follows the default Voigt order in Tensors.jl. """ -function write_nodedata(vtks::VTKStream, nodedata, name) +function write_nodedata(vtks::VTKStream, ::AbstractGrid, nodedata, name) _vtk_write_nodedata(vtks.vtk, nodedata, name) end """ - write_nodeset(vtks::VTKStream, nodeset::String) + write_nodeset(vtks::VTKStream, grid::AbstractGrid, nodeset::String) Export nodal values of 1 for nodes in `nodeset`, and 0 otherwise """ -function write_nodeset(vtks::VTKStream, nodeset::String) - grid = getgrid(vtks) +function write_nodeset(vtks, grid::AbstractGrid, nodeset::String) z = zeros(getnnodes(grid)) z[collect(getnodeset(grid, nodeset))] .= 1.0 - WriteVTK.vtk_point_data(vtks.vtk, z, nodeset) + write_nodedata(vtks, grid, z, nodeset) return vtks end """ - write_cellset(vtks) - write_cellset(vtks, cellset::String) - write_cellset(vtks, cellsets::Union{AbstractVector{String},AbstractSet{String}) + write_cellset(vtks, grid::AbstractGrid) + write_cellset(vtks, grid::AbstractGrid, cellset::String) + write_cellset(vtks, grid::AbstractGrid, cellsets::Union{AbstractVector{String},AbstractSet{String}) Export all cell sets in the grid with name according to their keys and celldata 1 if the cell is in the set, and 0 otherwise. It is also possible to only export a single `cellset`, or multiple `cellsets`. """ -function write_cellset(vtks, cellsets=keys(getcellsets(getgrid(vtks)))) - grid = getgrid(vtks) +function write_cellset(vtks, grid::AbstractGrid, cellsets=keys(getcellsets(getgrid(vtks)))) z = zeros(getncells(grid)) for cellset in cellsets - z .= 0.0 + fill!(z, 0) z[collect(getcellset(grid, cellset))] .= 1.0 - write_celldata(vtks, z, cellset) + write_celldata(vtks, grid, z, cellset) end return vtks end -write_cellset(vtks::VTKStream, cellset::String) = write_cellset(vtks, [cellset]) +write_cellset(vtks, grid::AbstractGrid, cellset::String) = write_cellset(vtks, grid, [cellset]) """ write_dirichlet(vtks::VTKStream, ch::ConstraintHandler) @@ -280,12 +252,7 @@ write_cellset(vtks::VTKStream, cellset::String) = write_cellset(vtks, [cellset]) Saves the dirichlet boundary conditions to a vtkfile. Values will have a 1 where bcs are active and 0 otherwise """ -function write_dirichlet(vtks, ch::ConstraintHandler) - - if getgrid(vtks) !== ch.dh.grid - @warn("The grid saved in $(typeof(vtks)) and ConstraintHandler are not aliased, no checks are performed to ensure that they are equal") - end - +function write_dirichlet(vtks, ch::ConstraintHandler) unique_fields = [] for dbc in ch.dbcs push!(unique_fields, dbc.field_name) @@ -314,24 +281,24 @@ function write_dirichlet(vtks, ch::ConstraintHandler) end end end - write_nodedata(vtks, data, string(field, "_bc")) + write_nodedata(vtks, get_grid(ch.dh), data, string(field, "_bc")) end return vtks end """ - write_cell_colors(vtks::VTKStream, cell_colors, name="coloring") + write_cell_colors(vtks::VTKStream, grid::AbstractGrid, cell_colors, name="coloring") Write cell colors (see [`create_coloring`](@ref)) to a VTK file for visualization. In case of coloring a subset, the cells which are not part of the subset are represented as color 0. """ -function write_cell_colors(vtks, cell_colors::AbstractVector{<:AbstractVector{<:Integer}}, name="coloring") - color_vector = zeros(Int, getncells(getgrid(vtks))) +function write_cell_colors(vtks, grid::AbstractGrid, cell_colors::AbstractVector{<:AbstractVector{<:Integer}}, name="coloring") + color_vector = zeros(Int, getncells(grid)) for (i, cells_color) in enumerate(cell_colors) for cell in cells_color color_vector[cell] = i end end - write_celldata(vtks, color_vector, name) + write_celldata(vtks, grid, color_vector, name) end diff --git a/src/deprecations.jl b/src/deprecations.jl index dd70befccf..8135c7d160 100644 --- a/src/deprecations.jl +++ b/src/deprecations.jl @@ -63,27 +63,23 @@ export Line2D, Line3D, Quadrilateral3D import WriteVTK: vtk_grid, vtk_cell_data, vtk_point_data, vtk_save -@deprecate vtk_grid(filename::String, grid::AbstractGrid; kwargs...) open_vtk(filename, grid; kwargs...) -@deprecate vtk_grid(filename::String, dh::DofHandler; kwargs...) open_vtk(filename, dh; kwargs...) -@deprecate vtk_cell_data(vtks::VTKStream, args...) write_celldata(vtks, args...) -@deprecate vtk_point_data(vtks::VTKStream, data::Vector, args...) write_nodedata(vtks, data, args...) +@deprecate vtk_grid(filename::String, grid::AbstractGrid; kwargs...) VTKStream(filename, grid; kwargs...) +@deprecate vtk_grid(filename::String, dh::DofHandler; kwargs...) VTKStream(filename, get_grid(dh); kwargs...) +struct _DummyGrid{D} <: AbstractGrid{D} + ncells::Int +end +_DummyGrid(ncells=1) = _DummyGrid{1}(ncells) +getncells(g::_DummyGrid) = g.ncells + +@deprecate vtk_cell_data(vtks::VTKStream, args...) write_celldata(vtks, _DummyGrid(), args...) +@deprecate vtk_point_data(vtks::VTKStream, data::Vector, args...) write_nodedata(vtks, _DummyGrid(), data, args...) @deprecate vtk_point_data(vtks::VTKStream, proj::L2Projector, args...) write_projected(vtks, proj, args...) @deprecate vtk_point_data(vtks::VTKStream, ch::ConstraintHandler) write_dirichlet(vtks, ch) -@deprecate vtk_cellset(vtks::VTKStream, grid::AbstractGrid, args...) write_cellset(vtks, args...) -@deprecate vtk_nodeset(vtks::VTKStream, grid::AbstractGrid, args...) write_nodeset(vtks, args...) -@deprecate vtk_cell_data_colors(vtks::VTKStream, args...) write_cell_colors(vtks, args...) +@deprecate vtk_cellset(vtks::VTKStream, grid::AbstractGrid, args...) write_cellset(vtks, grid, args...) +@deprecate vtk_nodeset(vtks::VTKStream, grid::AbstractGrid, args...) write_nodeset(vtks, grid, args...) +@deprecate vtk_cell_data_colors(vtks::VTKStream, args...) write_cell_colors(vtks, _DummyGrid(vtks.vtk.Ncls), args...) @deprecate vtk_save(vtks::VTKStream) close(vtks) - -# Give better warning than produced by the @deprecate alternative -# @deprecate vtk_point_data(vtks::VTKStream, dh::DofHandler, u, suffix="") (_vtk_write_solution(vtks.vtk, dh, u, suffix); vtks) -function vtk_point_data(vtks::VTKStream, dh::DofHandler, u, suffix="") - msg = "vtk_point_data(vtk, dh::DofHandler, args...) is deprecated. Use write_solution(::VTKStream, args...) instead" - Base.depwarn(msg, :vtk_point_data) - _vtk_write_solution(vtks.vtk, dh, u, suffix) - return vtks -end - -@deprecate component_names(T) get_component_names(T) false # Internal function +@deprecate vtk_point_data(vtks::VTKStream, dh::DofHandler, args...) write_solution(vtks, dh, args...) # Deprecation of auto-vectorized methods function add!(dh::DofHandler, name::Symbol, dim::Int) diff --git a/test/runtests.jl b/test/runtests.jl index d11ed6d582..d72f9aab3a 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -17,16 +17,16 @@ if HAS_EXTENSIONS && MODULE_CAN_BE_TYPE_PARAMETER import Metis end -include("test_utils.jl") +include("test_utils.jl") include("test_interpolations.jl") include("test_cellvalues.jl") include("test_facevalues.jl") include("test_quadrules.jl") include("test_assemble.jl") include("test_dofs.jl") -include("test_constraints.jl") +include("test_constraints.jl") include("test_grid_dofhandler_vtk.jl") -include("test_abstractgrid.jl") +include("test_abstractgrid.jl") include("test_grid_addboundaryset.jl") include("test_mixeddofhandler.jl") include("test_l2_projection.jl") From 077cf58ec0f65f3bf288f0651cf03729f1a42d24 Mon Sep 17 00:00:00 2001 From: Knut Andreas Meyer Date: Tue, 18 Jul 2023 20:57:29 +0200 Subject: [PATCH 13/67] Export new functions and update docs --- docs/Manifest.toml | 415 ++++++++++-------- docs/src/literate-gallery/helmholtz.jl | 6 +- docs/src/literate-gallery/landau.jl | 12 +- .../quasi_incompressible_hyperelasticity.jl | 7 +- .../literate-gallery/topology_optimization.jl | 8 +- docs/src/literate-howto/postprocessing.jl | 4 +- docs/src/literate-howto/threaded_assembly.jl | 6 +- .../computational_homogenization.jl | 10 +- docs/src/literate-tutorials/heat_equation.jl | 4 +- .../src/literate-tutorials/hyperelasticity.jl | 4 +- .../incompressible_elasticity.jl | 4 +- docs/src/literate-tutorials/linear_shell.jl | 4 +- docs/src/literate-tutorials/ns_vs_diffeq.jl | 7 +- docs/src/literate-tutorials/plasticity.jl | 8 +- docs/src/literate-tutorials/stokes-flow.jl | 4 +- .../transient_heat_equation.jl | 14 +- docs/src/reference/export.md | 13 +- docs/src/topics/export.md | 104 +---- src/exports.jl | 13 +- 19 files changed, 326 insertions(+), 321 deletions(-) diff --git a/docs/Manifest.toml b/docs/Manifest.toml index e8cfd843f7..77b5a7dc19 100644 --- a/docs/Manifest.toml +++ b/docs/Manifest.toml @@ -1,9 +1,14 @@ # This file is machine-generated - editing it directly is not advised -julia_version = "1.9.1" +julia_version = "1.9.2" manifest_format = "2.0" project_hash = "36aa80ebfd72e2016135d6d7b3122eb6efdc74ea" +[[deps.ADTypes]] +git-tree-sha1 = "e58c18d2312749847a74f5be80bb0fa53da102bd" +uuid = "47edcb42-4c32-4615-8424-f2b9edc5f35b" +version = "0.1.5" + [[deps.ANSIColoredPrinters]] git-tree-sha1 = "574baf8110975760d391c710b6341da1afa48d8c" uuid = "a4c015fc-c6ff-483c-b24f-f7ea428134e9" @@ -16,9 +21,9 @@ version = "0.4.4" [[deps.Adapt]] deps = ["LinearAlgebra", "Requires"] -git-tree-sha1 = "cc37d689f599e8df4f464b2fa3870ff7db7492ef" +git-tree-sha1 = "76289dc51920fdc6e0013c872ba9551d54961c24" uuid = "79e6a3ab-5dfb-504d-930d-738a2a938a0e" -version = "3.6.1" +version = "3.6.2" weakdeps = ["StaticArrays"] [deps.Adapt.extensions] @@ -35,10 +40,10 @@ uuid = "ec485272-7323-5ecc-a04f-4719b315124d" version = "0.2.0" [[deps.ArrayInterface]] -deps = ["Adapt", "LinearAlgebra", "Requires", "SnoopPrecompile", "SparseArrays", "SuiteSparse"] -git-tree-sha1 = "38911c7737e123b28182d89027f4216cfc8a9da7" +deps = ["Adapt", "LinearAlgebra", "Requires", "SparseArrays", "SuiteSparse"] +git-tree-sha1 = "f83ec24f76d4c8f525099b2ac475fc098138ec31" uuid = "4fba245c-0d91-5ea0-9b3e-6abc04ee57a9" -version = "7.4.3" +version = "7.4.11" [deps.ArrayInterface.extensions] ArrayInterfaceBandedMatricesExt = "BandedMatrices" @@ -64,9 +69,9 @@ version = "0.1.29" [[deps.ArrayLayouts]] deps = ["FillArrays", "LinearAlgebra", "SparseArrays"] -git-tree-sha1 = "4efc22e4c299e49995a38d503d9dbb0544a37838" +git-tree-sha1 = "e0da03c52673bc0ab5138d1381b4dbc48ea343b9" uuid = "4c555306-a7a7-4459-81d9-ec55ddd5c99a" -version = "1.0.4" +version = "1.0.12" [[deps.Artifacts]] uuid = "56f22d72-fd6d-98f1-02f0-08ddc0907c33" @@ -87,9 +92,9 @@ version = "0.1.5" [[deps.BlockArrays]] deps = ["ArrayLayouts", "FillArrays", "LinearAlgebra"] -git-tree-sha1 = "c7d7789c2c6ec98ec78ea5e017485549a95b051e" +git-tree-sha1 = "174b4970af15a500a29e76151f5c53195784b9d4" uuid = "8e7c35d0-a365-5155-bbbb-fb81a777f24e" -version = "0.16.27" +version = "0.16.36" [[deps.Bzip2_jll]] deps = ["Artifacts", "JLLWrappers", "Libdl", "Pkg"] @@ -98,10 +103,10 @@ uuid = "6e34b625-4abd-537c-b88f-471c36dfa7a0" version = "1.0.8+0" [[deps.CPUSummary]] -deps = ["CpuId", "IfElse", "Static"] -git-tree-sha1 = "2c144ddb46b552f72d7eafe7cc2f50746e41ea21" +deps = ["CpuId", "IfElse", "PrecompileTools", "Static"] +git-tree-sha1 = "89e0654ed8c7aebad6d5ad235d6242c2d737a928" uuid = "2a0fbf3d-bb9c-48f3-b0a9-814d99fd7ab9" -version = "0.2.2" +version = "0.2.3" [[deps.Cairo_jll]] deps = ["Artifacts", "Bzip2_jll", "CompilerSupportLibraries_jll", "Fontconfig_jll", "FreeType2_jll", "Glib_jll", "JLLWrappers", "LZO_jll", "Libdl", "Pixman_jll", "Pkg", "Xorg_libXext_jll", "Xorg_libXrender_jll", "Zlib_jll", "libpng_jll"] @@ -123,9 +128,9 @@ version = "0.1.12" [[deps.CodecZlib]] deps = ["TranscodingStreams", "Zlib_jll"] -git-tree-sha1 = "9c209fb7536406834aa938fb149964b985de6c83" +git-tree-sha1 = "02aa26a4cf76381be7f66e020a3eddeb27b0a092" uuid = "944b1d66-785c-5afd-91f1-9de20f533193" -version = "0.7.1" +version = "0.7.2" [[deps.ColorSchemes]] deps = ["ColorTypes", "ColorVectorSpace", "Colors", "FixedPointNumbers", "PrecompileTools", "Random"] @@ -152,9 +157,9 @@ uuid = "5ae59095-9a9b-59fe-a467-6f913c188581" version = "0.12.10" [[deps.CommonSolve]] -git-tree-sha1 = "9441451ee712d1aec22edad62db1a9af3dc8d852" +git-tree-sha1 = "0eee5eb66b1cf62cd6ad1b460238e60e4b09400c" uuid = "38540f10-b2f7-11e9-35d8-d573e4eb0ff2" -version = "0.2.3" +version = "0.2.4" [[deps.CommonSubexpressions]] deps = ["MacroTools", "Test"] @@ -164,9 +169,9 @@ version = "0.3.0" [[deps.Compat]] deps = ["UUIDs"] -git-tree-sha1 = "7a60c856b9fa189eb34f5f8a6f6b5529b7942957" +git-tree-sha1 = "4e88377ae7ebeaf29a047aa1ee40826e0b708a5d" uuid = "34da2185-b29b-5c13-b0c7-acf172513d20" -version = "4.6.1" +version = "4.7.0" weakdeps = ["Dates", "LinearAlgebra"] [deps.Compat.extensions] @@ -175,19 +180,19 @@ weakdeps = ["Dates", "LinearAlgebra"] [[deps.CompilerSupportLibraries_jll]] deps = ["Artifacts", "Libdl"] uuid = "e66e0078-7015-5450-92f7-15fbd957f2ae" -version = "1.0.2+0" +version = "1.0.5+0" [[deps.ConcurrentUtilities]] deps = ["Serialization", "Sockets"] -git-tree-sha1 = "b306df2650947e9eb100ec125ff8c65ca2053d30" +git-tree-sha1 = "5372dbbf8f0bdb8c700db5367132925c0771ef7e" uuid = "f0e56b4a-5159-44fe-b623-3e5288b988bb" -version = "2.1.1" +version = "2.2.1" [[deps.ConstructionBase]] deps = ["LinearAlgebra"] -git-tree-sha1 = "738fec4d684a9a6ee9598a8bfee305b26831f28c" +git-tree-sha1 = "fe2838a593b5f776e1597e086dcd47560d94e816" uuid = "187b0558-2788-49d3-abe0-74a17ed4e7c9" -version = "1.5.2" +version = "1.5.3" [deps.ConstructionBase.extensions] ConstructionBaseIntervalSetsExt = "IntervalSets" @@ -209,15 +214,15 @@ uuid = "adafc99b-e345-5852-983c-f28acb93d879" version = "0.3.1" [[deps.DataAPI]] -git-tree-sha1 = "e8119c1a33d267e16108be441a287a6981ba1630" +git-tree-sha1 = "8da84edb865b0b5b0100c0666a9bc9a0b71c553c" uuid = "9a962f9c-6df0-11e9-0e5d-c546b8b5ee8a" -version = "1.14.0" +version = "1.15.0" [[deps.DataStructures]] deps = ["Compat", "InteractiveUtils", "OrderedCollections"] -git-tree-sha1 = "d1fff3a548102f48987a52a2e0d114fa97d730f0" +git-tree-sha1 = "cf25ccb972fec4e4817764d01c82386ae94f77b4" uuid = "864edb3b-99cc-5e75-8d2d-829cb0a9cfe8" -version = "0.18.13" +version = "0.18.14" [[deps.DataValueInterfaces]] git-tree-sha1 = "bfc1187b79289637fa0ef6d4436ebdfe6905cbd6" @@ -235,10 +240,10 @@ uuid = "8bb1440f-4735-579b-a4ab-409b98df4dab" version = "1.9.1" [[deps.DiffEqBase]] -deps = ["ArrayInterface", "ChainRulesCore", "DataStructures", "DocStringExtensions", "EnumX", "FastBroadcast", "ForwardDiff", "FunctionWrappers", "FunctionWrappersWrappers", "LinearAlgebra", "Logging", "Markdown", "MuladdMacro", "Parameters", "PreallocationTools", "Printf", "RecursiveArrayTools", "Reexport", "Requires", "SciMLBase", "Setfield", "SparseArrays", "Static", "StaticArraysCore", "Statistics", "Tricks", "TruncatedStacktraces", "ZygoteRules"] -git-tree-sha1 = "ed1108bd9a68977d5e0cbd8b2882293337c15f1c" +deps = ["ArrayInterface", "ChainRulesCore", "DataStructures", "DocStringExtensions", "EnumX", "FastBroadcast", "ForwardDiff", "FunctionWrappers", "FunctionWrappersWrappers", "LinearAlgebra", "Logging", "Markdown", "MuladdMacro", "Parameters", "PreallocationTools", "Printf", "RecursiveArrayTools", "Reexport", "Requires", "SciMLBase", "SciMLOperators", "Setfield", "SparseArrays", "Static", "StaticArraysCore", "Statistics", "Tricks", "TruncatedStacktraces", "ZygoteRules"] +git-tree-sha1 = "c5692436e7f8279503466db216c74165d1b301e4" uuid = "2b5f629d-d688-5b77-993f-72d75c75574e" -version = "6.124.0" +version = "6.127.0" [deps.DiffEqBase.extensions] DiffEqBaseDistributionsExt = "Distributions" @@ -270,9 +275,9 @@ version = "1.1.0" [[deps.DiffRules]] deps = ["IrrationalConstants", "LogExpFunctions", "NaNMath", "Random", "SpecialFunctions"] -git-tree-sha1 = "a4ad7ef19d2cdc2eff57abbbe68032b1cd0bd8f8" +git-tree-sha1 = "23163d55f885173722d1e4cf0f6110cdbaf7e272" uuid = "b552c78f-8df3-52c6-915a-8e097449b14b" -version = "1.13.0" +version = "1.15.1" [[deps.Distances]] deps = ["LinearAlgebra", "SparseArrays", "Statistics", "StatsAPI"] @@ -292,7 +297,7 @@ version = "0.9.3" [[deps.Documenter]] deps = ["ANSIColoredPrinters", "AbstractTrees", "Base64", "Dates", "DocStringExtensions", "IOCapture", "InteractiveUtils", "JSON", "LibGit2", "Logging", "Markdown", "MarkdownAST", "REPL", "SnoopPrecompile", "Test", "Unicode"] -git-tree-sha1 = "2afe1f1706b90fd4a8593d70b5324d04ddefed69" +git-tree-sha1 = "15192af26eb49bb61f7b780ae2482015bba24c40" repo-rev = "master" repo-url = "https://github.com/JuliaDocs/Documenter.jl.git" uuid = "e30172f5-a6a5-5a46-863b-614d45cd2de4" @@ -308,11 +313,17 @@ git-tree-sha1 = "bdb1942cd4c45e3c678fd11569d5cccd80976237" uuid = "4e289a0a-7415-4d19-859d-a7e5c4648b56" version = "1.0.4" +[[deps.ExceptionUnwrapping]] +deps = ["Test"] +git-tree-sha1 = "e90caa41f5a86296e014e148ee061bd6c3edec96" +uuid = "460bff9d-24e4-43bc-9d9f-a8973cb893f4" +version = "0.1.9" + [[deps.Expat_jll]] -deps = ["Artifacts", "JLLWrappers", "Libdl", "Pkg"] -git-tree-sha1 = "bad72f730e9e91c08d9427d5e8db95478a3c323d" +deps = ["Artifacts", "JLLWrappers", "Libdl"] +git-tree-sha1 = "4558ab818dcceaab612d1bb8c19cee87eda2b83c" uuid = "2e619515-83b5-522b-bb60-26c02a35a201" -version = "2.4.8+0" +version = "2.5.0+0" [[deps.ExponentialUtilities]] deps = ["Adapt", "ArrayInterface", "GPUArraysCore", "GenericSchur", "LinearAlgebra", "Printf", "SnoopPrecompile", "SparseArrays", "libblastrampoline_jll"] @@ -356,9 +367,9 @@ version = "0.3.2" [[deps.FastLapackInterface]] deps = ["LinearAlgebra"] -git-tree-sha1 = "c1293a93193f0ae94be7cf338d33e162c39d8788" +git-tree-sha1 = "b12f05108e405dadcc2aff0008db7f831374e051" uuid = "29a986be-02c6-4525-aec4-84b980013641" -version = "1.2.9" +version = "2.0.0" [[deps.Ferrite]] deps = ["EnumX", "LinearAlgebra", "NearestNeighbors", "Preferences", "Reexport", "SparseArrays", "StaticArrays", "Tensors", "WriteVTK"] @@ -391,15 +402,25 @@ uuid = "7b1f6079-737a-58dc-b8bc-7a2ca5c1b5ee" [[deps.FillArrays]] deps = ["LinearAlgebra", "Random", "SparseArrays", "Statistics"] -git-tree-sha1 = "fc86b4fd3eff76c3ce4f5e96e2fdfa6282722885" +git-tree-sha1 = "192cee6de045c39e26f4ce4b7e0f00a9dae14dd1" uuid = "1a297f60-69ca-5386-bcde-b61e274b549b" -version = "1.0.0" +version = "1.4.1" [[deps.FiniteDiff]] -deps = ["ArrayInterface", "LinearAlgebra", "Requires", "Setfield", "SparseArrays", "StaticArrays"] -git-tree-sha1 = "6604e18a0220650dbbea7854938768f15955dd8e" +deps = ["ArrayInterface", "LinearAlgebra", "Requires", "Setfield", "SparseArrays"] +git-tree-sha1 = "c6e4a1fbe73b31a3dea94b1da449503b8830c306" uuid = "6a86dc24-6348-571c-b903-95158fe2bd41" -version = "2.20.0" +version = "2.21.1" + + [deps.FiniteDiff.extensions] + FiniteDiffBandedMatricesExt = "BandedMatrices" + FiniteDiffBlockBandedMatricesExt = "BlockBandedMatrices" + FiniteDiffStaticArraysExt = "StaticArrays" + + [deps.FiniteDiff.weakdeps] + BandedMatrices = "aae01518-5342-5314-be14-df237901396f" + BlockBandedMatrices = "ffab5731-97b5-5995-9138-79e8c1846df0" + StaticArrays = "90137ffa-7385-5640-81b9-e52037218182" [[deps.FixedPointNumbers]] deps = ["Statistics"] @@ -430,10 +451,10 @@ weakdeps = ["StaticArrays"] ForwardDiffStaticArraysExt = "StaticArrays" [[deps.FreeType2_jll]] -deps = ["Artifacts", "Bzip2_jll", "JLLWrappers", "Libdl", "Pkg", "Zlib_jll"] -git-tree-sha1 = "87eb71354d8ec1a96d4a7636bd57a7347dde3ef9" +deps = ["Artifacts", "Bzip2_jll", "JLLWrappers", "Libdl", "Zlib_jll"] +git-tree-sha1 = "d8db6a5a2fe1381c1ea4ef2cab7c69c2de7f9ea0" uuid = "d7e528f0-a631-5988-bf34-fe36492bcfd7" -version = "2.10.4+0" +version = "2.13.1+0" [[deps.FriBidi_jll]] deps = ["Artifacts", "JLLWrappers", "Libdl", "Pkg"] @@ -475,21 +496,21 @@ version = "6.2.1+2" [[deps.GPUArraysCore]] deps = ["Adapt"] -git-tree-sha1 = "1cd7f0af1aa58abc02ea1d872953a97359cb87fa" +git-tree-sha1 = "2d6ca471a6c7b536127afccfa7564b5b39227fe0" uuid = "46192b85-c4d5-4398-a991-12ede77f4527" -version = "0.1.4" +version = "0.1.5" [[deps.GR]] deps = ["Artifacts", "Base64", "DelimitedFiles", "Downloads", "GR_jll", "HTTP", "JSON", "Libdl", "LinearAlgebra", "Pkg", "Preferences", "Printf", "Random", "Serialization", "Sockets", "TOML", "Tar", "Test", "UUIDs", "p7zip_jll"] -git-tree-sha1 = "efaac003187ccc71ace6c755b197284cd4811bfe" +git-tree-sha1 = "8e2d86e06ceb4580110d9e716be26658effc5bfd" uuid = "28b8d3ca-fb5f-59d9-8090-bfdbd6d07a71" -version = "0.72.4" +version = "0.72.8" [[deps.GR_jll]] deps = ["Artifacts", "Bzip2_jll", "Cairo_jll", "FFMPEG_jll", "Fontconfig_jll", "GLFW_jll", "JLLWrappers", "JpegTurbo_jll", "Libdl", "Libtiff_jll", "Pixman_jll", "Qt5Base_jll", "Zlib_jll", "libpng_jll"] -git-tree-sha1 = "4486ff47de4c18cb511a0da420efebb314556316" +git-tree-sha1 = "da121cbdc95b065da07fbb93638367737969693f" uuid = "d2c73de3-f751-5644-a686-071e5b155ba9" -version = "0.72.4+0" +version = "0.72.8+0" [[deps.GenericSchur]] deps = ["LinearAlgebra", "Printf"] @@ -539,10 +560,10 @@ uuid = "0234f1f7-429e-5d53-9886-15a909be8d59" version = "1.12.2+2" [[deps.HTTP]] -deps = ["Base64", "CodecZlib", "ConcurrentUtilities", "Dates", "Logging", "LoggingExtras", "MbedTLS", "NetworkOptions", "OpenSSL", "Random", "SimpleBufferStream", "Sockets", "URIs", "UUIDs"] -git-tree-sha1 = "69182f9a2d6add3736b7a06ab6416aafdeec2196" +deps = ["Base64", "CodecZlib", "ConcurrentUtilities", "Dates", "ExceptionUnwrapping", "Logging", "LoggingExtras", "MbedTLS", "NetworkOptions", "OpenSSL", "Random", "SimpleBufferStream", "Sockets", "URIs", "UUIDs"] +git-tree-sha1 = "cb56ccdd481c0dd7f975ad2b3b62d9eda088f7e2" uuid = "cd3eb016-35fb-5094-929b-558a96fad6f3" -version = "1.8.0" +version = "1.9.14" [[deps.HarfBuzz_jll]] deps = ["Artifacts", "Cairo_jll", "Fontconfig_jll", "FreeType2_jll", "Glib_jll", "Graphite2_jll", "JLLWrappers", "Libdl", "Libffi_jll", "Pkg"] @@ -552,15 +573,15 @@ version = "2.8.1+1" [[deps.HostCPUFeatures]] deps = ["BitTwiddlingConvenienceFunctions", "IfElse", "Libdl", "Static"] -git-tree-sha1 = "734fd90dd2f920a2f1921d5388dcebe805b262dc" +git-tree-sha1 = "d38bd0d9759e3c6cfa19bdccc314eccf8ce596cc" uuid = "3e5b6fbb-0976-4d2c-9146-d79de83f2fb0" -version = "0.1.14" +version = "0.1.15" [[deps.IOCapture]] deps = ["Logging", "Random"] -git-tree-sha1 = "f7be53659ab06ddc986428d3a9dcc95f6fa6705a" +git-tree-sha1 = "d75853a0bdbfb1ac815478bacd89cd27b550ace6" uuid = "b5f81e59-6552-4d32-b1f0-c071b021bf89" -version = "0.2.2" +version = "0.2.3" [[deps.IfElse]] git-tree-sha1 = "debdd00ffef04665ccbb3e150747a77560e8fad1" @@ -624,15 +645,9 @@ version = "0.4.0" [[deps.Krylov]] deps = ["LinearAlgebra", "Printf", "SparseArrays"] -git-tree-sha1 = "dd90aacbfb622f898a97c2a4411ac49101ebab8a" +git-tree-sha1 = "6dc4ad9cd74ad4ca0a8e219e945dbd22039f2125" uuid = "ba0b0d4f-ebba-5204-a429-3ac8c609bfb7" -version = "0.9.0" - -[[deps.KrylovKit]] -deps = ["ChainRulesCore", "GPUArraysCore", "LinearAlgebra", "Printf"] -git-tree-sha1 = "1a5e1d9941c783b0119897d29f2eb665d876ecf3" -uuid = "0b1a1467-8014-51b9-945f-bf0ae24f4b77" -version = "0.6.0" +version = "0.9.2" [[deps.LAME_jll]] deps = ["Artifacts", "JLLWrappers", "Libdl", "Pkg"] @@ -665,9 +680,9 @@ version = "1.3.0" [[deps.Latexify]] deps = ["Formatting", "InteractiveUtils", "LaTeXStrings", "MacroTools", "Markdown", "OrderedCollections", "Printf", "Requires"] -git-tree-sha1 = "099e356f267354f46ba65087981a77da23a279b7" +git-tree-sha1 = "f428ae552340899a935973270b8d98e5a31c49fe" uuid = "23fbe1c1-3f47-55db-b15f-69d7ec21a316" -version = "0.16.0" +version = "0.16.1" [deps.Latexify.extensions] DataFramesExt = "DataFrames" @@ -782,16 +797,24 @@ uuid = "18c40d15-f7cd-5a6d-bc92-87468d86c5db" version = "5.0.0+0" [[deps.LinearSolve]] -deps = ["ArrayInterface", "DocStringExtensions", "EnumX", "FastLapackInterface", "GPUArraysCore", "IterativeSolvers", "KLU", "Krylov", "KrylovKit", "LinearAlgebra", "Preferences", "RecursiveFactorization", "Reexport", "SciMLBase", "SciMLOperators", "Setfield", "SnoopPrecompile", "SparseArrays", "Sparspak", "SuiteSparse", "UnPack"] -git-tree-sha1 = "4a4f8cc7a59fadbb02d1852d1e0cef5dca3a9460" +deps = ["ArrayInterface", "DocStringExtensions", "EnumX", "FastLapackInterface", "GPUArraysCore", "InteractiveUtils", "KLU", "Krylov", "LinearAlgebra", "PrecompileTools", "Preferences", "RecursiveFactorization", "Reexport", "Requires", "SciMLBase", "SciMLOperators", "Setfield", "SparseArrays", "Sparspak", "SuiteSparse", "UnPack"] +git-tree-sha1 = "1b55771f2c211583ad52af5a5ca6475be374c961" uuid = "7ed4a6bd-45f5-4d41-b270-4a48e9bafcae" -version = "1.42.0" +version = "2.4.1" [deps.LinearSolve.extensions] - LinearSolveHYPRE = "HYPRE" + LinearSolveCUDAExt = "CUDA" + LinearSolveHYPREExt = "HYPRE" + LinearSolveIterativeSolversExt = "IterativeSolvers" + LinearSolveKrylovKitExt = "KrylovKit" + LinearSolvePardisoExt = "Pardiso" [deps.LinearSolve.weakdeps] + CUDA = "052768ef-5323-5732-b1bb-66c8b64840ba" HYPRE = "b5ffcf37-a2bd-41ab-a3da-4bd9bc8ad771" + IterativeSolvers = "42fd0dbc-a981-5370-80f2-aaf504508153" + KrylovKit = "0b1a1467-8014-51b9-945f-bf0ae24f4b77" + Pardiso = "46dd5b70-b6fb-5a00-ae2d-e8fea33afaf2" [[deps.Literate]] deps = ["Base64", "IOCapture", "JSON", "REPL"] @@ -800,16 +823,16 @@ uuid = "98b081ad-f1c9-55d3-8b20-4c87d4299306" version = "2.14.0" [[deps.LiveServer]] -deps = ["HTTP", "MIMEs", "Pkg", "Sockets"] -git-tree-sha1 = "494010f12dd98fa0d558cb7679b7c21d3a0a430a" +deps = ["HTTP", "MIMEs", "Pkg", "Sockets", "Test"] +git-tree-sha1 = "f47a6149a045fefea1d76f456e8e7caf90c4c81e" uuid = "16fef848-5104-11e9-1b77-fb7a48bbb589" -version = "1.2.0" +version = "1.2.4" [[deps.LogExpFunctions]] deps = ["DocStringExtensions", "IrrationalConstants", "LinearAlgebra"] -git-tree-sha1 = "0a1b7c2863e44523180fdb3146534e265a91870b" +git-tree-sha1 = "c3ce8e7420b3a6e071e0fe4745f5d4300e37b13f" uuid = "2ab3a3ac-af41-5b50-aa03-7779005ae688" -version = "0.3.23" +version = "0.3.24" [deps.LogExpFunctions.extensions] LogExpFunctionsChainRulesCoreExt = "ChainRulesCore" @@ -832,9 +855,9 @@ version = "1.0.0" [[deps.LoopVectorization]] deps = ["ArrayInterface", "ArrayInterfaceCore", "CPUSummary", "CloseOpenIntervals", "DocStringExtensions", "HostCPUFeatures", "IfElse", "LayoutPointers", "LinearAlgebra", "OffsetArrays", "PolyesterWeave", "PrecompileTools", "SIMDTypes", "SLEEFPirates", "Static", "StaticArrayInterface", "ThreadingUtilities", "UnPack", "VectorizationBase"] -git-tree-sha1 = "e7ce3cdc520da8135e73d7cb303e0617a19f582b" +git-tree-sha1 = "24e6c5697a6c93b5e10af2acf95f0b2e15303332" uuid = "bdcacae8-1622-11e9-2a5c-532679323890" -version = "0.12.158" +version = "0.12.163" weakdeps = ["ChainRulesCore", "ForwardDiff", "SpecialFunctions"] [deps.LoopVectorization.extensions] @@ -942,10 +965,10 @@ uuid = "ca575930-c2e3-43a9-ace4-1e988b2c1908" version = "1.2.0" [[deps.NonlinearSolve]] -deps = ["ArrayInterface", "DiffEqBase", "EnumX", "FiniteDiff", "ForwardDiff", "LinearAlgebra", "LinearSolve", "RecursiveArrayTools", "Reexport", "SciMLBase", "SimpleNonlinearSolve", "SnoopPrecompile", "SparseArrays", "SparseDiffTools", "StaticArraysCore", "UnPack"] -git-tree-sha1 = "a6000c813371cd3cd9cbbdf8a356fc3a97138d92" +deps = ["ArrayInterface", "DiffEqBase", "EnumX", "FiniteDiff", "ForwardDiff", "LinearAlgebra", "LinearSolve", "PrecompileTools", "RecursiveArrayTools", "Reexport", "SciMLBase", "SimpleNonlinearSolve", "SparseArrays", "SparseDiffTools", "StaticArraysCore", "UnPack"] +git-tree-sha1 = "2a7f28c62eb2c16b9c375c38f664cdcf22313cf5" uuid = "8913a72c-1f9b-4ce2-8d82-65094dcecaec" -version = "1.6.0" +version = "1.8.0" [[deps.OCCT_jll]] deps = ["Artifacts", "FreeType2_jll", "JLLWrappers", "Libdl", "Libglvnd_jll", "Pkg", "Xorg_libX11_jll", "Xorg_libXext_jll", "Xorg_libXfixes_jll", "Xorg_libXft_jll", "Xorg_libXinerama_jll", "Xorg_libXrender_jll"] @@ -955,9 +978,9 @@ version = "7.6.2+2" [[deps.OffsetArrays]] deps = ["Adapt"] -git-tree-sha1 = "82d7c9e310fe55aa54996e6f7f94674e2a38fcb4" +git-tree-sha1 = "2ac17d29c523ce1cd38e27785a7d23024853a4bb" uuid = "6fe1bfb0-de20-5000-8ca7-80f57d26f881" -version = "1.12.9" +version = "1.12.10" [[deps.Ogg_jll]] deps = ["Artifacts", "JLLWrappers", "Libdl", "Pkg"] @@ -982,10 +1005,10 @@ uuid = "4d8831e6-92b7-49fb-bdf8-b643e874388c" version = "1.4.1" [[deps.OpenSSL_jll]] -deps = ["Artifacts", "JLLWrappers", "Libdl", "Pkg"] -git-tree-sha1 = "9ff31d101d987eb9d66bd8b176ac7c277beccd09" +deps = ["Artifacts", "JLLWrappers", "Libdl"] +git-tree-sha1 = "1aa4b74f80b01c6bc2b89992b861b5f210e665b5" uuid = "458c3c95-2e84-50aa-8efc-19380b2a3a95" -version = "1.1.20+0" +version = "1.1.21+0" [[deps.OpenSpecFun_jll]] deps = ["Artifacts", "CompilerSupportLibraries_jll", "JLLWrappers", "Libdl", "Pkg"] @@ -995,9 +1018,9 @@ version = "0.5.5+0" [[deps.Optim]] deps = ["Compat", "FillArrays", "ForwardDiff", "LineSearches", "LinearAlgebra", "NLSolversBase", "NaNMath", "Parameters", "PositiveFactorizations", "Printf", "SparseArrays", "StatsBase"] -git-tree-sha1 = "a89b11f0f354f06099e4001c151dffad7ebab015" +git-tree-sha1 = "e3a6546c1577bfd701771b477b794a52949e7594" uuid = "429524aa-4258-5aef-a3af-852621145aeb" -version = "1.7.5" +version = "1.7.6" [[deps.Opus_jll]] deps = ["Artifacts", "JLLWrappers", "Libdl", "Pkg"] @@ -1011,16 +1034,22 @@ uuid = "bac558e1-5e72-5ebc-8fee-abe8a469f55d" version = "1.6.0" [[deps.OrdinaryDiffEq]] -deps = ["Adapt", "ArrayInterface", "DataStructures", "DiffEqBase", "DocStringExtensions", "ExponentialUtilities", "FastBroadcast", "FastClosures", "FiniteDiff", "ForwardDiff", "FunctionWrappersWrappers", "IfElse", "LineSearches", "LinearAlgebra", "LinearSolve", "Logging", "LoopVectorization", "MacroTools", "MuladdMacro", "NLsolve", "NonlinearSolve", "Polyester", "PreallocationTools", "PrecompileTools", "Preferences", "RecursiveArrayTools", "Reexport", "SciMLBase", "SciMLNLSolve", "SimpleNonlinearSolve", "SimpleUnPack", "SparseArrays", "SparseDiffTools", "StaticArrayInterface", "StaticArrays", "TruncatedStacktraces"] -git-tree-sha1 = "47fc5cf4174a7d45fa541669abc5405d9ef6b8df" +deps = ["ADTypes", "Adapt", "ArrayInterface", "DataStructures", "DiffEqBase", "DocStringExtensions", "ExponentialUtilities", "FastBroadcast", "FastClosures", "FiniteDiff", "ForwardDiff", "FunctionWrappersWrappers", "IfElse", "InteractiveUtils", "LineSearches", "LinearAlgebra", "LinearSolve", "Logging", "LoopVectorization", "MacroTools", "MuladdMacro", "NLsolve", "NonlinearSolve", "Polyester", "PreallocationTools", "PrecompileTools", "Preferences", "RecursiveArrayTools", "Reexport", "SciMLBase", "SciMLNLSolve", "SciMLOperators", "SimpleNonlinearSolve", "SimpleUnPack", "SparseArrays", "SparseDiffTools", "StaticArrayInterface", "StaticArrays", "TruncatedStacktraces"] +git-tree-sha1 = "4f1ab68f236fa846d0c30718c6b29c1665b019c0" uuid = "1dea7af3-3e70-54e6-95c3-0bf5283fa5ed" -version = "6.51.1" +version = "6.53.3" [[deps.PCRE2_jll]] deps = ["Artifacts", "Libdl"] uuid = "efcefdf7-47ab-520b-bdef-62a2eaa19f15" version = "10.42.0+0" +[[deps.PackageExtensionCompat]] +git-tree-sha1 = "32f3d52212a8d1c5d589a58851b1f04c97339110" +uuid = "65ce6f38-6b18-4e1d-a461-8949797d7930" +version = "1.0.0" +weakdeps = ["Requires", "TOML"] + [[deps.Parameters]] deps = ["OrderedCollections", "UnPack"] git-tree-sha1 = "34c0e9ad262e5f7fc75b10a9952ca7692cfc5fbe" @@ -1028,10 +1057,10 @@ uuid = "d96e819e-fc66-5662-9728-84c9c7592b0a" version = "0.12.3" [[deps.Parsers]] -deps = ["Dates", "SnoopPrecompile"] -git-tree-sha1 = "478ac6c952fddd4399e71d4779797c538d0ff2bf" +deps = ["Dates", "PrecompileTools", "UUIDs"] +git-tree-sha1 = "4b2e829ee66d4218e0cef22c0a64ee37cf258c29" uuid = "69de0a69-1ddd-5017-9359-2bf0b02dc9f0" -version = "2.5.8" +version = "2.7.1" [[deps.Pipe]] git-tree-sha1 = "6842804e7867b115ca9de748a0cf6b364523c16d" @@ -1039,15 +1068,15 @@ uuid = "b98c9c47-44ae-5843-9183-064241ee97a0" version = "1.3.0" [[deps.Pixman_jll]] -deps = ["Artifacts", "JLLWrappers", "Libdl", "Pkg"] -git-tree-sha1 = "b4f5d02549a10e20780a24fce72bea96b6329e29" +deps = ["Artifacts", "CompilerSupportLibraries_jll", "JLLWrappers", "LLVMOpenMP_jll", "Libdl"] +git-tree-sha1 = "64779bc4c9784fee475689a1752ef4d5747c5e87" uuid = "30392449-352a-5448-841d-b1acce4e97dc" -version = "0.40.1+0" +version = "0.42.2+0" [[deps.Pkg]] deps = ["Artifacts", "Dates", "Downloads", "FileWatching", "LibGit2", "Libdl", "Logging", "Markdown", "Printf", "REPL", "Random", "SHA", "Serialization", "TOML", "Tar", "UUIDs", "p7zip_jll"] uuid = "44cfe95a-1eb2-52ea-b672-e2afdf69b78f" -version = "1.9.0" +version = "1.9.2" [[deps.PlotThemes]] deps = ["PlotUtils", "Statistics"] @@ -1062,10 +1091,10 @@ uuid = "995b91a9-d308-5afd-9ec6-746e21dbc043" version = "1.3.5" [[deps.Plots]] -deps = ["Base64", "Contour", "Dates", "Downloads", "FFMPEG", "FixedPointNumbers", "GR", "JLFzf", "JSON", "LaTeXStrings", "Latexify", "LinearAlgebra", "Measures", "NaNMath", "Pkg", "PlotThemes", "PlotUtils", "PrecompileTools", "Preferences", "Printf", "REPL", "Random", "RecipesBase", "RecipesPipeline", "Reexport", "RelocatableFolders", "Requires", "Scratch", "Showoff", "SparseArrays", "Statistics", "StatsBase", "UUIDs", "UnicodeFun", "Unzip"] -git-tree-sha1 = "6c7f47fd112001fc95ea1569c2757dffd9e81328" +deps = ["Base64", "Contour", "Dates", "Downloads", "FFMPEG", "FixedPointNumbers", "GR", "JLFzf", "JSON", "LaTeXStrings", "Latexify", "LinearAlgebra", "Measures", "NaNMath", "Pkg", "PlotThemes", "PlotUtils", "PrecompileTools", "Preferences", "Printf", "REPL", "Random", "RecipesBase", "RecipesPipeline", "Reexport", "RelocatableFolders", "Requires", "Scratch", "Showoff", "SparseArrays", "Statistics", "StatsBase", "UUIDs", "UnicodeFun", "UnitfulLatexify", "Unzip"] +git-tree-sha1 = "75ca67b2c6512ad2d0c767a7cfc55e75075f8bbc" uuid = "91a5bcdd-55d7-5caf-9e0b-520d859cae80" -version = "1.38.11" +version = "1.38.16" [deps.Plots.extensions] FileIOExt = "FileIO" @@ -1113,9 +1142,9 @@ version = "0.4.12" [[deps.PrecompileTools]] deps = ["Preferences"] -git-tree-sha1 = "259e206946c293698122f63e2b513a7c99a244e8" +git-tree-sha1 = "9673d39decc5feece56ef3940e5dafba15ba0f81" uuid = "aea7be01-6a6a-4083-8856-8a6e6704d82a" -version = "1.1.1" +version = "1.1.2" [[deps.Preferences]] deps = ["TOML"] @@ -1161,9 +1190,9 @@ version = "0.6.12" [[deps.RecursiveArrayTools]] deps = ["Adapt", "ArrayInterface", "DocStringExtensions", "GPUArraysCore", "IteratorInterfaceExtensions", "LinearAlgebra", "RecipesBase", "Requires", "StaticArraysCore", "Statistics", "SymbolicIndexingInterface", "Tables"] -git-tree-sha1 = "68078e9fa9130a6a768815c48002d0921a232c11" +git-tree-sha1 = "7ed35fb5f831aaf09c2d7c8736d44667a1afdcb0" uuid = "731186ca-8d62-57ce-b412-fbd966d074cd" -version = "2.38.4" +version = "2.38.7" [deps.RecursiveArrayTools.extensions] RecursiveArrayToolsMeasurementsExt = "Measurements" @@ -1200,9 +1229,9 @@ version = "1.3.0" [[deps.RuntimeGeneratedFunctions]] deps = ["ExprTools", "SHA", "Serialization"] -git-tree-sha1 = "d7d9ebe28062161c1e314ed643097b0c6fe657d9" +git-tree-sha1 = "237edc1563bbf078629b4f8d194bd334e97907cf" uuid = "7e49a35a-f44a-4d26-94aa-eba1b4ca6b47" -version = "0.5.7" +version = "0.5.11" [[deps.SCOTCH_jll]] deps = ["Artifacts", "JLLWrappers", "Libdl", "Pkg", "Zlib_jll"] @@ -1215,10 +1244,10 @@ uuid = "ea8e919c-243c-51af-8825-aaa63cd721ce" version = "0.7.0" [[deps.SIMD]] -deps = ["SnoopPrecompile"] -git-tree-sha1 = "8b20084a97b004588125caebf418d8cab9e393d1" +deps = ["PrecompileTools"] +git-tree-sha1 = "0e270732477b9e551d884e6b07e23bb2ec947790" uuid = "fdea26ae-647d-5447-a871-4b548cad5224" -version = "3.4.4" +version = "3.4.5" [[deps.SIMDTypes]] git-tree-sha1 = "330289636fb8107c5f32088d2741e9fd7a061a5c" @@ -1227,27 +1256,27 @@ version = "0.1.0" [[deps.SLEEFPirates]] deps = ["IfElse", "Static", "VectorizationBase"] -git-tree-sha1 = "cda0aece8080e992f6370491b08ef3909d1c04e7" +git-tree-sha1 = "4b8586aece42bee682399c4c4aee95446aa5cd19" uuid = "476501e8-09a2-5ece-8869-fb82de89a1fa" -version = "0.6.38" +version = "0.6.39" [[deps.SciMLBase]] -deps = ["ArrayInterface", "CommonSolve", "ConstructionBase", "Distributed", "DocStringExtensions", "EnumX", "FunctionWrappersWrappers", "IteratorInterfaceExtensions", "LinearAlgebra", "Logging", "Markdown", "Preferences", "RecipesBase", "RecursiveArrayTools", "Reexport", "RuntimeGeneratedFunctions", "SciMLOperators", "SnoopPrecompile", "StaticArraysCore", "Statistics", "SymbolicIndexingInterface", "Tables", "TruncatedStacktraces"] -git-tree-sha1 = "392d3e28b05984496af37100ded94dc46fa6c8de" +deps = ["ADTypes", "ArrayInterface", "CommonSolve", "ConstructionBase", "Distributed", "DocStringExtensions", "EnumX", "FunctionWrappersWrappers", "IteratorInterfaceExtensions", "LinearAlgebra", "Logging", "Markdown", "PrecompileTools", "Preferences", "RecipesBase", "RecursiveArrayTools", "Reexport", "RuntimeGeneratedFunctions", "SciMLOperators", "StaticArraysCore", "Statistics", "SymbolicIndexingInterface", "Tables", "TruncatedStacktraces"] +git-tree-sha1 = "af577ca25a8e87c1143fb455770fbb1faba812b2" uuid = "0bca4576-84f4-4d90-8ffe-ffa030f20462" -version = "1.91.7" +version = "1.93.3" [[deps.SciMLNLSolve]] deps = ["DiffEqBase", "LineSearches", "NLsolve", "Reexport", "SciMLBase"] -git-tree-sha1 = "a8eb97c56cac50c21096582afb2a0110784dc36e" +git-tree-sha1 = "9dfc8e9e3d58c0c74f1a821c762b5349da13eccf" uuid = "e9a6253c-8580-4d32-9898-8661bb511710" -version = "0.1.6" +version = "0.1.8" [[deps.SciMLOperators]] deps = ["ArrayInterface", "DocStringExtensions", "Lazy", "LinearAlgebra", "Setfield", "SparseArrays", "StaticArraysCore", "Tricks"] -git-tree-sha1 = "5950ad7bec86ba22e4861db61d031625a26a9ec3" +git-tree-sha1 = "3ff715d32b305c7793683953f718c5c5d002ba3c" uuid = "c0aeaf25-5076-4817-a8d5-81caf7dfa961" -version = "0.2.3" +version = "0.3.4" [[deps.Scratch]] deps = ["Dates"] @@ -1280,13 +1309,13 @@ uuid = "777ac1f9-54b0-4bf8-805c-2214025038e7" version = "1.1.0" [[deps.SimpleNonlinearSolve]] -deps = ["ArrayInterface", "DiffEqBase", "FiniteDiff", "ForwardDiff", "LinearAlgebra", "Reexport", "Requires", "SciMLBase", "SnoopPrecompile", "StaticArraysCore"] -git-tree-sha1 = "54c78ac3cc0343a16785adabe5bbf4063c737967" +deps = ["ArrayInterface", "DiffEqBase", "FiniteDiff", "ForwardDiff", "LinearAlgebra", "PackageExtensionCompat", "PrecompileTools", "Reexport", "SciMLBase", "StaticArraysCore"] +git-tree-sha1 = "d4005f0ada4442c0cd7a63705d6043b442d41990" uuid = "727e6d20-b764-4bd8-a329-72de5adea6c7" -version = "0.1.14" +version = "0.1.17" [deps.SimpleNonlinearSolve.extensions] - SimpleBatchedNonlinearSolveExt = "NNlib" + SimpleNonlinearSolveNNlibExt = "NNlib" [deps.SimpleNonlinearSolve.weakdeps] NNlib = "872c559c-99b0-510c-b3b7-b6c96a88d5cd" @@ -1313,19 +1342,25 @@ uuid = "6462fe0b-24de-5631-8697-dd941f90decc" [[deps.SortingAlgorithms]] deps = ["DataStructures"] -git-tree-sha1 = "a4ada03f999bd01b3a25dcaa30b2d929fe537e00" +git-tree-sha1 = "c60ec5c62180f27efea3ba2908480f8055e17cee" uuid = "a2af1166-a08f-5f64-846c-94a0d3cef48c" -version = "1.1.0" +version = "1.1.1" [[deps.SparseArrays]] deps = ["Libdl", "LinearAlgebra", "Random", "Serialization", "SuiteSparse_jll"] uuid = "2f01184e-e22b-5df5-ae63-d93ebab69eaf" [[deps.SparseDiffTools]] -deps = ["Adapt", "ArrayInterface", "Compat", "DataStructures", "FiniteDiff", "ForwardDiff", "Graphs", "LinearAlgebra", "Requires", "SparseArrays", "StaticArrays", "VertexSafeGraphs"] -git-tree-sha1 = "e19ac47477c9a8fcca06dab5e5471417d5d9d723" +deps = ["ADTypes", "Adapt", "ArrayInterface", "Compat", "DataStructures", "FiniteDiff", "ForwardDiff", "Graphs", "LinearAlgebra", "Reexport", "Requires", "SciMLOperators", "Setfield", "SparseArrays", "StaticArrayInterface", "StaticArrays", "Tricks", "VertexSafeGraphs"] +git-tree-sha1 = "4c1a57bcbc0b795fbfdc2009e70f9c2fd2815bfe" uuid = "47a9eef4-7e08-11e9-0b38-333d64bd3804" -version = "1.31.0" +version = "2.4.1" + + [deps.SparseDiffTools.extensions] + SparseDiffToolsZygoteExt = "Zygote" + + [deps.SparseDiffTools.weakdeps] + Zygote = "e88e6eb3-aa80-5325-afca-941959d7151f" [[deps.Sparspak]] deps = ["Libdl", "LinearAlgebra", "Logging", "OffsetArrays", "Printf", "SparseArrays", "Test"] @@ -1335,9 +1370,9 @@ version = "0.3.9" [[deps.SpecialFunctions]] deps = ["IrrationalConstants", "LogExpFunctions", "OpenLibm_jll", "OpenSpecFun_jll"] -git-tree-sha1 = "ef28127915f4229c971eb43f3fc075dd3fe91880" +git-tree-sha1 = "7beb031cf8145577fbccacd94b8a8f4ce78428d3" uuid = "276daf66-3868-5448-9aa4-cd146d93841b" -version = "2.2.0" +version = "2.3.0" weakdeps = ["ChainRulesCore"] [deps.SpecialFunctions.extensions] @@ -1345,9 +1380,9 @@ weakdeps = ["ChainRulesCore"] [[deps.Static]] deps = ["IfElse"] -git-tree-sha1 = "08be5ee09a7632c32695d954a602df96a877bf0d" +git-tree-sha1 = "dbde6766fc677423598138a5951269432b0fcc90" uuid = "aedffcd0-7271-4cad-89d0-dc628f76c6d3" -version = "0.8.6" +version = "0.8.7" [[deps.StaticArrayInterface]] deps = ["ArrayInterface", "Compat", "IfElse", "LinearAlgebra", "Requires", "SnoopPrecompile", "SparseArrays", "Static", "SuiteSparse"] @@ -1361,15 +1396,19 @@ weakdeps = ["OffsetArrays", "StaticArrays"] StaticArrayInterfaceStaticArraysExt = "StaticArrays" [[deps.StaticArrays]] -deps = ["LinearAlgebra", "Random", "StaticArraysCore", "Statistics"] -git-tree-sha1 = "c262c8e978048c2b095be1672c9bee55b4619521" +deps = ["LinearAlgebra", "Random", "StaticArraysCore"] +git-tree-sha1 = "fffc14c695c17bfdbfa92a2a01836cdc542a1e46" uuid = "90137ffa-7385-5640-81b9-e52037218182" -version = "1.5.24" +version = "1.6.1" +weakdeps = ["Statistics"] + + [deps.StaticArrays.extensions] + StaticArraysStatisticsExt = "Statistics" [[deps.StaticArraysCore]] -git-tree-sha1 = "6b7ba252635a5eff6a0b0664a41ee140a1c9e72a" +git-tree-sha1 = "36b3d696ce6366023a0ea192b4cd442268995a0d" uuid = "1e83bf80-4336-4d27-bf5d-d5a4f845583c" -version = "1.4.0" +version = "1.4.2" [[deps.Statistics]] deps = ["LinearAlgebra", "SparseArrays"] @@ -1384,15 +1423,15 @@ version = "1.6.0" [[deps.StatsBase]] deps = ["DataAPI", "DataStructures", "LinearAlgebra", "LogExpFunctions", "Missings", "Printf", "Random", "SortingAlgorithms", "SparseArrays", "Statistics", "StatsAPI"] -git-tree-sha1 = "d1bf48bfcc554a3761a133fe3a9bb01488e06916" +git-tree-sha1 = "75ebe04c5bed70b91614d684259b661c9e6274a4" uuid = "2913bbd2-ae8a-5f71-8c99-4fb6c76f3a91" -version = "0.33.21" +version = "0.34.0" [[deps.StrideArraysCore]] deps = ["ArrayInterface", "CloseOpenIntervals", "IfElse", "LayoutPointers", "ManualMemory", "SIMDTypes", "Static", "StaticArrayInterface", "ThreadingUtilities"] -git-tree-sha1 = "b3e9c174a9df77ed7b66fc0aa605def3351a0653" +git-tree-sha1 = "f02eb61eb5c97b48c153861c72fbbfdddc607e06" uuid = "7792a7ef-975c-4747-a70f-980b88e8d1da" -version = "0.4.13" +version = "0.4.17" [[deps.SuiteSparse]] deps = ["Libdl", "LinearAlgebra", "Serialization", "SparseArrays"] @@ -1438,10 +1477,10 @@ uuid = "62fd8b95-f654-4bbd-a8a5-9c27f68ccd50" version = "0.1.1" [[deps.Tensors]] -deps = ["ForwardDiff", "LinearAlgebra", "SIMD", "SnoopPrecompile", "StaticArrays", "Statistics"] -git-tree-sha1 = "71f054343e85ab1eab12bf8336004309002ff82d" +deps = ["ForwardDiff", "LinearAlgebra", "PrecompileTools", "SIMD", "StaticArrays", "Statistics"] +git-tree-sha1 = "f6cb7a764c8afca494a27d74430c9b3eb40ce2b8" uuid = "48a634ad-e948-5137-8d70-aa71f2a747f4" -version = "1.13.1" +version = "1.14.0" [[deps.Test]] deps = ["InteractiveUtils", "Logging", "Random", "Serialization"] @@ -1449,9 +1488,9 @@ uuid = "8dfed614-e22c-5e08-85e1-65c5234f0b40" [[deps.ThreadingUtilities]] deps = ["ManualMemory"] -git-tree-sha1 = "c97f60dd4f2331e1a495527f80d242501d2f9865" +git-tree-sha1 = "eda08f7e9818eb53661b3deb74e3159460dfbc27" uuid = "8290d209-cae3-49c0-8002-c8c24d57dab5" -version = "0.5.1" +version = "0.5.2" [[deps.TimerOutputs]] deps = ["ExprTools", "Printf"] @@ -1478,9 +1517,9 @@ version = "0.1.7" [[deps.TruncatedStacktraces]] deps = ["InteractiveUtils", "MacroTools", "Preferences"] -git-tree-sha1 = "7bc1632a4eafbe9bd94cf1a784a9a4eb5e040a91" +git-tree-sha1 = "ea3e54c2bdde39062abf5a9758a23735558705e1" uuid = "781d530d-4396-4725-bb49-402e4bee1e77" -version = "1.3.0" +version = "1.4.0" [[deps.URIs]] git-tree-sha1 = "074f993b0ca030848b897beff716d93aca60f06a" @@ -1505,6 +1544,26 @@ git-tree-sha1 = "53915e50200959667e78a92a418594b428dffddf" uuid = "1cfade01-22cf-5700-b092-accc4b62d6e1" version = "0.4.1" +[[deps.Unitful]] +deps = ["Dates", "LinearAlgebra", "Random"] +git-tree-sha1 = "c4d2a349259c8eba66a00a540d550f122a3ab228" +uuid = "1986cc42-f94f-5a68-af5c-568840ba703d" +version = "1.15.0" + + [deps.Unitful.extensions] + ConstructionBaseUnitfulExt = "ConstructionBase" + InverseFunctionsUnitfulExt = "InverseFunctions" + + [deps.Unitful.weakdeps] + ConstructionBase = "187b0558-2788-49d3-abe0-74a17ed4e7c9" + InverseFunctions = "3587e190-3f89-42d0-90ee-14403ec27112" + +[[deps.UnitfulLatexify]] +deps = ["LaTeXStrings", "Latexify", "Unitful"] +git-tree-sha1 = "e2d817cc500e960fdbafcf988ac8436ba3208bfd" +uuid = "45397f5d-5981-4c77-b2b3-fc36d6e9b728" +version = "1.6.3" + [[deps.Unzip]] git-tree-sha1 = "ca0969166a028236229f63514992fc073799bb78" uuid = "41fe7b60-77ed-43a1-b4f0-825fd5a5650d" @@ -1558,16 +1617,16 @@ uuid = "aed1982a-8fda-507f-9586-7b0439959a61" version = "1.1.34+0" [[deps.Xorg_libX11_jll]] -deps = ["Artifacts", "JLLWrappers", "Libdl", "Pkg", "Xorg_libxcb_jll", "Xorg_xtrans_jll"] -git-tree-sha1 = "5be649d550f3f4b95308bf0183b82e2582876527" +deps = ["Artifacts", "JLLWrappers", "Libdl", "Xorg_libxcb_jll", "Xorg_xtrans_jll"] +git-tree-sha1 = "afead5aba5aa507ad5a3bf01f58f82c8d1403495" uuid = "4f6342f7-b3d2-589e-9d20-edeb45f2b2bc" -version = "1.6.9+4" +version = "1.8.6+0" [[deps.Xorg_libXau_jll]] -deps = ["Artifacts", "JLLWrappers", "Libdl", "Pkg"] -git-tree-sha1 = "4e490d5c960c314f33885790ed410ff3a94ce67e" +deps = ["Artifacts", "JLLWrappers", "Libdl"] +git-tree-sha1 = "6035850dcc70518ca32f012e46015b9beeda49d8" uuid = "0c0b7dd1-d40b-584c-a123-a41640f87eec" -version = "1.0.9+4" +version = "1.0.11+0" [[deps.Xorg_libXcursor_jll]] deps = ["Artifacts", "JLLWrappers", "Libdl", "Pkg", "Xorg_libXfixes_jll", "Xorg_libXrender_jll"] @@ -1576,10 +1635,10 @@ uuid = "935fb764-8cf2-53bf-bb30-45bb1f8bf724" version = "1.2.0+4" [[deps.Xorg_libXdmcp_jll]] -deps = ["Artifacts", "JLLWrappers", "Libdl", "Pkg"] -git-tree-sha1 = "4fe47bd2247248125c428978740e18a681372dd4" +deps = ["Artifacts", "JLLWrappers", "Libdl"] +git-tree-sha1 = "34d526d318358a859d7de23da945578e8e8727b7" uuid = "a3789734-cfe1-5b06-b2d0-1dd0d9d62d05" -version = "1.1.3+4" +version = "1.1.4+0" [[deps.Xorg_libXext_jll]] deps = ["Artifacts", "JLLWrappers", "Libdl", "Pkg", "Xorg_libX11_jll"] @@ -1624,22 +1683,22 @@ uuid = "ea2f1a96-1ddc-540d-b46f-429655e07cfa" version = "0.9.10+4" [[deps.Xorg_libpthread_stubs_jll]] -deps = ["Artifacts", "JLLWrappers", "Libdl", "Pkg"] -git-tree-sha1 = "6783737e45d3c59a4a4c4091f5f88cdcf0908cbb" +deps = ["Artifacts", "JLLWrappers", "Libdl"] +git-tree-sha1 = "8fdda4c692503d44d04a0603d9ac0982054635f9" uuid = "14d82f49-176c-5ed1-bb49-ad3f5cbd8c74" -version = "0.1.0+3" +version = "0.1.1+0" [[deps.Xorg_libxcb_jll]] -deps = ["Artifacts", "JLLWrappers", "Libdl", "Pkg", "XSLT_jll", "Xorg_libXau_jll", "Xorg_libXdmcp_jll", "Xorg_libpthread_stubs_jll"] -git-tree-sha1 = "daf17f441228e7a3833846cd048892861cff16d6" +deps = ["Artifacts", "JLLWrappers", "Libdl", "XSLT_jll", "Xorg_libXau_jll", "Xorg_libXdmcp_jll", "Xorg_libpthread_stubs_jll"] +git-tree-sha1 = "b4bfde5d5b652e22b9c790ad00af08b6d042b97d" uuid = "c7cfdc94-dc32-55de-ac96-5a1b8d977c5b" -version = "1.13.0+3" +version = "1.15.0+0" [[deps.Xorg_libxkbfile_jll]] -deps = ["Artifacts", "JLLWrappers", "Libdl", "Pkg", "Xorg_libX11_jll"] -git-tree-sha1 = "926af861744212db0eb001d9e40b5d16292080b2" +deps = ["Artifacts", "JLLWrappers", "Libdl", "Xorg_libX11_jll"] +git-tree-sha1 = "730eeca102434283c50ccf7d1ecdadf521a765a4" uuid = "cc61e674-0454-545c-8b26-ed2c68acab7a" -version = "1.1.0+4" +version = "1.1.2+0" [[deps.Xorg_xcb_util_image_jll]] deps = ["Artifacts", "JLLWrappers", "Libdl", "Pkg", "Xorg_xcb_util_jll"] @@ -1672,22 +1731,22 @@ uuid = "c22f9ab0-d5fe-5066-847c-f4bb1cd4e361" version = "0.4.1+1" [[deps.Xorg_xkbcomp_jll]] -deps = ["Artifacts", "JLLWrappers", "Libdl", "Pkg", "Xorg_libxkbfile_jll"] -git-tree-sha1 = "4bcbf660f6c2e714f87e960a171b119d06ee163b" +deps = ["Artifacts", "JLLWrappers", "Libdl", "Xorg_libxkbfile_jll"] +git-tree-sha1 = "330f955bc41bb8f5270a369c473fc4a5a4e4d3cb" uuid = "35661453-b289-5fab-8a00-3d9160c6a3a4" -version = "1.4.2+4" +version = "1.4.6+0" [[deps.Xorg_xkeyboard_config_jll]] -deps = ["Artifacts", "JLLWrappers", "Libdl", "Pkg", "Xorg_xkbcomp_jll"] -git-tree-sha1 = "5c8424f8a67c3f2209646d4425f3d415fee5931d" +deps = ["Artifacts", "JLLWrappers", "Libdl", "Xorg_xkbcomp_jll"] +git-tree-sha1 = "691634e5453ad362044e2ad653e79f3ee3bb98c3" uuid = "33bec58e-1273-512f-9401-5d533626f822" -version = "2.27.0+4" +version = "2.39.0+0" [[deps.Xorg_xtrans_jll]] -deps = ["Artifacts", "JLLWrappers", "Libdl", "Pkg"] -git-tree-sha1 = "79c31e7844f6ecf779705fbc12146eb190b7d845" +deps = ["Artifacts", "JLLWrappers", "Libdl"] +git-tree-sha1 = "e92a1a012a10506618f10b7047e478403a046c77" uuid = "c5fb5394-a638-5e4d-96e5-b29de1b5cf10" -version = "1.4.0+3" +version = "1.5.0+0" [[deps.Zlib_jll]] deps = ["Libdl"] diff --git a/docs/src/literate-gallery/helmholtz.jl b/docs/src/literate-gallery/helmholtz.jl index e1f41124a2..f7a73d788a 100644 --- a/docs/src/literate-gallery/helmholtz.jl +++ b/docs/src/literate-gallery/helmholtz.jl @@ -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) +vtks = VTKStream("helmholtz", grid) +write_solution(vtks, dh, u) +close(vtks) using Test #src #src this test catches unexpected changes in the result over time. #src the true maximum is slightly bigger then 1.0 diff --git a/docs/src/literate-gallery/landau.jl b/docs/src/literate-gallery/landau.jl index e28eb75f8e..819f4092ec 100644 --- a/docs/src/literate-gallery/landau.jl +++ b/docs/src/literate-gallery/landau.jl @@ -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) + VTKStream(path, model.dofhandler.grid) do vtks + write_solution(vtks, model.dofhandler, dofs) + end end # ## Assembly @@ -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, diff --git a/docs/src/literate-gallery/quasi_incompressible_hyperelasticity.jl b/docs/src/literate-gallery/quasi_incompressible_hyperelasticity.jl index cc709ff59a..b4ae726030 100644 --- a/docs/src/literate-gallery/quasi_incompressible_hyperelasticity.jl +++ b/docs/src/literate-gallery/quasi_incompressible_hyperelasticity.jl @@ -334,10 +334,9 @@ 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 + VTKStream("hyperelasticity_incomp_mixed_$t.vtu", grid) do vtks + write_solution(vtks, dh, w) + pvd[t] = vtks end end; vtk_save(pvd); diff --git a/docs/src/literate-gallery/topology_optimization.jl b/docs/src/literate-gallery/topology_optimization.jl index ed86aa7a82..fec8c2dcce 100644 --- a/docs/src/literate-gallery/topology_optimization.jl +++ b/docs/src/literate-gallery/topology_optimization.jl @@ -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") + VTKStream(filename_it, grid) do vtks + write_celldata(vtks, grid, χ, "density") end end end ## export converged results if(!output) - vtk_grid(filename, grid) do vtk - vtk_cell_data(vtk, χ, "density") + VTKStream(filename, grid) do vtks + write_celldata(vtks, grid, χ, "density") end end @printf "Rel. stiffness: %.4f \n" compliance^(-1)/compliance_0^(-1) diff --git a/docs/src/literate-howto/postprocessing.jl b/docs/src/literate-howto/postprocessing.jl index dffd61965b..e2bcb819fa 100644 --- a/docs/src/literate-howto/postprocessing.jl +++ b/docs/src/literate-howto/postprocessing.jl @@ -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") +VTKStream("heat_equation_flux", grid) do vtks + write_projected(vtks, projector, q_projected, "q") end; # ## Point Evaluation diff --git a/docs/src/literate-howto/threaded_assembly.jl b/docs/src/literate-howto/threaded_assembly.jl index 2a959212f2..47271849df 100644 --- a/docs/src/literate-howto/threaded_assembly.jl +++ b/docs/src/literate-howto/threaded_assembly.jl @@ -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") + VTKStream("colored", grid) do vtks + write_cell_colors(vtks, grid, colors_workstream, "workstream-coloring") + write_cell_colors(vtks, grid, colors_greedy, "greedy-coloring") end end diff --git a/docs/src/literate-tutorials/computational_homogenization.jl b/docs/src/literate-tutorials/computational_homogenization.jl index 1a06cf495c..63c26aba88 100644 --- a/docs/src/literate-tutorials/computational_homogenization.jl +++ b/docs/src/literate-tutorials/computational_homogenization.jl @@ -518,16 +518,16 @@ round.(ev; digits=-8) uM = zeros(ndofs(dh)) -vtk_grid("homogenization", dh) do vtk +VTKStream("homogenization", grid) do vtks 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(vtks, dh, uM + u.dirichlet[i], "_dirichlet_$i") + write_projected(vtks, 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(vtks, dh, uM + u.periodic[i], "_periodic_$i") + write_projected(vtks, projector, σ.periodic[i], "σvM_periodic_$i") end end; diff --git a/docs/src/literate-tutorials/heat_equation.jl b/docs/src/literate-tutorials/heat_equation.jl index 4a82dac7b7..aa6ec1c91f 100644 --- a/docs/src/literate-tutorials/heat_equation.jl +++ b/docs/src/literate-tutorials/heat_equation.jl @@ -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) +VTKStream("heat_equation", grid) do vtks + write_solution(vtks, dh, u) end ## test the result #src diff --git a/docs/src/literate-tutorials/hyperelasticity.jl b/docs/src/literate-tutorials/hyperelasticity.jl index 63eb9a9369..37d0d5e6ca 100644 --- a/docs/src/literate-tutorials/hyperelasticity.jl +++ b/docs/src/literate-tutorials/hyperelasticity.jl @@ -397,8 +397,8 @@ function solve() ## Save the solution @timeit "export" begin - vtk_grid("hyperelasticity", dh) do vtkfile - vtk_point_data(vtkfile, dh, u) + VTKStream("hyperelasticity", grid) do vtks + write_solution(vtks, dh, u) end end diff --git a/docs/src/literate-tutorials/incompressible_elasticity.jl b/docs/src/literate-tutorials/incompressible_elasticity.jl index 98c180fb5f..cccf771fe3 100644 --- a/docs/src/literate-tutorials/incompressible_elasticity.jl +++ b/docs/src/literate-tutorials/incompressible_elasticity.jl @@ -209,8 +209,8 @@ function solve(ν, interpolation_u, interpolation_p) ## export filename = "cook_" * (isa(interpolation_u, Lagrange{RefTriangle,1}) ? "linear" : "quadratic") * "_linear" - vtk_grid(filename, dh) do vtkfile - vtk_point_data(vtkfile, dh, u) + VTKStream(filename, grid) do vtks + write_solution(vtks, dh, u) end return u end diff --git a/docs/src/literate-tutorials/linear_shell.jl b/docs/src/literate-tutorials/linear_shell.jl index e5927b42e3..ea1cfd467e 100644 --- a/docs/src/literate-tutorials/linear_shell.jl +++ b/docs/src/literate-tutorials/linear_shell.jl @@ -113,8 +113,8 @@ a = K\f # Output results. #+ -vtk_grid("linear_shell", dh) do vtk - vtk_point_data(vtk, dh, a) +VTKStream("linear_shell", grid) do vtks + write_solution(vtks, dh, a) end end; #end main functions diff --git a/docs/src/literate-tutorials/ns_vs_diffeq.jl b/docs/src/literate-tutorials/ns_vs_diffeq.jl index 886bc8a490..f532bc82be 100644 --- a/docs/src/literate-tutorials/ns_vs_diffeq.jl +++ b/docs/src/literate-tutorials/ns_vs_diffeq.jl @@ -440,10 +440,9 @@ 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 + VTKStream("vortex-street-$t.vtu", grid) do vtks + write_solution(vtks, dh, u) + pvd[t] = vtks end end vtk_save(pvd); diff --git a/docs/src/literate-tutorials/plasticity.jl b/docs/src/literate-tutorials/plasticity.jl index c1ec97781a..1276d7b4ba 100644 --- a/docs/src/literate-tutorials/plasticity.jl +++ b/docs/src/literate-tutorials/plasticity.jl @@ -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]") + VTKStream("plasticity", grid) do vtks + write_solution(vtks, dh, u) # displacement field + write_celldata(vtks, grid, mises_values, "von Mises [Pa]") + write_celldata(vtks, grid, κ_values, "Drag stress [Pa]") end return u_max, traction_magnitude diff --git a/docs/src/literate-tutorials/stokes-flow.jl b/docs/src/literate-tutorials/stokes-flow.jl index 2ad2eb544d..c1f027ac24 100644 --- a/docs/src/literate-tutorials/stokes-flow.jl +++ b/docs/src/literate-tutorials/stokes-flow.jl @@ -505,8 +505,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) + VTKStream("stokes-flow", grid) do vtks + write_solution(vtks, dh, u) end ## Check the result #src diff --git a/docs/src/literate-tutorials/transient_heat_equation.jl b/docs/src/literate-tutorials/transient_heat_equation.jl index b25a822aa4..3766412b7a 100644 --- a/docs/src/literate-tutorials/transient_heat_equation.jl +++ b/docs/src/literate-tutorials/transient_heat_equation.jl @@ -192,10 +192,9 @@ apply!(A, ch); # To store the solution, we initialize a `paraview_collection` (.pvd) file. pvd = paraview_collection("transient-heat.pvd"); t = 0 -vtk_grid("transient-heat-$t", dh) do vtk - vtk_point_data(vtk, dh, uₙ) - vtk_save(vtk) - pvd[t] = vtk +VTKStream("transient-heat-$t", grid) do vtks + write_solution(vtks, dh, uₙ) + pvd[t] = vtks end # At this point everything is set up and we can finally approach the time loop. @@ -211,10 +210,9 @@ 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 + VTKStream("transient-heat-$t", grid) do vtks + write_solution(vtks, dh, u) + pvd[t] = vtks 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 diff --git a/docs/src/reference/export.md b/docs/src/reference/export.md index 2fc0b26a53..05f00394dd 100644 --- a/docs/src/reference/export.md +++ b/docs/src/reference/export.md @@ -26,8 +26,13 @@ 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 +VTKStream +write_solution +write_projected +write_celldata +write_nodedata +write_cellset +write_nodeset +write_dirichlet +write_cell_colors ``` diff --git a/docs/src/topics/export.md b/docs/src/topics/export.md index 855b5d62c8..f3510361ff 100644 --- a/docs/src/topics/export.md +++ b/docs/src/topics/export.md @@ -10,98 +10,34 @@ u = rand(ndofs(dh)); σ = rand(getncells(grid)) 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`](https://www.paraview.org/). -To write VTK-files, Ferrite uses, and extends, functions from the -[`WriteVTK.jl`](https://github.com/jipolanco/WriteVTK.jl) package to simplify +To write VTK-files, Ferrite comes with a filestream with a +[`WriteVTK.jl`](https://github.com/jipolanco/WriteVTK.jl) backend to simplify the exporting. -First we need to create a file, based on the grid. This is done with the -`vtk_grid` function: +The following structure can be used to write various output to a vtk-file: ```@example export -vtk = vtk_grid("my-solution", grid) -# hide -``` - -Next we have to add data to the file. We may add different kinds of data; -point data using `vtk_point_data` or cell data using -`vtk_cell_data`. Point data is data for each nodal coordinate in the -grid, for example our solution vector. Point data can be either scalars -or vectors. Cell data is -- as the name suggests -- data for each cell. This -can be for example the stress. As an example, lets add a solution vector `u` -as point data, and a vector with stress for each cell, `σ`, as cell data: - -```@example export -vtk_point_data(vtk, u, "my-point-data") -vtk_cell_data(vtk, σ, "my-cell-data") -# hide -``` - -Finally, we need to save the file to disk, using `vtk_save` - -```@example export -vtk_save(vtk) -rm("my-solution.vtu") # hide -``` - -Alternatively, all of the above can be done using a `do` block: - -```@example export -vtk_grid("my-solution", grid) do vtk - vtk_point_data(vtk, u, "my-point-data") - vtk_cell_data(vtk, σ, "my-cell-data") +VTKStream("my_solution", grid) do vtks + write_(vtks, args...) end -rm("my-solution.vtu") # hide ``` +where `write_` can be -For other functionality, and more information refer to the -[`WriteVTK.jl` README](https://github.com/jipolanco/WriteVTK.jl/blob/master/README.md). -In particular, for exporting the solution at multiple time steps, the -[section on PVD files](https://github.com/jipolanco/WriteVTK.jl#paraview-data-pvd-file-format) -is useful. - -## Exporting with `DofHandler` - -There is an even more convenient way to export a solution vector `u` -- using the -`DofHandler`. The `DofHandler` already contains all of the information needed, -such as the names of our fields and if they are scalar or vector fields. But most -importantly the `DofHandler` knows about the numbering and distribution of -degrees of freedom, and thus knows how to "distribute" the solution vector on -the grid. For example, lets say we have a `DofHandler` `dh` and a solution -vector `u`: - -```@example export -vtk = vtk_grid("my-solution", dh) -vtk_point_data(vtk, dh, u) -vtk_save(vtk) -rm("my-solution.vtu") # hide -``` - -or with a `do`-block: +* [`write_solution`](@ref) +* [`write_celldata`](@ref) +* [`write_nodedata`](@ref) +* [`write_projected`](@ref) +* [`write_cellset`](@ref) +* [`write_nodeset`](@ref) +* [`write_dirichlet`](@ref) +* [`write_cell_colors`](@ref) +Instead of using the `do`-block, it is also possible to do ```@example export -vtk_grid("my-solution", dh) do vtk - vtk_point_data(vtk, dh, u) - vtk_cell_data(vtk, σ, "my-cell-data") -end -rm("my-solution.vtu") # hide -``` - -When `vtk_point_data` is used with a `DofHandler` all of the fields will be -written to the VTK file, and the names will be determined by the fieldname -symbol that was used when the field was added to the `DofHandler`. - -## Exporting Boundary Conditions - -There is also a `vtk_point_data` which accepts a `ConstraintHandler`. -This method is useful to verify that the boundary conditions are -applied where they are supposed to. For a `ConstraintHandler` `ch` -we can export the boundary conditions as - -```julia -vtk_grid("boundary-conditions", grid) do vtk - vtk_point_data(vtk, ch) -end +vtks = VTKStream("my_solution", grid) +write_(vtks, args...) +# ... +close(vtks) ``` -This will export zero-valued fields with ones on the parts where the -boundary conditions are active. +The data written by `write_solution`, `write_celldata`, `write_nodedata`, and `write_projected` may be either scalar (`Vector{<:Number}`) or tensor (`Vector{<:AbstractTensor}`) data. \ No newline at end of file diff --git a/src/exports.jl b/src/exports.jl index a1d36c8970..2a83535bd6 100644 --- a/src/exports.jl +++ b/src/exports.jl @@ -146,8 +146,17 @@ export assemble!, finish_assemble, -# VTK export - +# (VTK) export stream + VTKStream, + write_solution, + write_celldata, + write_nodedata, + write_projected, + write_nodeset, + write_cellset, + write_cell_colors, + write_dirichlet, + # L2 Projection project, L2Projector, From cd6091b9553f845c712323a356d70c121de0839b Mon Sep 17 00:00:00 2001 From: Knut Andreas Meyer Date: Tue, 18 Jul 2023 21:21:26 +0200 Subject: [PATCH 14/67] Update tests with new functions --- test/test_constraints.jl | 6 +++--- test/test_grid_dofhandler_vtk.jl | 32 ++++++++++++++++---------------- test/test_l2_projection.jl | 13 +++++++------ test/test_mixeddofhandler.jl | 10 +++++----- 4 files changed, 31 insertions(+), 30 deletions(-) diff --git a/test/test_constraints.jl b/test/test_constraints.jl index 5b511632e5..00e3832a14 100644 --- a/test/test_constraints.jl +++ b/test/test_constraints.jl @@ -1553,9 +1553,9 @@ end # testset @test norm(u_dbc) ≈ 3.8249286998373586 @test norm(u_p) ≈ 3.7828270430540893 end - # vtk_grid("local_application_azero_$(azero)", grid) do vtk - # vtk_point_data(vtk, dh, u_dbc, "_dbc") - # vtk_point_data(vtk, dh, u_p, "_p") + # VTKStream("local_application_azero_$(azero)", grid) do vtks + # write_solution(vtks, dh, u_dbc, "_dbc") + # write_solution(vtks, dh, u_p, "_p") # end @test K_dbc_standard \ f_dbc_standard ≈ K_dbc_ch \ f_dbc_ch ≈ K_dbc_local \ f_dbc_local ≈ K_ac_standard \ f_ac_standard ≈ K_ac_ch \ f_ac_ch ≈ K_ac_local \ f_ac_local diff --git a/test/test_grid_dofhandler_vtk.jl b/test/test_grid_dofhandler_vtk.jl index b465ab53de..5f6329f57b 100644 --- a/test/test_grid_dofhandler_vtk.jl +++ b/test/test_grid_dofhandler_vtk.jl @@ -36,10 +36,10 @@ end addnodeset!(grid, "middle-nodes", x -> norm(x) < radius) gridfilename = "grid-$(repr(celltype))" - vtk_grid(gridfilename, grid) do vtk - vtk_cellset(vtk, grid, "cell-1") - vtk_cellset(vtk, grid, "middle-cells") - vtk_nodeset(vtk, grid, "middle-nodes") + VTKStream(gridfilename, grid) do vtks + write_cellset(vtks, grid, "cell-1") + write_cellset(vtks, grid, "middle-cells") + write_nodeset(vtks, grid, "middle-nodes") end # test the sha of the file @@ -75,9 +75,9 @@ end apply!(u, ch) dofhandlerfilename = "dofhandler-$(repr(celltype))" - vtk_grid(dofhandlerfilename, dofhandler) do vtk - vtk_point_data(vtk, ch) - vtk_point_data(vtk, dofhandler, u) + VTKStream(dofhandlerfilename, grid) do vtks + write_dirichlet(vtks, ch) + write_solution(vtks, dofhandler, u) end # test the sha of the file @@ -112,10 +112,10 @@ close(csio) vector_data = [Vec{3}(ntuple(i->i, 3)) for j=1:8] filename_3d = "test_vtk_3d" - vtk_grid(filename_3d, grid) do vtk_file - vtk_point_data(vtk_file, sym_tensor_data, "symmetric tensor") - vtk_point_data(vtk_file, tensor_data, "tensor") - vtk_point_data(vtk_file, vector_data, "vector") + VTKStream(filename_3d, grid) do vtks + write_nodedata(vtks, grid, sym_tensor_data, "symmetric tensor") + write_nodedata(vtks, grid, tensor_data, "tensor") + write_nodedata(vtks, grid, vector_data, "vector") end # 2D grid @@ -127,11 +127,11 @@ close(csio) vector_data = [Vec{2}(ntuple(i->i, 2)) for j=1:4] filename_2d = "test_vtk_2d" - vtk_grid(filename_2d, grid) do vtk_file - vtk_point_data(vtk_file, sym_tensor_data, "symmetric tensor") - vtk_point_data(vtk_file, tensor_data, "tensor") - vtk_point_data(vtk_file, tensor_data_1D, "tensor_1d") - vtk_point_data(vtk_file, vector_data, "vector") + VTKStream(filename_2d, grid) do vtks + write_nodedata(vtks, grid, sym_tensor_data, "symmetric tensor") + write_nodedata(vtks, grid, tensor_data, "tensor") + write_nodedata(vtks, grid, tensor_data_1D, "tensor_1d") + write_nodedata(vtks, grid, vector_data, "vector") end # test the shas of the files diff --git a/test/test_l2_projection.jl b/test/test_l2_projection.jl index 9a02f2f798..d497975fef 100644 --- a/test/test_l2_projection.jl +++ b/test/test_l2_projection.jl @@ -267,13 +267,14 @@ function test_export(;subset::Bool) end mktempdir() do tmp - fname = vtk_grid(joinpath(tmp, "projected"), grid) do vtk - vtk_point_data(vtk, p, p_scalar, "p_scalar") - vtk_point_data(vtk, p, p_vec, "p_vec") - vtk_point_data(vtk, p, p_tens, "p_tens") - vtk_point_data(vtk, p, p_stens, "p_stens") + fname = joinpath(tmp, "projected") + VTKStream(fname, grid) do vtks + write_projected(vtks, p, p_scalar, "p_scalar") + write_projected(vtks, p, p_vec, "p_vec") + write_projected(vtks, p, p_tens, "p_tens") + write_projected(vtks, p, p_stens, "p_stens") end - @test bytes2hex(open(SHA.sha1, fname[1], "r")) in ( + @test bytes2hex(open(SHA.sha1, fname*".vtu", "r")) in ( subset ? ("261cfe21de7a478e14f455e783694651a91eeb60", "b3fef3de9f38ca9ddd92f2f67a1606d07ca56d67") : ("3b8ffb444db1b4cee1246a751da88136116fe49b", "bc2ec8f648f9b8bccccf172c1fc48bf03340329b") ) diff --git a/test/test_mixeddofhandler.jl b/test/test_mixeddofhandler.jl index c5c598918d..17044fc052 100644 --- a/test/test_mixeddofhandler.jl +++ b/test/test_mixeddofhandler.jl @@ -355,11 +355,11 @@ function test_2_element_heat_eq() gridfilename = "mixed_grid" addcellset!(grid, "cell-1", [1,]) addcellset!(grid, "cell-2", [2,]) - vtk_grid(gridfilename, grid) do vtk - vtk_cellset(vtk, grid, "cell-1") - vtk_cellset(vtk, grid, "cell-2") - vtk_point_data(vtk, dh, u) - # vtk_point_data(vtk, ch) #FIXME + VTKStream(gridfilename, grid) do vtks + write_cellset(vtks, grid, "cell-1") + write_cellset(vtks, grid, "cell-2") + write_solution(vtks, dh, u) + # write_dirichlet(vtks, ch) #FIXME end sha = bytes2hex(open(SHA.sha1, gridfilename*".vtu")) @test sha in ("e96732c000b0b385db7444f002461468b60b3b2c", "7b26edc27b5e59a2f60907374cd5a5790cc37a6a") From a17e02434860c80dbe9d1453956bae552f2f8d85 Mon Sep 17 00:00:00 2001 From: Knut Andreas Meyer Date: Tue, 18 Jul 2023 21:24:05 +0200 Subject: [PATCH 15/67] Remove (at)example from pseudo-code block in docs --- docs/src/topics/export.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/src/topics/export.md b/docs/src/topics/export.md index f3510361ff..b67994d34d 100644 --- a/docs/src/topics/export.md +++ b/docs/src/topics/export.md @@ -16,7 +16,7 @@ the exporting. The following structure can be used to write various output to a vtk-file: -```@example export +```julia VTKStream("my_solution", grid) do vtks write_(vtks, args...) end From 699aec282ce075217bf9545d3b95e7b522cac6a3 Mon Sep 17 00:00:00 2001 From: Knut Andreas Meyer Date: Tue, 18 Jul 2023 21:51:45 +0200 Subject: [PATCH 16/67] Try to fix docs --- docs/src/topics/export.md | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/docs/src/topics/export.md b/docs/src/topics/export.md index b67994d34d..62888c8c23 100644 --- a/docs/src/topics/export.md +++ b/docs/src/topics/export.md @@ -16,12 +16,12 @@ the exporting. The following structure can be used to write various output to a vtk-file: -```julia +```@example export VTKStream("my_solution", grid) do vtks - write_(vtks, args...) + write_solution(vtks, dh, u) end ``` -where `write_` can be +where `write_solution` is just one example of the following functions that can be used * [`write_solution`](@ref) * [`write_celldata`](@ref) @@ -35,8 +35,8 @@ where `write_` can be Instead of using the `do`-block, it is also possible to do ```@example export vtks = VTKStream("my_solution", grid) -write_(vtks, args...) -# ... +write_solution(vtks, dh, u) +# etc. close(vtks) ``` From cf82d1c42953488823d9fb6f238809a62a31c268 Mon Sep 17 00:00:00 2001 From: Knut Andreas Meyer Date: Tue, 18 Jul 2023 22:14:17 +0200 Subject: [PATCH 17/67] Improve docs --- docs/src/topics/export.md | 16 +++++++++++- src/Export/VTK.jl | 52 +++++++++++++++++++-------------------- 2 files changed, 41 insertions(+), 27 deletions(-) diff --git a/docs/src/topics/export.md b/docs/src/topics/export.md index 62888c8c23..2cd7202383 100644 --- a/docs/src/topics/export.md +++ b/docs/src/topics/export.md @@ -40,4 +40,18 @@ write_solution(vtks, dh, u) close(vtks) ``` -The data written by `write_solution`, `write_celldata`, `write_nodedata`, and `write_projected` may be either scalar (`Vector{<:Number}`) or tensor (`Vector{<:AbstractTensor}`) data. \ No newline at end of file +The data written by `write_solution`, `write_celldata`, `write_nodedata`, and `write_projected` may be either scalar (`Vector{<:Number}`) or tensor (`Vector{<:AbstractTensor}`) data. + +To save time-dependent data, `WriteVTK.jl`'s, `paraview_collection` may be used + +```@example pvdexport +pvd = paraview_collection("my_results.pvd"); +for i in 1:5 + # Do calculations to update u + VTKStream("my_results_$i", grid) do vtks + write_solution(vtks, dh, u) + pvd[i] = vtk + end +end +``` +See [Transient heat equation](@ref tutorial-transient-heat-equation) for an example \ No newline at end of file diff --git a/src/Export/VTK.jl b/src/Export/VTK.jl index 11a6345ca6..8bbeb79240 100644 --- a/src/Export/VTK.jl +++ b/src/Export/VTK.jl @@ -5,18 +5,22 @@ end """ VTKStream(filename::AbstractString, grid::AbstractGrid; kwargs...) -Create a `Ferrite.VTKStream` that contains an unstructured VTK grid from -a `DofHandler` (limited functionality if only a `Grid` is given). -This stream can be used to to write data with -[`write_solution`](@ref), [`write_celldata`](@ref), [`write_nodedata`](@ref), -[`write_projected`](@ref), -[`write_cellset`](@ref), [`write_nodeset`](@ref), and [`write_constraints`](@ref). - +Create a `Ferrite.VTKStream` that contains an unstructured VTK grid. The keyword arguments are forwarded to `WriteVTK.vtk_grid`, see [Data Formatting Options](https://juliavtk.github.io/WriteVTK.jl/stable/grids/syntax/#Data-formatting-options) -It is necessary to call [`close`](@ref) to save the data after writing to the stream, -or alternatively use the `do`-block syntax which does this implicitly, e.g., +This stream can be used to to write data with + +* [`write_solution`](@ref) +* [`write_celldata`](@ref) +* [`write_nodedata`](@ref). +* [`write_projected`](@ref) +* [`write_cellset`](@ref) +* [`write_nodeset`](@ref) +* [`write_constraints`](@ref) + +It is necessary to call `close(::VTKStream)` to save the data after writing to the stream, +Alternatively, the `do`-block syntax that does this implicitly is supported: ```julia VTKStream(filename, grid) do vtks write_solution(vtks, dh, u) @@ -37,11 +41,6 @@ function VTKStream(f::Function, args...; kwargs...) end end -""" - Base.close(vtks::VTKStream) - -Close the vtk stream and save the data to disk. -""" Base.close(vtks::VTKStream) = WriteVTK.vtk_save(vtks.vtk) function Base.show(io::IO, ::MIME"text/plain", vtks::VTKStream) @@ -159,12 +158,13 @@ end """ write_solution(vtks::VTKStream, dh::AbstractDofHandler, u::Vector, suffix="") -Save the values at the nodes in the degree of freedom vector `u` to a -the a vtk file for each field in `DofHandler` in `vtks`. -`suffix` can be used to append to the fieldname. +Save the values at the nodes in the degree of freedom vector `u` to the stream. +Each field in `dh` will be saved separately, and `suffix` can be used to append +to the fieldname. -`u` can also contain tensorial values, but each entry in `u` must correspond to a degree of freedom in `dh`, -see [`write_nodedata`](@ref) for details. This function should be used directly when exporting values already +`u` can also contain tensorial values, but each entry in `u` must correspond to a +degree of freedom in `dh`, see [`write_nodedata`](@ref) for details. +Use `write_nodedata` directly when exporting values that are already sorted by the nodes in the grid. """ function write_solution(vtks::VTKStream, dh::AbstractDofHandler, u::Vector, suffix="") @@ -179,7 +179,7 @@ end """ write_projected(vtks::VTKStream, proj::L2Projector, vals::Vector, name::AbstractString) -Write `vals` that have been projected with `proj` to the vtk file in `vtks` +Project `vals` to the grid nodes with `proj` and save to the stream. """ function write_projected(vtks::VTKStream, proj::L2Projector, vals, name) data = _evaluate_at_grid_nodes(proj, vals, #=vtk=# Val(true))::Matrix @@ -189,7 +189,7 @@ function write_projected(vtks::VTKStream, proj::L2Projector, vals, name) end """ - write_celldata(vtks::VTKStream, celldata, name) + write_celldata(vtks::VTKStream, grid::AbstractGrid, celldata::AbstractVector, name::String) Write the `celldata` that is ordered by the cells in the grid to the vtk file. """ @@ -198,10 +198,10 @@ function write_celldata(vtks::VTKStream, ::AbstractGrid, celldata, name) end """ - write_nodedata(vtks::VTKStream, nodedata::Vector{Real}, name) - write_nodedata(vtks::VTKStream, nodedata::Vector{<:AbstractTensor}, name) + write_nodedata(vtks::VTKStream, grid::AbstractGrid, nodedata::Vector{Real}, name) + write_nodedata(vtks::VTKStream, grid::AbstractGrid, nodedata::Vector{<:AbstractTensor}, name) -Write the `nodedata` that is ordered by the nodes in the grid to the vtk file. +Write the `nodedata` that is ordered by the nodes in the grid to the vtk stream. When `nodedata` contains `Tensors.Vec`s, each component is exported. Two-dimensional vectors are padded with zeros. @@ -217,7 +217,7 @@ end """ write_nodeset(vtks::VTKStream, grid::AbstractGrid, nodeset::String) -Export nodal values of 1 for nodes in `nodeset`, and 0 otherwise +Write nodal values of 1 for nodes in `nodeset`, and 0 otherwise """ function write_nodeset(vtks, grid::AbstractGrid, nodeset::String) z = zeros(getnnodes(grid)) @@ -231,7 +231,7 @@ end write_cellset(vtks, grid::AbstractGrid, cellset::String) write_cellset(vtks, grid::AbstractGrid, cellsets::Union{AbstractVector{String},AbstractSet{String}) -Export all cell sets in the grid with name according to their keys and +Write all cell sets in the grid with name according to their keys and celldata 1 if the cell is in the set, and 0 otherwise. It is also possible to only export a single `cellset`, or multiple `cellsets`. """ From 69a002c22255cf73bcf02efad8bee61a4d55cc60 Mon Sep 17 00:00:00 2001 From: Knut Andreas Meyer Date: Wed, 19 Jul 2023 09:09:39 +0200 Subject: [PATCH 18/67] pin documenter --- docs/Manifest.toml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/docs/Manifest.toml b/docs/Manifest.toml index 77b5a7dc19..d22a5bebba 100644 --- a/docs/Manifest.toml +++ b/docs/Manifest.toml @@ -297,7 +297,8 @@ version = "0.9.3" [[deps.Documenter]] deps = ["ANSIColoredPrinters", "AbstractTrees", "Base64", "Dates", "DocStringExtensions", "IOCapture", "InteractiveUtils", "JSON", "LibGit2", "Logging", "Markdown", "MarkdownAST", "REPL", "SnoopPrecompile", "Test", "Unicode"] -git-tree-sha1 = "15192af26eb49bb61f7b780ae2482015bba24c40" +git-tree-sha1 = "2afe1f1706b90fd4a8593d70b5324d04ddefed69" +pinned = true repo-rev = "master" repo-url = "https://github.com/JuliaDocs/Documenter.jl.git" uuid = "e30172f5-a6a5-5a46-863b-614d45cd2de4" From bff63b040a79c187b53cd0cd42250a7236bb7f0e Mon Sep 17 00:00:00 2001 From: Knut Andreas Meyer Date: Wed, 19 Jul 2023 15:30:45 +0200 Subject: [PATCH 19/67] Renames and unexports --- docs/src/literate-gallery/helmholtz.jl | 6 +- docs/src/literate-gallery/landau.jl | 4 +- .../quasi_incompressible_hyperelasticity.jl | 6 +- .../literate-gallery/topology_optimization.jl | 8 +- docs/src/literate-howto/postprocessing.jl | 4 +- docs/src/literate-howto/threaded_assembly.jl | 6 +- .../computational_homogenization.jl | 10 +- docs/src/literate-tutorials/heat_equation.jl | 4 +- .../src/literate-tutorials/hyperelasticity.jl | 4 +- .../incompressible_elasticity.jl | 4 +- docs/src/literate-tutorials/linear_shell.jl | 4 +- docs/src/literate-tutorials/ns_vs_diffeq.jl | 6 +- docs/src/literate-tutorials/plasticity.jl | 8 +- docs/src/literate-tutorials/stokes-flow.jl | 4 +- .../transient_heat_equation.jl | 12 +- docs/src/reference/export.md | 10 +- docs/src/topics/export.md | 24 ++-- src/Export/VTK.jl | 124 +++++++++--------- src/deprecations.jl | 22 ++-- src/exports.jl | 8 +- test/test_constraints.jl | 6 +- test/test_grid_dofhandler_vtk.jl | 32 ++--- test/test_l2_projection.jl | 10 +- test/test_mixeddofhandler.jl | 10 +- 24 files changed, 165 insertions(+), 171 deletions(-) diff --git a/docs/src/literate-gallery/helmholtz.jl b/docs/src/literate-gallery/helmholtz.jl index f7a73d788a..98714d74ec 100644 --- a/docs/src/literate-gallery/helmholtz.jl +++ b/docs/src/literate-gallery/helmholtz.jl @@ -162,9 +162,9 @@ K, f = doassemble(cellvalues, facevalues, K, dh); apply!(K, f, dbcs) u = Symmetric(K) \ f; -vtks = VTKStream("helmholtz", grid) -write_solution(vtks, dh, u) -close(vtks) +vtk = VTKFile("helmholtz", grid) +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 diff --git a/docs/src/literate-gallery/landau.jl b/docs/src/literate-gallery/landau.jl index 819f4092ec..b2fd6937f0 100644 --- a/docs/src/literate-gallery/landau.jl +++ b/docs/src/literate-gallery/landau.jl @@ -114,8 +114,8 @@ end # utility to quickly save a model function save_landau(path, model, dofs=model.dofs) - VTKStream(path, model.dofhandler.grid) do vtks - write_solution(vtks, model.dofhandler, dofs) + VTKFile(path, model.dofhandler.grid) do vtk + write_solution(vtk, model.dofhandler, dofs) end end diff --git a/docs/src/literate-gallery/quasi_incompressible_hyperelasticity.jl b/docs/src/literate-gallery/quasi_incompressible_hyperelasticity.jl index b4ae726030..d47f2f3638 100644 --- a/docs/src/literate-gallery/quasi_incompressible_hyperelasticity.jl +++ b/docs/src/literate-gallery/quasi_incompressible_hyperelasticity.jl @@ -334,9 +334,9 @@ function solve(interpolation_u, interpolation_p) end; ## Save the solution fields - VTKStream("hyperelasticity_incomp_mixed_$t.vtu", grid) do vtks - write_solution(vtks, dh, w) - pvd[t] = vtks + VTKFile("hyperelasticity_incomp_mixed_$t.vtu", grid) do vtk + write_solution(vtk, dh, w) + pvd[t] = vtk end end; vtk_save(pvd); diff --git a/docs/src/literate-gallery/topology_optimization.jl b/docs/src/literate-gallery/topology_optimization.jl index fec8c2dcce..3bac1900d4 100644 --- a/docs/src/literate-gallery/topology_optimization.jl +++ b/docs/src/literate-gallery/topology_optimization.jl @@ -492,16 +492,16 @@ function topopt(ra,ρ,n,filename; output=:false) i = @sprintf("%3.3i", it) filename_it = string(filename, "_", i) - VTKStream(filename_it, grid) do vtks - write_celldata(vtks, grid, χ, "density") + VTKFile(filename_it, grid) do vtk + write_celldata(vtk, grid, χ, "density") end end end ## export converged results if(!output) - VTKStream(filename, grid) do vtks - write_celldata(vtks, grid, χ, "density") + VTKFile(filename, grid) do vtk + write_celldata(vtk, grid, χ, "density") end end @printf "Rel. stiffness: %.4f \n" compliance^(-1)/compliance_0^(-1) diff --git a/docs/src/literate-howto/postprocessing.jl b/docs/src/literate-howto/postprocessing.jl index e2bcb819fa..94e43e0be1 100644 --- a/docs/src/literate-howto/postprocessing.jl +++ b/docs/src/literate-howto/postprocessing.jl @@ -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*. -VTKStream("heat_equation_flux", grid) do vtks - write_projected(vtks, projector, q_projected, "q") +VTKFile("heat_equation_flux", grid) do vtk + write_projected(vtk, projector, q_projected, "q") end; # ## Point Evaluation diff --git a/docs/src/literate-howto/threaded_assembly.jl b/docs/src/literate-howto/threaded_assembly.jl index 47271849df..3450325e0f 100644 --- a/docs/src/literate-howto/threaded_assembly.jl +++ b/docs/src/literate-howto/threaded_assembly.jl @@ -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) - VTKStream("colored", grid) do vtks - write_cell_colors(vtks, grid, colors_workstream, "workstream-coloring") - write_cell_colors(vtks, grid, colors_greedy, "greedy-coloring") + VTKFile("colored", grid) do vtk + write_cell_colors(vtk, grid, colors_workstream, "workstream-coloring") + write_cell_colors(vtk, grid, colors_greedy, "greedy-coloring") end end diff --git a/docs/src/literate-tutorials/computational_homogenization.jl b/docs/src/literate-tutorials/computational_homogenization.jl index 63c26aba88..03fbfb8fb8 100644 --- a/docs/src/literate-tutorials/computational_homogenization.jl +++ b/docs/src/literate-tutorials/computational_homogenization.jl @@ -518,16 +518,16 @@ round.(ev; digits=-8) uM = zeros(ndofs(dh)) -VTKStream("homogenization", grid) do vtks +VTKFile("homogenization", grid) do vtk for i in 1:3 ## Compute macroscopic solution apply_analytical!(uM, dh, :u, x -> εᴹ[i] ⋅ x) ## Dirichlet - write_solution(vtks, dh, uM + u.dirichlet[i], "_dirichlet_$i") - write_projected(vtks, projector, σ.dirichlet[i], "σvM_dirichlet_$i") + write_solution(vtk, dh, uM + u.dirichlet[i], "_dirichlet_$i") + write_projected(vtk, projector, σ.dirichlet[i], "σvM_dirichlet_$i") ## Periodic - write_solution(vtks, dh, uM + u.periodic[i], "_periodic_$i") - write_projected(vtks, projector, σ.periodic[i], "σvM_periodic_$i") + write_solution(vtk, dh, uM + u.periodic[i], "_periodic_$i") + write_projected(vtk, projector, σ.periodic[i], "σvM_periodic_$i") end end; diff --git a/docs/src/literate-tutorials/heat_equation.jl b/docs/src/literate-tutorials/heat_equation.jl index aa6ec1c91f..887de39793 100644 --- a/docs/src/literate-tutorials/heat_equation.jl +++ b/docs/src/literate-tutorials/heat_equation.jl @@ -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/). -VTKStream("heat_equation", grid) do vtks - write_solution(vtks, dh, u) +VTKFile("heat_equation", grid) do vtk + write_solution(vtk, dh, u) end ## test the result #src diff --git a/docs/src/literate-tutorials/hyperelasticity.jl b/docs/src/literate-tutorials/hyperelasticity.jl index 37d0d5e6ca..ad915aaa6e 100644 --- a/docs/src/literate-tutorials/hyperelasticity.jl +++ b/docs/src/literate-tutorials/hyperelasticity.jl @@ -397,8 +397,8 @@ function solve() ## Save the solution @timeit "export" begin - VTKStream("hyperelasticity", grid) do vtks - write_solution(vtks, dh, u) + VTKFile("hyperelasticity", grid) do vtk + write_solution(vtk, dh, u) end end diff --git a/docs/src/literate-tutorials/incompressible_elasticity.jl b/docs/src/literate-tutorials/incompressible_elasticity.jl index cccf771fe3..74df3ebf53 100644 --- a/docs/src/literate-tutorials/incompressible_elasticity.jl +++ b/docs/src/literate-tutorials/incompressible_elasticity.jl @@ -209,8 +209,8 @@ function solve(ν, interpolation_u, interpolation_p) ## export filename = "cook_" * (isa(interpolation_u, Lagrange{RefTriangle,1}) ? "linear" : "quadratic") * "_linear" - VTKStream(filename, grid) do vtks - write_solution(vtks, dh, u) + VTKFile(filename, grid) do vtk + write_solution(vtk, dh, u) end return u end diff --git a/docs/src/literate-tutorials/linear_shell.jl b/docs/src/literate-tutorials/linear_shell.jl index ea1cfd467e..e876f0c1cb 100644 --- a/docs/src/literate-tutorials/linear_shell.jl +++ b/docs/src/literate-tutorials/linear_shell.jl @@ -113,8 +113,8 @@ a = K\f # Output results. #+ -VTKStream("linear_shell", grid) do vtks - write_solution(vtks, dh, a) +VTKFile("linear_shell", grid) do vtk + write_solution(vtk, dh, a) end end; #end main functions diff --git a/docs/src/literate-tutorials/ns_vs_diffeq.jl b/docs/src/literate-tutorials/ns_vs_diffeq.jl index f532bc82be..d2ce50b628 100644 --- a/docs/src/literate-tutorials/ns_vs_diffeq.jl +++ b/docs/src/literate-tutorials/ns_vs_diffeq.jl @@ -440,9 +440,9 @@ for (u_uc,t) in integrator update!(ch, t) u = copy(u_uc) apply!(u, ch) - VTKStream("vortex-street-$t.vtu", grid) do vtks - write_solution(vtks, dh, u) - pvd[t] = vtks + VTKFile("vortex-street-$t.vtu", grid) do vtk + write_solution(vtk, dh, u) + pvd[t] = vtk end end vtk_save(pvd); diff --git a/docs/src/literate-tutorials/plasticity.jl b/docs/src/literate-tutorials/plasticity.jl index 1276d7b4ba..3e9f1755a1 100644 --- a/docs/src/literate-tutorials/plasticity.jl +++ b/docs/src/literate-tutorials/plasticity.jl @@ -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 - VTKStream("plasticity", grid) do vtks - write_solution(vtks, dh, u) # displacement field - write_celldata(vtks, grid, mises_values, "von Mises [Pa]") - write_celldata(vtks, grid, κ_values, "Drag stress [Pa]") + VTKFile("plasticity", grid) do vtk + write_solution(vtk, dh, u) # displacement field + write_celldata(vtk, grid, mises_values, "von Mises [Pa]") + write_celldata(vtk, grid, κ_values, "Drag stress [Pa]") end return u_max, traction_magnitude diff --git a/docs/src/literate-tutorials/stokes-flow.jl b/docs/src/literate-tutorials/stokes-flow.jl index c1f027ac24..2ee740a499 100644 --- a/docs/src/literate-tutorials/stokes-flow.jl +++ b/docs/src/literate-tutorials/stokes-flow.jl @@ -505,8 +505,8 @@ function main() u = K \ f apply!(u, ch) ## Export the solution - VTKStream("stokes-flow", grid) do vtks - write_solution(vtks, dh, u) + VTKFile("stokes-flow", grid) do vtk + write_solution(vtk, dh, u) end ## Check the result #src diff --git a/docs/src/literate-tutorials/transient_heat_equation.jl b/docs/src/literate-tutorials/transient_heat_equation.jl index 3766412b7a..ef945bd542 100644 --- a/docs/src/literate-tutorials/transient_heat_equation.jl +++ b/docs/src/literate-tutorials/transient_heat_equation.jl @@ -192,9 +192,9 @@ apply!(A, ch); # To store the solution, we initialize a `paraview_collection` (.pvd) file. pvd = paraview_collection("transient-heat.pvd"); t = 0 -VTKStream("transient-heat-$t", grid) do vtks - write_solution(vtks, dh, uₙ) - pvd[t] = vtks +VTKFile("transient-heat-$t", grid) do vtk + write_solution(vtk, dh, uₙ) + pvd[t] = vtk end # At this point everything is set up and we can finally approach the time loop. @@ -210,9 +210,9 @@ for t in Δt:Δt:T #Finally, we can solve the time step and save the solution afterwards. u = A \ b - VTKStream("transient-heat-$t", grid) do vtks - write_solution(vtks, dh, u) - pvd[t] = vtks + VTKFile("transient-heat-$t", grid) do vtk + write_solution(vtk, dh, u) + pvd[t] = vtk 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 diff --git a/docs/src/reference/export.md b/docs/src/reference/export.md index 05f00394dd..3344179643 100644 --- a/docs/src/reference/export.md +++ b/docs/src/reference/export.md @@ -26,13 +26,13 @@ evaluate_at_grid_nodes ## VTK Export ```@docs -VTKStream +VTKFile write_solution write_projected write_celldata -write_nodedata -write_cellset -write_nodeset -write_dirichlet +Ferrite.write_nodedata +Ferrite.write_cellset +Ferrite.write_nodeset +Ferrite.write_dirichlet write_cell_colors ``` diff --git a/docs/src/topics/export.md b/docs/src/topics/export.md index 2cd7202383..2ab215116d 100644 --- a/docs/src/topics/export.md +++ b/docs/src/topics/export.md @@ -17,30 +17,30 @@ the exporting. The following structure can be used to write various output to a vtk-file: ```@example export -VTKStream("my_solution", grid) do vtks - write_solution(vtks, dh, u) +VTKFile("my_solution", grid) do vtk + write_solution(vtk, dh, u) end ``` where `write_solution` is just one example of the following functions that can be used * [`write_solution`](@ref) * [`write_celldata`](@ref) -* [`write_nodedata`](@ref) +* [`Ferrite.write_nodedata`](@ref) * [`write_projected`](@ref) -* [`write_cellset`](@ref) -* [`write_nodeset`](@ref) -* [`write_dirichlet`](@ref) +* [`Ferrite.write_cellset`](@ref) +* [`Ferrite.write_nodeset`](@ref) +* [`Ferrite.write_dirichlet`](@ref) * [`write_cell_colors`](@ref) Instead of using the `do`-block, it is also possible to do ```@example export -vtks = VTKStream("my_solution", grid) -write_solution(vtks, dh, u) +vtk = VTKFile("my_solution", grid) +write_solution(vtk, dh, u) # etc. -close(vtks) +close(vtk) ``` -The data written by `write_solution`, `write_celldata`, `write_nodedata`, and `write_projected` may be either scalar (`Vector{<:Number}`) or tensor (`Vector{<:AbstractTensor}`) data. +The data written by `write_solution`, `write_celldata`, `Ferrite.write_nodedata`, and `write_projected` may be either scalar (`Vector{<:Number}`) or tensor (`Vector{<:AbstractTensor}`) data. To save time-dependent data, `WriteVTK.jl`'s, `paraview_collection` may be used @@ -48,8 +48,8 @@ To save time-dependent data, `WriteVTK.jl`'s, `paraview_collection` may be used pvd = paraview_collection("my_results.pvd"); for i in 1:5 # Do calculations to update u - VTKStream("my_results_$i", grid) do vtks - write_solution(vtks, dh, u) + VTKFile("my_results_$i", grid) do vtk + write_solution(vtk, dh, u) pvd[i] = vtk end end diff --git a/src/Export/VTK.jl b/src/Export/VTK.jl index 8bbeb79240..fe06c1c6e2 100644 --- a/src/Export/VTK.jl +++ b/src/Export/VTK.jl @@ -1,60 +1,60 @@ -struct VTKStream{VTK<:WriteVTK.DatasetFile} +struct VTKFile{VTK<:WriteVTK.DatasetFile} vtk::VTK end """ - VTKStream(filename::AbstractString, grid::AbstractGrid; kwargs...) + Ferrite.VTKFile(filename::AbstractString, grid::AbstractGrid; kwargs...) -Create a `Ferrite.VTKStream` that contains an unstructured VTK grid. +Create a `Ferrite.VTKFile` that contains an unstructured VTK grid. The keyword arguments are forwarded to `WriteVTK.vtk_grid`, see [Data Formatting Options](https://juliavtk.github.io/WriteVTK.jl/stable/grids/syntax/#Data-formatting-options) -This stream can be used to to write data with +This file handler can be used to to write data with * [`write_solution`](@ref) * [`write_celldata`](@ref) -* [`write_nodedata`](@ref). * [`write_projected`](@ref) -* [`write_cellset`](@ref) -* [`write_nodeset`](@ref) -* [`write_constraints`](@ref) +* [`Ferrite.write_nodedata`](@ref). +* [`Ferrite.write_cellset`](@ref) +* [`Ferrite.write_nodeset`](@ref) +* [`Ferrite.write_dirichlet`](@ref) -It is necessary to call `close(::VTKStream)` to save the data after writing to the stream, -Alternatively, the `do`-block syntax that does this implicitly is supported: +It is necessary to call `close(::VTKFile)` to save the data after writing +to the file handler. Using the supported `do`-block does this automatically: ```julia -VTKStream(filename, grid) do vtks - write_solution(vtks, dh, u) - write_celldata(vtks, grid, celldata) +VTKFile(filename, grid) do vtk + write_solution(vtk, dh, u) + write_celldata(vtk, grid, celldata) end """ -function VTKStream(filename::String, grid::AbstractGrid; kwargs...) +function VTKFile(filename::String, grid::AbstractGrid; kwargs...) vtk = create_vtk_grid(filename, grid; kwargs...) - return VTKStream(vtk) + return VTKFile(vtk) end # Makes it possible to use the `do`-block syntax -function VTKStream(f::Function, args...; kwargs...) - vtks = VTKStream(args...; kwargs...) +function VTKFile(f::Function, args...; kwargs...) + vtk = VTKFile(args...; kwargs...) try - f(vtks) + f(vtk) finally - close(vtks) + close(vtk) end end -Base.close(vtks::VTKStream) = WriteVTK.vtk_save(vtks.vtk) +Base.close(vtk::VTKFile) = WriteVTK.vtk_save(vtk.vtk) -function Base.show(io::IO, ::MIME"text/plain", vtks::VTKStream) - open_str = WriteVTK.isopen(vtks.vtk) ? "open" : "closed" - filename = vtks.vtk.path - print(io, "VTKStream for the $open_str file \"$(filename)\".") +function Base.show(io::IO, ::MIME"text/plain", vtk::VTKFile) + open_str = WriteVTK.isopen(vtk.vtk) ? "open" : "closed" + filename = vtk.vtk.path + print(io, "VTKFile for the $open_str file \"$(filename)\".") end # Support ParaviewCollection -function Base.setindex!(pvd::WriteVTK.CollectionFile, vtks::VTKStream, time::Real) - WriteVTK.collection_add_timestep(pvd, vtks, time) +function Base.setindex!(pvd::WriteVTK.CollectionFile, vtk::VTKFile, time::Real) + WriteVTK.collection_add_timestep(pvd, vtk, time) end -function WriteVTK.collection_add_timestep(pvd::WriteVTK.CollectionFile, vtks::VTKStream, time::Real) - WriteVTK.collection_add_timestep(pvd, vtks.vtk, time) +function WriteVTK.collection_add_timestep(pvd::WriteVTK.CollectionFile, vtk::VTKFile, time::Real) + WriteVTK.collection_add_timestep(pvd, vtk.vtk, time) end cell_to_vtkcell(::Type{Line}) = VTKCellTypes.VTK_LINE @@ -156,50 +156,50 @@ function component_names(::Type{S}) where S end """ - write_solution(vtks::VTKStream, dh::AbstractDofHandler, u::Vector, suffix="") + write_solution(vtk::VTKFile, dh::AbstractDofHandler, u::Vector, suffix="") Save the values at the nodes in the degree of freedom vector `u` to the stream. Each field in `dh` will be saved separately, and `suffix` can be used to append to the fieldname. `u` can also contain tensorial values, but each entry in `u` must correspond to a -degree of freedom in `dh`, see [`write_nodedata`](@ref) for details. +degree of freedom in `dh`, see [`write_nodedata`](@ref Ferrite.write_nodedata) for details. Use `write_nodedata` directly when exporting values that are already sorted by the nodes in the grid. """ -function write_solution(vtks::VTKStream, dh::AbstractDofHandler, u::Vector, suffix="") +function write_solution(vtk::VTKFile, dh::AbstractDofHandler, u::Vector, suffix="") fieldnames = Ferrite.getfieldnames(dh) # all primary fields for name in fieldnames data = _evaluate_at_grid_nodes(dh, u, name, #=vtk=# Val(true)) - _vtk_write_nodedata(vtks.vtk, data, string(name, suffix)) + _vtk_write_nodedata(vtk.vtk, data, string(name, suffix)) end - return vtks + return vtk end """ - write_projected(vtks::VTKStream, proj::L2Projector, vals::Vector, name::AbstractString) + write_projected(vtk::VTKFile, proj::L2Projector, vals::Vector, name::AbstractString) Project `vals` to the grid nodes with `proj` and save to the stream. """ -function write_projected(vtks::VTKStream, proj::L2Projector, vals, name) +function write_projected(vtk::VTKFile, proj::L2Projector, vals, name) data = _evaluate_at_grid_nodes(proj, vals, #=vtk=# Val(true))::Matrix @assert size(data, 2) == getnnodes(get_grid(proj.dh)) - _vtk_write_nodedata(vtks.vtk, data, name; component_names=component_names(eltype(vals))) - return vtks + _vtk_write_nodedata(vtk.vtk, data, name; component_names=component_names(eltype(vals))) + return vtk end """ - write_celldata(vtks::VTKStream, grid::AbstractGrid, celldata::AbstractVector, name::String) + write_celldata(vtk::VTKFile, grid::AbstractGrid, celldata::AbstractVector, name::String) Write the `celldata` that is ordered by the cells in the grid to the vtk file. """ -function write_celldata(vtks::VTKStream, ::AbstractGrid, celldata, name) - WriteVTK.vtk_cell_data(vtks.vtk, celldata, name) +function write_celldata(vtk::VTKFile, ::AbstractGrid, celldata, name) + WriteVTK.vtk_cell_data(vtk.vtk, celldata, name) end """ - write_nodedata(vtks::VTKStream, grid::AbstractGrid, nodedata::Vector{Real}, name) - write_nodedata(vtks::VTKStream, grid::AbstractGrid, nodedata::Vector{<:AbstractTensor}, name) + write_nodedata(vtk::VTKFile, grid::AbstractGrid, nodedata::Vector{Real}, name) + write_nodedata(vtk::VTKFile, grid::AbstractGrid, nodedata::Vector{<:AbstractTensor}, name) Write the `nodedata` that is ordered by the nodes in the grid to the vtk stream. @@ -209,50 +209,50 @@ Two-dimensional vectors are padded with zeros. When `nodedata` contains second order tensors, the index order, `[11, 22, 33, 23, 13, 12, 32, 31, 21]`, follows the default Voigt order in Tensors.jl. """ -function write_nodedata(vtks::VTKStream, ::AbstractGrid, nodedata, name) - _vtk_write_nodedata(vtks.vtk, nodedata, name) +function write_nodedata(vtk::VTKFile, ::AbstractGrid, nodedata, name) + _vtk_write_nodedata(vtk.vtk, nodedata, name) end """ - write_nodeset(vtks::VTKStream, grid::AbstractGrid, nodeset::String) + write_nodeset(vtk::VTKFile, grid::AbstractGrid, nodeset::String) Write nodal values of 1 for nodes in `nodeset`, and 0 otherwise """ -function write_nodeset(vtks, grid::AbstractGrid, nodeset::String) +function write_nodeset(vtk, grid::AbstractGrid, nodeset::String) z = zeros(getnnodes(grid)) z[collect(getnodeset(grid, nodeset))] .= 1.0 - write_nodedata(vtks, grid, z, nodeset) - return vtks + write_nodedata(vtk, grid, z, nodeset) + return vtk end """ - write_cellset(vtks, grid::AbstractGrid) - write_cellset(vtks, grid::AbstractGrid, cellset::String) - write_cellset(vtks, grid::AbstractGrid, cellsets::Union{AbstractVector{String},AbstractSet{String}) + write_cellset(vtk, grid::AbstractGrid) + write_cellset(vtk, grid::AbstractGrid, cellset::String) + write_cellset(vtk, grid::AbstractGrid, cellsets::Union{AbstractVector{String},AbstractSet{String}) Write all cell sets in the grid with name according to their keys and celldata 1 if the cell is in the set, and 0 otherwise. It is also possible to only export a single `cellset`, or multiple `cellsets`. """ -function write_cellset(vtks, grid::AbstractGrid, cellsets=keys(getcellsets(getgrid(vtks)))) +function write_cellset(vtk, grid::AbstractGrid, cellsets=keys(getcellsets(getgrid(vtk)))) z = zeros(getncells(grid)) for cellset in cellsets fill!(z, 0) z[collect(getcellset(grid, cellset))] .= 1.0 - write_celldata(vtks, grid, z, cellset) + write_celldata(vtk, grid, z, cellset) end - return vtks + return vtk end -write_cellset(vtks, grid::AbstractGrid, cellset::String) = write_cellset(vtks, grid, [cellset]) +write_cellset(vtk, grid::AbstractGrid, cellset::String) = write_cellset(vtk, grid, [cellset]) """ - write_dirichlet(vtks::VTKStream, ch::ConstraintHandler) + write_dirichlet(vtk::VTKFile, ch::ConstraintHandler) Saves the dirichlet boundary conditions to a vtkfile. Values will have a 1 where bcs are active and 0 otherwise """ -function write_dirichlet(vtks, ch::ConstraintHandler) +function write_dirichlet(vtk, ch::ConstraintHandler) unique_fields = [] for dbc in ch.dbcs push!(unique_fields, dbc.field_name) @@ -281,24 +281,24 @@ function write_dirichlet(vtks, ch::ConstraintHandler) end end end - write_nodedata(vtks, get_grid(ch.dh), data, string(field, "_bc")) + write_nodedata(vtk, get_grid(ch.dh), data, string(field, "_bc")) end - return vtks + return vtk end """ - write_cell_colors(vtks::VTKStream, grid::AbstractGrid, cell_colors, name="coloring") + write_cell_colors(vtk::VTKFile, grid::AbstractGrid, cell_colors, name="coloring") Write cell colors (see [`create_coloring`](@ref)) to a VTK file for visualization. In case of coloring a subset, the cells which are not part of the subset are represented as color 0. """ -function write_cell_colors(vtks, grid::AbstractGrid, cell_colors::AbstractVector{<:AbstractVector{<:Integer}}, name="coloring") +function write_cell_colors(vtk, grid::AbstractGrid, cell_colors::AbstractVector{<:AbstractVector{<:Integer}}, name="coloring") color_vector = zeros(Int, getncells(grid)) for (i, cells_color) in enumerate(cell_colors) for cell in cells_color color_vector[cell] = i end end - write_celldata(vtks, grid, color_vector, name) + write_celldata(vtk, grid, color_vector, name) end diff --git a/src/deprecations.jl b/src/deprecations.jl index 8135c7d160..625a3bb42f 100644 --- a/src/deprecations.jl +++ b/src/deprecations.jl @@ -63,23 +63,23 @@ export Line2D, Line3D, Quadrilateral3D import WriteVTK: vtk_grid, vtk_cell_data, vtk_point_data, vtk_save -@deprecate vtk_grid(filename::String, grid::AbstractGrid; kwargs...) VTKStream(filename, grid; kwargs...) -@deprecate vtk_grid(filename::String, dh::DofHandler; kwargs...) VTKStream(filename, get_grid(dh); kwargs...) +@deprecate vtk_grid(filename::String, grid::AbstractGrid; kwargs...) VTKFile(filename, grid; kwargs...) +@deprecate vtk_grid(filename::String, dh::DofHandler; kwargs...) VTKFile(filename, get_grid(dh); kwargs...) struct _DummyGrid{D} <: AbstractGrid{D} ncells::Int end _DummyGrid(ncells=1) = _DummyGrid{1}(ncells) getncells(g::_DummyGrid) = g.ncells -@deprecate vtk_cell_data(vtks::VTKStream, args...) write_celldata(vtks, _DummyGrid(), args...) -@deprecate vtk_point_data(vtks::VTKStream, data::Vector, args...) write_nodedata(vtks, _DummyGrid(), data, args...) -@deprecate vtk_point_data(vtks::VTKStream, proj::L2Projector, args...) write_projected(vtks, proj, args...) -@deprecate vtk_point_data(vtks::VTKStream, ch::ConstraintHandler) write_dirichlet(vtks, ch) -@deprecate vtk_cellset(vtks::VTKStream, grid::AbstractGrid, args...) write_cellset(vtks, grid, args...) -@deprecate vtk_nodeset(vtks::VTKStream, grid::AbstractGrid, args...) write_nodeset(vtks, grid, args...) -@deprecate vtk_cell_data_colors(vtks::VTKStream, args...) write_cell_colors(vtks, _DummyGrid(vtks.vtk.Ncls), args...) -@deprecate vtk_save(vtks::VTKStream) close(vtks) -@deprecate vtk_point_data(vtks::VTKStream, dh::DofHandler, args...) write_solution(vtks, dh, args...) +@deprecate vtk_cell_data(vtk::VTKFile, args...) write_celldata(vtk, _DummyGrid(), args...) +@deprecate vtk_point_data(vtk::VTKFile, data::Vector, args...) write_nodedata(vtk, _DummyGrid(), data, args...) +@deprecate vtk_point_data(vtk::VTKFile, proj::L2Projector, args...) write_projected(vtk, proj, args...) +@deprecate vtk_point_data(vtk::VTKFile, ch::ConstraintHandler) write_dirichlet(vtk, ch) +@deprecate vtk_cellset(vtk::VTKFile, grid::AbstractGrid, args...) write_cellset(vtk, grid, args...) +@deprecate vtk_nodeset(vtk::VTKFile, grid::AbstractGrid, args...) write_nodeset(vtk, grid, args...) +@deprecate vtk_cell_data_colors(vtk::VTKFile, args...) write_cell_colors(vtk, _DummyGrid(vtk.vtk.Ncls), args...) +@deprecate vtk_save(vtk::VTKFile) close(vtk) +@deprecate vtk_point_data(vtk::VTKFile, dh::DofHandler, args...) write_solution(vtk, dh, args...) # Deprecation of auto-vectorized methods function add!(dh::DofHandler, name::Symbol, dim::Int) diff --git a/src/exports.jl b/src/exports.jl index 2a83535bd6..ff3ed43e40 100644 --- a/src/exports.jl +++ b/src/exports.jl @@ -146,16 +146,10 @@ export assemble!, finish_assemble, -# (VTK) export stream - VTKStream, +# export data (using e.g. Ferrite.VTKFile) write_solution, write_celldata, - write_nodedata, write_projected, - write_nodeset, - write_cellset, - write_cell_colors, - write_dirichlet, # L2 Projection project, diff --git a/test/test_constraints.jl b/test/test_constraints.jl index 00e3832a14..d24f5ccee7 100644 --- a/test/test_constraints.jl +++ b/test/test_constraints.jl @@ -1553,9 +1553,9 @@ end # testset @test norm(u_dbc) ≈ 3.8249286998373586 @test norm(u_p) ≈ 3.7828270430540893 end - # VTKStream("local_application_azero_$(azero)", grid) do vtks - # write_solution(vtks, dh, u_dbc, "_dbc") - # write_solution(vtks, dh, u_p, "_p") + # VTKFile("local_application_azero_$(azero)", grid) do vtk + # write_solution(vtk, dh, u_dbc, "_dbc") + # write_solution(vtk, dh, u_p, "_p") # end @test K_dbc_standard \ f_dbc_standard ≈ K_dbc_ch \ f_dbc_ch ≈ K_dbc_local \ f_dbc_local ≈ K_ac_standard \ f_ac_standard ≈ K_ac_ch \ f_ac_ch ≈ K_ac_local \ f_ac_local diff --git a/test/test_grid_dofhandler_vtk.jl b/test/test_grid_dofhandler_vtk.jl index 5f6329f57b..23558b9f36 100644 --- a/test/test_grid_dofhandler_vtk.jl +++ b/test/test_grid_dofhandler_vtk.jl @@ -36,10 +36,10 @@ end addnodeset!(grid, "middle-nodes", x -> norm(x) < radius) gridfilename = "grid-$(repr(celltype))" - VTKStream(gridfilename, grid) do vtks - write_cellset(vtks, grid, "cell-1") - write_cellset(vtks, grid, "middle-cells") - write_nodeset(vtks, grid, "middle-nodes") + VTKFile(gridfilename, grid) do vtk + Ferrite.write_cellset(vtk, grid, "cell-1") + Ferrite.write_cellset(vtk, grid, "middle-cells") + Ferrite.write_nodeset(vtk, grid, "middle-nodes") end # test the sha of the file @@ -75,9 +75,9 @@ end apply!(u, ch) dofhandlerfilename = "dofhandler-$(repr(celltype))" - VTKStream(dofhandlerfilename, grid) do vtks - write_dirichlet(vtks, ch) - write_solution(vtks, dofhandler, u) + VTKFile(dofhandlerfilename, grid) do vtk + Ferrite.write_dirichlet(vtk, ch) + write_solution(vtk, dofhandler, u) end # test the sha of the file @@ -112,10 +112,10 @@ close(csio) vector_data = [Vec{3}(ntuple(i->i, 3)) for j=1:8] filename_3d = "test_vtk_3d" - VTKStream(filename_3d, grid) do vtks - write_nodedata(vtks, grid, sym_tensor_data, "symmetric tensor") - write_nodedata(vtks, grid, tensor_data, "tensor") - write_nodedata(vtks, grid, vector_data, "vector") + VTKFile(filename_3d, grid) do vtk + Ferrite.write_nodedata(vtk, grid, sym_tensor_data, "symmetric tensor") + Ferrite.write_nodedata(vtk, grid, tensor_data, "tensor") + Ferrite.write_nodedata(vtk, grid, vector_data, "vector") end # 2D grid @@ -127,11 +127,11 @@ close(csio) vector_data = [Vec{2}(ntuple(i->i, 2)) for j=1:4] filename_2d = "test_vtk_2d" - VTKStream(filename_2d, grid) do vtks - write_nodedata(vtks, grid, sym_tensor_data, "symmetric tensor") - write_nodedata(vtks, grid, tensor_data, "tensor") - write_nodedata(vtks, grid, tensor_data_1D, "tensor_1d") - write_nodedata(vtks, grid, vector_data, "vector") + VTKFile(filename_2d, grid) do vtk + Ferrite.write_nodedata(vtk, grid, sym_tensor_data, "symmetric tensor") + Ferrite.write_nodedata(vtk, grid, tensor_data, "tensor") + Ferrite.write_nodedata(vtk, grid, tensor_data_1D, "tensor_1d") + Ferrite.write_nodedata(vtk, grid, vector_data, "vector") end # test the shas of the files diff --git a/test/test_l2_projection.jl b/test/test_l2_projection.jl index d497975fef..50ccbf12e6 100644 --- a/test/test_l2_projection.jl +++ b/test/test_l2_projection.jl @@ -268,11 +268,11 @@ function test_export(;subset::Bool) mktempdir() do tmp fname = joinpath(tmp, "projected") - VTKStream(fname, grid) do vtks - write_projected(vtks, p, p_scalar, "p_scalar") - write_projected(vtks, p, p_vec, "p_vec") - write_projected(vtks, p, p_tens, "p_tens") - write_projected(vtks, p, p_stens, "p_stens") + VTKFile(fname, grid) do vtk + write_projected(vtk, p, p_scalar, "p_scalar") + write_projected(vtk, p, p_vec, "p_vec") + write_projected(vtk, p, p_tens, "p_tens") + write_projected(vtk, p, p_stens, "p_stens") end @test bytes2hex(open(SHA.sha1, fname*".vtu", "r")) in ( subset ? ("261cfe21de7a478e14f455e783694651a91eeb60", "b3fef3de9f38ca9ddd92f2f67a1606d07ca56d67") : diff --git a/test/test_mixeddofhandler.jl b/test/test_mixeddofhandler.jl index 17044fc052..b2c87619b8 100644 --- a/test/test_mixeddofhandler.jl +++ b/test/test_mixeddofhandler.jl @@ -355,11 +355,11 @@ function test_2_element_heat_eq() gridfilename = "mixed_grid" addcellset!(grid, "cell-1", [1,]) addcellset!(grid, "cell-2", [2,]) - VTKStream(gridfilename, grid) do vtks - write_cellset(vtks, grid, "cell-1") - write_cellset(vtks, grid, "cell-2") - write_solution(vtks, dh, u) - # write_dirichlet(vtks, ch) #FIXME + VTKFile(gridfilename, grid) do vtk + Ferrite.write_cellset(vtk, grid, "cell-1") + Ferrite.write_cellset(vtk, grid, "cell-2") + write_solution(vtk, dh, u) + # Ferrite.write_dirichlet(vtk, ch) #FIXME end sha = bytes2hex(open(SHA.sha1, gridfilename*".vtu")) @test sha in ("e96732c000b0b385db7444f002461468b60b3b2c", "7b26edc27b5e59a2f60907374cd5a5790cc37a6a") From ee61c6ec6af42db0c4c3c888c14953fb24c6948f Mon Sep 17 00:00:00 2001 From: Knut Andreas Meyer Date: Wed, 19 Jul 2023 15:39:02 +0200 Subject: [PATCH 20/67] Fix tests --- docs/src/literate-gallery/helmholtz.jl | 2 +- docs/src/literate-gallery/landau.jl | 2 +- .../quasi_incompressible_hyperelasticity.jl | 2 +- docs/src/literate-gallery/topology_optimization.jl | 4 ++-- docs/src/literate-howto/postprocessing.jl | 4 ++-- docs/src/literate-howto/threaded_assembly.jl | 2 +- .../literate-tutorials/computational_homogenization.jl | 6 +++--- docs/src/literate-tutorials/heat_equation.jl | 2 +- docs/src/literate-tutorials/hyperelasticity.jl | 2 +- .../literate-tutorials/incompressible_elasticity.jl | 2 +- docs/src/literate-tutorials/linear_shell.jl | 2 +- docs/src/literate-tutorials/ns_vs_diffeq.jl | 2 +- docs/src/literate-tutorials/plasticity.jl | 2 +- docs/src/literate-tutorials/stokes-flow.jl | 2 +- docs/src/literate-tutorials/transient_heat_equation.jl | 4 ++-- docs/src/reference/export.md | 4 ++-- docs/src/topics/export.md | 10 +++++----- src/Export/VTK.jl | 6 +++--- src/deprecations.jl | 2 +- src/exports.jl | 2 +- test/test_constraints.jl | 2 +- test/test_grid_dofhandler_vtk.jl | 8 ++++---- test/test_l2_projection.jl | 10 +++++----- test/test_mixeddofhandler.jl | 2 +- 24 files changed, 43 insertions(+), 43 deletions(-) diff --git a/docs/src/literate-gallery/helmholtz.jl b/docs/src/literate-gallery/helmholtz.jl index 98714d74ec..b702fa9928 100644 --- a/docs/src/literate-gallery/helmholtz.jl +++ b/docs/src/literate-gallery/helmholtz.jl @@ -162,7 +162,7 @@ K, f = doassemble(cellvalues, facevalues, K, dh); apply!(K, f, dbcs) u = Symmetric(K) \ f; -vtk = VTKFile("helmholtz", grid) +vtk = Ferrite.VTKFile("helmholtz", grid) write_solution(vtk, dh, u) close(vtk) using Test #src diff --git a/docs/src/literate-gallery/landau.jl b/docs/src/literate-gallery/landau.jl index b2fd6937f0..dd185b6f47 100644 --- a/docs/src/literate-gallery/landau.jl +++ b/docs/src/literate-gallery/landau.jl @@ -114,7 +114,7 @@ end # utility to quickly save a model function save_landau(path, model, dofs=model.dofs) - VTKFile(path, model.dofhandler.grid) do vtk + Ferrite.VTKFile(path, model.dofhandler.grid) do vtk write_solution(vtk, model.dofhandler, dofs) end end diff --git a/docs/src/literate-gallery/quasi_incompressible_hyperelasticity.jl b/docs/src/literate-gallery/quasi_incompressible_hyperelasticity.jl index d47f2f3638..59ae227e7a 100644 --- a/docs/src/literate-gallery/quasi_incompressible_hyperelasticity.jl +++ b/docs/src/literate-gallery/quasi_incompressible_hyperelasticity.jl @@ -334,7 +334,7 @@ function solve(interpolation_u, interpolation_p) end; ## Save the solution fields - VTKFile("hyperelasticity_incomp_mixed_$t.vtu", grid) do vtk + Ferrite.VTKFile("hyperelasticity_incomp_mixed_$t.vtu", grid) do vtk write_solution(vtk, dh, w) pvd[t] = vtk end diff --git a/docs/src/literate-gallery/topology_optimization.jl b/docs/src/literate-gallery/topology_optimization.jl index 3bac1900d4..5c880df7e2 100644 --- a/docs/src/literate-gallery/topology_optimization.jl +++ b/docs/src/literate-gallery/topology_optimization.jl @@ -492,7 +492,7 @@ function topopt(ra,ρ,n,filename; output=:false) i = @sprintf("%3.3i", it) filename_it = string(filename, "_", i) - VTKFile(filename_it, grid) do vtk + Ferrite.VTKFile(filename_it, grid) do vtk write_celldata(vtk, grid, χ, "density") end end @@ -500,7 +500,7 @@ function topopt(ra,ρ,n,filename; output=:false) ## export converged results if(!output) - VTKFile(filename, grid) do vtk + Ferrite.VTKFile(filename, grid) do vtk write_celldata(vtk, grid, χ, "density") end end diff --git a/docs/src/literate-howto/postprocessing.jl b/docs/src/literate-howto/postprocessing.jl index 94e43e0be1..6e9c960ea2 100644 --- a/docs/src/literate-howto/postprocessing.jl +++ b/docs/src/literate-howto/postprocessing.jl @@ -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*. -VTKFile("heat_equation_flux", grid) do vtk - write_projected(vtk, projector, q_projected, "q") +Ferrite.VTKFile("heat_equation_flux", grid) do vtk + write_projection(vtk, projector, q_projected, "q") end; # ## Point Evaluation diff --git a/docs/src/literate-howto/threaded_assembly.jl b/docs/src/literate-howto/threaded_assembly.jl index 3450325e0f..d709e4c5f2 100644 --- a/docs/src/literate-howto/threaded_assembly.jl +++ b/docs/src/literate-howto/threaded_assembly.jl @@ -25,7 +25,7 @@ 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) - VTKFile("colored", grid) do vtk + Ferrite.VTKFile("colored", grid) do vtk write_cell_colors(vtk, grid, colors_workstream, "workstream-coloring") write_cell_colors(vtk, grid, colors_greedy, "greedy-coloring") end diff --git a/docs/src/literate-tutorials/computational_homogenization.jl b/docs/src/literate-tutorials/computational_homogenization.jl index 03fbfb8fb8..f8b1a304e4 100644 --- a/docs/src/literate-tutorials/computational_homogenization.jl +++ b/docs/src/literate-tutorials/computational_homogenization.jl @@ -518,16 +518,16 @@ round.(ev; digits=-8) uM = zeros(ndofs(dh)) -VTKFile("homogenization", grid) do vtk +Ferrite.VTKFile("homogenization", grid) do vtk for i in 1:3 ## Compute macroscopic solution apply_analytical!(uM, dh, :u, x -> εᴹ[i] ⋅ x) ## Dirichlet write_solution(vtk, dh, uM + u.dirichlet[i], "_dirichlet_$i") - write_projected(vtk, projector, σ.dirichlet[i], "σvM_dirichlet_$i") + write_projection(vtk, projector, σ.dirichlet[i], "σvM_dirichlet_$i") ## Periodic write_solution(vtk, dh, uM + u.periodic[i], "_periodic_$i") - write_projected(vtk, projector, σ.periodic[i], "σvM_periodic_$i") + write_projection(vtk, projector, σ.periodic[i], "σvM_periodic_$i") end end; diff --git a/docs/src/literate-tutorials/heat_equation.jl b/docs/src/literate-tutorials/heat_equation.jl index 887de39793..da8847c756 100644 --- a/docs/src/literate-tutorials/heat_equation.jl +++ b/docs/src/literate-tutorials/heat_equation.jl @@ -213,7 +213,7 @@ 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/). -VTKFile("heat_equation", grid) do vtk +Ferrite.VTKFile("heat_equation", grid) do vtk write_solution(vtk, dh, u) end diff --git a/docs/src/literate-tutorials/hyperelasticity.jl b/docs/src/literate-tutorials/hyperelasticity.jl index ad915aaa6e..2c82a8dc42 100644 --- a/docs/src/literate-tutorials/hyperelasticity.jl +++ b/docs/src/literate-tutorials/hyperelasticity.jl @@ -397,7 +397,7 @@ function solve() ## Save the solution @timeit "export" begin - VTKFile("hyperelasticity", grid) do vtk + Ferrite.VTKFile("hyperelasticity", grid) do vtk write_solution(vtk, dh, u) end end diff --git a/docs/src/literate-tutorials/incompressible_elasticity.jl b/docs/src/literate-tutorials/incompressible_elasticity.jl index 74df3ebf53..8b597ffffc 100644 --- a/docs/src/literate-tutorials/incompressible_elasticity.jl +++ b/docs/src/literate-tutorials/incompressible_elasticity.jl @@ -209,7 +209,7 @@ function solve(ν, interpolation_u, interpolation_p) ## export filename = "cook_" * (isa(interpolation_u, Lagrange{RefTriangle,1}) ? "linear" : "quadratic") * "_linear" - VTKFile(filename, grid) do vtk + Ferrite.VTKFile(filename, grid) do vtk write_solution(vtk, dh, u) end return u diff --git a/docs/src/literate-tutorials/linear_shell.jl b/docs/src/literate-tutorials/linear_shell.jl index e876f0c1cb..e38b429cc9 100644 --- a/docs/src/literate-tutorials/linear_shell.jl +++ b/docs/src/literate-tutorials/linear_shell.jl @@ -113,7 +113,7 @@ a = K\f # Output results. #+ -VTKFile("linear_shell", grid) do vtk +Ferrite.VTKFile("linear_shell", grid) do vtk write_solution(vtk, dh, a) end diff --git a/docs/src/literate-tutorials/ns_vs_diffeq.jl b/docs/src/literate-tutorials/ns_vs_diffeq.jl index d2ce50b628..1e589e165d 100644 --- a/docs/src/literate-tutorials/ns_vs_diffeq.jl +++ b/docs/src/literate-tutorials/ns_vs_diffeq.jl @@ -440,7 +440,7 @@ for (u_uc,t) in integrator update!(ch, t) u = copy(u_uc) apply!(u, ch) - VTKFile("vortex-street-$t.vtu", grid) do vtk + Ferrite.VTKFile("vortex-street-$t.vtu", grid) do vtk write_solution(vtk, dh, u) pvd[t] = vtk end diff --git a/docs/src/literate-tutorials/plasticity.jl b/docs/src/literate-tutorials/plasticity.jl index 3e9f1755a1..762fca5c62 100644 --- a/docs/src/literate-tutorials/plasticity.jl +++ b/docs/src/literate-tutorials/plasticity.jl @@ -344,7 +344,7 @@ function solve() mises_values[el] /= length(cell_states) # average von Mises stress κ_values[el] /= length(cell_states) # average drag stress end - VTKFile("plasticity", grid) do vtk + Ferrite.VTKFile("plasticity", grid) do vtk write_solution(vtk, dh, u) # displacement field write_celldata(vtk, grid, mises_values, "von Mises [Pa]") write_celldata(vtk, grid, κ_values, "Drag stress [Pa]") diff --git a/docs/src/literate-tutorials/stokes-flow.jl b/docs/src/literate-tutorials/stokes-flow.jl index 2ee740a499..88d4037290 100644 --- a/docs/src/literate-tutorials/stokes-flow.jl +++ b/docs/src/literate-tutorials/stokes-flow.jl @@ -505,7 +505,7 @@ function main() u = K \ f apply!(u, ch) ## Export the solution - VTKFile("stokes-flow", grid) do vtk + Ferrite.VTKFile("stokes-flow", grid) do vtk write_solution(vtk, dh, u) end diff --git a/docs/src/literate-tutorials/transient_heat_equation.jl b/docs/src/literate-tutorials/transient_heat_equation.jl index ef945bd542..068ca1d928 100644 --- a/docs/src/literate-tutorials/transient_heat_equation.jl +++ b/docs/src/literate-tutorials/transient_heat_equation.jl @@ -192,7 +192,7 @@ apply!(A, ch); # To store the solution, we initialize a `paraview_collection` (.pvd) file. pvd = paraview_collection("transient-heat.pvd"); t = 0 -VTKFile("transient-heat-$t", grid) do vtk +Ferrite.VTKFile("transient-heat-$t", grid) do vtk write_solution(vtk, dh, uₙ) pvd[t] = vtk end @@ -210,7 +210,7 @@ for t in Δt:Δt:T #Finally, we can solve the time step and save the solution afterwards. u = A \ b - VTKFile("transient-heat-$t", grid) do vtk + Ferrite.VTKFile("transient-heat-$t", grid) do vtk write_solution(vtk, dh, u) pvd[t] = vtk end diff --git a/docs/src/reference/export.md b/docs/src/reference/export.md index 3344179643..3921923e06 100644 --- a/docs/src/reference/export.md +++ b/docs/src/reference/export.md @@ -26,9 +26,9 @@ evaluate_at_grid_nodes ## VTK Export ```@docs -VTKFile +Ferrite.VTKFile write_solution -write_projected +write_projection write_celldata Ferrite.write_nodedata Ferrite.write_cellset diff --git a/docs/src/topics/export.md b/docs/src/topics/export.md index 2ab215116d..92f4813ed3 100644 --- a/docs/src/topics/export.md +++ b/docs/src/topics/export.md @@ -17,7 +17,7 @@ the exporting. The following structure can be used to write various output to a vtk-file: ```@example export -VTKFile("my_solution", grid) do vtk +Ferrite.VTKFile("my_solution", grid) do vtk write_solution(vtk, dh, u) end ``` @@ -26,7 +26,7 @@ where `write_solution` is just one example of the following functions that can b * [`write_solution`](@ref) * [`write_celldata`](@ref) * [`Ferrite.write_nodedata`](@ref) -* [`write_projected`](@ref) +* [`write_projection`](@ref) * [`Ferrite.write_cellset`](@ref) * [`Ferrite.write_nodeset`](@ref) * [`Ferrite.write_dirichlet`](@ref) @@ -34,13 +34,13 @@ where `write_solution` is just one example of the following functions that can b Instead of using the `do`-block, it is also possible to do ```@example export -vtk = VTKFile("my_solution", grid) +vtk = Ferrite.VTKFile("my_solution", grid) write_solution(vtk, dh, u) # etc. close(vtk) ``` -The data written by `write_solution`, `write_celldata`, `Ferrite.write_nodedata`, and `write_projected` may be either scalar (`Vector{<:Number}`) or tensor (`Vector{<:AbstractTensor}`) data. +The data written by `write_solution`, `write_celldata`, `Ferrite.write_nodedata`, and `write_projection` may be either scalar (`Vector{<:Number}`) or tensor (`Vector{<:AbstractTensor}`) data. To save time-dependent data, `WriteVTK.jl`'s, `paraview_collection` may be used @@ -48,7 +48,7 @@ To save time-dependent data, `WriteVTK.jl`'s, `paraview_collection` may be used pvd = paraview_collection("my_results.pvd"); for i in 1:5 # Do calculations to update u - VTKFile("my_results_$i", grid) do vtk + Ferrite.VTKFile("my_results_$i", grid) do vtk write_solution(vtk, dh, u) pvd[i] = vtk end diff --git a/src/Export/VTK.jl b/src/Export/VTK.jl index fe06c1c6e2..3ab36cb229 100644 --- a/src/Export/VTK.jl +++ b/src/Export/VTK.jl @@ -13,7 +13,7 @@ This file handler can be used to to write data with * [`write_solution`](@ref) * [`write_celldata`](@ref) -* [`write_projected`](@ref) +* [`write_projection`](@ref) * [`Ferrite.write_nodedata`](@ref). * [`Ferrite.write_cellset`](@ref) * [`Ferrite.write_nodeset`](@ref) @@ -177,11 +177,11 @@ function write_solution(vtk::VTKFile, dh::AbstractDofHandler, u::Vector, suffix= end """ - write_projected(vtk::VTKFile, proj::L2Projector, vals::Vector, name::AbstractString) + write_projection(vtk::VTKFile, proj::L2Projector, vals::Vector, name::AbstractString) Project `vals` to the grid nodes with `proj` and save to the stream. """ -function write_projected(vtk::VTKFile, proj::L2Projector, vals, name) +function write_projection(vtk::VTKFile, proj::L2Projector, vals, name) data = _evaluate_at_grid_nodes(proj, vals, #=vtk=# Val(true))::Matrix @assert size(data, 2) == getnnodes(get_grid(proj.dh)) _vtk_write_nodedata(vtk.vtk, data, name; component_names=component_names(eltype(vals))) diff --git a/src/deprecations.jl b/src/deprecations.jl index 625a3bb42f..6da12f9f68 100644 --- a/src/deprecations.jl +++ b/src/deprecations.jl @@ -73,7 +73,7 @@ getncells(g::_DummyGrid) = g.ncells @deprecate vtk_cell_data(vtk::VTKFile, args...) write_celldata(vtk, _DummyGrid(), args...) @deprecate vtk_point_data(vtk::VTKFile, data::Vector, args...) write_nodedata(vtk, _DummyGrid(), data, args...) -@deprecate vtk_point_data(vtk::VTKFile, proj::L2Projector, args...) write_projected(vtk, proj, args...) +@deprecate vtk_point_data(vtk::VTKFile, proj::L2Projector, args...) write_projection(vtk, proj, args...) @deprecate vtk_point_data(vtk::VTKFile, ch::ConstraintHandler) write_dirichlet(vtk, ch) @deprecate vtk_cellset(vtk::VTKFile, grid::AbstractGrid, args...) write_cellset(vtk, grid, args...) @deprecate vtk_nodeset(vtk::VTKFile, grid::AbstractGrid, args...) write_nodeset(vtk, grid, args...) diff --git a/src/exports.jl b/src/exports.jl index ff3ed43e40..10dd063aa5 100644 --- a/src/exports.jl +++ b/src/exports.jl @@ -149,7 +149,7 @@ export # export data (using e.g. Ferrite.VTKFile) write_solution, write_celldata, - write_projected, + write_projection, # L2 Projection project, diff --git a/test/test_constraints.jl b/test/test_constraints.jl index d24f5ccee7..007324cca1 100644 --- a/test/test_constraints.jl +++ b/test/test_constraints.jl @@ -1553,7 +1553,7 @@ end # testset @test norm(u_dbc) ≈ 3.8249286998373586 @test norm(u_p) ≈ 3.7828270430540893 end - # VTKFile("local_application_azero_$(azero)", grid) do vtk + # Ferrite.VTKFile("local_application_azero_$(azero)", grid) do vtk # write_solution(vtk, dh, u_dbc, "_dbc") # write_solution(vtk, dh, u_p, "_p") # end diff --git a/test/test_grid_dofhandler_vtk.jl b/test/test_grid_dofhandler_vtk.jl index 23558b9f36..90f7ca3d8d 100644 --- a/test/test_grid_dofhandler_vtk.jl +++ b/test/test_grid_dofhandler_vtk.jl @@ -36,7 +36,7 @@ end addnodeset!(grid, "middle-nodes", x -> norm(x) < radius) gridfilename = "grid-$(repr(celltype))" - VTKFile(gridfilename, grid) do vtk + Ferrite.VTKFile(gridfilename, grid) do vtk Ferrite.write_cellset(vtk, grid, "cell-1") Ferrite.write_cellset(vtk, grid, "middle-cells") Ferrite.write_nodeset(vtk, grid, "middle-nodes") @@ -75,7 +75,7 @@ end apply!(u, ch) dofhandlerfilename = "dofhandler-$(repr(celltype))" - VTKFile(dofhandlerfilename, grid) do vtk + Ferrite.VTKFile(dofhandlerfilename, grid) do vtk Ferrite.write_dirichlet(vtk, ch) write_solution(vtk, dofhandler, u) end @@ -112,7 +112,7 @@ close(csio) vector_data = [Vec{3}(ntuple(i->i, 3)) for j=1:8] filename_3d = "test_vtk_3d" - VTKFile(filename_3d, grid) do vtk + Ferrite.VTKFile(filename_3d, grid) do vtk Ferrite.write_nodedata(vtk, grid, sym_tensor_data, "symmetric tensor") Ferrite.write_nodedata(vtk, grid, tensor_data, "tensor") Ferrite.write_nodedata(vtk, grid, vector_data, "vector") @@ -127,7 +127,7 @@ close(csio) vector_data = [Vec{2}(ntuple(i->i, 2)) for j=1:4] filename_2d = "test_vtk_2d" - VTKFile(filename_2d, grid) do vtk + Ferrite.VTKFile(filename_2d, grid) do vtk Ferrite.write_nodedata(vtk, grid, sym_tensor_data, "symmetric tensor") Ferrite.write_nodedata(vtk, grid, tensor_data, "tensor") Ferrite.write_nodedata(vtk, grid, tensor_data_1D, "tensor_1d") diff --git a/test/test_l2_projection.jl b/test/test_l2_projection.jl index 50ccbf12e6..544a76784c 100644 --- a/test/test_l2_projection.jl +++ b/test/test_l2_projection.jl @@ -268,11 +268,11 @@ function test_export(;subset::Bool) mktempdir() do tmp fname = joinpath(tmp, "projected") - VTKFile(fname, grid) do vtk - write_projected(vtk, p, p_scalar, "p_scalar") - write_projected(vtk, p, p_vec, "p_vec") - write_projected(vtk, p, p_tens, "p_tens") - write_projected(vtk, p, p_stens, "p_stens") + Ferrite.VTKFile(fname, grid) do vtk + write_projection(vtk, p, p_scalar, "p_scalar") + write_projection(vtk, p, p_vec, "p_vec") + write_projection(vtk, p, p_tens, "p_tens") + write_projection(vtk, p, p_stens, "p_stens") end @test bytes2hex(open(SHA.sha1, fname*".vtu", "r")) in ( subset ? ("261cfe21de7a478e14f455e783694651a91eeb60", "b3fef3de9f38ca9ddd92f2f67a1606d07ca56d67") : diff --git a/test/test_mixeddofhandler.jl b/test/test_mixeddofhandler.jl index b2c87619b8..622a71718d 100644 --- a/test/test_mixeddofhandler.jl +++ b/test/test_mixeddofhandler.jl @@ -355,7 +355,7 @@ function test_2_element_heat_eq() gridfilename = "mixed_grid" addcellset!(grid, "cell-1", [1,]) addcellset!(grid, "cell-2", [2,]) - VTKFile(gridfilename, grid) do vtk + Ferrite.VTKFile(gridfilename, grid) do vtk Ferrite.write_cellset(vtk, grid, "cell-1") Ferrite.write_cellset(vtk, grid, "cell-2") write_solution(vtk, dh, u) From 22937f03598a74ae79b76a545db266dc1779fc10 Mon Sep 17 00:00:00 2001 From: Knut Andreas Meyer Date: Wed, 19 Jul 2023 15:52:54 +0200 Subject: [PATCH 21/67] Use qualified name for write_cell_colors --- docs/src/literate-howto/threaded_assembly.jl | 4 ++-- docs/src/reference/export.md | 2 +- docs/src/topics/export.md | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/docs/src/literate-howto/threaded_assembly.jl b/docs/src/literate-howto/threaded_assembly.jl index d709e4c5f2..d860d81b9b 100644 --- a/docs/src/literate-howto/threaded_assembly.jl +++ b/docs/src/literate-howto/threaded_assembly.jl @@ -26,8 +26,8 @@ function create_example_2d_grid() colors_workstream = create_coloring(grid; alg=ColoringAlgorithm.WorkStream) colors_greedy = create_coloring(grid; alg=ColoringAlgorithm.Greedy) Ferrite.VTKFile("colored", grid) do vtk - write_cell_colors(vtk, grid, colors_workstream, "workstream-coloring") - write_cell_colors(vtk, grid, colors_greedy, "greedy-coloring") + Ferrite.write_cell_colors(vtk, grid, colors_workstream, "workstream-coloring") + Ferrite.write_cell_colors(vtk, grid, colors_greedy, "greedy-coloring") end end diff --git a/docs/src/reference/export.md b/docs/src/reference/export.md index 3921923e06..161369f861 100644 --- a/docs/src/reference/export.md +++ b/docs/src/reference/export.md @@ -34,5 +34,5 @@ Ferrite.write_nodedata Ferrite.write_cellset Ferrite.write_nodeset Ferrite.write_dirichlet -write_cell_colors +Ferrite.write_cell_colors ``` diff --git a/docs/src/topics/export.md b/docs/src/topics/export.md index 92f4813ed3..523106cd6a 100644 --- a/docs/src/topics/export.md +++ b/docs/src/topics/export.md @@ -30,7 +30,7 @@ where `write_solution` is just one example of the following functions that can b * [`Ferrite.write_cellset`](@ref) * [`Ferrite.write_nodeset`](@ref) * [`Ferrite.write_dirichlet`](@ref) -* [`write_cell_colors`](@ref) +* [`Ferrite.write_cell_colors`](@ref) Instead of using the `do`-block, it is also possible to do ```@example export From ccaeca22c0bf955a47f5a980621711017cc55aa4 Mon Sep 17 00:00:00 2001 From: Knut Andreas Meyer Date: Wed, 19 Jul 2023 20:34:36 +0200 Subject: [PATCH 22/67] Error instead of deprecation warning --- src/Ferrite.jl | 2 +- src/deprecations.jl | 24 ++++++------------------ src/exports.jl | 1 + 3 files changed, 8 insertions(+), 19 deletions(-) diff --git a/src/Ferrite.jl b/src/Ferrite.jl index 533f90f05e..cf6035a598 100644 --- a/src/Ferrite.jl +++ b/src/Ferrite.jl @@ -1,7 +1,6 @@ module Ferrite using Reexport @reexport using Tensors -@reexport using WriteVTK using LinearAlgebra using SparseArrays @@ -9,6 +8,7 @@ using StaticArrays using Base: @propagate_inbounds using NearestNeighbors using EnumX +import WriteVTK: paraview_collection include("exports.jl") diff --git a/src/deprecations.jl b/src/deprecations.jl index 6da12f9f68..0ebea07c6a 100644 --- a/src/deprecations.jl +++ b/src/deprecations.jl @@ -61,25 +61,13 @@ Base.@deprecate_binding Line3D Line Base.@deprecate_binding Quadrilateral3D Quadrilateral export Line2D, Line3D, Quadrilateral3D -import WriteVTK: vtk_grid, vtk_cell_data, vtk_point_data, vtk_save - -@deprecate vtk_grid(filename::String, grid::AbstractGrid; kwargs...) VTKFile(filename, grid; kwargs...) -@deprecate vtk_grid(filename::String, dh::DofHandler; kwargs...) VTKFile(filename, get_grid(dh); kwargs...) -struct _DummyGrid{D} <: AbstractGrid{D} - ncells::Int +function WriteVTK.vtk_grid(::String, ::Union{AbstractGrid,AbstractDofHandler}; kwargs...) + error(join(("The vtk interface has been updated in Ferrite v1.0.", + "See https://github.com/Ferrite-FEM/Ferrite.jl/pull/679.", + "Use Ferrite.VTKFile to open a vtk file, and the functions", + "write_solution, write_celldata, and write_projection to save data."), + "\n")) end -_DummyGrid(ncells=1) = _DummyGrid{1}(ncells) -getncells(g::_DummyGrid) = g.ncells - -@deprecate vtk_cell_data(vtk::VTKFile, args...) write_celldata(vtk, _DummyGrid(), args...) -@deprecate vtk_point_data(vtk::VTKFile, data::Vector, args...) write_nodedata(vtk, _DummyGrid(), data, args...) -@deprecate vtk_point_data(vtk::VTKFile, proj::L2Projector, args...) write_projection(vtk, proj, args...) -@deprecate vtk_point_data(vtk::VTKFile, ch::ConstraintHandler) write_dirichlet(vtk, ch) -@deprecate vtk_cellset(vtk::VTKFile, grid::AbstractGrid, args...) write_cellset(vtk, grid, args...) -@deprecate vtk_nodeset(vtk::VTKFile, grid::AbstractGrid, args...) write_nodeset(vtk, grid, args...) -@deprecate vtk_cell_data_colors(vtk::VTKFile, args...) write_cell_colors(vtk, _DummyGrid(vtk.vtk.Ncls), args...) -@deprecate vtk_save(vtk::VTKFile) close(vtk) -@deprecate vtk_point_data(vtk::VTKFile, dh::DofHandler, args...) write_solution(vtk, dh, args...) # Deprecation of auto-vectorized methods function add!(dh::DofHandler, name::Symbol, dim::Int) diff --git a/src/exports.jl b/src/exports.jl index 10dd063aa5..1f98f611c1 100644 --- a/src/exports.jl +++ b/src/exports.jl @@ -150,6 +150,7 @@ export write_solution, write_celldata, write_projection, + paraview_collection, # Reexport from WriteVTK.jl # L2 Projection project, From c5b21f75947c8bbb6926e778b9675ca99a5fe805 Mon Sep 17 00:00:00 2001 From: Knut Andreas Meyer Date: Wed, 19 Jul 2023 20:50:14 +0200 Subject: [PATCH 23/67] Don't reexport WriteVTK --- src/Export/VTK.jl | 6 +++--- src/Ferrite.jl | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Export/VTK.jl b/src/Export/VTK.jl index 3ab36cb229..ea2270d976 100644 --- a/src/Export/VTK.jl +++ b/src/Export/VTK.jl @@ -105,13 +105,13 @@ nodes_to_vtkorder(cell::QuadraticHexahedron) = [ ] function create_vtk_grid(filename::AbstractString, grid::Grid{dim,C,T}; kwargs...) where {dim,C,T} - cls = MeshCell[] + cls = WriteVTK.MeshCell[] for cell in getcells(grid) celltype = Ferrite.cell_to_vtkcell(typeof(cell)) - push!(cls, MeshCell(celltype, nodes_to_vtkorder(cell))) + push!(cls, WriteVTK.MeshCell(celltype, nodes_to_vtkorder(cell))) end coords = reshape(reinterpret(T, getnodes(grid)), (dim, getnnodes(grid))) - return vtk_grid(filename, coords, cls; kwargs...) + return WriteVTK.vtk_grid(filename, coords, cls; kwargs...) end function toparaview!(v, x::Vec{D}) where D diff --git a/src/Ferrite.jl b/src/Ferrite.jl index cf6035a598..137dae853e 100644 --- a/src/Ferrite.jl +++ b/src/Ferrite.jl @@ -8,7 +8,7 @@ using StaticArrays using Base: @propagate_inbounds using NearestNeighbors using EnumX -import WriteVTK: paraview_collection +import WriteVTK: WriteVTK, paraview_collection, VTKCellTypes include("exports.jl") From 6451632d8e717e2b6a1cf9827bca430576cf170b Mon Sep 17 00:00:00 2001 From: Knut Andreas Meyer Date: Wed, 19 Jul 2023 22:47:14 +0200 Subject: [PATCH 24/67] More export fixes --- docs/src/literate-tutorials/incompressible_elasticity.jl | 4 ++-- docs/src/topics/export.md | 1 + src/Ferrite.jl | 2 +- src/deprecations.jl | 3 +++ src/exports.jl | 5 +++-- 5 files changed, 10 insertions(+), 5 deletions(-) diff --git a/docs/src/literate-tutorials/incompressible_elasticity.jl b/docs/src/literate-tutorials/incompressible_elasticity.jl index d4137ee8a7..ee07e19937 100644 --- a/docs/src/literate-tutorials/incompressible_elasticity.jl +++ b/docs/src/literate-tutorials/incompressible_elasticity.jl @@ -275,9 +275,9 @@ function solve(ν, interpolation_u, interpolation_p) write_solution(vtk, dh, u) for i in 1:3, j in 1:3 σij = [x[i, j] for x in σ] - write_celldata(vtk, σij, "sigma_$(i)$(j)") + write_celldata(vtk, grid, σij, "sigma_$(i)$(j)") end - write_celldata(vtk, σvM, "sigma von Mises") + write_celldata(vtk, grid, σvM, "sigma von Mises") end return u end diff --git a/docs/src/topics/export.md b/docs/src/topics/export.md index 523106cd6a..ab4dd921a1 100644 --- a/docs/src/topics/export.md +++ b/docs/src/topics/export.md @@ -53,5 +53,6 @@ for i in 1:5 pvd[i] = vtk end end +vtk_save(pvd) ``` See [Transient heat equation](@ref tutorial-transient-heat-equation) for an example \ No newline at end of file diff --git a/src/Ferrite.jl b/src/Ferrite.jl index 137dae853e..8b2f019a25 100644 --- a/src/Ferrite.jl +++ b/src/Ferrite.jl @@ -8,7 +8,7 @@ using StaticArrays using Base: @propagate_inbounds using NearestNeighbors using EnumX -import WriteVTK: WriteVTK, paraview_collection, VTKCellTypes +import WriteVTK: WriteVTK, paraview_collection, vtk_save, VTKCellTypes include("exports.jl") diff --git a/src/deprecations.jl b/src/deprecations.jl index 0ebea07c6a..ea660a82f3 100644 --- a/src/deprecations.jl +++ b/src/deprecations.jl @@ -61,6 +61,9 @@ Base.@deprecate_binding Line3D Line Base.@deprecate_binding Quadrilateral3D Quadrilateral export Line2D, Line3D, Quadrilateral3D +import WriteVTK: vtk_grid +export vtk_grid # To give better error + function WriteVTK.vtk_grid(::String, ::Union{AbstractGrid,AbstractDofHandler}; kwargs...) error(join(("The vtk interface has been updated in Ferrite v1.0.", "See https://github.com/Ferrite-FEM/Ferrite.jl/pull/679.", diff --git a/src/exports.jl b/src/exports.jl index e40708a690..4509ec73d3 100644 --- a/src/exports.jl +++ b/src/exports.jl @@ -96,7 +96,6 @@ export # Grid coloring create_coloring, ColoringAlgorithm, - vtk_cell_data_colors, # Dofs DofHandler, @@ -153,7 +152,9 @@ export write_solution, write_celldata, write_projection, - paraview_collection, # Reexport from WriteVTK.jl + # Reexports from WriteVTK.jl for collections + paraview_collection, + vtk_save, # L2 Projection project, From e49e8acbdd82082329720f2b03a0a3371dcf162b Mon Sep 17 00:00:00 2001 From: Knut Andreas Meyer Date: Thu, 20 Jul 2023 09:42:16 +0200 Subject: [PATCH 25/67] Export VTKFile --- docs/src/literate-gallery/helmholtz.jl | 2 +- docs/src/literate-gallery/landau.jl | 2 +- .../quasi_incompressible_hyperelasticity.jl | 2 +- docs/src/literate-gallery/topology_optimization.jl | 4 ++-- docs/src/literate-howto/postprocessing.jl | 2 +- docs/src/literate-howto/threaded_assembly.jl | 2 +- .../literate-tutorials/computational_homogenization.jl | 2 +- docs/src/literate-tutorials/heat_equation.jl | 2 +- docs/src/literate-tutorials/hyperelasticity.jl | 2 +- docs/src/literate-tutorials/incompressible_elasticity.jl | 2 +- docs/src/literate-tutorials/linear_shell.jl | 2 +- docs/src/literate-tutorials/ns_vs_diffeq.jl | 2 +- docs/src/literate-tutorials/plasticity.jl | 2 +- docs/src/literate-tutorials/stokes-flow.jl | 2 +- docs/src/literate-tutorials/transient_heat_equation.jl | 4 ++-- docs/src/reference/export.md | 2 +- docs/src/topics/export.md | 6 +++--- src/Export/VTK.jl | 4 ++-- src/deprecations.jl | 2 +- src/exports.jl | 3 ++- test/test_constraints.jl | 2 +- test/test_grid_dofhandler_vtk.jl | 8 ++++---- test/test_l2_projection.jl | 2 +- test/test_mixeddofhandler.jl | 2 +- 24 files changed, 33 insertions(+), 32 deletions(-) diff --git a/docs/src/literate-gallery/helmholtz.jl b/docs/src/literate-gallery/helmholtz.jl index b702fa9928..98714d74ec 100644 --- a/docs/src/literate-gallery/helmholtz.jl +++ b/docs/src/literate-gallery/helmholtz.jl @@ -162,7 +162,7 @@ K, f = doassemble(cellvalues, facevalues, K, dh); apply!(K, f, dbcs) u = Symmetric(K) \ f; -vtk = Ferrite.VTKFile("helmholtz", grid) +vtk = VTKFile("helmholtz", grid) write_solution(vtk, dh, u) close(vtk) using Test #src diff --git a/docs/src/literate-gallery/landau.jl b/docs/src/literate-gallery/landau.jl index dd185b6f47..b2fd6937f0 100644 --- a/docs/src/literate-gallery/landau.jl +++ b/docs/src/literate-gallery/landau.jl @@ -114,7 +114,7 @@ end # utility to quickly save a model function save_landau(path, model, dofs=model.dofs) - Ferrite.VTKFile(path, model.dofhandler.grid) do vtk + VTKFile(path, model.dofhandler.grid) do vtk write_solution(vtk, model.dofhandler, dofs) end end diff --git a/docs/src/literate-gallery/quasi_incompressible_hyperelasticity.jl b/docs/src/literate-gallery/quasi_incompressible_hyperelasticity.jl index 59ae227e7a..d47f2f3638 100644 --- a/docs/src/literate-gallery/quasi_incompressible_hyperelasticity.jl +++ b/docs/src/literate-gallery/quasi_incompressible_hyperelasticity.jl @@ -334,7 +334,7 @@ function solve(interpolation_u, interpolation_p) end; ## Save the solution fields - Ferrite.VTKFile("hyperelasticity_incomp_mixed_$t.vtu", grid) do vtk + VTKFile("hyperelasticity_incomp_mixed_$t.vtu", grid) do vtk write_solution(vtk, dh, w) pvd[t] = vtk end diff --git a/docs/src/literate-gallery/topology_optimization.jl b/docs/src/literate-gallery/topology_optimization.jl index 5c880df7e2..3bac1900d4 100644 --- a/docs/src/literate-gallery/topology_optimization.jl +++ b/docs/src/literate-gallery/topology_optimization.jl @@ -492,7 +492,7 @@ function topopt(ra,ρ,n,filename; output=:false) i = @sprintf("%3.3i", it) filename_it = string(filename, "_", i) - Ferrite.VTKFile(filename_it, grid) do vtk + VTKFile(filename_it, grid) do vtk write_celldata(vtk, grid, χ, "density") end end @@ -500,7 +500,7 @@ function topopt(ra,ρ,n,filename; output=:false) ## export converged results if(!output) - Ferrite.VTKFile(filename, grid) do vtk + VTKFile(filename, grid) do vtk write_celldata(vtk, grid, χ, "density") end end diff --git a/docs/src/literate-howto/postprocessing.jl b/docs/src/literate-howto/postprocessing.jl index 6e9c960ea2..51bdbbe05f 100644 --- a/docs/src/literate-howto/postprocessing.jl +++ b/docs/src/literate-howto/postprocessing.jl @@ -87,7 +87,7 @@ 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*. -Ferrite.VTKFile("heat_equation_flux", grid) do vtk +VTKFile("heat_equation_flux", grid) do vtk write_projection(vtk, projector, q_projected, "q") end; diff --git a/docs/src/literate-howto/threaded_assembly.jl b/docs/src/literate-howto/threaded_assembly.jl index d860d81b9b..b2a972e3af 100644 --- a/docs/src/literate-howto/threaded_assembly.jl +++ b/docs/src/literate-howto/threaded_assembly.jl @@ -25,7 +25,7 @@ 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) - Ferrite.VTKFile("colored", grid) do vtk + 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 diff --git a/docs/src/literate-tutorials/computational_homogenization.jl b/docs/src/literate-tutorials/computational_homogenization.jl index f8b1a304e4..8c2c73d25c 100644 --- a/docs/src/literate-tutorials/computational_homogenization.jl +++ b/docs/src/literate-tutorials/computational_homogenization.jl @@ -518,7 +518,7 @@ round.(ev; digits=-8) uM = zeros(ndofs(dh)) -Ferrite.VTKFile("homogenization", grid) do vtk +VTKFile("homogenization", grid) do vtk for i in 1:3 ## Compute macroscopic solution apply_analytical!(uM, dh, :u, x -> εᴹ[i] ⋅ x) diff --git a/docs/src/literate-tutorials/heat_equation.jl b/docs/src/literate-tutorials/heat_equation.jl index da8847c756..887de39793 100644 --- a/docs/src/literate-tutorials/heat_equation.jl +++ b/docs/src/literate-tutorials/heat_equation.jl @@ -213,7 +213,7 @@ 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/). -Ferrite.VTKFile("heat_equation", grid) do vtk +VTKFile("heat_equation", grid) do vtk write_solution(vtk, dh, u) end diff --git a/docs/src/literate-tutorials/hyperelasticity.jl b/docs/src/literate-tutorials/hyperelasticity.jl index 2c82a8dc42..ad915aaa6e 100644 --- a/docs/src/literate-tutorials/hyperelasticity.jl +++ b/docs/src/literate-tutorials/hyperelasticity.jl @@ -397,7 +397,7 @@ function solve() ## Save the solution @timeit "export" begin - Ferrite.VTKFile("hyperelasticity", grid) do vtk + VTKFile("hyperelasticity", grid) do vtk write_solution(vtk, dh, u) end end diff --git a/docs/src/literate-tutorials/incompressible_elasticity.jl b/docs/src/literate-tutorials/incompressible_elasticity.jl index ee07e19937..a80546c759 100644 --- a/docs/src/literate-tutorials/incompressible_elasticity.jl +++ b/docs/src/literate-tutorials/incompressible_elasticity.jl @@ -271,7 +271,7 @@ function solve(ν, interpolation_u, interpolation_p) filename = "cook_" * (interpolation_u == Lagrange{RefTriangle, 1}()^2 ? "linear" : "quadratic") * "_linear" - Ferrite.VTKFile(filename, grid) do vtk + 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 σ] diff --git a/docs/src/literate-tutorials/linear_shell.jl b/docs/src/literate-tutorials/linear_shell.jl index e38b429cc9..e876f0c1cb 100644 --- a/docs/src/literate-tutorials/linear_shell.jl +++ b/docs/src/literate-tutorials/linear_shell.jl @@ -113,7 +113,7 @@ a = K\f # Output results. #+ -Ferrite.VTKFile("linear_shell", grid) do vtk +VTKFile("linear_shell", grid) do vtk write_solution(vtk, dh, a) end diff --git a/docs/src/literate-tutorials/ns_vs_diffeq.jl b/docs/src/literate-tutorials/ns_vs_diffeq.jl index 1e589e165d..d2ce50b628 100644 --- a/docs/src/literate-tutorials/ns_vs_diffeq.jl +++ b/docs/src/literate-tutorials/ns_vs_diffeq.jl @@ -440,7 +440,7 @@ for (u_uc,t) in integrator update!(ch, t) u = copy(u_uc) apply!(u, ch) - Ferrite.VTKFile("vortex-street-$t.vtu", grid) do vtk + VTKFile("vortex-street-$t.vtu", grid) do vtk write_solution(vtk, dh, u) pvd[t] = vtk end diff --git a/docs/src/literate-tutorials/plasticity.jl b/docs/src/literate-tutorials/plasticity.jl index 762fca5c62..3e9f1755a1 100644 --- a/docs/src/literate-tutorials/plasticity.jl +++ b/docs/src/literate-tutorials/plasticity.jl @@ -344,7 +344,7 @@ function solve() mises_values[el] /= length(cell_states) # average von Mises stress κ_values[el] /= length(cell_states) # average drag stress end - Ferrite.VTKFile("plasticity", grid) do vtk + VTKFile("plasticity", grid) do vtk write_solution(vtk, dh, u) # displacement field write_celldata(vtk, grid, mises_values, "von Mises [Pa]") write_celldata(vtk, grid, κ_values, "Drag stress [Pa]") diff --git a/docs/src/literate-tutorials/stokes-flow.jl b/docs/src/literate-tutorials/stokes-flow.jl index 88d4037290..2ee740a499 100644 --- a/docs/src/literate-tutorials/stokes-flow.jl +++ b/docs/src/literate-tutorials/stokes-flow.jl @@ -505,7 +505,7 @@ function main() u = K \ f apply!(u, ch) ## Export the solution - Ferrite.VTKFile("stokes-flow", grid) do vtk + VTKFile("stokes-flow", grid) do vtk write_solution(vtk, dh, u) end diff --git a/docs/src/literate-tutorials/transient_heat_equation.jl b/docs/src/literate-tutorials/transient_heat_equation.jl index 068ca1d928..ef945bd542 100644 --- a/docs/src/literate-tutorials/transient_heat_equation.jl +++ b/docs/src/literate-tutorials/transient_heat_equation.jl @@ -192,7 +192,7 @@ apply!(A, ch); # To store the solution, we initialize a `paraview_collection` (.pvd) file. pvd = paraview_collection("transient-heat.pvd"); t = 0 -Ferrite.VTKFile("transient-heat-$t", grid) do vtk +VTKFile("transient-heat-$t", grid) do vtk write_solution(vtk, dh, uₙ) pvd[t] = vtk end @@ -210,7 +210,7 @@ for t in Δt:Δt:T #Finally, we can solve the time step and save the solution afterwards. u = A \ b - Ferrite.VTKFile("transient-heat-$t", grid) do vtk + VTKFile("transient-heat-$t", grid) do vtk write_solution(vtk, dh, u) pvd[t] = vtk end diff --git a/docs/src/reference/export.md b/docs/src/reference/export.md index 161369f861..d6d2025c45 100644 --- a/docs/src/reference/export.md +++ b/docs/src/reference/export.md @@ -26,7 +26,7 @@ evaluate_at_grid_nodes ## VTK Export ```@docs -Ferrite.VTKFile +VTKFile write_solution write_projection write_celldata diff --git a/docs/src/topics/export.md b/docs/src/topics/export.md index ab4dd921a1..933b0a3d8b 100644 --- a/docs/src/topics/export.md +++ b/docs/src/topics/export.md @@ -17,7 +17,7 @@ the exporting. The following structure can be used to write various output to a vtk-file: ```@example export -Ferrite.VTKFile("my_solution", grid) do vtk +VTKFile("my_solution", grid) do vtk write_solution(vtk, dh, u) end ``` @@ -34,7 +34,7 @@ where `write_solution` is just one example of the following functions that can b Instead of using the `do`-block, it is also possible to do ```@example export -vtk = Ferrite.VTKFile("my_solution", grid) +vtk = VTKFile("my_solution", grid) write_solution(vtk, dh, u) # etc. close(vtk) @@ -48,7 +48,7 @@ To save time-dependent data, `WriteVTK.jl`'s, `paraview_collection` may be used pvd = paraview_collection("my_results.pvd"); for i in 1:5 # Do calculations to update u - Ferrite.VTKFile("my_results_$i", grid) do vtk + VTKFile("my_results_$i", grid) do vtk write_solution(vtk, dh, u) pvd[i] = vtk end diff --git a/src/Export/VTK.jl b/src/Export/VTK.jl index ea2270d976..e3ea9bd128 100644 --- a/src/Export/VTK.jl +++ b/src/Export/VTK.jl @@ -3,9 +3,9 @@ struct VTKFile{VTK<:WriteVTK.DatasetFile} end """ - Ferrite.VTKFile(filename::AbstractString, grid::AbstractGrid; kwargs...) + VTKFile(filename::AbstractString, grid::AbstractGrid; kwargs...) -Create a `Ferrite.VTKFile` that contains an unstructured VTK grid. +Create a `VTKFile` that contains an unstructured VTK grid. The keyword arguments are forwarded to `WriteVTK.vtk_grid`, see [Data Formatting Options](https://juliavtk.github.io/WriteVTK.jl/stable/grids/syntax/#Data-formatting-options) diff --git a/src/deprecations.jl b/src/deprecations.jl index ea660a82f3..d1a41e8424 100644 --- a/src/deprecations.jl +++ b/src/deprecations.jl @@ -67,7 +67,7 @@ export vtk_grid # To give better error function WriteVTK.vtk_grid(::String, ::Union{AbstractGrid,AbstractDofHandler}; kwargs...) error(join(("The vtk interface has been updated in Ferrite v1.0.", "See https://github.com/Ferrite-FEM/Ferrite.jl/pull/679.", - "Use Ferrite.VTKFile to open a vtk file, and the functions", + "Use VTKFile to open a vtk file, and the functions", "write_solution, write_celldata, and write_projection to save data."), "\n")) end diff --git a/src/exports.jl b/src/exports.jl index 4509ec73d3..457150d7ce 100644 --- a/src/exports.jl +++ b/src/exports.jl @@ -148,7 +148,8 @@ export assemble!, finish_assemble, -# export data (using e.g. Ferrite.VTKFile) +# exporting data + VTKFile, write_solution, write_celldata, write_projection, diff --git a/test/test_constraints.jl b/test/test_constraints.jl index 007324cca1..d24f5ccee7 100644 --- a/test/test_constraints.jl +++ b/test/test_constraints.jl @@ -1553,7 +1553,7 @@ end # testset @test norm(u_dbc) ≈ 3.8249286998373586 @test norm(u_p) ≈ 3.7828270430540893 end - # Ferrite.VTKFile("local_application_azero_$(azero)", grid) do vtk + # VTKFile("local_application_azero_$(azero)", grid) do vtk # write_solution(vtk, dh, u_dbc, "_dbc") # write_solution(vtk, dh, u_p, "_p") # end diff --git a/test/test_grid_dofhandler_vtk.jl b/test/test_grid_dofhandler_vtk.jl index ed6a1a4b43..6fbac97511 100644 --- a/test/test_grid_dofhandler_vtk.jl +++ b/test/test_grid_dofhandler_vtk.jl @@ -36,7 +36,7 @@ end addnodeset!(grid, "middle-nodes", x -> norm(x) < radius) gridfilename = "grid-$(repr(celltype))" - Ferrite.VTKFile(gridfilename, grid) do vtk + VTKFile(gridfilename, grid) do vtk Ferrite.write_cellset(vtk, grid, "cell-1") Ferrite.write_cellset(vtk, grid, "middle-cells") Ferrite.write_nodeset(vtk, grid, "middle-nodes") @@ -75,7 +75,7 @@ end apply!(u, ch) dofhandlerfilename = "dofhandler-$(repr(celltype))" - Ferrite.VTKFile(dofhandlerfilename, grid) do vtk + VTKFile(dofhandlerfilename, grid) do vtk Ferrite.write_dirichlet(vtk, ch) write_solution(vtk, dofhandler, u) end @@ -112,7 +112,7 @@ close(csio) vector_data = [Vec{3}(ntuple(i->i, 3)) for j=1:8] filename_3d = "test_vtk_3d" - Ferrite.VTKFile(filename_3d, grid) do vtk + VTKFile(filename_3d, grid) do vtk Ferrite.write_nodedata(vtk, grid, sym_tensor_data, "symmetric tensor") Ferrite.write_nodedata(vtk, grid, tensor_data, "tensor") Ferrite.write_nodedata(vtk, grid, vector_data, "vector") @@ -127,7 +127,7 @@ close(csio) vector_data = [Vec{2}(ntuple(i->i, 2)) for j=1:4] filename_2d = "test_vtk_2d" - Ferrite.VTKFile(filename_2d, grid) do vtk + VTKFile(filename_2d, grid) do vtk Ferrite.write_nodedata(vtk, grid, sym_tensor_data, "symmetric tensor") Ferrite.write_nodedata(vtk, grid, tensor_data, "tensor") Ferrite.write_nodedata(vtk, grid, tensor_data_1D, "tensor_1d") diff --git a/test/test_l2_projection.jl b/test/test_l2_projection.jl index 544a76784c..7c5ee58dd9 100644 --- a/test/test_l2_projection.jl +++ b/test/test_l2_projection.jl @@ -268,7 +268,7 @@ function test_export(;subset::Bool) mktempdir() do tmp fname = joinpath(tmp, "projected") - Ferrite.VTKFile(fname, grid) do vtk + VTKFile(fname, grid) do vtk write_projection(vtk, p, p_scalar, "p_scalar") write_projection(vtk, p, p_vec, "p_vec") write_projection(vtk, p, p_tens, "p_tens") diff --git a/test/test_mixeddofhandler.jl b/test/test_mixeddofhandler.jl index 622a71718d..b2c87619b8 100644 --- a/test/test_mixeddofhandler.jl +++ b/test/test_mixeddofhandler.jl @@ -355,7 +355,7 @@ function test_2_element_heat_eq() gridfilename = "mixed_grid" addcellset!(grid, "cell-1", [1,]) addcellset!(grid, "cell-2", [2,]) - Ferrite.VTKFile(gridfilename, grid) do vtk + VTKFile(gridfilename, grid) do vtk Ferrite.write_cellset(vtk, grid, "cell-1") Ferrite.write_cellset(vtk, grid, "cell-2") write_solution(vtk, dh, u) From 2398490bdf3058d21a0f82ed07447c2234d3d371 Mon Sep 17 00:00:00 2001 From: Knut Andreas Meyer Date: Sun, 23 Jul 2023 10:53:09 +0200 Subject: [PATCH 26/67] Tryout PVDFile --- src/Export/VTK.jl | 46 ++++++++++++++++++++++++++++++++++++++-------- src/exports.jl | 5 ++--- 2 files changed, 40 insertions(+), 11 deletions(-) diff --git a/src/Export/VTK.jl b/src/Export/VTK.jl index e3ea9bd128..7734c3f045 100644 --- a/src/Export/VTK.jl +++ b/src/Export/VTK.jl @@ -1,6 +1,3 @@ -struct VTKFile{VTK<:WriteVTK.DatasetFile} - vtk::VTK -end """ VTKFile(filename::AbstractString, grid::AbstractGrid; kwargs...) @@ -27,6 +24,9 @@ VTKFile(filename, grid) do vtk write_celldata(vtk, grid, celldata) end """ +struct VTKFile{VTK<:WriteVTK.DatasetFile} + vtk::VTK +end function VTKFile(filename::String, grid::AbstractGrid; kwargs...) vtk = create_vtk_grid(filename, grid; kwargs...) return VTKFile(vtk) @@ -49,12 +49,42 @@ function Base.show(io::IO, ::MIME"text/plain", vtk::VTKFile) print(io, "VTKFile for the $open_str file \"$(filename)\".") end -# Support ParaviewCollection -function Base.setindex!(pvd::WriteVTK.CollectionFile, vtk::VTKFile, time::Real) - WriteVTK.collection_add_timestep(pvd, vtk, time) +""" + PVDFile(name::String, grid::AbstractGrid) + +Create a paraview collection file that can be used to +save multiple vtk file. Example, +``` +pvd = PVDFile("test", grid) +for t in range(0, 2, 4) + # Solve the timestep to find u and σeff + Ferrite.addstep!(pvd, t) do io + write_solution(io, dh, u) + write_celldata(io, grid, σeff, "Effective stress") + end end -function WriteVTK.collection_add_timestep(pvd::WriteVTK.CollectionFile, vtk::VTKFile, time::Real) - WriteVTK.collection_add_timestep(pvd, vtk.vtk, time) +``` +""" +mutable struct PVDFile{P<:WriteVTK.CollectionFile,G<:AbstractGrid} + pvd::P + grid::G + name::String + step::Int +end +function PVDFile(name::String, grid::AbstractGrid) + pvd = WriteVTK.paraview_collection(name) + return PVDFile(pvd, grid, name, 0) +end + +function addstep!(f::Function, pvd::PVDFile, t, grid=pvd.grid) + pvd.step += 1 + vtk = VTKFile(string(pvd.name, "_", pvd.step), grid) + try + f(vtk) + pvd.pvd[t] = vtk.vtk # Add to collection + finally + close(vtk) + end end cell_to_vtkcell(::Type{Line}) = VTKCellTypes.VTK_LINE diff --git a/src/exports.jl b/src/exports.jl index 457150d7ce..59c4455943 100644 --- a/src/exports.jl +++ b/src/exports.jl @@ -153,9 +153,8 @@ export write_solution, write_celldata, write_projection, - # Reexports from WriteVTK.jl for collections - paraview_collection, - vtk_save, + PVDFile, + addstep!, # L2 Projection project, From 91b5e206ba685f1647334913c48421008785f0ae Mon Sep 17 00:00:00 2001 From: Knut Andreas Meyer Date: Sun, 23 Jul 2023 11:01:09 +0200 Subject: [PATCH 27/67] Add close of pvd --- src/Export/VTK.jl | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/Export/VTK.jl b/src/Export/VTK.jl index 7734c3f045..e6f6f3a28e 100644 --- a/src/Export/VTK.jl +++ b/src/Export/VTK.jl @@ -63,6 +63,7 @@ for t in range(0, 2, 4) write_celldata(io, grid, σeff, "Effective stress") end end +close(pvd) ``` """ mutable struct PVDFile{P<:WriteVTK.CollectionFile,G<:AbstractGrid} @@ -75,6 +76,7 @@ function PVDFile(name::String, grid::AbstractGrid) pvd = WriteVTK.paraview_collection(name) return PVDFile(pvd, grid, name, 0) end +Base.close(pvd::PVDFile) = WriteVTK.vtk_save(pvd.pvd) function addstep!(f::Function, pvd::PVDFile, t, grid=pvd.grid) pvd.step += 1 From dda42e3dc2ee3d74a86a883b43b384c1fc4ded9b Mon Sep 17 00:00:00 2001 From: Knut Andreas Meyer Date: Sun, 23 Jul 2023 11:08:25 +0200 Subject: [PATCH 28/67] Remove qualified name --- src/Export/VTK.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Export/VTK.jl b/src/Export/VTK.jl index e6f6f3a28e..8551400dcc 100644 --- a/src/Export/VTK.jl +++ b/src/Export/VTK.jl @@ -58,7 +58,7 @@ save multiple vtk file. Example, pvd = PVDFile("test", grid) for t in range(0, 2, 4) # Solve the timestep to find u and σeff - Ferrite.addstep!(pvd, t) do io + addstep!(pvd, t) do io write_solution(io, dh, u) write_celldata(io, grid, σeff, "Effective stress") end From 1cb8f997e526243bb75abbeabd7dd55b4afc8351 Mon Sep 17 00:00:00 2001 From: Knut Andreas Meyer Date: Sat, 16 Sep 2023 00:36:59 +0200 Subject: [PATCH 29/67] Replace VTK.paraview_collection with ParaviewCollection --- .../quasi_incompressible_hyperelasticity.jl | 9 ++++---- docs/src/literate-tutorials/ns_vs_diffeq.jl | 9 ++++---- .../transient_heat_equation.jl | 16 ++++++------- docs/src/topics/export.md | 13 +++++------ src/Export/VTK.jl | 23 ++++++++----------- src/exports.jl | 4 ++-- 6 files changed, 33 insertions(+), 41 deletions(-) diff --git a/docs/src/literate-gallery/quasi_incompressible_hyperelasticity.jl b/docs/src/literate-gallery/quasi_incompressible_hyperelasticity.jl index d47f2f3638..f5613452b3 100644 --- a/docs/src/literate-gallery/quasi_incompressible_hyperelasticity.jl +++ b/docs/src/literate-gallery/quasi_incompressible_hyperelasticity.jl @@ -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 = ParaviewCollection("hyperelasticity_incomp_mixed.pvd", grid); for t ∈ 0.0:Δt:Tf ## Perform Newton iterations Ferrite.update!(dbc, t) @@ -334,12 +334,11 @@ function solve(interpolation_u, interpolation_p) end; ## Save the solution fields - VTKFile("hyperelasticity_incomp_mixed_$t.vtu", grid) do vtk - write_solution(vtk, dh, w) - pvd[t] = vtk + 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; diff --git a/docs/src/literate-tutorials/ns_vs_diffeq.jl b/docs/src/literate-tutorials/ns_vs_diffeq.jl index dc24ee7517..8141630a0f 100644 --- a/docs/src/literate-tutorials/ns_vs_diffeq.jl +++ b/docs/src/literate-tutorials/ns_vs_diffeq.jl @@ -431,7 +431,7 @@ integrator = init( progress=true, progress_steps=1, saveat=Δt_save); -pvd = paraview_collection("vortex-street.pvd"); +pvd = ParaviewCollection("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, @@ -440,12 +440,11 @@ for (u_uc,t) in integrator update!(ch, t) u = copy(u_uc) apply!(u, ch) - VTKFile("vortex-street-$t.vtu", grid) do vtk - write_solution(vtk, dh, u) - 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 diff --git a/docs/src/literate-tutorials/transient_heat_equation.jl b/docs/src/literate-tutorials/transient_heat_equation.jl index ef945bd542..c5a89e4b49 100644 --- a/docs/src/literate-tutorials/transient_heat_equation.jl +++ b/docs/src/literate-tutorials/transient_heat_equation.jl @@ -189,12 +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 `ParaviewCollection` (.pvd) file. +pvd = ParaviewCollection("transient-heat", grid); t = 0 -VTKFile("transient-heat-$t", grid) do vtk - write_solution(vtk, dh, uₙ) - 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. @@ -210,15 +209,14 @@ for t in Δt:Δt:T #Finally, we can solve the time step and save the solution afterwards. u = A \ b - VTKFile("transient-heat-$t", grid) do vtk - write_solution(vtk, dh, u) - 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 # diff --git a/docs/src/topics/export.md b/docs/src/topics/export.md index 933b0a3d8b..ede937ed0f 100644 --- a/docs/src/topics/export.md +++ b/docs/src/topics/export.md @@ -1,7 +1,7 @@ ```@setup export using Ferrite grid = generate_grid(Triangle, (2, 2)) -dh = DofHandler(grid); add!(dh, :u, Lagrange{2,RefTetrahedron,1}()); close!(dh) +dh = DofHandler(grid); add!(dh, :u, Lagrange{RefTriangle,1}()); close!(dh) u = rand(ndofs(dh)); σ = rand(getncells(grid)) ``` @@ -42,17 +42,16 @@ close(vtk) The data written by `write_solution`, `write_celldata`, `Ferrite.write_nodedata`, and `write_projection` may be either scalar (`Vector{<:Number}`) or tensor (`Vector{<:AbstractTensor}`) data. -To save time-dependent data, `WriteVTK.jl`'s, `paraview_collection` may be used +`ParaviewCollection` may be used to save time-dependent data ```@example pvdexport -pvd = paraview_collection("my_results.pvd"); -for i in 1:5 +pvd = ParaviewCollection("my_results", grid) +for t in range(0, 1, 5) # Do calculations to update u - VTKFile("my_results_$i", grid) do vtk + addstep!(pvd, t) do vtk write_solution(vtk, dh, u) - pvd[i] = vtk end end -vtk_save(pvd) +close(pvd) ``` See [Transient heat equation](@ref tutorial-transient-heat-equation) for an example \ No newline at end of file diff --git a/src/Export/VTK.jl b/src/Export/VTK.jl index 0d8baa8c24..39117e8109 100644 --- a/src/Export/VTK.jl +++ b/src/Export/VTK.jl @@ -50,15 +50,15 @@ function Base.show(io::IO, ::MIME"text/plain", vtk::VTKFile) end """ - PVDFile(name::String, grid::AbstractGrid) + ParaviewCollection(name::String, grid::AbstractGrid) -Create a paraview collection file that can be used to +Create a paraview collection file (.pvd) that can be used to save multiple vtk file. Example, ``` -pvd = PVDFile("test", grid) +pvd = ParaviewCollection("test", grid) for t in range(0, 2, 4) # Solve the timestep to find u and σeff - addstep!(pvd, t) do io + addstep!(pvd, t) do io # io::VTKFile write_solution(io, dh, u) write_celldata(io, grid, σeff, "Effective stress") end @@ -66,26 +66,23 @@ end close(pvd) ``` """ -mutable struct PVDFile{P<:WriteVTK.CollectionFile,G<:AbstractGrid} +mutable struct ParaviewCollection{P<:WriteVTK.CollectionFile,G<:AbstractGrid} pvd::P grid::G name::String step::Int end -function PVDFile(name::String, grid::AbstractGrid) +function ParaviewCollection(name::String, grid::AbstractGrid) pvd = WriteVTK.paraview_collection(name) - return PVDFile(pvd, grid, name, 0) + return ParaviewCollection(pvd, grid, name, 0) end -Base.close(pvd::PVDFile) = WriteVTK.vtk_save(pvd.pvd) +Base.close(pvd::ParaviewCollection) = WriteVTK.vtk_save(pvd.pvd) -function addstep!(f::Function, pvd::PVDFile, t, grid=pvd.grid) +function addstep!(f::Function, pvd::ParaviewCollection, t, grid=pvd.grid) pvd.step += 1 - vtk = VTKFile(string(pvd.name, "_", pvd.step), grid) - try + VTKFile(string(pvd.name, "_", pvd.step), grid) do vtk f(vtk) pvd.pvd[t] = vtk.vtk # Add to collection - finally - close(vtk) end end diff --git a/src/exports.jl b/src/exports.jl index da9dc91c8c..a9303e42ee 100644 --- a/src/exports.jl +++ b/src/exports.jl @@ -155,8 +155,8 @@ export write_solution, write_celldata, write_projection, - PVDFile, - addstep!, + ParaviewCollection, + addstep!, # L2 Projection project, From 8a4c084520e35ed3d504c7a19e4d7699e8dbcf09 Mon Sep 17 00:00:00 2001 From: Knut Andreas Meyer Date: Sat, 16 Sep 2023 11:56:30 +0200 Subject: [PATCH 30/67] dev Ferrite from docs env --- docs/Manifest.toml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/Manifest.toml b/docs/Manifest.toml index 88a7d913c1..f720bdc345 100644 --- a/docs/Manifest.toml +++ b/docs/Manifest.toml @@ -405,8 +405,8 @@ uuid = "29a986be-02c6-4525-aec4-84b980013641" version = "2.0.0" [[deps.Ferrite]] -deps = ["EnumX", "LinearAlgebra", "NearestNeighbors", "Preferences", "Reexport", "SparseArrays", "Tensors", "WriteVTK"] -git-tree-sha1 = "a31b9d4dd58e00686e5da175dab11667af3108b6" +deps = ["EnumX", "LinearAlgebra", "NearestNeighbors", "Preferences", "Reexport", "SparseArrays", "StaticArrays", "Tensors", "WriteVTK"] +path = ".." uuid = "c061ca5d-56c9-439f-9c0e-210fe06d3992" version = "0.3.14" From 5beaf6c4f92aaf5adb81bc36057d86beab2bfca4 Mon Sep 17 00:00:00 2001 From: Knut Andreas Meyer Date: Sat, 16 Sep 2023 12:27:37 +0200 Subject: [PATCH 31/67] Doc improvements --- docs/src/reference/export.md | 3 ++- docs/src/topics/export.md | 14 ++++++++------ 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/docs/src/reference/export.md b/docs/src/reference/export.md index d6d2025c45..51a3c35c06 100644 --- a/docs/src/reference/export.md +++ b/docs/src/reference/export.md @@ -24,9 +24,10 @@ evaluate_at_grid_nodes ``` ## VTK Export - ```@docs VTKFile +ParaviewCollection +addstep! write_solution write_projection write_celldata diff --git a/docs/src/topics/export.md b/docs/src/topics/export.md index ede937ed0f..6737bd91b7 100644 --- a/docs/src/topics/export.md +++ b/docs/src/topics/export.md @@ -10,16 +10,15 @@ u = rand(ndofs(dh)); σ = rand(getncells(grid)) 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`](https://www.paraview.org/). -To write VTK-files, Ferrite comes with a filestream with a +To write VTK-files, Ferrite comes with an export interface with a [`WriteVTK.jl`](https://github.com/jipolanco/WriteVTK.jl) backend to simplify the exporting. The following structure can be used to write various output to a vtk-file: - ```@example export VTKFile("my_solution", grid) do vtk write_solution(vtk, dh, u) -end +end; ``` where `write_solution` is just one example of the following functions that can be used @@ -37,12 +36,15 @@ Instead of using the `do`-block, it is also possible to do vtk = VTKFile("my_solution", grid) write_solution(vtk, dh, u) # etc. -close(vtk) +close(vtk); ``` The data written by `write_solution`, `write_celldata`, `Ferrite.write_nodedata`, and `write_projection` may be either scalar (`Vector{<:Number}`) or tensor (`Vector{<:AbstractTensor}`) data. -`ParaviewCollection` may be used to save time-dependent data +For simulations with multiple time steps, typically one `vtk` file is written +for each time step. In order to connect the actual time with each of these files, +a `ParaviewCollection` can be used, which will write one paraview collection (.pvd) +file and one `vtk` for each time step. ```@example pvdexport pvd = ParaviewCollection("my_results", grid) @@ -52,6 +54,6 @@ for t in range(0, 1, 5) write_solution(vtk, dh, u) end end -close(pvd) +close(pvd); ``` See [Transient heat equation](@ref tutorial-transient-heat-equation) for an example \ No newline at end of file From 6487031cd26325a409dd36fc3cfb1bba6a9f6ef9 Mon Sep 17 00:00:00 2001 From: Knut Andreas Meyer Date: Sat, 16 Sep 2023 13:10:34 +0200 Subject: [PATCH 32/67] Document addstep --- src/Export/VTK.jl | 28 +++++++++++++++++++++++----- 1 file changed, 23 insertions(+), 5 deletions(-) diff --git a/src/Export/VTK.jl b/src/Export/VTK.jl index 39117e8109..30ef6090fc 100644 --- a/src/Export/VTK.jl +++ b/src/Export/VTK.jl @@ -1,6 +1,7 @@ """ VTKFile(filename::AbstractString, grid::AbstractGrid; kwargs...) + VTKFile(filename::AbstractString, dh::DofHandler; kwargs...) Create a `VTKFile` that contains an unstructured VTK grid. The keyword arguments are forwarded to `WriteVTK.vtk_grid`, see @@ -27,6 +28,9 @@ end struct VTKFile{VTK<:WriteVTK.DatasetFile} vtk::VTK end +function VTKFile(filename::String, dh::DofHandler; kwargs...) + return VTKFile(filename, get_grid(dh); kwargs...) +end function VTKFile(filename::String, grid::AbstractGrid; kwargs...) vtk = create_vtk_grid(filename, grid; kwargs...) return VTKFile(vtk) @@ -51,6 +55,7 @@ end """ ParaviewCollection(name::String, grid::AbstractGrid) + ParaviewCollection(name::String, dh::DofHandler) Create a paraview collection file (.pvd) that can be used to save multiple vtk file. Example, @@ -66,19 +71,32 @@ end close(pvd) ``` """ -mutable struct ParaviewCollection{P<:WriteVTK.CollectionFile,G<:AbstractGrid} +mutable struct ParaviewCollection{P<:WriteVTK.CollectionFile,G_DH} pvd::P - grid::G + grid_or_dh::G_DH name::String step::Int end -function ParaviewCollection(name::String, grid::AbstractGrid) +function ParaviewCollection(name::String, grid_or_dh::Union{AbstractGrid,AbstractDofHandler}) pvd = WriteVTK.paraview_collection(name) - return ParaviewCollection(pvd, grid, name, 0) + return ParaviewCollection(pvd, grid_or_dh, name, 0) end Base.close(pvd::ParaviewCollection) = WriteVTK.vtk_save(pvd.pvd) -function addstep!(f::Function, pvd::ParaviewCollection, t, grid=pvd.grid) +""" + addstep!(f::Function, pvd::ParaviewCollection, t::Real, [grid_or_dh]) + +Add a step at time `t` by writing a `VTKFile` to `pvd`. +If required, a new grid can be used by supplying the grid or dofhandler as the last argument. +Should be used in a do-block: +```julia +addstep!(pvd, t) do vtk + write_solution(vtk, dh, u) +end +``` +See also [`ParaviewCollection`](@ref). +""" +function addstep!(f::Function, pvd::ParaviewCollection, t, grid=pvd.grid_or_dh) pvd.step += 1 VTKFile(string(pvd.name, "_", pvd.step), grid) do vtk f(vtk) From dbc1ac3cff63aae7d1c745e36719212b87e03d53 Mon Sep 17 00:00:00 2001 From: Knut Andreas Meyer Date: Sat, 16 Sep 2023 13:21:26 +0200 Subject: [PATCH 33/67] Allow dofhandler input as alternative to grid --- docs/src/literate-gallery/helmholtz.jl | 2 +- docs/src/literate-gallery/landau.jl | 2 +- docs/src/literate-tutorials/computational_homogenization.jl | 2 +- docs/src/literate-tutorials/heat_equation.jl | 2 +- docs/src/literate-tutorials/hyperelasticity.jl | 2 +- docs/src/literate-tutorials/linear_shell.jl | 2 +- docs/src/literate-tutorials/plasticity.jl | 2 +- 7 files changed, 7 insertions(+), 7 deletions(-) diff --git a/docs/src/literate-gallery/helmholtz.jl b/docs/src/literate-gallery/helmholtz.jl index 1d5a779f96..c2b830b2c9 100644 --- a/docs/src/literate-gallery/helmholtz.jl +++ b/docs/src/literate-gallery/helmholtz.jl @@ -162,7 +162,7 @@ K, f = doassemble(cellvalues, facevalues, K, dh); apply!(K, f, dbcs) u = Symmetric(K) \ f; -vtk = VTKFile("helmholtz", grid) +vtk = VTKFile("helmholtz", dh) write_solution(vtk, dh, u) close(vtk) using Test #src diff --git a/docs/src/literate-gallery/landau.jl b/docs/src/literate-gallery/landau.jl index b2fd6937f0..68ba97af4c 100644 --- a/docs/src/literate-gallery/landau.jl +++ b/docs/src/literate-gallery/landau.jl @@ -114,7 +114,7 @@ end # utility to quickly save a model function save_landau(path, model, dofs=model.dofs) - VTKFile(path, model.dofhandler.grid) do vtk + VTKFile(path, model.dofhandler) do vtk write_solution(vtk, model.dofhandler, dofs) end end diff --git a/docs/src/literate-tutorials/computational_homogenization.jl b/docs/src/literate-tutorials/computational_homogenization.jl index 8c2c73d25c..4eff201973 100644 --- a/docs/src/literate-tutorials/computational_homogenization.jl +++ b/docs/src/literate-tutorials/computational_homogenization.jl @@ -518,7 +518,7 @@ round.(ev; digits=-8) uM = zeros(ndofs(dh)) -VTKFile("homogenization", grid) do vtk +VTKFile("homogenization", dh) do vtk for i in 1:3 ## Compute macroscopic solution apply_analytical!(uM, dh, :u, x -> εᴹ[i] ⋅ x) diff --git a/docs/src/literate-tutorials/heat_equation.jl b/docs/src/literate-tutorials/heat_equation.jl index 887de39793..1bcfbec707 100644 --- a/docs/src/literate-tutorials/heat_equation.jl +++ b/docs/src/literate-tutorials/heat_equation.jl @@ -213,7 +213,7 @@ 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/). -VTKFile("heat_equation", grid) do vtk +VTKFile("heat_equation", dh) do vtk write_solution(vtk, dh, u) end diff --git a/docs/src/literate-tutorials/hyperelasticity.jl b/docs/src/literate-tutorials/hyperelasticity.jl index ad915aaa6e..1a65ddb598 100644 --- a/docs/src/literate-tutorials/hyperelasticity.jl +++ b/docs/src/literate-tutorials/hyperelasticity.jl @@ -397,7 +397,7 @@ function solve() ## Save the solution @timeit "export" begin - VTKFile("hyperelasticity", grid) do vtk + VTKFile("hyperelasticity", dh) do vtk write_solution(vtk, dh, u) end end diff --git a/docs/src/literate-tutorials/linear_shell.jl b/docs/src/literate-tutorials/linear_shell.jl index 375ec33048..1f5589ed72 100644 --- a/docs/src/literate-tutorials/linear_shell.jl +++ b/docs/src/literate-tutorials/linear_shell.jl @@ -113,7 +113,7 @@ a = K\f # Output results. #+ -VTKFile("linear_shell", grid) do vtk +VTKFile("linear_shell", dh) do vtk write_solution(vtk, dh, a) end diff --git a/docs/src/literate-tutorials/plasticity.jl b/docs/src/literate-tutorials/plasticity.jl index 3e9f1755a1..53a1d5d289 100644 --- a/docs/src/literate-tutorials/plasticity.jl +++ b/docs/src/literate-tutorials/plasticity.jl @@ -344,7 +344,7 @@ function solve() mises_values[el] /= length(cell_states) # average von Mises stress κ_values[el] /= length(cell_states) # average drag stress end - VTKFile("plasticity", grid) do vtk + VTKFile("plasticity", dh) do vtk write_solution(vtk, dh, u) # displacement field write_celldata(vtk, grid, mises_values, "von Mises [Pa]") write_celldata(vtk, grid, κ_values, "Drag stress [Pa]") From cd1e303db89613a5717520488ddcff1edb9a0c1f Mon Sep 17 00:00:00 2001 From: Knut Andreas Meyer Date: Sat, 16 Sep 2023 13:43:14 +0200 Subject: [PATCH 34/67] Remove unused grid input in write_celldata and write_nodedata --- .../quasi_incompressible_hyperelasticity.jl | 2 +- .../literate-gallery/topology_optimization.jl | 4 ++-- .../incompressible_elasticity.jl | 4 ++-- docs/src/literate-tutorials/plasticity.jl | 4 ++-- src/Export/VTK.jl | 22 +++++++++---------- test/test_grid_dofhandler_vtk.jl | 14 ++++++------ 6 files changed, 25 insertions(+), 25 deletions(-) diff --git a/docs/src/literate-gallery/quasi_incompressible_hyperelasticity.jl b/docs/src/literate-gallery/quasi_incompressible_hyperelasticity.jl index f5613452b3..53cf1b81cc 100644 --- a/docs/src/literate-gallery/quasi_incompressible_hyperelasticity.jl +++ b/docs/src/literate-gallery/quasi_incompressible_hyperelasticity.jl @@ -305,7 +305,7 @@ function solve(interpolation_u, interpolation_p) Δt = 0.1; NEWTON_TOL = 1e-8 - pvd = ParaviewCollection("hyperelasticity_incomp_mixed.pvd", grid); + pvd = ParaviewCollection("hyperelasticity_incomp_mixed", grid); for t ∈ 0.0:Δt:Tf ## Perform Newton iterations Ferrite.update!(dbc, t) diff --git a/docs/src/literate-gallery/topology_optimization.jl b/docs/src/literate-gallery/topology_optimization.jl index bf297c8df2..50c4ba6628 100644 --- a/docs/src/literate-gallery/topology_optimization.jl +++ b/docs/src/literate-gallery/topology_optimization.jl @@ -493,7 +493,7 @@ function topopt(ra,ρ,n,filename; output=:false) filename_it = string(filename, "_", i) VTKFile(filename_it, grid) do vtk - write_celldata(vtk, grid, χ, "density") + write_celldata(vtk, χ, "density") end end end @@ -501,7 +501,7 @@ function topopt(ra,ρ,n,filename; output=:false) ## export converged results if(!output) VTKFile(filename, grid) do vtk - write_celldata(vtk, grid, χ, "density") + write_celldata(vtk, χ, "density") end end @printf "Rel. stiffness: %.4f \n" compliance^(-1)/compliance_0^(-1) diff --git a/docs/src/literate-tutorials/incompressible_elasticity.jl b/docs/src/literate-tutorials/incompressible_elasticity.jl index a80546c759..d7285e7489 100644 --- a/docs/src/literate-tutorials/incompressible_elasticity.jl +++ b/docs/src/literate-tutorials/incompressible_elasticity.jl @@ -275,9 +275,9 @@ function solve(ν, interpolation_u, interpolation_p) write_solution(vtk, dh, u) for i in 1:3, j in 1:3 σij = [x[i, j] for x in σ] - write_celldata(vtk, grid, σij, "sigma_$(i)$(j)") + write_celldata(vtk, σij, "sigma_$(i)$(j)") end - write_celldata(vtk, grid, σvM, "sigma von Mises") + write_celldata(vtk, σvM, "sigma von Mises") end return u end diff --git a/docs/src/literate-tutorials/plasticity.jl b/docs/src/literate-tutorials/plasticity.jl index 53a1d5d289..3732ea78d2 100644 --- a/docs/src/literate-tutorials/plasticity.jl +++ b/docs/src/literate-tutorials/plasticity.jl @@ -346,8 +346,8 @@ function solve() end VTKFile("plasticity", dh) do vtk write_solution(vtk, dh, u) # displacement field - write_celldata(vtk, grid, mises_values, "von Mises [Pa]") - write_celldata(vtk, grid, κ_values, "Drag stress [Pa]") + write_celldata(vtk, mises_values, "von Mises [Pa]") + write_celldata(vtk, κ_values, "Drag stress [Pa]") end return u_max, traction_magnitude diff --git a/src/Export/VTK.jl b/src/Export/VTK.jl index 30ef6090fc..0563f15fe8 100644 --- a/src/Export/VTK.jl +++ b/src/Export/VTK.jl @@ -22,7 +22,7 @@ to the file handler. Using the supported `do`-block does this automatically: ```julia VTKFile(filename, grid) do vtk write_solution(vtk, dh, u) - write_celldata(vtk, grid, celldata) + write_celldata(vtk, celldata) end """ struct VTKFile{VTK<:WriteVTK.DatasetFile} @@ -65,7 +65,7 @@ for t in range(0, 2, 4) # Solve the timestep to find u and σeff addstep!(pvd, t) do io # io::VTKFile write_solution(io, dh, u) - write_celldata(io, grid, σeff, "Effective stress") + write_celldata(io, σeff, "Effective stress") end end close(pvd) @@ -238,17 +238,17 @@ function write_projection(vtk::VTKFile, proj::L2Projector, vals, name) end """ - write_celldata(vtk::VTKFile, grid::AbstractGrid, celldata::AbstractVector, name::String) + write_celldata(vtk::VTKFile, celldata::AbstractVector, name::String) Write the `celldata` that is ordered by the cells in the grid to the vtk file. """ -function write_celldata(vtk::VTKFile, ::AbstractGrid, celldata, name) +function write_celldata(vtk::VTKFile, celldata, name) WriteVTK.vtk_cell_data(vtk.vtk, celldata, name) end """ - write_nodedata(vtk::VTKFile, grid::AbstractGrid, nodedata::Vector{Real}, name) - write_nodedata(vtk::VTKFile, grid::AbstractGrid, nodedata::Vector{<:AbstractTensor}, name) + write_nodedata(vtk::VTKFile, nodedata::Vector{Real}, name) + write_nodedata(vtk::VTKFile, nodedata::Vector{<:AbstractTensor}, name) Write the `nodedata` that is ordered by the nodes in the grid to the vtk stream. @@ -258,7 +258,7 @@ Two-dimensional vectors are padded with zeros. When `nodedata` contains second order tensors, the index order, `[11, 22, 33, 23, 13, 12, 32, 31, 21]`, follows the default Voigt order in Tensors.jl. """ -function write_nodedata(vtk::VTKFile, ::AbstractGrid, nodedata, name) +function write_nodedata(vtk::VTKFile, nodedata, name) _vtk_write_nodedata(vtk.vtk, nodedata, name) end @@ -271,7 +271,7 @@ Write nodal values of 1 for nodes in `nodeset`, and 0 otherwise function write_nodeset(vtk, grid::AbstractGrid, nodeset::String) z = zeros(getnnodes(grid)) z[collect(getnodeset(grid, nodeset))] .= 1.0 - write_nodedata(vtk, grid, z, nodeset) + write_nodedata(vtk, z, nodeset) return vtk end @@ -289,7 +289,7 @@ function write_cellset(vtk, grid::AbstractGrid, cellsets=keys(getcellsets(getgri for cellset in cellsets fill!(z, 0) z[collect(getcellset(grid, cellset))] .= 1.0 - write_celldata(vtk, grid, z, cellset) + write_celldata(vtk, z, cellset) end return vtk end @@ -330,7 +330,7 @@ function write_dirichlet(vtk, ch::ConstraintHandler) end end end - write_nodedata(vtk, get_grid(ch.dh), data, string(field, "_bc")) + write_nodedata(vtk, data, string(field, "_bc")) end return vtk end @@ -349,5 +349,5 @@ function write_cell_colors(vtk, grid::AbstractGrid, cell_colors::AbstractVector{ color_vector[cell] = i end end - write_celldata(vtk, grid, color_vector, name) + write_celldata(vtk, color_vector, name) end diff --git a/test/test_grid_dofhandler_vtk.jl b/test/test_grid_dofhandler_vtk.jl index f2907245b0..52c5912d04 100644 --- a/test/test_grid_dofhandler_vtk.jl +++ b/test/test_grid_dofhandler_vtk.jl @@ -115,9 +115,9 @@ close(csio) filename_3d = "test_vtk_3d" VTKFile(filename_3d, grid) do vtk - Ferrite.write_nodedata(vtk, grid, sym_tensor_data, "symmetric tensor") - Ferrite.write_nodedata(vtk, grid, tensor_data, "tensor") - Ferrite.write_nodedata(vtk, grid, vector_data, "vector") + Ferrite.write_nodedata(vtk, sym_tensor_data, "symmetric tensor") + Ferrite.write_nodedata(vtk, tensor_data, "tensor") + Ferrite.write_nodedata(vtk, vector_data, "vector") end # 2D grid @@ -130,10 +130,10 @@ close(csio) filename_2d = "test_vtk_2d" VTKFile(filename_2d, grid) do vtk - Ferrite.write_nodedata(vtk, grid, sym_tensor_data, "symmetric tensor") - Ferrite.write_nodedata(vtk, grid, tensor_data, "tensor") - Ferrite.write_nodedata(vtk, grid, tensor_data_1D, "tensor_1d") - Ferrite.write_nodedata(vtk, grid, vector_data, "vector") + Ferrite.write_nodedata(vtk, sym_tensor_data, "symmetric tensor") + Ferrite.write_nodedata(vtk, tensor_data, "tensor") + Ferrite.write_nodedata(vtk, tensor_data_1D, "tensor_1d") + Ferrite.write_nodedata(vtk, vector_data, "vector") end # test the shas of the files From 9226fed5647427e69d3345db05608f234211b095 Mon Sep 17 00:00:00 2001 From: Knut Andreas Meyer Date: Sat, 16 Sep 2023 14:47:35 +0200 Subject: [PATCH 35/67] Remove doc output and files --- docs/src/topics/export.md | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/docs/src/topics/export.md b/docs/src/topics/export.md index 6737bd91b7..45d6abadf8 100644 --- a/docs/src/topics/export.md +++ b/docs/src/topics/export.md @@ -18,7 +18,8 @@ The following structure can be used to write various output to a vtk-file: ```@example export VTKFile("my_solution", grid) do vtk write_solution(vtk, dh, u) -end; +end +rm("my_solution.vtk") # hide ``` where `write_solution` is just one example of the following functions that can be used @@ -36,7 +37,8 @@ Instead of using the `do`-block, it is also possible to do vtk = VTKFile("my_solution", grid) write_solution(vtk, dh, u) # etc. -close(vtk); +close(vtk) +rm("my_solution.vtk") # hide ``` The data written by `write_solution`, `write_celldata`, `Ferrite.write_nodedata`, and `write_projection` may be either scalar (`Vector{<:Number}`) or tensor (`Vector{<:AbstractTensor}`) data. @@ -55,5 +57,7 @@ for t in range(0, 1, 5) end end close(pvd); +rm.((string("my_results_", i, ".vtu") for i in 1:5)) #hide +rm("my_results.pvd") #hide ``` See [Transient heat equation](@ref tutorial-transient-heat-equation) for an example \ No newline at end of file From db226cec3679b154416ccf8e70174629851c8cab Mon Sep 17 00:00:00 2001 From: Knut Andreas Meyer Date: Tue, 19 Sep 2023 21:46:06 +0200 Subject: [PATCH 36/67] Merge manifest from master --- docs/Manifest.toml | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/docs/Manifest.toml b/docs/Manifest.toml index f720bdc345..6e0ba79a2d 100644 --- a/docs/Manifest.toml +++ b/docs/Manifest.toml @@ -1,13 +1,13 @@ # This file is machine-generated - editing it directly is not advised -julia_version = "1.9.2" +julia_version = "1.9.3" manifest_format = "2.0" project_hash = "a0caf5d07899f1863658c7736f8530d20d28db07" [[deps.ADTypes]] -git-tree-sha1 = "f2b16fe1a3491b295105cae080c2a5f77a842718" +git-tree-sha1 = "5d2e21d7b0d8c22f67483ef95ebdc39c0e6b6003" uuid = "47edcb42-4c32-4615-8424-f2b9edc5f35b" -version = "0.2.3" +version = "0.2.4" [[deps.ANSIColoredPrinters]] git-tree-sha1 = "574baf8110975760d391c710b6341da1afa48d8c" @@ -1228,10 +1228,10 @@ uuid = "92933f4c-e287-5a05-a399-4b506db050ca" version = "1.9.0" [[deps.Qt6Base_jll]] -deps = ["Artifacts", "CompilerSupportLibraries_jll", "Fontconfig_jll", "Glib_jll", "JLLWrappers", "Libdl", "Libglvnd_jll", "OpenSSL_jll", "Pkg", "Xorg_libXext_jll", "Xorg_libXrender_jll", "Xorg_libxcb_jll", "Xorg_xcb_util_image_jll", "Xorg_xcb_util_keysyms_jll", "Xorg_xcb_util_renderutil_jll", "Xorg_xcb_util_wm_jll", "Zlib_jll", "xkbcommon_jll"] -git-tree-sha1 = "364898e8f13f7eaaceec55fd3d08680498c0aa6e" +deps = ["Artifacts", "CompilerSupportLibraries_jll", "Fontconfig_jll", "Glib_jll", "JLLWrappers", "Libdl", "Libglvnd_jll", "OpenSSL_jll", "Vulkan_Loader_jll", "Xorg_libXext_jll", "Xorg_libXrender_jll", "Xorg_libxcb_jll", "Xorg_xcb_util_image_jll", "Xorg_xcb_util_keysyms_jll", "Xorg_xcb_util_renderutil_jll", "Xorg_xcb_util_wm_jll", "Zlib_jll", "xkbcommon_jll"] +git-tree-sha1 = "ea513c73c8f657985e8fb9b8067dd7cf306adc35" uuid = "c0090381-4147-56d7-9ebc-da0b1113ec56" -version = "6.4.2+3" +version = "6.5.2+0" [[deps.REPL]] deps = ["InteractiveUtils", "Markdown", "Sockets", "Unicode"] @@ -1335,9 +1335,9 @@ version = "0.6.39" [[deps.SciMLBase]] deps = ["ADTypes", "ArrayInterface", "ChainRulesCore", "CommonSolve", "ConstructionBase", "Distributed", "DocStringExtensions", "EnumX", "FillArrays", "FunctionWrappersWrappers", "IteratorInterfaceExtensions", "LinearAlgebra", "Logging", "Markdown", "PrecompileTools", "Preferences", "RecipesBase", "RecursiveArrayTools", "Reexport", "RuntimeGeneratedFunctions", "SciMLOperators", "StaticArraysCore", "Statistics", "SymbolicIndexingInterface", "Tables", "TruncatedStacktraces", "ZygoteRules"] -git-tree-sha1 = "827c87edbb5ad34a5e61accc99269285291c692e" +git-tree-sha1 = "6de099dba3c80e23bde1d19011161ea91a23ed6b" uuid = "0bca4576-84f4-4d90-8ffe-ffa030f20462" -version = "1.97.1" +version = "1.98.0" [deps.SciMLBase.extensions] ZygoteExt = "Zygote" @@ -1681,6 +1681,12 @@ git-tree-sha1 = "8351f8d73d7e880bfc042a8b6922684ebeafb35c" uuid = "19fa3120-7c27-5ec5-8db8-b0b0aa330d6f" version = "0.2.0" +[[deps.Vulkan_Loader_jll]] +deps = ["Artifacts", "JLLWrappers", "Libdl", "Wayland_jll", "Xorg_libX11_jll", "Xorg_libXrandr_jll", "xkbcommon_jll"] +git-tree-sha1 = "2f0486047a07670caad3a81a075d2e518acc5c59" +uuid = "a44049a8-05dd-5a78-86c9-5fde0876e88c" +version = "1.3.243+0" + [[deps.Wayland_jll]] deps = ["Artifacts", "Expat_jll", "JLLWrappers", "Libdl", "Libffi_jll", "Pkg", "XML2_jll"] git-tree-sha1 = "ed8d92d9774b077c53e1da50fd81a36af3744c1c" From 57f0f33f628d6b1ba71058cbef0628ea72dac43e Mon Sep 17 00:00:00 2001 From: Knut Andreas Meyer Date: Tue, 19 Sep 2023 21:53:40 +0200 Subject: [PATCH 37/67] ParaviewCollection -> VTKFileCollection --- .../quasi_incompressible_hyperelasticity.jl | 2 +- docs/src/literate-tutorials/ns_vs_diffeq.jl | 2 +- .../transient_heat_equation.jl | 4 ++-- docs/src/reference/export.md | 2 +- docs/src/topics/export.md | 16 +++++-------- src/Export/VTK.jl | 24 +++++++++---------- src/exports.jl | 2 +- 7 files changed, 24 insertions(+), 28 deletions(-) diff --git a/docs/src/literate-gallery/quasi_incompressible_hyperelasticity.jl b/docs/src/literate-gallery/quasi_incompressible_hyperelasticity.jl index 53cf1b81cc..8a624127f4 100644 --- a/docs/src/literate-gallery/quasi_incompressible_hyperelasticity.jl +++ b/docs/src/literate-gallery/quasi_incompressible_hyperelasticity.jl @@ -305,7 +305,7 @@ function solve(interpolation_u, interpolation_p) Δt = 0.1; NEWTON_TOL = 1e-8 - pvd = ParaviewCollection("hyperelasticity_incomp_mixed", grid); + pvd = VTKFileCollection("hyperelasticity_incomp_mixed", grid); for t ∈ 0.0:Δt:Tf ## Perform Newton iterations Ferrite.update!(dbc, t) diff --git a/docs/src/literate-tutorials/ns_vs_diffeq.jl b/docs/src/literate-tutorials/ns_vs_diffeq.jl index 8141630a0f..81075fd70a 100644 --- a/docs/src/literate-tutorials/ns_vs_diffeq.jl +++ b/docs/src/literate-tutorials/ns_vs_diffeq.jl @@ -431,7 +431,7 @@ integrator = init( progress=true, progress_steps=1, saveat=Δt_save); -pvd = ParaviewCollection("vortex-street", grid); +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, diff --git a/docs/src/literate-tutorials/transient_heat_equation.jl b/docs/src/literate-tutorials/transient_heat_equation.jl index c5a89e4b49..db835c7ea6 100644 --- a/docs/src/literate-tutorials/transient_heat_equation.jl +++ b/docs/src/literate-tutorials/transient_heat_equation.jl @@ -189,8 +189,8 @@ 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 `ParaviewCollection` (.pvd) file. -pvd = ParaviewCollection("transient-heat", grid); +# To store the solution, we initialize a `VTKFileCollection` (.pvd) file. +pvd = VTKFileCollection("transient-heat", grid); t = 0 addstep!(pvd, t) do io write_solution(io, dh, uₙ) diff --git a/docs/src/reference/export.md b/docs/src/reference/export.md index 51a3c35c06..bcfaf25b23 100644 --- a/docs/src/reference/export.md +++ b/docs/src/reference/export.md @@ -26,7 +26,7 @@ evaluate_at_grid_nodes ## VTK Export ```@docs VTKFile -ParaviewCollection +VTKFileCollection addstep! write_solution write_projection diff --git a/docs/src/topics/export.md b/docs/src/topics/export.md index 45d6abadf8..edac993fde 100644 --- a/docs/src/topics/export.md +++ b/docs/src/topics/export.md @@ -18,8 +18,7 @@ The following structure can be used to write various output to a vtk-file: ```@example export VTKFile("my_solution", grid) do vtk write_solution(vtk, dh, u) -end -rm("my_solution.vtk") # hide +end; ``` where `write_solution` is just one example of the following functions that can be used @@ -37,19 +36,18 @@ Instead of using the `do`-block, it is also possible to do vtk = VTKFile("my_solution", grid) write_solution(vtk, dh, u) # etc. -close(vtk) -rm("my_solution.vtk") # hide +close(vtk); ``` The data written by `write_solution`, `write_celldata`, `Ferrite.write_nodedata`, and `write_projection` may be either scalar (`Vector{<:Number}`) or tensor (`Vector{<:AbstractTensor}`) data. -For simulations with multiple time steps, typically one `vtk` file is written +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, -a `ParaviewCollection` can be used, which will write one paraview collection (.pvd) -file and one `vtk` for each time step. +a `VTKFileCollection` can be used, which will write one paraview datafile (`.pvd`) +file and one `VTKFile` (`.vtu`) for each time step. ```@example pvdexport -pvd = ParaviewCollection("my_results", grid) +pvd = VTKFileCollection("my_results", grid) for t in range(0, 1, 5) # Do calculations to update u addstep!(pvd, t) do vtk @@ -57,7 +55,5 @@ for t in range(0, 1, 5) end end close(pvd); -rm.((string("my_results_", i, ".vtu") for i in 1:5)) #hide -rm("my_results.pvd") #hide ``` See [Transient heat equation](@ref tutorial-transient-heat-equation) for an example \ No newline at end of file diff --git a/src/Export/VTK.jl b/src/Export/VTK.jl index 0563f15fe8..b9213ab5bf 100644 --- a/src/Export/VTK.jl +++ b/src/Export/VTK.jl @@ -54,13 +54,13 @@ function Base.show(io::IO, ::MIME"text/plain", vtk::VTKFile) end """ - ParaviewCollection(name::String, grid::AbstractGrid) - ParaviewCollection(name::String, dh::DofHandler) + VTKFileCollection(name::String, grid::AbstractGrid) + VTKFileCollection(name::String, dh::DofHandler) -Create a paraview collection file (.pvd) that can be used to -save multiple vtk file. Example, +Create a paraview data file (.pvd) that can be used to +save multiple vtk file along with a time stamp. Example, ``` -pvd = ParaviewCollection("test", grid) +pvd = VTKFileCollection("test", grid) for t in range(0, 2, 4) # Solve the timestep to find u and σeff addstep!(pvd, t) do io # io::VTKFile @@ -71,20 +71,20 @@ end close(pvd) ``` """ -mutable struct ParaviewCollection{P<:WriteVTK.CollectionFile,G_DH} +mutable struct VTKFileCollection{P<:WriteVTK.CollectionFile,G_DH} pvd::P grid_or_dh::G_DH name::String step::Int end -function ParaviewCollection(name::String, grid_or_dh::Union{AbstractGrid,AbstractDofHandler}) +function VTKFileCollection(name::String, grid_or_dh::Union{AbstractGrid,AbstractDofHandler}) pvd = WriteVTK.paraview_collection(name) - return ParaviewCollection(pvd, grid_or_dh, name, 0) + return VTKFileCollection(pvd, grid_or_dh, name, 0) end -Base.close(pvd::ParaviewCollection) = WriteVTK.vtk_save(pvd.pvd) +Base.close(pvd::VTKFileCollection) = WriteVTK.vtk_save(pvd.pvd) """ - addstep!(f::Function, pvd::ParaviewCollection, t::Real, [grid_or_dh]) + addstep!(f::Function, pvd::VTKFileCollection, t::Real, [grid_or_dh]) Add a step at time `t` by writing a `VTKFile` to `pvd`. If required, a new grid can be used by supplying the grid or dofhandler as the last argument. @@ -94,9 +94,9 @@ addstep!(pvd, t) do vtk write_solution(vtk, dh, u) end ``` -See also [`ParaviewCollection`](@ref). +See also [`VTKFileCollection`](@ref). """ -function addstep!(f::Function, pvd::ParaviewCollection, t, grid=pvd.grid_or_dh) +function addstep!(f::Function, pvd::VTKFileCollection, t, grid=pvd.grid_or_dh) pvd.step += 1 VTKFile(string(pvd.name, "_", pvd.step), grid) do vtk f(vtk) diff --git a/src/exports.jl b/src/exports.jl index a9303e42ee..f9d5d8194e 100644 --- a/src/exports.jl +++ b/src/exports.jl @@ -155,7 +155,7 @@ export write_solution, write_celldata, write_projection, - ParaviewCollection, + VTKFileCollection, addstep!, # L2 Projection From ba5fbb18ea2f2c36ce630c0573caa285311aae3a Mon Sep 17 00:00:00 2001 From: Knut Andreas Meyer Date: Tue, 19 Sep 2023 22:25:32 +0200 Subject: [PATCH 38/67] Allow VTKFile keywords to be given to VTKFileCollection --- src/Export/VTK.jl | 18 +++++++++++------- test/test_grid_dofhandler_vtk.jl | 17 +++++++++++++++++ 2 files changed, 28 insertions(+), 7 deletions(-) diff --git a/src/Export/VTK.jl b/src/Export/VTK.jl index b9213ab5bf..a388308409 100644 --- a/src/Export/VTK.jl +++ b/src/Export/VTK.jl @@ -54,11 +54,14 @@ function Base.show(io::IO, ::MIME"text/plain", vtk::VTKFile) end """ - VTKFileCollection(name::String, grid::AbstractGrid) - VTKFileCollection(name::String, dh::DofHandler) + VTKFileCollection(name::String, grid::AbstractGrid; vtk_kwargs...) + VTKFileCollection(name::String, dh::DofHandler; vtk_kwargs...) Create a paraview data file (.pvd) that can be used to -save multiple vtk file along with a time stamp. Example, +save multiple vtk file along with a time stamp. The keyword arguments +are forwarded to each `VTKFile` constructor, which again forwards them +to `WriteVTK.vtk_grid`. +Example, ``` pvd = VTKFileCollection("test", grid) for t in range(0, 2, 4) @@ -71,15 +74,16 @@ end close(pvd) ``` """ -mutable struct VTKFileCollection{P<:WriteVTK.CollectionFile,G_DH} +mutable struct VTKFileCollection{P<:WriteVTK.CollectionFile,G_DH,KW} pvd::P grid_or_dh::G_DH name::String step::Int + vtk_kwargs::KW end -function VTKFileCollection(name::String, grid_or_dh::Union{AbstractGrid,AbstractDofHandler}) +function VTKFileCollection(name::String, grid_or_dh::Union{AbstractGrid,AbstractDofHandler}; vtk_kwargs...) pvd = WriteVTK.paraview_collection(name) - return VTKFileCollection(pvd, grid_or_dh, name, 0) + return VTKFileCollection(pvd, grid_or_dh, name, 0, vtk_kwargs) end Base.close(pvd::VTKFileCollection) = WriteVTK.vtk_save(pvd.pvd) @@ -98,7 +102,7 @@ See also [`VTKFileCollection`](@ref). """ function addstep!(f::Function, pvd::VTKFileCollection, t, grid=pvd.grid_or_dh) pvd.step += 1 - VTKFile(string(pvd.name, "_", pvd.step), grid) do vtk + VTKFile(string(pvd.name, "_", pvd.step), grid; pvd.vtk_kwargs...) do vtk f(vtk) pvd.pvd[t] = vtk.vtk # Add to collection end diff --git a/test/test_grid_dofhandler_vtk.jl b/test/test_grid_dofhandler_vtk.jl index 52c5912d04..22d0fae235 100644 --- a/test/test_grid_dofhandler_vtk.jl +++ b/test/test_grid_dofhandler_vtk.jl @@ -622,4 +622,21 @@ end close!(dh2) @test dh1.cell_dofs == dh2.cell_dofs end + + @testset "VTKFileCollection" begin + grid = generate_grid(Quadrilateral, (10,10)) + file_sizes = Int[] + fname = "test_collection_kwargs" + for compress in (true, false) + pvd = VTKFileCollection(fname, grid; compress) + addstep!(pvd, 0.0) do io + nothing + end + close(pvd) + push!(file_sizes, stat(string(fname, "_1.vtu")).size) + rm(string(fname, "_1.vtu")) + end + rm(string(fname, ".pvd")) + @test file_sizes[1] < file_sizes[2] # Check that compress=true gives smaller file size + end end From 0a90f09811352205708f447f66c3b327fc42f547 Mon Sep 17 00:00:00 2001 From: Knut Andreas Meyer Date: Mon, 25 Sep 2023 12:17:24 +0200 Subject: [PATCH 39/67] Factor out create_vtk_griddata --- src/Export/VTK.jl | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/Export/VTK.jl b/src/Export/VTK.jl index a388308409..16ed51e3fd 100644 --- a/src/Export/VTK.jl +++ b/src/Export/VTK.jl @@ -157,13 +157,18 @@ nodes_to_vtkorder(cell::QuadraticHexahedron) = [ cell.nodes[27], # interior ] -function create_vtk_grid(filename::AbstractString, grid::Grid{dim,C,T}; kwargs...) where {dim,C,T} +function create_vtk_griddata(grid::Grid{dim,C,T}) where {dim,C,T} cls = WriteVTK.MeshCell[] for cell in getcells(grid) celltype = Ferrite.cell_to_vtkcell(typeof(cell)) push!(cls, WriteVTK.MeshCell(celltype, nodes_to_vtkorder(cell))) end coords = reshape(reinterpret(T, getnodes(grid)), (dim, getnnodes(grid))) + return coords, cls +end + +function create_vtk_grid(filename::AbstractString, grid::Grid{dim,C,T}; kwargs...) where {dim,C,T} + coords, cls = create_vtk_griddata(grid) return WriteVTK.vtk_grid(filename, coords, cls; kwargs...) end From 4cc50c63c86040210345a79daa9294e30e20c97d Mon Sep 17 00:00:00 2001 From: Knut Andreas Meyer Date: Sat, 30 Sep 2023 16:04:18 +0200 Subject: [PATCH 40/67] Allow more vtk file types in VTKFile, e.g. pvtk --- src/Export/VTK.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Export/VTK.jl b/src/Export/VTK.jl index 16ed51e3fd..ecd097d072 100644 --- a/src/Export/VTK.jl +++ b/src/Export/VTK.jl @@ -25,7 +25,7 @@ VTKFile(filename, grid) do vtk write_celldata(vtk, celldata) end """ -struct VTKFile{VTK<:WriteVTK.DatasetFile} +struct VTKFile{VTK<:WriteVTK.VTKFile} vtk::VTK end function VTKFile(filename::String, dh::DofHandler; kwargs...) From 193a375701d297f6fae1dd0ac6a0bc4cfc57c308 Mon Sep 17 00:00:00 2001 From: Knut Andreas Meyer Date: Sat, 30 Sep 2023 17:17:03 +0200 Subject: [PATCH 41/67] Fix test failure due to merge --- test/test_mixeddofhandler.jl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/test_mixeddofhandler.jl b/test/test_mixeddofhandler.jl index 8c8c774bf1..12fb7bc0d4 100644 --- a/test/test_mixeddofhandler.jl +++ b/test/test_mixeddofhandler.jl @@ -633,8 +633,8 @@ function test_vtk_export() close!(dh) u = collect(1:ndofs(dh)) filename = "mixed_2d_grid" - vtk_grid(filename, dh) do vtk - vtk_point_data(vtk, dh, u) + VTKFile(filename, dh) do vtk + write_solution(vtk, dh, u) end sha = bytes2hex(open(SHA.sha1, filename*".vtu")) @test sha == "339ab8a8a613c2f38af684cccd695ae816671607" From 112c4c225072b01a0773913b45ed9915cd5f5e5d Mon Sep 17 00:00:00 2001 From: Knut Andreas Meyer Date: Sat, 30 Sep 2023 17:19:34 +0200 Subject: [PATCH 42/67] Remove addstep and use VTKFile --- .../quasi_incompressible_hyperelasticity.jl | 2 +- docs/src/literate-tutorials/ns_vs_diffeq.jl | 2 +- docs/src/literate-tutorials/transient_heat_equation.jl | 4 ++-- docs/src/reference/export.md | 1 - docs/src/topics/export.md | 2 +- src/Export/VTK.jl | 8 ++++---- src/exports.jl | 1 - test/test_grid_dofhandler_vtk.jl | 2 +- 8 files changed, 10 insertions(+), 12 deletions(-) diff --git a/docs/src/literate-gallery/quasi_incompressible_hyperelasticity.jl b/docs/src/literate-gallery/quasi_incompressible_hyperelasticity.jl index 8a624127f4..44953410de 100644 --- a/docs/src/literate-gallery/quasi_incompressible_hyperelasticity.jl +++ b/docs/src/literate-gallery/quasi_incompressible_hyperelasticity.jl @@ -334,7 +334,7 @@ function solve(interpolation_u, interpolation_p) end; ## Save the solution fields - addstep!(pvd, t) do io + VTKFile(pvd, t) do io write_solution(io, dh, w) end end; diff --git a/docs/src/literate-tutorials/ns_vs_diffeq.jl b/docs/src/literate-tutorials/ns_vs_diffeq.jl index 81075fd70a..962b17c646 100644 --- a/docs/src/literate-tutorials/ns_vs_diffeq.jl +++ b/docs/src/literate-tutorials/ns_vs_diffeq.jl @@ -440,7 +440,7 @@ for (u_uc,t) in integrator update!(ch, t) u = copy(u_uc) apply!(u, ch) - addstep!(pvd, t) do io + VTKFile(pvd, t) do io write_solution(io, dh, u) end end diff --git a/docs/src/literate-tutorials/transient_heat_equation.jl b/docs/src/literate-tutorials/transient_heat_equation.jl index db835c7ea6..5a251bd393 100644 --- a/docs/src/literate-tutorials/transient_heat_equation.jl +++ b/docs/src/literate-tutorials/transient_heat_equation.jl @@ -192,7 +192,7 @@ apply!(A, ch); # To store the solution, we initialize a `VTKFileCollection` (.pvd) file. pvd = VTKFileCollection("transient-heat", grid); t = 0 -addstep!(pvd, t) do io +VTKFile(pvd, t) do io write_solution(io, dh, uₙ) end @@ -209,7 +209,7 @@ for t in Δt:Δt:T #Finally, we can solve the time step and save the solution afterwards. u = A \ b - addstep!(pvd, t) do io + VTKFile(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. diff --git a/docs/src/reference/export.md b/docs/src/reference/export.md index bcfaf25b23..3c51f240d7 100644 --- a/docs/src/reference/export.md +++ b/docs/src/reference/export.md @@ -27,7 +27,6 @@ evaluate_at_grid_nodes ```@docs VTKFile VTKFileCollection -addstep! write_solution write_projection write_celldata diff --git a/docs/src/topics/export.md b/docs/src/topics/export.md index edac993fde..b3b79c3449 100644 --- a/docs/src/topics/export.md +++ b/docs/src/topics/export.md @@ -50,7 +50,7 @@ file and one `VTKFile` (`.vtu`) for each time step. pvd = VTKFileCollection("my_results", grid) for t in range(0, 1, 5) # Do calculations to update u - addstep!(pvd, t) do vtk + VTKFile(pvd, t) do vtk write_solution(vtk, dh, u) end end diff --git a/src/Export/VTK.jl b/src/Export/VTK.jl index ecd097d072..b39869d7fc 100644 --- a/src/Export/VTK.jl +++ b/src/Export/VTK.jl @@ -66,7 +66,7 @@ Example, pvd = VTKFileCollection("test", grid) for t in range(0, 2, 4) # Solve the timestep to find u and σeff - addstep!(pvd, t) do io # io::VTKFile + VTKFile(pvd, t) do io # io::VTKFile write_solution(io, dh, u) write_celldata(io, σeff, "Effective stress") end @@ -88,19 +88,19 @@ end Base.close(pvd::VTKFileCollection) = WriteVTK.vtk_save(pvd.pvd) """ - addstep!(f::Function, pvd::VTKFileCollection, t::Real, [grid_or_dh]) + VTKFile(f::Function, pvd::VTKFileCollection, t::Real, [grid_or_dh]) Add a step at time `t` by writing a `VTKFile` to `pvd`. If required, a new grid can be used by supplying the grid or dofhandler as the last argument. Should be used in a do-block: ```julia -addstep!(pvd, t) do vtk +VTKFile(pvd, t) do vtk write_solution(vtk, dh, u) end ``` See also [`VTKFileCollection`](@ref). """ -function addstep!(f::Function, pvd::VTKFileCollection, t, grid=pvd.grid_or_dh) +function VTKFile(f::Function, pvd::VTKFileCollection, t, grid=pvd.grid_or_dh) pvd.step += 1 VTKFile(string(pvd.name, "_", pvd.step), grid; pvd.vtk_kwargs...) do vtk f(vtk) diff --git a/src/exports.jl b/src/exports.jl index f9d5d8194e..f5901c425a 100644 --- a/src/exports.jl +++ b/src/exports.jl @@ -156,7 +156,6 @@ export write_celldata, write_projection, VTKFileCollection, - addstep!, # L2 Projection project, diff --git a/test/test_grid_dofhandler_vtk.jl b/test/test_grid_dofhandler_vtk.jl index 22d0fae235..6f49493330 100644 --- a/test/test_grid_dofhandler_vtk.jl +++ b/test/test_grid_dofhandler_vtk.jl @@ -629,7 +629,7 @@ end fname = "test_collection_kwargs" for compress in (true, false) pvd = VTKFileCollection(fname, grid; compress) - addstep!(pvd, 0.0) do io + VTKFile(pvd, 0.0) do io nothing end close(pvd) From 2047ab05504887cc2a15133d72803d9a12e8e7cf Mon Sep 17 00:00:00 2001 From: Knut Andreas Meyer Date: Sat, 30 Sep 2023 17:50:05 +0200 Subject: [PATCH 43/67] Revert "Remove addstep and use VTKFile" This reverts commit 112c4c225072b01a0773913b45ed9915cd5f5e5d. --- .../quasi_incompressible_hyperelasticity.jl | 2 +- docs/src/literate-tutorials/ns_vs_diffeq.jl | 2 +- docs/src/literate-tutorials/transient_heat_equation.jl | 4 ++-- docs/src/reference/export.md | 1 + docs/src/topics/export.md | 2 +- src/Export/VTK.jl | 8 ++++---- src/exports.jl | 1 + test/test_grid_dofhandler_vtk.jl | 2 +- 8 files changed, 12 insertions(+), 10 deletions(-) diff --git a/docs/src/literate-gallery/quasi_incompressible_hyperelasticity.jl b/docs/src/literate-gallery/quasi_incompressible_hyperelasticity.jl index 44953410de..8a624127f4 100644 --- a/docs/src/literate-gallery/quasi_incompressible_hyperelasticity.jl +++ b/docs/src/literate-gallery/quasi_incompressible_hyperelasticity.jl @@ -334,7 +334,7 @@ function solve(interpolation_u, interpolation_p) end; ## Save the solution fields - VTKFile(pvd, t) do io + addstep!(pvd, t) do io write_solution(io, dh, w) end end; diff --git a/docs/src/literate-tutorials/ns_vs_diffeq.jl b/docs/src/literate-tutorials/ns_vs_diffeq.jl index 962b17c646..81075fd70a 100644 --- a/docs/src/literate-tutorials/ns_vs_diffeq.jl +++ b/docs/src/literate-tutorials/ns_vs_diffeq.jl @@ -440,7 +440,7 @@ for (u_uc,t) in integrator update!(ch, t) u = copy(u_uc) apply!(u, ch) - VTKFile(pvd, t) do io + addstep!(pvd, t) do io write_solution(io, dh, u) end end diff --git a/docs/src/literate-tutorials/transient_heat_equation.jl b/docs/src/literate-tutorials/transient_heat_equation.jl index 5a251bd393..db835c7ea6 100644 --- a/docs/src/literate-tutorials/transient_heat_equation.jl +++ b/docs/src/literate-tutorials/transient_heat_equation.jl @@ -192,7 +192,7 @@ apply!(A, ch); # To store the solution, we initialize a `VTKFileCollection` (.pvd) file. pvd = VTKFileCollection("transient-heat", grid); t = 0 -VTKFile(pvd, t) do io +addstep!(pvd, t) do io write_solution(io, dh, uₙ) end @@ -209,7 +209,7 @@ for t in Δt:Δt:T #Finally, we can solve the time step and save the solution afterwards. u = A \ b - VTKFile(pvd, t) do io + 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. diff --git a/docs/src/reference/export.md b/docs/src/reference/export.md index 3c51f240d7..bcfaf25b23 100644 --- a/docs/src/reference/export.md +++ b/docs/src/reference/export.md @@ -27,6 +27,7 @@ evaluate_at_grid_nodes ```@docs VTKFile VTKFileCollection +addstep! write_solution write_projection write_celldata diff --git a/docs/src/topics/export.md b/docs/src/topics/export.md index b3b79c3449..edac993fde 100644 --- a/docs/src/topics/export.md +++ b/docs/src/topics/export.md @@ -50,7 +50,7 @@ file and one `VTKFile` (`.vtu`) for each time step. pvd = VTKFileCollection("my_results", grid) for t in range(0, 1, 5) # Do calculations to update u - VTKFile(pvd, t) do vtk + addstep!(pvd, t) do vtk write_solution(vtk, dh, u) end end diff --git a/src/Export/VTK.jl b/src/Export/VTK.jl index b39869d7fc..ecd097d072 100644 --- a/src/Export/VTK.jl +++ b/src/Export/VTK.jl @@ -66,7 +66,7 @@ Example, pvd = VTKFileCollection("test", grid) for t in range(0, 2, 4) # Solve the timestep to find u and σeff - VTKFile(pvd, t) do io # io::VTKFile + addstep!(pvd, t) do io # io::VTKFile write_solution(io, dh, u) write_celldata(io, σeff, "Effective stress") end @@ -88,19 +88,19 @@ end Base.close(pvd::VTKFileCollection) = WriteVTK.vtk_save(pvd.pvd) """ - VTKFile(f::Function, pvd::VTKFileCollection, t::Real, [grid_or_dh]) + addstep!(f::Function, pvd::VTKFileCollection, t::Real, [grid_or_dh]) Add a step at time `t` by writing a `VTKFile` to `pvd`. If required, a new grid can be used by supplying the grid or dofhandler as the last argument. Should be used in a do-block: ```julia -VTKFile(pvd, t) do vtk +addstep!(pvd, t) do vtk write_solution(vtk, dh, u) end ``` See also [`VTKFileCollection`](@ref). """ -function VTKFile(f::Function, pvd::VTKFileCollection, t, grid=pvd.grid_or_dh) +function addstep!(f::Function, pvd::VTKFileCollection, t, grid=pvd.grid_or_dh) pvd.step += 1 VTKFile(string(pvd.name, "_", pvd.step), grid; pvd.vtk_kwargs...) do vtk f(vtk) diff --git a/src/exports.jl b/src/exports.jl index f5901c425a..f9d5d8194e 100644 --- a/src/exports.jl +++ b/src/exports.jl @@ -156,6 +156,7 @@ export write_celldata, write_projection, VTKFileCollection, + addstep!, # L2 Projection project, diff --git a/test/test_grid_dofhandler_vtk.jl b/test/test_grid_dofhandler_vtk.jl index 6f49493330..22d0fae235 100644 --- a/test/test_grid_dofhandler_vtk.jl +++ b/test/test_grid_dofhandler_vtk.jl @@ -629,7 +629,7 @@ end fname = "test_collection_kwargs" for compress in (true, false) pvd = VTKFileCollection(fname, grid; compress) - VTKFile(pvd, 0.0) do io + addstep!(pvd, 0.0) do io nothing end close(pvd) From 0cfbd24c4d2d27158b904a3d490f367b0c571374 Mon Sep 17 00:00:00 2001 From: Knut Andreas Meyer Date: Sun, 1 Oct 2023 12:48:30 +0200 Subject: [PATCH 44/67] Fix formatting in docstring --- src/Export/VTK.jl | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Export/VTK.jl b/src/Export/VTK.jl index ecd097d072..b088975cde 100644 --- a/src/Export/VTK.jl +++ b/src/Export/VTK.jl @@ -24,6 +24,7 @@ VTKFile(filename, grid) do vtk write_solution(vtk, dh, u) write_celldata(vtk, celldata) end +``` """ struct VTKFile{VTK<:WriteVTK.VTKFile} vtk::VTK From 12b8ed7c25a8156b99f79de92bfda68d44d077c8 Mon Sep 17 00:00:00 2001 From: Knut Andreas Meyer Date: Sat, 14 Oct 2023 15:17:59 +0200 Subject: [PATCH 45/67] Support and test addstep[bang](pvd, vtk, t) --- src/Export/VTK.jl | 51 ++++++++++++++++++++--------- test/test_grid_dofhandler_vtk.jl | 55 +++++++++++++++++++++++++------- 2 files changed, 79 insertions(+), 27 deletions(-) diff --git a/src/Export/VTK.jl b/src/Export/VTK.jl index b088975cde..90654d8973 100644 --- a/src/Export/VTK.jl +++ b/src/Export/VTK.jl @@ -62,17 +62,8 @@ Create a paraview data file (.pvd) that can be used to save multiple vtk file along with a time stamp. The keyword arguments are forwarded to each `VTKFile` constructor, which again forwards them to `WriteVTK.vtk_grid`. -Example, -``` -pvd = VTKFileCollection("test", grid) -for t in range(0, 2, 4) - # Solve the timestep to find u and σeff - addstep!(pvd, t) do io # io::VTKFile - write_solution(io, dh, u) - write_celldata(io, σeff, "Effective stress") - end -end -close(pvd) + +See [`addstep!`](@ref) for examples for how to use `VTKFileCollection`. ``` """ mutable struct VTKFileCollection{P<:WriteVTK.CollectionFile,G_DH,KW} @@ -93,13 +84,19 @@ Base.close(pvd::VTKFileCollection) = WriteVTK.vtk_save(pvd.pvd) Add a step at time `t` by writing a `VTKFile` to `pvd`. If required, a new grid can be used by supplying the grid or dofhandler as the last argument. -Should be used in a do-block: +Should be used in a do-block, e.g. ```julia -addstep!(pvd, t) do vtk - write_solution(vtk, dh, u) +filename = "myoutput" +pvd = VTKFileCollection(filename, grid) +for (n, t) in pairs(timevector) + # Calculate, e.g., the solution `u` and the stress `σeff` + addstep!(pvd, t) do io + write_celldata(io, σeff, "Effective stress") + write_solution(io, dh, u) + end end +close(pvd) ``` -See also [`VTKFileCollection`](@ref). """ function addstep!(f::Function, pvd::VTKFileCollection, t, grid=pvd.grid_or_dh) pvd.step += 1 @@ -109,6 +106,30 @@ function addstep!(f::Function, pvd::VTKFileCollection, t, grid=pvd.grid_or_dh) end end +""" + addstep!(pvd::VTKFileCollection, vtk::VTKFile, t) + +As an alternative to using the `addstep!(pvd, t) do` block, it is +also possible to add a specific `vtk` at time `t` to `pvd`. +Note that this will close the `vtk`. Example +```julia +filename = "myoutput" +pvd = VTKFileCollection(filename, grid) +for (n, t) in pairs(timevector) + # Calculate, e.g., the solution `u` and the stress `σeff` + vtk = VTKFile(string(filename, "_", n), dh) + write_celldata(vtk, σeff, "Effective stress") + write_solution(vtk, dh, u) + addstep!(pvd, vtk, t) +end +close(pvd) +``` +""" +function addstep!(pvd::VTKFileCollection, vtk::VTKFile, t) + pvd.step += 1 + pvd.pvd[t] = vtk.vtk +end + cell_to_vtkcell(::Type{Line}) = VTKCellTypes.VTK_LINE cell_to_vtkcell(::Type{QuadraticLine}) = VTKCellTypes.VTK_QUADRATIC_EDGE diff --git a/test/test_grid_dofhandler_vtk.jl b/test/test_grid_dofhandler_vtk.jl index 22d0fae235..b524cde450 100644 --- a/test/test_grid_dofhandler_vtk.jl +++ b/test/test_grid_dofhandler_vtk.jl @@ -624,19 +624,50 @@ end end @testset "VTKFileCollection" begin - grid = generate_grid(Quadrilateral, (10,10)) - file_sizes = Int[] - fname = "test_collection_kwargs" - for compress in (true, false) - pvd = VTKFileCollection(fname, grid; compress) - addstep!(pvd, 0.0) do io - nothing + @testset "equivalence of addstep methods" begin + grid = generate_grid(Triangle, (2,2)) + celldata = rand(getncells(grid)) + fname = "addstep" + pvd1 = VTKFileCollection(fname, grid) + pvd2 = VTKFileCollection(fname, grid) + timesteps = 0:0.5:0.5 + for (n, t) in pairs(timesteps) + addstep!(pvd1, t) do io + write_celldata(io, celldata*n, "celldata") + end + vtk = VTKFile(string(fname, "2_", n), grid) + write_celldata(vtk, celldata*n, "celldata") + addstep!(pvd2, vtk, t) + @test !(isopen(vtk.vtk)) + end + close.((pvd1, pvd2)) + @test pvd1.step == pvd2.step # Same nr of steps added + for (n, t) in pairs(timesteps) + fname1 = string(fname, "_", n, ".vtu") + fname2 = string(fname, "2_", n, ".vtu") + sha_vtk1 = bytes2hex(open(SHA.sha1, fname1)) + sha_vtk2 = bytes2hex(open(SHA.sha1, fname2)) + @test sha_vtk1 == sha_vtk2 + rm.((fname1, fname2)) + end + # Solving https://github.com/Ferrite-FEM/Ferrite.jl/issues/397 + # would allow checking the pvd files as well. + end + @testset "kwargs forwarding" begin + grid = generate_grid(Quadrilateral, (10,10)) + file_sizes = Int[] + fname = "test_collection_kwargs" + for compress in (true, false) + pvd = VTKFileCollection(fname, grid; compress) + addstep!(pvd, 0.0) do io + nothing + end + close(pvd) + push!(file_sizes, stat(string(fname, "_1.vtu")).size) + rm(string(fname, "_1.vtu")) end - close(pvd) - push!(file_sizes, stat(string(fname, "_1.vtu")).size) - rm(string(fname, "_1.vtu")) + rm(string(fname, ".pvd")) + @test file_sizes[1] < file_sizes[2] # Check that compress=true gives smaller file size end - rm(string(fname, ".pvd")) - @test file_sizes[1] < file_sizes[2] # Check that compress=true gives smaller file size end end From 3e8d454ae59608ed6d4df217b6ae25cd11db8e13 Mon Sep 17 00:00:00 2001 From: Knut Andreas Meyer Date: Sat, 14 Oct 2023 20:42:07 +0200 Subject: [PATCH 46/67] Allow input to VTKFileCollection ending with .pvd and update porous media example --- docs/src/literate-tutorials/porous_media.jl | 12 +++++------- src/Export/VTK.jl | 3 ++- 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/docs/src/literate-tutorials/porous_media.jl b/docs/src/literate-tutorials/porous_media.jl index ef2ee7e6ce..94d2e38eb8 100644 --- a/docs/src/literate-tutorials/porous_media.jl +++ b/docs/src/literate-tutorials/porous_media.jl @@ -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) @@ -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 diff --git a/src/Export/VTK.jl b/src/Export/VTK.jl index 90654d8973..c72f6af7c1 100644 --- a/src/Export/VTK.jl +++ b/src/Export/VTK.jl @@ -75,7 +75,8 @@ mutable struct VTKFileCollection{P<:WriteVTK.CollectionFile,G_DH,KW} end function VTKFileCollection(name::String, grid_or_dh::Union{AbstractGrid,AbstractDofHandler}; vtk_kwargs...) pvd = WriteVTK.paraview_collection(name) - return VTKFileCollection(pvd, grid_or_dh, name, 0, vtk_kwargs) + basename = endswith(name, ".pvd") ? string(first(split(name, ".pvd"))) : name + return VTKFileCollection(pvd, grid_or_dh, basename, 0, vtk_kwargs) end Base.close(pvd::VTKFileCollection) = WriteVTK.vtk_save(pvd.pvd) From 68b5d131243832cb14dd224f090d876cc6e0e1ac Mon Sep 17 00:00:00 2001 From: Knut Andreas Meyer Date: Sat, 21 Oct 2023 18:11:13 +0200 Subject: [PATCH 47/67] Export write_nodedata --- docs/src/reference/export.md | 2 +- src/Export/VTK.jl | 4 ++-- src/exports.jl | 1 + test/test_grid_dofhandler_vtk.jl | 14 +++++++------- 4 files changed, 11 insertions(+), 10 deletions(-) diff --git a/docs/src/reference/export.md b/docs/src/reference/export.md index bcfaf25b23..44268714bf 100644 --- a/docs/src/reference/export.md +++ b/docs/src/reference/export.md @@ -31,7 +31,7 @@ addstep! write_solution write_projection write_celldata -Ferrite.write_nodedata +write_nodedata Ferrite.write_cellset Ferrite.write_nodeset Ferrite.write_dirichlet diff --git a/src/Export/VTK.jl b/src/Export/VTK.jl index c72f6af7c1..400a87ac94 100644 --- a/src/Export/VTK.jl +++ b/src/Export/VTK.jl @@ -12,7 +12,7 @@ This file handler can be used to to write data with * [`write_solution`](@ref) * [`write_celldata`](@ref) * [`write_projection`](@ref) -* [`Ferrite.write_nodedata`](@ref). +* [`write_nodedata`](@ref). * [`Ferrite.write_cellset`](@ref) * [`Ferrite.write_nodeset`](@ref) * [`Ferrite.write_dirichlet`](@ref) @@ -244,7 +244,7 @@ Each field in `dh` will be saved separately, and `suffix` can be used to append to the fieldname. `u` can also contain tensorial values, but each entry in `u` must correspond to a -degree of freedom in `dh`, see [`write_nodedata`](@ref Ferrite.write_nodedata) for details. +degree of freedom in `dh`, see [`write_nodedata`](@ref write_nodedata) for details. Use `write_nodedata` directly when exporting values that are already sorted by the nodes in the grid. """ diff --git a/src/exports.jl b/src/exports.jl index f9d5d8194e..0c053d98c8 100644 --- a/src/exports.jl +++ b/src/exports.jl @@ -155,6 +155,7 @@ export write_solution, write_celldata, write_projection, + write_nodedata, VTKFileCollection, addstep!, diff --git a/test/test_grid_dofhandler_vtk.jl b/test/test_grid_dofhandler_vtk.jl index b524cde450..6e824a32ab 100644 --- a/test/test_grid_dofhandler_vtk.jl +++ b/test/test_grid_dofhandler_vtk.jl @@ -115,9 +115,9 @@ close(csio) filename_3d = "test_vtk_3d" VTKFile(filename_3d, grid) do vtk - Ferrite.write_nodedata(vtk, sym_tensor_data, "symmetric tensor") - Ferrite.write_nodedata(vtk, tensor_data, "tensor") - Ferrite.write_nodedata(vtk, vector_data, "vector") + write_nodedata(vtk, sym_tensor_data, "symmetric tensor") + write_nodedata(vtk, tensor_data, "tensor") + write_nodedata(vtk, vector_data, "vector") end # 2D grid @@ -130,10 +130,10 @@ close(csio) filename_2d = "test_vtk_2d" VTKFile(filename_2d, grid) do vtk - Ferrite.write_nodedata(vtk, sym_tensor_data, "symmetric tensor") - Ferrite.write_nodedata(vtk, tensor_data, "tensor") - Ferrite.write_nodedata(vtk, tensor_data_1D, "tensor_1d") - Ferrite.write_nodedata(vtk, vector_data, "vector") + write_nodedata(vtk, sym_tensor_data, "symmetric tensor") + write_nodedata(vtk, tensor_data, "tensor") + write_nodedata(vtk, tensor_data_1D, "tensor_1d") + write_nodedata(vtk, vector_data, "vector") end # test the shas of the files From 5aa6cb5b339f98d6dd4486fa144bafa8a5cb8b97 Mon Sep 17 00:00:00 2001 From: Knut Andreas Meyer Date: Sat, 21 Oct 2023 18:34:32 +0200 Subject: [PATCH 48/67] Remove kwargs forwarding --- docs/src/topics/export.md | 4 ++-- src/Export/VTK.jl | 25 ++++++++++++------------- test/test_grid_dofhandler_vtk.jl | 5 +++-- 3 files changed, 17 insertions(+), 17 deletions(-) diff --git a/docs/src/topics/export.md b/docs/src/topics/export.md index edac993fde..1f89aea5b0 100644 --- a/docs/src/topics/export.md +++ b/docs/src/topics/export.md @@ -24,7 +24,7 @@ where `write_solution` is just one example of the following functions that can b * [`write_solution`](@ref) * [`write_celldata`](@ref) -* [`Ferrite.write_nodedata`](@ref) +* [`write_nodedata`](@ref) * [`write_projection`](@ref) * [`Ferrite.write_cellset`](@ref) * [`Ferrite.write_nodeset`](@ref) @@ -39,7 +39,7 @@ write_solution(vtk, dh, u) close(vtk); ``` -The data written by `write_solution`, `write_celldata`, `Ferrite.write_nodedata`, and `write_projection` may be either scalar (`Vector{<:Number}`) or tensor (`Vector{<:AbstractTensor}`) data. +The data written by `write_solution`, `write_celldata`, `write_nodedata`, 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, diff --git a/src/Export/VTK.jl b/src/Export/VTK.jl index 400a87ac94..128c5e12e9 100644 --- a/src/Export/VTK.jl +++ b/src/Export/VTK.jl @@ -55,35 +55,34 @@ function Base.show(io::IO, ::MIME"text/plain", vtk::VTKFile) end """ - VTKFileCollection(name::String, grid::AbstractGrid; vtk_kwargs...) - VTKFileCollection(name::String, dh::DofHandler; vtk_kwargs...) + VTKFileCollection(name::String, grid::AbstractGrid; kwargs...) + VTKFileCollection(name::String, dh::DofHandler; kwargs...) Create a paraview data file (.pvd) that can be used to save multiple vtk file along with a time stamp. The keyword arguments -are forwarded to each `VTKFile` constructor, which again forwards them -to `WriteVTK.vtk_grid`. +are forwarded to `WriteVTK.paraview_collection`. See [`addstep!`](@ref) for examples for how to use `VTKFileCollection`. ``` """ -mutable struct VTKFileCollection{P<:WriteVTK.CollectionFile,G_DH,KW} +mutable struct VTKFileCollection{P<:WriteVTK.CollectionFile,G_DH} pvd::P grid_or_dh::G_DH name::String step::Int - vtk_kwargs::KW end -function VTKFileCollection(name::String, grid_or_dh::Union{AbstractGrid,AbstractDofHandler}; vtk_kwargs...) - pvd = WriteVTK.paraview_collection(name) - basename = endswith(name, ".pvd") ? string(first(split(name, ".pvd"))) : name - return VTKFileCollection(pvd, grid_or_dh, basename, 0, vtk_kwargs) +function VTKFileCollection(name::String, grid_or_dh::Union{AbstractGrid,AbstractDofHandler}; kwargs...) + pvd = WriteVTK.paraview_collection(name; kwargs...) + basename = string(first(split(pvd.path, ".pvd"))) + return VTKFileCollection(pvd, grid_or_dh, basename, 0) end Base.close(pvd::VTKFileCollection) = WriteVTK.vtk_save(pvd.pvd) """ - addstep!(f::Function, pvd::VTKFileCollection, t::Real, [grid_or_dh]) + addstep!(f::Function, pvd::VTKFileCollection, t::Real, [grid_or_dh]; kwargs...) Add a step at time `t` by writing a `VTKFile` to `pvd`. +The keyword arguments are forwarded to `WriteVTK.vtk_grid`. If required, a new grid can be used by supplying the grid or dofhandler as the last argument. Should be used in a do-block, e.g. ```julia @@ -99,9 +98,9 @@ end close(pvd) ``` """ -function addstep!(f::Function, pvd::VTKFileCollection, t, grid=pvd.grid_or_dh) +function addstep!(f::Function, pvd::VTKFileCollection, t, grid=pvd.grid_or_dh; kwargs...) pvd.step += 1 - VTKFile(string(pvd.name, "_", pvd.step), grid; pvd.vtk_kwargs...) do vtk + VTKFile(string(pvd.name, "_", pvd.step), grid; kwargs...) do vtk f(vtk) pvd.pvd[t] = vtk.vtk # Add to collection end diff --git a/test/test_grid_dofhandler_vtk.jl b/test/test_grid_dofhandler_vtk.jl index 6e824a32ab..ae3c256ce4 100644 --- a/test/test_grid_dofhandler_vtk.jl +++ b/test/test_grid_dofhandler_vtk.jl @@ -650,6 +650,7 @@ end @test sha_vtk1 == sha_vtk2 rm.((fname1, fname2)) end + rm(string(fname, ".pvd")) # Solving https://github.com/Ferrite-FEM/Ferrite.jl/issues/397 # would allow checking the pvd files as well. end @@ -658,8 +659,8 @@ end file_sizes = Int[] fname = "test_collection_kwargs" for compress in (true, false) - pvd = VTKFileCollection(fname, grid; compress) - addstep!(pvd, 0.0) do io + pvd = VTKFileCollection(fname, grid) + addstep!(pvd, 0.0; compress) do io nothing end close(pvd) From 36322e21bb48dc5e809299620c06c799fd136aae Mon Sep 17 00:00:00 2001 From: Knut Andreas Meyer Date: Sun, 7 Jan 2024 19:13:29 +0100 Subject: [PATCH 49/67] Initial work on discontinuous vtk export --- src/Export/VTK.jl | 22 +++++--- src/Export/vtk_discontinuous.jl | 94 +++++++++++++++++++++++++++++++++ testit.jl | 17 ++++++ 3 files changed, 127 insertions(+), 6 deletions(-) create mode 100644 src/Export/vtk_discontinuous.jl create mode 100644 testit.jl diff --git a/src/Export/VTK.jl b/src/Export/VTK.jl index 128c5e12e9..d8556eafc2 100644 --- a/src/Export/VTK.jl +++ b/src/Export/VTK.jl @@ -1,3 +1,4 @@ +include("vtk_discontinuous.jl") """ VTKFile(filename::AbstractString, grid::AbstractGrid; kwargs...) @@ -28,13 +29,14 @@ end """ struct VTKFile{VTK<:WriteVTK.VTKFile} vtk::VTK + write_discontinuous::Bool end function VTKFile(filename::String, dh::DofHandler; kwargs...) return VTKFile(filename, get_grid(dh); kwargs...) end -function VTKFile(filename::String, grid::AbstractGrid; kwargs...) - vtk = create_vtk_grid(filename, grid; kwargs...) - return VTKFile(vtk) +function VTKFile(filename::String, grid::AbstractGrid; write_discontinuous=false, kwargs...) + vtk = create_vtk_grid(filename, grid, write_discontinuous; kwargs...) + return VTKFile(vtk, write_discontinuous) end # Makes it possible to use the `do`-block syntax function VTKFile(f::Function, args...; kwargs...) @@ -189,8 +191,12 @@ function create_vtk_griddata(grid::Grid{dim,C,T}) where {dim,C,T} return coords, cls end -function create_vtk_grid(filename::AbstractString, grid::Grid{dim,C,T}; kwargs...) where {dim,C,T} - coords, cls = create_vtk_griddata(grid) +function create_vtk_grid(filename::AbstractString, grid::Grid{dim,C,T}, write_discontinuous; kwargs...) where {dim,C,T} + if write_discontinuous + coords, cls = create_discontinuous_vtk_griddata(grid) + else + coords, cls = create_vtk_griddata(grid) + end return WriteVTK.vtk_grid(filename, coords, cls; kwargs...) end @@ -250,7 +256,11 @@ sorted by the nodes in the grid. function write_solution(vtk::VTKFile, dh::AbstractDofHandler, u::Vector, suffix="") fieldnames = Ferrite.getfieldnames(dh) # all primary fields for name in fieldnames - data = _evaluate_at_grid_nodes(dh, u, name, #=vtk=# Val(true)) + if vtk.write_discontinuous + data = evaluate_at_discontinuous_vtkgrid_nodes(dh, u, name) + else + data = _evaluate_at_grid_nodes(dh, u, name, #=vtk=# Val(true)) + end _vtk_write_nodedata(vtk.vtk, data, string(name, suffix)) end return vtk diff --git a/src/Export/vtk_discontinuous.jl b/src/Export/vtk_discontinuous.jl new file mode 100644 index 0000000000..a9ee715481 --- /dev/null +++ b/src/Export/vtk_discontinuous.jl @@ -0,0 +1,94 @@ + + + +function create_discontinuous_vtk_griddata(grid::Grid{dim,C,T}) where {dim,C,T} + cls = Vector{WriteVTK.MeshCell}(undef, getncells(grid)) + ncoords = sum(nnodes, getcells(grid)) + coords = zeros(T, dim, ncoords) + icoord = 0 + # Need to have one of the following solution + # 1) Save information cellid => node_rante::UnitRange + # 2) Have access to the DofHandler to create the griddata. + # (This also relies on CellIterator order being stable) + for sdh in CellIterator(grid) + CT = getcelltype(grid, cellid(cell)) + vtk_celltype = Ferrite.cell_to_vtkcell(CT) + cell_coords = getcoordinates(cell) + n = length(cell_coords) + vtk_cellnodes = nodes_to_vtkorder(CT((ntuple(i->i+icoord, n)))) + push!(cls, WriteVTK.MeshCell(vtk_celltype, vtk_cellnodes)) + for x in cell_coords + icoord += 1 + coords[:, icoord] = x + end + end + return coords, cls +end + +function evaluate_at_discontinuous_vtkgrid_nodes(dh::DofHandler, u::Vector, fieldname::Symbol) + # Make sure the field exists + fieldname ∈ getfieldnames(dh) || error("Field $fieldname not found.") + # Figure out the return type (scalar or vector) + field_idx = find_field(dh, fieldname) + ip = getfieldinterpolation(dh, field_idx) + RT = ip isa ScalarInterpolation ? T : Vec{n_components(ip),T} + n_c = n_components(ip) + vtk_dim = n_c == 2 ? 3 : n_c # VTK wants vectors padded to 3D + data = fill(NaN * zero(T), vtk_dim, getnnodes(get_grid(dh))) + # Loop over the subdofhandlers + istart = 0 + for sdh in dh.subdofhandlers + # Check if this sdh contains this field, otherwise continue to the next + field_idx = _find_field(sdh, fieldname) + num_nodes = nnodes_per_cell(getcelltype(sdh))*length(sdh.cellset) + if field_idx === nothing + istart += num_nodes + continue + end + # Set up CellValues with the local node coords as quadrature points + CT = getcelltype(sdh) + ip = getfieldinterpolation(sdh, field_idx) + ip_geo = default_interpolation(CT) + local_node_coords = reference_coordinates(ip_geo) + qr = QuadratureRule{getrefshape(ip)}(zeros(length(local_node_coords)), local_node_coords) + if ip isa VectorizedInterpolation + # TODO: Remove this hack when embedding works... + cv = CellValues(qr, ip.ip, ip_geo) + else + cv = CellValues(qr, ip, ip_geo) + end + drange = dof_range(sdh, field_idx) + # Function barrier + data_view = view(data, :, (istart+1):(istart + num_nodes)) + _evaluate_at_discontinuous_vtkgrid_nodes!(data_view, sdh, u, cv, drange, RT) + istart += num_nodes + end + return data +end + +function _evaluate_at_discontinuous_vtkgrid_nodes!(data::SubArray, sdh::SubDofHandler, + u::Vector{T}, cv::CellValues, drange::UnitRange, ::Type{RT}) where {T, RT} + ue = zeros(T, length(drange)) + # TODO: Remove this hack when embedding works... + if RT <: Vec && function_interpolation(cv) isa ScalarInterpolation + uer = reinterpret(RT, ue) + else + uer = ue + end + inode = 0 + n = nnodes_per_cell(getcells(get_grid(sdh.dh)), first(sdh.cellset)) + for cell in CellIterator(sdh) + # Note: We are only using the shape functions: no reinit!(cv, cell) necessary + @assert getnquadpoints(cv) == length(cell.nodes) + for (i, I) in pairs(drange) + ue[i] = u[cell.dofs[I]] + end + for (qp, nodeid) in pairs(1:n .+ inode) + val = function_value(cv, qp, uer) + data[1:length(val), nodeid] .= val + data[(length(val)+1):end, nodeid] .= 0 # purge the NaN + end + inode += n + end + return data +end \ No newline at end of file diff --git a/testit.jl b/testit.jl new file mode 100644 index 0000000000..35d5a7ec60 --- /dev/null +++ b/testit.jl @@ -0,0 +1,17 @@ +using Ferrite + +grid = generate_grid(Quadrilateral, (20,20)) +dh = DofHandler(grid) +add!(dh, :u, Lagrange{RefQuadrilateral,1}()) +close!(dh) +u = zeros(ndofs(dh)) +apply_analytical!(u, dh, :u, x -> sinpi(x[1])*cospi(x[2])) + +VTKFile("continuous", grid) do vtk + write_solution(vtk, dh, u) +end + +VTKFile("discontinuous", grid; write_discontinuous=true) do vtk + write_solution(vtk, dh, u) +end + From eeb7b55416f4e2e46a3bfedd485356490a2b4300 Mon Sep 17 00:00:00 2001 From: Knut Andreas Meyer Date: Mon, 8 Jan 2024 10:07:08 +0100 Subject: [PATCH 50/67] Initial POC --- src/Export/VTK.jl | 24 +++++++++++++----- src/Export/vtk_discontinuous.jl | 45 ++++++++++++--------------------- testit.jl | 38 +++++++++++++++++++++++++++- 3 files changed, 70 insertions(+), 37 deletions(-) diff --git a/src/Export/VTK.jl b/src/Export/VTK.jl index d8556eafc2..709961728b 100644 --- a/src/Export/VTK.jl +++ b/src/Export/VTK.jl @@ -29,14 +29,21 @@ end """ struct VTKFile{VTK<:WriteVTK.VTKFile} vtk::VTK - write_discontinuous::Bool + cellnodes::Vector{UnitRange{Int}} end function VTKFile(filename::String, dh::DofHandler; kwargs...) + for sdh in dh.subdofhandlers + for ip in sdh.field_interpolations + if is_discontinuous(ip) + return VTKFile(filename, get_grid(dh); write_discontinuous=true, kwargs...) + end + end + end return VTKFile(filename, get_grid(dh); kwargs...) end function VTKFile(filename::String, grid::AbstractGrid; write_discontinuous=false, kwargs...) - vtk = create_vtk_grid(filename, grid, write_discontinuous; kwargs...) - return VTKFile(vtk, write_discontinuous) + vtk, cellnodes = create_vtk_grid(filename, grid, write_discontinuous; kwargs...) + return VTKFile(vtk, cellnodes) end # Makes it possible to use the `do`-block syntax function VTKFile(f::Function, args...; kwargs...) @@ -48,6 +55,8 @@ function VTKFile(f::Function, args...; kwargs...) end end +write_discontinuous(vtk::VTKFile) = length(vtk.cellnodes) > 0 + Base.close(vtk::VTKFile) = WriteVTK.vtk_save(vtk.vtk) function Base.show(io::IO, ::MIME"text/plain", vtk::VTKFile) @@ -193,11 +202,12 @@ end function create_vtk_grid(filename::AbstractString, grid::Grid{dim,C,T}, write_discontinuous; kwargs...) where {dim,C,T} if write_discontinuous - coords, cls = create_discontinuous_vtk_griddata(grid) + coords, cls, cellnodes = create_discontinuous_vtk_griddata(grid) else coords, cls = create_vtk_griddata(grid) + cellnodes = Vector{UnitRange{Int}}(undef, 0) end - return WriteVTK.vtk_grid(filename, coords, cls; kwargs...) + return WriteVTK.vtk_grid(filename, coords, cls; kwargs...), cellnodes end function toparaview!(v, x::Vec{D}) where D @@ -256,8 +266,8 @@ sorted by the nodes in the grid. function write_solution(vtk::VTKFile, dh::AbstractDofHandler, u::Vector, suffix="") fieldnames = Ferrite.getfieldnames(dh) # all primary fields for name in fieldnames - if vtk.write_discontinuous - data = evaluate_at_discontinuous_vtkgrid_nodes(dh, u, name) + if write_discontinuous(vtk) + data = evaluate_at_discontinuous_vtkgrid_nodes(dh, u, name, vtk.cellnodes) else data = _evaluate_at_grid_nodes(dh, u, name, #=vtk=# Val(true)) end diff --git a/src/Export/vtk_discontinuous.jl b/src/Export/vtk_discontinuous.jl index a9ee715481..9534abe94e 100644 --- a/src/Export/vtk_discontinuous.jl +++ b/src/Export/vtk_discontinuous.jl @@ -1,31 +1,26 @@ - - - -function create_discontinuous_vtk_griddata(grid::Grid{dim,C,T}) where {dim,C,T} +function create_discontinuous_vtk_griddata(grid::Grid{dim, C, T}) where {dim, C, T} cls = Vector{WriteVTK.MeshCell}(undef, getncells(grid)) + cellnodes = Vector{UnitRange{Int}}(undef, getncells(grid)) ncoords = sum(nnodes, getcells(grid)) coords = zeros(T, dim, ncoords) icoord = 0 - # Need to have one of the following solution - # 1) Save information cellid => node_rante::UnitRange - # 2) Have access to the DofHandler to create the griddata. - # (This also relies on CellIterator order being stable) - for sdh in CellIterator(grid) + for cell in CellIterator(grid) CT = getcelltype(grid, cellid(cell)) vtk_celltype = Ferrite.cell_to_vtkcell(CT) cell_coords = getcoordinates(cell) n = length(cell_coords) + cellnodes[cellid(cell)] = (1:n) .+ icoord vtk_cellnodes = nodes_to_vtkorder(CT((ntuple(i->i+icoord, n)))) - push!(cls, WriteVTK.MeshCell(vtk_celltype, vtk_cellnodes)) + cls[cellid(cell)] = WriteVTK.MeshCell(vtk_celltype, vtk_cellnodes) for x in cell_coords icoord += 1 coords[:, icoord] = x end end - return coords, cls + return coords, cls, cellnodes end -function evaluate_at_discontinuous_vtkgrid_nodes(dh::DofHandler, u::Vector, fieldname::Symbol) +function evaluate_at_discontinuous_vtkgrid_nodes(dh::DofHandler, u::Vector{T}, fieldname::Symbol, cellnodes) where T # Make sure the field exists fieldname ∈ getfieldnames(dh) || error("Field $fieldname not found.") # Figure out the return type (scalar or vector) @@ -34,17 +29,14 @@ function evaluate_at_discontinuous_vtkgrid_nodes(dh::DofHandler, u::Vector, fiel RT = ip isa ScalarInterpolation ? T : Vec{n_components(ip),T} n_c = n_components(ip) vtk_dim = n_c == 2 ? 3 : n_c # VTK wants vectors padded to 3D - data = fill(NaN * zero(T), vtk_dim, getnnodes(get_grid(dh))) + n_vtk_nodes = maximum(maximum, cellnodes) + data = fill(NaN * zero(T), vtk_dim, n_vtk_nodes) # Loop over the subdofhandlers - istart = 0 for sdh in dh.subdofhandlers # Check if this sdh contains this field, otherwise continue to the next field_idx = _find_field(sdh, fieldname) - num_nodes = nnodes_per_cell(getcelltype(sdh))*length(sdh.cellset) - if field_idx === nothing - istart += num_nodes - continue - end + field_idx === nothing && continue + # Set up CellValues with the local node coords as quadrature points CT = getcelltype(sdh) ip = getfieldinterpolation(sdh, field_idx) @@ -59,15 +51,13 @@ function evaluate_at_discontinuous_vtkgrid_nodes(dh::DofHandler, u::Vector, fiel end drange = dof_range(sdh, field_idx) # Function barrier - data_view = view(data, :, (istart+1):(istart + num_nodes)) - _evaluate_at_discontinuous_vtkgrid_nodes!(data_view, sdh, u, cv, drange, RT) - istart += num_nodes + _evaluate_at_discontinuous_vtkgrid_nodes!(data, sdh, u, cv, drange, RT, cellnodes) end return data end -function _evaluate_at_discontinuous_vtkgrid_nodes!(data::SubArray, sdh::SubDofHandler, - u::Vector{T}, cv::CellValues, drange::UnitRange, ::Type{RT}) where {T, RT} +function _evaluate_at_discontinuous_vtkgrid_nodes!(data::Matrix, sdh::SubDofHandler, + u::Vector{T}, cv::CellValues, drange::UnitRange, ::Type{RT}, cellnodes) where {T, RT} ue = zeros(T, length(drange)) # TODO: Remove this hack when embedding works... if RT <: Vec && function_interpolation(cv) isa ScalarInterpolation @@ -75,20 +65,17 @@ function _evaluate_at_discontinuous_vtkgrid_nodes!(data::SubArray, sdh::SubDofHa else uer = ue end - inode = 0 - n = nnodes_per_cell(getcells(get_grid(sdh.dh)), first(sdh.cellset)) for cell in CellIterator(sdh) # Note: We are only using the shape functions: no reinit!(cv, cell) necessary @assert getnquadpoints(cv) == length(cell.nodes) for (i, I) in pairs(drange) ue[i] = u[cell.dofs[I]] end - for (qp, nodeid) in pairs(1:n .+ inode) + for (qp, nodeid) in pairs(cellnodes[cellid(cell)]) val = function_value(cv, qp, uer) data[1:length(val), nodeid] .= val data[(length(val)+1):end, nodeid] .= 0 # purge the NaN end - inode += n end return data -end \ No newline at end of file +end diff --git a/testit.jl b/testit.jl index 35d5a7ec60..792072208e 100644 --- a/testit.jl +++ b/testit.jl @@ -5,7 +5,9 @@ dh = DofHandler(grid) add!(dh, :u, Lagrange{RefQuadrilateral,1}()) close!(dh) u = zeros(ndofs(dh)) -apply_analytical!(u, dh, :u, x -> sinpi(x[1])*cospi(x[2])) +f(x) = sinpi(x[1])*cospi(x[2]) +f(x) = x[1] + x[2] +apply_analytical!(u, dh, :u, f) VTKFile("continuous", grid) do vtk write_solution(vtk, dh, u) @@ -15,3 +17,37 @@ VTKFile("discontinuous", grid; write_discontinuous=true) do vtk write_solution(vtk, dh, u) end +dh = DofHandler(grid) +ip = DiscontinuousLagrange{RefQuadrilateral,1}() +add!(dh, :u, ip) +close!(dh) + +function calculate_u(dh, ip, fun) + u = zeros(ndofs(dh)) + ref_points = Ferrite.reference_coordinates(ip) + qr = QuadratureRule{RefQuadrilateral}(zeros(length(ref_points)), ref_points) + cv = CellValues(qr, ip) + for cell in CellIterator(dh) + reinit!(cv, cell) + for q_point in 1:getnquadpoints(qr) + x = spatial_coordinate(cv, q_point, getcoordinates(cell)) + v = fun(x) + u[celldofs(cell)[q_point]] = v + cellid(cell)/getncells(dh.grid) + end + end + return u +end + +u = calculate_u(dh, ip, f) + +VTKFile("really_discontinuous", grid; write_discontinuous=true) do vtk + write_solution(vtk, dh, u) +end + +VTKFile("not_discontinuous", grid) do vtk + write_solution(vtk, dh, u) +end + +VTKFile("really_discontinuous_auto", dh) do vtk + write_solution(vtk, dh, u) +end From d1020fda69777674866b1813fcd5d07fb83aafc4 Mon Sep 17 00:00:00 2001 From: Knut Andreas Meyer Date: Mon, 8 Jan 2024 10:21:29 +0100 Subject: [PATCH 51/67] Update DG example to new syntax --- docs/src/literate-tutorials/dg_heat_equation.jl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/src/literate-tutorials/dg_heat_equation.jl b/docs/src/literate-tutorials/dg_heat_equation.jl index c1c1f0fb16..de40c2f4f8 100644 --- a/docs/src/literate-tutorials/dg_heat_equation.jl +++ b/docs/src/literate-tutorials/dg_heat_equation.jl @@ -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 From 5301307dd3d28a7586d7ea0b6e7c7dec40719bea Mon Sep 17 00:00:00 2001 From: Knut Andreas Meyer Date: Fri, 1 Mar 2024 15:51:01 +0100 Subject: [PATCH 52/67] Fix docs --- docs/src/topics/export.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/src/topics/export.md b/docs/src/topics/export.md index 1f89aea5b0..e44f922dc3 100644 --- a/docs/src/topics/export.md +++ b/docs/src/topics/export.md @@ -46,7 +46,7 @@ for each time step. In order to connect the actual time with each of these files a `VTKFileCollection` can be used, which will write one paraview datafile (`.pvd`) file and one `VTKFile` (`.vtu`) for each time step. -```@example pvdexport +```@example export pvd = VTKFileCollection("my_results", grid) for t in range(0, 1, 5) # Do calculations to update u From d6f2edee39747c66dacb93dfbaabf3dceda050a8 Mon Sep 17 00:00:00 2001 From: Knut Andreas Meyer Date: Fri, 26 Apr 2024 08:49:40 +0200 Subject: [PATCH 53/67] using VTKCellTypes explicitly --- src/Ferrite.jl | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Ferrite.jl b/src/Ferrite.jl index 93a90b3786..a2cb741fc8 100644 --- a/src/Ferrite.jl +++ b/src/Ferrite.jl @@ -16,11 +16,12 @@ using SparseArrays: SparseArrays, SparseMatrixCSC, nonzeros, nzrange, rowvals, sparse, spzeros using StaticArrays: StaticArrays, MMatrix, SMatrix, SVector +using WriteVTK: + WriteVTK, VTKCellTypes using Tensors: Tensors, AbstractTensor, SecondOrderTensor, SymmetricTensor, Tensor, Vec, gradient, rotation_tensor, symmetric, tovoigt! -import WriteVTK include("exports.jl") From f55c932d6e2c0755bfc8f337cc664e35aecce16e Mon Sep 17 00:00:00 2001 From: Knut Andreas Meyer Date: Fri, 26 Apr 2024 08:55:18 +0200 Subject: [PATCH 54/67] Change to using WriteVTK: vtk_grid --- src/deprecations.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/deprecations.jl b/src/deprecations.jl index c7dfe7c3a5..e5a8824843 100644 --- a/src/deprecations.jl +++ b/src/deprecations.jl @@ -59,7 +59,7 @@ Base.@deprecate_binding Line3D Line Base.@deprecate_binding Quadrilateral3D Quadrilateral export Line2D, Line3D, Quadrilateral3D -import WriteVTK: vtk_grid +using WriteVTK: vtk_grid export vtk_grid # To give better error function WriteVTK.vtk_grid(::String, ::Union{AbstractGrid,AbstractDofHandler}; kwargs...) From 692cf786be4e6d6463f67a5ec97c1687eb5ce3cd Mon Sep 17 00:00:00 2001 From: Knut Andreas Meyer Date: Sun, 19 May 2024 12:48:13 +0200 Subject: [PATCH 55/67] Apply suggestions from code review Co-authored-by: Fredrik Ekre --- test/runtests.jl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/runtests.jl b/test/runtests.jl index 6052ff1c05..f864f31b9a 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -40,9 +40,9 @@ include("test_interfacevalues.jl") include("test_quadrules.jl") include("test_assemble.jl") include("test_dofs.jl") -include("test_constraints.jl") +include("test_constraints.jl") include("test_grid_dofhandler_vtk.jl") -include("test_abstractgrid.jl") +include("test_abstractgrid.jl") include("test_grid_addboundaryset.jl") include("test_mixeddofhandler.jl") include("test_l2_projection.jl") From 4e84b76f7c6c2baaf858a240fdbb51ef27e5b218 Mon Sep 17 00:00:00 2001 From: Knut Andreas Meyer Date: Sun, 19 May 2024 12:53:29 +0200 Subject: [PATCH 56/67] write_cell_colors -> write_cellcolors --- docs/src/literate-howto/threaded_assembly.jl | 4 ++-- docs/src/reference/export.md | 2 +- docs/src/topics/export.md | 2 +- src/Export/VTK.jl | 4 ++-- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/docs/src/literate-howto/threaded_assembly.jl b/docs/src/literate-howto/threaded_assembly.jl index 2f21fb33b1..5af5c6a068 100644 --- a/docs/src/literate-howto/threaded_assembly.jl +++ b/docs/src/literate-howto/threaded_assembly.jl @@ -26,8 +26,8 @@ function create_example_2d_grid() colors_workstream = create_coloring(grid; alg=ColoringAlgorithm.WorkStream) colors_greedy = create_coloring(grid; alg=ColoringAlgorithm.Greedy) 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") + Ferrite.write_cellcolors(vtk, grid, colors_workstream, "workstream-coloring") + Ferrite.write_cellcolors(vtk, grid, colors_greedy, "greedy-coloring") end end diff --git a/docs/src/reference/export.md b/docs/src/reference/export.md index 44268714bf..5a72c88ee1 100644 --- a/docs/src/reference/export.md +++ b/docs/src/reference/export.md @@ -35,5 +35,5 @@ write_nodedata Ferrite.write_cellset Ferrite.write_nodeset Ferrite.write_dirichlet -Ferrite.write_cell_colors +Ferrite.write_cellcolors ``` diff --git a/docs/src/topics/export.md b/docs/src/topics/export.md index e44f922dc3..89d7ebf56c 100644 --- a/docs/src/topics/export.md +++ b/docs/src/topics/export.md @@ -29,7 +29,7 @@ where `write_solution` is just one example of the following functions that can b * [`Ferrite.write_cellset`](@ref) * [`Ferrite.write_nodeset`](@ref) * [`Ferrite.write_dirichlet`](@ref) -* [`Ferrite.write_cell_colors`](@ref) +* [`Ferrite.write_cellcolors`](@ref) Instead of using the `do`-block, it is also possible to do ```@example export diff --git a/src/Export/VTK.jl b/src/Export/VTK.jl index 180e9882ca..2f95447ac6 100644 --- a/src/Export/VTK.jl +++ b/src/Export/VTK.jl @@ -367,13 +367,13 @@ function write_dirichlet(vtk, ch::ConstraintHandler) end """ - write_cell_colors(vtk::VTKFile, grid::AbstractGrid, cell_colors, name="coloring") + write_cellcolors(vtk::VTKFile, grid::AbstractGrid, cell_colors, name="coloring") Write cell colors (see [`create_coloring`](@ref)) to a VTK file for visualization. In case of coloring a subset, the cells which are not part of the subset are represented as color 0. """ -function write_cell_colors(vtk, grid::AbstractGrid, cell_colors::AbstractVector{<:AbstractVector{<:Integer}}, name="coloring") +function write_cellcolors(vtk, grid::AbstractGrid, cell_colors::AbstractVector{<:AbstractVector{<:Integer}}, name="coloring") color_vector = zeros(Int, getncells(grid)) for (i, cells_color) in enumerate(cell_colors) for cell in cells_color From acad0dafb83432e907267f9dd118f94d39f7f8dc Mon Sep 17 00:00:00 2001 From: Knut Andreas Meyer Date: Sun, 19 May 2024 12:54:17 +0200 Subject: [PATCH 57/67] write_dirichlet -> write_constraints --- docs/src/reference/export.md | 2 +- docs/src/topics/export.md | 2 +- src/Export/VTK.jl | 6 +++--- test/test_grid_dofhandler_vtk.jl | 2 +- test/test_mixeddofhandler.jl | 2 +- 5 files changed, 7 insertions(+), 7 deletions(-) diff --git a/docs/src/reference/export.md b/docs/src/reference/export.md index 5a72c88ee1..6adab45a1f 100644 --- a/docs/src/reference/export.md +++ b/docs/src/reference/export.md @@ -34,6 +34,6 @@ write_celldata write_nodedata Ferrite.write_cellset Ferrite.write_nodeset -Ferrite.write_dirichlet +Ferrite.write_constraints Ferrite.write_cellcolors ``` diff --git a/docs/src/topics/export.md b/docs/src/topics/export.md index 89d7ebf56c..b61bcfed40 100644 --- a/docs/src/topics/export.md +++ b/docs/src/topics/export.md @@ -28,7 +28,7 @@ where `write_solution` is just one example of the following functions that can b * [`write_projection`](@ref) * [`Ferrite.write_cellset`](@ref) * [`Ferrite.write_nodeset`](@ref) -* [`Ferrite.write_dirichlet`](@ref) +* [`Ferrite.write_constraints`](@ref) * [`Ferrite.write_cellcolors`](@ref) Instead of using the `do`-block, it is also possible to do diff --git a/src/Export/VTK.jl b/src/Export/VTK.jl index 2f95447ac6..a6447f13cc 100644 --- a/src/Export/VTK.jl +++ b/src/Export/VTK.jl @@ -15,7 +15,7 @@ This file handler can be used to to write data with * [`write_nodedata`](@ref). * [`Ferrite.write_cellset`](@ref) * [`Ferrite.write_nodeset`](@ref) -* [`Ferrite.write_dirichlet`](@ref) +* [`Ferrite.write_constraints`](@ref) It is necessary to call `close(::VTKFile)` to save the data after writing to the file handler. Using the supported `do`-block does this automatically: @@ -327,12 +327,12 @@ end write_cellset(vtk, grid::AbstractGrid, cellset::String) = write_cellset(vtk, grid, [cellset]) """ - write_dirichlet(vtk::VTKFile, ch::ConstraintHandler) + write_constraints(vtk::VTKFile, ch::ConstraintHandler) Saves the dirichlet boundary conditions to a vtkfile. Values will have a 1 where bcs are active and 0 otherwise """ -function write_dirichlet(vtk, ch::ConstraintHandler) +function write_constraints(vtk, ch::ConstraintHandler) unique_fields = [] for dbc in ch.dbcs push!(unique_fields, dbc.field_name) diff --git a/test/test_grid_dofhandler_vtk.jl b/test/test_grid_dofhandler_vtk.jl index 7da0d6a63a..7cc4d6e593 100644 --- a/test/test_grid_dofhandler_vtk.jl +++ b/test/test_grid_dofhandler_vtk.jl @@ -78,7 +78,7 @@ end dofhandlerfilename = "dofhandler-$(repr(celltype))" VTKFile(dofhandlerfilename, grid) do vtk - Ferrite.write_dirichlet(vtk, ch) + Ferrite.write_constraints(vtk, ch) write_solution(vtk, dofhandler, u) end diff --git a/test/test_mixeddofhandler.jl b/test/test_mixeddofhandler.jl index 5369837316..c9a0b50603 100644 --- a/test/test_mixeddofhandler.jl +++ b/test/test_mixeddofhandler.jl @@ -361,7 +361,7 @@ function test_2_element_heat_eq() Ferrite.write_cellset(vtk, grid, "cell-1") Ferrite.write_cellset(vtk, grid, "cell-2") write_solution(vtk, dh, u) - # Ferrite.write_dirichlet(vtk, ch) #FIXME + # Ferrite.write_constraints(vtk, ch) #FIXME end sha = bytes2hex(open(SHA.sha1, gridfilename*".vtu")) @test sha in ("e96732c000b0b385db7444f002461468b60b3b2c", "7b26edc27b5e59a2f60907374cd5a5790cc37a6a") From 819bef61cce6d13045668d0f2751bb3d4a53efb0 Mon Sep 17 00:00:00 2001 From: Knut Andreas Meyer Date: Sun, 19 May 2024 14:03:04 +0200 Subject: [PATCH 58/67] Add missing tests for vtk export --- test/runtests.jl | 1 + test/test_vtk_export.jl | 46 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 47 insertions(+) create mode 100644 test/test_vtk_export.jl diff --git a/test/runtests.jl b/test/runtests.jl index f864f31b9a..3d6498c011 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -42,6 +42,7 @@ include("test_assemble.jl") include("test_dofs.jl") include("test_constraints.jl") include("test_grid_dofhandler_vtk.jl") +include("test_vtk_export.jl") include("test_abstractgrid.jl") include("test_grid_addboundaryset.jl") include("test_mixeddofhandler.jl") diff --git a/test/test_vtk_export.jl b/test/test_vtk_export.jl new file mode 100644 index 0000000000..919efb5fc4 --- /dev/null +++ b/test/test_vtk_export.jl @@ -0,0 +1,46 @@ + +@testset "VTKFile" begin + #TODO: Move all vtk tests here + @testset "show(::VTKFile)" begin + mktempdir() do tmp + grid = generate_grid(Quadrilateral, (2,2)) + vtk = VTKFile(joinpath(tmp, "showfile"), grid) + showstring_open = sprint(show, MIME"text/plain"(), vtk) + @test startswith(showstring_open, "VTKFile for the open file") + @test contains(showstring_open, "showfile.vtu") + close(vtk) + showstring_closed = sprint(show, MIME"text/plain"(), vtk) + @test startswith(showstring_closed, "VTKFile for the closed file") + @test contains(showstring_closed, "showfile.vtu") + end + end + @testset "cellcolors" begin + mktempdir() do tmp + grid = generate_grid(Quadrilateral, (4, 4)) + colors = create_coloring(grid) + fname = joinpath(tmp, "colors") + VTKFile(fname, grid) do vtk + Ferrite.write_cellcolors(vtk, grid, colors) + end + @test bytes2hex(open(SHA.sha1, fname*".vtu")) == "b804d0b064121b672d8e35bcff8446eda361cac3" + end + end + @testset "constraints" begin + mktempdir() do tmp + grid = generate_grid(Tetrahedron, (4, 4, 4)) + dh = DofHandler(grid) + add!(dh, :u, Lagrange{RefTetrahedron, 1}()) + close!(dh) + ch = ConstraintHandler(dh) + add!(ch, Dirichlet(:u, getfacetset(grid, "left"), x -> 0.0)) + addnodeset!(grid, "nodeset", x -> x[1] ≈ 1.0) + add!(ch, Dirichlet(:u, getnodeset(grid, "nodeset"), x -> 0.0)) + close!(ch) + fname = joinpath(tmp, "constraints") + VTKFile(fname, grid) do vtk + Ferrite.write_constraints(vtk, ch) + end + @test bytes2hex(open(SHA.sha1, fname*".vtu")) == "31b506bd9729b11992f8bcb79a2191eb65d223bf" + end + end +end \ No newline at end of file From e405b384928b39ad25311c145347287451389b3b Mon Sep 17 00:00:00 2001 From: Knut Andreas Meyer Date: Sun, 19 May 2024 14:26:54 +0200 Subject: [PATCH 59/67] Test deprecation error --- test/test_deprecations.jl | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/test/test_deprecations.jl b/test/test_deprecations.jl index 9547bfea8c..3e7a731eae 100644 --- a/test/test_deprecations.jl +++ b/test/test_deprecations.jl @@ -96,4 +96,9 @@ addfaceset!(grid, "right_face_explicit", Set(Ferrite.FaceIndex(fi[1], fi[2]) for @test getfacetset(grid, "right_face_explicit") == getfacetset(grid, "right") end +@testset "vtk_grid" begin + # Ensure no MethodError on pre v1. + @test_throws ErrorException vtk_grid("old", generate_grid(Line, (1,))) +end + end # testset deprecations From 20668efe52689639dc930eb3a34bb7d6f3dce2dc Mon Sep 17 00:00:00 2001 From: Knut Andreas Meyer Date: Sun, 19 May 2024 14:33:41 +0200 Subject: [PATCH 60/67] Format test file --- test/test_vtk_export.jl | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/test/test_vtk_export.jl b/test/test_vtk_export.jl index 919efb5fc4..c9a329548f 100644 --- a/test/test_vtk_export.jl +++ b/test/test_vtk_export.jl @@ -1,6 +1,4 @@ - -@testset "VTKFile" begin - #TODO: Move all vtk tests here +@testset "VTKFile" begin #TODO: Move all vtk tests here @testset "show(::VTKFile)" begin mktempdir() do tmp grid = generate_grid(Quadrilateral, (2,2)) @@ -43,4 +41,4 @@ @test bytes2hex(open(SHA.sha1, fname*".vtu")) == "31b506bd9729b11992f8bcb79a2191eb65d223bf" end end -end \ No newline at end of file +end From 5a0b4fbe82456277395ce7763847620337c12a66 Mon Sep 17 00:00:00 2001 From: Knut Andreas Meyer Date: Sun, 19 May 2024 14:39:12 +0200 Subject: [PATCH 61/67] Add changelog entry --- CHANGELOG.md | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 69acecbf52..655e399460 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -190,6 +190,11 @@ more discussion). + add!(dh, :u, Lagrange{RefTriangle, 1}()) ``` +- **VTK export**: Ferrite no longer extends methods from `WriteVTK.jl`, instead the new types + `VTKFile` and `VTKFileCollection` should be used instead. New methods exists for writing to + a `VTKFile`, e.g. `write_solution`, `write_celldata`, `write_nodedata`, and `write_projection`. + See [#692][github-692]. + ### Added - `InterfaceValues` for computing jumps and averages over interfaces. ([#743][github-743]) @@ -858,6 +863,7 @@ poking into Ferrite internals: [github-684]: https://github.com/Ferrite-FEM/Ferrite.jl/pull/684 [github-687]: https://github.com/Ferrite-FEM/Ferrite.jl/pull/687 [github-688]: https://github.com/Ferrite-FEM/Ferrite.jl/pull/688 +[github-692]: https://github.com/Ferrite-FEM/Ferrite.jl/pull/692 [github-694]: https://github.com/Ferrite-FEM/Ferrite.jl/pull/694 [github-695]: https://github.com/Ferrite-FEM/Ferrite.jl/pull/695 [github-697]: https://github.com/Ferrite-FEM/Ferrite.jl/pull/697 @@ -896,4 +902,3 @@ poking into Ferrite internals: [github-835]: https://github.com/Ferrite-FEM/Ferrite.jl/pull/835 [github-855]: https://github.com/Ferrite-FEM/Ferrite.jl/pull/855 [github-880]: https://github.com/Ferrite-FEM/Ferrite.jl/pull/880 - From c69b9c65b493637f62e55c4ad80cf05ebdbc3775 Mon Sep 17 00:00:00 2001 From: Knut Andreas Meyer Date: Sun, 19 May 2024 14:55:11 +0200 Subject: [PATCH 62/67] Remove old mentions of "stream" in docstrings --- src/Export/VTK.jl | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Export/VTK.jl b/src/Export/VTK.jl index a6447f13cc..474f4b2336 100644 --- a/src/Export/VTK.jl +++ b/src/Export/VTK.jl @@ -238,7 +238,7 @@ end """ write_solution(vtk::VTKFile, dh::AbstractDofHandler, u::Vector, suffix="") -Save the values at the nodes in the degree of freedom vector `u` to the stream. +Save the values at the nodes in the degree of freedom vector `u` to `vtk`. Each field in `dh` will be saved separately, and `suffix` can be used to append to the fieldname. @@ -259,7 +259,7 @@ end """ write_projection(vtk::VTKFile, proj::L2Projector, vals::Vector, name::AbstractString) -Project `vals` to the grid nodes with `proj` and save to the stream. +Project `vals` to the grid nodes with `proj` and save to `vtk`. """ function write_projection(vtk::VTKFile, proj::L2Projector, vals, name) data = _evaluate_at_grid_nodes(proj, vals, #=vtk=# Val(true))::Matrix @@ -281,7 +281,7 @@ end write_nodedata(vtk::VTKFile, nodedata::Vector{Real}, name) write_nodedata(vtk::VTKFile, nodedata::Vector{<:AbstractTensor}, name) -Write the `nodedata` that is ordered by the nodes in the grid to the vtk stream. +Write the `nodedata` that is ordered by the nodes in the grid to `vtk`. When `nodedata` contains `Tensors.Vec`s, each component is exported. Two-dimensional vectors are padded with zeros. From d6a199e1c937277a22a6550cf86907f5415a91ee Mon Sep 17 00:00:00 2001 From: Knut Andreas Meyer Date: Sun, 19 May 2024 18:20:06 +0200 Subject: [PATCH 63/67] Add underscores to some names --- CHANGELOG.md | 2 +- .../literate-gallery/topology_optimization.jl | 4 +- docs/src/literate-howto/threaded_assembly.jl | 4 +- .../incompressible_elasticity.jl | 4 +- docs/src/literate-tutorials/plasticity.jl | 4 +- docs/src/reference/export.md | 6 +-- docs/src/topics/export.md | 8 ++-- src/Export/VTK.jl | 48 +++++++++---------- src/deprecations.jl | 2 +- src/exports.jl | 4 +- test/test_grid_dofhandler_vtk.jl | 18 +++---- test/test_vtk_export.jl | 2 +- 12 files changed, 53 insertions(+), 53 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 655e399460..dfd8bacd81 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -192,7 +192,7 @@ more discussion). - **VTK export**: Ferrite no longer extends methods from `WriteVTK.jl`, instead the new types `VTKFile` and `VTKFileCollection` should be used instead. New methods exists for writing to - a `VTKFile`, e.g. `write_solution`, `write_celldata`, `write_nodedata`, and `write_projection`. + a `VTKFile`, e.g. `write_solution`, `write_cell_data`, `write_node_data`, and `write_projection`. See [#692][github-692]. ### Added diff --git a/docs/src/literate-gallery/topology_optimization.jl b/docs/src/literate-gallery/topology_optimization.jl index c23049c84f..e3b2c154f2 100644 --- a/docs/src/literate-gallery/topology_optimization.jl +++ b/docs/src/literate-gallery/topology_optimization.jl @@ -493,7 +493,7 @@ function topopt(ra,ρ,n,filename; output=:false) filename_it = string(filename, "_", i) VTKFile(filename_it, grid) do vtk - write_celldata(vtk, χ, "density") + write_cell_data(vtk, χ, "density") end end end @@ -501,7 +501,7 @@ function topopt(ra,ρ,n,filename; output=:false) ## export converged results if(!output) VTKFile(filename, grid) do vtk - write_celldata(vtk, χ, "density") + write_cell_data(vtk, χ, "density") end end @printf "Rel. stiffness: %.4f \n" compliance^(-1)/compliance_0^(-1) diff --git a/docs/src/literate-howto/threaded_assembly.jl b/docs/src/literate-howto/threaded_assembly.jl index 5af5c6a068..2f21fb33b1 100644 --- a/docs/src/literate-howto/threaded_assembly.jl +++ b/docs/src/literate-howto/threaded_assembly.jl @@ -26,8 +26,8 @@ function create_example_2d_grid() colors_workstream = create_coloring(grid; alg=ColoringAlgorithm.WorkStream) colors_greedy = create_coloring(grid; alg=ColoringAlgorithm.Greedy) VTKFile("colored", grid) do vtk - Ferrite.write_cellcolors(vtk, grid, colors_workstream, "workstream-coloring") - Ferrite.write_cellcolors(vtk, grid, colors_greedy, "greedy-coloring") + Ferrite.write_cell_colors(vtk, grid, colors_workstream, "workstream-coloring") + Ferrite.write_cell_colors(vtk, grid, colors_greedy, "greedy-coloring") end end diff --git a/docs/src/literate-tutorials/incompressible_elasticity.jl b/docs/src/literate-tutorials/incompressible_elasticity.jl index e1c0a08e09..14a1e0c69a 100644 --- a/docs/src/literate-tutorials/incompressible_elasticity.jl +++ b/docs/src/literate-tutorials/incompressible_elasticity.jl @@ -275,9 +275,9 @@ function solve(ν, interpolation_u, interpolation_p) write_solution(vtk, dh, u) for i in 1:3, j in 1:3 σij = [x[i, j] for x in σ] - write_celldata(vtk, σij, "sigma_$(i)$(j)") + write_cell_data(vtk, σij, "sigma_$(i)$(j)") end - write_celldata(vtk, σvM, "sigma von Mises") + write_cell_data(vtk, σvM, "sigma von Mises") end return u end diff --git a/docs/src/literate-tutorials/plasticity.jl b/docs/src/literate-tutorials/plasticity.jl index 4dd210271c..6b34be0e2e 100644 --- a/docs/src/literate-tutorials/plasticity.jl +++ b/docs/src/literate-tutorials/plasticity.jl @@ -346,8 +346,8 @@ function solve() end 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]") + write_cell_data(vtk, mises_values, "von Mises [Pa]") + write_cell_data(vtk, κ_values, "Drag stress [Pa]") end return u_max, traction_magnitude diff --git a/docs/src/reference/export.md b/docs/src/reference/export.md index 6adab45a1f..81a77e1cc9 100644 --- a/docs/src/reference/export.md +++ b/docs/src/reference/export.md @@ -30,10 +30,10 @@ VTKFileCollection addstep! write_solution write_projection -write_celldata -write_nodedata +write_cell_data +write_node_data Ferrite.write_cellset Ferrite.write_nodeset Ferrite.write_constraints -Ferrite.write_cellcolors +Ferrite.write_cell_colors ``` diff --git a/docs/src/topics/export.md b/docs/src/topics/export.md index b61bcfed40..702561f522 100644 --- a/docs/src/topics/export.md +++ b/docs/src/topics/export.md @@ -23,13 +23,13 @@ end; where `write_solution` is just one example of the following functions that can be used * [`write_solution`](@ref) -* [`write_celldata`](@ref) -* [`write_nodedata`](@ref) +* [`write_cell_data`](@ref) +* [`write_node_data`](@ref) * [`write_projection`](@ref) * [`Ferrite.write_cellset`](@ref) * [`Ferrite.write_nodeset`](@ref) * [`Ferrite.write_constraints`](@ref) -* [`Ferrite.write_cellcolors`](@ref) +* [`Ferrite.write_cell_colors`](@ref) Instead of using the `do`-block, it is also possible to do ```@example export @@ -39,7 +39,7 @@ write_solution(vtk, dh, u) close(vtk); ``` -The data written by `write_solution`, `write_celldata`, `write_nodedata`, and `write_projection` may be either scalar (`Vector{<:Number}`) or tensor (`Vector{<:AbstractTensor}`) data. +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, diff --git a/src/Export/VTK.jl b/src/Export/VTK.jl index 474f4b2336..5df796035f 100644 --- a/src/Export/VTK.jl +++ b/src/Export/VTK.jl @@ -10,9 +10,9 @@ The keyword arguments are forwarded to `WriteVTK.vtk_grid`, see This file handler can be used to to write data with * [`write_solution`](@ref) -* [`write_celldata`](@ref) +* [`write_cell_data`](@ref) * [`write_projection`](@ref) -* [`write_nodedata`](@ref). +* [`write_node_data`](@ref). * [`Ferrite.write_cellset`](@ref) * [`Ferrite.write_nodeset`](@ref) * [`Ferrite.write_constraints`](@ref) @@ -22,7 +22,7 @@ to the file handler. Using the supported `do`-block does this automatically: ```julia VTKFile(filename, grid) do vtk write_solution(vtk, dh, u) - write_celldata(vtk, celldata) + write_cell_data(vtk, celldata) end ``` """ @@ -91,7 +91,7 @@ pvd = VTKFileCollection(filename, grid) for (n, t) in pairs(timevector) # Calculate, e.g., the solution `u` and the stress `σeff` addstep!(pvd, t) do io - write_celldata(io, σeff, "Effective stress") + write_cell_data(io, σeff, "Effective stress") write_solution(io, dh, u) end end @@ -118,7 +118,7 @@ pvd = VTKFileCollection(filename, grid) for (n, t) in pairs(timevector) # Calculate, e.g., the solution `u` and the stress `σeff` vtk = VTKFile(string(filename, "_", n), dh) - write_celldata(vtk, σeff, "Effective stress") + write_cell_data(vtk, σeff, "Effective stress") write_solution(vtk, dh, u) addstep!(pvd, vtk, t) end @@ -201,7 +201,7 @@ function toparaview!(v, x::SecondOrderTensor) tovoigt!(v, x) end -function _vtk_write_nodedata( +function _vtk_write_node_data( vtk::WriteVTK.DatasetFile, nodedata::Vector{S}, name::AbstractString @@ -214,10 +214,10 @@ function _vtk_write_nodedata( end return WriteVTK.vtk_point_data(vtk, out, name; component_names=component_names(S)) end -function _vtk_write_nodedata(vtk::WriteVTK.DatasetFile, nodedata::Vector{<:Real}, name::AbstractString) +function _vtk_write_node_data(vtk::WriteVTK.DatasetFile, nodedata::Vector{<:Real}, name::AbstractString) return WriteVTK.vtk_point_data(vtk, nodedata, name) end -function _vtk_write_nodedata(vtk::WriteVTK.DatasetFile, nodedata::Matrix{<:Real}, name::AbstractString; component_names=nothing) +function _vtk_write_node_data(vtk::WriteVTK.DatasetFile, nodedata::Matrix{<:Real}, name::AbstractString; component_names=nothing) return WriteVTK.vtk_point_data(vtk, nodedata, name; component_names=component_names) end @@ -243,15 +243,15 @@ Each field in `dh` will be saved separately, and `suffix` can be used to append to the fieldname. `u` can also contain tensorial values, but each entry in `u` must correspond to a -degree of freedom in `dh`, see [`write_nodedata`](@ref write_nodedata) for details. -Use `write_nodedata` directly when exporting values that are already +degree of freedom in `dh`, see [`write_node_data`](@ref write_node_data) for details. +Use `write_node_data` directly when exporting values that are already sorted by the nodes in the grid. """ function write_solution(vtk::VTKFile, dh::AbstractDofHandler, u::Vector, suffix="") fieldnames = Ferrite.getfieldnames(dh) # all primary fields for name in fieldnames data = _evaluate_at_grid_nodes(dh, u, name, #=vtk=# Val(true)) - _vtk_write_nodedata(vtk.vtk, data, string(name, suffix)) + _vtk_write_node_data(vtk.vtk, data, string(name, suffix)) end return vtk end @@ -264,22 +264,22 @@ Project `vals` to the grid nodes with `proj` and save to `vtk`. function write_projection(vtk::VTKFile, proj::L2Projector, vals, name) data = _evaluate_at_grid_nodes(proj, vals, #=vtk=# Val(true))::Matrix @assert size(data, 2) == getnnodes(get_grid(proj.dh)) - _vtk_write_nodedata(vtk.vtk, data, name; component_names=component_names(eltype(vals))) + _vtk_write_node_data(vtk.vtk, data, name; component_names=component_names(eltype(vals))) return vtk end """ - write_celldata(vtk::VTKFile, celldata::AbstractVector, name::String) + write_cell_data(vtk::VTKFile, celldata::AbstractVector, name::String) Write the `celldata` that is ordered by the cells in the grid to the vtk file. """ -function write_celldata(vtk::VTKFile, celldata, name) +function write_cell_data(vtk::VTKFile, celldata, name) WriteVTK.vtk_cell_data(vtk.vtk, celldata, name) end """ - write_nodedata(vtk::VTKFile, nodedata::Vector{Real}, name) - write_nodedata(vtk::VTKFile, nodedata::Vector{<:AbstractTensor}, name) + write_node_data(vtk::VTKFile, nodedata::Vector{Real}, name) + write_node_data(vtk::VTKFile, nodedata::Vector{<:AbstractTensor}, name) Write the `nodedata` that is ordered by the nodes in the grid to `vtk`. @@ -289,8 +289,8 @@ Two-dimensional vectors are padded with zeros. When `nodedata` contains second order tensors, the index order, `[11, 22, 33, 23, 13, 12, 32, 31, 21]`, follows the default Voigt order in Tensors.jl. """ -function write_nodedata(vtk::VTKFile, nodedata, name) - _vtk_write_nodedata(vtk.vtk, nodedata, name) +function write_node_data(vtk::VTKFile, nodedata, name) + _vtk_write_node_data(vtk.vtk, nodedata, name) end @@ -302,7 +302,7 @@ Write nodal values of 1 for nodes in `nodeset`, and 0 otherwise function write_nodeset(vtk, grid::AbstractGrid, nodeset::String) z = zeros(getnnodes(grid)) z[collect(getnodeset(grid, nodeset))] .= 1.0 - write_nodedata(vtk, z, nodeset) + write_node_data(vtk, z, nodeset) return vtk end @@ -320,7 +320,7 @@ function write_cellset(vtk, grid::AbstractGrid, cellsets=keys(getcellsets(getgri for cellset in cellsets fill!(z, 0) z[collect(getcellset(grid, cellset))] .= 1.0 - write_celldata(vtk, z, cellset) + write_cell_data(vtk, z, cellset) end return vtk end @@ -361,24 +361,24 @@ function write_constraints(vtk, ch::ConstraintHandler) end end end - write_nodedata(vtk, data, string(field, "_bc")) + write_node_data(vtk, data, string(field, "_bc")) end return vtk end """ - write_cellcolors(vtk::VTKFile, grid::AbstractGrid, cell_colors, name="coloring") + write_cell_colors(vtk::VTKFile, grid::AbstractGrid, cell_colors, name="coloring") Write cell colors (see [`create_coloring`](@ref)) to a VTK file for visualization. In case of coloring a subset, the cells which are not part of the subset are represented as color 0. """ -function write_cellcolors(vtk, grid::AbstractGrid, cell_colors::AbstractVector{<:AbstractVector{<:Integer}}, name="coloring") +function write_cell_colors(vtk, grid::AbstractGrid, cell_colors::AbstractVector{<:AbstractVector{<:Integer}}, name="coloring") color_vector = zeros(Int, getncells(grid)) for (i, cells_color) in enumerate(cell_colors) for cell in cells_color color_vector[cell] = i end end - write_celldata(vtk, color_vector, name) + write_cell_data(vtk, color_vector, name) end diff --git a/src/deprecations.jl b/src/deprecations.jl index 276c10df50..9c9d9c7c17 100644 --- a/src/deprecations.jl +++ b/src/deprecations.jl @@ -66,7 +66,7 @@ function WriteVTK.vtk_grid(::String, ::Union{AbstractGrid,AbstractDofHandler}; k error(join(("The vtk interface has been updated in Ferrite v1.0.", "See https://github.com/Ferrite-FEM/Ferrite.jl/pull/679.", "Use VTKFile to open a vtk file, and the functions", - "write_solution, write_celldata, and write_projection to save data."), + "write_solution, write_cell_data, and write_projection to save data."), "\n")) end diff --git a/src/exports.jl b/src/exports.jl index 8328211fa6..d2daeb8eb6 100644 --- a/src/exports.jl +++ b/src/exports.jl @@ -161,9 +161,9 @@ export # exporting data VTKFile, write_solution, - write_celldata, + write_cell_data, write_projection, - write_nodedata, + write_node_data, VTKFileCollection, addstep!, diff --git a/test/test_grid_dofhandler_vtk.jl b/test/test_grid_dofhandler_vtk.jl index 7cc4d6e593..6ac0cba198 100644 --- a/test/test_grid_dofhandler_vtk.jl +++ b/test/test_grid_dofhandler_vtk.jl @@ -119,9 +119,9 @@ close(csio) filename_3d = "test_vtk_3d" VTKFile(filename_3d, grid) do vtk - write_nodedata(vtk, sym_tensor_data, "symmetric tensor") - write_nodedata(vtk, tensor_data, "tensor") - write_nodedata(vtk, vector_data, "vector") + write_node_data(vtk, sym_tensor_data, "symmetric tensor") + write_node_data(vtk, tensor_data, "tensor") + write_node_data(vtk, vector_data, "vector") end # 2D grid @@ -134,10 +134,10 @@ close(csio) filename_2d = "test_vtk_2d" VTKFile(filename_2d, grid) do vtk - write_nodedata(vtk, sym_tensor_data, "symmetric tensor") - write_nodedata(vtk, tensor_data, "tensor") - write_nodedata(vtk, tensor_data_1D, "tensor_1d") - write_nodedata(vtk, vector_data, "vector") + write_node_data(vtk, sym_tensor_data, "symmetric tensor") + write_node_data(vtk, tensor_data, "tensor") + write_node_data(vtk, tensor_data_1D, "tensor_1d") + write_node_data(vtk, vector_data, "vector") end # test the shas of the files @@ -719,10 +719,10 @@ end timesteps = 0:0.5:0.5 for (n, t) in pairs(timesteps) addstep!(pvd1, t) do io - write_celldata(io, celldata*n, "celldata") + write_cell_data(io, celldata*n, "celldata") end vtk = VTKFile(string(fname, "2_", n), grid) - write_celldata(vtk, celldata*n, "celldata") + write_cell_data(vtk, celldata*n, "celldata") addstep!(pvd2, vtk, t) @test !(isopen(vtk.vtk)) end diff --git a/test/test_vtk_export.jl b/test/test_vtk_export.jl index c9a329548f..97c88fe20f 100644 --- a/test/test_vtk_export.jl +++ b/test/test_vtk_export.jl @@ -18,7 +18,7 @@ colors = create_coloring(grid) fname = joinpath(tmp, "colors") VTKFile(fname, grid) do vtk - Ferrite.write_cellcolors(vtk, grid, colors) + Ferrite.write_cell_colors(vtk, grid, colors) end @test bytes2hex(open(SHA.sha1, fname*".vtu")) == "b804d0b064121b672d8e35bcff8446eda361cac3" end From e663ceac9c6fe7f1ea4437786f446bfaa29cf230 Mon Sep 17 00:00:00 2001 From: Knut Andreas Meyer Date: Fri, 24 May 2024 12:03:54 +0200 Subject: [PATCH 64/67] Fix merge errors --- CHANGELOG.md | 3 --- src/Export/VTK.jl | 9 --------- 2 files changed, 12 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 140c0f3ece..456316478c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -985,9 +985,6 @@ poking into Ferrite internals: [github-835]: https://github.com/Ferrite-FEM/Ferrite.jl/pull/835 [github-855]: https://github.com/Ferrite-FEM/Ferrite.jl/pull/855 [github-880]: https://github.com/Ferrite-FEM/Ferrite.jl/pull/880 -<<<<<<< HEAD -======= [github-914]: https://github.com/Ferrite-FEM/Ferrite.jl/pull/914 [github-924]: https://github.com/Ferrite-FEM/Ferrite.jl/pull/924 [github-943]: https://github.com/Ferrite-FEM/Ferrite.jl/pull/943 ->>>>>>> master diff --git a/src/Export/VTK.jl b/src/Export/VTK.jl index 9dbf59f341..9d6d36a0c2 100644 --- a/src/Export/VTK.jl +++ b/src/Export/VTK.jl @@ -4,13 +4,8 @@ include("vtk_discontinuous.jl") VTKFile(filename::AbstractString, grid::AbstractGrid; kwargs...) VTKFile(filename::AbstractString, dh::DofHandler; kwargs...) -<<<<<<< HEAD Create a `VTKFile` that contains an unstructured VTK grid. The keyword arguments are forwarded to `WriteVTK.vtk_grid`, see -======= -Create a `VTKFile` that contains an unstructured VTK grid. -The keyword arguments are forwarded to `WriteVTK.vtk_grid`, see ->>>>>>> master [Data Formatting Options](https://juliavtk.github.io/WriteVTK.jl/stable/grids/syntax/#Data-formatting-options) This file handler can be used to to write data with @@ -23,11 +18,7 @@ This file handler can be used to to write data with * [`Ferrite.write_nodeset`](@ref) * [`Ferrite.write_constraints`](@ref) -<<<<<<< HEAD -It is necessary to call `close(::VTKFile)` to save the data after writing -======= It is necessary to call `close(::VTKFile)` to save the data after writing ->>>>>>> master to the file handler. Using the supported `do`-block does this automatically: ```julia VTKFile(filename, grid) do vtk From 726cbe474ded49fb9126c9dffa911a39fead0883 Mon Sep 17 00:00:00 2001 From: Knut Andreas Meyer Date: Fri, 24 May 2024 17:10:53 +0200 Subject: [PATCH 65/67] Add test case --- test/test_vtk_export.jl | 57 +++++++++++++++++++++++++++++++++++++++++ testit.jl | 53 -------------------------------------- 2 files changed, 57 insertions(+), 53 deletions(-) delete mode 100644 testit.jl diff --git a/test/test_vtk_export.jl b/test/test_vtk_export.jl index f6a3dc467f..9b450fdbd2 100644 --- a/test/test_vtk_export.jl +++ b/test/test_vtk_export.jl @@ -41,4 +41,61 @@ @test bytes2hex(open(SHA.sha1, fname*".vtu")) == "31b506bd9729b11992f8bcb79a2191eb65d223bf" end end + + @testset "discontinuous" begin + # Produce a u such that the overall shape is f(x, xc) = 2 * (x[1]^2 - x[2]^2) + (xc[1]^2 - xc[2]^2) + # where xc is the center point of the cell. To avoid floating point issues for the hash, + # we test that all values are approximately an integer, and round to integers before storing. + function calculate_u(dh) + f(z) = z[1]^2 - z[2]^2 + u = zeros(ndofs(dh)) + ip = Ferrite.getfieldinterpolation(dh, (1, 1)) # Only one subdofhandler and one field. + cv = CellValues(QuadratureRule{RefQuadrilateral}(:lobatto, 2), ip) + for cell in CellIterator(dh) + reinit!(cv, cell) + # Cell center + xc = sum(getcoordinates(cell)) / getnquadpoints(cv) + for q_point in 1:getnquadpoints(cv) + x = spatial_coordinate(cv, q_point, getcoordinates(cell)) + for i in 1:getnbasefunctions(cv) + δu = shape_value(cv, q_point, i) + val = δu * f(x) * 2 + f(xc) + intval = round(Int, val) + # Ensure output unaffected by floating point errors, + # as we will compare vtk output with a hash + @assert abs(val - intval) < sqrt(eps()) + u[celldofs(cell)[i]] += intval + end + end + end + return u + end + + mktempdir() do tmp + nel = 20 # Dimensions assure integer coordinates at nodes and quad cell centers + xcorner = nel * ones(Vec{2}) + grid = generate_grid(Quadrilateral, (nel, nel), -xcorner, xcorner) + # Good to keep for comparison: + # dh_cont = close!(add!(DofHandler(grid), :u, Lagrange{RefQuadrilateral,1}())) + # u_cont = calculate_u(dh_cont) + dh_dg = close!(add!(DofHandler(grid), :u, DiscontinuousLagrange{RefQuadrilateral,1}())) + + u_dg = calculate_u(dh_dg) + + testhash = "aac3484ca583d8c27c925a468436876398c6b0c7" + + fname1 = joinpath(tmp, "discont_kwarg") + VTKFile(fname1, grid; write_discontinuous=true) do vtk + write_solution(vtk, dh_dg, u_dg) + end + @test bytes2hex(open(SHA.sha1, fname1*".vtu")) == testhash + + fname2 = joinpath(tmp, "discont_auto") + VTKFile(fname2, dh_dg) do vtk + write_solution(vtk, dh_dg, u_dg) + end + @test bytes2hex(open(SHA.sha1, fname2*".vtu")) == testhash + end + + end end diff --git a/testit.jl b/testit.jl deleted file mode 100644 index 792072208e..0000000000 --- a/testit.jl +++ /dev/null @@ -1,53 +0,0 @@ -using Ferrite - -grid = generate_grid(Quadrilateral, (20,20)) -dh = DofHandler(grid) -add!(dh, :u, Lagrange{RefQuadrilateral,1}()) -close!(dh) -u = zeros(ndofs(dh)) -f(x) = sinpi(x[1])*cospi(x[2]) -f(x) = x[1] + x[2] -apply_analytical!(u, dh, :u, f) - -VTKFile("continuous", grid) do vtk - write_solution(vtk, dh, u) -end - -VTKFile("discontinuous", grid; write_discontinuous=true) do vtk - write_solution(vtk, dh, u) -end - -dh = DofHandler(grid) -ip = DiscontinuousLagrange{RefQuadrilateral,1}() -add!(dh, :u, ip) -close!(dh) - -function calculate_u(dh, ip, fun) - u = zeros(ndofs(dh)) - ref_points = Ferrite.reference_coordinates(ip) - qr = QuadratureRule{RefQuadrilateral}(zeros(length(ref_points)), ref_points) - cv = CellValues(qr, ip) - for cell in CellIterator(dh) - reinit!(cv, cell) - for q_point in 1:getnquadpoints(qr) - x = spatial_coordinate(cv, q_point, getcoordinates(cell)) - v = fun(x) - u[celldofs(cell)[q_point]] = v + cellid(cell)/getncells(dh.grid) - end - end - return u -end - -u = calculate_u(dh, ip, f) - -VTKFile("really_discontinuous", grid; write_discontinuous=true) do vtk - write_solution(vtk, dh, u) -end - -VTKFile("not_discontinuous", grid) do vtk - write_solution(vtk, dh, u) -end - -VTKFile("really_discontinuous_auto", dh) do vtk - write_solution(vtk, dh, u) -end From e0cabaf72d8c5dedd78a516e7c2c3e8bc273902b Mon Sep 17 00:00:00 2001 From: Knut Andreas Meyer Date: Fri, 24 May 2024 17:54:36 +0200 Subject: [PATCH 66/67] Make better test case showing node order is correct --- test/test_vtk_export.jl | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/test/test_vtk_export.jl b/test/test_vtk_export.jl index 9b450fdbd2..df39b5e01b 100644 --- a/test/test_vtk_export.jl +++ b/test/test_vtk_export.jl @@ -43,7 +43,7 @@ end @testset "discontinuous" begin - # Produce a u such that the overall shape is f(x, xc) = 2 * (x[1]^2 - x[2]^2) + (xc[1]^2 - xc[2]^2) + # Produce a u such that the overall shape is f(x, xc) = 2 * (x[1]^2 - x[2]^2) - (xc[1]^2 - xc[2]^2) # where xc is the center point of the cell. To avoid floating point issues for the hash, # we test that all values are approximately an integer, and round to integers before storing. function calculate_u(dh) @@ -59,7 +59,7 @@ x = spatial_coordinate(cv, q_point, getcoordinates(cell)) for i in 1:getnbasefunctions(cv) δu = shape_value(cv, q_point, i) - val = δu * f(x) * 2 + f(xc) + val = δu * (f(x) * 2 - f(xc)) intval = round(Int, val) # Ensure output unaffected by floating point errors, # as we will compare vtk output with a hash @@ -82,7 +82,7 @@ u_dg = calculate_u(dh_dg) - testhash = "aac3484ca583d8c27c925a468436876398c6b0c7" + testhash = "daf0cbe26ff709705f338526b19881ef5758f16b" fname1 = joinpath(tmp, "discont_kwarg") VTKFile(fname1, grid; write_discontinuous=true) do vtk From 18835142fffe9f9d8b0e79fed22207c54344003e Mon Sep 17 00:00:00 2001 From: Knut Andreas Meyer Date: Sat, 10 Aug 2024 14:57:51 +0200 Subject: [PATCH 67/67] Fix merge error --- test/test_vtk_export.jl | 1 + 1 file changed, 1 insertion(+) diff --git a/test/test_vtk_export.jl b/test/test_vtk_export.jl index 4baef3f207..8cb869cac8 100644 --- a/test/test_vtk_export.jl +++ b/test/test_vtk_export.jl @@ -96,6 +96,7 @@ end @test bytes2hex(open(SHA.sha1, fname2*".vtu")) == testhash end + end @testset "write_cellset" begin # More tests in `test_grid_dofhandler_vtk.jl`, this just validates writing all sets in the grid