FemElement.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_FEMELEMENT_H
#define SURGSIM_PHYSICS_FEMELEMENT_H
#include <vector>
#include "SurgSim/Framework/ObjectFactory.h"
#include "SurgSim/Math/Matrix.h"
#include "SurgSim/Math/SparseMatrix.h"
#include "SurgSim/Math/Vector.h"
#include "SurgSim/Physics/Fem.h"
namespace SurgSim
{
namespace Math
{
class OdeState;
};
namespace Physics
{
class FemElement
{
public:
FemElement();
virtual ~FemElement();
virtual void initialize(const SurgSim::Math::OdeState& state);
typedef SurgSim::Framework::ObjectFactory1<FemElement, std::shared_ptr<FemElementStructs::FemElementParameter>>
FactoryType;
static FactoryType& getFactory();
size_t getNumDofPerNode() const;
size_t getNumNodes() const;
size_t getNodeId(size_t elementNodeId) const;
const std::vector<size_t>& getNodeIds() const;
void setYoungModulus(double E);
double getYoungModulus() const;
void setPoissonRatio(double nu);
double getPoissonRatio() const;
void setMassDensity(double rho);
double getMassDensity() const;
double getMass(const SurgSim::Math::OdeState& state) const;
virtual double getVolume(const SurgSim::Math::OdeState& state) const = 0;
virtual void addForce(SurgSim::Math::Vector* F, double scale = 1.0) const;
virtual void addMass(SurgSim::Math::SparseMatrix* M, double scale = 1.0) const;
virtual void addDamping(SurgSim::Math::SparseMatrix* D, double scale = 1.0) const;
virtual void addStiffness(SurgSim::Math::SparseMatrix* K, double scale = 1.0) const;
virtual void addFMDK(SurgSim::Math::Vector* F,
SurgSim::Math::SparseMatrix* M,
SurgSim::Math::SparseMatrix* D,
SurgSim::Math::SparseMatrix* K) const;
virtual void addMatVec(double alphaM, double alphaD, double alphaK,
const SurgSim::Math::Vector& x, SurgSim::Math::Vector* F) const;
bool isValidCoordinate(const SurgSim::Math::Vector& naturalCoordinate) const;
virtual SurgSim::Math::Vector computeCartesianCoordinate(
const SurgSim::Math::OdeState& state,
const SurgSim::Math::Vector& naturalCoordinate) const = 0;
virtual SurgSim::Math::Vector computeNaturalCoordinate(
const SurgSim::Math::OdeState& state,
const SurgSim::Math::Vector& cartesianCoordinate) const = 0;
template <typename DerivedSub, typename T, int Opt, typename Index>
void assembleMatrixBlocks(const DerivedSub& subMatrix, const std::vector<size_t> blockIds,
size_t blockSize, Eigen::SparseMatrix<T, Opt, Index>* matrix,
bool initialize = true) const;
void updateFMDK(const Math::OdeState& state, int options);
protected:
void setNumDofPerNode(size_t numDofPerNode);
virtual void doUpdateFMDK(const Math::OdeState& state, int options) = 0;
void initializeFMDK();
virtual void doInitializeFMDK();
size_t m_numDofPerNode;
std::vector<size_t> m_nodeIds;
double m_rho;
double m_E;
double m_nu;
SurgSim::Math::Vector m_f;
SurgSim::Math::Matrix m_M;
SurgSim::Math::Matrix m_D;
bool m_useDamping;
SurgSim::Math::Matrix m_K;
private:
bool m_initializedFMDK;
};
} // namespace Physics
} // namespace SurgSim
#include "SurgSim/Physics/FemElement-inl.h"
#endif // SURGSIM_PHYSICS_FEMELEMENT_H
SurgSim
Definition: CompoundShapeToGraphics.cpp:29
SurgSim::Physics::FemElement::m_numDofPerNode
size_t m_numDofPerNode
Number of degree of freedom per node for this element.
Definition: FemElement.h:231
SurgSim::Math::Matrix
Eigen::Matrix< double, Eigen::Dynamic, Eigen::Dynamic > Matrix
A dynamic size matrix.
Definition: Matrix.h:65
SurgSim::Physics::FemElement::m_nu
double m_nu
Poisson ratio (unitless)
Definition: FemElement.h:243
SurgSim::Physics::FemElement::FactoryType
SurgSim::Framework::ObjectFactory1< FemElement, std::shared_ptr< FemElementStructs::FemElementParameter > > FactoryType
Definition: FemElement.h:59
SurgSim::Physics::FemElement::m_D
SurgSim::Math::Matrix m_D
The damping matrix.
Definition: FemElement.h:252
SurgSim::Physics::FemElement::m_K
SurgSim::Math::Matrix m_K
The stiffness matrix.
Definition: FemElement.h:258
ObjectFactory.h
SurgSim::Math::OdeState
The state of an ode of 2nd order of the form with boundary conditions.
Definition: OdeState.h:38
SurgSim::Physics::FemElement
Base class for all Fem Element (1D, 2D, 3D) It handles the node ids to which it is connected and requ...
Definition: FemElement.h:45
SparseMatrix.h
Definitions of useful sparse matrix functions.
SurgSim::Physics::FemElement::m_rho
double m_rho
Mass density (in Kg.m-3)
Definition: FemElement.h:237
SurgSim::Math::Vector
Eigen::Matrix< double, Eigen::Dynamic, 1 > Vector
A dynamic size column vector.
Definition: Vector.h:68
SurgSim::Math::SparseMatrix
Eigen::SparseMatrix< double > SparseMatrix
A sparse matrix.
Definition: SparseMatrix.h:32
SurgSim::Physics::FemElement::m_f
SurgSim::Math::Vector m_f
The force vector.
Definition: FemElement.h:246
SurgSim::Physics::FemElement::m_E
double m_E
Young modulus (in N.m-2)
Definition: FemElement.h:240
SurgSim::Physics::FemElement::m_M
SurgSim::Math::Matrix m_M
The mass matrix.
Definition: FemElement.h:249
Matrix.h
Definitions of small fixed-size square matrix types.
Vector.h
Definitions of small fixed-size vector types.
SurgSim::Physics::FemElement::m_nodeIds
std::vector< size_t > m_nodeIds
Node ids connected by this element.
Definition: FemElement.h:234
SurgSim::Physics::FemElement::m_initializedFMDK
bool m_initializedFMDK
Flag to check in the f, M, D, K variables have been initialized.
Definition: FemElement.h:262
Fem.h
FemElement-inl.h
SurgSim::Physics::FemElement::m_useDamping
bool m_useDamping
Flag to specify of the damping is used.
Definition: FemElement.h:255
SurgSim::Framework::ObjectFactory1
An object factory, once a class is registered with the factory it can be used to create instances of ...
Definition: ObjectFactory.h:83