MassSpringRepresentation.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_MASSSPRINGREPRESENTATION_H
#define SURGSIM_PHYSICS_MASSSPRINGREPRESENTATION_H
#include <memory>
#include "SurgSim/Physics/DeformableRepresentation.h"
#include "SurgSim/Physics/Mass.h"
#include "SurgSim/Physics/Spring.h"
#include "SurgSim/Math/Vector.h"
#include "SurgSim/Math/Matrix.h"
namespace SurgSim
{
namespace Physics
{
class MassSpringRepresentation : public DeformableRepresentation
{
public:
explicit MassSpringRepresentation(const std::string& name);
virtual ~MassSpringRepresentation();
void addMass(const std::shared_ptr<Mass> mass);
void addSpring(const std::shared_ptr<Spring> spring);
size_t getNumMasses() const;
size_t getNumSprings() const;
std::shared_ptr<Mass> getMass(size_t nodeId);
std::shared_ptr<Spring> getSpring(size_t springId);
double getTotalMass() const;
double getRayleighDampingStiffness() const;
double getRayleighDampingMass() const;
void setRayleighDampingStiffness(double stiffnessCoef);
void setRayleighDampingMass(double massCoef);
void addExternalGeneralizedForce(std::shared_ptr<Localization> localization,
const SurgSim::Math::Vector& generalizedForce,
const SurgSim::Math::Matrix& K = SurgSim::Math::Matrix(),
const SurgSim::Math::Matrix& D = SurgSim::Math::Matrix()) override;
void beforeUpdate(double dt) override;
std::shared_ptr<Localization> createLocalization(const SurgSim::DataStructures::Location& location) override;
protected:
void addRayleighDampingForce(SurgSim::Math::Vector* f, const SurgSim::Math::OdeState& state,
bool useGlobalStiffnessMatrix = false, bool useGlobalMassMatrix = false,
double scale = 1.0);
void addSpringsForce(SurgSim::Math::Vector* f, const SurgSim::Math::OdeState& state, double scale = 1.0);
void addGravityForce(SurgSim::Math::Vector* f, const SurgSim::Math::OdeState& state, double scale = 1.0);
void transformState(std::shared_ptr<SurgSim::Math::OdeState> state,
const SurgSim::Math::RigidTransform3d& transform);
bool doInitialize() override;
void computeF(const SurgSim::Math::OdeState& state) override;
void computeM(const SurgSim::Math::OdeState& state) override;
void computeD(const SurgSim::Math::OdeState& state) override;
void computeK(const SurgSim::Math::OdeState& state) override;
void computeFMDK(const SurgSim::Math::OdeState& state) override;
private:
std::vector<std::shared_ptr<Mass>> m_masses;
std::vector<std::shared_ptr<Spring>> m_springs;
struct
{
double massCoefficient;
double stiffnessCoefficient;
} m_rayleighDamping;
};
} // namespace Physics
} // namespace SurgSim
#endif // SURGSIM_PHYSICS_MASSSPRINGREPRESENTATION_H
SurgSim
Definition: CompoundShapeToGraphics.cpp:29
SurgSim::Physics::MassSpringRepresentation::computeD
void computeD(const SurgSim::Math::OdeState &state) override
Evaluation of for a given state.
Definition: MassSpringRepresentation.cpp:233
SurgSim::Physics::MassSpringRepresentation::getRayleighDampingMass
double getRayleighDampingMass() const
Gets the Rayleigh mass parameter.
Definition: MassSpringRepresentation.cpp:143
Mass.h
SurgSim::Physics::MassSpringRepresentation::~MassSpringRepresentation
virtual ~MassSpringRepresentation()
Destructor.
Definition: MassSpringRepresentation.cpp:46
Spring.h
SurgSim::Physics::MassSpringRepresentation::addRayleighDampingForce
void addRayleighDampingForce(SurgSim::Math::Vector *f, const SurgSim::Math::OdeState &state, bool useGlobalStiffnessMatrix=false, bool useGlobalMassMatrix=false, double scale=1.0)
Add the Rayleigh damping forces.
Definition: MassSpringRepresentation.cpp:351
SurgSim::DataStructures::Location
A Location defines a local position w.r.t.
Definition: Location.h:39
SurgSim::Physics::MassSpringRepresentation::getSpring
std::shared_ptr< Spring > getSpring(size_t springId)
Retrieves a given spring from its id.
Definition: MassSpringRepresentation.cpp:122
SurgSim::Math::Matrix
Eigen::Matrix< double, Eigen::Dynamic, Eigen::Dynamic > Matrix
A dynamic size matrix.
Definition: Matrix.h:65
SurgSim::Physics::MassSpringRepresentation::stiffnessCoefficient
double stiffnessCoefficient
Definition: MassSpringRepresentation.h:170
SurgSim::Physics::DeformableRepresentation
Base class for all deformable representations MassSprings, Finite Element Models,...
Definition: DeformableRepresentation.h:50
DeformableRepresentation.h
Base class for all deformable representations (abstract class)
SurgSim::Physics::MassSpringRepresentation::getNumSprings
size_t getNumSprings() const
Gets the number of springs.
Definition: MassSpringRepresentation.cpp:111
SurgSim::Math::OdeState
The state of an ode of 2nd order of the form with boundary conditions.
Definition: OdeState.h:38
SurgSim::Physics::MassSpringRepresentation::transformState
void transformState(std::shared_ptr< SurgSim::Math::OdeState > state, const SurgSim::Math::RigidTransform3d &transform)
Transform a state using a given transformation.
Definition: MassSpringRepresentation.cpp:446
SurgSim::Physics::MassSpringRepresentation::getMass
std::shared_ptr< Mass > getMass(size_t nodeId)
Retrieves the mass of a given node.
Definition: MassSpringRepresentation.cpp:116
SurgSim::Physics::MassSpringRepresentation::setRayleighDampingMass
void setRayleighDampingMass(double massCoef)
Sets the Rayleigh mass parameter.
Definition: MassSpringRepresentation.cpp:153
SurgSim::Math::Vector
Eigen::Matrix< double, Eigen::Dynamic, 1 > Vector
A dynamic size column vector.
Definition: Vector.h:68
SurgSim::Physics::MassSpringRepresentation::computeFMDK
void computeFMDK(const SurgSim::Math::OdeState &state) override
Evaluation of , , and .
Definition: MassSpringRepresentation.cpp:295
SurgSim::Physics::MassSpringRepresentation
MassSpring model is a deformable model (a set of masses connected by springs).
Definition: MassSpringRepresentation.h:38
SurgSim::Physics::MassSpringRepresentation::addExternalGeneralizedForce
void addExternalGeneralizedForce(std::shared_ptr< Localization > localization, const SurgSim::Math::Vector &generalizedForce, const SurgSim::Math::Matrix &K=SurgSim::Math::Matrix(), const SurgSim::Math::Matrix &D=SurgSim::Math::Matrix()) override
Add an external generalized force applied on a specific localization.
Definition: MassSpringRepresentation.cpp:158
SurgSim::Physics::MassSpringRepresentation::doInitialize
bool doInitialize() override
Interface to be implemented by derived classes.
Definition: MassSpringRepresentation.cpp:50
SurgSim::Physics::MassSpringRepresentation::getTotalMass
double getTotalMass() const
Gets the total mass of the mass spring.
Definition: MassSpringRepresentation.cpp:128
SurgSim::Physics::MassSpringRepresentation::addSpringsForce
void addSpringsForce(SurgSim::Math::Vector *f, const SurgSim::Math::OdeState &state, double scale=1.0)
Add the springs force to f (given a state)
Definition: MassSpringRepresentation.cpp:402
SurgSim::Physics::MassSpringRepresentation::MassSpringRepresentation
MassSpringRepresentation(const std::string &name)
Constructor.
Definition: MassSpringRepresentation.cpp:35
Matrix.h
Definitions of small fixed-size square matrix types.
SurgSim::Physics::MassSpringRepresentation::computeM
void computeM(const SurgSim::Math::OdeState &state) override
Evaluation of the LHS matrix for a given state.
Definition: MassSpringRepresentation.cpp:217
SurgSim::Math::RigidTransform3d
Eigen::Transform< double, 3, Eigen::Isometry > RigidTransform3d
A 3D rigid (isometric) transform, represented as doubles.
Definition: RigidTransform.h:46
SurgSim::Physics::MassSpringRepresentation::createLocalization
std::shared_ptr< Localization > createLocalization(const SurgSim::DataStructures::Location &location) override
Computes a localized coordinate w.r.t this representation, given a Location object.
Definition: MassSpringRepresentation.cpp:453
SurgSim::Physics::MassSpringRepresentation::m_springs
std::vector< std::shared_ptr< Spring > > m_springs
Springs.
Definition: MassSpringRepresentation.h:162
SurgSim::Physics::MassSpringRepresentation::addMass
void addMass(const std::shared_ptr< Mass > mass)
Adds a mass.
Definition: MassSpringRepresentation.cpp:96
Vector.h
Definitions of small fixed-size vector types.
SurgSim::Physics::MassSpringRepresentation::computeF
void computeF(const SurgSim::Math::OdeState &state) override
Evaluation of the RHS function for a given state.
Definition: MassSpringRepresentation.cpp:201
SurgSim::Physics::MassSpringRepresentation::massCoefficient
double massCoefficient
Definition: MassSpringRepresentation.h:169
SurgSim::Physics::MassSpringRepresentation::m_masses
std::vector< std::shared_ptr< Mass > > m_masses
Masses.
Definition: MassSpringRepresentation.h:159
SurgSim::Physics::MassSpringRepresentation::getRayleighDampingStiffness
double getRayleighDampingStiffness() const
Gets the Rayleigh stiffness parameter.
Definition: MassSpringRepresentation.cpp:138
SurgSim::Physics::MassSpringRepresentation::addSpring
void addSpring(const std::shared_ptr< Spring > spring)
Adds a spring.
Definition: MassSpringRepresentation.cpp:101
SurgSim::Physics::MassSpringRepresentation::computeK
void computeK(const SurgSim::Math::OdeState &state) override
Evaluation of for a given state.
Definition: MassSpringRepresentation.cpp:278
SurgSim::Physics::MassSpringRepresentation::setRayleighDampingStiffness
void setRayleighDampingStiffness(double stiffnessCoef)
Sets the Rayleigh stiffness parameter.
Definition: MassSpringRepresentation.cpp:148
SurgSim::Physics::MassSpringRepresentation::m_rayleighDamping
struct SurgSim::Physics::MassSpringRepresentation::@4 m_rayleighDamping
Rayleigh damping parameters (massCoefficient and stiffnessCoefficient) D = massCoefficient.M + stiffnessCoefficient.K Matrices: D = damping, M = mass, K = stiffness.
SurgSim::Physics::MassSpringRepresentation::getNumMasses
size_t getNumMasses() const
Gets the number of masses.
Definition: MassSpringRepresentation.cpp:106
SurgSim::Physics::MassSpringRepresentation::addGravityForce
void addGravityForce(SurgSim::Math::Vector *f, const SurgSim::Math::OdeState &state, double scale=1.0)
Add the gravity force to f (given a state)
Definition: MassSpringRepresentation.cpp:410
SurgSim::Physics::MassSpringRepresentation::beforeUpdate
void beforeUpdate(double dt) override
Preprocessing done before the update call.
Definition: MassSpringRepresentation.cpp:182