<html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;" class=""><br class=""><div><blockquote type="cite" class=""><div class="">On 3 Apr 2019, at 3:15 PM, Stefano Zampini <<a href="mailto:stefano.zampini@gmail.com" class="">stefano.zampini@gmail.com</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><div dir="ltr" class=""><div dir="ltr" class="">Pierre,<div class=""><br class=""></div><div class="">using MatHeaderReplace should be discouraged in a SNES/TS callback ;-)</div></div></div></div></blockquote><div><br class=""></div>Gotcha!</div><div><br class=""><blockquote type="cite" class=""><div class=""><div dir="ltr" class=""><div dir="ltr" class=""><div class="">I coded this way to have the possibility of changing the MatType while running SNES or TS, not for variable sizes.</div><div class=""><br class=""></div><div class="">A tricky way of achieving what you want is to code a proper hook function (see <a href="https://www.mcs.anl.gov/petsc/petsc-current/docs/manualpages/SNES/SNESSetUpdate.html" class="">https://www.mcs.anl.gov/petsc/petsc-current/docs/manualpages/SNES/SNESSetUpdate.html</a>), which gets called right before each linear solve.</div><div class="">This is very tricky (and implementation dependent) because you also need to update/interpolate all the relevant vectors SNES may use later for line search</div><div class=""><br class=""></div><div class="">The proper solution would be to extend DMAdaptor to the case of user-defined refinements and stopping criterion callbacks. Matt? </div></div></div></div></blockquote><div><br class=""></div><div>Following Matt’s message, I’ve permuted the two “loops" (SNESSolve and mesh adaptation), but if there is some way to do the adaptation in the inner loop coming along, I’ll give it a go.</div><div><br class=""></div><div>Thanks,</div><div>Pierre</div><br class=""><blockquote type="cite" class=""><div class=""><div class="gmail_quote"><div dir="ltr" class="gmail_attr">Il giorno mer 3 apr 2019 alle ore 14:52 Matthew Knepley via petsc-dev <<a href="mailto:petsc-dev@mcs.anl.gov" class="">petsc-dev@mcs.anl.gov</a>> ha scritto:<br class=""></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr" class=""><div dir="ltr" class="">On Wed, Apr 3, 2019 at 5:43 AM Pierre Jolivet via petsc-dev <<a href="mailto:petsc-dev@mcs.anl.gov" target="_blank" class="">petsc-dev@mcs.anl.gov</a>> wrote:<br class=""></div><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div style="overflow-wrap: break-word;" class=""><div dir="auto" style="overflow-wrap: break-word;" class="">I’d like to do mesh adaptation in a Newton loop.<div class="">I’m using a SNES with SNESSetFunction and SNESSetJacobian.</div><div class="">My first question is: may the dimension of the linear systems change throughout the nonlinear iterations?</div><div class=""></div></div></div></blockquote><div class=""><br class=""></div><div class="">No. Everything we do is algebraic right now. You would have to reformulate Newton in</div><div class="">some Banach space, and make sure all the measures you were using were discretization</div><div class="">independent. Then you could allow the underlying linear algebra to change, but you would</div><div class="">need operations for projecting the the new space, making BC in the new space, etc. There</div><div class="">is a lot of machinery in the continuous space that PETSc does not have.</div><div class=""><br class=""></div><div class="">It sounds like it should be setup as an FAS.</div><div class=""><br class=""></div><div class="">  Thanks,</div><div class=""><br class=""></div><div class="">     Matt</div><div class=""> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div style="overflow-wrap: break-word;" class=""><div dir="auto" style="overflow-wrap: break-word;" class=""><div class="">If so, what are the proper things to do? I tried to do as Stefano in MFEM and use MatHeaderReplace <a href="https://github.com/mfem/mfem/blob/master/linalg/petsc.cpp#L3833" target="_blank" class="">https://github.com/mfem/mfem/blob/master/linalg/petsc.cpp#L3833</a> inside the function supplied to SNESSetJacobian, but I end up with a [0]PETSC ERROR: PCApply() line 455 in petsc/src/ksp/pc/interface/precon.c Preconditioner number of local rows 6561 does not equal resulting vector number of rows 1681 further down the road. Should I also call something like VecHeaderReplace (which apparently does not exist) on the residual Vec?</div><div class=""><br class=""></div><div class="">Thanks,</div><div class="">Pierre</div></div></div></blockquote></div><br clear="all" class=""><div class=""><br class=""></div>-- <br class=""><div dir="ltr" class="gmail-m_-3564516740463737086gmail_signature"><div dir="ltr" class=""><div class=""><div dir="ltr" class=""><div class=""><div dir="ltr" class=""><div class="">What most experimenters take for granted before they begin their experiments is infinitely more interesting than any results to which their experiments lead.<br class="">-- Norbert Wiener</div><div class=""><br class=""></div><div class=""><a href="http://www.cse.buffalo.edu/~knepley/" target="_blank" class="">https://www.cse.buffalo.edu/~knepley/</a><br class=""></div></div></div></div></div></div></div></div>
</blockquote></div><br clear="all" class=""><div class=""><br class=""></div>-- <br class=""><div dir="ltr" class="gmail_signature">Stefano</div>
</div></blockquote></div><br class=""></body></html>