opensurgsim
MlcpGaussSeidelSolver.h
1 // This file is a part of the OpenSurgSim project.
2 // Copyright 2013, SimQuest Solutions Inc.
3 //
4 // Licensed under the Apache License, Version 2.0 (the "License");
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
7 //
8 // http://www.apache.org/licenses/LICENSE-2.0
9 //
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an "AS IS" BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
15 
16 #ifndef SURGSIM_MATH_MLCPGAUSSSEIDELSOLVER_H
17 #define SURGSIM_MATH_MLCPGAUSSSEIDELSOLVER_H
18 
19 #include <memory.h>
20 
21 #include "SurgSim/Math/Matrix.h"
22 #include "SurgSim/Math/MlcpProblem.h"
23 #include "SurgSim/Math/MlcpSolver.h"
24 #include "SurgSim/Math/MlcpSolution.h"
25 #include "SurgSim/Math/Vector.h"
26 
27 namespace SurgSim
28 {
29 namespace Framework
30 {
31 class Logger;
32 }
33 
34 namespace Math
35 {
36 
54 {
55 public:
58 
63  MlcpGaussSeidelSolver(double epsilonConvergence, double contactTolerance, size_t maxIterations);
64 
66  virtual ~MlcpGaussSeidelSolver();
67 
72  bool solve(const MlcpProblem& problem, MlcpSolution* solution);
73 
75  double getEpsilonConvergence() const;
76 
79  void setEpsilonConvergence(double precision);
80 
82  double getContactTolerance() const;
83 
86  void setContactTolerance(double tolerance);
87 
89  size_t getMaxIterations() const;
90 
93  void setMaxIterations(size_t maxIterations);
94 
95 private:
96  void computeEnforcementSystem(size_t problemSize, const MlcpProblem::Matrix& A,
97  const MlcpProblem::Vector& b,
98  const MlcpSolution::Vector& initialGuessAndSolution,
99  const std::vector<MlcpConstraintType>& constraintsType,
100  size_t constraintID, size_t matrixEntryForConstraintID);
101 
102  void calculateConvergenceCriteria(size_t problemSize, const MlcpProblem::Matrix& A,
103  const MlcpProblem::Vector& b,
104  const MlcpSolution::Vector& initialGuessAndSolution,
105  const std::vector<MlcpConstraintType>& constraintsType,
106  double constraintConvergenceCriteria[MLCP_NUM_CONSTRAINT_TYPES],
107  double* convergenceCriteria,
108  bool* validSignorini);
109 
110  void doOneIteration(size_t problemSize, const MlcpProblem::Matrix& A,
111  const MlcpProblem::Vector& b,
112  MlcpSolution::Vector* initialGuessAndSolution,
113  const MlcpProblem::Vector& frictionCoefs,
114  const std::vector<MlcpConstraintType>& constraintsType,
115  double constraintConvergenceCriteria[MLCP_NUM_CONSTRAINT_TYPES], double* convergenceCriteria,
116  bool* validSignorini);
117 
118  void printViolationsAndConvergence(size_t problemSize, const MlcpProblem::Matrix& A,
119  const MlcpProblem::Vector& b,
120  const MlcpSolution::Vector& initialGuessAndSolution,
121  const std::vector<MlcpConstraintType>& constraintsType,
122  double convergenceCriteria,
123  bool validSignorini, size_t iterations);
124 
126  double m_epsilonConvergence;
127 
129  double m_contactTolerance;
130 
132  size_t m_maxIterations;
133 
135  size_t m_numEnforcedAtomicConstraints;
136 
138  Matrix m_lhsEnforcedLocalSystem;
139 
141  Vector m_rhsEnforcedLocalSystem;
142 
144  std::shared_ptr<SurgSim::Framework::Logger> m_logger;
145 };
146 
147 }; // namespace Math
148 }; // namespace SurgSim
149 
150 #endif // SURGSIM_MATH_MLCPGAUSSSEIDELSOLVER_H
Wraps glewInit() to separate the glew opengl definitions from the osg opengl definitions only imgui n...
Definition: AddRandomSphereBehavior.cpp:36
A solver for mixed LCP problems using the Gauss-Seidel iterative method.
Definition: MlcpGaussSeidelSolver.h:53
Eigen::Matrix< double, Eigen::Dynamic, 1 > Vector
A dynamic size column vector.
Definition: Vector.h:68
The description of a solution to a mixed linear complementarity problem.
Definition: MlcpSolution.h:33
This class provides a solver interface for mixed linear complementarity problems. ...
Definition: MlcpSolver.h:30
Definitions of small fixed-size square matrix types.
Definitions of small fixed-size vector types.
A description of an MLCP (mixed linear complementarity problem, or mixed LCP) system to be solved...
Definition: MlcpProblem.h:57
Eigen::Matrix< double, Eigen::Dynamic, Eigen::Dynamic > Matrix
A dynamic size matrix.
Definition: Matrix.h:65