All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
MlcpProblem.h
Go to the documentation of this file.
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_MLCPPROBLEM_H
17 #define SURGSIM_MATH_MLCPPROBLEM_H
18 
19 #include <vector>
20 #include <Eigen/Core>
22 
23 
24 namespace SurgSim
25 {
26 namespace Math
27 {
28 
54 //
55 // TODO(advornik): Describe the approach to friction in more detail.
56 // TODO(advornik): Get rid of the constraint types and encode necessary info in other ways.
58 {
60  virtual ~MlcpProblem();
61 
62  typedef Eigen::Matrix<double, Eigen::Dynamic, Eigen::Dynamic> Matrix;
63  typedef Eigen::Matrix<double, Eigen::Dynamic, 1> Vector;
64 
74  std::vector<MlcpConstraintType> constraintTypes;
75 
76  // NB: We let the compiler generate the default code for the constructor, copy constructor and copy assignment,
77  // because we currently sometimes need to copy the problem (although we ought to minimize this).
78  // The C++11-ish way to indicate that explicitly would be to write code like this:
79  // MlcpProblem() = default;
80  // MlcpProblem(const MlcpProblem& other) = default;
81  // MlcpProblem& operator= (const MlcpProblem& other) = default;
82  // but I haven't yet tested that this works correctly on VS 2010, so I'm just putting in the comment.
83  // We may also want to add move construction and move assignment. --advornik 2013-06-24
84 
87  size_t getSize() const
88  {
89  return (b.rows() >= 0) ? static_cast<size_t>(b.rows()) : 0;
90  }
91 
94  bool isConsistent() const
95  {
96  size_t numConstraintTypes = constraintTypes.size();
97  return ((b.rows() >= 0) && (b.cols() == 1) && (A.rows() == b.rows()) && (A.cols() == A.rows())
98  && (numConstraintTypes <= static_cast<size_t>(b.rows())) && (mu.size() >= 0)
99  && (static_cast<size_t>(mu.size()) == numConstraintTypes));
100  }
101 
106  virtual void setZero(size_t numDof, size_t numConstraintDof, size_t numConstraints);
107 
113  static MlcpProblem Zero(size_t numDof, size_t numConstraintDof, size_t numConstraints);
114 };
115 
116 }; // namespace Math
117 }; // namespace SurgSim
118 
119 #endif // SURGSIM_MATH_MLCPPROBLEM_H
Eigen::Matrix< double, Eigen::Dynamic, 1 > Vector
Definition: MlcpProblem.h:63
Matrix A
Matrix used to describe the mixed LCP problem.
Definition: MlcpProblem.h:66
virtual void setZero(size_t numDof, size_t numConstraintDof, size_t numConstraints)
Resize an MlcpProblem and set to zero.
Definition: MlcpProblem.cpp:27
bool isConsistent() const
Checks if the sizes of various elements of the system are consistent with each other.
Definition: MlcpProblem.h:94
size_t getSize() const
Gets the size of the system.
Definition: MlcpProblem.h:87
Eigen::Matrix< double, Eigen::Dynamic, Eigen::Dynamic > Matrix
Definition: MlcpProblem.h:62
static MlcpProblem Zero(size_t numDof, size_t numConstraintDof, size_t numConstraints)
Initialize an MlcpProblem with zero values.
Definition: MlcpProblem.cpp:39
std::vector< MlcpConstraintType > constraintTypes
A vector of constraint types used to describe the mixed LCP problem.
Definition: MlcpProblem.h:74
Vector b
Vector used to describe the mixed LCP problem.
Definition: MlcpProblem.h:68
A description of an MLCP (mixed linear complementarity problem, or mixed LCP) system to be solved...
Definition: MlcpProblem.h:57
Vector mu
A vector of friction coefficients used to describe the mixed LCP problem.
Definition: MlcpProblem.h:71
virtual ~MlcpProblem()
Destructor.
Definition: MlcpProblem.cpp:23