MTL4Solver.h 2.78 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
      mtl_x >> xVecMap;
      return error;
    }
61

62
63
64
  public:
    MTL4Solver(std::string n):
      OEMSolver(n),
65
      matrix(0,0),
66
67
      worker(this)
    {}
68

69
    virtual int solveSystem(const SolverMatrix<Matrix<DOFMatrix*> >& A,
70
71
72
			    SystemVector& x, 
			    SystemVector& b,
			    VectorialMapper& m)
73
74
75
    {
      return solve(A,x,b,m);
    }
76
77
78
79
80

      
  };
}
#endif