So-Bogus
A c++ sparse block matrix library aimed at Second Order cone problems
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Pages
FrictionProblem.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 #ifndef BOGUS_FRICTION_PROBLEM_HPP
22 #define BOGUS_FRICTION_PROBLEM_HPP
23 
24 #include "../Core/Block.hpp"
25 #include "../Core/BlockSolvers.fwd.hpp"
26 
27 #include "../Extra/SecondOrder.fwd.hpp"
28 
29 #include "../Core/Utils/Signal.hpp"
30 
31 namespace bogus
32 {
33 
35 
56 template< unsigned Dimension >
58 {
59  // Primal Data
60 
63  MType M ;
66 
67  typedef Eigen::Matrix< double, Dimension, Eigen::Dynamic > HBlock ;
71 
73  const double *f ;
75  const double *w ;
77  const double *mu ;
78 
79  // Cached data
80 
83  MInvType MInv ;
84 
87  void computeMInv () ;
88 
89 
90  // Primal-dual solve functions
91 
92  typedef ADMM < HType > ADMMType ;
95 
97 
101  double solveWith( ProductGaussSeidelType &pgs, double * r, const bool staticProblem = false ) const ;
103 
110  double solveWith( ADMMType &admm, double lambda, double* v, double * r ) const ;
112 
117  double solveWith( DualAMAType &dama, double* v, double * r, const bool staticProblem = false ) const ;
118 } ;
119 
121 
129 template< unsigned Dimension >
131 {
133  SYMMETRIC > WType ;
134 
137 
140 
142 
145 
147  Eigen::VectorXd b ;
148 
150  Eigen::VectorXd mu ;
151 
153 
154  void computeFrom( const PrimalFrictionProblem< Dimension >& primal ) ;
155 
157 
163  double solveWith( GaussSeidelType &gs, double * r, const bool staticProblem = false ) const ;
164  double solveWith( ProjectedGradientType &pg, double * r ) const ;
165 
167 
174  double evalWith( const GaussSeidelType &gs, const double * r, const bool staticProblem = false ) const ;
175  double evalWith( const ProjectedGradientType &gs, const double * r ) const ;
176 
178 
186  double solveCadoux( GaussSeidelType &gs, double * r, const unsigned fpIterations,
187  const SignalType* callback = BOGUS_NULL_PTR(const SignalType) ) const ;
188  double solveCadoux( ProjectedGradientType &pg, double * r, const unsigned fpIterations,
189  const SignalType* callback = BOGUS_NULL_PTR(const SignalType) ) const ;
190 
192  double solveCadouxVel( GaussSeidelType &gs, double * u, const unsigned fpIterations,
193  const SignalType* callback = BOGUS_NULL_PTR(const SignalType) ) const ;
194  double solveCadouxVel( ProjectedGradientType &pg, double * u, const unsigned fpIterations,
195  const SignalType* callback = BOGUS_NULL_PTR(const SignalType) ) const ;
196 
197 
199 
204  void applyPermutation( const std::vector< std::size_t > &permutation ) ;
205  void undoPermutation() ;
206  bool permuted() const { return !m_permutation.empty() ; }
207 
208  const std::vector< std::size_t > &permutation() const { return m_permutation ; }
209  const std::vector< std::size_t > &invPermutation() const { return m_invPermutation ; }
210 private:
211 
212  // Current permutation of contact indices
213  std::vector< std::size_t > m_permutation ;
214  std::vector< std::size_t > m_invPermutation ;
215 } ;
216 
217 } //namespace bogus
218 
219 #endif
HType H
H – deformation gradient ( generalized coordinates &lt;-&gt; contact basis coordinates ) ...
Definition: FrictionProblem.hpp:70
const double * mu
Coulomb friction coefficients.
Definition: FrictionProblem.hpp:77
Eigen::VectorXd mu
Coulomb friction coefficients.
Definition: FrictionProblem.hpp:150
void computeMInv()
Definition: PrimalFrictionProblem.cpp:31
double solveCadoux(GaussSeidelType &gs, double *r, const unsigned fpIterations, const SignalType *callback=(static_cast< const SignalType * >(0))) const
Solves this problem using the Cadoux algorithm ( with fixed-point iteration )
Definition: FrictionProblem.cpp:80
double solveWith(ProductGaussSeidelType &pgs, double *r, const bool staticProblem=false) const
Matrix-free Gauss-Seidel solver.
Definition: PrimalFrictionProblem.cpp:45
WType W
W – Delassus operator.
Definition: FrictionProblem.hpp:144
ADMM (Alternating Direction Method of Multipliers ) iterative solver.
Definition: ADMM.hpp:44
Projected Gradient iterative solver.
Definition: ProjectedGradient.hpp:41
MType M
M – mass matrix.
Definition: FrictionProblem.hpp:63
Store only half the matrix, or rather the triangular part for which inner &lt;= outer,.
Definition: Constants.hpp:64
Dual AMA iterative solver (Alternating Minimization Algorithm on dual formuation of quadratic optimiz...
Definition: ADMM.hpp:191
const double * w
Free velocity in world coordinates ( such that u = Hv + E^T w )
Definition: FrictionProblem.hpp:75
double solveCadouxVel(GaussSeidelType &gs, double *u, const unsigned fpIterations, const SignalType *callback=(static_cast< const SignalType * >(0))) const
Idem as solveCadoux, but interpreting the problem as r = Wu + b.
Definition: FrictionProblem.cpp:98
bogus::SparseBlockMatrix< Eigen::Matrix< double, Dimension, Dimension > > E
E – local rotation matrix ( contact basis coordinates to world coordinates )
Definition: FrictionProblem.hpp:65
Eigen::VectorXd b
Rhs ( such that u = Wr + b )
Definition: FrictionProblem.hpp:147
Projected Gauss-Seidel iterative solver.
Definition: GaussSeidel.hpp:43
double solveWith(GaussSeidelType &gs, double *r, const bool staticProblem=false) const
Solves this problem.
Definition: FrictionProblem.cpp:46
void computeFrom(const PrimalFrictionProblem< Dimension > &primal)
Computes this DualFrictionProblem from the given primal.
Definition: FrictionProblem.cpp:32
Signal class, to which an arbitrary number of listeners can be connected.
Definition: Signal.hpp:23
Matrix-free version of the GaussSeidel iterative solver.
Definition: ProductGaussSeidel.hpp:41
Non-smooth laws based on Second Order Cone complementarity. To be used within as the first argument t...
Definition: SecondOrder.fwd.hpp:56
Primal Coulomb friction problem for a block-diagonal mass matrix M with dense blocks.
Definition: FrictionProblem.hpp:57
const double * f
External forces.
Definition: FrictionProblem.hpp:73
SparseBlockMatrix< LU< Eigen::MatrixBase< Eigen::MatrixXd > > > MInvType
M^-1.
Definition: FrictionProblem.hpp:82
Dual representation of a Coulomb friction problem, with explicit Delassus operator.
Definition: FrictionProblem.hpp:130
void applyPermutation(const std::vector< std::size_t > &permutation)
Apply a permutation on the contact indices.
Definition: FrictionProblem.cpp:116
double evalWith(const GaussSeidelType &gs, const double *r, const bool staticProblem=false) const
Evaluate a residual using the GS&#39;s error function.
Definition: FrictionProblem.cpp:64