dune-pdelab  2.7-git
Solving a linear system within PDELab

Here we show how to solve a linear system of equations originating from a PDE using PDELab.

First, we set up a GridOperator as in Assembling a linear system from a PDE

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 we choose the preconditioner and solver we want to use

and plug it into a StationaryLinearProblemSolver. This takes care of assembling as well as solving the system.

SLP slp(go,ls,x,1e-10);
slp.apply(); // here all the work is done!

Finally, let's print the result to console via

Dune::printvector(std::cout, native(x), "Solution", "");

There is a number of alternative solvers and preconditioners available we could use instead, for example this one:

Full example code: recipe-linear-system-solution-pdelab.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::ISTLBackend_SEQ_CG_ILU0
Backend for sequential conjugate gradient solver with ILU0 preconditioner.
Definition: seqistlsolverbackend.hh:451
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
e
const Entity & e
Definition: localfunctionspace.hh:121
Dune::PDELab::StationaryLinearProblemSolver
Definition: linearproblem.hh:44
Dune::PDELab::ISTLBackend_SEQ_CG_AMG_SSOR
Sequential conjugate gradient solver preconditioned with AMG smoothed by SSOR.
Definition: seqistlsolverbackend.hh:854
Dune::PDELab::interpolate
void interpolate(const F &f, const GFS &gfs, XG &xg)
interpolation from a given grid function
Definition: interpolate.hh:177