All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
OdeState.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_ODESTATE_H
17 #define SURGSIM_MATH_ODESTATE_H
18 
19 #include <memory>
20 
21 #include "SurgSim/Math/Matrix.h"
22 #include "SurgSim/Math/Vector.h"
23 
24 namespace SurgSim
25 {
26 
27 namespace Math
28 {
29 
34 class OdeState
35 {
36 public:
38  OdeState();
39 
41  ~OdeState();
42 
46  bool operator ==(const OdeState& state) const;
47 
51  bool operator !=(const OdeState& state) const;
52 
55  void reset();
56 
61  void setNumDof(size_t numDofPerNode, size_t numNodes);
62 
65  size_t getNumDof() const;
66 
69  size_t getNumNodes() const;
70 
74 
77  const SurgSim::Math::Vector& getPositions() const;
78 
83  const SurgSim::Math::Vector3d getPosition(size_t nodeId) const;
84 
88 
91  const SurgSim::Math::Vector& getVelocities() const;
92 
97  const SurgSim::Math::Vector3d getVelocity(size_t nodeId) const;
98 
101  void addBoundaryCondition(size_t nodeId);
102 
106  void addBoundaryCondition(size_t nodeId, size_t nodeDofId);
107 
110  size_t getNumBoundaryConditions() const;
111 
114  const std::vector<size_t>& getBoundaryConditions() const;
115 
120  bool isBoundaryCondition(size_t dof) const;
121 
126 
133  void applyBoundaryConditionsToMatrix(Matrix* matrix, bool hasCompliance = true) const;
134 
137  bool isValid() const;
138 
139 private:
141 
144 
147 
150 
152  std::vector<size_t> m_boundaryConditionsAsDofIds;
153 
155  Eigen::Matrix<bool, Eigen::Dynamic, 1> m_boundaryConditionsPerDof;
156 };
157 
158 }; // namespace Math
159 
160 }; // namespace SurgSim
161 
162 #endif // SURGSIM_MATH_ODESTATE_H
size_t m_numDofPerNode
Default public copy constructor and assignment operator are being used on purpose.
Definition: OdeState.h:143
size_t m_numNodes
Definition: OdeState.h:143
std::vector< size_t > m_boundaryConditionsAsDofIds
Boundary conditions stored as a list of dof ids.
Definition: OdeState.h:152
void reset()
Resets the state.
Definition: OdeState.cpp:45
SurgSim::Math::Vector m_v
Degrees of freedom velocity (m_x 1st derivative w.r.t. time)
Definition: OdeState.h:149
SurgSim::Math::Vector & getVelocities()
Retrieves all degrees of freedom's velocity (non-const version)
Definition: OdeState.cpp:98
Eigen::Matrix< bool, Eigen::Dynamic, 1 > m_boundaryConditionsPerDof
Boundary conditions stored per dof (True indicates a boundary condition, False does not) ...
Definition: OdeState.h:155
size_t getNumNodes() const
Retrieves the number of nodes.
Definition: OdeState.cpp:78
SurgSim::Math::Vector m_x
Degrees of freedom position.
Definition: OdeState.h:146
Eigen::Matrix< double, Eigen::Dynamic, Eigen::Dynamic > Matrix
A dynamic size matrix.
Definition: Matrix.h:65
void applyBoundaryConditionsToMatrix(Matrix *matrix, bool hasCompliance=true) const
Apply boundary conditions to a given matrix.
Definition: OdeState.cpp:170
~OdeState()
Destructor.
Definition: OdeState.cpp:31
OdeState defines the state y of an ode of 2nd order of the form M(x,v).a = F(x, v) with boundary cond...
Definition: OdeState.h:34
const std::vector< size_t > & getBoundaryConditions() const
Retrieves all boundary conditions.
Definition: OdeState.cpp:145
bool operator==(const OdeState &state) const
Comparison operator (equality test)
Definition: OdeState.cpp:35
const SurgSim::Math::Vector3d getPosition(size_t nodeId) const
Retrieves the position of a given node (const version)
Definition: OdeState.cpp:93
Eigen::Matrix< double, Eigen::Dynamic, 1 > Vector
A dynamic size column vector.
Definition: Vector.h:67
bool isBoundaryCondition(size_t dof) const
Queries if a specific dof is a boundary condition or not.
Definition: OdeState.cpp:150
Vector * applyBoundaryConditionsToVector(Vector *vector) const
Apply boundary conditions to a given vector.
Definition: OdeState.cpp:155
bool operator!=(const OdeState &state) const
Comparison operator (difference test)
Definition: OdeState.cpp:40
bool isValid() const
Check if this state is numerically valid.
Definition: OdeState.cpp:194
Definitions of small fixed-size square matrix types.
Definitions of small fixed-size vector types.
size_t getNumBoundaryConditions() const
Retrieves the number of boundary conditions.
Definition: OdeState.cpp:140
void addBoundaryCondition(size_t nodeId)
Adds boundary conditions for a given node (fixes all the dof for this node)
Definition: OdeState.cpp:113
void setNumDof(size_t numDofPerNode, size_t numNodes)
Allocates the state for a given number of degrees of freedom.
Definition: OdeState.cpp:53
OdeState()
Default constructor.
Definition: OdeState.cpp:27
SurgSim::Math::Vector & getPositions()
Retrieves all degrees of freedom's position (non-const version)
Definition: OdeState.cpp:83
Eigen::Matrix< double, 3, 1 > Vector3d
A 3D vector of doubles.
Definition: Vector.h:56
size_t getNumDof() const
Retrieves the number of degrees of freedom.
Definition: OdeState.cpp:68
const SurgSim::Math::Vector3d getVelocity(size_t nodeId) const
Retrieves the velocity of a given node (const version)
Definition: OdeState.cpp:108