MTL4Solver.h 2.96 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
24
25
26
27
28
// ============================================================================
// ==                                                                        ==
// == AMDiS - Adaptive multidimensional simulations                          ==
// ==                                                                        ==
// ============================================================================
// ==                                                                        ==
// ==  TU Dresden                                                            ==
// ==                                                                        ==
// ==  Institut für Wissenschaftliches Rechnen                               ==
// ==  Zellescher Weg 12-14                                                  ==
// ==  01069 Dresden                                                         ==
// ==  germany                                                               ==
// ==                                                                        ==
// ============================================================================
// ==                                                                        ==
// ==  https://gforge.zih.tu-dresden.de/projects/amdis/                      ==
// ==                                                                        ==
// ============================================================================

#ifndef MTL4SOLVER_H
#define MTL4SOLVER_H

#include "OEMSolver.h"
#include "MatrixStreams.h"
#include <iostream>

namespace AMDiS {

29
30
  template< typename MTLMatrix, typename MTLVector, typename Worker >
  class MTL4Solver : public OEMSolver {    
31
    MTLMatrix matrix;
32
33
  protected:    
    Worker worker;
34

35
36
37
    template< typename Matrix, typename Vector, typename Mapper >
    int solve(const Matrix& A, Vector& x, Vector& b, Mapper& mapper) 
    {
38
39
40
41
42
43
44
      if(num_rows(matrix) == 0 || !getMultipleRhs() ) {
        matrix.change_dim(mapper.nRow(), mapper.nCol());
        set_to_zero(matrix);
        MatMap< const Matrix, Mapper > matMap(A,mapper);
        matrix << matMap;
	worker.init(matrix);
      }
45

46
47
48
49
      MTLVector mtl_x(mapper.nRow());
      set_to_zero(mtl_x);
      VecMap< Vector, Mapper > xVecMap(x, mapper);
      mtl_x << xVecMap;
50

51
52
53
54
      MTLVector mtl_b(mapper.nRow());
      set_to_zero(mtl_b);
      VecMap< Vector, Mapper> bVecMap(b, mapper);
      mtl_b << bVecMap;
55

56
      error = worker.solve(matrix ,mtl_x, mtl_b);
57

58
59
60
61
62
      mtl::dense_vector<typename MTLMatrix::value_type> r(mtl_b); 
      r -= matrix * mtl_x; 
      double residual = two_norm(r);
      MSG("MTL4Solver: ||b-Ax||= %e\n", residual);

63
64
65
      mtl_x >> xVecMap;
      return error;
    }
66

67
68
69
  public:
    MTL4Solver(std::string n):
      OEMSolver(n),
70
      matrix(0,0),
71
72
      worker(this)
    {}
73

74
    virtual int solveSystem(const SolverMatrix<Matrix<DOFMatrix*> >& A,
75
76
77
			    SystemVector& x, 
			    SystemVector& b,
			    VectorialMapper& m)
78
79
80
    {
      return solve(A,x,b,m);
    }
81
82
83
84
85

      
  };
}
#endif