From 558f85a264b8265fb80d34696d40621295e22c6e Mon Sep 17 00:00:00 2001 From: Hendrik Ranocha Date: Fri, 25 Sep 2020 12:36:51 +0200 Subject: [PATCH] fix resize! for LowStorageRK2NCache; closes #1277 --- .../low_storage_rk_perform_step.jl | 7 +++++ test/integrators/ode_cache_tests.jl | 29 ++++++++++++++++--- 2 files changed, 32 insertions(+), 4 deletions(-) diff --git a/src/perform_step/low_storage_rk_perform_step.jl b/src/perform_step/low_storage_rk_perform_step.jl index e23bd1504b..7e8a2ad520 100644 --- a/src/perform_step/low_storage_rk_perform_step.jl +++ b/src/perform_step/low_storage_rk_perform_step.jl @@ -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 diff --git a/test/integrators/ode_cache_tests.jl b/test/integrators/ode_cache_tests.jl index a26a18a4cf..f898f72fbc 100644 --- a/test/integrators/ode_cache_tests.jl +++ b/test/integrators/ode_cache_tests.jl @@ -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)) @@ -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