Spring.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_PHYSICS_SPRING_H
17 #define SURGSIM_PHYSICS_SPRING_H
18 
19 #include <vector>
20 
21 #include "SurgSim/Math/Matrix.h"
23 #include "SurgSim/Math/Vector.h"
24 
25 namespace SurgSim
26 {
27 
28 namespace Math
29 {
30 class OdeState;
31 };
32 
33 namespace Physics
34 {
35 
42 class Spring
43 {
44 public:
46  virtual ~Spring();
47 
50  virtual void initialize(const SurgSim::Math::OdeState& state);
51 
54  size_t getNumNodes() const;
55 
58  size_t getNodeId(size_t springNodeId) const;
59 
62  const std::vector<size_t>& getNodeIds() const;
63 
68  virtual void addForce(const SurgSim::Math::OdeState& state, SurgSim::Math::Vector* F,
69  double scale = 1.0) = 0;
70 
77  double scale = 1.0) = 0;
78 
85  double scale = 1.0) = 0;
86 
93  virtual void addFDK(const SurgSim::Math::OdeState& state, SurgSim::Math::Vector* F,
95 
103  virtual void addMatVec(const SurgSim::Math::OdeState& state, double alphaD, double alphaK,
105 
106 protected:
108  std::vector<size_t> m_nodeIds;
109 };
110 
111 } // namespace Physics
112 
113 } // namespace SurgSim
114 
115 #endif // SURGSIM_PHYSICS_SPRING_H
SurgSim::Physics::Spring::~Spring
virtual ~Spring()
Virtual destructor.
Definition: Spring.cpp:23
SurgSim::Physics::Spring::addStiffness
virtual void addStiffness(const SurgSim::Math::OdeState &state, SurgSim::Math::SparseMatrix *K, double scale=1.0)=0
Adds the spring stiffness matrix K (= -df/dx) (computed for a given state) to a complete system stiff...
Vector.h
SurgSim::Math::OdeState
The state of an ode of 2nd order of the form with boundary conditions.
Definition: OdeState.h:38
SurgSim::Physics::Spring
Base class for all springs It handles the node ids to which it is connected and requires all derived ...
Definition: Spring.h:42
SurgSim::Physics::Spring::addFDK
virtual void addFDK(const SurgSim::Math::OdeState &state, SurgSim::Math::Vector *F, SurgSim::Math::SparseMatrix *D, SurgSim::Math::SparseMatrix *K)=0
Adds the spring force vector, mass, stiffness and damping matrices (computed for a given state) into ...
Matrix.h
SparseMatrix.h
SurgSim
Definition: CompoundShapeToGraphics.cpp:29
SurgSim::Physics::Spring::addForce
virtual void addForce(const SurgSim::Math::OdeState &state, SurgSim::Math::Vector *F, double scale=1.0)=0
Adds the spring force (computed for a given state) to a complete system force vector F (assembly)
SurgSim::Physics::Spring::addDamping
virtual void addDamping(const SurgSim::Math::OdeState &state, SurgSim::Math::SparseMatrix *D, double scale=1.0)=0
Adds the spring damping matrix D (= -df/dv) (computed for a given state) to a complete system damping...
SurgSim::Physics::Spring::getNodeIds
const std::vector< size_t > & getNodeIds() const
Gets the node ids for this spring.
Definition: Spring.cpp:40
SurgSim::Math::SparseMatrix
Eigen::SparseMatrix< double > SparseMatrix
A sparse matrix.
Definition: SparseMatrix.h:32
SurgSim::Physics::Spring::initialize
virtual void initialize(const SurgSim::Math::OdeState &state)
Initialize the Spring once everything has been set.
Definition: Spring.cpp:26
SurgSim::Physics::Spring::getNumNodes
size_t getNumNodes() const
Gets the number of nodes the spring is connecting.
Definition: Spring.cpp:30
SurgSim::Physics::Spring::m_nodeIds
std::vector< size_t > m_nodeIds
Node ids connected by this spring.
Definition: Spring.h:108
SurgSim::Math::Vector
Eigen::Matrix< double, Eigen::Dynamic, 1 > Vector
A dynamic size column vector.
Definition: Vector.h:68
SurgSim::Physics::Spring::getNodeId
size_t getNodeId(size_t springNodeId) const
Gets the springNodeId-th node id.
Definition: Spring.cpp:35
SurgSim::Physics::Spring::addMatVec
virtual void addMatVec(const SurgSim::Math::OdeState &state, double alphaD, double alphaK, const SurgSim::Math::Vector &x, SurgSim::Math::Vector *F)=0
Adds the spring matrix-vector contribution F += (alphaD.D + alphaK.K).x (computed for a given state) ...