From: schrage Date: Fri, 11 Jun 1999 15:36:45 +0000 (+0000) Subject: Added some more solvers and SolverSelector X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=5f42e46997be67862da47fcbbe8ff1b7a5d7de99;p=dealii-svn.git Added some more solvers and SolverSelector git-svn-id: https://svn.dealii.org/trunk@1400 0785d39b-7218-0410-832d-ea1e28bc413d --- diff --git a/deal.II/doc/tutorial/chapter-1.elements/solve.html b/deal.II/doc/tutorial/chapter-1.elements/solve.html index 73619fc876..c8de3fa8a0 100644 --- a/deal.II/doc/tutorial/chapter-1.elements/solve.html +++ b/deal.II/doc/tutorial/chapter-1.elements/solve.html @@ -41,18 +41,47 @@

-Besides, there is a class named -SolverControl in order to +Besides, there are several utility classes: +

+

+ +

A note on deal.II solvers

+ +

+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.

Solver Control

@@ -79,6 +108,48 @@ SolverControl control(1000,1e-6); +

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);
+
+
+ +

Preconditioning

@@ -238,6 +309,124 @@ solver.solve(A,u,f,preconditioning); +

SolverGMRES

+ +

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);
+
+
+ + +

SolverRichardson

+ +

+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);
+
+