So-Bogus
A c++ sparse block matrix library aimed at Second Order cone problems
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Pages
ConstrainedSolverBase.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_CONSTRAINED_SOLVER_BASE_HPP
12 #define BOGUS_CONSTRAINED_SOLVER_BASE_HPP
13 
14 #include "BlockSolverBase.hpp"
15 
16 namespace bogus
17 {
18 
19 template< typename Derived, typename BlockMatrixType >
20 class ConstrainedSolverBase : public BlockSolverBase< BlockMatrixType >
21 {
23 
24 public:
25 
27  typedef typename GlobalProblemTraits::Scalar Scalar ;
28  typedef typename BlockMatrixTraits< BlockMatrixType >::Index Index ;
29 
31 
33  void useInfinityNorm( bool useInfNorm ) { m_useInfinityNorm = useInfNorm ; }
34  bool usesInfinityNorm( ) const { return m_useInfinityNorm ; }
35 
37 
43  template < typename NSLaw, typename RhsT, typename ResT >
44  Scalar eval ( const NSLaw &law, const ResT &y, const RhsT &x ) const ;
45 
47  template < typename NSLaw, typename VectorT >
48  void projectOnConstraints( const NSLaw &projector, VectorT &x ) const ;
49 
51  template < typename NSLaw, typename RhsT, typename ResT >
52  void dualityCOV( const NSLaw &law, const RhsT &b, ResT &x ) const ;
53 
54  template < typename NSLaw, typename RhsT, typename ResT >
55  Scalar solve( const NSLaw &law, const RhsT &b, ResT &x ) const
56  {
57  return static_cast< const Derived& >( *this ).solve( law, b, x ) ;
58  }
59 
61 
62  Derived& setMatrix( const BlockObjectBase< BlockMatrixType > & matrix )
63  {
64  return static_cast< Derived& >( *this ).setMatrix( matrix ) ;
65  }
66 
67 protected:
68 
69  void updateScalings( ) ;
70 
71  ConstrainedSolverBase() : Base(), m_useInfinityNorm( false ) {}
72  using Base::m_matrix ;
73 
74  typename GlobalProblemTraits::DynVector m_scaling ;
75 
78 
79 };
80 
81 } //namespace bogus
82 
83 #endif
void useInfinityNorm(bool useInfNorm)
Sets whether the solver will use the infinity norm instead of the l1 one to compute the global residu...
Definition: ConstrainedSolverBase.hpp:33
void dualityCOV(const NSLaw &law, const RhsT &b, ResT &x) const
Compute associated change of variable (see NSLaw)
Scalar eval(const NSLaw &law, const ResT &y, const RhsT &x) const
Eval the current global residual as a function of the local ones.
Definition: Traits.hpp:19
Definition: BlockSolvers.fwd.hpp:33
Base class for solvers that operate on BlockMatrixBase matrices.
Definition: BlockSolverBase.hpp:29
Derived & setMatrix(const BlockObjectBase< BlockMatrixType > &matrix)
Sets the system matrix and initializes internal structures.
Definition: ConstrainedSolverBase.hpp:62
void projectOnConstraints(const NSLaw &projector, VectorT &x) const
Projects the variable x on the constraints defined by projector.
const BlockObjectBase< BlockMatrixType > * m_matrix
Pointer to the matrix of the system.
Definition: BlockSolverBase.hpp:65
Definition: ConstrainedSolverBase.hpp:20
Definition: EigenProblemTraits.hpp:38
bool m_useInfinityNorm
See useInfinityNorm(). Defaults to false.
Definition: ConstrainedSolverBase.hpp:77