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
X x(gfs,0.0);
typename impl::BackendVectorSelector< GridFunctionSpace, FieldType >::Type Vector
alias of the return type of BackendVectorSelector
Definition: backend/interface.hh:106
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);
void interpolate(const F &f, const GFS &gfs, XG &xg)
interpolation from a given grid function
Definition: interpolate.hh:177
Definition: convectiondiffusionparameter.hh:325
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.apply();
const Entity & e
Definition: localfunctionspace.hh:123
Solve linear problems using a residual formulation.
Definition: linearproblem.hh:61
Finally, let's print the result to console via
Dune::printvector(std::cout,
native(x),
"Solution",
"");
std::enable_if< std::is_base_of< impl::WrapperBase, T >::value, Native< T > & >::type native(T &t)
Definition: backend/interface.hh:192
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