opensurgsim
Public Member Functions | Protected Member Functions | List of all members
SurgSim::Physics::LinearSpring Class Reference

Linear spring connecting 2 nodes with a viscous term. More...

#include <LinearSpring.h>

Inheritance diagram for SurgSim::Physics::LinearSpring:
SurgSim::Physics::Spring

Public Member Functions

 LinearSpring (size_t nodeId0, size_t nodeId1)
 Constructor. More...
 
 LinearSpring (const std::shared_ptr< Math::OdeState > state, size_t nodeId0, size_t nodeId1, double stiffness, double damping)
 Constructor. More...
 
 LinearSpring (const std::shared_ptr< MassSpringModel > massSpring, size_t nodeId0, size_t nodeId1, double stiffness, double damping)
 Constructor. More...
 
void initialize (const SurgSim::Math::OdeState &state) override
 Initialize the Spring once everything has been set. More...
 
void setStiffness (double stiffness)
 Sets the spring stiffness parameter. More...
 
double getStiffness () const
 Gets the spring stiffness parameter. More...
 
void setDamping (double damping)
 Sets the spring damping parameter. More...
 
double getDamping () const
 Gets the spring damping parameter. More...
 
void setRestLength (double restLength)
 Sets the rest length of the spring. More...
 
double getRestLength () const
 Gets the rest length of the spring. More...
 
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) More...
 
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 matrix D (assembly) More...
 
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 stiffness matrix K (assembly) More...
 
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 a complete system data structure F, D, K (assembly) More...
 
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) into a complete system data structure F (assembly) More...
 
bool operator== (const Spring &spring) const
 Comparison operator (equality) More...
 
bool operator!= (const Spring &spring) const
 Comparison operator (inequality) More...
 
- Public Member Functions inherited from SurgSim::Physics::Spring
virtual ~Spring ()
 Virtual destructor.
 
size_t getNumNodes () const
 Gets the number of nodes the spring is connecting. More...
 
size_t getNodeId (size_t springNodeId) const
 Gets the springNodeId-th node id. More...
 
const std::vector< size_t > & getNodeIds () const
 Gets the node ids for this spring. More...
 

Protected Member Functions

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 given state, where this spring is defined by its 2 nodes positions {x1, x2}, velocities {v1, v2} and forces {F1, F2=-F1}. More...
 

Additional Inherited Members

- Protected Attributes inherited from SurgSim::Physics::Spring
std::vector< size_t > m_nodeIds
 Node ids connected by this spring.
 

Detailed Description

Linear spring connecting 2 nodes with a viscous term.

Constructor & Destructor Documentation

§ LinearSpring() [1/3]

SurgSim::Physics::LinearSpring::LinearSpring ( size_t  nodeId0,
size_t  nodeId1 
)

Constructor.

Parameters
nodeId0,nodeId1The node ids on which the spring is attached

§ LinearSpring() [2/3]

SurgSim::Physics::LinearSpring::LinearSpring ( const std::shared_ptr< Math::OdeState state,
size_t  nodeId0,
size_t  nodeId1,
double  stiffness,
double  damping 
)
explicit

Constructor.

Parameters
stateThe state to initialize the spring with (rest length calculation)
nodeId0,nodeId1Node ids of the 2 connected masses
stiffness,dampingThe spring parameters

§ LinearSpring() [3/3]

SurgSim::Physics::LinearSpring::LinearSpring ( const std::shared_ptr< MassSpringModel massSpring,
size_t  nodeId0,
size_t  nodeId1,
double  stiffness,
double  damping 
)
explicit

Constructor.

Parameters
massSpringThe MassSpringModel to initialize the spring's rest length with.
nodeId0,nodeId1Node ids of the 2 connected masses
stiffness,dampingThe spring parameters

Member Function Documentation

§ addDamping()

void SurgSim::Physics::LinearSpring::addDamping ( const SurgSim::Math::OdeState state,
SurgSim::Math::SparseMatrix D,
double  scale = 1.0 
)
overridevirtual

Adds the spring damping matrix D (= -df/dv) (computed for a given state) to a complete system damping matrix D (assembly)

Parameters
stateThe state to compute the damping matrix with
[in,out]DThe complete system damping matrix to add the spring damping matrix into
scaleA factor to scale the added damping matrix with

Implements SurgSim::Physics::Spring.

§ addFDK()

void SurgSim::Physics::LinearSpring::addFDK ( const SurgSim::Math::OdeState state,
SurgSim::Math::Vector F,
SurgSim::Math::SparseMatrix D,
SurgSim::Math::SparseMatrix K 
)
overridevirtual

Adds the spring force vector, mass, stiffness and damping matrices (computed for a given state) into a complete system data structure F, D, K (assembly)

Parameters
stateThe state to compute everything with
[in,out]FThe complete system force vector to add the spring force into
[in,out]DThe complete system damping matrix to add the spring damping matrix into
[in,out]KThe complete system stiffness matrix to add the spring stiffness matrix into

Implements SurgSim::Physics::Spring.

§ addForce()

