OEMSolver.h 6.64 KB
Newer Older
1
2
3
4
// ============================================================================
// ==                                                                        ==
// == AMDiS - Adaptive multidimensional simulations                          ==
// ==                                                                        ==
5
// ==  http://www.amdis-fem.org                                              ==
6
7
// ==                                                                        ==
// ============================================================================
8
9
10
11
12
13
14
15
16
17
18
19
//
// Software License for AMDiS
//
// Copyright (c) 2010 Dresden University of Technology 
// All rights reserved.
// Authors: Simon Vey, Thomas Witkowski et al.
//
// This file is part of AMDiS
//
// See also license.opensource.txt in the distribution.


20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35

/** \file OEMSolver.h */

/**
 * \defgroup Solver Solver module
 * @{ <img src="solver.png"> @}
 * 
 * \brief
 * Contains all classes needed for solving linear and non linear equation
 * systems.
 */

#ifndef AMDIS_OEM_SOLVER_H
#define AMDIS_OEM_SOLVER_H

#include "Global.h"
36
#include "AMDiS_fwd.h"
37
#include "Initfile.h"
38
39
40
41
#include "SolverMatrix.h"
#include "DOFVector.h"
#include "SystemVector.h"
#include "DOFMatrix.h"
42
43
44
45
46
47
48
#include "BasePreconditioner.h"
#include "Mapper.h"

#ifdef HAVE_PARALLEL_DOMAIN_AMDIS
#include "parallel/ParallelMapper.h"
#endif
//#include "ITL_Preconditioner.h"
49
50
51
52
53
54
55
56
57
58
59
60

namespace AMDiS {

  /**
   * \ingroup Solver
   * 
   *\brief
   * Solver for linear equation systems.
   */
  class OEMSolver
  {
  public:
61
62
63
64

    typedef DOFMatrix::base_matrix_type   matrix_type;
    typedef DOFMatrix::value_type         value_type;

65
    /// The constructor reads needed parameters and sets solvers \ref name.
66
67
68
69
70
71
72
73
    OEMSolver(std::string str) 
      : name(str),
	tolerance(0),
	relative(0),
	max_iter(1000),
	info(0),
	residual(0),
	print_cycle(100),
74
75
	iterations(-1),
	error(-1),
76
	multipleRhs(false)
77
    {}
78

79
    ///
80
    virtual ~OEMSolver() 
Thomas Witkowski's avatar
Thomas Witkowski committed
81
    {}
82

83
84
85
    void initParameters()
    {
      FUNCNAME("OEMSolver::initParameters()");
86
      
87
88
89
90
91
      Parameters::get(name + "->tolerance", tolerance);
      Parameters::get(name + "->relative tolerance", relative);
      Parameters::get(name + "->max iteration", max_iter);
      Parameters::get(name + "->print cycle", print_cycle);
      Parameters::get(name + "->info", info);
92
    }
93
94


95
    /// Solve a linear system for a vectorial problem.
96
97
    virtual int solveSystem(const SolverMatrix<Matrix<DOFMatrix*> >& A,
			    SystemVector& x, 
98
			    SystemVector& b,
Naumann, Andreas's avatar
Naumann, Andreas committed
99
100
101
102
103
104
			    VectorialMapper&) 
    {
      FUNCNAME("OEMSolver::solveSystem()");
      TEST_EXIT(false)("This linear solver is not suitable for sequentiell problems\n");
      return -1;
    }
105

106
107
108
    inline int solveSystem(const SolverMatrix<Matrix<DOFMatrix*> >& A,
			   SystemVector& x,
			   SystemVector& b) 
109
    {
110
111
      VectorialMapper mapper(A);
      return solveSystem(A, x, b, mapper);
112
113
114
115
116
117
118
119
120
121
122
123
124
    }

#ifdef HAVE_PARALLEL_DOMAIN_AMDIS
    virtual int solveSystem(const SolverMatrix<Matrix<DOFMatrix*> >& A,
			    SystemVector& x, 
			    SystemVector& b,
			    ParallelMapper&) 
    { 
      FUNCNAME("OEMSolver::solveSystem()");
      TEST_EXIT(false)("This linear solver is not suitable for domaindecomposition problems\n");
      return -1;
    }
#endif
125
126
127
128
129

    /** \name getting methods
     * \{ 
     */

130
    /// Returns solvers \ref name.
131
    inline std::string getName() const
132
    { 
133
      return name; 
134
    }
135

136
    /// Returns \ref tolerance
137
    inline double getTolerance() const
138
    {
139
      return tolerance;
140
    }  
141

142
    /// Returns \ref max_iter
143
    inline int getMaxIterations() const
144
    {
145
      return max_iter;
146
    }
147

148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
    /// Returns number of iterations in last run of an iterative solver
    inline int getIterations() 
    {
      return iterations;
    }

    /// Returns error code in last run of an iterative solver
    inline int getErrorCode() 
    {
      return error;
    }

    /// Returns info
    inline int getInfo()
    {
      return info;
    }

    /// Returns \ref print_cycle
    inline int getPrint_cycle() const
    {
      return print_cycle;
    }

172
    /// Returns \ref residual
173
    inline double getResidual() const
174
    {
175
      return residual;
176
    }
177

178
179
180
181
182
183
184
185
186
187
188
189
190
    /// Returns \ref relative
    inline double getRelative() const
    {
      return relative;
    }

    /// Returns \ref multipleRhs
    inline bool getMultipleRhs() const
    {
      return multipleRhs;
    }


191
192
193
194
195
196
    /** \} */ 

    /** \name setting methods
     * \{ 
     */

197
    /// Sets \ref tolerance
198
199
    inline void setTolerance(double tol) 
    {
200
      tolerance = tol;
201
    }
202

203
204
205
206
207
    inline void setResidual(double r)
    {
      residual = r;
    }

208
    /// Sets \ref relative
Thomas Witkowski's avatar
Thomas Witkowski committed
209
    inline void setRelative(double rel) 
210
    {
211
      relative = rel;
212
    }
213

214
    /// Sets \ref max_iter
215
216
    inline void setMaxIterations(int i) 
    {
217
      max_iter = i;
218
    }
219

220
    inline void setIterations(int i)
221
    {
222
      iterations=i;
223
224
    }

225
226
    /// set the \ref error
    inline void setErrorCode(int code)
227
    {
228
      error=code;
229
    }
230
  
231
    /// Sets \ref info
232
233
    inline void setInfo(int i) 
    {
234
      info = i;
235
    }
236

237
    inline void setMultipleRhs(bool b)
238
239
240
241
    {
      multipleRhs = b;
    }

242
243
244
    /** \} */

  protected:
245
    /// solvers name.
246
    std::string name;
247

248
    /// Solver tolerance |r|. Set in OEMSolver's constructor. 
249
250
    double tolerance;

251
    /// Relative solver tolerance |r|/|r0|. Set in OEMSolver's constructor. 
252
    double relative;
253

254
    /// maximal number of iterations. Set in OEMSolver's constructor.
255
256
    int max_iter;

257
    /// info level during solving the system. Set in OEMSolver's constructor.
258
259
    int info;

260
    /// current residual.
261
262
    double residual;

263
264
    /// Print cycle, after how many iterations the residuum norm is logged.
    int print_cycle;
265

266
267
268
269
270
271
    /// How many iterations were performed in last solver (not set by UmfPack)
    int iterations;

    /// Error code  in last solver (not set by UmfPack)
    int error;

272
273
274
275
276
277
    /** \brief
     * If true, the solver has to solve multiple right hand sides with the same
     * matrix. Some solvers, e.g. direct once, may take advanteges from this knowledge,
     * as they can do the factorization of the matrix only once.
     */
    bool multipleRhs;
278
279
280
281
282
283
284
285
  };

  /** 
   * \ingroup Solver
   *
   * \brief
   * Interface for creators of concrete OEMSolvers. 
   */
286
  class OEMSolverCreator : public CreatorInterface<OEMSolver>
287
288
  { 
  public:
289
    virtual ~OEMSolverCreator() {}
290

291
    /// Sets \ref problem
292
293
    void setName(std::string str) 
    { 
294
      name = str; 
295
    }
296
297
298
299
300
301

  protected:
    /** \brief
     * Pointer to the problem the solver will belong to. Needed as parameter
     * when constructing an OEMSolver
     */
302
    std::string name;
303
304
305
  };
}

306
//#include "ITL_Solver.h"
307
308

#endif // AMDIS_OEM_SOLVER_H