Skip to content

Commit

Permalink
fix resize! for LowStorageRK2NCache; closes #1277
Browse files Browse the repository at this point in the history
  • Loading branch information
ranocha committed Sep 25, 2020
1 parent 821fc83 commit 558f85a
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 4 deletions.
7 changes: 7 additions & 0 deletions src/perform_step/low_storage_rk_perform_step.jl
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,13 @@ end
@unpack k,tmp,williamson_condition = cache
@unpack A2end,B1,B2end,c2end = cache.tab

if integrator.u_modified
if !get_current_isfsal(integrator.alg, integrator.cache)
f(k, u, p, t+dt)
end
@.. tmp = dt*k
end

# u1
@.. u = u + B1*tmp
# other stages
Expand Down
29 changes: 25 additions & 4 deletions test/integrators/ode_cache_tests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,14 @@ for alg in broken_CACHE_TEST_ALGS
@test_broken length(solve(prob,alg,callback=callback,dt=1/2)[end]) > 1
end

sol = solve(prob,Rodas4(chunk_size=1),callback=callback,dt=1/2)
@test length(sol[end]) > 1
sol = solve(prob,Rodas5(chunk_size=1),callback=callback,dt=1/2)
@test length(sol[end]) > 1


# cache tests resizing multidimensional arrays
println("Check resizing multidimensional arrays")
u0_matrix = ElasticArray(ones(2, 2))
f_matrix = (du, u, p, t) -> du .= u
prob_matrix = ODEProblem(f_matrix, u0_matrix, (0.0, 2.0))
Expand All @@ -87,11 +94,25 @@ for alg in CACHE_TEST_ALGS
@test size(sol[end]) == (2,3)
end

# additional cache tests to find more bugs
println("Additional resize! checks")
u0resize3 = ones(2)
fresize3 = (du, u, p, t) -> du .= u
prob_resize3 = ODEProblem(fresize3, u0resize3, (0.0, 2.0))
condition_resize3 = (u, t, integrator) -> t - 1
affect!_resize3 = function (integrator)
resize!(integrator, 3)
integrator.u .= 1
nothing
end
callback_resize3 = ContinuousCallback(condition_resize3, affect!_resize3)

sol = solve(prob,Rodas4(chunk_size=1),callback=callback,dt=1/2)
@test length(sol[end]) > 1
sol = solve(prob,Rodas5(chunk_size=1),callback=callback,dt=1/2)
@test length(sol[end]) > 1
for alg in CACHE_TEST_ALGS
@show alg
sol = solve(prob_resize3, alg, callback=callback_resize3, dt=0.125)
@test size(sol[end]) == (3,)
@test all(sol[end] .== sol[end][1])
end


# Force switching
Expand Down

0 comments on commit 558f85a

Please sign in to comment.