LinearSpring.h
Go to the documentation of this file.
// This file is a part of the OpenSurgSim project.
// Copyright 2013, SimQuest Solutions Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#ifndef SURGSIM_PHYSICS_LINEARSPRING_H
#define SURGSIM_PHYSICS_LINEARSPRING_H
#include "SurgSim/Physics/Spring.h"
namespace SurgSim
{
namespace Physics
{
class LinearSpring : public Spring
{
public:
LinearSpring(size_t nodeId0, size_t nodeId1);
void initialize(const SurgSim::Math::OdeState& state) override;
void setStiffness(double stiffness);
double getStiffness() const;
void setDamping(double damping);
double getDamping() const;
void setRestLength(double restLength);
double getRestLength() const;
void addForce(const SurgSim::Math::OdeState& state, SurgSim::Math::Vector* F, double scale = 1.0) override;
void addDamping(const SurgSim::Math::OdeState& state, SurgSim::Math::SparseMatrix* D, double scale = 1.0) override;
void addStiffness(const SurgSim::Math::OdeState& state, SurgSim::Math::SparseMatrix* K,
double scale = 1.0) override;
void addFDK(const SurgSim::Math::OdeState& state, SurgSim::Math::Vector* F,
SurgSim::Math::SparseMatrix* D, SurgSim::Math::SparseMatrix* K) override;
void addMatVec(const SurgSim::Math::OdeState& state, double alphaD, double alphaK,
const SurgSim::Math::Vector& vector, SurgSim::Math::Vector* F) override;
bool operator ==(const Spring& spring) const;
bool operator !=(const Spring& spring) const;
protected:
bool computeDampingAndStiffness(const SurgSim::Math::OdeState& state,
SurgSim::Math::Matrix33d* De,
SurgSim::Math::Matrix33d* Ke);
private:
double m_restLength;
double m_stiffness;
double m_damping;
};
}; // namespace Physics
}; // namespace SurgSim
#endif // SURGSIM_PHYSICS_LINEARSPRING_H
SurgSim::Physics::LinearSpring::getStiffness
double getStiffness() const
Gets the spring stiffness parameter.
Definition: LinearSpring.cpp:56
SurgSim
Definition: CompoundShapeToGraphics.cpp:29
SurgSim::Physics::LinearSpring::getRestLength
double getRestLength() const
Gets the rest length of the spring.
Definition: LinearSpring.cpp:78
SurgSim::Physics::LinearSpring::addFDK
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
SurgSim::Physics::LinearSpring::getDamping
double getDamping() const
Gets the spring damping parameter.
Definition: LinearSpring.cpp:67
SurgSim::Physics::LinearSpring::m_damping
double m_damping
Damping parameters (in N.s.m-1)
Definition: LinearSpring.h:136
Spring.h
SurgSim::Physics::LinearSpring::setRestLength
void setRestLength(double restLength)
Sets the rest length of the spring.
Definition: LinearSpring.cpp:72
SurgSim::Physics::LinearSpring::addForce
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
SurgSim::Physics::LinearSpring::operator!=
bool operator!=(const Spring &spring) const
Comparison operator (inequality)
Definition: LinearSpring.cpp:308
SurgSim::Physics::LinearSpring::LinearSpring
LinearSpring(size_t nodeId0, size_t nodeId1)
Constructor.
Definition: LinearSpring.cpp:35
SurgSim::Physics::LinearSpring::addDamping
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
SurgSim::Math::OdeState
The state of an ode of 2nd order of the form with boundary conditions.
Definition: OdeState.h:38
SurgSim::Physics::LinearSpring::m_stiffness
double m_stiffness
Stiffness parameters (in N.m-1)
Definition: LinearSpring.h:133
SurgSim::Physics::LinearSpring::initialize
void initialize(const SurgSim::Math::OdeState &state) override
Initialize the Spring once everything has been set.
Definition: LinearSpring.cpp:42
SurgSim::Math::Vector
Eigen::Matrix< double, Eigen::Dynamic, 1 > Vector
A dynamic size column vector.
Definition: Vector.h:68
SurgSim::Math::SparseMatrix
Eigen::SparseMatrix< double > SparseMatrix
A sparse matrix.
Definition: SparseMatrix.h:32
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::LinearSpring::m_restLength
double m_restLength
Rest length (in m)
Definition: LinearSpring.h:130
SurgSim::Physics::LinearSpring::addStiffness
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
SurgSim::Physics::LinearSpring
Linear spring connecting 2 nodes with a viscous term.
Definition: LinearSpring.h:28
SurgSim::Physics::LinearSpring::operator==
bool operator==(const Spring &spring) const
Comparison operator (equality)
Definition: LinearSpring.cpp:297
SurgSim::Math::Matrix33d
Eigen::Matrix< double, 3, 3, Eigen::RowMajor > Matrix33d
A 3x3 matrix of doubles.
Definition: Matrix.h:51
SurgSim::Physics::LinearSpring::setStiffness
void setStiffness(double stiffness)
Sets the spring stiffness parameter.
Definition: LinearSpring.cpp:50
SurgSim::Physics::LinearSpring::computeDampingAndStiffness
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
SurgSim::Physics::LinearSpring::setDamping
void setDamping(double damping)
Sets the spring damping parameter.
Definition: LinearSpring.cpp:61
SurgSim::Physics::LinearSpring::addMatVec
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