HermesCommon  2.0
linear_matrix_solver.h
1 // This file is part of HermesCommon
2 //
3 // Copyright (c) 2009 hp-FEM group at the University of Nevada, Reno (UNR).
4 // Email: hpfem-group@unr.edu, home page: http://hpfem.org/.
5 //
6 // Hermes2D is free software; you can redistribute it and/or modify
7 // it under the terms of the GNU General Public License as published
8 // by the Free Software Foundation; either version 2 of the License,
9 // or (at your option) any later version.
10 //
11 // Hermes2D is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
15 //
16 // You should have received a copy of the GNU General Public License
17 // along with Hermes2D; if not, write to the Free Software
18 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
22 #ifndef __HERMES_COMMON_SOLVER_H_
23 #define __HERMES_COMMON_SOLVER_H_
24 
25 #include "precond.h"
26 #include "dp_interface.h"
27 #include "exceptions.h"
28 #include "mixins.h"
29 
30 using namespace Hermes::Algebra;
31 
33 namespace Hermes
34 {
36  namespace Solvers
37  {
38  using namespace Hermes::Preconditioners;
74  {
76 
78 
80 
81 
83 
84  };
85 
91  template <typename Scalar>
93  {
94  public:
96 
97  virtual ~LinearMatrixSolver();
98 
101  virtual bool solve() = 0;
102 
105  Scalar *get_sln_vector();
106 
108  int get_error();
111  double get_time();
113  virtual int get_matrix_size() = 0;
114 
117  virtual void set_factorization_scheme(FactorizationScheme reuse_scheme) { };
118 
120  virtual void set_factorization_scheme();
121 
122  protected:
124  Scalar *sln;
126  int error;
127  double time;
128  };
129 
132  template <typename Scalar>
133  class DirectSolver : public LinearMatrixSolver<Scalar>
134  {
135  public:
136  DirectSolver(unsigned int factorization_scheme = HERMES_FACTORIZE_FROM_SCRATCH)
137  : LinearMatrixSolver<Scalar>(), factorization_scheme(factorization_scheme) {};
138 
139  protected:
140  virtual void set_factorization_scheme(FactorizationScheme reuse_scheme);
141 
142  unsigned int factorization_scheme;
143  };
144 
147  template <typename Scalar>
148  class IterSolver : public LinearMatrixSolver<Scalar>
149  {
150  public:
151  IterSolver() : LinearMatrixSolver<Scalar>(), max_iters(10000), tolerance(1e-8), precond_yes(false) {};
152 
153  virtual int get_num_iters() = 0;
154  virtual double get_residual() = 0;
155 
158  void set_tolerance(double tol);
159 
162  void set_max_iters(int iters);
163 
164  virtual void set_precond(const char *name) = 0;
165 
166  virtual void set_precond(Precond<Scalar> *pc) = 0;
167 
168  protected:
169  int max_iters;
170  double tolerance;
171  bool precond_yes;
172  };
173 
178  template<typename Scalar>
179  HERMES_API LinearMatrixSolver<Scalar>*
181  }
182 } // End of documentation group Solvers.
184 #endif