The assembler converts the PDE problem into a linear algebraic system by evaluating all the integrals of test/ansatz functions multiplied with the derivatives of \( f \) and \( g \) and scattering the results into a large sparse matrix.
The class VariationalFunctionalAssembler implements this, and is parametrized with the variational functional class defining the PDE and the involved FE spaces.
using Assembler = VariationalFunctionalAssembler<LinearizationAt<Functional>>;
Assembler assembler(spaces);
The constructor takes the tuple of finite element spaces. The functional itself is supplied later, when assembling a particular linearization point u.
For assembly, we may choose between any combination of functional value (d0), right hand side (d1), and stiffness matrix (d2) to be assembled — the value of course only if the problem is a variational functional and not a weak formulation.
assembler.assemble(linearization(F,u),
Assembler::MATRIX|Assembler::RHS|Assembler::VALUE);
The flags are also available through the Kaskade::Assembler namespace (Kaskade::Assembler::MATRIX, etc.). Omitting the flags assembles everything (Assembler::EVERYTHING). The flags are passed on to the DomainCache and BoundaryCache objects, so a cache can skip the evaluation of quantities that are not requested. The optional remaining arguments of assemble are the number of threads and a verbosity flag.
After assembly, the right hand side and stiffness matrix can be extracted as a sparse matrix, or the assembler can be passed directly to a more abstract wrapper class such as AssembledGalerkinOperator.
// Extract the assembled matrix as a sparse NumaBCRSMatrix.
auto M = assembler.get<NumaBCRSMatrix<Dune::FieldMatrix<double,1,1>>>();
// Wrap the assembler in an operator and build a direct solver from it.
AssembledGalerkinOperator<Assembler> A(assembler);
auto Ainv = directInverseOperator(A);
Extraction is not limited to NumaBCRSMatrix: Kaskade 7 provides the necessary AssemblyDetail::Fill specializations for MatrixAsTriplet<Scalar>, Dune::BCRSMatrix<Dune::FieldMatrix<Scalar,1,1>>, and NumaBCRSMatrix<Dune::FieldMatrix<Scalar,1,1>>. For other matrix types, specialize AssemblyDetail::Fill accordingly.
AssembledGalerkinOperator also accepts two optional constructor arguments: a flag that requests only the lower triangular part (useful for symmetric problems), and the number of threads. Its update() method refreshes the operator after the assembler has been called again, for example after grid refinement.
To access single subblocks at a certain position of the stiffness matrix, use
auto const& M00 = assembler.get<0,0>();
The template arguments are block indices (row/column of the variable), not scalar matrix indices. The call returns a reference to the corresponding block matrix, e.g. a NumaBCRSMatrix. For symmetric problems only the lower triangular blocks are stored; requesting a missing block is a compile-time error.
For access to subblocks in a certain half-open range [rbegin,rend), [cbegin,cend), use
auto M = assembler.get<MatrixType>(onlyLowerTriangle, rbegin, rend, cbegin, cend);
where onlyLowerTriangle=true extracts only the lower triangular part and can be used if the matrix is symmetric.
For parabolic equations, the mass matrix has to be assembled in addition to the stiffness matrix. This is done by the b2 cache and processed with help of the ParabolicEquation interface (see fem/variationalfunctional.hh). Assembly then follows the same procedures as for the elliptic equations, and the combined mass and stiffness matrix can be accessed in the same ways.