Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix resize! for LowStorageRK2NCache; closes #1277 #1278

Merged
merged 1 commit into from
Sep 28, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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