> On 3 Apr 2019, at 3:40 PM, Matthew Knepley <knep...@gmail.com> wrote: > > On Wed, Apr 3, 2019 at 9:31 AM Pierre Jolivet <pierre.joli...@enseeiht.fr > <mailto:pierre.joli...@enseeiht.fr>> wrote: >> On 3 Apr 2019, at 3:15 PM, Stefano Zampini <stefano.zamp...@gmail.com >> <mailto:stefano.zamp...@gmail.com>> wrote: >> >> Pierre, >> >> using MatHeaderReplace should be discouraged in a SNES/TS callback ;-) > > Gotcha! > >> I coded this way to have the possibility of changing the MatType while >> running SNES or TS, not for variable sizes. >> >> A tricky way of achieving what you want is to code a proper hook function >> (see >> https://www.mcs.anl.gov/petsc/petsc-current/docs/manualpages/SNES/SNESSetUpdate.html >> >> <https://www.mcs.anl.gov/petsc/petsc-current/docs/manualpages/SNES/SNESSetUpdate.html>), >> which gets called right before each linear solve. >> 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 >> >> The proper solution would be to extend DMAdaptor to the case of user-defined >> refinements and stopping criterion callbacks. Matt? > > 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. > > For now, this is the best. > > Can you tell me a little about what you are adapting, and why adapting after > only a linearized solve would be preferable > to adapting after the nonlinear solve?
I am just adapting the mesh depending on the solution from the previous SNESSolve. At first, I wanted to avoid writing an outer loop around the SNESSolve, so I thought, let’s put the adaptation in the SNESSetJacobian. It would have been preferable because it would have required fewer lines of code (as I had imagined this to work), that’s the main reason. I understand this is too much to ask of PETSc to continue working without any further information from the application. Thanks, Pierre > Thanks, > > Matt > > Thanks, > Pierre > >> Il giorno mer 3 apr 2019 alle ore 14:52 Matthew Knepley via petsc-dev >> <petsc-dev@mcs.anl.gov <mailto:petsc-dev@mcs.anl.gov>> ha scritto: >> On Wed, Apr 3, 2019 at 5:43 AM Pierre Jolivet via petsc-dev >> <petsc-dev@mcs.anl.gov <mailto:petsc-dev@mcs.anl.gov>> wrote: >> I’d like to do mesh adaptation in a Newton loop. >> I’m using a SNES with SNESSetFunction and SNESSetJacobian. >> My first question is: may the dimension of the linear systems change >> throughout the nonlinear iterations? >> >> No. Everything we do is algebraic right now. You would have to reformulate >> Newton in >> some Banach space, and make sure all the measures you were using were >> discretization >> independent. Then you could allow the underlying linear algebra to change, >> but you would >> need operations for projecting the the new space, making BC in the new >> space, etc. There >> is a lot of machinery in the continuous space that PETSc does not have. >> >> It sounds like it should be setup as an FAS. >> >> Thanks, >> >> Matt >> >> If so, what are the proper things to do? I tried to do as Stefano in MFEM >> and use MatHeaderReplace >> https://github.com/mfem/mfem/blob/master/linalg/petsc.cpp#L3833 >> <https://github.com/mfem/mfem/blob/master/linalg/petsc.cpp#L3833> 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? >> >> Thanks, >> Pierre >> >> >> -- >> What most experimenters take for granted before they begin their experiments >> is infinitely more interesting than any results to which their experiments >> lead. >> -- Norbert Wiener >> >> https://www.cse.buffalo.edu/~knepley/ <http://www.cse.buffalo.edu/~knepley/> >> >> >> -- >> Stefano > > > > -- > What most experimenters take for granted before they begin their experiments > is infinitely more interesting than any results to which their experiments > lead. > -- Norbert Wiener > > https://www.cse.buffalo.edu/~knepley/ <http://www.cse.buffalo.edu/~knepley/>