How to properly handle mesh refinement in dynamic adaptive loops

I’m implementing an adaptive mesh loop where I need to:

  1. Solve PDEs on current mesh
  2. Compute error indicators based on solutions
  3. Mark cells according to error indicators
  4. Refine marked cells to generate new mesh
  5. change current mesh to new mesh
  6. Repeat 1-5 until no cell is marked

My current approach recreates all function spaces, functions, boundary conditions and so on, after each mesh refinement. However, in parallel execution (MPI), the program occasionally hangs, especially when the number of cores >6. I think this should be very resource intensive, which may be the reason for the program stopping.

Is it truly necessary to redefine everything for each refined mesh? Or is there a more elegant or efficient way to handle this process across refinements?

I’d really appreciate any insight or suggestions. Thanks in advance!

See for instance

which shows how one can avoid having to redefine the forms.
However, on a refined mesh, you need to:

  1. create a new function space (this creates the dofmap)
  2. Create the associated Functions that goes into the variational form, or stores the solution.
  3. the solver, can be re-used, but the matrix and vectors sent to PETSc has to be re-assembled (as the dofmap has changed )
1 Like