Skip to content

Commit 7fc7a25

Browse files
author
LasNikas
committed
fix tests
1 parent 25b3d00 commit 7fc7a25

File tree

5 files changed

+44
-21
lines changed

5 files changed

+44
-21
lines changed

examples/postprocessing/interpolation_plane.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ combined_plot = Plots.plot(plot1, plot2, plot3, plot_3d, layout=(2, 2),
107107
# Note that the arguments `system, v_ode, u_ode, semi, t` are more powerful than the
108108
# documented arguments `system, data, t`, allowing us to use interpolation (which requires
109109
# a semidiscretization).
110-
function save_interpolated_plane(system, v_ode, u_ode, semi, t)
110+
function save_interpolated_plane(system, dv_ode, du_ode, v_ode, u_ode, semi, t)
111111
# Size of the patch to be interpolated
112112
interpolation_start = [0.0, 0.0]
113113
interpolation_end = [tank_size[1], tank_size[2]]

examples/postprocessing/postprocessing.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ using JSON
1515

1616
# Any custom function with the arguments `v, u, t, system` can be passed to the callback
1717
# to be called every 10th timestep. See example below:
18-
function hello(system, v_ode, u_ode, semi, t)
18+
function hello(system, dv_ode, du_ode, v_ode, u_ode, semi, t)
1919
# Will write "hello" and the current simulation time
2020
println("hello at ", t)
2121

src/io/write_vtk.jl

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

141141
# Extract custom quantities for this system
142-
# TODO: Check if any custom quantities and then adapt from gpu
143-
dv_ode, du_ode = dvdu_ode_.x
144-
for (key, quantity) in custom_quantities
145-
value = custom_quantity(quantity, system, dv_ode, du_ode, v_ode, u_ode, semi, t)
146-
if value !== nothing
147-
vtk[string(key)] = value
142+
if !isempty(custom_quantities)
143+
dv_ode, du_ode = dvdu_ode_.x
144+
dv_ode, du_ode = transfer2cpu(dv_ode, du_ode)
145+
146+
for (key, quantity) in custom_quantities
147+
value = custom_quantity(quantity, system, dv_ode, du_ode, v_ode, u_ode,
148+
semi, t)
149+
if value !== nothing
150+
vtk[string(key)] = value
151+
end
148152
end
149153
end
150154

@@ -155,19 +159,30 @@ function trixi2vtk(system_, dvdu_ode_, vu_ode_, semi_, t, periodic_box;
155159
end
156160

157161
function transfer2cpu(v_::AbstractGPUArray, u_, system_, semi_)
158-
v = Adapt.adapt(Array, v_)
159-
u = Adapt.adapt(Array, u_)
160162
semi = Adapt.adapt(Array, semi_)
161163
system_index = system_indices(system_, semi_)
162164
system = semi.systems[system_index]
163165

166+
v, u = transfer2cpu(v_, u_)
167+
164168
return v, u, system, semi
165169
end
166170

167171
function transfer2cpu(v_, u_, system_, semi_)
168172
return v_, u_, system_, semi_
169173
end
170174

175+
function transfer2cpu(v_::AbstractGPUArray, u_)
176+
v = Adapt.adapt(Array, v_)
177+
u = Adapt.adapt(Array, u_)
178+
179+
return v, u
180+
end
181+
182+
function transfer2cpu(v_, u_)
183+
return v_, u_
184+
end
185+
171186
function custom_quantity(quantity::AbstractArray, system, dv_ode, du_ode, v_ode, u_ode,
172187
semi, t)
173188
return quantity

test/callbacks/solution_saving.jl

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -69,18 +69,21 @@
6969
@testset verbose=true "custom quantities" begin
7070
# Test that `custom_quantity` correctly chooses the correct method
7171
quantity1(system, data, t) = data
72-
quantity2(system, v_ode, u_ode, semi, t) = 2
72+
quantity2(system, dv_ode, du_ode, v_ode, u_ode, semi, t) = 2
7373
quantity3() = 3
7474

7575
system = Val(:mock_system)
7676
TrixiParticles.system_data(::Val{:mock_system}, dv_ode, du_ode, v_ode, u_ode,
7777
semi) = 1
7878

79-
data = v_ode = u_ode = semi = t = nothing
79+
data = v_ode = u_ode = dv_ode = du_ode = semi = t = nothing
8080

81-
@test TrixiParticles.custom_quantity(quantity1, system, v_ode, u_ode, semi, t) == 1
82-
@test TrixiParticles.custom_quantity(quantity2, system, v_ode, u_ode, semi, t) == 2
83-
@test_throws MethodError TrixiParticles.custom_quantity(quantity3, system, v_ode,
84-
u_ode, semi, t)
81+
@test TrixiParticles.custom_quantity(quantity1, system, dv_ode, du_ode, v_ode,
82+
u_ode, semi, t) == 1
83+
@test TrixiParticles.custom_quantity(quantity2, system, dv_ode, du_ode, v_ode,
84+
u_ode, semi, t) == 2
85+
@test_throws MethodError TrixiParticles.custom_quantity(quantity3, system, dv_ode,
86+
du_ode, v_ode, u_ode,
87+
semi, t)
8588
end
8689
end

test/io/read_vtk.jl

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
@testset verbose=true "`vtk2trixi`" begin
22
mktempdir() do tmp_dir
3-
coordinates=fill(1.0, 2, 12)
4-
velocity=fill(2.0, 2, 12)
3+
coordinates = fill(1.0, 2, 12)
4+
velocity = fill(2.0, 2, 12)
55

66
expected_ic = InitialCondition(; coordinates=coordinates, velocity=velocity,
77
density=1000.0, pressure=900.0, mass=50.0)
@@ -29,15 +29,17 @@
2929
semi = Semidiscretization(fluid_system)
3030

3131
# Create random ODE solutions
32+
dvdu_ode = nothing
3233
v = fill(2.0, ndims(fluid_system), nparticles(fluid_system))
3334
pressure = fill(3.0, nparticles(fluid_system))
3435
v_ode = vec([v; pressure'])
35-
3636
u = fill(1.0, ndims(fluid_system), nparticles(fluid_system))
3737
u_ode = vec(u)
38+
x = (; v_ode, u_ode)
39+
vu_ode = (; x)
3840

3941
# Write out `FluidSystem` Simulation-File
40-
trixi2vtk(fluid_system, v_ode, u_ode, semi, 0.0,
42+
trixi2vtk(fluid_system, dvdu_ode, vu_ode, semi, 0.0,
4143
nothing; system_name="tmp_file_fluid", output_directory=tmp_dir,
4244
iter=1)
4345

@@ -65,11 +67,14 @@
6567
semi = Semidiscretization(boundary_system)
6668

6769
# Create dummy ODE solutions
70+
dvdu_ode = nothing
6871
v_ode = zeros(ndims(boundary_system) * nparticles(boundary_system))
6972
u_ode = zeros(ndims(boundary_system) * nparticles(boundary_system))
73+
x = (; v_ode, u_ode)
74+
vu_ode = (; x)
7075

7176
# Write out `BoundarySystem` Simulation-File
72-
trixi2vtk(boundary_system, v_ode, u_ode, semi, 0.0,
77+
trixi2vtk(boundary_system, dvdu_ode, vu_ode, semi, 0.0,
7378
nothing; system_name="tmp_file_boundary", output_directory=tmp_dir,
7479
iter=1)
7580

0 commit comments

Comments
 (0)