[petsc-users] Setting up nonlinear preconditioning with petsc4py

Matthew Knepley knepley at gmail.com
Wed Dec 4 06:47:54 CST 2024


On Wed, Dec 4, 2024 at 4:44 AM Blauth, Sebastian <
sebastian.blauth at itwm.fraunhofer.de> wrote:

> Hi everyone,
>
>
>
> I wanted to try nonlinear preconditioning for solving nonlinear systems.
> The problems arise from PDEs discretized with FEniCS and I have
> successfully implemented a wrapper for SNES. However, once I want to try
> nonlinear preconditioning by adding the option “-npc_snes_type newtonls”
> (or other solvers such as nrichardson), I get the error code 56.
>
>
>
> My approach looks something like this
>
>
>
> from petsc4py import PETSc
>
>
>
> snes = PETSc.SNES().create()
>
> snes.setFunction(self.assemble_function, self.residual_petsc)
>
> snes.setJacobian(self.assemble_jacobian, self.A_petsc, self.P_petsc)
>
> snes.setFromOptions()
>
>
>
> snes.solve(None, self.u.vector().vec())
>
> snes.destroy()
>
>
>
> I don’t think that my user defined functions are problematic. The code
> runs well with the options (just an example)
>
> -snes_type newtonls
>
> -snes_rtol 1e-6
>
> -snes_monitor
>
> -ksp_type gmres
>
> -ksp_monitor_true_residual
>
> -pc_type lu
>
> -pc_factor_mat_solver_type mumps
>
> -mat_mumps_icntl_24
>
>
>
> Here, the gmres is just used to verify that the direct solver works as
> expected. Newton Krylov methods also work well.
>
> However, once I use
>
>
>
> -snes_type nrichardson
>
> -npc_snes_type newtonls
>
> -npc_snes_max_it 4
>
>
>
> (as discussed e.g. in
> https://urldefense.us/v3/__https://climatemodeling.org/*rmills/talks/PSU-ACM-seminar-2024.pdf__;fg!!G_uCfscf7eWS!ZpQxakVxVcyih0WUbW_MxFNHXR0tUbZAvis8z497q782yqbJraYBBCMst79xJm6nlGdBUqW3I2vIDAtJiUTR$ ) I get
> the error message
>
>
>
> File "/p/tv/blauths/cashocs/cashocs/nonlinear_solvers/snes.py", line 250,
> in solve
>
>     snes.solve(None, self.u.vector().vec())
>
>   File "petsc4py/PETSc/SNES.pyx", line 1555, in petsc4py.PETSc.SNES.solve
>
> petsc4py.PETSc.Error: error code 56
>
>
>
> I would be really grateful if someone could point me to the right
> direction on how to use nonlinear precondition with petsc4py.
>

56 is PETSC_ERR_SUP, which means we hit an unsupported operation. petsc4py
preserves the stack trace, so FEniCS should not be throwing it away (along
with the error message). Maybe run in the debugger so we can see the error
message and stack?

  Thanks,

      Matt


> Thanks a lot in advance,
>
> Sebastian
>
>
>
> --
>
> Dr. Sebastian Blauth
>
> Fraunhofer-Institut für
>
> Techno- und Wirtschaftsmathematik ITWM
>
> Abteilung Transportvorgänge
>
> Fraunhofer-Platz 1, 67663 Kaiserslautern
>
> Telefon: +49 631 31600-4968
>
> sebastian.blauth at itwm.fraunhofer.de
>
> https://urldefense.us/v3/__https://www.itwm.fraunhofer.de__;!!G_uCfscf7eWS!ZpQxakVxVcyih0WUbW_MxFNHXR0tUbZAvis8z497q782yqbJraYBBCMst79xJm6nlGdBUqW3I2vIDJ9nKGZK$ 
>
>
>


-- 
What most experimenters take for granted before they begin their
experiments is infinitely more interesting than any results to which their
experiments lead.
-- Norbert Wiener

https://urldefense.us/v3/__https://www.cse.buffalo.edu/*knepley/__;fg!!G_uCfscf7eWS!ZpQxakVxVcyih0WUbW_MxFNHXR0tUbZAvis8z497q782yqbJraYBBCMst79xJm6nlGdBUqW3I2vIDOFKYWl_$  <https://urldefense.us/v3/__http://www.cse.buffalo.edu/*knepley/__;fg!!G_uCfscf7eWS!ZpQxakVxVcyih0WUbW_MxFNHXR0tUbZAvis8z497q782yqbJraYBBCMst79xJm6nlGdBUqW3I2vIDIJYMNfe$ >
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mcs.anl.gov/pipermail/petsc-users/attachments/20241204/b5aaa74a/attachment.html>


More information about the petsc-users mailing list