opensurgsim
Public Types | Public Member Functions | Static Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
SurgSim::Physics::FemElement Class Referenceabstract

Base class for all Fem Element (1D, 2D, 3D) It handles the node ids to which it is connected and requires all derived classes to compute the element mass matrix and the force vector along with the derivatives (the stiffness and damping matrices). More...

#include <FemElement.h>

Inheritance diagram for SurgSim::Physics::FemElement:
SurgSim::Physics::Fem1DElementBeam SurgSim::Physics::Fem2DElementTriangle SurgSim::Physics::Fem3DElementCube SurgSim::Physics::Fem3DElementTetrahedron SurgSim::Physics::MockFemElement MockFem1DElement MockFem2DElement MockFem3DElementCube MockFem3DElementTet SurgSim::Physics::Fem3DElementCorotationalTetrahedron MockFem3DElementCorotationalTet

Public Types

typedef SurgSim::Framework::ObjectFactory1< FemElement, std::shared_ptr< FemElementStructs::FemElementParameter > > FactoryType
 

Public Member Functions

 FemElement ()
 Constructor.
 
virtual ~FemElement ()
 Virtual destructor.
 
virtual void initialize (const SurgSim::Math::OdeState &state)
 Initialize the FemElement once everything has been set. More...
 
size_t getNumDofPerNode () const
 Gets the number of degree of freedom per node. More...
 
size_t getNumNodes () const
 Gets the number of nodes connected by this element. More...
 
size_t getNodeId (size_t elementNodeId) const
 Gets the elementNodeId-th node id. More...
 
const std::vector< size_t > & getNodeIds () const
 Gets the node ids for this element. More...
 
void setYoungModulus (double E)
 Sets the Young modulus (in N.m-2) More...
 
double getYoungModulus () const
 Gets the Young modulus (in N.m-2) More...
 
void setPoissonRatio (double nu)
 Sets the Poisson ratio (unitless) More...
 
double getPoissonRatio () const
 Gets the Poisson ratio (unitless) More...
 
void setMassDensity (double rho)
 Sets the mass density (in Kg.m-3) More...
 
double getMassDensity () const
 Gets the mass density (in Kg.m-3) More...
 
double getMass (const SurgSim::Math::OdeState &state) const
 Gets the element mass based on the input state (in Kg) More...
 
virtual double getVolume (const SurgSim::Math::OdeState &state) const =0
 Gets the element volume based on the input state (in m-3) More...
 
virtual void addForce (SurgSim::Math::Vector *F, double scale) const
 Adds the element force (computed for a given state) to a complete system force vector F (assembly) More...
 
virtual void addForce (SurgSim::Math::Vector *F) const
 
virtual void addMass (SurgSim::Math::SparseMatrix *M, double scale) const
 Adds the element mass matrix M (computed for a given state) to a complete system mass matrix M (assembly) More...
 
virtual void addMass (SurgSim::Math::SparseMatrix *M) const
 
virtual void addDamping (SurgSim::Math::SparseMatrix *D, double scale) const
 Adds the element damping matrix D (= -df/dv) (comuted for a given state) to a complete system damping matrix D (assembly) More...
 
virtual void addDamping (SurgSim::Math::SparseMatrix *D) const
 
virtual void addStiffness (SurgSim::Math::SparseMatrix *K, double scale) const
 Adds the element stiffness matrix K (= -df/dx) (computed for a given state) to a complete system stiffness matrix K (assembly) More...
 
virtual void addStiffness (SurgSim::Math::SparseMatrix *K) const
 
virtual void addFMDK (SurgSim::Math::Vector *F, SurgSim::Math::SparseMatrix *M, SurgSim::Math::SparseMatrix *D, SurgSim::Math::SparseMatrix *K) const
 Adds the element force vector, mass, stiffness and damping matrices (computed for a given state) into a complete system data structure F, M, D, K (assembly) More...
 
virtual void addMatVec (double alphaM, double alphaD, double alphaK, const SurgSim::Math::Vector &x, SurgSim::Math::Vector *F, SurgSim::Math::Vector *extractedX, SurgSim::Math::Vector *acumulator) const
 Adds the element matrix-vector contribution F += (alphaM.M + alphaD.D + alphaK.K).x (computed for a given state) into a complete system data structure F (assembly) More...
 
bool isValidCoordinate (const SurgSim::Math::Vector &naturalCoordinate) const
 Determines whether a given natural coordinate is valid. More...
 
virtual SurgSim::Math::Vector computeCartesianCoordinate (const SurgSim::Math::OdeState &state, const SurgSim::Math::Vector &naturalCoordinate) const =0
 Computes a given natural coordinate in cartesian coordinates. More...
 
