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"
22 #include "SurgSim/Math/Vector.h"
23 
24 namespace SurgSim
25 {
26 
27 namespace Math
28 {
29 class OdeState;
30 };
31 
32 namespace Physics
33 {
34 
41 class Spring
42 {
43 public:
45  virtual ~Spring()
46  {}
47 
50  size_t getNumNodes() const
51  {
52  return m_nodeIds.size();
53  }
54 
57  size_t getNodeId(size_t springNodeId) const
58  {
59  return m_nodeIds[springNodeId];
60  }
61 
64  const std::vector<size_t>& getNodeIds() const
65  {
66  return m_nodeIds;
67  }
68 
73  virtual void addForce(const SurgSim::Math::OdeState& state, SurgSim::Math::Vector* F,
74  double scale = 1.0) = 0;
75 
81  virtual void addDamping(const SurgSim::Math::OdeState& state, SurgSim::Math::Matrix* D,
82  double scale = 1.0) = 0;
83 
89  virtual void addStiffness(const SurgSim::Math::OdeState& state, SurgSim::Math::Matrix* K,
90  double scale = 1.0) = 0;
91 
98  virtual void addFDK(const SurgSim::Math::OdeState& state, SurgSim::Math::Vector* F,
100 
108  virtual void addMatVec(const SurgSim::Math::OdeState& state, double alphaD, double alphaK,
110 
111 protected:
113  std::vector<size_t> m_nodeIds;
114 };
115 
116 } // namespace Physics
117 
118 } // namespace SurgSim
119 
120 #endif // SURGSIM_PHYSICS_SPRING_H
Definition: DriveElementFromInputBehavior.cpp:27
Eigen::Matrix< double, Eigen::Dynamic, Eigen::Dynamic > Matrix
A dynamic size matrix.
Definition: Matrix.h:65
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
std::vector< size_t > m_nodeIds
Node ids connected by this spring.
Definition: Spring.h:113
Eigen::Matrix< double, Eigen::Dynamic, 1 > Vector
A dynamic size column vector.
Definition: Vector.h:67
Base class for all springs It handles the node ids to which it is connected and requires all derived ...
Definition: Spring.h:41
Definitions of small fixed-size square matrix types.
Definitions of small fixed-size vector types.
size_t getNumNodes() const
Gets the number of nodes the spring is connecting.
Definition: Spring.h:50
const std::vector< size_t > & getNodeIds() const
Gets the node ids for this spring.
Definition: Spring.h:64
virtual ~Spring()
Virtual destructor.
Definition: Spring.h:45
size_t getNodeId(size_t springNodeId) const
Gets the springNodeId-th node id.
Definition: Spring.h:57