Yes, you have setup the Jacobian function, but you never setup the residual function, which<div>is what the error is complaining about.</div><div><br></div><div>   Matt<br><br><div class="gmail_quote">On Thu, Jul 22, 2010 at 11:43 AM, Xuan YU <span dir="ltr">&lt;<a href="mailto:xxy113@psu.edu">xxy113@psu.edu</a>&gt;</span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;"><div style="word-wrap:break-word"><br><div><br><div>Begin forwarded message:</div><br><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 &lt;<a href="mailto:jed@59A2.org" target="_blank">jed@59A2.org</a>&gt;</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 &lt;<a href="mailto:xxy113@psu.edu" target="_blank">xxy113@psu.edu</a>&gt;, PETSc users list &lt;<a href="mailto:petsc-users@mcs.anl.gov" target="_blank">petsc-users@mcs.anl.gov</a>&gt;</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 &lt;<a href="mailto:xxy113@psu.edu" target="_blank">xxy113@psu.edu</a>&gt; 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&#39;t want to provide Jacobian function by myself, but  <br></blockquote><blockquote type="cite">I didn&#39;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,&amp;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 style="font-size:15px">Finite Difference Jacobian Approximations</span></div><div><br></div><div>So, before I call the function: MatGetColoring(J,MATCOLORINGSL,&amp;iscoloring);CHKERRQ(ierr); I should assemble J. I tried to use SNESComputeJacobian(snes,x,&amp;J,&amp;J,&amp;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,&amp;J);CHKERRQ(ierr);</div><div>        ierr = TSCreate(PETSC_COMM_WORLD,&amp;ts);CHKERRQ(ierr);</div>
<div>        ierr = TSSetProblemType(ts,TS_NONLINEAR);CHKERRQ(ierr);</div><div>        ierr = TSMonitorSet(ts,Monitor,&amp;appctx,PETSC_NULL);CHKERRQ(ierr);</div><div>        ierr = TSSetSolution(ts,CV_Y);CHKERRQ(ierr);</div>
<div>        ierr = TSSetRHSFunction(ts,f,&amp;appctx);CHKERRQ(ierr);</div><div>        ierr = TSSetType(ts,TSBEULER);CHKERRQ(ierr);</div><div>        ierr = TSGetSNES(ts,&amp;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,&amp;J,&amp;J,&amp;flag);CHKERRQ(ierr);</div><div>        ierr = MatGetColoring(J,MATCOLORINGSL,&amp;iscoloring);CHKERRQ(ierr);</div>
<div>        ierr = MatFDColoringCreate(J,iscoloring,&amp;matfdcoloring);CHKERRQ(ierr);</div><div>        ISColoringDestroy(iscoloring);</div><div><br></div><div>        ierr = MatFDColoringSetFunction(matfdcoloring,(PetscErrorCode (*)(void))f,(void*)&amp;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 <a href="http://kernighan.aset.psu.edu" target="_blank">kernighan.aset.psu.edu</a> 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></div></blockquote></div><br><br clear="all"><br>-- <br>What most experimenters take for granted before they begin their experiments is infinitely more interesting than any results to which their experiments lead.<br>
-- Norbert Wiener<br>
</div>