Fix SNES NonlinearPDE class when using line search - #3507
Conversation
|
Failing line search in parallel run https://petsc.org/release/manualpages/SNES/SNES_DIVERGED_LINE_SEARCH |
|
This works but seems unsatisfactory. A point from Jonas: "...the pointer to the PETSc solution vector is linked directly to the pointer of the solution vector of Dolfinx, while in fact both instead should be independent, i.e. the vector at which Dolfinx assembles the forms and the solution vector PETSc works must not be the same to allow for these temporary solution vectors in PETSc." |
|
Looking at this again, I think a simpler solution would be to pass a new independent vector to a call to snes.solve(). |
|
Could we move this implementation into the dolfinx namespace? It is rather hard for users to see how to use PETSC snes as they have to browse the tests. |
|
To elaborate a bit more on the PETSc side of things to help the discussion: In my understanding, the SNES solver object usually only works with a solution vector This is not an issue unless we want to properly use the SNESLinesearch routines: See for instance here. instead of the expected which causes them to fail when they try to fit an ansatz e.g. to So perhaps another idea to fix the issue would be to somehow 'unlink' |
|
I think this was also the problem in this post on the discourse group. |
|
"So perhaps another idea to fix the issue would be to somehow 'unlink' u in the dolfinx namespace from X in the PETSc namespace?" Agreed, I think that is the best solution and I think it's more consistent with the design of DOLFINx and SNES. We should also consider adjusting our own NewtonSolver if we make the same link there. |
|
Thanks @jonas-heinzmann for noticing this. I'd suggest following patch. I've checked and all other uses of SNES (e.g. |
|
I think this is fixed - @jonas-heinzmann can you try this out? In short, users should (almost) never pass the same vector memory to @jorgensd We can bring I also took a look at our |
|
This seems to do the trick, thanks a lot! |
* Fix SNES NonlinearPDE class when using line search. * Remove comments. * Removing typing. * Works in parallel, needs reviewing (end of day). * Not entirely satisfactory... * Patch from Michal. * Add a comment * Ruff.
Thanks to @jonas-heinzmann for clearly identifying and explaining this issue and @michalhabera for help creating this fix.
When using a linesearch routine SNES needs to calculate (multiple times) the norm of the residual evaluated at a vector
wequal to the current solution plus some proposed scaling factor times the Newton increment. To do this SNES calls the user-defined residual evaluation routine passingw. Our current implementation of the residual evaluation routine overwrites the residual form stateuwithwbut does not replaceuwith the current solutionxbefore returning. This leads to a failure of the linesearch.This patch fixes this behaviour by preserving the internal state of the residual.