ITL_OEMSolver.h 3.97 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

/** \file ITL_OEMSolver.h */


#ifndef AMDIS_ITL_OEM_SOLVER_H
#define AMDIS_ITL_OEM_SOLVER_H

27
#include <iostream>
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
#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.
55
    ITL_OEMSolver(std::string name) : OEMSolver(name)  {}
56
57
58
59
60
61
62
63
64
65
66
67
  
    ~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);
68
69
70
71

      error = ITLSolver()(A, x, b, *this->leftPrecon, *this->rightPrecon, iter);
      iterations = iter.iterations();
      residual = iter.resid();
72
      return error;
73
74
75
76
77
78
79
80
81
82
    }


    /// Creator class used in the OEMSolverMap.
    class Creator : public OEMSolverCreator
    {
    public:
      virtual ~Creator() {}
      
      /// Returns a new CGSolver object.
83
84
      OEMSolver* create() 
      { 
Thomas Witkowski's avatar
Thomas Witkowski committed
85
	return new ITL_OEMSolver<ITLSolver>(this->name); 
86
      }
Thomas Witkowski's avatar
Thomas Witkowski committed
87
    };
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
  
  };


  /**
   * \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.
105
      ITL_OEMSolver_para(std::string name) 
106
	  : OEMSolver(name), ell(OEMSolver::max_iter) 
107
      {
108
	Parameters::get(name + "->ell", ell);
109
110
111
112
113
      }
      
      ~ITL_OEMSolver_para() {}

      /// Set parameter of iterative solver
114
    void setEll(int p) { ell= p; }
115
116
117
118
119
120
121
122

    /// 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);
123
124
125
	error = ITLSolver()(A, x, b, *this->leftPrecon, *this->rightPrecon, iter, ell);
	iterations = iter.iterations();
	residual = iter.resid();
126
	return error;
127
128
129
130
131
132
133
134
    }

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


} // namespace AMDiS

#endif // AMDIS_ITL_OEM_SOLVER_H