bindings/python/algorithm/contact-cholesky.hpp
Go to the documentation of this file.
1 //
2 // Copyright (c) 2020-2024 INRIA
3 //
4 
5 #ifndef __pinocchio_python_algorithm_contact_cholesky_hpp__
6 #define __pinocchio_python_algorithm_contact_cholesky_hpp__
7 
8 #include <eigenpy/memory.hpp>
10 
13 
18 
20 
21 namespace pinocchio
22 {
23  namespace python
24  {
25  namespace bp = boost::python;
26 
27  template<typename ContactCholeskyDecomposition>
29  : public boost::python::def_visitor<
30  ContactCholeskyDecompositionPythonVisitor<ContactCholeskyDecomposition>>
31  {
36  typedef typename ContactCholeskyDecomposition::Matrix Matrix;
37  typedef typename ContactCholeskyDecomposition::Vector Vector;
39  RigidConstraintModelVector;
41  RigidConstraintDataVector;
42 
45 
46  template<class PyClass>
47  void visit(PyClass & cl) const
48  {
49  cl.def(bp::init<>(bp::arg("self"), "Default constructor."))
50  .def(bp::init<const Model &>(bp::args("self", "model"), "Constructor from a model."))
51  .def(bp::init<const Model &, const RigidConstraintModelVector &>(
52  (bp::arg("self"), bp::arg("model"), bp::arg("contact_models")),
53  "Constructor from a model and a collection of RigidConstraintModels."))
54 
55  .PINOCCHIO_ADD_PROPERTY_READONLY_BYVALUE(Self, U, "")
56  .PINOCCHIO_ADD_PROPERTY_READONLY_BYVALUE(Self, D, "")
57  .PINOCCHIO_ADD_PROPERTY_READONLY_BYVALUE(Self, Dinv, "")
58 
59  .def("size", &Self::size, bp::arg("self"), "Size of the decomposition.")
60  .def(
61  "constraintDim", &Self::constraintDim, bp::arg("self"),
62  "Returns the total dimension of the constraints contained in the Cholesky "
63  "factorization.")
64  .def(
65  "numContacts", &Self::numContacts, bp::arg("self"),
66  "Returns the number of contacts associated to this decomposition.")
67  .def(
68  "matrix", (Matrix(Self::*)(void) const)&Self::matrix, bp::arg("self"),
69  "Returns the matrix resulting from the decomposition.")
70 
71  .def(
72  "compute",
73  (void (*)(
74  Self & self, const Model &, Data &, const RigidConstraintModelVector &,
75  RigidConstraintDataVector &, const Scalar))&compute,
76  (bp::arg("self"), bp::arg("model"), bp::arg("data"), bp::arg("contact_models"),
77  bp::arg("contact_datas"), bp::arg("mu") = 0),
78  "Computes the Cholesky decompostion of the augmented matrix containing the KKT matrix\n"
79  "related to the system mass matrix and the Jacobians of the contact patches contained "
80  "in\n"
81  "the vector of RigidConstraintModel named contact_models. The decomposition is "
82  "regularized with a factor mu.")
83 
84  .def(
85  "compute",
86  (void (*)(
87  Self & self, const Model &, Data &, const RigidConstraintModelVector &,
88  RigidConstraintDataVector &, const Vector &))&compute,
89  (bp::arg("self"), bp::arg("model"), bp::arg("data"), bp::arg("contact_models"),
90  bp::arg("contact_datas"), bp::arg("mus")),
91  "Computes the Cholesky decompostion of the augmented matrix containing the KKT matrix\n"
92  "related to the system mass matrix and the Jacobians of the contact patches contained "
93  "in\n"
94  "the vector of RigidConstraintModel named contact_models. The decomposition is "
95  "regularized with a factor mu.")
96 
97  .def(
98  "updateDamping", (void(Self::*)(const Scalar &)) & Self::updateDamping,
99  bp::args("self", "mu"),
100  "Update the damping term on the upper left block part of the KKT matrix. The "
101  "damping term should be positive.")
102 
103  .def(
104  "updateDamping", &Self::template updateDamping<Vector>, bp::args("self", "mus"),
105  "Update the damping terms on the upper left block part of the KKT matrix. The "
106  "damping terms should be all positives.")
107 
108  .def(
109  "getInverseOperationalSpaceInertiaMatrix",
110  (Matrix(Self::*)(void) const)&Self::getInverseOperationalSpaceInertiaMatrix,
111  bp::arg("self"),
112  "Returns the Inverse of the Operational Space Inertia Matrix resulting from the "
113  "decomposition.",
114  bp::return_value_policy<bp::return_by_value>())
115 
116  .def(
117  "getOperationalSpaceInertiaMatrix",
118  (Matrix(Self::*)(void) const)&Self::getOperationalSpaceInertiaMatrix, bp::arg("self"),
119  "Returns the Operational Space Inertia Matrix resulting from the decomposition.",
120  bp::return_value_policy<bp::return_by_value>())
121 
122  .def(
123  "getInverseMassMatrix", (Matrix(Self::*)(void) const)&Self::getInverseMassMatrix,
124  bp::arg("self"),
125  "Returns the inverse of the Joint Space Inertia Matrix or \"mass matrix\".",
126  bp::return_value_policy<bp::return_by_value>())
127 
128  .def(
129  "solve", &solve<Matrix>, bp::args("self", "matrix"),
130  "Computes the solution of \f$ A x = b \f$ where self corresponds to the Cholesky "
131  "decomposition of A.",
132  bp::return_value_policy<bp::return_by_value>())
133 
134  .def(
135  "inverse", (Matrix(Self::*)(void) const)&Self::inverse, bp::arg("self"),
136  "Returns the inverse matrix resulting from the decomposition.")
137 
138  .def(
139  "getMassMatrixChoeslkyDecomposition",
140  &Self::template getMassMatrixChoeslkyDecomposition<
142  bp::arg("self"),
143  "Retrieves the Cholesky decomposition of the Mass Matrix contained in the current "
144  "decomposition.")
145 
146  .def(
147  "getDelassusCholeskyExpression", &Self::getDelassusCholeskyExpression, bp::arg("self"),
148  "Returns the Cholesky decomposition expression associated to the underlying "
149  "Delassus matrix.",
150  bp::with_custodian_and_ward_postcall<0, 1>())
151 
153  }
154 
155  static void expose()
156  {
157  bp::class_<ContactCholeskyDecomposition>(
158  "ContactCholeskyDecomposition",
159  "Contact information container for contact dynamic algorithms.", bp::no_init)
162 
163  {
164  typedef typename ContactCholeskyDecomposition::DelassusCholeskyExpression
165  DelassusCholeskyExpression;
166 
167  bp::class_<DelassusCholeskyExpression>(
168  "DelassusCholeskyExpression",
169  "Delassus Cholesky expression associated to a "
170  "given ContactCholeskyDecomposition object.",
171  bp::no_init)
172  .def(bp::init<const ContactCholeskyDecomposition &>(
173  bp::args("self", "cholesky_decomposition"),
174  "Build from a given ContactCholeskyDecomposition object.")
175  [bp::with_custodian_and_ward<1, 2>()])
176  .def(
177  "cholesky",
178  +[](const DelassusCholeskyExpression & self) -> ContactCholeskyDecomposition & {
179  return const_cast<ContactCholeskyDecomposition &>(self.cholesky());
180  },
181  bp::arg("self"),
182  "Returns the Constraint Cholesky decomposition associated to this "
183  "DelassusCholeskyExpression.",
184  bp::return_internal_reference<>())
185 
187  }
188 
189  {
191  bp::class_<DelassusOperatorDense>(
192  "DelassusOperatorDense", "Delassus Cholesky dense operator from a dense matrix.",
193  bp::no_init)
194  .def(bp::init<const Eigen::Ref<const context::MatrixXs>>(
195  bp::args("self", "matrix"), "Build from a given dense matrix"))
196 
198  }
199 
200  {
203  bp::class_<DelassusOperatorSparse, boost::noncopyable>(
204  "DelassusOperatorSparse", "Delassus Cholesky sparse operator from a sparse matrix.",
205  bp::no_init)
206  .def(bp::init<const context::SparseMatrix &>(
207  bp::args("self", "matrix"), "Build from a given sparse matrix"))
208 
210  }
211 #ifdef PINOCCHIO_WITH_ACCELERATE_SUPPORT
212  {
213  typedef Eigen::AccelerateLLT<context::SparseMatrix> AccelerateCholeskyDecomposition;
215  context::Scalar, context::Options, AccelerateCholeskyDecomposition>
216  DelassusOperatorSparseAccelerate;
217  bp::class_<DelassusOperatorSparseAccelerate, boost::noncopyable>(
218  "DelassusOperatorSparseAccelerate",
219  "Delassus Cholesky sparse operator leveraging the Accelerate framework on APPLE "
220  "systems.",
221  bp::no_init)
222  .def(bp::init<const context::SparseMatrix &>(
223  bp::args("self", "matrix"), "Build from a given sparse matrix"))
224 
226  }
227 #endif
228  }
229 
230  template<typename MatrixType>
231  static Matrix solve(const Self & self, const MatrixType & mat)
232  {
233  return self.solve(mat);
234  }
235 
236  static void compute(
237  Self & self,
238  const Model & model,
239  Data & data,
240  const RigidConstraintModelVector & contact_models,
241  RigidConstraintDataVector & contact_datas,
242  const Scalar mu = static_cast<Scalar>(0))
243  {
244  self.compute(model, data, contact_models, contact_datas, mu);
245  }
246 
247  static void compute(
248  Self & self,
249  const Model & model,
250  Data & data,
251  const RigidConstraintModelVector & contact_models,
252  RigidConstraintDataVector & contact_datas,
253  const Vector & mus)
254  {
255  self.compute(model, data, contact_models, contact_datas, mus);
256  }
257  };
258 
259  } // namespace python
260 } // namespace pinocchio
261 
262 #endif // ifndef __pinocchio_python_algorithm_contact_cholesky_hpp__
pinocchio::RigidConstraintData
RigidConstraintDataTpl< context::Scalar, context::Options > RigidConstraintData
Definition: algorithm/fwd.hpp:27
init
void init(bool compute_local_aabb=true)
boost::python
pinocchio::DataTpl
Definition: context/generic.hpp:25
contact-cholesky.hpp
delassus-operator-sparse.hpp
pinocchio::python::ContactCholeskyDecompositionPythonVisitor::Self
ContactCholeskyDecomposition Self
Definition: bindings/python/algorithm/contact-cholesky.hpp:32
pinocchio::python::ContactCholeskyDecompositionPythonVisitor
Definition: bindings/python/algorithm/contact-cholesky.hpp:28
pinocchio::python::ContactCholeskyDecompositionPythonVisitor::Model
pinocchio::python::context::Model Model
Definition: bindings/python/algorithm/contact-cholesky.hpp:43
pinocchio::python::ContactCholeskyDecompositionPythonVisitor::Scalar
ContactCholeskyDecomposition::Scalar Scalar
Definition: bindings/python/algorithm/contact-cholesky.hpp:33
pinocchio::python::ContactCholeskyDecompositionPythonVisitor::RigidConstraintData
ContactCholeskyDecomposition::RigidConstraintData RigidConstraintData
Definition: bindings/python/algorithm/contact-cholesky.hpp:35
setup.data
data
Definition: cmake/cython/setup.in.py:48
pinocchio::DelassusOperatorSparseTpl
Definition: delassus-operator-sparse.hpp:127
pinocchio::DelassusOperatorSparse
DelassusOperatorSparseTpl< context::Scalar, context::Options > DelassusOperatorSparse
Definition: algorithm/fwd.hpp:36
pinocchio::python::Scalar
context::Scalar Scalar
Definition: admm-solver.cpp:29
pinocchio::python::ContactCholeskyDecompositionPythonVisitor::compute
static void compute(Self &self, const Model &model, Data &data, const RigidConstraintModelVector &contact_models, RigidConstraintDataVector &contact_datas, const Vector &mus)
Definition: bindings/python/algorithm/contact-cholesky.hpp:247
pinocchio::python::ComparableVisitor
Add the Python method == and != to allow a comparison of this.
Definition: comparable.hpp:21
def
void def(const char *name, Func func)
pinocchio::python::ContactCholeskyDecompositionPythonVisitor::expose
static void expose()
Definition: bindings/python/algorithm/contact-cholesky.hpp:155
simulation-contact-dynamics.contact_datas
list contact_datas
Definition: simulation-contact-dynamics.py:60
pinocchio::python::DelassusOperatorBasePythonVisitor
Definition: delassus-operator.hpp:18
pinocchio::python::ContactCholeskyDecompositionPythonVisitor::visit
void visit(PyClass &cl) const
Definition: bindings/python/algorithm/contact-cholesky.hpp:47
comparable.hpp
pinocchio::python::ContactCholeskyDecompositionPythonVisitor::Data
pinocchio::python::context::Data Data
Definition: bindings/python/algorithm/contact-cholesky.hpp:44
python
mat
mat
D
D
pinocchio::is_floating_point
Definition: math/fwd.hpp:17
size
FCL_REAL size() const
pinocchio::python::CopyableVisitor
Add the Python method copy to allow a copy of this by calling the copy constructor.
Definition: copyable.hpp:21
pinocchio::python::ContactCholeskyDecompositionPythonVisitor::compute
static void compute(Self &self, const Model &model, Data &data, const RigidConstraintModelVector &contact_models, RigidConstraintDataVector &contact_datas, const Scalar mu=static_cast< Scalar >(0))
Definition: bindings/python/algorithm/contact-cholesky.hpp:236
pinocchio::inverse
void inverse(const Eigen::MatrixBase< MatrixIn > &m_in, const Eigen::MatrixBase< MatrixOut > &dest)
Definition: math/matrix.hpp:273
pinocchio::python::ContactCholeskyDecompositionPythonVisitor::PINOCCHIO_STD_VECTOR_WITH_EIGEN_ALLOCATOR
typedef PINOCCHIO_STD_VECTOR_WITH_EIGEN_ALLOCATOR(RigidConstraintModel) RigidConstraintModelVector
pinocchio::python::ContactCholeskyDecompositionPythonVisitor::solve
static Matrix solve(const Self &self, const MatrixType &mat)
Definition: bindings/python/algorithm/contact-cholesky.hpp:231
copyable.hpp
pinocchio::python::context::Options
@ Options
Definition: bindings/python/context/generic.hpp:40
macros.hpp
mu
double mu
Definition: delassus.cpp:58
ocp.U
U
Definition: ocp.py:80
pinocchio::python::ContactCholeskyDecompositionPythonVisitor::Matrix
ContactCholeskyDecomposition::Matrix Matrix
Definition: bindings/python/algorithm/contact-cholesky.hpp:36
delassus-operator-dense.hpp
pinocchio::python::ContactCholeskyDecompositionPythonVisitor::RigidConstraintModel
ContactCholeskyDecomposition::RigidConstraintModel RigidConstraintModel
Definition: bindings/python/algorithm/contact-cholesky.hpp:34
cl
cl
memory.hpp
pinocchio::DelassusOperatorDenseTpl
Definition: delassus-operator-dense.hpp:29
pinocchio::RigidConstraintModel
RigidConstraintModelTpl< context::Scalar, context::Options > RigidConstraintModel
Definition: algorithm/fwd.hpp:24
contact-cholesky.contact_models
list contact_models
Definition: contact-cholesky.py:22
std-vector.hpp
pinocchio::ContactCholeskyDecompositionTpl< context::Scalar, context::Options >
pinocchio::JointCollectionDefaultTpl
Definition: context/generic.hpp:15
pinocchio::ModelTpl
Definition: context/generic.hpp:20
delassus-operator.hpp
pinocchio::python::ContactCholeskyDecompositionPythonVisitor::Vector
ContactCholeskyDecomposition::Vector Vector
Definition: bindings/python/algorithm/contact-cholesky.hpp:37
pinocchio::python::context::Scalar
PINOCCHIO_PYTHON_SCALAR_TYPE Scalar
Definition: bindings/python/context/generic.hpp:37
pinocchio::model
JointCollectionTpl & model
Definition: joint-configuration.hpp:1082
pinocchio
Main pinocchio namespace.
Definition: timings.cpp:27
pinocchio::DelassusOperatorDense
DelassusOperatorDenseTpl< context::Scalar, context::Options > DelassusOperatorDense
Definition: algorithm/fwd.hpp:30


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