ITL_OEMSolver.h 4.84 KB
Newer Older
1
2
3
4
5
6
// ============================================================================
// ==                                                                        ==
// == AMDiS - Adaptive multidimensional simulations                          ==
// ==                                                                        ==
// ============================================================================
// ==                                                                        ==
7
// ==  TU Dresden                                                            ==
8
// ==                                                                        ==
9
10
11
// ==  Institut fr Wissenschaftliches Rechnen                               ==
// ==  Zellescher Weg 12-14                                                  ==
// ==  01069 Dresden                                                         ==
12
13
14
15
// ==  germany                                                               ==
// ==                                                                        ==
// ============================================================================
// ==                                                                        ==
16
// ==  https://gforge.zih.tu-dresden.de/projects/amdis/                      ==
17
18
19
20
21
22
23
24
25
// ==                                                                        ==
// ============================================================================

/** \file ITL_OEMSolver.h */


#ifndef AMDIS_ITL_OEM_SOLVER_H
#define AMDIS_ITL_OEM_SOLVER_H

26
#include <iostream>
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#include "OEMSolver.h"
#include "ITL_Preconditioner.h"
#include "SolverMatrix.h"
#include "DOFVector.h"
#include "SystemVector.h"
#include "DOFMatrix.h"
#include "Parameters.h"

#include <boost/numeric/itl/itl.hpp>
#include <boost/numeric/mtl/mtl.hpp>

namespace AMDiS {

  
  /**
   * \ingroup Solver
   * 
   *\brief
   * Template for using solvers from ITL in AMDiS. 
   */
  template <typename ITLSolver>
  class ITL_OEMSolver : public OEMSolver
  {
    typedef ITL_Preconditioner<itl::pc::identity<DOFMatrix> > id_t;

  public:
    /// The constructor reads needed parameters and sets solvers \ref name.
    ITL_OEMSolver(::std::string name) : OEMSolver(name)  {}
  
    ~ITL_OEMSolver() {}


    /// Solves the system iteratively
    // This function is virtual because derived class calls solver with parameter
    virtual int solveSystem(const DOFMatrix::base_matrix_type&      A,
			    mtl::dense_vector<value_type>&          x,
			    const mtl::dense_vector<value_type>&    b)
    {
      itl::cyclic_iteration<value_type> iter(b, this->max_iter, this->relative, 
					     this->tolerance, this->print_cycle);
67
68
69
70
71
72
73
#if 0
      std::cout << "A is " << num_rows(A) << " x " << num_cols(A)
		<< ", one_norm(A) = " << one_norm(A)
		<< ", b is " << num_rows(b) 
		<< ", one_norm(b) = " << one_norm(b)
		<< ", x is " << num_rows(x)
		<< ", one_norm(x) = " << one_norm(x) << "\n";
74
75
      if (one_norm(x) > 1e100)
	  x= 0.0;
76
#endif 
77
78
79
      error= ITLSolver()(A, x, b, *this->leftPrecon, *this->rightPrecon, iter);
      iterations= iter.iterations();
      return error;
80
81
82
83
84
85
86
87
88
89
    }


    /// Creator class used in the OEMSolverMap.
    class Creator : public OEMSolverCreator
    {
    public:
      virtual ~Creator() {}
      
      /// Returns a new CGSolver object.
90
91
      OEMSolver* create() 
      { 
Thomas Witkowski's avatar
Thomas Witkowski committed
92
	return new ITL_OEMSolver<ITLSolver>(this->name); 
93
      }
94
    }
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
  
  };


  /**
   * \ingroup Solver
   * 
   *\brief
   * Template for using solvers from ITL that have one run-time parameter in AMDiS. 
   */
  template <typename ITLSolver>
  class ITL_OEMSolver_para
      : public OEMSolver // ITL_OEMSolver<ITLSolver>
  {
      typedef DOFMatrix::value_type value_type;
  public:
      /// The constructor reads needed parameters and sets solvers \ref name.
      ITL_OEMSolver_para(::std::string name) 
113
	  : OEMSolver(name), ell(OEMSolver::max_iter) 
114
      {
115
	  GET_PARAMETER(0, name + "->ell", "%d", &ell);
116
117
118
119
120
      }
      
      ~ITL_OEMSolver_para() {}

      /// Set parameter of iterative solver
121
    void setEll(int p) { ell= p; }
122
123
124
125
126
127
128
129

    /// Solves the system iteratively
    int solveSystem(const DOFMatrix::base_matrix_type&      A,
		    mtl::dense_vector<value_type>&          x,
		    const mtl::dense_vector<value_type>&    b)
    {
	itl::cyclic_iteration<value_type> iter(b, this->max_iter, this->relative, 
					       this->tolerance, this->print_cycle);
130
131
132
	error= ITLSolver()(A, x, b, *this->leftPrecon, *this->rightPrecon, iter, ell);
	iterations= iter.iterations();
	return error;
133
134
135
136
137
138
139
140
    }

    class Creator : public OEMSolverCreator
    {
    public:
      virtual ~Creator() {}
      
      /// Returns a new CGSolver object.
141
142
      OEMSolver* create() 
      { 
Thomas Witkowski's avatar
Thomas Witkowski committed
143
	return new ITL_OEMSolver_para<ITLSolver>(this->name); 
144
145
146
147
      }
    }; 
      
  private:
148
149
    /// parameter for bicgstab_ell iterative solver    
    int ell;
150
151
152
153
154
155
  };


} // namespace AMDiS

#endif // AMDIS_ITL_OEM_SOLVER_H