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

Barry Smith bsmith at petsc.dev
Thu Jul 6 21:03:44 CDT 2023


   Could you provide more context on when and why "Some values in the solution vectors must be inserted to some different location." during the solution process.

   SNES provides two "hooks" already that allow some "changes" to the solution during the solve process. Maybe one of the hooks is what you need, if not we may be able to provide another hook.  https://petsc.org/release/manualpages/SNES/SNESLineSearchSetPreCheck/ https://petsc.org/release/manualpages/SNES/SNESLineSearchSetPostCheck/#sneslinesearchsetpostcheck  It is a delicate process changing solution values within a Newton solve.



> On Jul 6, 2023, at 4:13 PM, YuSh Lo <ysjosh.lo at gmail.com> wrote:
> 
> Hi Matthew,
> 
> Thank you. I will try setting up custom linesearch.
> 
> Thanks,
> Josh
> 
> 
> Matthew Knepley <knepley at gmail.com <mailto:knepley at gmail.com>> 於 2023年7月6日 週四 下午3:01寫道:
>> On Thu, Jul 6, 2023 at 3:42 PM YuSh Lo <ysjosh.lo at gmail.com <mailto: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/fbcd55de/attachment-0001.html>


More information about the petsc-users mailing list