<a href="http://www.mcs.anl.gov/petsc/petsc-as/snapshots/petsc-current/docs/manualpages/TS/TSSetRHSFunction.html">http://www.mcs.anl.gov/petsc/petsc-as/snapshots/petsc-current/docs/manualpages/TS/TSSetRHSFunction.html</a><div>
<br></div><div>  Matt<br><br><div class="gmail_quote">On Thu, Jul 22, 2010 at 12:25 PM, 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><div class="im"><br><br>---------------- Forwarded Message ----------------<br>From:
Matthew Knepley &lt;<a href="mailto:knepley@gmail.com" target="_blank">knepley@gmail.com</a>&gt;<br>Date: Wed, Jul 21, 2010 09:50
PM<br>Subject: Re: [petsc-users] TSDefaultComputeJacobian<br></div><div class="im">To: PETSc users
list &lt;<a href="mailto:petsc-users@mcs.anl.gov" target="_blank">petsc-users@mcs.anl.gov</a>&gt;<br><br></div><span><span><div class="im"><p>Yes, you have setup
the Jacobian function, but you never setup the residual function, which</p>
</div><div><div class="im">is what the error is complaining
about.<br><br></div>-----------------------------------------<br><br><br>Could you
please give me some suggestions about how to setup residual function? Is there
some example?<br><br><br><br><br></div><div><div></div><div class="h5">
<div><br></div>
<div>   Matt<br><br><div class="gmail_quote">On Thu, Jul 22, 2010 at
11:43 AM, Xuan YU <span dir="">&lt;<a href="#129f7f8b5b43d140_">xxy113@psu.edu</a>&gt;</span>
wrote:<br><blockquote class="gmail_quote" style="margin:0pt 0pt 0pt 0.8ex;border-left:1px solid rgb(204, 204, 204);padding-left:1ex"><div style="word-wrap:break-word">
<br><div>
<br><div>Begin forwarded message:</div>
<br><blockquote type="">
<div>
<div style="margin:0px">
<font style="font:12px Helvetica;color:rgb(0, 0, 0)" size="3" color="#000000" face="Helvetica"><b>From: </b></font><font style="font:12px Helvetica" size="3" face="Helvetica">Jed Brown &lt;<a href="#129f7f8b5b43d140_">jed@59A2.org</a>&gt;</font>
</div>
<div style="margin:0px">
<font style="font:12px Helvetica;color:rgb(0, 0, 0)" size="3" color="#000000" face="Helvetica"><b>Date: </b></font><font style="font:12px Helvetica" size="3" face="Helvetica">July 21, 2010 8:04:17 PM EDT</font>
</div>
<div style="margin:0px">
<font style="font:12px Helvetica;color:rgb(0, 0, 0)" size="3" color="#000000" face="Helvetica"><b>To: </b></font><font style="font:12px Helvetica" size="3" face="Helvetica">Xuan YU &lt;<a href="#129f7f8b5b43d140_">xxy113@psu.edu</a>&gt;, PETSc users list &lt;<a href="#129f7f8b5b43d140_">petsc-users@mcs.anl.gov</a>&gt;</font>
</div>
<div style="margin:0px">
<font style="font:12px Helvetica;color:rgb(0, 0, 0)" size="3" color="#000000" face="Helvetica"><b>Subject: </b></font><font style="font:12px Helvetica" size="3" face="Helvetica"><b>Re: [petsc-users]
TSDefaultComputeJacobian</b></font>
</div>
<div style="margin:0px;min-height:14px"><br></div> </div>
<div>On Wed, 21 Jul 2010 19:52:23 -0400, Xuan YU &lt;<a href="#129f7f8b5b43d140_">xxy113@psu.edu</a>&gt; wrote:<br><blockquote type="">Hi,<br>
</blockquote>
<blockquote type=""><br></blockquote>
<blockquote type="">In SNES, Petsc can compute Jacobian by:<br>
</blockquote>
<blockquote type=""><br></blockquote>
<blockquote type="">
ierr =  <br>
</blockquote>
<blockquote type="">SNESSetJacobian <br>
</blockquote>
<blockquote type="">(snes,J,J,SNESDefaultComputeJacobian,PETSC_NULL);CHKERRQ(ierr);<br>
</blockquote>
<blockquote type=""><br></blockquote>
<blockquote type="">How about TS? I don&#39;t want to provide Jacobian function by
myself, but  <br>
</blockquote>
<blockquote type="">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=""><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="">
<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></div></div></span></span><br><br><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>