Public Member Functions | |
Solver (SolverControl &solver_control, VectorMemory< VECTOR > &vector_memory) | |
Solver (SolverControl &solver_control) | |
SolverControl & | control () const |
Protected Attributes | |
GrowingVectorMemory< VECTOR > | static_vector_memory |
SolverControl & | cntrl |
VectorMemory< VECTOR > & | memory |
Since iterative solvers do not rely on any special structure of matrices or the format of storage, but only require that matrices and vector define certain operations such as matrix-vector products, or scalar products between vectors, this class as well as the derived classes implementing concrete linear solvers are templated on the types of matrices and vectors. However, there are some common requirements a matrix or vector type must fulfill to qualify as an applicable type for the solvers in this hierarchy. These requirements are listed following. The listed classes are not any concrete class, they are rather intended to form a `signature' which a concrete class has to conform to. Note that the matrix and vector classes within this library of course conform to this interface; therefore, SparseMatrix and Vector are good examples for these classes.
class Matrix { public: // Application of matrix to vector src. // write result into dst void vmult (VECTOR &dst, const VECTOR &src) const; // Application of transpose to a Vector. // Only used by certain iterative methods. void Tvmult (VECTOR &dst, const VECTOR &src) const; }; class VECTOR { public: // resize to have the same structure // as the one provided and/or // clear vector. note // that the second argument must have // a default value equal to false void reinit (const VECTOR&, bool leave_elements_uninitialized = false); // scalar product double operator * (const VECTOR &v) const; // addition of vectors void add (const VECTOR &x); // scaled addition of vectors void add (const double a, const VECTOR &x); // scaled addition of vectors void sadd (const double a, const double b, const VECTOR &x); // scaled assignment of a vector void equ (const double a, const VECTOR &x); // scale the elements of the vector // by a fixed value VECTOR & operator *= (const double a); // return the l2 norm of the vector double l2_norm () const; };
In addition, for some solvers there has to be a global function swap(VECTOR &a, VECTOR &b)
that exchanges the values of the two vectors.
The preconditioners used must have the same interface as matrices, i.e. in particular they have to provide a member function vmult
which denotes the application of the preconditioner.
Several solvers need additional data, like the damping parameter omega
of the SolverRichardson
class or the maximum number of temporary vectors of the SolverGMRES
. To have a standardized constructor for each solver class the struct AdditionalData
has been introduced to each solver class. Some solvers need no additional data, like SolverCG
or SolverBicgstab
. For these solvers the struct AdditionalData
is empty and calling the constructor may be done without giving the additional structure as an argument as a default AdditionalData
is set by default.
Now the generating of a solver looks like
// GMRES with 50 tmp vectors SolverGMRES solver_gmres (solver_control, vector_memory, SolverGMRES::AdditionalData(50)); // Richardson with omega=0.8 SolverRichardson solver_richardson (solver_control, vector_memory, SolverGMRES::AdditionalData(0.8)); // CG with default AdditionalData SolverCG solver_cg (solver_control, vector_memory);
Using a unified constructor parameter list for all solvers was introduced when the SolverSelector
class was written; the unified interface enabled us to use this class unchanged even if the number of types of parameters to a certain solver changes and it is still possible in a simple way to give these additional data to the SolverSelector
object for each solver which it may use.
Solver< VECTOR >::Solver | ( | SolverControl & | solver_control, | |
VectorMemory< VECTOR > & | vector_memory | |||
) |
Constructor. Takes a control object which evaluates the conditions for convergence, and an object to provide memory.
Of both objects, a reference is stored, so it is the user's responsibility to guarantee that the lifetime of the two arguments is at least as long as that of the solver object.
Solver< VECTOR >::Solver | ( | SolverControl & | solver_control | ) |
Constructor. Takes a control object which evaluates the conditions for convergence. In contrast to the other constructor, this constructor denotes an internal object of type GrowingVectorMemory to allocate memory.
A reference to the control object is stored, so it is the user's responsibility to guarantee that the lifetime of the two arguments is at least as long as that of the solver object.
SolverControl& Solver< VECTOR >::control | ( | ) | const |
Access to object that controls convergence.
GrowingVectorMemory<VECTOR> Solver< VECTOR >::static_vector_memory [mutable, protected] |
A static vector memory object to be used whenever no such object has been given to the constructor.
SolverControl& Solver< VECTOR >::cntrl [protected] |
Control structure.
Referenced by Solver< VECTOR >::control().
VectorMemory<VECTOR>& Solver< VECTOR >::memory [protected] |
Memory for auxilliary vectors.