LinearSpring.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_LINEARSPRING_H
17 #define SURGSIM_PHYSICS_LINEARSPRING_H
18 
19 #include "SurgSim/Physics/Spring.h"
20 
21 namespace SurgSim
22 {
23 
24 namespace Physics
25 {
26 
28 class LinearSpring : public Spring
29 {
30 public:
33  LinearSpring(size_t nodeId0, size_t nodeId1);
34 
35  void initialize(const SurgSim::Math::OdeState& state) override;
36 
40  void setStiffness(double stiffness);
41 
44  double getStiffness() const;
45 
49  void setDamping(double damping);
50 
53  double getDamping() const;
54 
58  void setRestLength(double restLength);
59 
62  double getRestLength() const;
63 
68  void addForce(const SurgSim::Math::OdeState& state, SurgSim::Math::Vector* F, double scale = 1.0) override;
69 
75  void addDamping(const SurgSim::Math::OdeState& state, SurgSim::Math::SparseMatrix* D, double scale = 1.0) override;
76 
83  double scale = 1.0) override;
84 
93 
101  void addMatVec(const SurgSim::Math::OdeState& state, double alphaD, double alphaK,
102  const SurgSim::Math::Vector& vector, SurgSim::Math::Vector* F) override;
103 
108  bool operator ==(const Spring& spring) const;
109 
114  bool operator !=(const Spring& spring) const;
115 
116 protected:
127 
128 private:
130  double m_restLength;
131 
133  double m_stiffness;
134 
136  double m_damping;
137 };
138 
139 }; // namespace Physics
140 
141 }; // namespace SurgSim
142 
143 #endif // SURGSIM_PHYSICS_LINEARSPRING_H
double getStiffness() const
Gets the spring stiffness parameter.
Definition: LinearSpring.cpp:56
Definition: CompoundShapeToGraphics.cpp:29
double getRestLength() const
Gets the rest length of the spring.
Definition: LinearSpring.cpp:78
void addFDK(const SurgSim::Math::OdeState &state, SurgSim::Math::Vector *F, SurgSim::Math::SparseMatrix *D, SurgSim::Math::SparseMatrix *K) override
Adds the spring force vector, mass, stiffness and damping matrices (computed for a given state) into ...
Definition: LinearSpring.cpp:174
double getDamping() const
Gets the spring damping parameter.
Definition: LinearSpring.cpp:67
double m_damping
Damping parameters (in N.s.m-1)
Definition: LinearSpring.h:136
void setRestLength(double restLength)
Sets the rest length of the spring.
Definition: LinearSpring.cpp:72
void addForce(const SurgSim::Math::OdeState &state, SurgSim::Math::Vector *F, double scale=1.0) override
Adds the spring force (computed for a given state) to a complete system force vector F (assembly) ...
Definition: LinearSpring.cpp:83
bool operator!=(const Spring &spring) const
Comparison operator (inequality)
Definition: LinearSpring.cpp:308
LinearSpring(size_t nodeId0, size_t nodeId1)
Constructor.
Definition: LinearSpring.cpp:35
void addDamping(const SurgSim::Math::OdeState &state, SurgSim::Math::SparseMatrix *D, double scale=1.0) override
Adds the spring damping matrix D (= -df/dv) (computed for a given state) to a complete system damping...
Definition: LinearSpring.cpp:108
The state of an ode of 2nd order of the form with boundary conditions.
Definition: OdeState.h:38
double m_stiffness
Stiffness parameters (in N.m-1)
Definition: LinearSpring.h:133
void initialize(const SurgSim::Math::OdeState &state) override
Initialize the Spring once everything has been set.
Definition: LinearSpring.cpp:42
Eigen::Matrix< double, Eigen::Dynamic, 1 > Vector
A dynamic size column vector.
Definition: Vector.h:68
Eigen::SparseMatrix< double > SparseMatrix
A sparse matrix.
Definition: SparseMatrix.h:32
Base class for all springs It handles the node ids to which it is connected and requires all derived ...
Definition: Spring.h:42
double m_restLength
Rest length (in m)
Definition: LinearSpring.h:130
void addStiffness(const SurgSim::Math::OdeState &state, SurgSim::Math::SparseMatrix *K, double scale=1.0) override
Adds the spring stiffness matrix K (= -df/dx) (computed for a given state) to a complete system stiff...
Definition: LinearSpring.cpp:141
Linear spring connecting 2 nodes with a viscous term.
Definition: LinearSpring.h:28
bool operator==(const Spring &spring) const
Comparison operator (equality)
Definition: LinearSpring.cpp:297
Eigen::Matrix< double, 3, 3, Eigen::RowMajor > Matrix33d
A 3x3 matrix of doubles.
Definition: Matrix.h:51
void setStiffness(double stiffness)
Sets the spring stiffness parameter.
Definition: LinearSpring.cpp:50
bool computeDampingAndStiffness(const SurgSim::Math::OdeState &state, SurgSim::Math::Matrix33d *De, SurgSim::Math::Matrix33d *Ke)
Compute the stiffness matrix Ke = -dF1/dx1 and damping matrix De = -dF1/dv1 of this spring for a give...
Definition: LinearSpring.cpp:259
void setDamping(double damping)
Sets the spring damping parameter.
Definition: LinearSpring.cpp:61
void addMatVec(const SurgSim::Math::OdeState &state, double alphaD, double alphaK, const SurgSim::Math::Vector &vector, SurgSim::Math::Vector *F) override
Adds the spring matrix-vector contribution F += (alphaD.D + alphaK.K).x (computed for a given state) ...
Definition: LinearSpring.cpp:226