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 <SurgSim/Physics/FemElement.h>`

Inheritance diagram for SurgSim::Physics::FemElement:

## Public Types

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

## Public Member Functions

| FemElement ()
| Constructor. More...
virtual | ~FemElement ()
| Virtual destructor. More...
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=1.0) const
| Adds the element force (computed for a given state) to a complete system force vector F (assembly) More...
virtual void | addMass (SurgSim::Math::SparseMatrix *M, double scale=1.0) const
| Adds the element mass matrix M (computed for a given state) to a complete system mass matrix M (assembly) More...
virtual void | addDamping (SurgSim::Math::SparseMatrix *D, double scale=1.0) 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 | addStiffness (SurgSim::Math::SparseMatrix *K, double scale=1.0) 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 | 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) 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 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
| Helper method to add a sub-matrix made of squared-blocks into a matrix, for the sake of clarity. More...
void | updateFMDK (const Math::OdeState &state, int options)
| Update the FemElement based on the given state. More...

## Static Public Member Functions

static FactoryType & | getFactory ()

## 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. More...
virtual void | doInitializeFMDK ()
| Function to be overridden by the derived classes to initialize the f, M, D, K variables. More...

## Protected Attributes

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

## Private Attributes

bool | m_initializedFMDK
| Flag to check in the f, M, D, K variables have been initialized. More...

## 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 Typedef Documentation

## FactoryType

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

## Constructor & Destructor Documentation

## FemElement()

SurgSim::Physics::FemElement::FemElement | ( |  | ) |

Constructor.

## ~FemElement()

SurgSim::Physics::FemElement::~FemElement | ( |  | ) |

virtual

Virtual destructor.

## Member Function Documentation

## addDamping()

void SurgSim::Physics::FemElement::addDamping | ( | SurgSim::Math::SparseMatrix * | D,
|  | double | scale = `1.0`
| ) |  | 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] | D | The complete system damping matrix to add the element damping matrix into
  | scale | A 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] | F | The complete system force vector to add the element force into
  [in,out] | M | The complete system mass matrix to add the element mass matrix into
  [in,out] | D | The complete system damping matrix to add the element damping matrix into
  [in,out] | K | The 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 = `1.0`
| ) |  | const

virtual

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

Parameters

  [in,out] | F | The complete system force vector to add the element force into
  | scale | A 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 = `1.0`
| ) |  | const

virtual

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

Parameters

  [in,out] | M | The complete system mass matrix to add the element mass-matrix into
  | scale | A 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
| ) |  | 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

  | alphaM | The scaling factor for the mass contribution
  | alphaD | The scaling factor for the damping contribution
  | alphaK | The scaling factor for the stiffness contribution
  | x | A complete system vector to be used as the vector in the matrix-vector multiplication
  [in,out] | F | The complete system force vector to add the element matrix-vector contribution into

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 = `1.0`
| ) |  | 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] | K | The complete system stiffness matrix to add the element stiffness matrix into
  | scale | A 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 DerivedSub , typename T , int Opt, typename Index >

void SurgSim::Physics::FemElement::assembleMatrixBlocks | ( | const DerivedSub & | subMatrix,
|  | const std::vector< size_t > | blockIds,
|  | size_t | blockSize,
|  | Eigen::SparseMatrix< T, Opt, Index > * | matrix,
|  | bool | initialize = `true`
| ) |  | const

Helper method to add a sub-matrix made of squared-blocks into a matrix, for the sake of clarity.

Template Parameters

  DerivedSub | The type of the 'subMatrix' (can usually be inferred). Can be any type, but does not support Eigen expression. If it is a Sparse storage type the alignment must be the same as the SparseMatrix: Opt. Note that no assertion or verification is done on this type.
  T,Opt,Index | Types and option defining the output matrix type SparseMatrix<T, Opt, Index>

Parameters

  | subMatrix | The sub-matrix (containing all the squared-blocks)
  | blockIds | Vector of block indices (for accessing matrix) corresponding to the blocks in sub-matrix
  | blockSize | The blocks size
  [out] | matrix | The matrix to add the sub-matrix blocks into
  | initialize | Optional parameter, default true. If true, the matrix form is assumed to be undefined and is initialized when necessary. If false, the matrix form is assumed to be previously defined.

## 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

  state | The state at which to transform coordinates
  naturalCoordinate | The 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

  state | The state at which to transform coordinates
  cartesianCoordinate | The coordinates to transform

Returns
  The resultant natural coordinates

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

## doInitializeFMDK()

void SurgSim::Physics::FemElement::doInitializeFMDK | ( |  | ) |

protected virtual

Function to be overridden by the derived classes to initialize the f, M, D, K variables.

## doUpdateFMDK()

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

protected pure virtual

Update the FemElement based on the given state.

Parameters

  state | \((x, v)\) the current position and velocity to evaluate the various terms with
  options | Flag 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.

## getFactory()

FemElement::FactoryType & SurgSim::Physics::FemElement::getFactory | ( |  | ) |

static

## getMass()

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

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

Parameters

  state | The 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

  state | The state to compute the volume with

Returns
  The volume of this element (in m-3)

Implemented in 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

Initialize the FemElement once everything has been set.

Parameters

  state | The state to initialize the FemElement with

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

## initializeFMDK()

void SurgSim::Physics::FemElement::initializeFMDK | ( |  | ) |

protected

Initialize f, M, D, K variables.

## isValidCoordinate()

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

Determines whether a given natural coordinate is valid.

Parameters

  naturalCoordinate | Coordinate to check

Returns
  True if valid

## setMassDensity()

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

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

Parameters

  rho | The mass density

## setNumDofPerNode()

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

protected

Sets the number of degrees of freedom per node.

Parameters

  numDofPerNode | The 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

  nu | The Poisson ratio

## setYoungModulus()

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

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

Parameters

  E | The 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
  options | Flag to specify which of the F, M, D, K needs to be updated

## Member Data Documentation

## m_D

SurgSim::Math::Matrix SurgSim::Physics::FemElement::m_D

protected

The damping matrix.

## m_E

double SurgSim::Physics::FemElement::m_E

protected

Young modulus (in N.m-2)

## m_f

SurgSim::Math::Vector SurgSim::Physics::FemElement::m_f

protected

The force vector.

## m_initializedFMDK

bool SurgSim::Physics::FemElement::m_initializedFMDK

private

Flag to check in the f, M, D, K variables have been initialized.

## m_K

SurgSim::Math::Matrix SurgSim::Physics::FemElement::m_K

protected

The stiffness matrix.

## m_M

SurgSim::Math::Matrix SurgSim::Physics::FemElement::m_M

protected

The mass matrix.

## m_nodeIds

std::vector<size_t> SurgSim::Physics::FemElement::m_nodeIds

protected

Node ids connected by this element.

## m_nu

double SurgSim::Physics::FemElement::m_nu

protected

Poisson ratio (unitless)

## m_numDofPerNode

size_t SurgSim::Physics::FemElement::m_numDofPerNode

protected

Number of degree of freedom per node for this element.

## m_rho

double SurgSim::Physics::FemElement::m_rho

protected

Mass density (in Kg.m-3)

## m_useDamping

bool SurgSim::Physics::FemElement::m_useDamping

protected

Flag to specify of the damping is used.

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

- SurgSim/Physics/FemElement.h
- SurgSim/Physics/FemElement-inl.h
- SurgSim/Physics/FemElement.cpp