[petsc-users] User-defined updating function in SNES

Matthew Knepley knepley at gmail.com
Thu Jul 6 15:01:04 CDT 2023


On Thu, Jul 6, 2023 at 3:42 PM YuSh Lo <ysjosh.lo at gmail.com> wrote:

> Hi,
>
> I am using SNES to solve some nonlinear functions.
> After each iteration, I have an user-defined updating to do.
> Some values in the solution vectors must be inserted to some different
> location.
> I have tried to do it in the beginning of form RHS and form Jacobian, but
> the vector is read-only. The results are correct although some warnings are
> thrown with debug build saying that the vector is in wrong state. I also
> tried setting a function with SNESSetupdate, but the convergence is bad.
> Is the vector I get using SNESGetSolution the same as the vector that will
> be used in following forming Jacobian and RHS?, and is it again read only?
>

For these kinds of things, it might be easiest to put this in the line
search. I would write a custom line search routine that did your
modifications. That way you are assured that it does not short circuit
anything else since the line search is where we are updating the solution
directly.

It should also work in the Update(), and we could try to determine what is
wrong here, but that would be more digging. I think making it a line search
is easier.

  Thanks,

     Matt


> Thanks,
> Josh
>
>


-- 
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://www.cse.buffalo.edu/~knepley/ <http://www.cse.buffalo.edu/~knepley/>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mcs.anl.gov/pipermail/petsc-users/attachments/20230706/6e06e6af/attachment.html>


More information about the petsc-users mailing list