<div dir="ltr"><div dir="ltr"><div dir="ltr">Jed,</div><div dir="ltr"><br clear="all"><div>It appears that the testsuite does not currently cover a nasty code we have to cache RHS Jacobian computation when using the implicit interface. If I run the testsuite with the below modification, no tests fail. (my continuous adjoint codes instead show some reusage)<br></div><div><br></div><div>This caching mechanism is causing headaches to me and Hong when supporting adjoints.</div><div>It would be nice if we can come up with a proper test (try to cover as much user cases as possible) and provide a definitive fix for this (even erroring if we don't support something, instead of silently doing the wrong thing) </div><div><br></div><div>I'm pretty sure that when Jacobian computations are performed by TS itself, using the proper matrices A,B obtained from TSGetIJacobian(ts,&A,B,...) the caching is correct ( I have spent hours on this)</div><div><br></div><div>When different matrices are used, TSComputeIJacobian() without an IJacobian callback  is buggy: note that  TSComputeIJacobian() is a public method.</div><div><br></div><div><br></div><div><div>diff --git a/src/ts/interface/ts.c b/src/ts/interface/ts.c</div><div>index 4b003c8f6e..02211b62ea 100644</div><div>--- a/src/ts/interface/ts.c</div><div>+++ b/src/ts/interface/ts.c</div><div>@@ -575,6 +575,7 @@ PetscErrorCode  TSComputeRHSJacobian(TS ts,PetscReal t,Vec U,Mat A,Mat B)</div><div>   if (ts->rhsjacobian.time == t && (ts->problem_type == TS_LINEAR || (ts->rhsjacobian.Xid == Uid && ts->rhsjacobian.Xstate == Ustate)) && (rhsfunction != TSComputeRHSFunctionLinear)) {</div><div>     /* restore back RHS Jacobian matrices if they have been shifted/scaled */</div><div>     if (A == ts->Arhs) {</div><div>+      PetscPrintf(PetscObjectComm((PetscObject)ts),"REUSE %g %g\n",ts->rhsjacobian.shift,ts->rhsjacobian.scale);</div><div>       if (ts->rhsjacobian.shift != 0) {</div><div>         ierr = MatShift(A,-ts->rhsjacobian.shift);CHKERRQ(ierr);</div><div>       }</div></div><div><br></div>-- <br><div dir="ltr" class="gmail_signature">Stefano</div></div></div></div>