CVode returns wrong yout if h becomes zero
- Dominant language
- C
- Stars
- 686
- Forks
- 167
- Avg merge
- 1d 20h
- Merged PRs (30d)
- 17
Description
Hi, I stumbled across a problem in `CVode` which seems to yield a wrong `yout` if `h` becomes zero.
After `CVode`: `Internal t = 0 and h = 0 are such that t + h = t on the next step. The solver will continue anyway.` and `CVodeGetDky`: `Illegal value for t.t = 900 is not between tcur - hu = 0 and tcur = 0`, `CVode` still returns `CV_SUCCESS`, but `yout` is not the correct value for `tout`, but for the time when `h` became zero.
The problem seems to be the multiplication with `cv_mem->cv_h` for checking whether `tout` was reached and subsequently ignoring the return value of `CVodeGetDky` (`CV_BAD_T`), here:
https://github.com/LLNL/sundials/blob/a9bc74f6f188cd513521cbbdace3d0a85a8d76b9/src/cvodes/cvodes.c#L3298-L3305
Similar checks exist in `CVodeF` here:
https://github.com/LLNL/sundials/blob/a9bc74f6f188cd513521cbbdace3d0a85a8d76b9/src/cvodes/cvodea.c#L560-L561
and here:
https://github.com/LLNL/sundials/blob/a9bc74f6f188cd513521cbbdace3d0a85a8d76b9/src/cvodes/cvodea.c#L472-L473
`CVodeF` leads to the same warnings, but returns `CV_BAD_T`. That is at least not `CV_SUCCESS`, but it is somewhat misleading, as `CVodeGetDky` should not have been called in the first place.
This happens in a more complex application and I am not sure I can easily provide a minimal reproducible example.
Contributor guide
Research direction
Start in src/cvodes/cvodes.c around the CVode return-to-tout logic at lines 3298-3305, then compare the related checks in src/cvodes/cvodea.c at lines 472-473 and 560-561. Trace how a zero cv_h affects the tout check and how CVodeGetDky results are handled; done means CVode and CVodeF report a consistent status and do not return an incorrect yout for the requested tout.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- c
- Domain
- hpc
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100