So-Bogus
A c++ sparse block matrix library aimed at Second Order cone problems
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Pages
GaussSeidel.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 
12 #ifndef BOGUS_BLOCK_GAUSS_SEIDEL_HPP
13 #define BOGUS_BLOCK_GAUSS_SEIDEL_HPP
14 
15 #include "GaussSeidelBase.hpp"
16 #include "Coloring.hpp"
17 
18 #include <vector>
19 
20 namespace bogus
21 {
22 
24 
42 template < typename BlockMatrixType >
43 class GaussSeidel : public GaussSeidelBase< GaussSeidel<BlockMatrixType>, BlockMatrixType >
44 {
45 public:
47 
49  typedef typename GlobalProblemTraits::Scalar Scalar ;
50 
52  GaussSeidel( ) : Base() { }
54  explicit GaussSeidel( const BlockObjectBase< BlockMatrixType > & matrix ) : Base()
55  { setMatrix( matrix ) ; }
56 
59 
61 
82  template < typename NSLaw, typename RhsT, typename ResT >
83  Scalar solve( const NSLaw &law, const RhsT &b, ResT &x, bool tryZeroAsWell = true ) const ;
84 
100  template < typename NSLaw, typename RhsT, typename ResT, typename LSDerived, typename HDerived >
101  Scalar solveWithLinearConstraints( const NSLaw &law,
102  const BlockObjectBase< LSDerived >& Cinv,
104  const Scalar alpha,
105  const RhsT &b, const RhsT &c,
106  ResT &x,
107  bool tryZeroAsWell = true, unsigned solveEvery = 1) const ;
108 
122  template < typename NSLaw, typename RhsT, typename ResT, typename WDerived >
123  Scalar solveWithLinearConstraints( const NSLaw &law,
125  const RhsT &b, ResT &x,
126  bool tryZeroAsWell = true, unsigned solveEvery = 1 ) const ;
127 
129 
132  Coloring& coloring( ) { return m_coloring ; }
133 
134 protected:
135  void updateLocalMatrices() ;
136 
137  template < typename NSLaw, typename RhsT, typename ResT >
138  void innerLoop (
139  bool parallelize, const NSLaw &law, const RhsT& b,
140  std::vector< unsigned char > &skip, Scalar &ndxRef,
141  ResT &x ) const ;
142 
143  typedef typename Base::Index Index ;
144 
145  using Base::m_matrix ;
146  using Base::m_maxIters ;
147  using Base::m_tol ;
148  using Base::m_scaling ;
149  using Base::m_maxThreads ;
150  using Base::m_evalEvery ;
151  using Base::m_skipTol ;
152  using Base::m_skipIters ;
153  using Base::m_localMatrices ;
154  using Base::m_regularization ;
155 
158 } ;
159 
160 } //namespace bogus
161 
162 
163 #endif
Coloring m_coloring
Definition: GaussSeidel.hpp:157
Scalar m_tol
See setTol()
Definition: BlockSolverBase.hpp:70
Abstract Gauss-Seidel interface .
Definition: GaussSeidelBase.hpp:25
Scalar m_skipTol
See setSkipTol(). Defaults to 1.e-6.
Definition: GaussSeidelBase.hpp:140
unsigned m_skipIters
See setSkipIters() Defaults to 10.
Definition: GaussSeidelBase.hpp:142
Definition: BlockSolvers.fwd.hpp:33
Scalar solve(const NSLaw &law, const RhsT &b, ResT &x, bool tryZeroAsWell=true) const
Finds an approximate solution for a constrained linear problem.
GaussSeidel()
Default constructor – you will have to call setMatrix() before using the solve() function.
Definition: GaussSeidel.hpp:52
unsigned m_maxThreads
See setMaxThreads(). Defaults to 0 .
Definition: GaussSeidelBase.hpp:135
const BlockObjectBase< BlockMatrixType > * m_matrix
Pointer to the matrix of the system.
Definition: BlockSolverBase.hpp:65
Coloring & coloring()
Access to the current Coloring. Will be reset whenever the matrix is changed.
Definition: GaussSeidel.hpp:132
Projected Gauss-Seidel iterative solver.
Definition: GaussSeidel.hpp:43
Coloring algorithm to determine which rows of a matrix can be treated in parallel.
Definition: Coloring.hpp:20
unsigned m_evalEvery
See setEvalEvery(). Defaults to 25.
Definition: GaussSeidelBase.hpp:138
GaussSeidel & setMatrix(const BlockObjectBase< BlockMatrixType > &matrix)
Sets the system matrix and initializes internal structures.
unsigned m_maxIters
See setMaxIters()
Definition: BlockSolverBase.hpp:68
GaussSeidel(const BlockObjectBase< BlockMatrixType > &matrix)
Constructor with the system matrix.
Definition: GaussSeidel.hpp:54
Scalar solveWithLinearConstraints(const NSLaw &law, const BlockObjectBase< LSDerived > &Cinv, const BlockObjectBase< HDerived > &H, const Scalar alpha, const RhsT &b, const RhsT &c, ResT &x, bool tryZeroAsWell=true, unsigned solveEvery=1) const