From: schrage
-Besides, there is a class named
-SolverControl
in order to
+Besides, there are several utility classes:
+
+
+SolverControl
to
control the iterative solvers, i.e. to determine whether the iteration
-should be continued and a class named
+should be continued
+SolverSelector
, the use of which
+offers several advantages over solver selection by hand
+PreconditionSelector
that allows
-you to select a preconditioner.
+you to select a preconditioner
+
+All of the deal.II solvers have a structure
+AdditionalData
that is used to pass additional
+arguments to the solver. We discuss this structure only for those
+solvers that need it.
-We will begin with the discussion of the SolverControl
+Information on common solution methods can be found in any modern
+textbook on finite elements, for example in Braess, Dietrich, Finite
+Elements. The GMRES solver discussed below is rather
+special, and if you are going to use it you probably know what
+you ar edoing anyway.
+
+
+We will now begin with the discussion of the SolverControl
, the
+SolverSelector
and the PreconditionSelector
classes, then discuss the solvers
-in more detail.
+in more detail. Although we do not demonstrate this method in the
+examples for the different solvers every last solver can be called
+using SolverSelector
.
+The SolverSelector
class is a wrapper for all the
+deal.II solver classes. By calling it with the
+right constructor you select your solver, and by calling its solve
+method you call the solve
method of the solver you selected.
+The advantage of this approach is that your solver is an argument
+to this class and - more important - an argument you can set in a
+parameter file. That means that if you want to change your solver, e.g.
+because a new one has been added you do not have to rewrite your program.
+
+The SolverSelector
is initialized using
+
+SolverSelector(const string solvername, SolverControl &control,
+VectorMemory<Vector> &mem)
+
+
+Example:We initialize a solver selector +that will call the cg-solver. The problem matrix is a sparse matrix of +doubles and the right hand side a vector of doubles. +
+ +
+
+#include <lac/solver_control.h>
+#include <lac/solver_selector.h>
+#include <lac/sparsematrix.h>
+#include <lac/vector.h>
+
+SolverControl control;
+VectorMemory<Vector<double> > mem;
+
+SolverSelector<SparseMatrix<double>, Vector<double> >
+ solver_selector("cg", control, mem);
+
+
+
+
@@ -238,6 +309,124 @@ solver.solve(A,u,f,preconditioning); +
This class implements the Restarted Preconditioned Direct Generalized
+Minimal Residual Method. The stopping criterion is the norm of the residual.
+It is initialized using
+SolverGMRES(SolverControl &cn, VectorMemory<Vector> &mem,
+const AdditionalData &data=Additionaldata())
+
+This constructor needs the maximum number of temporary vectors to be used.
+A number too small can seriously affect its performance. This number is
+contained in the AdditionalData
structure with a default of 30.
+This solver is rather special, and for a detailed explanation you should
+take a look at the detailed description of the SolverGMRES
+class.
+
+Example:We initialize a GMRES-solver for
+the problem Au=f
, using the solver control
+explained above. A
shall be a sparse matrix and the vectors
+u
and f
shall be vectors of doubles.
+Next, we solve the problem. We use the default number of thirty temporary
+vectors.
+
+
+// Include files for solver control, solver and preconditioner
+#include <lac/solver_control.h>
+#include <lac/solver_gmres.h>
+#include <lac/precondition_selector.h>
+
+// Include files for matrices and vectors
+#include <lac/sparsematrix.h>
+#include <lac/vector.h>
+
+// Initialize the solver control and the solver
+
+SolverControl control(1000,1e-6);
+VectorMemory<Vector<double> > vectormem;
+SolverCG<SparseMatrix,Vector<double> > solver(control,vectormem);
+
+// Initialize the problem matrices. Well...they shouldn't only be
+// initialized but also contain the problem, so this is just an example
+// to get the definitions and types and everything right.
+// To make it clear: This code as it is will not do anything because
+// it does not contain any mathematical problem !
+
+SparseMatrix<double> A;
+Vector<double> u,f;
+
+// Generate a Jacobi preconditioner with the damping parameter 1
+PreconditionSelector<SparseMatrix<double>, Vector<double> > preconditioning("jacobi",1.);
+
+// Use the matrix of the linear equation system for preconditioning
+// (this is the usual case).
+preconditioning.use_matrix(A);
+
+solver.solve(A,u,f,preconditioning);
+
+
+
+
+
+This class implements the Richardson iteration method. The stopping criterion
+is the norm of the residual. It is initialized using
+SolverRichardson(SolverControl &cn, VectorMemory<Vector>
+&mem, const AdditionalData &data=Additionaldata())
+
+The additional data for this solver is the damping, with a default of 1.
+
+Example:We initialize a Richardson-solver for
+the problem Au=f
, using the solver control
+explained above. A
shall be a sparse matrix and the vectors
+u
and f
shall be vectors of doubles. Next,
+we solve the problem. We use the default damping parameter of 1.
+
+
+// Include files for solver control, solver and preconditioner
+#include <lac/solver_control.h>
+#include <lac/solver_richardson.h>
+#include <lac/precondition_selector.h>
+
+// Include files for matrices and vectors
+#include <lac/sparsematrix.h>
+#include <lac/vector.h>
+
+// Initialize the solver control and the solver
+
+SolverControl control(1000,1e-6);
+VectorMemory<Vector<double> > vectormem;
+SolverCG<SparseMatrix,Vector<double> > solver(control,vectormem);
+
+// Initialize the problem matrices. Well...they shouldn't only be
+// initialized but also contain the problem, so this is just an example
+// to get the definitions and types and everything right.
+// To make it clear: This code as it is will not do anything because
+// it does not contain any mathematical problem !
+
+SparseMatrix<double> A;
+Vector<double> u,f;
+
+// Generate a Jacobi preconditioner with the damping parameter 1
+PreconditionSelector<SparseMatrix<double>, Vector<double> > preconditioning("jacobi",1.);
+
+// Use the matrix of the linear equation system for preconditioning
+// (this is the usual case).
+preconditioning.use_matrix(A);
+
+solver.solve(A,u,f,preconditioning);
+
+