[petsc-users] TSDefaultComputeJacobian

XUAN YU xxy113 at psu.edu
Wed Jul 21 21:25:54 CDT 2010



---------------- Forwarded Message ----------------
From: Matthew Knepley <knepley at gmail.com>
Date: Wed, Jul 21, 2010 09:50 PM
Subject: Re: [petsc-users] TSDefaultComputeJacobian
To: PETSc users list <petsc-users at mcs.anl.gov>



Yes, you have setup the Jacobian function, but you never setup the residual
function, which
is what the error is complaining about.

-----------------------------------------


Could you please give me some suggestions about how to setup residual function?
Is there some example?







   Matt

On Thu, Jul 22, 2010 at 11:43 AM, Xuan YU <<#>> wrote:
>>

>>

>>Begin forwarded message:

>
>
>
From: Jed Brown <<#>>

>
Date: July 21, 2010 8:04:17 PM EDT

>
To: Xuan YU <<#>>, PETSc users list <<#>>

>
Subject: Re: [petsc-users] TSDefaultComputeJacobian

>
> 
>On Wed, 21 Jul 2010 19:52:23 -0400, Xuan YU <<#>> wrote:
>Hi,
>


>
In SNES, Petsc can compute Jacobian by:
>


>

ierr =  
>

SNESSetJacobian 
>

(snes,J,J,SNESDefaultComputeJacobian,PETSC_NULL);CHKERRQ(ierr);
>


>
How about TS? I don't want to provide Jacobian function by myself, but  
>

I didn't find something like TSDefaultComputeJacobian.
>


>You can use -snes_fd (or -snes_mf or -snes_mf_operator) with TS.
>
Programmatically,
>
>  TSGetSNES(ts,&snes);
>


> SNESSetJacobian(snes,A,B,SNESDefaultComputeJacobian,ts);
>
>

>
>
>I have already tried this function.
>
>
>I want to use Finite Difference Jacobian Approximations

>
>
>So, before I call the function:
MatGetColoring(J,MATCOLORINGSL,&iscoloring);CHKERRQ(ierr); I should assemble J.
I tried to use SNESComputeJacobian(snes,x,&J,&J,&flag) to assemble J.
>
>
>Here is the code
>
>
>
>
>
>
>
>        ierr =
MatCreateSeqAIJ(PETSC_COMM_SELF,N,N,10,PETSC_NULL,&J);CHKERRQ(ierr);
>        ierr = TSCreate(PETSC_COMM_WORLD,&ts);CHKERRQ(ierr);
>        ierr = TSSetProblemType(ts,TS_NONLINEAR);CHKERRQ(ierr);
>        ierr = TSMonitorSet(ts,Monitor,&appctx,PETSC_NULL);CHKERRQ(ierr);
>        ierr = TSSetSolution(ts,CV_Y);CHKERRQ(ierr);
>        ierr = TSSetRHSFunction(ts,f,&appctx);CHKERRQ(ierr);
>        ierr = TSSetType(ts,TSBEULER);CHKERRQ(ierr);
>        ierr = TSGetSNES(ts,&ts_snes);
>        ierr=
SNESSetJacobian(ts_snes,J,J,SNESDefaultComputeJacobian,PETSC_NULL);CHKERRQ(ierr);
>        MatStructure  flag;
>        ierr = SNESComputeJacobian(ts_snes,CV_Y,&J,&J,&flag);CHKERRQ(ierr);
>        ierr = MatGetColoring(J,MATCOLORINGSL,&iscoloring);CHKERRQ(ierr);
>        ierr = MatFDColoringCreate(J,iscoloring,&matfdcoloring);CHKERRQ(ierr);
>        ISColoringDestroy(iscoloring);
>
>
>        ierr = MatFDColoringSetFunction(matfdcoloring,(PetscErrorCode (*)(void))f,(void*)&appctx);CHKERRQ(ierr);
>        ierr = MatFDColoringSetFromOptions(matfdcoloring);CHKERRQ(ierr);
>        ierr = TSSetRHSJacobian(ts,J,J,TSDefaultComputeJacobianColor,matfdcoloring);
>
>
But I got the error:
>
>[0]PETSC ERROR: --------------------- Error Message ------------------------------------
>[0]PETSC ERROR: Object is in wrong state!
>[0]PETSC ERROR: Must call SNESSetFunction() before SNESComputeFunction(), likely called from SNESSolve().!
>[0]PETSC ERROR: ------------------------------------------------------------------------
>[0]PETSC ERROR: Petsc Development HG revision: fdc7be12de37b8a400b6e561de9850bcc7e79f4f  HG Date: Fri Jul 02 21:17:36 2010 -0500
>[0]PETSC ERROR: See docs/changes/index.html for recent updates.
>[0]PETSC ERROR: See docs/faq.html for hints about trouble shooting.
>[0]PETSC ERROR: See docs/index.html for manual pages.
>
[0]PETSC ERROR: ------------------------------------------------------------------------
>[0]PETSC ERROR: ./pihm on a arch-linu named <http://kernighan.aset.psu.edu> by xxy113 Wed Jul 21 21:35:01 2010
>[0]PETSC ERROR: Libraries linked from /gpfs/home/xxy113/soft/petsc-dev/arch-linux-gnu-c-debug/lib
>[0]PETSC ERROR: Configure run at Sun Jul  4 14:09:16 2010
>[0]PETSC ERROR: Configure options --download-f-blas-lapack=1 --download-mpich=1
>[0]PETSC ERROR: ------------------------------------------------------------------------
>[0]PETSC ERROR: SNESComputeFunction() line 1180 in src/snes/interface/snes.c
>[0]PETSC ERROR: SNESDefaultComputeJacobian() line 77 in src/snes/interface/snesj.c
>[0]PETSC ERROR: SNESComputeJacobian() line 1264 in src/snes/interface/snes.c
>[0]PETSC ERROR: VecRestoreArrayPrivate3() line 234 in /work/petsc/pihm.c
>
>
>
>
>
>

>Jed
>
>




>







-- 
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




-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mcs.anl.gov/pipermail/petsc-users/attachments/20100721/bcdba0ac/attachment.htm>


More information about the petsc-users mailing list