Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Abstraction layer around vtk export #692

Merged
merged 83 commits into from
May 19, 2024
Merged

Abstraction layer around vtk export #692

merged 83 commits into from
May 19, 2024

Conversation

KnutAM
Copy link
Member

@KnutAM KnutAM commented May 1, 2023

closes #278 (replaces #691, xref #686)

Following the discussion in #691, this PR introduces an abstraction layer for exporting from Ferrite to VTK. With this PR, no functions from WriteVTK.jl should be called directly by the user. (If still needed for special/custom reasons, it is possible by accessing the internal methods and or the vtk field in VTKFile)

Using vtk_grid with an AbstractGrid or AbstractDofHandler will error telling how to upgrade

Main motivations

  1. Avoid re-exporting and extending methods from WriteVTK. Makes dispatch and function owner ship more clear and flexible
  2. Provides infrastructure for backend-agnostic export by allowing users to define their own backends (see e.g. Abstraction layer around vtk export #692 (comment) below)

The new workflow is

VTKFile(filename, grid_or_dh; kwargs...) do vtk
    write_solution(vtk, dh::DofHandler, u)
    write_projection(vtk, proj::L2Projector, vals)
    write_cell_data(vtk, celldata)
    write_node_data(vtk, nodedata)
    Ferrite.write_cellset(vtk, grid, [setnames])
    Ferrite.write_nodeset(vtk, grid, setname)
    Ferrite.write_constraints(vtk, ch::ConstraintHandler)
    Ferrite.write_cell_colors(vtk, grid, cell_colors)
end

or alternatively

vtk = VTKFile(filename, grid_or_dh; kwargs...)
# write ....
close(vtk) # Overload of Base.close

For writing paraview collections, the workflow is

pvd = VTKFileCollection(filename, grid_or_dh; kwargs...)
for t in range(0, end_time, num_steps)
    # calculate e.g. the dof-vector u and cell data s
    addstep!(pvd, t, [grid_or_dh]) do vtk
        write_solution(vtk, dh, u)
        write_cell_data(vtk, s, "stress")
    end
end
close(pvd)

Alternatively,

pvd = VTKFileCollection(filename, grid_or_dh; kwargs...)
for (n, t) in pairs(range(0, end_time, num_steps))
    # calculate e.g. the dof-vector u and cell data s
    vtk = VTKFile(string(filename, "_", n), grid_or_dh)
    write_solution(vtk, dh, u)
    write_cell_data(vtk, s, "stress")
    addstep!(pvd, vtk, t)
end
close(pvd)

@KnutAM KnutAM mentioned this pull request May 1, 2023
@KnutAM KnutAM requested a review from fredrikekre May 1, 2023 13:10
@codecov-commenter
Copy link

codecov-commenter commented May 10, 2023

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 93.86%. Comparing base (2ca4f94) to head (d6a199e).
Report is 1 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #692      +/-   ##
==========================================
+ Coverage   93.56%   93.86%   +0.29%     
==========================================
  Files          36       36              
  Lines        5272     5313      +41     
==========================================
+ Hits         4933     4987      +54     
+ Misses        339      326      -13     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@koehlerson
Copy link
Member

having something like write_projected sounds very good to me at least from a new user perspective it seems quite convenient to have this

@KnutAM KnutAM changed the title Export abstractions Abstraction layer around vtk export Jul 5, 2023
@KnutAM KnutAM added this to the v1.0.0 milestone Jul 5, 2023
src/Export/VTK.jl Outdated Show resolved Hide resolved
src/Export/VTK.jl Outdated Show resolved Hide resolved
src/exports.jl Show resolved Hide resolved
src/Export/VTK.jl Outdated Show resolved Hide resolved
src/Export/VTK.jl Outdated Show resolved Hide resolved
@KnutAM
Copy link
Member Author

KnutAM commented Apr 26, 2024

Not sure why the mac CI fails, seems unrelated to changes but I don't have a mac so cannot test locally.
Edit: Is unrelated, happens in other PRs too (xref #914 / bbc202a)

@KnutAM KnutAM mentioned this pull request Apr 29, 2024
docs/src/reference/export.md Outdated Show resolved Hide resolved
src/Export/VTK.jl Show resolved Hide resolved
src/Export/VTK.jl Outdated Show resolved Hide resolved
test/runtests.jl Outdated Show resolved Hide resolved
test/runtests.jl Outdated Show resolved Hide resolved
test/test_l2_projection.jl Show resolved Hide resolved
@fredrikekre fredrikekre merged commit 821a710 into master May 19, 2024
9 checks passed
@fredrikekre fredrikekre deleted the kam/VTKStream branch May 19, 2024 21:47
@KnutAM KnutAM removed the awaiting review PR is finished from the authors POV, waiting for feedback label May 22, 2024
KnutAM added a commit that referenced this pull request May 23, 2024
Adressing changes in #692, #789, and #914
---------

Co-authored-by: Fredrik Ekre <[email protected]>
@KnutAM KnutAM mentioned this pull request Jul 4, 2024
KnutAM added a commit that referenced this pull request Aug 10, 2024
Restores pre #692 functionality for collection files by removing VTKFileCollection.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Maybe remove the fallback vtk_point_data
6 participants