virtual SurgSim::Math::Vector computeNaturalCoordinate (const SurgSim::Math::OdeState &state, const SurgSim::Math::Vector &cartesianCoordinate) const =0
 Computes a natural coordinate given a global coordinate. More...
 
template<typename T , int Opt, typename StorageIndex >
void assembleMatrixBlocks (const Eigen::Ref< const Math::Matrix > &subMatrix, const std::vector< size_t > &blockIds, size_t blockSize, Eigen::SparseMatrix< T, Opt, StorageIndex > *matrix) const
 Add a sub-matrix made of squared-blocks into a matrix that could be un-initialized. More...
 
template<typename T , int Opt, typename StorageIndex >
void assembleMatrixBlocksNoInitialize (const Eigen::Ref< const Math::Matrix > &subMatrix, const std::vector< size_t > &blockIds, size_t blockSize, Eigen::SparseMatrix< T, Opt, StorageIndex > *matrix) const
 Add a sub-matrix made of squared-blocks into a matrix that is already initialized. More...
 
void updateFMDK (const Math::OdeState &state, int options)
 Update the FemElement based on the given state. More...
 

Static Public Member Functions

static FactoryTypegetFactory ()
 

Protected Member Functions

void setNumDofPerNode (size_t numDofPerNode)
 Sets the number of degrees of freedom per node. More...
 
virtual void doUpdateFMDK (const Math::OdeState &state, int options)=0
 Update the FemElement based on the given state. More...
 
void initializeFMDK ()
 Initialize f, M, D, K variables.
 
virtual void doInitializeFMDK ()
 Function to be overridden by the derived classes to initialize the f, M, D, K variables.
 

Protected Attributes

size_t m_numDofPerNode
 Number of degree of freedom per node for this element.
 
std::vector< size_t > m_nodeIds
 Node ids connected by this element.
 
SurgSim::Math::Vector m_f
 The force vector.
 
SurgSim::Math::Matrix m_K
 The stiffness matrix.
 
SurgSim::Math::Matrix m_M
 The mass matrix.
 
SurgSim::Math::Matrix m_D
 The damping matrix.
 
bool m_useDamping
 Flag to specify of the damping is used.
 
double m_rho
 Mass density (in Kg.m-3)
 
double m_E
 Young modulus (in N.m-2)
 
double m_nu
 Poisson ratio (unitless)
 

Detailed Description

Base class for all Fem Element (1D, 2D, 3D) It handles the node ids to which it is connected and requires all derived classes to compute the element mass matrix and the force vector along with the derivatives (the stiffness and damping matrices).

A extra method also exist to compute all of them at once for performance purposes. It holds on to the actual computed values (m_f, m_M, m_D, m_K) as its size is not predefined from outside and would requires intensive (de)allocation or a temporary variable anyway. It contains the linear elasticity parameter (Young modulus and Poisson ratio) as well as mass density

Member Function Documentation

§ addDamping()

void SurgSim::Physics::FemElement::addDamping ( SurgSim::Math::SparseMatrix D,
double  scale 
) const
virtual

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

Parameters
[in,out]DThe complete system damping matrix to add the element damping matrix into
scaleA factor to scale the added damping matrix with
Note
The element damping matrix is square of size getNumDofPerNode() x getNumNodes()
This method supposes that the incoming state contains information with the same number of
dof per node as getNumDofPerNode()

§ addFMDK()

void SurgSim::Physics::FemElement::addFMDK ( SurgSim::Math::Vector F,
SurgSim::Math::SparseMatrix M,
SurgSim::Math::SparseMatrix D,
SurgSim::Math::SparseMatrix K 
) const
virtual

Adds the element force vector, mass, stiffness and damping matrices (computed for a given state) into a complete system data structure F, M, D, K (assembly)

Parameters
[in,out]FThe complete system force vector to add the element force into
[in,out]MThe complete system mass matrix to add the element mass matrix into
[in,out]DThe complete system damping matrix to add the element damping matrix into
[in,out]KThe complete system stiffness matrix to add the element stiffness matrix into
Note
This method supposes that the incoming state contains information with the same number of dof
per node as getNumDofPerNode()

§ addForce()

void SurgSim::Physics::FemElement::addForce ( SurgSim::Math::Vector F,
double  scale 
) const
virtual

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

Parameters
[in,out]FThe complete system force vector to add the element force into
scaleA factor to scale the added force with
Note
The element force is of size (getNumDofPerNode() x getNumNodes())
This method supposes that the incoming state contains information with the same number of dof
per node as getNumDofPerNode()

§ addMass()

void SurgSim::Physics::FemElement::addMass ( SurgSim::Math::SparseMatrix M,
double  scale 
) const
virtual

