<html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;" class=""><div class=""><br class=""></div> SNESSetKSP() (and friends) was a mistake, it was originally introduced for symmetry reasons but doesn't seem to have a good reason to exist.<div class=""><br class=""></div><div class=""> Barry</div><div class=""><br class=""><div><br class=""><blockquote type="cite" class=""><div class="">On Oct 12, 2021, at 2:24 PM, Matthew Knepley <<a href="mailto:knepley@gmail.com" class="">knepley@gmail.com</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><div dir="ltr" class=""><div dir="ltr" class="">On Tue, Oct 12, 2021 at 10:27 AM Nicolás Barnafi <<a href="mailto:nabw91@gmail.com" class="">nabw91@gmail.com</a>> wrote:<br class=""></div><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr" class="">Thank you for the support. I rewrote the initialization in a simpler way, now it works as expected:<div class=""><br class=""></div><div class="">> dofmap_s = V.sub(0).dofmap().dofs(); is_s = PETSc.IS().createGeneral(dofmap_s)<br class="">> dofmap_p = V.sub(1).dofmap().dofs(); is_p = PETSc.IS().createGeneral(dofmap_p)<br class="">> snes = PETSc.SNES().create(MPI.COMM_WORLD)<br class="">> snes.setFunction(problem.F, b.vec()); snes.setJacobian(problem.J, J_mat.mat())<br class="">> pc = snes.ksp.getPC()<br class="">> pc.setType('fieldsplit')<br class="">> pc.setFieldSplitIS((None, is_s), (None, is_p))<br class="">> snes.setFromOptions()<br class="">> snes.solve(None, problem.u.vector().vec())<br class=""></div><div class=""><br class=""></div><div class="">Apparently trying to setup the solver's internals is not recommended. As a side note, I tried also setting up the KSP using 'SNESSetKSP', but this solution is not so good as giving the command 'snes_ksp_ew' does nothing, even though it gets correctly read as shown by snes.view(). </div></div></blockquote><div class=""><br class=""></div><div class="">I think I can explain this. The Eisenstat-Walker scheme is a way to set tolerances for the linear solves inside a Newton iteration. The goal is</div><div class="">to avoid over-solving the linear systems, meaning that far away from the solution accurate linear solves have no advantage over inaccurate ones.</div><div class="">Implementing this involves coordination with the linear solver since we are setting the convergence tolerance. When you replace the linear solve,</div><div class="">that setup is discarded. Thus, when configuring things, we recommend that you pull out the existing object</div><div class=""><br class=""></div><div class=""> SNESGetKSP()</div><div class=""><br class=""></div><div class="">and customize it, rather than creating a new object and setting it.</div><div class=""><br class=""></div><div class=""> Thanks,</div><div class=""><br class=""></div><div class=""> Matt</div><div class=""> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr" class=""><div class="">Thanks for the help!</div><div class="">Best, </div><div class="">Nicolas</div></div><br class=""><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Tue, Oct 12, 2021 at 4:23 PM Matthew Knepley <<a href="mailto:knepley@gmail.com" target="_blank" class="">knepley@gmail.com</a>> wrote:<br class=""></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr" class="">I looked over every place we use that error code. I do not think it is coming from PETSc, but rather from petsc4py. However, something<div class="">is eating the error message, and I think Stefano indicated. My first step would be to get the FEniCS folks to display the error message.</div><div class=""><br class=""></div><div class="">Another option is to just run it in Firedrake since I think we can see the stack properly there.</div><div class=""><br class=""></div><div class=""> Thanks,</div><div class=""><br class=""></div><div class=""> Matt</div></div><br class=""><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Tue, Oct 12, 2021 at 8:37 AM Nicolás Barnafi <<a href="mailto:nabw91@gmail.com" target="_blank" class="">nabw91@gmail.com</a>> wrote:<br class=""></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr" class="">Thank you Stefano for the help. I added the lines you indicated, but the error remains the same, here goes snes.view() + error<div class=""><br class=""></div><div class="">> SNES Object: 1 MPI processes<br class="">> type: qn<br class="">> SNES has not been set up so information may be incomplete<br class="">> type is BROYDEN, restart type is DEFAULT, scale type is JACOBIAN<br class="">> Stored subspace size: 10<br class="">> Using the single reduction variant.<br class="">> maximum iterations=10000, maximum function evaluations=30000<br class="">> tolerances: relative=1e-08, absolute=1e-50, solution=1e-08<br class="">> total number of function evaluations=0<br class="">> norm schedule ALWAYS<br class="">> SNESLineSearch Object: 1 MPI processes<br class="">> type: basic<br class="">> maxstep=1.000000e+08, minlambda=1.000000e-12<br class="">> tolerances: relative=1.000000e-08, absolute=1.000000e-15, lambda=1.000000e-08<br class="">> maximum iterations=1<br class="">> Traceback (most recent call last):<br class="">> File "Twist.py", line 234, in <module><br class="">> snes.setUp()<br class="">> File "PETSc/SNES.pyx", line 530, in petsc4py.PETSc.SNES.setUp<br class="">> petsc4py.PETSc.Error: error code 83<br class=""></div></div><br class=""><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Tue, Oct 12, 2021 at 2:07 PM Stefano Zampini <<a href="mailto:stefano.zampini@gmail.com" target="_blank" class="">stefano.zampini@gmail.com</a>> wrote:<br class=""></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr" class=""><div dir="ltr" class=""><br class=""></div><br class=""><div class="gmail_quote"><div dir="ltr" class="gmail_attr">Il giorno mar 12 ott 2021 alle ore 13:56 Nicolás Barnafi <<a href="mailto:nabw91@gmail.com" target="_blank" class="">nabw91@gmail.com</a>> ha scritto:<br class=""></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr" class="">Hello PETSc users, <div class=""><br class=""></div><div class="">first email sent!<br class="">I am creating a SNES solver using fenics, my example runs smoothly with 'newtonls', but gives a strange missing function error (error 83):</div><div class=""><br class=""></div></div></blockquote><div class=""><br class=""></div><div class="">Dolphin swallows any useful error information returned from PETSc. You can try using the below code snippet at the beginning of your script<br class=""></div><div class=""><br class=""></div><div class="">from petsc4py import PETSc<br class="">from dolfin import *<br class=""># Remove the dolfin error handler<br class="">PETSc.Sys.pushErrorHandler('python')</div><div class=""><br class=""></div><div class=""> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr" class=""><div class=""></div><div class=""><br class=""></div><div class="">these are the relevant lines of code where I setup the solver:</div><div class=""><br class=""></div><div class="">> problem = SNESProblem(Res, sol, bcs)<br class="">> b = PETScVector() # same as b = PETSc.Vec()<br class="">> J_mat = PETScMatrix()<br class="">> snes = PETSc.SNES().create(MPI.COMM_WORLD)<br class="">> snes.setFunction(problem.F, b.vec())<br class="">> snes.setJacobian(problem.J, J_mat.mat())<br class="">> # Set up fieldsplit<br class="">> ksp = snes.ksp<br class="">> ksp.setOperators(J_mat.mat())<br class="">> pc = ksp.pc<br class="">> pc.setType('fieldsplit')<br class="">> dofmap_s = V.sub(0).dofmap().dofs()<br class="">> dofmap_p = V.sub(1).dofmap().dofs()<br class="">> is_s = PETSc.IS().createGeneral(dofmap_s)<br class="">> is_p = PETSc.IS().createGeneral(dofmap_p)<br class="">> pc.setFieldSplitIS((None, is_s), (None, is_p))<br class="">> pc.setFromOptions()<br class="">> snes.setFromOptions()<br class="">> snes.setUp()<br class=""><div class=""> <br class=""></div></div></div></blockquote><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr" class=""><div class=""><div class="">If it can be useful, this are the outputs of snes.view(), ksp.view() and pc.view():</div><div class=""><br class=""></div><div class="">> type: qn<br class="">> SNES has not been set up so information may be incomplete<br class="">> type is BROYDEN, restart type is DEFAULT, scale type is JACOBIAN<br class="">> Stored subspace size: 10<br class="">> Using the single reduction variant.<br class="">> maximum iterations=10000, maximum function evaluations=30000<br class="">> tolerances: relative=1e-08, absolute=1e-50, solution=1e-08<br class="">> total number of function evaluations=0<br class="">> norm schedule ALWAYS<br class="">> SNESLineSearch Object: 4 MPI processes<br class="">> type: basic<br class="">> maxstep=1.000000e+08, minlambda=1.000000e-12<br class="">> tolerances: relative=1.000000e-08, absolute=1.000000e-15, lambda=1.000000e-08<br class="">> maximum iterations=1<br class=""></div><div class="">> KSP Object: 4 MPI processes<br class="">> type: gmres<br class="">> restart=1000, using Modified Gram-Schmidt Orthogonalization<br class="">> happy breakdown tolerance 1e-30<br class="">> maximum iterations=1000, initial guess is zero<br class="">> tolerances: relative=1e-05, absolute=1e-50, divergence=10000.<br class="">> left preconditioning<br class="">> using UNPRECONDITIONED norm type for convergence test<br class="">> PC Object: 4 MPI processes<br class="">> type: fieldsplit<br class="">> PC has not been set up so information may be incomplete<br class="">> FieldSplit with Schur preconditioner, factorization FULL<br class=""></div><div class=""><br class=""></div><div class="">I know that PC is not setup, but if I do it before setting up the SNES, the error persists. Thanks in advance for your help. </div><div class=""><br class=""></div><div class="">Best, </div><div class="">Nicolas</div>-- <br class=""><div dir="ltr" class=""><div dir="ltr" class=""><div class=""><div dir="ltr" class="">Nicolás Alejandro Barnafi Wittwer</div></div></div></div></div></div>
</blockquote></div><br clear="all" class=""><br class="">-- <br class=""><div dir="ltr" class="">Stefano</div></div>
</blockquote></div><br clear="all" class=""><div class=""><br class=""></div>-- <br class=""><div dir="ltr" class=""><div dir="ltr" class=""><div class=""><div dir="ltr" class="">Nicolás Alejandro Barnafi Wittwer</div></div></div></div>
</blockquote></div><br clear="all" class=""><div class=""><br class=""></div>-- <br class=""><div dir="ltr" class=""><div dir="ltr" class=""><div class=""><div dir="ltr" class=""><div class=""><div dir="ltr" class=""><div class="">What most experimenters take for granted before they begin their experiments is infinitely more interesting than any results to which their experiments lead.<br class="">-- Norbert Wiener</div><div class=""><br class=""></div><div class=""><a href="http://www.cse.buffalo.edu/~knepley/" target="_blank" class="">https://www.cse.buffalo.edu/~knepley/</a><br class=""></div></div></div></div></div></div></div>
</blockquote></div><br clear="all" class=""><div class=""><br class=""></div>-- <br class=""><div dir="ltr" class=""><div dir="ltr" class=""><div class=""><div dir="ltr" class="">Nicolás Alejandro Barnafi Wittwer</div></div></div></div>
</blockquote></div><br clear="all" class=""><div class=""><br class=""></div>-- <br class=""><div dir="ltr" class="gmail_signature"><div dir="ltr" class=""><div class=""><div dir="ltr" class=""><div class=""><div dir="ltr" class=""><div class="">What most experimenters take for granted before they begin their experiments is infinitely more interesting than any results to which their experiments lead.<br class="">-- Norbert Wiener</div><div class=""><br class=""></div><div class=""><a href="http://www.cse.buffalo.edu/~knepley/" target="_blank" class="">https://www.cse.buffalo.edu/~knepley/</a><br class=""></div></div></div></div></div></div></div></div>
</div></blockquote></div><br class=""></div></body></html>