Allium  0.1.0
gmres.hpp
1 // Copyright 2020 Hannah Rittich
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 
15 #ifndef ALLIUM_LA_GMRES_HPP
16 #define ALLIUM_LA_GMRES_HPP
17 
18 #include "vector_storage.hpp"
19 #include "linear_operator.hpp"
20 #include "iterative_solver.hpp"
21 #include <allium/util/extern.hpp>
22 #include "default.hpp"
23 
24 namespace allium {
25 
38  template <typename N>
40  {
41  public:
42  using Number = N;
43  using Real = real_part_t<N>;
45 
46  void solve(VectorStorage<N>& result,
47  const VectorStorage<N>& rhs,
48  InitialGuess initial_guess);
49 
50  int iteration_count() { return m_iteration_count; }
51  private:
52  bool inner_solve(VectorStorage<N>& result,
53  const VectorStorage<N>& residual,
54  real_part_t<N> residual_norm,
55  real_part_t<N> abs_tol);
56 
57  size_t m_max_krylov_size;
58  int m_iteration_count;
59  };
60 
64  template <typename V>
66 
72  template <typename V, typename M>
73  void gmres(V& result,
74  std::shared_ptr<M> mat,
75  const V& rhs,
76  real_part_t<typename V::Number> tol = 1e-6)
77  {
79  solver.tolerance(tol);
80  solver.setup(mat);
81  solver.solve(result, rhs);
82  }
83 
84  #define ALLIUM_LA_GMRES_DECL(extern, N) \
85  extern template class GmresSolverBase<N>; \
86  extern template class IterativeSolverMixin<GmresSolverBase<N>, DefaultVector<N>>;
87  ALLIUM_EXTERN_N(ALLIUM_LA_GMRES_DECL)
88 }
89 
90 #endif
Implementation of the GMRES algorithm (Saad and Schultz, 1986).
Definition: gmres.hpp:40
Base class for iterative solvers.
Definition: iterative_solver.hpp:29
Mixin for iterative solvers, which implements the apply_matrix method.
Definition: iterative_solver.hpp:52
Abstract base class for any vector storage.
Definition: vector_storage.hpp:41
InitialGuess
Behavior for the initial guess.
Definition: linear_solver.hpp:32
void gmres(V &result, std::shared_ptr< M > mat, const V &rhs, real_part_t< typename V::Number > tol=1e-6)
Definition: gmres.hpp:73