opensurgsim
OdeState.h
1 // This file is a part of the OpenSurgSim project.
2 // Copyright 2013-2016, 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"
23 #include "SurgSim/Math/Vector.h"
24 
25 namespace SurgSim
26 {
27 
28 namespace Math
29 {
30 
38 class OdeState
39 {
40 public:
42  OdeState();
43 
45  virtual ~OdeState();
46 
50  bool operator ==(const OdeState& state) const;
51 
55  bool operator !=(const OdeState& state) const;
56 
59  virtual void reset();
60 
65  virtual void setNumDof(size_t numDofPerNode, size_t numNodes);
66 
69  size_t getNumDof() const;
70 
73  size_t getNumNodes() const;
74 
78 
81  const SurgSim::Math::Vector& getPositions() const;
82 
87  const SurgSim::Math::Vector3d getPosition(size_t nodeId) const;
88 
92 
95  const SurgSim::Math::Vector& getVelocities() const;
96 
101  const SurgSim::Math::Vector3d getVelocity(size_t nodeId) const;
102 
105  void addBoundaryCondition(size_t nodeId);
106 
110  void addBoundaryCondition(size_t nodeId, size_t nodeDofId);
111 
114  size_t getNumBoundaryConditions() const;
115 
118  const std::vector<size_t>& getBoundaryConditions() const;
119 
124  bool isBoundaryCondition(size_t dof) const;
125 
131 
138  void applyBoundaryConditionsToMatrix(Matrix* matrix, bool hasCompliance = true) const;
139 
146  void applyBoundaryConditionsToMatrix(SparseMatrix* matrix, bool hasCompliance = true) const;
147 
155  void addBoundaryConditionStaticDof(size_t nodeId, double value);
156 
158  size_t getNumBoundaryConditionsStaticDof() const;
159 
161  const std::vector<std::pair<size_t, double>>& getBoundaryConditionsStaticDof() const;
162 
167  void setBoundaryConditionsStaticDof(const std::vector<std::pair<size_t, double>>& staticDof);
168 
173  void changeBoundaryConditionStaticDof(size_t nodeId, double value);
174 
177  virtual bool isValid() const;
178 
185  OdeState interpolate(const OdeState& other, double t) const;
186 
187 private:
189 
191  size_t m_numDofPerNode, m_numNodes;
192 
195 
198 
200  std::vector<size_t> m_boundaryConditionsAsDofIds;
201 
203  Eigen::Matrix<bool, Eigen::Dynamic, 1> m_boundaryConditionsPerDof;
204 
206  std::vector<std::pair<size_t, double>> m_boundaryConditionsStaticDof;
207 };
208 
209 }; // namespace Math
210 
211 }; // namespace SurgSim
212 
213 #endif // SURGSIM_MATH_ODESTATE_H
Wraps glewInit() to separate the glew opengl definitions from the osg opengl definitions only imgui n...
Definition: AddRandomSphereBehavior.cpp:36
virtual void reset()
Resets the state.
Definition: OdeState.cpp:46
void applyBoundaryConditionsToMatrix(Matrix *matrix, bool hasCompliance=true) const
Apply boundary conditions to a given matrix.
Definition: OdeState.cpp:174
SurgSim::Math::Vector & getVelocities()
Retrieves all degrees of freedom&#39;s velocity (non-const version)
Definition: OdeState.cpp:100
bool operator!=(const OdeState &state) const
Comparison operator (difference test)
Definition: OdeState.cpp:41
size_t getNumNodes() const
Retrieves the number of nodes.
Definition: OdeState.cpp:80
Eigen::SparseMatrix< double > SparseMatrix
A sparse matrix.
Definition: SparseMatrix.h:32
void changeBoundaryConditionStaticDof(size_t nodeId, double value)
Set the value of an existing boundary condition on a static dof.
Definition: OdeState.cpp:240
size_t getNumBoundaryConditionsStaticDof() const
Definition: OdeState.cpp:230
virtual ~OdeState()
Destructor.
Definition: OdeState.cpp:31
Eigen::Matrix< double, 3, 1 > Vector3d
A 3D vector of doubles.
Definition: Vector.h:57
The state of an ode of 2nd order of the form with boundary conditions.
Definition: OdeState.h:38
virtual bool isValid() const
Check if this state is numerically valid.
Definition: OdeState.cpp:268
Definitions of useful sparse matrix functions.
bool operator==(const OdeState &state) const
Comparison operator (equality test)
Definition: OdeState.cpp:35
void setBoundaryConditionsStaticDof(const std::vector< std::pair< size_t, double >> &staticDof)
Set all boundary conditions on static dofs.
Definition: OdeState.cpp:250
size_t getNumDof() const
Retrieves the number of degrees of freedom.
Definition: OdeState.cpp:70
size_t getNumBoundaryConditions() const
Retrieves the number of boundary conditions.
Definition: OdeState.cpp:144
Eigen::Matrix< double, Eigen::Dynamic, 1 > Vector
A dynamic size column vector.
Definition: Vector.h:68
const std::vector< std::pair< size_t, double > > & getBoundaryConditionsStaticDof() const
Definition: OdeState.cpp:235
Definitions of small fixed-size square matrix types.
OdeState interpolate(const OdeState &other, double t) const
Returns the linear interpolated ODE state between this and other at parameter t.
Definition: OdeState.cpp:280
Definitions of small fixed-size vector types.
const SurgSim::Math::Vector3d getVelocity(size_t nodeId) const
Retrieves the velocity of a given node (const version)
Definition: OdeState.cpp:110
Vector * applyBoundaryConditionsToVector(Vector *vector) const
Apply boundary conditions to a given vector.
Definition: OdeState.cpp:159
const std::vector< size_t > & getBoundaryConditions() const
Retrieves all boundary conditions.
Definition: OdeState.cpp:149
void addBoundaryCondition(size_t nodeId)
Adds boundary conditions for a given node (fixes all the dof for this node)
Definition: OdeState.cpp:115
virtual void setNumDof(size_t numDofPerNode, size_t numNodes)
Allocates the state for a given number of degrees of freedom.
Definition: OdeState.cpp:55
OdeState()
Default constructor.
Definition: OdeState.cpp:27
Eigen::Matrix< double, Eigen::Dynamic, Eigen::Dynamic > Matrix
A dynamic size matrix.
Definition: Matrix.h:65
SurgSim::Math::Vector & getPositions()
Retrieves all degrees of freedom&#39;s position (non-const version)
Definition: OdeState.cpp:85
const SurgSim::Math::Vector3d getPosition(size_t nodeId) const
Retrieves the position of a given node (const version)
Definition: OdeState.cpp:95
void addBoundaryConditionStaticDof(size_t nodeId, double value)
Adds a boundary condition on the static dof of a given node (we consider here that each node has a si...
Definition: OdeState.cpp:220
bool isBoundaryCondition(size_t dof) const
Queries if a specific dof is a boundary condition or not.
Definition: OdeState.cpp:154