So-Bogus
A c++ sparse block matrix library aimed at Second Order cone problems
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Pages
Krylov.hpp
1 /*
2  * This file is part of bogus, a C++ sparse block matrix library.
3  *
4  * Copyright 2013 Gilles Daviet <gdaviet@gmail.com>
5  *
6  * This Source Code Form is subject to the terms of the Mozilla Public
7  * License, v. 2.0. If a copy of the MPL was not distributed with this
8  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 */
10 
11 #ifndef BOGUS_KRYLOV_HPP
12 #define BOGUS_KRYLOV_HPP
13 
14 #include "BlockSolverBase.hpp"
15 #include "Preconditioners.hpp"
16 #include "KrylovMethods.hpp"
17 
18 #include <vector>
19 
20 namespace bogus
21 {
22 
23 
25 
33 template < typename BlockMatrixType,
34  template< typename BlockMatrixT > class PreconditionerType >
35 class Krylov : public BlockSolverBase< BlockMatrixType >
36 {
37 public:
39  typedef PreconditionerType< BlockObjectBase< BlockMatrixType > > PreconditionerImplType ;
40 
42  typedef typename GlobalProblemTraits::Scalar Scalar ;
43 
45  Krylov( ) ;
47  explicit Krylov( const BlockObjectBase< BlockMatrixType > & matrix ) ;
48 
51 
52  // For each value of the krylov::Method enum, create a MethodNameType typedef
53  // and the asMethodName() -> MethodNameType and solve_MethodName -> Scalar methods
54 #define BOGUS_PROCESS_KRYLOV_METHOD( MethodName )\
55  typedef krylov::solvers::MethodName< \
56  BlockMatrixType, PreconditionerType< BlockObjectBase< BlockMatrixType > >, \
57  GlobalProblemTraits > MethodName##Type ; \
58  \
59  MethodName##Type as##MethodName() const { \
60  return MethodName##Type( \
61  Base::m_matrix->derived(), \
62  Base::m_maxIters, Base::m_tol, \
63  &m_preconditioner, \
64  &this->m_callback \
65  ) ; } \
66  \
67  template < typename RhsT, typename ResT > \
68  Scalar solve_##MethodName( const RhsT &b, ResT &x ) const \
69  { return as##MethodName().solve( b, x ) ; }
70 
71 BOGUS_KRYLOV_METHODS
72 #undef BOGUS_PROCESS_KRYLOV_METHOD
73 
75  template < typename RhsT, typename ResT >
76  Scalar solve( const RhsT &b, ResT &x,
77  krylov::Method method = krylov::CG ) const ;
78 
79  const PreconditionerImplType& preconditioner() const {return m_preconditioner ; }
80  PreconditionerImplType& preconditioner() { return m_preconditioner ; }
81 
82 protected:
83 
84  PreconditionerImplType m_preconditioner ;
85 } ;
86 
87 } //namesoace bogus
88 
89 #endif
90 
Scalar solve(const RhsT &b, ResT &x, krylov::Method method=krylov::CG) const
Solve function that takes the method to use as an argument.
Definition: BlockSolvers.fwd.hpp:33
Base class for solvers that operate on BlockMatrixBase matrices.
Definition: BlockSolverBase.hpp:29
Krylov()
Default constructor – you will have to call setMatrix() before using any of the solve() functions...
Conjugate Gradient.
Definition: BlockSolvers.fwd.hpp:22
Method
Definition: BlockSolvers.fwd.hpp:20
Preconditionned Krylov Solvers.
Definition: Krylov.hpp:35
Krylov & setMatrix(const BlockObjectBase< BlockMatrixType > &matrix)
Sets the system matrix and initializes the preconditioner.