<div dir="ltr"><div dir="ltr">On Wed, Apr 3, 2019 at 9:31 AM Pierre Jolivet <<a href="mailto:pierre.jolivet@enseeiht.fr">pierre.jolivet@enseeiht.fr</a>> wrote:<br></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="word-wrap:break-word"><div><blockquote type="cite"><div>On 3 Apr 2019, at 3:15 PM, Stefano Zampini <<a href="mailto:stefano.zampini@gmail.com" target="_blank">stefano.zampini@gmail.com</a>> wrote:</div><br class="gmail-m_681576763191896732Apple-interchange-newline"><div><div dir="ltr"><div dir="ltr">Pierre,<div><br></div><div>using MatHeaderReplace should be discouraged in a SNES/TS callback ;-)</div></div></div></div></blockquote><div><br></div>Gotcha!</div><div><br><blockquote type="cite"><div><div dir="ltr"><div dir="ltr"><div>I coded this way to have the possibility of changing the MatType while running SNES or TS, not for variable sizes.</div><div><br></div><div>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" target="_blank">https://www.mcs.anl.gov/petsc/petsc-current/docs/manualpages/SNES/SNESSetUpdate.html</a>), which gets called right before each linear solve.</div><div>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><br></div><div>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></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></div></blockquote><div><br></div><div>For now, this is the best.</div><div><br></div><div>Can you tell me a little about what you are adapting, and why adapting after only a linearized solve would be preferable</div><div>to adapting after the nonlinear solve?</div><div><br></div><div> Thanks,</div><div><br></div><div> Matt</div><div> </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="word-wrap:break-word"><div><div>Thanks,</div><div>Pierre</div><br><blockquote type="cite"><div><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" target="_blank">petsc-dev@mcs.anl.gov</a>> ha scritto:<br></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"><div dir="ltr">On Wed, Apr 3, 2019 at 5:43 AM Pierre Jolivet via petsc-dev <<a href="mailto:petsc-dev@mcs.anl.gov" target="_blank">petsc-dev@mcs.anl.gov</a>> wrote:<br></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><div dir="auto">I’d like to do mesh adaptation in a Newton loop.<div>I’m using a SNES with SNESSetFunction and SNESSetJacobian.</div><div>My first question is: may the dimension of the linear systems change throughout the nonlinear iterations?</div><div></div></div></div></blockquote><div><br></div><div>No. Everything we do is algebraic right now. You would have to reformulate Newton in</div><div>some Banach space, and make sure all the measures you were using were discretization</div><div>independent. Then you could allow the underlying linear algebra to change, but you would</div><div>need operations for projecting the the new space, making BC in the new space, etc. There</div><div>is a lot of machinery in the continuous space that PETSc does not have.</div><div><br></div><div>It sounds like it should be setup as an FAS.</div><div><br></div><div> Thanks,</div><div><br></div><div> Matt</div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div><div dir="auto"><div>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">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><br></div><div>Thanks,</div><div>Pierre</div></div></div></blockquote></div><br clear="all"><div><br></div>-- <br><div dir="ltr" class="gmail-m_681576763191896732gmail-m_-3564516740463737086gmail_signature"><div dir="ltr"><div><div dir="ltr"><div><div dir="ltr"><div>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</div><div><br></div><div><a href="http://www.cse.buffalo.edu/~knepley/" target="_blank">https://www.cse.buffalo.edu/~knepley/</a><br></div></div></div></div></div></div></div></div>
</blockquote></div><br clear="all"><div><br></div>-- <br><div dir="ltr" class="gmail-m_681576763191896732gmail_signature">Stefano</div>
</div></blockquote></div><br></div></blockquote></div><br clear="all"><div><br></div>-- <br><div dir="ltr" class="gmail_signature"><div dir="ltr"><div><div dir="ltr"><div><div dir="ltr"><div>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</div><div><br></div><div><a href="http://www.cse.buffalo.edu/~knepley/" target="_blank">https://www.cse.buffalo.edu/~knepley/</a><br></div></div></div></div></div></div></div></div>