-
Notifications
You must be signed in to change notification settings - Fork 22
Open
Description
With the current implementation, we can not generate the paraview files when the triangulations are not present on all MPI ranks. In issue #70, this has been written as a #TODO task for taking nothing.
Since I needed this functionality for my use case, I tried to fix it myself, but I had to use functions from Mpi.jl as well. Below are the changes I made to make it work.
struct DistributedPvd{T<:AbstractArray}
pvds::T
main_rank::Int
end
function Visualization.createpvd(trian::DistributedTriangulation,parts::AbstractArray,args...;kwargs...)
main_rank = -1
map(local_views(trian), parts) do LocTrian, part
flag = part * !(num_cells(LocTrian) == 0)
global_flag = Vector{Int}(undef, MPI.Comm_size(MPI.COMM_WORLD))
MPI.Allgather!([flag], global_flag, MPI.COMM_WORLD)
main_rank = maximum(global_flag)
end
pvds = map_main(parts,main = main_rank) do part
p = paraview_collection(args...;kwargs...)
end
DistributedPvd(pvds,main_rank)
end
function Visualization.createpvd(f,trian::DistributedTriangulation,parts::AbstractArray,args...;kwargs...)
pvd = createpvd(trian,parts,args...;kwargs...)
try
f(pvd)
finally
savepvd(pvd)
end
end
function Visualization.createpvd(parts::AbstractArray,args...;kwargs...)
pvds = map_main(parts, main = 1) do part
p = paraview_collection(args...;kwargs...)
end
DistributedPvd(pvds,1)
end
function Visualization.createpvd(f,parts::AbstractArray,args...;kwargs...)
pvd = createpvd(parts,args...;kwargs...)
try
f(pvd)
finally
savepvd(pvd)
end
end
function Visualization.savepvd(pvd::DistributedPvd)
map_main(pvd.pvds, main = pvd.main_rank) do pvd
vtk_save(pvd)
end
end
function Base.setindex!(pvd::DistributedPvd,pvtk::AbstractArray,time::Real)
map(pvtk) do pvtk
if !isnothing(pvtk)
vtk_save(pvtk)
end
end
map_main(pvtk,pvd.pvds,main = pvd.main_rank) do pvtk,pvd
pvd[time] = pvtk
end
end
Metadata
Metadata
Assignees
Labels
No labels