Use SNESSetUpdate() to provide a callback function that gets called by SNES 
automatically immediately before each linear solve. Inside your callback use 
SNESGetFunction(snes,f,NULL,NULL); to access the last computed value of your 
function, from this you can update your global variable.

Barry


> On Feb 14, 2024, at 4:28 PM, Yi Hu <y...@mpie.de> wrote:
> 
> Dear PETSc team,
> 
> I am using a newtonls snes solver. I know that form residual is invoked at 
> several locations of the algorithm, first evaluated for the rhs of ksp 
> solver, then several times for obtaining the optimal step of line search.
> 
> In my problem I have a global variable that is updated every time when form 
> residual is called, which is not desired in the context of netwonls. 
> Basically, it should be only evaluated for the purpose of rhs of ksp (and not 
> in line search). So is it possible to know in which context my form residual 
> is used for? Then I can just skip my line of updating global variable 
> depending on this condition. If not possible, could you suggest a workaround? 
> Or do I need to design a customized line search routine?
> 
> Thanks for your help.
> 
> Best regards,
> 
> Yi
> 
> 
> 
> -------------------------------------------------
> Stay up to date and follow us on LinkedIn, Twitter and YouTube.
> 
> Max-Planck-Institut für Eisenforschung GmbH
> Max-Planck-Straße 1
> D-40237 Düsseldorf
> Handelsregister B 2533 Amtsgericht Düsseldorf
> Geschäftsführung
> Prof. Dr. Gerhard Dehm
> Prof. Dr. Jörg Neugebauer
> Prof. Dr. Dierk Raabe
> Dr. Kai de Weldige
> Ust.-Id.-Nr.: DE 11 93 58 514 Steuernummer: 105 5891 1000
> 
> 
> Please consider that invitations and e-mails of our institute are only valid 
> if they end with …@mpie.de. If you are not sure of the validity please 
> contact r...@mpie.de
> 
> Bitte beachten Sie, dass Einladungen zu Veranstaltungen und E-Mails
> aus unserem Haus nur mit der Endung …@mpie.de gültig sind. In Zweifelsfällen 
> wenden Sie sich bitte an r...@mpie.de
> -------------------------------------------------
> 

Reply via email to