<html><head><meta http-equiv="content-type" content="text/html; charset=utf-8"></head><body style="overflow-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;"><div><br></div> The callbacks for SNES, such as SNESSetFunction(), are not allowed to change the value of the solution x. The updates to the solution are controlled by the nonlinear solver being used by SNES; for example, with Newton's method with line search, the solution is updated by the SNES Newton solver after a successful linear search is computed. <div><br></div><div> Could you please fully explain the context in which you wish to change the value of x during the SNES solve directly and what callback the issue is occurring in?</div><div><br></div><div> Barry</div><div><br id="lineBreakAtBeginningOfMessage"><div><br><blockquote type="cite"><div>On Dec 10, 2024, at 3:27 AM, Blauth, Sebastian <sebastian.blauth@itwm.fraunhofer.de> wrote:</div><br class="Apple-interchange-newline"><div><meta charset="UTF-8"><div class="WordSection1" style="page: WordSection1; caret-color: rgb(0, 0, 0); font-family: Helvetica; font-size: 18px; font-style: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none;"><div style="margin: 0cm; font-size: 11pt; font-family: Calibri, sans-serif;">Hi everyone,<o:p></o:p></div><div style="margin: 0cm; font-size: 11pt; font-family: Calibri, sans-serif;"><o:p> </o:p></div><div style="margin: 0cm; font-size: 11pt; font-family: Calibri, sans-serif;"><span lang="EN-US">I am having trouble with using SNES from petsc4py in PETSc 3.22. The problem is similar to<span class="Apple-converted-space"> </span><a href="https://urldefense.us/v3/__https://gitlab.com/petsc/petsc/-/issues/1611__;!!G_uCfscf7eWS!e_sGSUu4uYIocD18SOI4JfyPT1NUuUlkmunWUuuC6WaK00lEvX4Blk795PTQ5WYfjVVE3jQP6g9RcRiDAzJ6Xd4$" style="color: rgb(5, 99, 193); text-decoration: underline;">https://gitlab.com/petsc/petsc/-/issues/1611</a><span class="Apple-converted-space"> </span>and related to the readonly access of “x”. Particularly, in my application, based on FEniCS, I want to solve a nonlinear PDE. Therefore, in my callbacks, I want to set the vector of DoFs of my FEniCS function to “x” with a line like<o:p></o:p></span></div><div style="margin: 0cm; font-size: 11pt; font-family: Calibri, sans-serif;"><span lang="EN-US"><o:p> </o:p></span></div><div style="margin: 0cm; font-size: 11pt; font-family: Calibri, sans-serif;"><span lang="EN-US">self.u.vector().vec().setArray(x)<o:p></o:p></span></div><div style="margin: 0cm; font-size: 11pt; font-family: Calibri, sans-serif;"><span lang="EN-US"><o:p> </o:p></span></div><div style="margin: 0cm; font-size: 11pt; font-family: Calibri, sans-serif;"><span lang="EN-US">However, this now raises the error<o:p></o:p></span></div><div style="margin: 0cm; font-size: 11pt; font-family: Calibri, sans-serif;"><span lang="EN-US"><o:p> </o:p></span></div><div style="margin: 0cm; font-size: 11pt; font-family: Calibri, sans-serif;"><span lang="EN-US">[0] Vector 'Vec_0x84000003_0' (argument #1) was locked for read-only access in unknown_function() at unknown file:0 (line numbers only accurate to function begin)<o:p></o:p></span></div><div style="margin: 0cm; font-size: 11pt; font-family: Calibri, sans-serif;"><span lang="EN-US"><o:p> </o:p></span></div><div style="margin: 0cm; font-size: 11pt; font-family: Calibri, sans-serif;"><span lang="EN-US">I believe that this is a consequence of<span class="Apple-converted-space"> </span><a href="https://urldefense.us/v3/__https://gitlab.com/petsc/petsc/-/merge_requests/7567*22c226fc29b6fc9dc5781b0aff4dcc70ac6c3489__;Iw!!G_uCfscf7eWS!e_sGSUu4uYIocD18SOI4JfyPT1NUuUlkmunWUuuC6WaK00lEvX4Blk795PTQ5WYfjVVE3jQP6g9RcRiDGTemu34$" style="color: rgb(5, 99, 193); text-decoration: underline;">https://gitlab.com/petsc/petsc/-/merge_requests/7567#22c226fc29b6fc9dc5781b0aff4dcc70ac6c3489</a>, but I did not find any information on how to remove the lock from the vector or how I can set use “x” to update the vector of my function. Using<o:p></o:p></span></div><div style="margin: 0cm; font-size: 11pt; font-family: Calibri, sans-serif;"><span lang="EN-US"><o:p> </o:p></span></div><div style="margin: 0cm; font-size: 11pt; font-family: Calibri, sans-serif;"><span lang="EN-US">xx = x.getArray(readonly=True)<o:p></o:p></span></div><div style="margin: 0cm; font-size: 11pt; font-family: Calibri, sans-serif;"><span lang="EN-US"><o:p> </o:p></span></div><div style="margin: 0cm; font-size: 11pt; font-family: Calibri, sans-serif;"><span lang="EN-US">as described in<span class="Apple-converted-space"> </span><a href="https://urldefense.us/v3/__https://gitlab.com/petsc/petsc/-/issues/1611__;!!G_uCfscf7eWS!e_sGSUu4uYIocD18SOI4JfyPT1NUuUlkmunWUuuC6WaK00lEvX4Blk795PTQ5WYfjVVE3jQP6g9RcRiDAzJ6Xd4$" style="color: rgb(5, 99, 193); text-decoration: underline;">https://gitlab.com/petsc/petsc/-/issues/1611</a><span class="Apple-converted-space"> </span>does not work either, as calling self.u.vector().vec().setArray(xx) then fails with the same error message.<o:p></o:p></span></div><div style="margin: 0cm; font-size: 11pt; font-family: Calibri, sans-serif;"><span lang="EN-US"><o:p> </o:p></span></div><div style="margin: 0cm; font-size: 11pt; font-family: Calibri, sans-serif;"><span lang="EN-US">Does anyone have an idea how to fix this?<span class="Apple-converted-space"> </span><o:p></o:p></span></div><div style="margin: 0cm; font-size: 11pt; font-family: Calibri, sans-serif;"><span lang="EN-US">Thanks a lot in advance,<o:p></o:p></span></div><div style="margin: 0cm; font-size: 11pt; font-family: Calibri, sans-serif;"><span lang="EN-US">Sebastian<o:p></o:p></span></div><div style="margin: 0cm; font-size: 11pt; font-family: Calibri, sans-serif;"><span lang="EN-US"><o:p> </o:p></span></div><div style="margin: 0cm; font-size: 11pt; font-family: Calibri, sans-serif;"><span lang="EN-US"><o:p> </o:p></span></div><div style="margin: 0cm; font-size: 11pt; font-family: Calibri, sans-serif;"><span lang="EN-US"><o:p> </o:p></span></div><div style="margin: 0cm; font-size: 11pt; font-family: Calibri, sans-serif;"><span>--<o:p></o:p></span></div><div style="margin: 0cm; font-size: 11pt; font-family: Calibri, sans-serif;"><span>Dr. Sebastian Blauth<o:p></o:p></span></div><div style="margin: 0cm; font-size: 11pt; font-family: Calibri, sans-serif;"><span>Fraunhofer-Institut für<o:p></o:p></span></div><div style="margin: 0cm; font-size: 11pt; font-family: Calibri, sans-serif;"><span>Techno- und Wirtschaftsmathematik ITWM<o:p></o:p></span></div><div style="margin: 0cm; font-size: 11pt; font-family: Calibri, sans-serif;"><span>Abteilung Transportvorgänge<o:p></o:p></span></div><div style="margin: 0cm; font-size: 11pt; font-family: Calibri, sans-serif;"><span>Fraunhofer-Platz 1, 67663 Kaiserslautern<o:p></o:p></span></div><div style="margin: 0cm; font-size: 11pt; font-family: Calibri, sans-serif;"><span>Telefon: +49 631 31600-4968<o:p></o:p></span></div><div style="margin: 0cm; font-size: 11pt; font-family: Calibri, sans-serif;"><span><a href="mailto:sebastian.blauth@itwm.fraunhofer.de" style="color: rgb(5, 99, 193); text-decoration: underline;"><span style="color: blue;">sebastian.blauth@itwm.fraunhofer.de</span></a><o:p></o:p></span></div><div style="margin: 0cm; font-size: 11pt; font-family: Calibri, sans-serif;"><span><a href="https://urldefense.us/v3/__https://www.itwm.fraunhofer.de/__;!!G_uCfscf7eWS!e_sGSUu4uYIocD18SOI4JfyPT1NUuUlkmunWUuuC6WaK00lEvX4Blk795PTQ5WYfjVVE3jQP6g9RcRiDCxmHUOY$" style="color: rgb(5, 99, 193); text-decoration: underline;"><span style="color: blue;">https://www.itwm.fraunhofer.de</span></a></span></div></div></div></blockquote></div><br></div></body></html>