advance limit handling to improve performance (#1453)#1976
advance limit handling to improve performance (#1453)#1976ischoegl merged 9 commits intoCantera:mainfrom
Conversation
speth
left a comment
There was a problem hiding this comment.
Thanks for looking into this, @wandadars. I think using the built-in CVODES functionality for this is a good approach to consider. I just wanted to share a couple of suggestions that might help with the implementation.
|
Thanks @speth . I totally spaced out and forgot that I had opened this PR. I'll look at this again this weekend and see if I can clean it up. |
d476b5c to
65704b2
Compare
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## main #1976 +/- ##
==========================================
- Coverage 76.41% 76.38% -0.03%
==========================================
Files 463 463
Lines 54952 55032 +80
Branches 9308 9317 +9
==========================================
+ Hits 41990 42038 +48
- Misses 9831 9863 +32
Partials 3131 3131 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
ischoegl
left a comment
There was a problem hiding this comment.
Thanks! It's great to see that there's actually a way to handle this. My only request would be to add a test so this is covered.
I hope to see this in the final version of 3.2 ...
There was a problem hiding this comment.
Thanks, @wandadars, this looks really good. I was worried that this would introduce a significant performance penalty due to the iteration required to exactly hit the target advance limit, but I think what actually happens is that this iteration is done entirely on the interpolated solution vector and as such doesn't require any additional evaluations of the ODE RHS function.
Addendum: I also agree with @ischoegl's suggestion on improving the testing of this. Probably the biggest gap in the coverage is on the verbose logging side. You can test this in pytest using the capsys fixture; there are a couple of instances in the test suite now that use this that you can use as examples.
02b8fee to
57028f5
Compare
speth
left a comment
There was a problem hiding this comment.
Thanks for the updates, @wandadars. This looks good to me.
I added the "no throw" wrapper around evalRootFunctions that I commented on but may not have been completely clear about and updated a few comments.
@ischoegl, since I've now modified this PR, will you please review/approve?
ischoegl
left a comment
There was a problem hiding this comment.
Thank you, @wandadars (and @speth). As the original author of the advance limits capability, I am very happy to see this being made more functional.
This was just an attempt to try and resolve the issue discussed in #1453. This may be too invasive to be useful to the code base, but just wanted to open a pull request just in case.
Event-based limiter: Enforce advance limits with a CVODE root function so integration stops exactly when any component reaches its configured limit, preventing large overshoots between output points. Hooked via CVodeRootInit and handled CV_ROOT_RETURN.
Closes #1453
First example case from #1453
The plot from that case using this updated approach is:
I also ran the case from the original issue report with the unit test parameters.
Click to view code example 1
This was using the default values from the unit test

And this was using the tighter tolerance values from the issue discussion.
For reference, this is the behavior of the Cantera version (3.1.0) running the same script with the tighter tolerances.