ITL_OEMSolver.h 4.83 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
// ============================================================================
// ==                                                                        ==
// == AMDiS - Adaptive multidimensional simulations                          ==
// ==                                                                        ==
// ============================================================================
// ==                                                                        ==
// ==  crystal growth group                                                  ==
// ==                                                                        ==
// ==  Stiftung caesar                                                       ==
// ==  Ludwig-Erhard-Allee 2                                                 ==
// ==  53175 Bonn                                                            ==
// ==  germany                                                               ==
// ==                                                                        ==
// ============================================================================
// ==                                                                        ==
// ==  http://www.caesar.de/cg/AMDiS                                         ==
// ==                                                                        ==
// ============================================================================

/** \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
90
    }


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


  /**
   * \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) 
112
	  : OEMSolver(name), ell(OEMSolver::max_iter) 
113
      {
114
	  GET_PARAMETER(0, name + "->ell", "%d", &ell);
115
116
117
118
119
      }
      
      ~ITL_OEMSolver_para() {}

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

    /// 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);
129
130
131
	error= ITLSolver()(A, x, b, *this->leftPrecon, *this->rightPrecon, iter, ell);
	iterations= iter.iterations();
	return error;
132
133
134
135
136
137
138
139
140
    }

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


} // namespace AMDiS

#endif // AMDIS_ITL_OEM_SOLVER_H