-
Notifications
You must be signed in to change notification settings - Fork 35
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
Added solve_system
to all DAE problem classes
#371
Conversation
Very nice! To me there seems to be quite a bit of boilerplate code (since the |
Of course it does make sense to have a class with the |
Sounds good! You can add more generic functions there, I assume? |
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## master #371 +/- ##
=======================================
Coverage 73.62% 73.63%
=======================================
Files 270 270
Lines 22383 22380 -3
=======================================
Hits 16480 16480
+ Misses 5903 5900 -3
☔ View full report in Codecov by Sentry. |
Yes, this should be possible. |
@@ -49,6 +55,7 @@ def __init__(self, nvars, newton_tol): | |||
# solution = data[:, 1:] | |||
# self.u_ref = interp1d(t, solution, kind='cubic', axis=0, fill_value='extrapolate') | |||
self.t_end = 0.0 | |||
self.work_counters['rhs'] = WorkCounter() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like at least this one could go to the generic parent class, too?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
True! I added this for all problem classes. I'll do that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks better and more convenient (like before), thanks a lot!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To me it seems like you could indeed save a lot of lines by inheriting from generic_implicit
in the fully_implicit_DAE
sweeper. You can also consider doing multiple inheritance if you plan to do IMEX at some point.
I have not checked very thoroughly, but I believe the integrate
, compute_residual
, predict
and compute_end_point
functions are all equivalent to the ones in generic_implicit
.
If you move the implSystem
function to the problem class, would it be possible to just use the generic_implicit
sweeper? I think there was some issue with this. Also, u_approx
is not usually passed to solve_system
, I think..? It probably doesn't work, but if it did, that would be nice.
""" | ||
Predictor to fill values at nodes before first sweep | ||
r""" | ||
Predictor to fill values at nodes before first sweep. It can decides whether the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
decides
-> decide
Yes, IMEX is indeed planned (and already done but not pushed yet), and I agree that multiple inheritance can be done here. At least |
Hm, I also got a message that you @brownbaerchen wrote somewhere (I cannot find it) that the |
Yes, I saw what you wrote after I made the comment, so I marked it as resolved. |
In this case, I vote to just overload the function and copy paste a few lines rather than adding default arguments to the other stuff. Multiple inheritance is tricky business in my opinion. For me, it requires a bit of trial and error as well as some praying. But it is kind of working here and I think it's quite elegant once it works. |
Indeed, I could removed lines by removing |
I see. In As for the residual, I am a bit confused that the residual is based on the magnitude of the right hand side evaluations rather than the integral. But I have no idea about the DAE implementation. Feel free to ignore this. You don't have to abstract as much as you can. Using code that is already there is better than repeating code, but bending over backwards to somehow make the code that is already there do what you want in a different place is also no good. |
I tried that but in the Regarding the residual: At first I was also a bit confused because using the right-hand side for computing the residual was a bit cumbersome. Let me explain you shortly (as this makes sense for me at least): How do you compute the residual for a system of equations? In case of having But now I'm thinking whether we also can compute the residual by using the integral formulation inside the DAE formulation.. Hm.. I know that repeating code is bad practice. @pancetta have already taught me the DRY principle some time, but I don't always see where I can apply it. In this case, I'm very thankful for such comments! |
Ah, I see. For |
Honestly, don't worry about abstraction. I was missing some small details that do make a difference and I think there is little to gain from further abstraction. Sorry about that :D |
Can we merge this? Issue lisawim#8 seems to be a topic for another PR anyway? |
Yes, can be merged. |
Currently, the
fully_implicit_DAE
sweeper solves all DAE problems in the same way, i.e., usingscipy.optimize.root(f, x0, method='hybr')
. Since it could be useful to choose the solver problem dependent, asolve_system
method is added to all DAE classes as this is already the case for all implemented ODE/PDE classes inpySDC
. The implicit system is defined in the sweeper anyway, because this nonlinear system does not change (since it is the collocation problem to be solved).So no magic here in this PR, I only moved these two line
Now, the problem classes still uses the same solver, but for the future, also different solver could be implemented and no one has to take care to change the sweeper itself every time.
to the problem classes.
Now, also
WorkCounters
are used to count the work which is also useful to get some statistics about the calls of the right-hand side and the calls of the right-hand side during the solve (because forhybr
no callback is available and also no iterations needed for the solve can be found..).