Adds the element mass matrix M (computed for a given state) to a complete system mass matrix M (assembly)

Parameters
[in,out]MThe complete system mass matrix to add the element mass-matrix into
scaleA factor to scale the added mass matrix with
Note
The element mass matrix is square of size getNumDofPerNode() x getNumNodes()
This method supposes that the incoming state contains information with the same number of
dof per node as getNumDofPerNode()

§ addMatVec()

void SurgSim::Physics::FemElement::addMatVec ( double  alphaM,
double  alphaD,
double  alphaK,
const SurgSim::Math::Vector x,
SurgSim::Math::Vector F,
SurgSim::Math::Vector extractedX,
SurgSim::Math::Vector acumulator 
) const
virtual

Adds the element matrix-vector contribution F += (alphaM.M + alphaD.D + alphaK.K).x (computed for a given state) into a complete system data structure F (assembly)

Parameters
alphaMThe scaling factor for the mass contribution
alphaDThe scaling factor for the damping contribution
alphaKThe scaling factor for the stiffness contribution
xA complete system vector to be used as the vector in the matrix-vector multiplication
[in,out]FThe complete system force vector to add the element matrix-vector contribution into
[out]extractedX,acumulatortemporary memory for the function operation, this is an optimization as addMatVec will get repeatedly called during one physics frame, preallocating these vectors helps
Note
This method supposes that the incoming state contains information with the same number of dof
per node as getNumDofPerNode()

§ addStiffness()

void SurgSim::Physics::FemElement::addStiffness ( SurgSim::Math::SparseMatrix K,
double  scale 
) const
virtual

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

Parameters
[in,out]KThe complete system stiffness matrix to add the element stiffness matrix into
scaleA factor to scale the added stiffness matrix with
Note
The element stiffness matrix is square of size getNumDofPerNode() x getNumNodes()
This method supposes that the incoming state contains information with the same number of
dof per node as getNumDofPerNode()

§ assembleMatrixBlocks()

template<typename T , int Opt, typename StorageIndex >
void SurgSim::Physics::FemElement::assembleMatrixBlocks ( const Eigen::Ref< const Math::Matrix > &  subMatrix,
const std::vector< size_t > &  blockIds,
size_t  blockSize,
Eigen::SparseMatrix< T, Opt, StorageIndex > *  matrix 
) const

Add a sub-matrix made of squared-blocks into a matrix that could be un-initialized.

Template Parameters
T,Opt,StorageIndexTypes and option defining the output matrix type SparseMatrix<T, Opt, StorageIndex>
Parameters
subMatrixThe sub-matrix (containing all the squared-blocks)
blockIdsVector of block indices (for accessing matrix) corresponding to the blocks in sub-matrix
blockSizeThe blocks size
[out]matrixThe matrix to add the sub-matrix blocks into

§ assembleMatrixBlocksNoInitialize()

template<typename T , int Opt, typename StorageIndex >
void SurgSim::Physics::FemElement::assembleMatrixBlocksNoInitialize ( const Eigen::Ref< const Math::Matrix > &  subMatrix,
const std::vector< size_t > &  blockIds,
size_t  blockSize,
Eigen::SparseMatrix< T, Opt, StorageIndex > *  matrix 
) const

Add a sub-matrix made of squared-blocks into a matrix that is already initialized.

Template Parameters
T,Opt,StorageIndexTypes and option defining the output matrix type SparseMatrix<T, Opt, StorageIndex>
Parameters
subMatrixThe sub-matrix (containing all the squared-blocks)
blockIdsVector of block indices (for accessing matrix) corresponding to the blocks in sub-matrix
blockSizeThe blocks size
[out]matrixThe matrix to add the sub-matrix blocks into

§ computeCartesianCoordinate()

virtual SurgSim::Math::Vector SurgSim::Physics::FemElement::computeCartesianCoordinate ( const SurgSim::Math::OdeState state,
const SurgSim::Math::Vector naturalCoordinate 
) const
pure virtual

Computes a given natural coordinate in cartesian coordinates.

Parameters
stateThe state at which to transform coordinates
naturalCoordinateThe coordinates to transform
Returns
The resultant cartesian coordinates

Implemented in SurgSim::Physics::Fem2DElementTriangle, SurgSim::Physics::Fem3DElementCube, SurgSim::Physics::Fem1DElementBeam, and SurgSim::Physics::Fem3DElementTetrahedron.

§ computeNaturalCoordinate()

virtual SurgSim::Math::Vector SurgSim::Physics::FemElement::computeNaturalCoordinate ( const SurgSim::Math::OdeState state,
const SurgSim::Math::Vector cartesianCoordinate 
) const
pure virtual

Computes a natural coordinate given a global coordinate.

