Skip to content

Commit

Permalink
Make SolutionSavingCallback work on GPUs (#579)
Browse files Browse the repository at this point in the history
* Make `SolutionSavingCallback` work on GPUs

* Avoid overhead on CPUs

---------

Co-authored-by: Sven Berger <[email protected]>
Co-authored-by: Niklas Neher <[email protected]>
  • Loading branch information
3 people authored Jul 24, 2024
1 parent 8273cbe commit c01d9ad
Showing 1 changed file with 21 additions and 2 deletions.
23 changes: 21 additions & 2 deletions src/visualization/write2vtk.jl
Original file line number Diff line number Diff line change
Expand Up @@ -75,12 +75,15 @@ function trixi2vtk(vu_ode, semi, t; iter=nothing, output_directory="out", prefix
end

# Convert data for a single TrixiParticle system to VTK format
function trixi2vtk(v, u, t, system, periodic_box; output_directory="out", prefix="",
iter=nothing, system_name=vtkname(system), write_meta_data=true,
function trixi2vtk(v_, u_, t, system_, periodic_box; output_directory="out", prefix="",
iter=nothing, system_name=vtkname(system_), write_meta_data=true,
max_coordinates=Inf, git_hash=compute_git_hash(),
custom_quantities...)
mkpath(output_directory)

# Transfer to CPU if data is on the GPU. Do nothing if already on CPU.
v, u, system = transfer2cpu(v_, u_, system_)

# handle "_" on optional pre/postfix strings
add_opt_str_pre(str) = (str === "" ? "" : "$(str)_")
add_opt_str_post(str) = (str === nothing ? "" : "_$(str)")
Expand Down Expand Up @@ -135,6 +138,18 @@ function trixi2vtk(v, u, t, system, periodic_box; output_directory="out", prefix
vtk_save(pvd)
end

function transfer2cpu(v_, u_, system_::GPUSystem)
v = Adapt.adapt(Array, v_)
u = Adapt.adapt(Array, u_)
system = Adapt.adapt(Array, system_)

return v, u, system
end

function transfer2cpu(v_, u_, system_)
return v_, u_, system_
end

function custom_quantity(quantity::AbstractArray, v, u, t, system)
return quantity
end
Expand Down Expand Up @@ -357,3 +372,7 @@ function write2vtk!(vtk, v, u, t, model::BoundaryModelDummyParticles, system;
vtk["wall_velocity"] = view(model.cache.wall_velocity, 1:ndims(system), :)
end
end

function write2vtk!(vtk, v, u, t, system::BoundaryDEMSystem; write_meta_data=true)
return vtk
end

0 comments on commit c01d9ad

Please sign in to comment.