Skip to content

Commit 535c399

Browse files
Merge pull request #71 from oriolcg/pvd_functions
createpvd and savepvd functions
2 parents 54d1766 + 4efec6f commit 535c399

File tree

3 files changed

+40
-0
lines changed

3 files changed

+40
-0
lines changed

NEWS.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1010
- Support for periodic boundary conditions for `CartesianDiscreteModel`. Since PR [#79](https://github.com/gridap/GridapDistributed.jl/pull/79)
1111
- Skeleton documentation and some content. Since PR [#77](https://github.com/gridap/GridapDistributed.jl/pull/77)
1212
- Added `interpolate_everywhere` and `interpolate_dirichlet` functions. Since PR [#74](https://github.com/gridap/GridapDistributed.jl/pull/74)
13+
- Added `createpvd` and `savepvd` functions to save collections of VTK files. Since PR [#71](https://github.com/gridap/GridapDistributed.jl/pull/71)
1314

1415
### Fixed
1516
- Visualization of functions and numbers. Since PR [#78](https://github.com/gridap/GridapDistributed.jl/pull/78)

src/Visualization.jl

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,3 +156,36 @@ function Visualization.create_vtk_file(
156156
celldata=c,nodaldata=n)
157157
end
158158
end
159+
160+
struct DistributedPvd{T<:AbstractPData}
161+
pvds::T
162+
end
163+
164+
function Visualization.createpvd(parts::AbstractPData,args...;kwargs...)
165+
pvds = map_main(parts) do part
166+
paraview_collection(args...;kwargs...)
167+
end
168+
DistributedPvd(pvds)
169+
end
170+
171+
function Visualization.createpvd(f,parts::AbstractPData,args...;kwargs...)
172+
pvd = createpvd(parts,args...;kwargs...)
173+
try
174+
f(pvd)
175+
finally
176+
savepvd(pvd)
177+
end
178+
end
179+
180+
function Visualization.savepvd(pvd::DistributedPvd)
181+
map_main(pvd.pvds) do pvd
182+
vtk_save(pvd)
183+
end
184+
end
185+
186+
function Base.setindex!(pvd::DistributedPvd,pvtk::AbstractPData,time::Real)
187+
map_parts(vtk_save,pvtk)
188+
map_main(pvtk,pvd.pvds) do pvtk,pvd
189+
pvd[time] = pvtk
190+
end
191+
end

test/CellDataTests.jl

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,12 @@ function main(parts)
2424
writevtk(Ω,joinpath(output,"Ω"),cellfields=["f"=>f,"u"=>u])
2525
writevtk(Γ,joinpath(output,"Γ"),cellfields=["f"=>f,"g"=>g,"u"=>u])
2626

27+
createpvd(parts,joinpath(output,"Ω_pvd")) do pvd
28+
pvd[0.1] = createvtk(Ω,joinpath(output,"Ω_1"),cellfields=["f"=>f])
29+
pvd[0.2] = createvtk(Ω,joinpath(output,"Ω_2"),cellfields=["f"=>f])
30+
end
31+
@test isfile(joinpath(output,"Ω_pvd")*".pvd")
32+
2733
x_Γ = get_cell_points(Γ)
2834
@test isa(f(x_Γ),AbstractPData)
2935

0 commit comments

Comments
 (0)