GMResSolver.h 4.69 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
// ============================================================================
// == AMDiS - Adaptive multidimensional simulations                          ==
// ==                                                                        ==
// ============================================================================
// ==                                                                        ==
// ==  crystal growth group                                                  ==
// ==                                                                        ==
// ==  Stiftung caesar                                                       ==
// ==  Ludwig-Erhard-Allee 2                                                 ==
// ==  53175 Bonn                                                            ==
// ==  germany                                                               ==
// ==                                                                        ==
// ============================================================================
// ==                                                                        ==
// ==  http://www.caesar.de/cg/AMDiS                                         ==
// ==                                                                        ==
// ============================================================================

/** \file GMResSolver.h */

#ifndef AMDIS_GMRESSOLVER_H
#define AMDIS_GMRESSOLVER_H

Thomas Witkowski's avatar
Thomas Witkowski committed
24
#include <vector>
25
26
27
28
29
30
#include "OEMSolver.h"
#include "MemoryManager.h"

namespace AMDiS {

  // ============================================================================
Thomas Witkowski's avatar
Thomas Witkowski committed
31
  // ===== class GMResSolver ===================================================
32
33
34
35
36
37
  // ============================================================================

  /** 
   * \ingroup Solver
   *
   * \brief
Thomas Witkowski's avatar
Thomas Witkowski committed
38
39
40
41
42
43
44
45
46
47
48
49
   * Solves a linear system by the restarted GMRES(m) method (Generalized Minimal
   * Residual) for general nonsymmetric system matrices.
   *
   * The implementation is based on the following book: "Numerik linearer
   * Gleichungssystene", 2. Auflage, Andreas Meister. The algorithm is described
   * on pages 150 and  154 (for the restarted version). The extension to the
   * preconditioned GMRES(m) is based on the description in the book "Iterative
   * Methods for Sparse Linear Systems", second edition, Yousef Saad, on page 268.
   *
   * The orthogonal system is build using the modified Gram Schmidt (MGS) method.
   * The least square problem is solved using Givens transformations.
   * 
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
   */
  template<typename VectorType>
  class GMResSolver : public OEMSolver<VectorType>
  {
  public:
    MEMORY_MANAGED(GMResSolver<VectorType>);

    /** \brief
     * Creator class used in the OEMSolverMap.
     */
    class Creator : public OEMSolverCreator<VectorType>
    {
    public:
      MEMORY_MANAGED(Creator);

      virtual ~Creator() {};

      /** \brief
       * Returns a new GMResSolver object.
       */   
      OEMSolver<VectorType>* create() { 
	return NEW GMResSolver<VectorType>(this->name);
      };
    };

    /** \brief
     * constructor
     */
    GMResSolver(::std::string name);

    /** \brief
     * destructor
     */
    ~GMResSolver();

  protected:
    /** \brief
     * realisation of OEMSolver::solveSystem
     */
    int solveSystem(MatVecMultiplier<VectorType> *mv, VectorType *x, VectorType *b);

    /** \brief
     * realisation of OEMSolver::init
     */
    void init();

    /** \brief
     * realisation of OEMSolver::exit
     */
    void exit();

Thomas Witkowski's avatar
Thomas Witkowski committed
101
102
103
104
105
106
107
    /** \brief
     * One run of the GMRES(m) method. Is called from solveSystem().
     */
    int gmres(MatVecMultiplier<VectorType> *mv,
	      VectorType *x, 
	      VectorType *b);

108
109
  private:
    /** \brief
Thomas Witkowski's avatar
Thomas Witkowski committed
110
     * Stores the tolerance boundary for numerical computations.
111
     */
Thomas Witkowski's avatar
Thomas Witkowski committed
112
    double TOL_;
113
114

    /** \brief
Thomas Witkowski's avatar
Thomas Witkowski committed
115
116
     * The parameter m of GMRES(m), i.e. the number of iterations before a restart of
     * the algorithm is forced.
117
     */
Thomas Witkowski's avatar
Thomas Witkowski committed
118
    int restart_;
119
120

    /** \brief
Thomas Witkowski's avatar
Thomas Witkowski committed
121
     * Stores intermediate results in the orthogonalization step.
122
     */
Thomas Witkowski's avatar
Thomas Witkowski committed
123
    VectorType *w_;
124
125


Thomas Witkowski's avatar
Thomas Witkowski committed
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
    VectorType *z_;

    VectorType *r_;

    /** \brief
     * Pointers to the vectors of the orthogonal system.
     */
    VectorType **v;

    /** \brief
     * Stores the gamma values for Givens transformations.
     */
    ::std::vector<double> gamma;

    /** \brief
     * Stores the c values for Givens transformations.
     */    
    ::std::vector<double> c;
144

Thomas Witkowski's avatar
Thomas Witkowski committed
145
146
147
148
    /** \brief
     * Stores the s values for Givens transformations.
     */
    ::std::vector<double> s;
149

Thomas Witkowski's avatar
Thomas Witkowski committed
150
151
152
153
154
155
    ::std::vector<double> y_;

    /** \brief
     * H-Matrix computed in the GMRES algorithm.
     */    
    ::std::vector< ::std::vector<double> > h;
156
157
158
159
160
161
162
163
  };


}

#include "GMResSolver.hh"

#endif // AMDIS_GMRESSOLVER_H