opensurgsim
|
Linear spring connecting 2 nodes with a viscous term. More...
#include <LinearSpring.h>
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... | |
![]() | |
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 | |
![]() | |
std::vector< size_t > | m_nodeIds |
Node ids connected by this spring. | |
Linear spring connecting 2 nodes with a viscous term.
SurgSim::Physics::LinearSpring::LinearSpring | ( | size_t | nodeId0, |
size_t | nodeId1 | ||
) |
Constructor.
nodeId0,nodeId1 | The node ids on which the spring is attached |
|
explicit |
Constructor.
state | The state to initialize the spring with (rest length calculation) |
nodeId0,nodeId1 | Node ids of the 2 connected masses |
stiffness,damping | The spring parameters |
|
explicit |
Constructor.
massSpring | The MassSpringModel to initialize the spring's rest length with. |
nodeId0,nodeId1 | Node ids of the 2 connected masses |
stiffness,damping | The spring parameters |
|
overridevirtual |
Adds the spring damping matrix D (= -df/dv) (computed for a given state) to a complete system damping matrix D (assembly)
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.
|
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)
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.
|
overridevirtual |
Adds the spring force (computed for a given state) to a complete system force vector F (assembly)
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.
|
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)
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.
|
overridevirtual |
Adds the spring stiffness matrix K (= -df/dx) (computed for a given state) to a complete system stiffness matrix K (assembly)
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.
|
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}.
state | The state to compute the jacobians from | |
[out] | De,Ke | Respectively the damping and stiffness matrices De and Ke |
double SurgSim::Physics::LinearSpring::getDamping | ( | ) | const |
Gets the spring damping parameter.
double SurgSim::Physics::LinearSpring::getRestLength | ( | ) | const |
Gets the rest length of the spring.
double SurgSim::Physics::LinearSpring::getStiffness | ( | ) | const |
Gets the spring stiffness parameter.
|
overridevirtual |
Initialize the Spring once everything has been set.
state | The state to initialize the Spring with |
Reimplemented from SurgSim::Physics::Spring.
bool SurgSim::Physics::LinearSpring::operator!= | ( | const Spring & | spring | ) | const |
Comparison operator (inequality)
spring | Spring to compare it to |
bool SurgSim::Physics::LinearSpring::operator== | ( | const Spring & | spring | ) | const |
Comparison operator (equality)
spring | Spring to compare it to |
void SurgSim::Physics::LinearSpring::setDamping | ( | double | damping | ) |
Sets the spring damping parameter.
damping | The damping to assign to the spring (in N.s.m-1) |
SurgSim::Framework::AssertionFailure | damping cannot be negative |
void SurgSim::Physics::LinearSpring::setRestLength | ( | double | restLength | ) |
Sets the rest length of the spring.
restLength | The rest length to assign to the spring (in m) |
SurgSim::Framework::AssertionFailure | rest length cannot be negative |
void SurgSim::Physics::LinearSpring::setStiffness | ( | double | stiffness | ) |
Sets the spring stiffness parameter.
stiffness | The stiffness to assign to the spring (in N.m-1) |
SurgSim::Framework::AssertionFailure | stiffness cannot be negative |