[petsc-users] Issue with SNES with petsc4py 3.22

Barry Smith bsmith at petsc.dev
Tue Dec 10 09:31:35 CST 2024


   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. 

   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?

   Barry


> On Dec 10, 2024, at 3:27 AM, Blauth, Sebastian <sebastian.blauth at itwm.fraunhofer.de> wrote:
> 
> Hi everyone,
>  
> I am having trouble with using SNES from petsc4py in PETSc 3.22. The problem is similar to https://urldefense.us/v3/__https://gitlab.com/petsc/petsc/-/issues/1611__;!!G_uCfscf7eWS!e_sGSUu4uYIocD18SOI4JfyPT1NUuUlkmunWUuuC6WaK00lEvX4Blk795PTQ5WYfjVVE3jQP6g9RcRiDAzJ6Xd4$  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
>  
> self.u.vector().vec().setArray(x)
>  
> However, this now raises the error
>  
> [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)
>  
> I believe that this is a consequence of https://urldefense.us/v3/__https://gitlab.com/petsc/petsc/-/merge_requests/7567*22c226fc29b6fc9dc5781b0aff4dcc70ac6c3489__;Iw!!G_uCfscf7eWS!e_sGSUu4uYIocD18SOI4JfyPT1NUuUlkmunWUuuC6WaK00lEvX4Blk795PTQ5WYfjVVE3jQP6g9RcRiDGTemu34$ , 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
>  
> xx = x.getArray(readonly=True)
>  
> as described in https://urldefense.us/v3/__https://gitlab.com/petsc/petsc/-/issues/1611__;!!G_uCfscf7eWS!e_sGSUu4uYIocD18SOI4JfyPT1NUuUlkmunWUuuC6WaK00lEvX4Blk795PTQ5WYfjVVE3jQP6g9RcRiDAzJ6Xd4$  does not work either, as calling self.u.vector().vec().setArray(xx) then fails with the same error message.
>  
> Does anyone have an idea how to fix this? 
> 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 <mailto:sebastian.blauth at itwm.fraunhofer.de>
> https://urldefense.us/v3/__https://www.itwm.fraunhofer.de__;!!G_uCfscf7eWS!e_sGSUu4uYIocD18SOI4JfyPT1NUuUlkmunWUuuC6WaK00lEvX4Blk795PTQ5WYfjVVE3jQP6g9RcRiDineKawk$  <https://urldefense.us/v3/__https://www.itwm.fraunhofer.de/__;!!G_uCfscf7eWS!e_sGSUu4uYIocD18SOI4JfyPT1NUuUlkmunWUuuC6WaK00lEvX4Blk795PTQ5WYfjVVE3jQP6g9RcRiDCxmHUOY$ >
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mcs.anl.gov/pipermail/petsc-users/attachments/20241210/ff875016/attachment-0001.html>


More information about the petsc-users mailing list