[petsc-users] about snes and finite difference jacobian approximations

Jed Brown jed at 59A2.org
Sat May 1 09:47:43 CDT 2010


On Fri, 30 Apr 2010 22:17:09 +0800, "=?gb2312?B?s8LA1sa9o6hMZXBpbmcgQ2hlbqOp?=" <chenleping at yahoo.cn> wrote:
> Dear petsc teams,
> When I use snes, I find the Jacobian matrix computation is an imposible misson,
> however,I don't konw how to use "Finite Difference Jacobian Approximations", for example,
> I modified the example "ex1f.F" and the function FormJacobian() remain unchanged,as follows,
>       call FormJacobian(snes,x,J,J,flag,dummy,ierr)
>       call MatGetColoring(J,MATCOLORING_SL,iscoloring,ierr)
>       call MatFDColoringCreate(J,iscoloring,fdcoloring,ierr)
>       call ISColoringDestroy(iscoloring,ierr)
>       call MatFDColoringSetFromOptions(fdcoloring,ierr)
>       call SNESSetJacobian(snes,J,J,SNESDefaultComputeJacobianColor, fdcoloring,ierr)
> but,
> [0]PETSC ERROR: --------------------- Error Message ------------------------------------
> [0]PETSC ERROR: Object is in wrong state!
> [0]PETSC ERROR: Must call MatFDColoringSetFunction()!

You have not given the MatFDColoring any information about your problem
so it has nothing to finite difference.  When modifying ex1f.F, you
dropped the mandatory call to MatFDColoringSetFunction().

> and I don't understand 
> /*
> This initializes the nonzero structure of the Jacobian. This is artificial
> because clearly if we had a routine to compute the Jacobian we wouldn’t
> need to use finite differences.
> */
> so I don't how to define the function FormJacobian().

Usually the nonzero structure is available based on the mesh and
discretization that you are using, and does not depend on the physics of
your problem.  If you are using a DA, DAGetMatrix() will initialize the
matrix so you can replace FormJacobian() with DAGetMatrix().  A more
realistic example is in snes/examples/tutorials/ex5.c.

Jed

PS: Either your message took a day to deliver or it's "Date" header is
incorrect.


More information about the petsc-users mailing list