[petsc-users] Regarding SNESSetFunction and SNESSetJacobian

Barry Smith bsmith at petsc.dev
Fri Oct 9 11:10:53 CDT 2020


    I'm sorry, I made a small mistake in my previous email. It is 

   F'(x) = A(x) + A'(x)x - b'(x)   not F'(x) = A(x) + A'(x)x + b'(x) 


> On Oct 9, 2020, at 10:40 AM, baikadi pranay <pranayreddy865 at gmail.com> wrote:
> 
> Thank you for the response. I have one more quick question.
> Is the solution of A(x)x=b(x) obtained from Newton's method the final solution or is it the solution of A(x^i)x^(i+1)=b(x^i). In other words, do I need to use the solution obtained from Newton's method to update the Jacobian, use Newton method again and repeat the process?

  SNESSolve() with SNESSetPicard() continues the iteration calling your routine that computes A repeatedly until the system has converged. You can control the convergence criteria with SNESSetTolerances() (see also the manual pages that page links to). You never need call your routine that computes A from your code, PETSc calls it as it needs it. 

  Also, and I apologize for being pedantic, but using the computation of A() and SNESSetPicard() is NOT doing Newton's method, it is a different algorithm called Picard. If you want to run Newton then you need to write a routine that computes the quantity A(x) + A'(x)x + b'(x)  (not necessarily by using this exact product-rule formula). Computing just A() cannot give you Newton's method. For many problems Picard is good enough so people don't bother to code F'(x) and skip Newton's method and just use Picard. For some problems the extra effort of coding F'(x) gives a Newton that converges much faster than Picard.

  Barry




> Best Regards,
> Pranay. 
>> 
> On Fri, Oct 9, 2020 at 7:43 AM Barry Smith <bsmith at petsc.dev <mailto:bsmith at petsc.dev>> wrote:
> 
>   To provide the functions to the Picard iteration you call SNESSetPicard() not SNESSetFunction() and SNESSetJacobian(), you provide code to compute A(x) and b(x).
> 
>   Note that in the Picard iteration the matrix A(x) is NOT the Jacobian of  F(x) = A(x) x - b(x). The Jacobian of F(x) is the more complicated F'(x) = A(x) + A'(x)x + b'(x) 
> 
>   Barry
> 
> 
>> On Oct 9, 2020, at 6:38 AM, Matthew Knepley <knepley at gmail.com <mailto:knepley at gmail.com>> wrote:
>> 
>> On Fri, Oct 9, 2020 at 4:53 AM baikadi pranay <pranayreddy865 at gmail.com <mailto:pranayreddy865 at gmail.com>> wrote:
>> Hello,
>> I have a couple of questions regarding how SNESSetFunction,SNESSetJacobian and SNESSolve work together. I am trying to solve a nonlinear system of the form A(x)x=b(x). I am using Fortran90. The way I intend to solve the above equation is as follows:
>> Step 1: initialize x with an initial guess
>> Step 2: Solve using SNESSolve for (x^i, i is the iteration number, i=1,2,3...)
>> Step 3: Calculate the update and check if it is less than tolerance
>> Step 4: If yes, end the loop. Else the jacobian matrix and function should be updated using x^(i) and go back to step 2.
>> 
>> You are describing the Picard iteration:
>> 
>>   https://www.mcs.anl.gov/petsc/petsc-current/docs/manualpages/SNES/SNESSetPicard.html <https://www.mcs.anl.gov/petsc/petsc-current/docs/manualpages/SNES/SNESSetPicard.html>
>> 
>> You can do this, but it will converge more slowly than Newton. We usually advise using Newton.
>>  
>> The part which is a little confusing to me is in understanding how to update the jacobian matrix and the function F (= A(x)x-b(x)). 
>> 
>> 1) Should I explicitly call the subroutines Form Function and FormJacobian by using x^i as the input argument or is this automatically taken care of when I go back to step 2 and call SNESSolve?
>> 
>> No. SNES calls these automatically.
>> 
>>   Thanks,
>> 
>>      Matt
>>  
>> 2) If the answer to the above question is yes, I do not fully understand the role played by the functions SNESSetFunction and SNESSetJacobian.
>> 
>> I apologize if I am not clear in my explanation. I would be glad to elaborate on any section of my question. Please let me know if you need any further information from my side.
>> 
>> Thank you,
>> Sincerely,
>> Pranay.
>>>> 
>> 
>> -- 
>> 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/20201009/4dcd674c/attachment-0001.html>


More information about the petsc-users mailing list