SurgSim::Physics::LinearSpring Class Reference

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

`#include <SurgSim/Physics/LinearSpring.h>`

Inheritance diagram for SurgSim::Physics::LinearSpring:

## Public Member Functions

| LinearSpring (size_t nodeId0, size_t nodeId1)
| 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. More...
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...

## Private Attributes

double | m_restLength
| Rest length (in m) More...
double | m_stiffness
| Stiffness parameters (in N.m-1) More...
double | m_damping
| Damping parameters (in N.s.m-1) More...

## Additional Inherited Members

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

## Detailed Description

Linear spring connecting 2 nodes with a viscous term.

## Constructor & Destructor Documentation

## LinearSpring()

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

Constructor.

Parameters

  nodeId0,nodeId1 | The node ids on which the spring is attached

## Member Function Documentation

## addDamping()

void SurgSim::Physics::LinearSpring::addDamping | ( | const SurgSim::Math::OdeState & | state,
|  | SurgSim::Math::SparseMatrix * | D,
|  | double | scale = `1.0`
| ) |  |

override virtual

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

Parameters

  | state | The state to compute the damping matrix with
  [in,out] | D | The complete system damping matrix to add the spring damping matrix into
  | scale | A 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
| ) |  |

override virtual

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

  | state | The state to compute everything with
  [in,out] | F | The complete system force vector to add the spring force into
  [in,out] | D | The complete system damping matrix to add the spring damping matrix into
  [in,out] | K | The 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`
| ) |  |

override virtual

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

Parameters

  | state | The state to compute the force with
  [in,out] | F | The complete system force vector to add the spring force into
  | scale | A 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
| ) |  |

override virtual

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

  | state | The state to compute everything with
  | alphaD | The scaling factor for the damping contribution
  | alphaK | The scaling factor for the stiffness contribution
  | vector | A complete system vector to use as the vector in the matrix-vector multiplication
  [in,out] | F | The 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`
| ) |  |

override virtual

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

Parameters

  | state | The state to compute the stiffness matrix with
  [in,out] | K | The complete system stiffness matrix to add the spring stiffness matrix into
  | scale | A 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

  | state | The state to compute the jacobians from
  [out] | De,Ke | Respectively 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 | ) |

override virtual

Initialize the Spring once everything has been set.

Parameters

  state | The 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

  spring | Spring 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

  spring | Spring 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

  damping | The damping to assign to the spring (in N.s.m-1)

Exceptions

  SurgSim::Framework::AssertionFailure | damping cannot be negative

## setRestLength()

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

Sets the rest length of the spring.

Parameters

  restLength | The rest length to assign to the spring (in m)

Exceptions

  SurgSim::Framework::AssertionFailure | rest length cannot be negative

## setStiffness()

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

Sets the spring stiffness parameter.

Parameters

  stiffness | The stiffness to assign to the spring (in N.m-1)

Exceptions

  SurgSim::Framework::AssertionFailure | stiffness cannot be negative

## Member Data Documentation

## m_damping

double SurgSim::Physics::LinearSpring::m_damping

private

Damping parameters (in N.s.m-1)

## m_restLength

double SurgSim::Physics::LinearSpring::m_restLength

private

Rest length (in m)

## m_stiffness

double SurgSim::Physics::LinearSpring::m_stiffness

private

Stiffness parameters (in N.m-1)

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

- SurgSim/Physics/LinearSpring.h
- SurgSim/Physics/LinearSpring.cpp