dune-pdelab  2.7-git
Assembling a linear system from a PDE

This recipe shows how to assemble a linear system of equations discretizing a PDE.

In particular, we start from a LocalOperator representing the PDE's bilinear form. Rather than defining one by ourselves, we use one already provided in PDELab. Further, we assume that a GridFunctionSpace and Constraints have already been set up.

LOP lop(problem);

This per-element LocalOperator can now be plugged into a GridOperator, which is capable of assembling a matrix for the entire domain.

auto go = GO(gfs,cc,gfs,cc,lop,MBE(nonzeros));

Next, we set up our degree of freedom vector.

and ensure it matches the Dirichlet boundary conditions at constrained degrees of freedom. In addition to specifying Dirichlet constrained degrees of freedom, it also serves as initial guess at unconstrained ones.

Now, from the GridOperator, we can assemble our residual vector depending on our initial guess

X d(gfs,0.0);
go.residual(x,d);

and print it to console.

Dune::printvector(std::cout, native(d), "Residual vector", "");

Likewise, we can assemble our matrix which again depends on the initial guess

typedef GO::Jacobian M;
M A(go);
go.jacobian(x,A);

and print it as well.

Dune::printmatrix(std::cout, native(A), "Stiffness matrix", "");

Full example code: recipe-linear-system-assembly.cc

Dune::PDELab::GridOperator
Standard grid operator implementation.
Definition: gridoperator.hh:35
Dune::PDELab::Backend::Vector
typename impl::BackendVectorSelector< GridFunctionSpace, FieldType >::Type Vector
alias of the return type of BackendVectorSelector
Definition: backend/interface.hh:106
Dune::PDELab::ConvectionDiffusionDirichletExtensionAdapter
Definition: convectiondiffusionparameter.hh:320
Dune::PDELab::Backend::native
std::enable_if< std::is_base_of< impl::WrapperBase, T >::value, Native< T > & >::type native(T &t)
Definition: backend/interface.hh:192
Dune::PDELab::ConvectionDiffusionFEM
Definition: convectiondiffusionfem.hh:39
Dune::PDELab::interpolate
void interpolate(const F &f, const GFS &gfs, XG &xg)
interpolation from a given grid function
Definition: interpolate.hh:177