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  }
100 
105  virtual void setZero(size_t numDof, size_t numConstraintDof, size_t numConstraints);
106 
112  static MlcpProblem Zero(size_t numDof, size_t numConstraintDof, size_t numConstraints);
113 };
114 
115 }; // namespace Math
116 }; // namespace SurgSim
117 
118 #endif // SURGSIM_MATH_MLCPPROBLEM_H
SurgSim::Math::MlcpProblem::Matrix
Eigen::Matrix< double, Eigen::Dynamic, Eigen::Dynamic > Matrix
Definition: MlcpProblem.h:62
MlcpConstraintType.h
SurgSim
Definition: CompoundShapeToGraphics.cpp:30
SurgSim::Math::MlcpProblem::~MlcpProblem
virtual ~MlcpProblem()
Destructor.
Definition: MlcpProblem.cpp:23
SurgSim::Math::MlcpProblem::mu
Vector mu
A vector of friction coefficients used to describe the mixed LCP problem.
Definition: MlcpProblem.h:71
SurgSim::Math::MlcpProblem
A description of an MLCP (mixed linear complementarity problem, or mixed LCP) system to be solved.
Definition: MlcpProblem.h:58
SurgSim::Math::MlcpProblem::Vector
Eigen::Matrix< double, Eigen::Dynamic, 1 > Vector
Definition: MlcpProblem.h:63
SurgSim::Math::MlcpProblem::b
Vector b
Vector used to describe the mixed LCP problem.
Definition: MlcpProblem.h:68
SurgSim::Math::MlcpProblem::constraintTypes
std::vector< MlcpConstraintType > constraintTypes
A vector of constraint types used to describe the mixed LCP problem.
Definition: MlcpProblem.h:74
SurgSim::Math::MlcpProblem::setZero
virtual void setZero(size_t numDof, size_t numConstraintDof, size_t numConstraints)
Resize an MlcpProblem and set to zero.
Definition: MlcpProblem.cpp:27
SurgSim::Math::MlcpProblem::Zero
static MlcpProblem Zero(size_t numDof, size_t numConstraintDof, size_t numConstraints)
Initialize an MlcpProblem with zero values.
Definition: MlcpProblem.cpp:36
SurgSim::Math::MlcpProblem::isConsistent
bool isConsistent() const
Checks if the sizes of various elements of the system are consistent with each other.
Definition: MlcpProblem.h:94
SurgSim::Math::MlcpProblem::getSize
size_t getSize() const
Gets the size of the system.
Definition: MlcpProblem.h:87
SurgSim::Math::MlcpProblem::A
Matrix A
Matrix used to describe the mixed LCP problem.
Definition: MlcpProblem.h:66