Multigrid methods are used in Kaskade 7 primarily as preconditioners for Krylov solvers such as CG, not as stand-alone solvers. The implementation lives in the mg/ directory and is built around the GridManager, which provides the hierarchy of nested grids obtained by refinement.
For elliptic problems, the convenience function makeMultigrid in mg/multigrid.hh chooses a reasonable default configuration from the assembled matrix and the finite element space:
#include "mg/multigrid.hh"
auto mg = makeMultigrid(Amat, h1Space);
It assumes globally continuous scalar finite element functions on simplicial grids. Based on the polynomial order reported by the space’s mapper, it selects
The number of pre- and post-smoothing steps is chosen according to the number of components (three for scalar problems, two for vector-valued problems such as elastomechanics). The return type is a std::unique_ptr to a SymmetricPreconditioner, because the concrete preconditioner type depends on runtime information. The optional arguments are a flag requesting only the lower triangular part of the matrix and the DirectType used for the coarse solves (default DirectType::MUMPS).
The preconditioner is passed to the Krylov solver by reference; it must outlive the solver:
constexpr int dim = 2;
using X = Dune::BlockVector<Dune::FieldVector<double,dim>>;
using Matrix = NumaBCRSMatrix<Dune::FieldMatrix<double,dim,dim>>;
Matrix Amat(assembler.get<0,0>(),true);
Dune::MatrixAdapter<Matrix,X,X> A(Amat);
DefaultDualPairing<X,X> dp;
SymmetricLinearOperatorWrapper<X,X> sa(A,dp);
PCGEnergyErrorTerminationCriterion<double> term(atol,maxit);
auto mg = makeMultigrid(Amat, h1Space);
CG<X,X> pcg(sa, *mg, term, verbose);
Dune::InverseOperatorResult result;
pcg.apply(x, rhs, result);
The complete working example is the elastomechanics tutorial (tutorial/elastomechanics/elastomechanics.cpp), which also demonstrates additive variants such as BPX and PBPX via makeBPX and makePBPX.
The headers in mg/ provide the underlying building blocks:
additiveMultigrid.hh: additive multigrid methods and BPX-type preconditioners,multiplicativeMultigrid.hh: multiplicative (V-cycle-type) multigrid,multiGridSolver.hh, multiGridStacks.hh: solver and stack infrastructure.For non-symmetric or indefinite problems, the multigrid components can also be used with suitable Krylov methods such as GMRES or BiCGSTAB; the choice of smoother and coarse solver then has to be adapted to the problem.