~ubuntu-branches/ubuntu/saucy/deal.ii/saucy

« back to all changes in this revision

Viewing changes to lac/include/lac/solver.h

  • Committer: Package Import Robot
  • Author(s): "Adam C. Powell, IV", Adam C. Powell, IV, Christophe Trophime
  • Date: 2012-02-21 06:57:30 UTC
  • mfrom: (3.1.7 sid)
  • Revision ID: package-import@ubuntu.com-20120221065730-r2iz70lg557wcd2e
Tags: 7.1.0-1
[ Adam C. Powell, IV ]
* New upstream (closes: #652057).
* Updated to use PETSc and SLEPc 3.2, and forward-ported all patches.
* Removed NetCDF Build-Depends because it uses serial HDF5.
* Made Sacado cmath patch work with new configure.
* Moved -dev package symlink lines in rules to arch all section.

[ Christophe Trophime ]
* debian/rules:
   - add dh_strip --dbg-package to generate dbg package (closes: #652058)
   - add .install files to simplify rules
* Add support for mumps, arpack (closes: #637655)
* Add patch for slepc 3.2 (closes: #659245)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
//---------------------------------------------------------------------------
2
 
//    $Id: solver.h 15606 2007-12-17 20:16:08Z kanschat $
3
 
//
4
 
//    Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007 by the deal.II authors
5
 
//
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.
10
 
//
11
 
//---------------------------------------------------------------------------
12
 
#ifndef __deal2__solver_h
13
 
#define __deal2__solver_h
14
 
 
15
 
#include <base/config.h>
16
 
#include <base/subscriptor.h>
17
 
#include <lac/vector_memory.h>
18
 
 
19
 
DEAL_II_NAMESPACE_OPEN
20
 
 
21
 
template <typename number> class Vector;
22
 
class SolverControl;
23
 
 
24
 
/**
25
 
 * This class defines possible return states of linear solvers and
26
 
 * provides interfaces to a memory pool and the control object.
27
 
 *
28
 
 * <h3>Requirements for template classes</h3>
29
 
 *
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.
44
 
 *
45
 
 * @code
46
 
 * class Matrix
47
 
 * {
48
 
 *   public:
49
 
 *                        // Application of matrix to vector src.
50
 
 *                        // write result into dst
51
 
 *     void vmult (VECTOR &dst, const VECTOR &src) const;
52
 
 * 
53
 
 *                        // Application of transpose to a Vector.
54
 
 *                        // Only used by certain iterative methods.
55
 
 *     void Tvmult (VECTOR &dst, const VECTOR &src) const;
56
 
 * };
57
 
 *
58
 
 *
59
 
 * class VECTOR
60
 
 * {
61
 
 *   public:
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);
69
 
 *
70
 
 *                        // scalar product
71
 
 *     double operator * (const VECTOR &v) const;
72
 
 *
73
 
 *                        // addition of vectors
74
 
 *     void add (const VECTOR &x);
75
 
 *
76
 
 *                        // scaled addition of vectors
77
 
 *     void add (const double  a,
78
 
 *               const VECTOR &x);
79
 
 *
80
 
 *                        // scaled addition of vectors
81
 
 *     void sadd (const double  a,
82
 
 *                const double  b,
83
 
 *                const VECTOR &x);
84
 
 * 
85
 
 *                        // scaled assignment of a vector
86
 
 *     void equ (const double  a,
87
 
 *               const VECTOR &x);
88
 
 *
89
 
 *                        // scale the elements of the vector
90
 
 *                        // by a fixed value
91
 
 *     VECTOR & operator *= (const double a);
92
 
 *
93
 
 *                        // return the l2 norm of the vector
94
 
 *     double l2_norm () const;
95
 
 * };
96
 
 * @endcode
97
 
 *
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.
100
 
 *
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.
104
 
 *
105
 
 *
106
 
 * <h3>AdditionalData</h3>
107
 
 *
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.
116
 
 *
117
 
 * Now the generating of a solver looks like
118
 
 * @code
119
 
 *                               // GMRES with 50 tmp vectors
120
 
 * SolverGMRES solver_gmres (solver_control, vector_memory,
121
 
 *                           SolverGMRES::AdditionalData(50));
122
 
 *
123
 
 *                               // Richardson with omega=0.8
124
 
 * SolverRichardson solver_richardson (solver_control, vector_memory,
125
 
 *                                     SolverGMRES::AdditionalData(0.8));
126
 
 *
127
 
 *                               // CG with default AdditionalData
128
 
 * SolverCG solver_cg (solver_control, vector_memory);
129
 
 * @endcode
130
 
 *
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.
137
 
 *
138
 
 * @ingroup Solvers
139
 
 * @author Wolfgang Bangerth, Guido Kanschat, Ralf Hartmann, 1997-2001, 2005
140
 
 */
141
 
template <class VECTOR = Vector<double> >
142
 
class Solver : public Subscriptor
143
 
{
144
 
  public:
145
 
                                     /**
146
 
                                      * Constructor. Takes a control
147
 
                                      * object which evaluates the
148
 
                                      * conditions for convergence,
149
 
                                      * and an object to provide
150
 
                                      * memory.
151
 
                                      *
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
157
 
                                      * object.
158
 
                                      */
159
 
    Solver (SolverControl        &solver_control,
160
 
            VectorMemory<VECTOR> &vector_memory);
161
 
 
162
 
                                     /**
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
170
 
                                      * allocate memory.
171
 
                                      *
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
178
 
                                      * object.
179
 
                                      */
180
 
    Solver (SolverControl        &solver_control);
181
 
    
182
 
                                     /**
183
 
                                      * Access to object that controls
184
 
                                      * convergence.
185
 
                                      */
186
 
    SolverControl & control() const;
187
 
  
188
 
  protected:
189
 
                                     /**
190
 
                                      * A static vector memory object
191
 
                                      * to be used whenever no such
192
 
                                      * object has been given to the
193
 
                                      * constructor.
194
 
                                      */
195
 
    mutable GrowingVectorMemory<VECTOR> static_vector_memory;
196
 
    
197
 
                                     /**
198
 
                                      * Control structure.
199
 
                                      */
200
 
    SolverControl &cntrl;
201
 
    
202
 
                                     /**
203
 
                                      * Memory for auxilliary vectors.
204
 
                                      */
205
 
    VectorMemory<VECTOR> &memory;
206
 
};
207
 
 
208
 
/*-------------------------------- Inline functions ------------------------*/
209
 
 
210
 
template<class VECTOR>
211
 
inline
212
 
Solver<VECTOR>::Solver (SolverControl        &solver_control,
213
 
                        VectorMemory<VECTOR> &vector_memory)
214
 
                :
215
 
                cntrl(solver_control),
216
 
                memory(vector_memory)
217
 
{}
218
 
 
219
 
 
220
 
 
221
 
template<class VECTOR>
222
 
inline
223
 
Solver<VECTOR>::Solver (SolverControl        &solver_control)
224
 
                :
225
 
                cntrl(solver_control),
226
 
                memory(static_vector_memory)
227
 
{}
228
 
 
229
 
 
230
 
 
231
 
template <class VECTOR>
232
 
inline
233
 
SolverControl &
234
 
Solver<VECTOR>::control() const
235
 
{
236
 
  return cntrl;
237
 
}
238
 
 
239
 
 
240
 
 
241
 
 
242
 
DEAL_II_NAMESPACE_CLOSE
243
 
 
244
 
#endif