<div class="gmail_quote">On Mon, Jun 6, 2011 at 23:23, Boyce Griffith <span dir="ltr"><<a href="mailto:griffith@cims.nyu.edu">griffith@cims.nyu.edu</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
Destructors don't get called within calls to KSPSolve()/SNESSolve() (unless called via PETSc internals).</blockquote></div><br><div>It must be a different model, but something vaguely along the following lines could work.</div>
<div><br></div><div>class UserVector : public SAMRAIVector { // SAMRAIVector is whatever was returned by getVector()</div><div><br></div><div>UserVector::UserVector(Vec X) {</div><div> VecSamraiCtx ctx = X->data;</div>
<div> this->vec = X;</div><div> this->SAMRAIVector(ctx.getVector()); // if there is internal reference counting</div><div>}</div><div><br></div><div>UserVector::~UserVector() {</div><div> // any cleanup</div><div>
if (this->modified) PetscObjectStateIncrease((PetscObject)this->vec);</div><div>}</div><div>};</div><div><br></div><div><br></div><div>Then you would have something like</div><div><br></div><div>PetscErrorCode FormResidual(SNES snes,Vec X,Vec Y,void *ctx) {</div>
<div> UserVector ux(X),uy(Y);</div><div><br></div><div> // compute the function and put the result in uy</div><div>}</div>