opensurgsim
Spring.h
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 
76  virtual void addDamping(const SurgSim::Math::OdeState& state, SurgSim::Math::SparseMatrix* D,
77  double scale = 1.0) = 0;
78 
84  virtual void addStiffness(const SurgSim::Math::OdeState& state, SurgSim::Math::SparseMatrix* K,
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
Wraps glewInit() to separate the glew opengl definitions from the osg opengl definitions only imgui n...
Definition: AddRandomSphereBehavior.cpp:36
Eigen::SparseMatrix< double > SparseMatrix
A sparse matrix.
Definition: SparseMatrix.h:32
The state of an ode of 2nd order of the form with boundary conditions.
Definition: OdeState.h:38
std::vector< size_t > m_nodeIds
Node ids connected by this spring.
Definition: Spring.h:108
Definitions of useful sparse matrix functions.
Base class for all springs It handles the node ids to which it is connected and requires all derived ...
Definition: Spring.h:42
Eigen::Matrix< double, Eigen::Dynamic, 1 > Vector
A dynamic size column vector.
Definition: Vector.h:68
Definitions of small fixed-size square matrix types.
Definitions of small fixed-size vector types.