<html><head></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><br><div><div>On Aug 31, 2010, at 3:16 PM, Jeremy Roberts wrote:</div><br class="Apple-interchange-newline"><blockquote type="cite">Ah, I understand now what you mean. I have u in a module used by all subroutines that need u, including the main program where it is an argument of SNESSolve and the subroutine jac_shell. I assumed having all routines use the same variable makes it the same everywhere at all times...maybe I'm just lucky with this particular problem. Putting it as you do, I see why the user might not want to assume what goes into solve is consistent with (points to?) what enters FOO at any given call.<br></blockquote><div><br></div> It does not neccessarily match, you should not depend on it.</div><div><br></div><div> Barry</div><div><br><blockquote type="cite">
<br>Thanks,<br>Jeremy<br><br>P.S. I've attached the working example, where "x" is the unknown vector. <br><br><div class="gmail_quote">On Tue, Aug 31, 2010 at 2:27 PM, Barry Smith <span dir="ltr"><<a href="mailto:bsmith@mcs.anl.gov">bsmith@mcs.anl.gov</a>></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><div class="im"><div>On Aug 31, 2010, at 2:17 PM, Jeremy Roberts wrote:</div>
<br><blockquote type="cite">To implement the safe method---i.e. copying the unknown vector u within FOO---what is proper generic form of FOO? <br><br>I guess I'm not clear exactly how FOO and jac_shell (the J*x routine) are linked. It appears they aren't, given I can use an empty subroutine, but how then is a local copy of u within FOO used in for J(u) in J(U)*x of jac_shell?<br>
</blockquote><div><br></div></div> Don't ask me. You wrote the code, I have no idea how you are accessing u. But you need to compute J(u)*x so you need to use u.</div><div><br></div><div> subroutine yourfoo(snes,u,A,B,flg,ierr)</div>
<div> common /mycommonblock/ v </div><div><br></div><div> call veccopy(u,v,ierr)</div><div> return</div><div><br></div><div> and create the v upfront in your main program. Of course, you don't need to use common blocks but that is one way of maintaining this global variables.</div>
<div><br></div><font color="#888888"><div> Barry</div></font><div class="im"><div><br></div><div> </div><div><br><blockquote type="cite">
<br><br><div class="gmail_quote">On Tue, Aug 31, 2010 at 1:14 PM, Barry Smith <span dir="ltr"><<a href="mailto:bsmith@mcs.anl.gov" target="_blank">bsmith@mcs.anl.gov</a>></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><div></div><div><br>
On Aug 31, 2010, at 1:03 PM, Jeremy Roberts wrote:<br>
<br>
><br>
> Hi Barry,<br>
><br>
> Thanks for the quick response.<br>
><br>
> I have the unknown vector u globally accessible and so forgo use of the user-defined context (I tried to get it to work---can it be used in Fortran?).<br>
><br>
> I used<br>
><br>
> call SNESSetJacobian( snes, Jshell, Jshell, FOO, PETSC_NULL_OBJECT, ierr )<br>
><br>
> where FOO is an empty function having the correct argument types. It seems to work now, and I get the exact same answer using an explicit Jacobian matrix and the shell version. Is there a way to get around needing FOO at all?<br>
><br>
<br>
</div></div> If it works great. But I how you know what the "unknown vector u " that is "globally accessible" in SNES is? How do you know it is the same each time a new Jacobian is needed? The only save way is to copy the vector passed into the FOO funcion.<br>
<br>
Barry<br>
<br>
<br>
<br>
> Jeremy<br>
><br>
><br>
<br>
</blockquote></div><br>
</blockquote></div><br></div></div></blockquote></div><br>
<span><exJac.F></span><span><exJac_mod.F></span><span><exJac_mod2.F></span></blockquote></div><br></body></html>