-
Notifications
You must be signed in to change notification settings - Fork 25
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
Custom solver #734
Custom solver #734
Conversation
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #734 +/- ##
==========================================
+ Coverage 99.52% 99.53% +0.01%
==========================================
Files 58 59 +1
Lines 2501 2577 +76
==========================================
+ Hits 2489 2565 +76
Misses 12 12 ☔ View full report in Codecov by Sentry. |
One thing to mention is that the |
@KulaginVladimir thanks for this I think it is much needed to give more flexibility. Would you mind listing the differences - if any - from the user point of view when running the default behaviour? |
Also tagging @Allentro as he was interested in this feature |
As I tested, there shouldn't appear significant differences (in errors or usage) with these changes if, for example, During the model initialisation, a default As I mentioned above, there is a change in fenics logs (i.e. when @RemDelaporteMathurin is this what you asked? I also wonder about an example of using a custom solver. Shall we add it somewhere? |
festim/concentration/traps/traps.py
Outdated
f.begin( | ||
"Solving nonlinear variational problem." | ||
) # Add message to fenics logs | ||
trap.newton_solver.solve(problem, trap.density[0].vector()) | ||
f.end() |
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.
So, I added fenics.begin()
/fenics.end()
(see decription) to increase the indentation level of info messages printed by the Newton solver.
I would like to keep this open while we test it thoroughly. Playing with the solver can be a bit dangerous so I want to make sure we're not merging any breaking stuff. |
@@ -36,18 +38,33 @@ def __init__( | |||
If None, the default fenics linear solver will be used ("umfpack"). | |||
More information can be found at: https://fenicsproject.org/pub/tutorial/html/._ftut1017.html. | |||
Defaults to None. | |||
preconditioner (str, optional): preconditioning method for the newton solver, | |||
options can be veiwed by print(list_krylov_solver_preconditioners()). |
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.
options can be veiwed by print(list_krylov_solver_preconditioners()). | |
options can be viewed by print(list_krylov_solver_preconditioners()). |
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.
Corrected
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.
Hi @KulaginVladimir my deepest apologies for taking so much time reviewing this.
I tested it and it seems to work perfectly well!
Several points:
- If users specify a custom solver for say the H transport problem, then the parameters given in
Settings
(absolute, relative tolerances, etc.) will be ignored. This is ok, but we should add a print statement to inform the users - Can be done in a separate PR but it would be nice to add some documentation and maybe a short demo in the workshop?
Co-authored-by: Rémi Delaporte-Mathurin <[email protected]>
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.
Thank you so much for this awesome contribution @KulaginVladimir !!
Proposed changes
Following #673, this PR introduces:
F.Settings(preconditioner="...")
HeatTransferProblem
) initialisation.The expected usage of a custom Newton solver is:
The same can be done for for the
F.ExtrinsicTrap
class:and for the
HeatTransferProblem
(but beforemy_model.initialise()
for the steady-state case!):Types of changes
What types of changes does your code introduce to FESTIM?
Checklist