[petsc-users] Issue with SNES with petsc4py 3.22
Blauth, Sebastian
sebastian.blauth at itwm.fraunhofer.de
Tue Dec 10 09:35:55 CST 2024
Thanks fort he clarification. And it makes sense that x is read-only. I solved my issue by actually creating a new, empty vector which is used in snes.solve and can update my FEniCS vector from this, see: https://github.com/sblauth/cashocs/pull/533
What I did not get at first is that PETSc.VEC.setArray seems to create a shallow copy, whereas PETSc.VEC.aypx(0.0, …) seems to create something like a deep copy. Using aypx this is not an issue anymore.
Best,
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://www.itwm.fraunhofer.de
From: Barry Smith <bsmith at petsc.dev>
Sent: Tuesday, December 10, 2024 4:32 PM
To: Blauth, Sebastian <sebastian.blauth at itwm.fraunhofer.de>
Cc: petsc-users at mcs.anl.gov
Subject: Re: [petsc-users] Issue with SNES with petsc4py 3.22
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 <mailto: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://gitlab.com/petsc/petsc/-/issues/1611> https://gitlab.com/petsc/petsc/-/issues/1611 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://gitlab.com/petsc/petsc/-/merge_requests/7567#22c226fc29b6fc9dc5781b0aff4dcc70ac6c3489> https://gitlab.com/petsc/petsc/-/merge_requests/7567#22c226fc29b6fc9dc5781b0aff4dcc70ac6c3489, 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://gitlab.com/petsc/petsc/-/issues/1611> https://gitlab.com/petsc/petsc/-/issues/1611 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://www.itwm.fraunhofer.de <https://www.itwm.fraunhofer.de/>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mcs.anl.gov/pipermail/petsc-users/attachments/20241210/fcdbd639/attachment-0001.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/pkcs7-signature
Size: 7943 bytes
Desc: not available
URL: <http://lists.mcs.anl.gov/pipermail/petsc-users/attachments/20241210/fcdbd639/attachment-0001.p7s>
More information about the petsc-users
mailing list