delassus-operator-dense.hpp
Go to the documentation of this file.
1 //
2 // Copyright (c) 2024 INRIA
3 //
4 
5 #ifndef __pinocchio_algorithm_delassus_operator_dense_hpp__
6 #define __pinocchio_algorithm_delassus_operator_dense_hpp__
7 
10 
11 namespace pinocchio
12 {
13 
14  template<typename _Scalar, int _Options>
15  struct traits<DelassusOperatorDenseTpl<_Scalar, _Options>>
16  {
17  typedef _Scalar Scalar;
18  enum
19  {
20  Options = _Options,
21  RowsAtCompileTime = Eigen::Dynamic
22  };
23 
24  typedef Eigen::Matrix<Scalar, Eigen::Dynamic, Eigen::Dynamic, Options> Matrix;
25  typedef Eigen::Matrix<Scalar, Eigen::Dynamic, 1, Options> Vector;
26  };
27 
28  template<typename _Scalar, int _Options>
30  : DelassusOperatorBase<DelassusOperatorDenseTpl<_Scalar, _Options>>
31  {
32  typedef _Scalar Scalar;
34  enum
35  {
36  Options = _Options,
38  };
39 
40  typedef typename traits<Self>::Matrix Matrix;
41  typedef typename traits<Self>::Vector Vector;
42  typedef Eigen::LLT<Matrix> CholeskyDecomposition;
44 
45  template<typename MatrixDerived>
46  explicit DelassusOperatorDenseTpl(const Eigen::MatrixBase<MatrixDerived> & mat)
47  : Base(mat.rows())
49  , mat_tmp(mat.rows(), mat.cols())
50  , llt(mat)
51  , damping(Vector::Zero(mat.rows()))
52  {
53  PINOCCHIO_CHECK_ARGUMENT_SIZE(mat.rows(), mat.cols());
54  }
55 
56  template<typename VectorLike>
57  void updateDamping(const Eigen::MatrixBase<VectorLike> & vec)
58  {
59  damping = vec;
61  mat_tmp += vec.asDiagonal();
62  llt.compute(mat_tmp);
63  }
64 
65  void updateDamping(const Scalar & mu)
66  {
67  updateDamping(Vector::Constant(size(), mu));
68  }
69 
70  template<typename MatrixLike>
71  void solveInPlace(const Eigen::MatrixBase<MatrixLike> & mat) const
72  {
73  llt.solveInPlace(mat.const_cast_derived());
74  }
75 
76  template<typename MatrixLike>
77  typename PINOCCHIO_EIGEN_PLAIN_TYPE(MatrixLike)
78  solve(const Eigen::MatrixBase<MatrixLike> & mat) const
79  {
80  typename PINOCCHIO_EIGEN_PLAIN_TYPE(MatrixLike) res(mat);
82  return res;
83  }
84 
85  template<typename MatrixDerivedIn, typename MatrixDerivedOut>
86  void solve(
87  const Eigen::MatrixBase<MatrixDerivedIn> & x,
88  const Eigen::MatrixBase<MatrixDerivedOut> & res) const
89  {
90  res.const_cast_derived() = x;
91  solveInPlace(res.const_cast_derived());
92  }
93 
94  template<typename MatrixIn, typename MatrixOut>
95  void applyOnTheRight(
96  const Eigen::MatrixBase<MatrixIn> & x, const Eigen::MatrixBase<MatrixOut> & res_) const
97  {
98  MatrixOut & res = res_.const_cast_derived();
99  res.noalias() = delassus_matrix * x;
100  res.array() += damping.array() * x.array();
101  }
102 
103  template<typename MatrixDerived>
104  typename PINOCCHIO_EIGEN_PLAIN_TYPE(MatrixDerived)
105  operator*(const Eigen::MatrixBase<MatrixDerived> & x) const
106  {
107  typedef typename PINOCCHIO_EIGEN_PLAIN_TYPE(MatrixDerived) ReturnType;
108 
110  ReturnType res(x.rows(), x.cols());
111  applyOnTheRight(x, res);
112  return res;
113  }
114 
115  Eigen::DenseIndex size() const
116  {
117  return delassus_matrix.rows();
118  }
119  Eigen::DenseIndex rows() const
120  {
121  return delassus_matrix.rows();
122  }
123  Eigen::DenseIndex cols() const
124  {
125  return delassus_matrix.cols();
126  }
127 
128  Matrix matrix() const
129  {
131  mat_tmp += damping.asDiagonal();
132  return mat_tmp;
133  }
134 
135  Matrix inverse() const
136  {
137  Matrix res = Matrix::Identity(size(), size());
138  llt.solveInPlace(res);
139  return res;
140  }
141 
142  protected:
144  mutable Matrix mat_tmp;
147 
148  }; // struct DelassusOperatorDenseTpl
149 
150 } // namespace pinocchio
151 
152 #endif // ifndef __pinocchio_algorithm_delassus_operator_dense_hpp__
PINOCCHIO_CHECK_ARGUMENT_SIZE
#define PINOCCHIO_CHECK_ARGUMENT_SIZE(...)
Macro to check if the size of an element is equal to the expected size.
Definition: include/pinocchio/macros.hpp:216
pinocchio::DelassusOperatorDenseTpl::Self
DelassusOperatorDenseTpl Self
Definition: delassus-operator-dense.hpp:33
pinocchio::DelassusOperatorDenseTpl::Vector
traits< Self >::Vector Vector
Definition: delassus-operator-dense.hpp:41
pinocchio::DelassusOperatorDenseTpl::llt
CholeskyDecomposition llt
Definition: delassus-operator-dense.hpp:145
pinocchio::DelassusOperatorDenseTpl::updateDamping
void updateDamping(const Eigen::MatrixBase< VectorLike > &vec)
Definition: delassus-operator-dense.hpp:57
pinocchio::DelassusOperatorBase
Definition: delassus-operator-base.hpp:15
delassus-operator-base.hpp
pinocchio::Options
Options
Definition: joint-configuration.hpp:1082
pinocchio::traits< DelassusOperatorDenseTpl< _Scalar, _Options > >::Vector
Eigen::Matrix< Scalar, Eigen::Dynamic, 1, Options > Vector
Definition: delassus-operator-dense.hpp:25
pinocchio::DelassusOperatorDenseTpl::Matrix
traits< Self >::Matrix Matrix
Definition: delassus-operator-dense.hpp:40
pinocchio::DelassusOperatorDenseTpl::DelassusOperatorDenseTpl
DelassusOperatorDenseTpl(const Eigen::MatrixBase< MatrixDerived > &mat)
Definition: delassus-operator-dense.hpp:46
rows
int rows
vec
vec
pinocchio::res
ReturnType res
Definition: spatial/classic-acceleration.hpp:57
pinocchio::operator*
TridiagonalSymmetricMatrixApplyOnTheLeftReturnType< LhsMatrixType, TridiagonalSymmetricMatrixTpl< S, O > > operator*(const Eigen::MatrixBase< LhsMatrixType > &lhs, const TridiagonalSymmetricMatrixTpl< S, O > &rhs)
Definition: math/tridiagonal-matrix.hpp:319
pinocchio::DelassusOperatorBase< DelassusOperatorDenseTpl< _Scalar, _Options > >::PINOCCHIO_EIGEN_PLAIN_TYPE
PINOCCHIO_EIGEN_PLAIN_TYPE(MatrixLike) solve(const Eigen
Definition: delassus-operator-base.hpp:125
pinocchio::DelassusOperatorDenseTpl::Options
@ Options
Definition: delassus-operator-dense.hpp:36
pinocchio::traits< DelassusOperatorDenseTpl< _Scalar, _Options > >::Scalar
_Scalar Scalar
Definition: delassus-operator-dense.hpp:17
pinocchio::cholesky::solve
Mat & solve(const ModelTpl< Scalar, Options, JointCollectionTpl > &model, const DataTpl< Scalar, Options, JointCollectionTpl > &data, const Eigen::MatrixBase< Mat > &y)
Return the solution of using the Cholesky decomposition stored in data given the entry ....
pinocchio::DelassusOperatorDenseTpl::damping
Vector damping
Definition: delassus-operator-dense.hpp:146
pinocchio::Dynamic
const int Dynamic
Definition: fwd.hpp:140
mat
mat
size
FCL_REAL size() const
x
x
pinocchio::inverse
void inverse(const Eigen::MatrixBase< MatrixIn > &m_in, const Eigen::MatrixBase< MatrixOut > &dest)
Definition: math/matrix.hpp:273
pinocchio::DelassusOperatorDenseTpl::Base
DelassusOperatorBase< Self > Base
Definition: delassus-operator-dense.hpp:43
contact-cholesky.delassus_matrix
delassus_matrix
Definition: contact-cholesky.py:40
pinocchio::DelassusOperatorDenseTpl::updateDamping
void updateDamping(const Scalar &mu)
Definition: delassus-operator-dense.hpp:65
mu
double mu
Definition: delassus.cpp:58
pinocchio::DelassusOperatorDenseTpl::mat_tmp
PINOCCHIO_EIGEN_PLAIN_TYPE(MatrixLike) solve(const Eigen Matrix mat_tmp
Definition: delassus-operator-dense.hpp:77
pinocchio::DelassusOperatorDenseTpl::Scalar
_Scalar Scalar
Definition: delassus-operator-dense.hpp:32
pinocchio::DelassusOperatorDenseTpl::CholeskyDecomposition
Eigen::LLT< Matrix > CholeskyDecomposition
Definition: delassus-operator-dense.hpp:42
fwd.hpp
pinocchio::DelassusOperatorDenseTpl
Definition: delassus-operator-dense.hpp:29
cols
int cols
pinocchio::traits
Common traits structure to fully define base classes for CRTP.
Definition: fwd.hpp:71
pinocchio::traits< DelassusOperatorDenseTpl< _Scalar, _Options > >::Matrix
Eigen::Matrix< Scalar, Eigen::Dynamic, Eigen::Dynamic, Options > Matrix
Definition: delassus-operator-dense.hpp:24
pinocchio::DelassusOperatorDenseTpl::RowsAtCompileTime
@ RowsAtCompileTime
Definition: delassus-operator-dense.hpp:37
pinocchio
Main pinocchio namespace.
Definition: timings.cpp:27
pinocchio::DelassusOperatorDenseTpl::solveInPlace
void solveInPlace(const Eigen::MatrixBase< MatrixLike > &mat) const
Definition: delassus-operator-dense.hpp:71


pinocchio
Author(s):
autogenerated on Sun Dec 22 2024 03:41:09