<html><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><br><div><br><div>Begin forwarded message:</div><br class="Apple-interchange-newline"><blockquote type="cite"><div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; "><font face="Helvetica" size="3" color="#000000" style="font: 12.0px Helvetica; color: #000000"><b>From: </b></font><font face="Helvetica" size="3" style="font: 12.0px Helvetica">Jed Brown <<a href="mailto:jed@59A2.org">jed@59A2.org</a>></font></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; "><font face="Helvetica" size="3" color="#000000" style="font: 12.0px Helvetica; color: #000000"><b>Date: </b></font><font face="Helvetica" size="3" style="font: 12.0px Helvetica">July 21, 2010 8:04:17 PM EDT</font></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; "><font face="Helvetica" size="3" color="#000000" style="font: 12.0px Helvetica; color: #000000"><b>To: </b></font><font face="Helvetica" size="3" style="font: 12.0px Helvetica">Xuan YU <<a href="mailto:xxy113@psu.edu">xxy113@psu.edu</a>>, PETSc users list <<a href="mailto:petsc-users@mcs.anl.gov">petsc-users@mcs.anl.gov</a>></font></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; "><font face="Helvetica" size="3" color="#000000" style="font: 12.0px Helvetica; color: #000000"><b>Subject: </b></font><font face="Helvetica" size="3" style="font: 12.0px Helvetica"><b>Re: [petsc-users] TSDefaultComputeJacobian</b></font></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; min-height: 14px; "><br></div> </div><div>On Wed, 21 Jul 2010 19:52:23 -0400, Xuan YU <<a href="mailto:xxy113@psu.edu">xxy113@psu.edu</a>> wrote:<br><blockquote type="cite">Hi,<br></blockquote><blockquote type="cite"><br></blockquote><blockquote type="cite">In SNES, Petsc can compute Jacobian by:<br></blockquote><blockquote type="cite"><br></blockquote><blockquote type="cite">ierr = <br></blockquote><blockquote type="cite">SNESSetJacobian <br></blockquote><blockquote type="cite">(snes,J,J,SNESDefaultComputeJacobian,PETSC_NULL);CHKERRQ(ierr);<br></blockquote><blockquote type="cite"><br></blockquote><blockquote type="cite">How about TS? I don't want to provide Jacobian function by myself, but <br></blockquote><blockquote type="cite">I didn't find something like TSDefaultComputeJacobian.<br></blockquote><br>You can use -snes_fd (or -snes_mf or -snes_mf_operator) with TS.<br>Programmatically,<br><br> TSGetSNES(ts,&snes);<br></div></blockquote><blockquote type="cite"><div> SNESSetJacobian(snes,A,B,SNESDefaultComputeJacobian,ts);<br><br></div></blockquote><div><br></div><div>I have already tried this function.</div><div><br></div><div>I want to use <span class="Apple-style-span" style="font-size: 15px; ">Finite Difference Jacobian Approximations</span></div><div><br></div><div>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.</div><div><br></div><div>Here is the code</div><div><br></div><div><br></div><div><br></div><div><div> ierr = MatCreateSeqAIJ(PETSC_COMM_SELF,N,N,10,PETSC_NULL,&J);CHKERRQ(ierr);</div><div> ierr = TSCreate(PETSC_COMM_WORLD,&ts);CHKERRQ(ierr);</div><div> ierr = TSSetProblemType(ts,TS_NONLINEAR);CHKERRQ(ierr);</div><div> ierr = TSMonitorSet(ts,Monitor,&appctx,PETSC_NULL);CHKERRQ(ierr);</div><div> ierr = TSSetSolution(ts,CV_Y);CHKERRQ(ierr);</div><div> ierr = TSSetRHSFunction(ts,f,&appctx);CHKERRQ(ierr);</div><div> ierr = TSSetType(ts,TSBEULER);CHKERRQ(ierr);</div><div> ierr = TSGetSNES(ts,&ts_snes);</div><div> ierr= SNESSetJacobian(ts_snes,J,J,SNESDefaultComputeJacobian,PETSC_NULL);CHKERRQ(ierr);</div><div> MatStructure flag;</div><div> ierr = SNESComputeJacobian(ts_snes,CV_Y,&J,&J,&flag);CHKERRQ(ierr);</div><div> ierr = MatGetColoring(J,MATCOLORINGSL,&iscoloring);CHKERRQ(ierr);</div><div> ierr = MatFDColoringCreate(J,iscoloring,&matfdcoloring);CHKERRQ(ierr);</div><div> ISColoringDestroy(iscoloring);</div><div><br></div><div> ierr = MatFDColoringSetFunction(matfdcoloring,(PetscErrorCode (*)(void))f,(void*)&appctx);CHKERRQ(ierr);</div><div> ierr = MatFDColoringSetFromOptions(matfdcoloring);CHKERRQ(ierr);</div><div> ierr = TSSetRHSJacobian(ts,J,J,TSDefaultComputeJacobianColor,matfdcoloring);</div><div><br></div></div>But I got the error:</div><div><div>[0]PETSC ERROR: --------------------- Error Message ------------------------------------</div><div>[0]PETSC ERROR: Object is in wrong state!</div><div>[0]PETSC ERROR: Must call SNESSetFunction() before SNESComputeFunction(), likely called from SNESSolve().!</div><div>[0]PETSC ERROR: ------------------------------------------------------------------------</div><div>[0]PETSC ERROR: Petsc Development HG revision: fdc7be12de37b8a400b6e561de9850bcc7e79f4f HG Date: Fri Jul 02 21:17:36 2010 -0500</div><div>[0]PETSC ERROR: See docs/changes/index.html for recent updates.</div><div>[0]PETSC ERROR: See docs/faq.html for hints about trouble shooting.</div><div>[0]PETSC ERROR: See docs/index.html for manual pages.</div><div>[0]PETSC ERROR: ------------------------------------------------------------------------</div><div>[0]PETSC ERROR: ./pihm on a arch-linu named kernighan.aset.psu.edu by xxy113 Wed Jul 21 21:35:01 2010</div><div>[0]PETSC ERROR: Libraries linked from /gpfs/home/xxy113/soft/petsc-dev/arch-linux-gnu-c-debug/lib</div><div>[0]PETSC ERROR: Configure run at Sun Jul 4 14:09:16 2010</div><div>[0]PETSC ERROR: Configure options --download-f-blas-lapack=1 --download-mpich=1</div><div>[0]PETSC ERROR: ------------------------------------------------------------------------</div><div>[0]PETSC ERROR: SNESComputeFunction() line 1180 in src/snes/interface/snes.c</div><div>[0]PETSC ERROR: SNESDefaultComputeJacobian() line 77 in src/snes/interface/snesj.c</div><div>[0]PETSC ERROR: SNESComputeJacobian() line 1264 in src/snes/interface/snes.c</div><div>[0]PETSC ERROR: VecRestoreArrayPrivate3() line 234 in /work/petsc/pihm.c</div><div><br></div><div><br></div><div><br></div><blockquote type="cite"><div>Jed<br><br></div></blockquote></div><br></body></html>