FemRepresentation.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_FEMREPRESENTATION_H
#define SURGSIM_PHYSICS_FEMREPRESENTATION_H
#include <memory>
#include "SurgSim/DataStructures/IndexedLocalCoordinate.h"
#include "SurgSim/Math/Matrix.h"
#include "SurgSim/Math/SparseMatrix.h"
#include "SurgSim/Math/Vector.h"
#include "SurgSim/Physics/DeformableRepresentation.h"
#include "SurgSim/Physics/Fem.h"
namespace SurgSim
{
namespace Physics
{
class FemElement;
class FemPlyReaderDelegate;
class FemRepresentation : public DeformableRepresentation
{
public:
explicit FemRepresentation(const std::string& name);
virtual ~FemRepresentation();
virtual void loadFem(const std::string& filename) = 0;
virtual void setFemElementType(const std::string& type);
const std::string& getFemElementType() const;
void addFemElement(const std::shared_ptr<FemElement> element);
size_t getNumFemElements() const;
std::shared_ptr<FemElement> getFemElement(size_t femElementId);
double getTotalMass() const;
double getRayleighDampingStiffness() const;
double getRayleighDampingMass() const;
void setRayleighDampingStiffness(double stiffnessCoef);
void setRayleighDampingMass(double massCoef);
bool isValidCoordinate(const SurgSim::DataStructures::IndexedLocalCoordinate& coordinate) const;
void beforeUpdate(double dt) override;
void update(double dt) override;
void setComplianceWarping(bool useComplianceWarping);
bool getComplianceWarping() const;
Math::Matrix applyCompliance(const Math::OdeState& state, const Math::Matrix& b) override;
const SurgSim::Math::Matrix& getComplianceMatrix() const override;
void updateFMDK(const SurgSim::Math::OdeState& state, int options) override;
protected:
void addRayleighDampingForce(SurgSim::Math::Vector* f, const SurgSim::Math::OdeState& state,
bool useGlobalMassMatrix = false, bool useGlobalStiffnessMatrix = false,
double scale = 1.0);
void addFemElementsForce(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);
bool doInitialize() override;
void updateComplianceMatrix(const SurgSim::Math::OdeState& state);
virtual SurgSim::Math::Matrix getNodeTransformation(const SurgSim::Math::OdeState& state, size_t nodeId);
bool isInitialComplianceMatrixComputed() const;
void setIsInitialComplianceMatrixComputed(bool flag);
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;
std::vector<double> m_massPerNode;
std::vector<std::shared_ptr<FemElement>> m_femElements;
std::string m_femElementType;
private:
struct
{
double massCoefficient;
double stiffnessCoefficient;
} m_rayleighDamping;
bool m_useComplianceWarping;
bool m_isInitialComplianceMatrixComputed;
SurgSim::Math::Matrix m_complianceWarpingMatrix;
Eigen::SparseMatrix<double> m_complianceWarpingTransformation;
};
} // namespace Physics
} // namespace SurgSim
#endif // SURGSIM_PHYSICS_FEMREPRESENTATION_H
SurgSim::Physics::FemRepresentation::m_useComplianceWarping
bool m_useComplianceWarping
Are we using Compliance Warping or not ?
Definition: FemRepresentation.h:217
SurgSim
Definition: CompoundShapeToGraphics.cpp:29
SurgSim::Physics::FemRepresentation::doInitialize
bool doInitialize() override
Interface to be implemented by derived classes.
Definition: FemRepresentation.cpp:75
SurgSim::DataStructures::IndexedLocalCoordinate
A generic (size_t index, Vector coordinate) pair.
Definition: IndexedLocalCoordinate.h:29
SurgSim::Physics::FemRepresentation::loadFem
virtual void loadFem(const std::string &filename)=0
Loads the FEM file into an Fem class data structure.
SurgSim::Physics::FemRepresentation::m_complianceWarpingMatrix
SurgSim::Math::Matrix m_complianceWarpingMatrix
The compliance warping matrix if compliance warping in use.
Definition: FemRepresentation.h:221
SurgSim::Physics::FemRepresentation
Finite Element Model (a.k.a FEM) is a deformable model (a set of nodes connected by FemElement)...
Definition: FemRepresentation.h:46
SurgSim::Physics::FemRepresentation::FemRepresentation
FemRepresentation(const std::string &name)
Constructor.
Definition: FemRepresentation.cpp:39
SurgSim::Physics::FemRepresentation::getComplianceMatrix
const SurgSim::Math::Matrix & getComplianceMatrix() const override
Gets the compliance matrix associated with motion.
Definition: FemRepresentation.cpp:293
SurgSim::Physics::FemRepresentation::getNumFemElements
size_t getNumFemElements() const
Gets the number of FemElement.
Definition: FemRepresentation.cpp:165
SurgSim::Math::Matrix
Eigen::Matrix< double, Eigen::Dynamic, Eigen::Dynamic > Matrix
A dynamic size matrix.
Definition: Matrix.h:65
SurgSim::Physics::FemRepresentation::update
void update(double dt) override
Update the representation state to the current time step.
Definition: FemRepresentation.cpp:222
SurgSim::Physics::FemRepresentation::m_isInitialComplianceMatrixComputed
bool m_isInitialComplianceMatrixComputed
For compliance warping: Is the initial compliance matrix computed ?
Definition: FemRepresentation.h:219
SurgSim::Physics::DeformableRepresentation
Base class for all deformable representations MassSprings, Finite Element Models,...
Definition: DeformableRepresentation.h:50
SurgSim::Physics::FemRepresentation::setIsInitialComplianceMatrixComputed
void setIsInitialComplianceMatrixComputed(bool flag)
Sets the flag keeping track of the initial compliance matrix calculation (compliance warping case) ...
Definition: FemRepresentation.cpp:565
DeformableRepresentation.h
Base class for all deformable representations (abstract class)
SurgSim::Physics::FemRepresentation::addFemElementsForce
void addFemElementsForce(SurgSim::Math::Vector *f, const SurgSim::Math::OdeState &state, double scale=1.0)
Adds the FemElements forces to f (given a state)
Definition: FemRepresentation.cpp:527
SurgSim::Physics::FemRepresentation::massCoefficient
double massCoefficient
Definition: FemRepresentation.h:213
SurgSim::Math::OdeState
The state of an ode of 2nd order of the form with boundary conditions.
Definition: OdeState.h:38
IndexedLocalCoordinate.h
SurgSim::Physics::FemRepresentation::setRayleighDampingStiffness
void setRayleighDampingStiffness(double stiffnessCoef)
Sets the Rayleigh stiffness parameter.
Definition: FemRepresentation.cpp:202
SurgSim::Physics::FemRepresentation::isInitialComplianceMatrixComputed
bool isInitialComplianceMatrixComputed() const
Gets the flag keeping track of the initial compliance matrix calculation (compliance warping case) ...
Definition: FemRepresentation.cpp:560
SparseMatrix.h
Definitions of useful sparse matrix functions.
SurgSim::Physics::FemRepresentation::isValidCoordinate
bool isValidCoordinate(const SurgSim::DataStructures::IndexedLocalCoordinate &coordinate) const
Determines whether the associated coordinate is valid.
Definition: FemRepresentation.cpp:176
SurgSim::Physics::FemRepresentation::stiffnessCoefficient
double stiffnessCoefficient
Definition: FemRepresentation.h:214
SurgSim::Physics::FemRepresentation::updateFMDK
void updateFMDK(const SurgSim::Math::OdeState &state, int options) override
Update the OdeEquation (and support data) based on the given state.
Definition: FemRepresentation.cpp:467
SurgSim::Math::Vector
Eigen::Matrix< double, Eigen::Dynamic, 1 > Vector
A dynamic size column vector.
Definition: Vector.h:68
SurgSim::Physics::FemRepresentation::applyCompliance
Math::Matrix applyCompliance(const Math::OdeState &state, const Math::Matrix &b) override
Calculate the product C.b where C is the compliance matrix with boundary conditions.
Definition: FemRepresentation.cpp:280
SurgSim::Physics::FemRepresentation::getRayleighDampingMass
double getRayleighDampingMass() const
Gets the Rayleigh mass parameter.
Definition: FemRepresentation.cpp:197
SurgSim::Physics::FemRepresentation::setFemElementType
virtual void setFemElementType(const std::string &type)
Sets the FemElement type pulled from the object factory.
Definition: FemRepresentation.cpp:64
SurgSim::Physics::FemRepresentation::m_femElements
std::vector< std::shared_ptr< FemElement > > m_femElements
FemElements.
Definition: FemRepresentation.h:199
SurgSim::Physics::FemRepresentation::setRayleighDampingMass
void setRayleighDampingMass(double massCoef)
Sets the Rayleigh mass parameter.
Definition: FemRepresentation.cpp:207
Matrix.h
Definitions of small fixed-size square matrix types.
SurgSim::Physics::FemRepresentation::computeM
void computeM(const SurgSim::Math::OdeState &state) override
Evaluation of the LHS matrix for a given state.
Definition: FemRepresentation.cpp:344
SurgSim::Physics::FemRepresentation::getNodeTransformation
virtual SurgSim::Math::Matrix getNodeTransformation(const SurgSim::Math::OdeState &state, size_t nodeId)
Retrieves a specific node transformation (useful for compliance warping)
Definition: FemRepresentation.cpp:304
Vector.h
Definitions of small fixed-size vector types.
SurgSim::Physics::FemRepresentation::getFemElementType
const std::string & getFemElementType() const
Gets the FemElement type pulled from the object factory.
Definition: FemRepresentation.cpp:70
SurgSim::Physics::FemRepresentation::computeFMDK
void computeFMDK(const SurgSim::Math::OdeState &state) override
Evaluation of , , and .
Definition: FemRepresentation.cpp:411
SurgSim::Physics::FemRepresentation::computeD
void computeD(const SurgSim::Math::OdeState &state) override
Evaluation of for a given state.
Definition: FemRepresentation.cpp:355
SurgSim::Physics::FemRepresentation::m_massPerNode
std::vector< double > m_massPerNode
Useful information per node.
Definition: FemRepresentation.h:196
SurgSim::Physics::FemRepresentation::getTotalMass
double getTotalMass() const
Gets the total mass of the fem.
Definition: FemRepresentation.cpp:182
SurgSim::Physics::FemRepresentation::beforeUpdate
void beforeUpdate(double dt) override
Preprocessing done before the update call.
Definition: FemRepresentation.cpp:212
SurgSim::Physics::FemRepresentation::~FemRepresentation
virtual ~FemRepresentation()
Destructor.
Definition: FemRepresentation.cpp:60
SurgSim::Physics::FemRepresentation::setComplianceWarping
void setComplianceWarping(bool useComplianceWarping)
Set the compliance warping flag.
Definition: FemRepresentation.cpp:268
SurgSim::Physics::FemRepresentation::getComplianceWarping
bool getComplianceWarping() const
Get the compliance warping flag (default = false)
Definition: FemRepresentation.cpp:275
SurgSim::Physics::FemRepresentation::addFemElement
void addFemElement(const std::shared_ptr< FemElement > element)
Adds a FemElement.
Definition: FemRepresentation.cpp:160
SurgSim::Physics::FemRepresentation::getRayleighDampingStiffness
double getRayleighDampingStiffness() const
Gets the Rayleigh stiffness parameter.
Definition: FemRepresentation.cpp:192
SurgSim::Physics::FemRepresentation::m_complianceWarpingTransformation
Eigen::SparseMatrix< double > m_complianceWarpingTransformation
The system-size transformation matrix. It contains nodes transformation on the diagonal blocks...
Definition: FemRepresentation.h:224
SurgSim::Physics::FemRepresentation::addRayleighDampingForce
void addRayleighDampingForce(SurgSim::Math::Vector *f, const SurgSim::Math::OdeState &state, bool useGlobalMassMatrix=false, bool useGlobalStiffnessMatrix=false, double scale=1.0)
Adds the Rayleigh damping forces.
Definition: FemRepresentation.cpp:479
SurgSim::Physics::FemRepresentation::computeF
void computeF(const SurgSim::Math::OdeState &state) override
Evaluation of the RHS function for a given state.
Definition: FemRepresentation.cpp:328
SurgSim::Physics::FemRepresentation::m_rayleighDamping
struct SurgSim::Physics::FemRepresentation::@3 m_rayleighDamping
Rayleigh damping parameters (massCoefficient and stiffnessCoefficient) D = massCoefficient.M + stiffnessCoefficient.K Matrices: D = damping, M = mass, K = stiffness.
SurgSim::Physics::FemRepresentation::getFemElement
std::shared_ptr< FemElement > getFemElement(size_t femElementId)
Retrieves a given FemElement from its id.
Definition: FemRepresentation.cpp:170
SurgSim::Physics::FemRepresentation::m_femElementType
std::string m_femElementType
The FemElement factory parameter invoked in doInitialize() when using a MeshAsset either with LoadFem...
Definition: FemRepresentation.h:205
Fem.h
SurgSim::Physics::FemRepresentation::computeK
void computeK(const SurgSim::Math::OdeState &state) override
Evaluation of for a given state.
Definition: FemRepresentation.cpp:394
SurgSim::Physics::FemRepresentation::updateComplianceMatrix
void updateComplianceMatrix(const SurgSim::Math::OdeState &state)
Updates the compliance matrix using nodes transformation (useful for compliance warping) ...
Definition: FemRepresentation.cpp:312
SurgSim::Physics::FemRepresentation::addGravityForce
void addGravityForce(SurgSim::Math::Vector *f, const SurgSim::Math::OdeState &state, double scale=1.0)
Adds the gravity force to f (given a state)
Definition: FemRepresentation.cpp:537