Skip to content

Commit 921bafc

Browse files
LasNikasLasNikasefaulhaber
authored
Fix GPU tests, GPU interpolation and GPU postprocessing (#912)
* fix gpu * rm saving callback * implement suggestions * rm solution_saving=nothing --------- Co-authored-by: LasNikas <niklas.nehe@web.de> Co-authored-by: Erik Faulhaber <44124897+efaulhaber@users.noreply.github.com>
1 parent 1545e1b commit 921bafc

5 files changed

Lines changed: 23 additions & 14 deletions

File tree

src/callbacks/post_process.jl

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -252,8 +252,10 @@ function (pp::PostprocessCallback)(integrator)
252252
system_index = system_indices(system, semi)
253253

254254
for (key, f) in pp.func
255-
result = custom_quantity(f, system, dv_ode, du_ode, v_ode, u_ode, semi, t)
256-
if result !== nothing
255+
result_ = custom_quantity(f, system, dv_ode, du_ode, v_ode, u_ode, semi, t)
256+
if result_ !== nothing
257+
# Transfer to CPU if data is on the GPU. Do nothing if already on CPU.
258+
result = transfer2cpu(result_)
257259
add_entry!(pp, string(key), t, result, filenames[system_index])
258260
new_data = true
259261
end

src/general/interpolation.jl

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -628,6 +628,11 @@ end
628628
return (; velocity, jacobian, von_mises_stress, cauchy_stress)
629629
end
630630

631+
function interpolate_system!(cache, v, neighbor_system,
632+
point, neighbor, volume_b, W_ab, clip_negative_pressure)
633+
return cache
634+
end
635+
631636
@inline function interpolate_system!(cache, v, system::AbstractFluidSystem,
632637
point, neighbor, volume_b, W_ab,
633638
clip_negative_pressure)

src/io/io.jl

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -135,12 +135,8 @@ function add_system_data!(system_data, system::OpenBoundarySystem)
135135
system_data["system_type"] = type2string(system)
136136
system_data["fluid_system_index"] = system.fluid_system_index[]
137137
system_data["smoothing_length"] = system.smoothing_length
138+
system_data["number_of_boundary_zones"] = length(system.boundary_zones)
138139
add_system_data!(system_data, system.boundary_model)
139-
140-
system_data["boundary_zones"] = Dict{String, Any}()
141-
for (indice, boundary_zone) in enumerate(system.boundary_zones)
142-
add_system_data!(system_data["boundary_zones"], boundary_zone, indice)
143-
end
144140
end
145141

146142
function add_system_data!(system_data, system::ParticlePackingSystem)
@@ -299,8 +295,6 @@ function add_system_data!(system_data, motion::PrescribedMotion)
299295
system_data["prescribed_motion"] = Dict{String, Any}()
300296
system_data["prescribed_motion"]["model"] = type2string(motion)
301297
system_data["prescribed_motion"]["movement_function"] = type2string(motion.movement_function)
302-
system_data["prescribed_motion"]["is_moving"] = type2string(motion.is_moving)
303-
system_data["prescribed_motion"]["moving_particles"] = motion.moving_particles
304298
end
305299

306300
function add_system_data!(system_data, penalty_force::PenaltyForceGanzenmueller)

src/io/write_vtk.jl

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -140,8 +140,8 @@ function trixi2vtk(system_, dvdu_ode_, vu_ode_, semi_, t, periodic_box;
140140

141141
# Extract custom quantities for this system
142142
if !isempty(custom_quantities)
143-
dv_ode, du_ode = dvdu_ode_.x
144-
dv_ode, du_ode = transfer2cpu(dv_ode, du_ode)
143+
dv_ode_, du_ode_ = dvdu_ode_.x
144+
dv_ode, du_ode = transfer2cpu(dv_ode_, du_ode_)
145145

146146
for (key, quantity) in custom_quantities
147147
value = custom_quantity(quantity, system, dv_ode, du_ode, v_ode, u_ode,
@@ -173,8 +173,8 @@ function transfer2cpu(v_, u_, system_, semi_)
173173
end
174174

175175
function transfer2cpu(v_::AbstractGPUArray, u_)
176-
v = Adapt.adapt(Array, v_)
177-
u = Adapt.adapt(Array, u_)
176+
v = transfer2cpu(v_)
177+
u = transfer2cpu(u_)
178178

179179
return v, u
180180
end
@@ -183,6 +183,14 @@ function transfer2cpu(v_, u_)
183183
return v_, u_
184184
end
185185

186+
function transfer2cpu(a_::AbstractGPUArray)
187+
return Adapt.adapt(Array, a_)
188+
end
189+
190+
function transfer2cpu(a_)
191+
return a_
192+
end
193+
186194
function custom_quantity(quantity::AbstractArray, system, dv_ode, du_ode, v_ode, u_ode,
187195
semi, t)
188196
return quantity

test/examples/gpu.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -453,7 +453,7 @@ end
453453
# Neighborhood search with `FullGridCellList` for GPU compatibility
454454
min_corner = minimum(tank.boundary.coordinates, dims=2)
455455
max_corner = maximum(tank.boundary.coordinates, dims=2)
456-
max_corner[2] = gate_height + movement_function(0.1)[2]
456+
max_corner[2] = gate_height + movement_function([0, 0], 0.1f0)[2]
457457
# We need a very high `max_points_per_cell` because the plate resolution
458458
# is much finer than the fluid resolution.
459459
cell_list = FullGridCellList(; min_corner, max_corner)

0 commit comments

Comments
 (0)