Parameters
stateThe state at which to transform coordinates
cartesianCoordinateThe coordinates to transform
Returns
The resultant natural coordinates

Implemented in SurgSim::Physics::Fem2DElementTriangle, SurgSim::Physics::Fem3DElementCube, SurgSim::Physics::Fem1DElementBeam, and SurgSim::Physics::Fem3DElementTetrahedron.

§ doUpdateFMDK()

virtual void SurgSim::Physics::FemElement::doUpdateFMDK ( const Math::OdeState state,
int  options 
)
protectedpure virtual

Update the FemElement based on the given state.

Parameters
state\((x, v)\) the current position and velocity to evaluate the various terms with
optionsFlag to specify which of the F, M, D, K needs to be updated

Implemented in SurgSim::Physics::Fem2DElementTriangle, SurgSim::Physics::Fem3DElementCube, SurgSim::Physics::Fem1DElementBeam, SurgSim::Physics::Fem3DElementTetrahedron, and SurgSim::Physics::Fem3DElementCorotationalTetrahedron.

§ getMass()

double SurgSim::Physics::FemElement::getMass ( const SurgSim::Math::OdeState state) const

Gets the element mass based on the input state (in Kg)

Parameters
stateThe state to compute the mass with
Returns
The mass of this element (in Kg)

§ getMassDensity()

double SurgSim::Physics::FemElement::getMassDensity ( ) const

Gets the mass density (in Kg.m-3)

Returns
The mass density

§ getNodeId()

size_t SurgSim::Physics::FemElement::getNodeId ( size_t  elementNodeId) const

Gets the elementNodeId-th node id.

Returns
The requested node id

§ getNodeIds()

const std::vector< size_t > & SurgSim::Physics::FemElement::getNodeIds ( ) const

Gets the node ids for this element.

Returns
A vector containing the node ids on which the element is defined

§ getNumDofPerNode()

size_t SurgSim::Physics::FemElement::getNumDofPerNode ( ) const

Gets the number of degree of freedom per node.

Returns
The number of dof per node

§ getNumNodes()

size_t SurgSim::Physics::FemElement::getNumNodes ( ) const

Gets the number of nodes connected by this element.

Returns
The number of nodes

§ getPoissonRatio()

double SurgSim::Physics::FemElement::getPoissonRatio ( ) const

Gets the Poisson ratio (unitless)

Returns
The Poisson ratio

§ getVolume()

virtual double SurgSim::Physics::FemElement::getVolume ( const SurgSim::Math::OdeState state) const
pure virtual

Gets the element volume based on the input state (in m-3)

Parameters
stateThe state to compute the volume with
Returns
The volume of this element (in m-3)

Implemented in SurgSim::Physics::MockFemElement, SurgSim::Physics::Fem2DElementTriangle, SurgSim::Physics::Fem3DElementCube, SurgSim::Physics::Fem3DElementTetrahedron, and SurgSim::Physics::Fem1DElementBeam.

§ getYoungModulus()

double SurgSim::Physics::FemElement::getYoungModulus ( ) const

Gets the Young modulus (in N.m-2)

Returns
The Young modulus

§ initialize()

void SurgSim::Physics::FemElement::initialize ( const SurgSim::Math::OdeState state)
virtual

§ isValidCoordinate()

bool SurgSim::Physics::FemElement::isValidCoordinate ( const SurgSim::Math::Vector naturalCoordinate) const

Determines whether a given natural coordinate is valid.

Parameters
naturalCoordinateCoordinate to check
Returns
True if valid

§ setMassDensity()

void SurgSim::Physics::FemElement::setMassDensity ( double  rho)

Sets the mass density (in Kg.m-3)

Parameters
rhoThe mass density

§ setNumDofPerNode()

void SurgSim::Physics::FemElement::setNumDofPerNode ( size_t  numDofPerNode)
protected

Sets the number of degrees of freedom per node.

Parameters
numDofPerNodeThe number of dof per node
Note
Protected to be accessible only to derived classes which should be the only
ones able to set this parameter

§ setPoissonRatio()

void SurgSim::Physics::FemElement::setPoissonRatio ( double  nu)

Sets the Poisson ratio (unitless)

Parameters
nuThe Poisson ratio

§ setYoungModulus()

void SurgSim::Physics::FemElement::setYoungModulus ( double  E)

Sets the Young modulus (in N.m-2)

Parameters
EThe Young modulus

§ updateFMDK()

void SurgSim::Physics::FemElement::updateFMDK ( const Math::OdeState state,
int  options 
)

Update the FemElement based on the given state.

Parameters
state\((x, v)\) the current position and velocity to evaluate the various terms with
optionsFlag to specify which of the F, M, D, K needs to be updated

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