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 ARKODE reinit #369

Merged
merged 1 commit into from
Aug 31, 2022
Merged

Fix ARKODE reinit #369

merged 1 commit into from
Aug 31, 2022

Conversation

ChrisRackauckas
Copy link
Member

Needs a test case

@superckl
Copy link

I can verify this fixes the error, but callbacks with ARKODE still seem to be behaving weird. Take this test case (which resulted in a runtime error previously):

using Sundials, DiffEqBase, Test

tspan = [0, 200]
E = 1E-2
h0 = 1

fun = ODEFunction((dh, _, _, _) -> dh .= -E, jac = (J, _, _, _) -> J .= 0)
prob = ODEProblem(fun, [h0], tspan)

cb = ContinuousCallback((h, _, _) -> h[1], terminate!)

sol_ark = solve(prob, ARKODE(), callback = cb)
sol_bdf = solve(prob, CVODE_BDF(), callback = cb)

@test isapprox(sol_bdf.t[end], 1/E, rtol = 1E-3)
@test isapprox(sol_bdf[end][1], 0, atol = 1E-3)
@test isapprox(sol_ark.t[end], 1/E, rtol = 1E-3)
@test isapprox(sol_ark[end][1], 0, atol = 1E-3)

which outputs

Test Failed at i:\My Drive\Research\Code\julia solver\Sundials\test\arkode_callback.jl:17
  Expression: isapprox(sol_ark.t[end], 1 / E, rtol = 0.001)
   Evaluated: isapprox(0.0, 100.0; rtol = 0.001)
ERROR: There was an error during testing

The system should be integrated to 1/E=1E2 and then stop because h=0. With CVODE_BDF, all is fine, but ARKODE seems to exit at t=0. Without the callback, ARKODE integrates the system fine:

display(solve(prob, ARKODE()))
retcode: Success
Interpolation: 3rd order Hermite
t: 6-element Vector{Float64}:
   0.0
   0.004112271831573867
   0.3427118254794238
   5.90547982484689
 117.16083981219622
 200.0
u: 6-element Vector{Vector{Float64}}:
 [1.0]
 [0.9999588772816843]
 [0.9965728817452059]
 [0.9409452017515313]
 [-0.17160839812196294]
 [-1.000000000000002]

@ChrisRackauckas
Copy link
Member Author

Can you see what happens if you swap fun 1 and 2 in the overload? I think I did it right: we have implicit-explicit and they have explicit-implicit. But double check.

@superckl
Copy link

Switching the functions seems to have no effect. This seems like it might be unrelated to this PR, I can just discover it now -- perhaps I should open a separate issue?

@ChrisRackauckas
Copy link
Member Author

Alright, well this is at least right so let's merge this and open an issue to investigate next steps.

@ChrisRackauckas ChrisRackauckas merged commit 0393742 into master Aug 31, 2022
@HumHongeKamyaab
Copy link

Mentioning this discourse thread here https://discourse.julialang.org/t/facing-problems-with-sundials-jl-arkode-with-discrete-callback/119278?u=humhongekamyaab
as it is related with reinit of ARKODE

@ChrisRackauckas ChrisRackauckas deleted the ChrisRackauckas-patch-1 branch September 15, 2024 14:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants