pinocchio  3.2.0
A fast and flexible implementation of Rigid Body Dynamics algorithms and their analytical derivatives
contact-solver-base.hpp
1 //
2 // Copyright (c) 2022-2024 INRIA
3 //
4 
5 #ifndef __pinocchio_algorithm_contact_solver_base_hpp__
6 #define __pinocchio_algorithm_contact_solver_base_hpp__
7 
8 #include "pinocchio/math/fwd.hpp"
9 #include "pinocchio/math/comparison-operators.hpp"
10 
11 #ifdef PINOCCHIO_WITH_HPP_FCL
12  #include <hpp/fcl/timings.h>
13 #endif // PINOCCHIO_WITH_HPP_FCL
14 
15 namespace pinocchio
16 {
17 
18  template<typename _Scalar>
20  {
21  typedef _Scalar Scalar;
22 
23 #ifdef PINOCCHIO_WITH_HPP_FCL
24  typedef hpp::fcl::CPUTimes CPUTimes;
25  typedef hpp::fcl::Timer Timer;
26 #endif // PINOCCHIO_WITH_HPP_FCL
27 
28  explicit ContactSolverBaseTpl(const int problem_size)
30  , max_it(1000)
31  , it(0)
32  , absolute_precision(Scalar(1e-6))
33  , relative_precision(Scalar(1e-6))
34  , absolute_residual(Scalar(-1))
35  , relative_residual(Scalar(-1))
36 #ifdef PINOCCHIO_WITH_HPP_FCL
37  , timer(false)
38 #endif // PINOCCHIO_WITH_HPP_FCL
39  {
40  }
41 
43  int getProblemSize() const
44  {
45  return problem_size;
46  }
47 
49  int getIterationCount() const
50  {
51  return it;
52  }
53 
55  void setMaxIterations(const int max_it)
56  {
57  PINOCCHIO_CHECK_INPUT_ARGUMENT(max_it > 0, "max_it should be greater than 0.");
58  this->max_it = max_it;
59  }
61  int getMaxIterations() const
62  {
63  return max_it;
64  }
65 
68  {
69  PINOCCHIO_CHECK_INPUT_ARGUMENT(
70  absolute_precision >= Scalar(0), "absolute_precision should be positive.");
71  this->absolute_precision = absolute_precision;
72  }
74  Scalar getAbsolutePrecision() const
75  {
76  return absolute_precision;
77  }
78 
81  {
82  PINOCCHIO_CHECK_INPUT_ARGUMENT(
83  relative_precision >= Scalar(0), "relative_precision should be positive.");
84  this->relative_precision = relative_precision;
85  }
87  Scalar getRelativePrecision() const
88  {
89  return relative_precision;
90  }
91 
95  {
96  return absolute_residual;
97  }
101  {
102  return relative_residual;
103  }
104 
105 #ifdef PINOCCHIO_WITH_HPP_FCL
106  CPUTimes getCPUTimes() const
107  {
108  return timer.elapsed();
109  }
110 #endif // PINOCCHIO_WITH_HPP_FCL
111 
112  protected:
116  int max_it;
118  int it;
127 
128 #ifdef PINOCCHIO_WITH_HPP_FCL
129  Timer timer;
130 #endif // PINOCCHIO_WITH_HPP_FCL
131 
132  }; // struct ContactSolverBaseTpl
133 
134 } // namespace pinocchio
135 
136 #endif // ifndef __pinocchio_algorithm_contact_solver_base_hpp__
Main pinocchio namespace.
Definition: treeview.dox:11
void setAbsolutePrecision(const Scalar absolute_precision)
Set the absolute precision for the problem.
Scalar getAbsolutePrecision() const
Get the absolute precision requested.
int it
Number of iterations needed to achieve convergence.
int getMaxIterations() const
Get the maximum number of iterations allowed.
Scalar getRelativeConvergenceResidual() const
Returns the value of the relative residual value corresponding to the difference between two successi...
Scalar relative_precision
Desired relative precision.
Scalar getAbsoluteConvergenceResidual() const
Returns the value of the absolute residual value corresponding to the contact complementary condition...
int problem_size
Size of the problem.
Scalar absolute_precision
Desired absolute precision.
int getProblemSize() const
Returns the size of the problem.
Scalar getRelativePrecision() const
Get the relative precision requested.
int getIterationCount() const
Get the number of iterations achieved by the solver.
Scalar relative_residual
Relative convergence residual value.
Scalar absolute_residual
Absolule convergence residual value.
void setMaxIterations(const int max_it)
Set the maximum number of iterations.
void setRelativePrecision(const Scalar relative_precision)
Set the relative precision for the problem.