void SurgSim::Physics::LinearSpring::addForce ( const SurgSim::Math::OdeState state,
SurgSim::Math::Vector F,
double  scale = 1.0 
)
overridevirtual

Adds the spring force (computed for a given state) to a complete system force vector F (assembly)

Parameters
stateThe state to compute the force with
[in,out]FThe complete system force vector to add the spring force into
scaleA factor to scale the added force with

Implements SurgSim::Physics::Spring.

§ addMatVec()

void SurgSim::Physics::LinearSpring::addMatVec ( const SurgSim::Math::OdeState state,
double  alphaD,
double  alphaK,
const SurgSim::Math::Vector vector,
SurgSim::Math::Vector F 
)
overridevirtual

Adds the spring matrix-vector contribution F += (alphaD.D + alphaK.K).x (computed for a given state) into a complete system data structure F (assembly)

Parameters
stateThe state to compute everything with
alphaDThe scaling factor for the damping contribution
alphaKThe scaling factor for the stiffness contribution
vectorA complete system vector to use as the vector in the matrix-vector multiplication
[in,out]FThe complete system force vector to add the element matrix-vector contribution into

Implements SurgSim::Physics::Spring.

§ addStiffness()

void SurgSim::Physics::LinearSpring::addStiffness ( const SurgSim::Math::OdeState state,
SurgSim::Math::SparseMatrix K,
double  scale = 1.0 
)
overridevirtual

Adds the spring stiffness matrix K (= -df/dx) (computed for a given state) to a complete system stiffness matrix K (assembly)

Parameters
stateThe state to compute the stiffness matrix with
[in,out]KThe complete system stiffness matrix to add the spring stiffness matrix into
scaleA factor to scale the added stiffness matrix with

Implements SurgSim::Physics::Spring.

§ computeDampingAndStiffness()

bool SurgSim::Physics::LinearSpring::computeDampingAndStiffness ( const SurgSim::Math::OdeState state,
SurgSim::Math::Matrix33d De,
SurgSim::Math::Matrix33d Ke 
)
protected

Compute the stiffness matrix Ke = -dF1/dx1 and damping matrix De = -dF1/dv1 of this spring for a given state, where this spring is defined by its 2 nodes positions {x1, x2}, velocities {v1, v2} and forces {F1, F2=-F1}.

Parameters
stateThe state to compute the jacobians from
[out]De,KeRespectively the damping and stiffness matrices De and Ke
Returns
True if the matrices could be computed, False otherwise (current length is null)
Note
This method calculates only the 3x3 parts related to the force applied on the first node,
derived w.r.t. first node. By nature, we have dF2/dx2 = dF1/dx1 = -dF1/dx2 = -dF2/dx1.

§ getDamping()

double SurgSim::Physics::LinearSpring::getDamping ( ) const

Gets the spring damping parameter.

Returns
The damping assigned to the spring (in N.s.m-1)

§ getRestLength()

double SurgSim::Physics::LinearSpring::getRestLength ( ) const

Gets the rest length of the spring.

Returns
The rest length assigned to the spring (in m)

§ getStiffness()

double SurgSim::Physics::LinearSpring::getStiffness ( ) const

Gets the spring stiffness parameter.

Returns
The stiffness assigned to the spring (in N.m-1)

§ initialize()

void SurgSim::Physics::LinearSpring::initialize ( const SurgSim::Math::OdeState state)
overridevirtual

Initialize the Spring once everything has been set.

Parameters
stateThe state to initialize the Spring with

Reimplemented from SurgSim::Physics::Spring.

§ operator!=()

bool SurgSim::Physics::LinearSpring::operator!= ( const Spring spring) const

Comparison operator (inequality)

Parameters
springSpring to compare it to
Returns
False if the 2 springs contains the same information, true otherwise
Note
Comparison is based on spring type, rest length, stiffness and damping coefficients ONLY

§ operator==()

bool SurgSim::Physics::LinearSpring::operator== ( const Spring spring) const

Comparison operator (equality)

Parameters
springSpring to compare it to
Returns
True if the 2 springs contains the same information, false otherwise
Note
Comparison is based on spring type, rest length, stiffness and damping coefficients ONLY

§ setDamping()

void SurgSim::Physics::LinearSpring::setDamping ( double  damping)

Sets the spring damping parameter.

Parameters
dampingThe damping to assign to the spring (in N.s.m-1)
Exceptions
SurgSim::Framework::AssertionFailuredamping cannot be negative

§ setRestLength()

void SurgSim::Physics::LinearSpring::setRestLength ( double  restLength)

Sets the rest length of the spring.

Parameters
restLengthThe rest length to assign to the spring (in m)
Exceptions
SurgSim::Framework::AssertionFailurerest length cannot be negative

§ setStiffness()

void SurgSim::Physics::LinearSpring::setStiffness ( double  stiffness)

Sets the spring stiffness parameter.

Parameters
stiffnessThe stiffness to assign to the spring (in N.m-1)
Exceptions
SurgSim::Framework::AssertionFailurestiffness cannot be negative

The documentation for this class was generated from the following files: