1
//---------------------------------------------------------------------------
2
// $Id: solver.h 15606 2007-12-17 20:16:08Z kanschat $
4
// Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007 by the deal.II authors
6
// This file is subject to QPL and may not be distributed
7
// without copyright and license information. Please refer
8
// to the file deal.II/doc/license.html for the text and
9
// further information on this license.
11
//---------------------------------------------------------------------------
12
#ifndef __deal2__solver_h
13
#define __deal2__solver_h
15
#include <base/config.h>
16
#include <base/subscriptor.h>
17
#include <lac/vector_memory.h>
19
DEAL_II_NAMESPACE_OPEN
21
template <typename number> class Vector;
25
* This class defines possible return states of linear solvers and
26
* provides interfaces to a memory pool and the control object.
28
* <h3>Requirements for template classes</h3>
30
* Since iterative solvers do not rely on any special structure of
31
* matrices or the format of storage, but only require that matrices
32
* and vector define certain operations such as matrix-vector
33
* products, or scalar products between vectors, this class as well as
34
* the derived classes implementing concrete linear solvers are
35
* templated on the types of matrices and vectors. However, there are
36
* some common requirements a matrix or vector type must fulfill to
37
* qualify as an applicable type for the solvers in this
38
* hierarchy. These requirements are listed following. The listed
39
* classes are not any concrete class, they are rather intended to
40
* form a `signature' which a concrete class has to conform to. Note
41
* that the matrix and vector classes within this library of course
42
* conform to this interface; therefore, SparseMatrix and Vector are
43
* good examples for these classes.
49
* // Application of matrix to vector src.
50
* // write result into dst
51
* void vmult (VECTOR &dst, const VECTOR &src) const;
53
* // Application of transpose to a Vector.
54
* // Only used by certain iterative methods.
55
* void Tvmult (VECTOR &dst, const VECTOR &src) const;
62
* // resize to have the same structure
63
* // as the one provided and/or
64
* // clear vector. note
65
* // that the second argument must have
66
* // a default value equal to false
67
* void reinit (const VECTOR&,
68
* bool leave_elements_uninitialized = false);
71
* double operator * (const VECTOR &v) const;
73
* // addition of vectors
74
* void add (const VECTOR &x);
76
* // scaled addition of vectors
77
* void add (const double a,
80
* // scaled addition of vectors
81
* void sadd (const double a,
85
* // scaled assignment of a vector
86
* void equ (const double a,
89
* // scale the elements of the vector
91
* VECTOR & operator *= (const double a);
93
* // return the l2 norm of the vector
94
* double l2_norm () const;
98
* In addition, for some solvers there has to be a global function
99
* <tt>swap(VECTOR &a, VECTOR &b)</tt> that exchanges the values of the two vectors.
101
* The preconditioners used must have the same interface as matrices,
102
* i.e. in particular they have to provide a member function @p vmult
103
* which denotes the application of the preconditioner.
106
* <h3>AdditionalData</h3>
108
* Several solvers need additional data, like the damping parameter @p omega
109
* of the @p SolverRichardson class or the maximum number of temporary
110
* vectors of the @p SolverGMRES. To have a standardized constructor for
111
* each solver class the <tt>struct AdditionalData</tt> has been introduced to each
112
* solver class. Some solvers need no additional data, like @p SolverCG or
113
* @p SolverBicgstab. For these solvers the struct @p AdditionalData is
114
* empty and calling the constructor may be done without giving the additional
115
* structure as an argument as a default @p AdditionalData is set by default.
117
* Now the generating of a solver looks like
119
* // GMRES with 50 tmp vectors
120
* SolverGMRES solver_gmres (solver_control, vector_memory,
121
* SolverGMRES::AdditionalData(50));
123
* // Richardson with omega=0.8
124
* SolverRichardson solver_richardson (solver_control, vector_memory,
125
* SolverGMRES::AdditionalData(0.8));
127
* // CG with default AdditionalData
128
* SolverCG solver_cg (solver_control, vector_memory);
131
* Using a unified constructor parameter list for all solvers was introduced
132
* when the @p SolverSelector class was written; the unified interface
133
* enabled us to use this class unchanged even if the number of types of
134
* parameters to a certain solver changes and it is still possible in a simple
135
* way to give these additional data to the @p SolverSelector object for each
136
* solver which it may use.
139
* @author Wolfgang Bangerth, Guido Kanschat, Ralf Hartmann, 1997-2001, 2005
141
template <class VECTOR = Vector<double> >
142
class Solver : public Subscriptor
146
* Constructor. Takes a control
147
* object which evaluates the
148
* conditions for convergence,
149
* and an object to provide
152
* Of both objects, a reference is
153
* stored, so it is the user's
154
* responsibility to guarantee that the
155
* lifetime of the two arguments is at
156
* least as long as that of the solver
159
Solver (SolverControl &solver_control,
160
VectorMemory<VECTOR> &vector_memory);
163
* Constructor. Takes a control
164
* object which evaluates the
165
* conditions for convergence. In
166
* contrast to the other
167
* constructor, this constructor
168
* denotes an internal object of
169
* type GrowingVectorMemory to
172
* A reference to the control
173
* object is stored, so it is the
174
* user's responsibility to
175
* guarantee that the lifetime of
176
* the two arguments is at least
177
* as long as that of the solver
180
Solver (SolverControl &solver_control);
183
* Access to object that controls
186
SolverControl & control() const;
190
* A static vector memory object
191
* to be used whenever no such
192
* object has been given to the
195
mutable GrowingVectorMemory<VECTOR> static_vector_memory;
200
SolverControl &cntrl;
203
* Memory for auxilliary vectors.
205
VectorMemory<VECTOR> &memory;
208
/*-------------------------------- Inline functions ------------------------*/
210
template<class VECTOR>
212
Solver<VECTOR>::Solver (SolverControl &solver_control,
213
VectorMemory<VECTOR> &vector_memory)
215
cntrl(solver_control),
216
memory(vector_memory)
221
template<class VECTOR>
223
Solver<VECTOR>::Solver (SolverControl &solver_control)
225
cntrl(solver_control),
226
memory(static_vector_memory)
231
template <class VECTOR>
234
Solver<VECTOR>::control() const
242
DEAL_II_NAMESPACE_CLOSE