So-Bogus
A c++ sparse block matrix library aimed at Second Order cone problems
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Pages
SOCLaw.hpp
1 /*
2  * This file is part of So-bogus, a C++ sparse block matrix library and
3  * Second Order Cone solver.
4  *
5  * Copyright 2013 Gilles Daviet <gdaviet@gmail.com>
6  *
7  * So-bogus is free software: you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation, either version 2 of the License, or
10  * (at your option) any later version.
11 
12  * So-bogus is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16 
17  * You should have received a copy of the GNU General Public License
18  * along with So-bogus. If not, see <http://www.gnu.org/licenses/>.
19 */
20 
21 
22 #ifndef BOGUS_SOCLAW_HPP
23 #define BOGUS_SOCLAW_HPP
24 
25 #include "FischerBurmeister.hpp"
26 #include "LocalSOCSolver.hpp"
27 
28 #include <vector>
29 
30 namespace bogus
31 {
32 
34 
41 template < DenseIndexType Dimension, typename Scalar, bool DeSaxceCOV,
43 class SOCLaw
44 {
45 public:
46  typedef LocalProblemTraits< Dimension, Scalar > Traits ;
47  enum{ dimension = Dimension } ;
48 
50 
54  SOCLaw( const unsigned n, const double * mu ) ;
55 
57  Scalar eval( const unsigned problemIndex,
58  const typename Traits::Vector &x,
59  const typename Traits::Vector &y ) const
60  {
62 
63  if(m_mu[problemIndex] < 0) return y.squaredNorm() ;
64 
65  typename Traits::Vector fb( x.rows() ) ;
66  FBFunction::compute( m_mu[problemIndex], x, y, fb ) ;
67 
68  return fb.squaredNorm() ;
69  }
70 
72 
87  bool solveLocal(
88  const unsigned problemIndex,
89  const typename Traits::Matrix &A,
90  const typename Traits::Vector &b,
91  typename Traits::Vector &x,
92  const Scalar scaling
93  ) const ;
94 
96  void projectOnConstraint( const unsigned problemIndex, typename Traits::Vector &x ) const ;
97 
99 
102  template< typename Segment >
103  void dualityCOV( const unsigned problemIndex, const Segment& y,
104  typename Traits::Vector& s ) const
105  {
106  if( DeSaxceCOV ) {
107  Traits::np( s ) = m_mu[problemIndex] * Traits::tp(y).norm() ;
108  Traits::tp( s ).setZero() ;
109  } else s.setZero() ;
110  }
111 
112 private:
113 
114  const double * m_mu ;
115  const unsigned m_n ;
116  Scalar m_localTol ;
117 
118 } ;
119 
128 
129 }
130 
131 #endif // SOCLAW_HPP
void dualityCOV(const unsigned problemIndex, const Segment &y, typename Traits::Vector &s) const
Computes the change of variable s(y) so that (x, y+s(y)) obeys an associated law. ...
Definition: SOCLaw.hpp:103
SOCLaw< 3, double, true > Coulomb3D
Predefined non-smooth law for 3D Coulomb friction.
Definition: SOCLaw.hpp:123
SOCLaw< 3, double, false > SOC3D
Predefined non-smooth law for 3D SOC complementarity.
Definition: SOCLaw.hpp:127
Scalar eval(const unsigned problemIndex, const typename Traits::Vector &x, const typename Traits::Vector &y) const
Definition: SOCLaw.hpp:57
bool solveLocal(const unsigned problemIndex, const typename Traits::Matrix &A, const typename Traits::Vector &b, typename Traits::Vector &x, const Scalar scaling) const
Solves the local problem.
SOCLaw< 2, double, false > SOC2D
Predefined non-smooth law for 2D SOC complementarity.
Definition: SOCLaw.hpp:125
Non-smooth laws based on Second Order Cone complementarity. To be used within as the first argument t...
Definition: SecondOrder.fwd.hpp:56
Strategy
Strategy to be used by the local SOC solver.
Definition: SecondOrder.fwd.hpp:36
SOCLaw< 2, double, true > Coulomb2D
Predefined non-smooth law for 2D Coulomb friction.
Definition: SOCLaw.hpp:121
SOCLaw(const unsigned n, const double *mu)
Constructor.
void projectOnConstraint(const unsigned problemIndex, typename Traits::Vector &x) const
Projects x on .
Fischer-Burmeister function and jacobian computation, with optional change of variable.
Definition: FischerBurmeister.hpp:61