So-Bogus
A c++ sparse block matrix library aimed at Second Order cone problems
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Pages
GaussSeidelBase.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_BASE_HPP
13 #define BOGUS_BLOCK_GAUSS_SEIDEL_BASE_HPP
14 
15 #include "ConstrainedSolverBase.hpp"
16 #include "Coloring.hpp"
17 
18 #include <vector>
19 
20 namespace bogus
21 {
22 
24 template < typename GaussSeidelImpl, typename BlockMatrixType >
25 class GaussSeidelBase : public ConstrainedSolverBase< GaussSeidelImpl, BlockMatrixType >
26 {
27 public:
29 
31  typedef typename GlobalProblemTraits::Scalar Scalar ;
32 
34 
42  void setMaxThreads( unsigned maxThreads = 0 ) {
43  m_maxThreads = maxThreads ;
44  }
45 
46 
48 
70  void setAutoRegularization( Scalar maxRegul ) { m_autoRegularization = maxRegul ; }
71 
72  // Debug
73 
75 
76  void setEvalEvery( unsigned evalEvery ) { m_evalEvery = evalEvery ; }
78  void setSkipTol ( Scalar skipTol ) { m_skipTol = skipTol ; }
80  void setSkipIters( unsigned skipIters ) { m_skipIters = skipIters ; }
81 
82 
83 protected:
84 
85  GaussSeidelBase() :
86  m_maxThreads ( 0 ),
87  m_evalEvery ( 25 ),
88  m_skipIters ( 10 ),
90  {
91  m_tol = 1.e-6 ;
92  m_maxIters = 250 ;
93  m_skipTol = 1.e-6 ;
94  }
95 
96  const BlockMatrixBase< BlockMatrixType >& explicitMatrix() const
97  {
98  // Will cause a compile error if BlockMatrixType does not derive from BlockMatrixBase
99  // This is voluntary, GaussSeidel implementations does not handle arbitrary expressions yet
100  return m_matrix->derived() ;
101  }
102  const IterableBlockObject< BlockMatrixType >& iterableMatrix() const
103  {
104  // Will cause a compile error if BlockMatrixType does not derive from IterableObjectBase
105  // This is voluntary, GaussSeidel implementations does not handle arbitrary expressions yet
106  return m_matrix->derived() ;
107  }
108 
109  // Add regularization, compute scalings from diagonal block matrices
110  void processLocalMatrices() ;
111 
112  template < typename NSLaw, typename ResT >
113  Scalar evalAndKeepBest(
114  const NSLaw &law, const ResT &x,
115  const typename GlobalProblemTraits::DynVector& y,
116  typename GlobalProblemTraits::DynVector& x_best, Scalar &err_best ) const ;
117 
118  template < typename NSLaw, typename RhsT, typename ResT >
119  bool tryZero(
120  const NSLaw &law, const RhsT &b, ResT &x,
121  typename GlobalProblemTraits::DynVector& x_best, Scalar &err_best ) const ;
122 
123 
124  using Base::m_matrix ;
125  using Base::m_maxIters ;
126  using Base::m_tol ;
127  using Base::m_scaling ;
128 
129  typedef typename Base::Index Index ;
130  typedef typename Base::BlockProblemTraits::Matrix DiagonalBlockType ;
131  typename ResizableSequenceContainer< DiagonalBlockType >::Type m_localMatrices ;
132  typename GlobalProblemTraits::DynVector m_regularization ;
133 
135  unsigned m_maxThreads ;
136 
138  unsigned m_evalEvery ;
140  Scalar m_skipTol ;
142  unsigned m_skipIters ;
143 
146 
147 } ;
148 
149 } //namespace bogus
150 
151 
152 #endif
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
const Derived & derived() const
Returns a const reference to the implementation.
Definition: BlockObjectBase.hpp:25
Definition: BlockSolvers.fwd.hpp:33
void setMaxThreads(unsigned maxThreads=0)
Sets the maximum number of threads that the solver can use.
Definition: GaussSeidelBase.hpp:42
void setEvalEvery(unsigned evalEvery)
Sets the number of iterations that should be performed between successive evaluations of the global e...
Definition: GaussSeidelBase.hpp:76
void setSkipIters(unsigned skipIters)
Sets the number of iterations for temporarily freezing local problems.
Definition: GaussSeidelBase.hpp:80
unsigned m_maxThreads
See setMaxThreads(). Defaults to 0 .
Definition: GaussSeidelBase.hpp:135
void setAutoRegularization(Scalar maxRegul)
Sets the auto-regularization (a.k.a. proximal point) coefficient.
Definition: GaussSeidelBase.hpp:70
const BlockObjectBase< BlockMatrixType > * m_matrix
Pointer to the matrix of the system.
Definition: BlockSolverBase.hpp:65
unsigned m_evalEvery
See setEvalEvery(). Defaults to 25.
Definition: GaussSeidelBase.hpp:138
unsigned m_maxIters
See setMaxIters()
Definition: BlockSolverBase.hpp:68
Definition: ConstrainedSolverBase.hpp:20
Scalar m_autoRegularization
Definition: GaussSeidelBase.hpp:145
void setSkipTol(Scalar skipTol)
Sets the minimum iteration step size under which local problems are temporarily frozen.
Definition: GaussSeidelBase.hpp:78