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));
Standard grid operator implementation.
Definition: gridoperator.hh:36
Next, we set up our degree of freedom vector
typedef Dune::PDELab::Backend::Vector<GFS,NumberType> X;
X x(gfs,0.0);
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.
G g(grid.leafGridView(),problem);
Definition: convectiondiffusionparameter.hh:325
void interpolate(const F &f, const GFS &gfs, XG &xg)
interpolation from a given grid function
Definition: interpolate.hh:177
Now we choose the preconditioner and solver we want to use
LS ls(100,3);
Sequential conjugate gradient solver preconditioned with AMG smoothed by SSOR.
Definition: seqistlsolverbackend.hh:856
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();
Solve linear problems using a residual formulation.
Definition: linearproblem.hh:61
Finally, let's print the result to console via
void printvector(std::ostream &s, const V &v, std::string title, std::string rowtext, int columns=1, int width=10, int precision=2)
Print an ISTL vector.
Definition: io.hh:89
There is a number of alternative solvers and preconditioners available we could use instead, for example this one:
Backend for sequential conjugate gradient solver with ILU0 preconditioner.
Definition: seqistlsolverbackend.hh:453
Full example code: recipe-linear-system-solution-pdelab.cc