I am currently implementing a code that minimizes an energy functional depending on a traceless symmetric tensor (5D solution) for liquid crystal physics. The physics details matters not, I will just mention that I am using a combination of trust-region Newton iterations with a Truncated Conjugate Gradient (TCG) solver and matrix-free approach with multigrid preconditioning. This works exceedingly well for simple problems with Dirichlet boundary conditions, and I must say I am very impressed by the quality and efficiency of the dealii library and the excellent documentation, so a big thanks to all the developers!
However, I have a problem when I want to use periodic boundary conditions together with matrix-free multigrid preconditioning (it works fine with matrix-free but no preconditioner). Specifically, the problem arises when I try to use the method MGTransferMatrixFree::interpolate_to_mg, that allows me to transfer the solution of my problem at each level of the triangulation (where it is further used in the calculation of the system matrix at this level, which in my case corresponds to the hessian of the free energy functional, but I think that it is irrelevant for the problem I have).
Basically, this
method tries to access an element of a distributed vector that is not
stored on the current MPI process, so I get an exception raised by
LinearAlgebra::distributed::Vector. If I use Dirichlet BCs instead of
periodic ones, the problem goes away. So it seems to be a problem
with the way that the vectors of my problem are partitioned when I
include periodic BCs. To illustrate this problem, I am attaching a
MWE that shows how I setup matrix-free and multigrid objects with
periodic BCs, and raises the same error as in my main code. I am using deal.II v9.3 on an archlinux distribution.
I have looked at all the tutorials related to matrix-free and multigrid objects (this is how I wrote the base program in the first place), but was not able to find a solution on my own. I have tried various way of specifying the AffineConstraints objects for the level matrix-free objects, but none worked out. I also tried dummy AffineConstraints like in step 59 which uses periodic faces, but this does not work, so I guess this is is specific to FE_DGQ (whereas I am using FE_Q spaces). I must do something wrong because it works so well without periodic BCs, so if anyone has an idea this would be great :) I am happy to provide any additional details that you would deem important.
Best regards,
Guilhem