So-Bogus
A c++ sparse block matrix library aimed at Second Order cone problems
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Pages
ProductGaussSeidel.hpp
1 /*
2  * This file is part of bogus, a C++ sparse block matrix library.
3  *
4  * Copyright 2016 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 
12 #ifndef BOGUS_PRODUCT_GAUSS_SEIDEL_HPP
13 #define BOGUS_PRODUCT_GAUSS_SEIDEL_HPP
14 
15 #include "GaussSeidelBase.hpp"
16 #include "ProductGaussSeidelUtils.hpp"
17 
18 #include <vector>
19 
20 namespace bogus
21 {
22 
24 
39 template < typename BlockMatrixType, typename DiagonalType = typename BlockMatrixType::Scalar,
40  bool PrecomputeDMt = !( IsSame<DiagonalType, typename BlockMatrixType::Scalar>::Value ) >
43 {
44 public:
46 
48  typedef typename GlobalProblemTraits::Scalar Scalar ;
49 
53 
56  : Base()
57  { }
60  : Base()
61  { setMatrix( matrix ) ; }
63  ProductGaussSeidel( const BlockObjectBase< BlockMatrixType > & matrix, const DiagonalType& diagonal )
64  : Base(), m_diagonal( DiagWrapper( diagonal ) )
65  { setMatrix( matrix ) ; }
66 
68  ProductGaussSeidel& setMatrix( const BlockObjectBase< BlockMatrixType > & matrix ) ;
69 
71  ProductGaussSeidel& setDiagonal( const DiagonalType &diagonal ) ;
72 
74  template < typename NSLaw, typename RhsT, typename ResT >
75  Scalar solve( const NSLaw &law, const RhsT &b, ResT &x, bool tryZeroAsWell = true ) const ;
76 
92  template < typename NSLaw, typename RhsT, typename ResT, typename LSDerived, typename HDerived >
93  Scalar solveWithLinearConstraints( const NSLaw &law,
94  const BlockObjectBase< LSDerived >& Cinv,
96  const Scalar alpha,
97  const RhsT &b, const RhsT &c,
98  ResT &x,
99  bool tryZeroAsWell = true, unsigned solveEvery = 1) const ;
100 
114  template < typename NSLaw, typename RhsT, typename ResT, typename WDerived >
115  Scalar solveWithLinearConstraints( const NSLaw &law,
117  const RhsT &b, ResT &x,
118  bool tryZeroAsWell = true, unsigned solveEvery = 1 ) const ;
119 
120 protected:
121 
122  DiagWrapper m_diagonal ;
123  DMtStorage m_DMt ;
124 
125  void updateLocalMatrices();
126 
127  template < typename NSLaw, typename VecT, typename ResT >
128  void innerLoop (
129  bool parallelize, const NSLaw &law, const VecT& b,
130  std::vector< unsigned char > &skip, Scalar &ndxRef,
131  VecT& Mx, ResT &x ) const ;
132 
133  typedef typename Base::Index Index ;
134 
135  using Base::m_matrix ;
136  using Base::m_maxIters ;
137  using Base::m_tol ;
138  using Base::m_scaling ;
139  using Base::m_maxThreads ;
140  using Base::m_evalEvery ;
141  using Base::m_skipTol ;
142  using Base::m_skipIters ;
143  using Base::m_localMatrices ;
144  using Base::m_regularization ;
145 
146 } ;
147 
148 } //namespace bogus
149 
150 
151 #endif
Abstract Gauss-Seidel interface .
Definition: GaussSeidelBase.hpp:25
Definition: BlockSolvers.fwd.hpp:33
Matrix-free version of the GaussSeidel iterative solver.
Definition: ProductGaussSeidel.hpp:41
ProductGaussSeidel(const BlockObjectBase< BlockMatrixType > &matrix, const DiagonalType &diagonal)
Constructor with both the main matrix M and the diagonal D.
Definition: ProductGaussSeidel.hpp:63
Definition: CppTools.hpp:62
ProductGaussSeidel(const BlockObjectBase< BlockMatrixType > &matrix)
Constructor with the main system matrix M.
Definition: ProductGaussSeidel.hpp:59
ProductGaussSeidel()
Default constructor – you will have to call setMatrix() before using the solve() function.
Definition: ProductGaussSeidel.hpp:55