[petsc-users] help about my first petsc program

Jed Brown jed at 59A2.org
Wed Jun 23 09:44:27 CDT 2010


On Wed, 23 Jun 2010 10:22:19 -0400, Xuan YU <xxy113 at psu.edu> wrote:
> I got the correct results! Thanks!
> 
> Could you please tell me whether I can use TS to solve ODE without  
> providing Jacobian matrix?

Sure, use -snes_mf to solve it without assembling any matrix (linear
systems are solved with an unpreconditioned Krylov method).  Note that
this usually will not converge for larger problems.  To assemble a dense
matrix by finite differencing, you can use -snes_fd.

To use coloring to compute a sparse matrix efficiently, you have to know
the sparsity pattern of the Jacobian, try something like (this is
somewhat different in petsc-dev than release).

    ISColoring     iscoloring;
    ierr = DAGetColoring(rd->da,IS_COLORING_GLOBAL,MATAIJ,&iscoloring);CHKERRQ(ierr);
    ierr = MatFDColoringCreate(B,iscoloring,&matfdcoloring);CHKERRQ(ierr);
    ierr = ISColoringDestroy(iscoloring);CHKERRQ(ierr);
    ierr = MatFDColoringSetFunction(matfdcoloring,(PetscErrorCode(*)(void))SNESTSFormFunction,ts);CHKERRQ(ierr);
    ierr = MatFDColoringSetFromOptions(matfdcoloring);CHKERRQ(ierr);
    ierr = SNESSetJacobian(snes,A,B,SNESDefaultComputeJacobianColor,matfdcoloring);CHKERRQ(ierr);

Jed


More information about the petsc-users mailing list