SOFA API  2a278d89
Open source framework for multi-physics simuation
sofa::component::mass::FEMMass< TDataTypes, TElementType > Class Template Reference

#include <FEMMass.h>

Computes and stores the mass matrix for a finite element model. More...

Inheritance diagram for sofa::component::mass::FEMMass< TDataTypes, TElementType >:

Detailed Description

template<class TDataTypes, class TElementType>
class sofa::component::mass::FEMMass< TDataTypes, TElementType >

Computes and stores the mass matrix for a finite element model.

This class calculates the mass matrix for a given set of finite elements based on a nodal mass density field. The mass matrix is computed using numerical integration (quadrature) over the element domain. The mass density is interpolated from the nodes using the element's shape functions.

Mathematically, the mass matrix M is defined as: $ M_{ij} = \int_{\Omega} \rho(\mathbf{x}) N_i(\mathbf{x}) N_j(\mathbf{x}) d\Omega $ where $ \rho(\mathbf{x}) $ is the mass density and $ N_i(\mathbf{x}) $ are the shape functions.

The resulting matrix is a block-diagonal-like matrix where each block is a scalar multiple of the identity, representing the contribution to each degree of freedom. This allows for efficient storage and computation.

Template Parameters
TDataTypesThe data types used for positions, velocities, etc. (e.g., Vec3Types).
TElementTypeThe type of finite element (e.g., sofa::geometry::Tetrahedron).

Public Attributes

sofa::SingleLink< FEMMass, NodalMassDensity, sofa::BaseLink::FLAG_STOREPATH|sofa::BaseLink::FLAG_STRONGLINKl_nodalMassDensity
 Link to the nodal mass density component. More...
 
- Public Attributes inherited from sofa::core::behavior::BaseForceField
Data< SReal > rayleighStiffness
 Rayleigh Damping stiffness matrix coefficient. More...
 
- Public Attributes inherited from sofa::core::objectmodel::BaseComponent
Data< boolf_listening
 if true, handle the events, otherwise ignore the events More...
 
- Public Attributes inherited from sofa::core::objectmodel::Base
std::vector< lifecycle::DeprecatedData * > m_oldAttributes
 
Data< intd_messageLogCount
 
Data< std::string > name
 Name of the object. More...
 
Data< boolf_printLog
 if true, emits extra messages at runtime. More...
 
Data< sofa::core::objectmodel::TagSetf_tags
 list of the subsets the object belongs to More...
 
Data< sofa::type::BoundingBoxf_bbox
 this object bounding box More...
 
Data< sofa::core::objectmodel::ComponentStated_componentState
 The state of the component among (Dirty, Valid, Undefined, Loading, Invalid). More...
 
std::string m_definitionSourceFileName {""}
 
int m_definitionSourceFilePos {-1}
 
std::string m_instanciationSourceFileName {""}
 
int m_instanciationSourceFilePos {-1}
 
- Public Attributes inherited from sofa::core::behavior::BaseMass
Data< boolm_separateGravity
 
Data< SReal > rayleighMass
 Rayleigh Damping mass matrix coefficient. More...
 
- Public Attributes inherited from sofa::core::behavior::TopologyAccessor
sofa::SingleLink< TopologyAccessor, sofa::core::topology::BaseMeshTopology, sofa::BaseLink::FLAG_STOREPATH|sofa::BaseLink::FLAG_STRONGLINKl_topology
 

Protected Attributes

GlobalMassMatrixType m_globalMassMatrix
 Represents the global mass matrix of the system. More...
 
- Protected Attributes inherited from sofa::core::behavior::Mass< TDataTypes >
std::unique_ptr< std::ofstream > m_gnuplotFileEnergy
 stream to export Kinematic, Potential and Mechanical Energy to gnuplot files More...
 
- Protected Attributes inherited from sofa::core::behavior::StateAccessor
MultiLink< StateAccessor, BaseMechanicalState, BaseLink::FLAG_DUPLICATEl_mechanicalStates
 
- Protected Attributes inherited from sofa::core::objectmodel::BaseComponent
SingleLink< BaseComponent, BaseContext, BaseLink::FLAG_DOUBLELINKl_context
 
LinkSlaves l_slaves
 
SingleLink< BaseComponent, BaseComponent, BaseLink::FLAG_DOUBLELINKl_master
 
- Protected Attributes inherited from sofa::core::objectmodel::Base
std::map< std::string, sofa::core::DataTrackerCallbackm_internalEngine
 
VecData m_vecData
 List of fields (Data instances) More...
 
MapData m_aliasData
 name -> Data multi-map (includes names and aliases) More...
 
VecLink m_vecLink
 List of links. More...
 
MapLink m_aliasLink
 name -> Link multi-map (includes names and aliases) More...
 
- Protected Attributes inherited from sofa::core::behavior::SingleStateAccessor< TDataTypes >
SingleLink< SingleStateAccessor< TDataTypes >, MechanicalState< TDataTypes >, BaseLink::FLAG_STRONGLINK > mstate
 

Static Protected Attributes

static constexpr sofa::Size spatial_dimensions = DataTypes::spatial_dimensions
 
static constexpr sofa::Size NumberOfNodesInElement = ElementType::NumberOfNodes
 
static constexpr sofa::Size NumberOfDofsInElement = NumberOfNodesInElement * spatial_dimensions
 
static constexpr sofa::Size TopologicalDimension = FiniteElement::TopologicalDimension
 

Public Member Functions

 SOFA_CLASS2 (SOFA_TEMPLATE2(FEMMass, DataTypes, ElementType), core::behavior::Mass< TDataTypes >, sofa::core::behavior::TopologyAccessor)
 
void init () final
 Initializes the component. More...
 
bool isDiagonal () const override
 Indicates whether the mass matrix is diagonal. More...
 
void addForce (const core::MechanicalParams *mparams, sofa::DataVecDeriv_t< DataTypes > &f, const sofa::DataVecCoord_t< DataTypes > &x, const sofa::DataVecDeriv_t< DataTypes > &v) override
 Adds the gravity force (f = M * g) to the force vector. More...
 
void buildMassMatrix (sofa::core::behavior::MassMatrixAccumulator *matrices) override
 Accumulates the mass matrix into a global matrix accumulator. More...
 
void addMDx (const core::MechanicalParams *mparams, DataVecDeriv_t< DataTypes > &f, const DataVecDeriv_t< DataTypes > &dx, SReal factor) override
 Adds the product of the mass matrix and a vector to another vector (f += M * dx * factor). More...
 
void accFromF (const core::MechanicalParams *mparams, DataVecDeriv_t< DataTypes > &a, const DataVecDeriv_t< DataTypes > &f) override
 Supposed to compute $ a = M^{-1} f $, but triggers an error in this implementation. More...
 
SReal getKineticEnergy (const core::MechanicalParams *mparams, const DataVecDeriv_t< DataTypes > &v) const override
 Computes the total kinetic energy of the system. More...
 
SReal getPotentialEnergy (const core::MechanicalParams *mparams, const DataVecCoord_t< DataTypes > &x) const override
 Computes the total gravitational potential energy of the system. More...
 
- Public Member Functions inherited from sofa::core::behavior::Mass< TDataTypes >
 SOFA_CLASS2 (SOFA_TEMPLATE(Mass, TDataTypes), SOFA_TEMPLATE(ForceField, TDataTypes), BaseMass)
 
void initGnuplot (const std::string path) override
 initialization to export kinetic and potential energy to gnuplot files format More...
 
void exportGnuplot (const MechanicalParams *mparams, SReal time) override
 export kinetic and potential energy state at "time" to a gnuplot file More...
 
void addGravityToV (const MechanicalParams *mparams, MultiVecDerivId) override
 perform v += dt*g operation. Used if mass wants to added G separately from the other forces to v. More...
 
virtual void addGravityToV (const MechanicalParams *, DataVecDeriv &)
 
SReal getElementMass (sofa::Index) const override
 recover the mass of an element More...
 
void getElementMass (sofa::Index index, linearalgebra::BaseMatrix *m) const override
 Get the matrix relative to the DOF at index. More...
 
bool insertInNode (objectmodel::BaseNode *node) override
 
bool removeInNode (objectmodel::BaseNode *node) override
 
void addMDx (const MechanicalParams *mparams, MultiVecDerivId fid, SReal factor) override
 f += factor M dx More...
 
virtual void addMDx (const MechanicalParams *mparams, DataVecDeriv &f, const DataVecDeriv &dx, SReal factor)
 
void accFromF (const MechanicalParams *mparams, MultiVecDerivId aid) override
 
virtual void accFromF (const MechanicalParams *mparams, DataVecDeriv &a, const DataVecDeriv &f)
 
void addDForce (const MechanicalParams *, DataVecDeriv &, const DataVecDeriv &) override
 Mass forces (gravity) often have null derivative. More...
 
void addMBKdx (const MechanicalParams *mparams, MultiVecDerivId dfId) override
 
SReal getKineticEnergy (const MechanicalParams *mparams) const override
 
virtual SReal getKineticEnergy (const MechanicalParams *mparams, const DataVecDeriv &v) const
 
SReal getPotentialEnergy (const MechanicalParams *mparams) const override
 
SReal getPotentialEnergy (const MechanicalParams *mparams, const DataVecCoord &x) const override
 
type::Vec6 getMomentum (const MechanicalParams *mparams) const override
 
virtual type::Vec6 getMomentum (const MechanicalParams *, const DataVecCoord &, const DataVecDeriv &) const
 
void addKToMatrix (sofa::linearalgebra::BaseMatrix *, SReal, unsigned int &) override
 
void addBToMatrix (sofa::linearalgebra::BaseMatrix *, SReal, unsigned int &) override
 
void addMToMatrix (const MechanicalParams *mparams, const sofa::core::behavior::MultiMatrixAccessor *matrix) override
 Add Mass contribution to global Matrix assembling. More...
 
virtual void addMToMatrix (sofa::linearalgebra::BaseMatrix *matrix, SReal mFact, unsigned int &offset)
 
void addMBKToMatrix (const MechanicalParams *mparams, const sofa::core::behavior::MultiMatrixAccessor *matrix) override
 
- Public Member Functions inherited from sofa::core::behavior::ForceField< TDataTypes >
 SOFA_CLASS2 (SOFA_TEMPLATE(ForceField, TDataTypes), BaseForceField, SOFA_TEMPLATE(SingleStateAccessor, TDataTypes))
 
void addForce (const MechanicalParams *mparams, MultiVecDerivId fId) override
 
virtual void addForce (const MechanicalParams *, DataVecDeriv &f, const DataVecCoord &x, const DataVecDeriv &v)=0
 
void addDForce (const MechanicalParams *mparams, MultiVecDerivId dfId) override
 
void addKToMatrix (const MechanicalParams *mparams, const sofa::core::behavior::MultiMatrixAccessor *matrix) override
 Compute the system matrix corresponding to $ k K $. More...
 
void addBToMatrix (const MechanicalParams *mparams, const sofa::core::behavior::MultiMatrixAccessor *matrix) override
 Compute the system matrix corresponding to $ b B $. More...
 
template<class IndexArray , class ElementMat >
void addToMatrix (sofa::linearalgebra::BaseMatrix *bm, unsigned offset, const IndexArray &nodeIndex, const ElementMat &em, SReal scale)
 
- Public Member Functions inherited from sofa::core::behavior::BaseForceField
 SOFA_ABSTRACT_CLASS (BaseForceField, StateAccessor)
 
virtual void buildStiffnessMatrix (StiffnessMatrix *matrix)
 
virtual void buildDampingMatrix (DampingMatrix *matrix)
 
- Public Member Functions inherited from sofa::core::behavior::StateAccessor
 SOFA_ABSTRACT_CLASS (StateAccessor, objectmodel::BaseComponent)
 
virtual const MultiLink< StateAccessor, BaseMechanicalState, BaseLink::FLAG_DUPLICATE >::Container & getMechanicalStates () const
 Return a list of mechanical states to which this component is associated. More...
 
void computeBBox (const core::ExecParams *params, bool onlyVisible=false) override
 
- Public Member Functions inherited from sofa::core::objectmodel::BaseComponent
 SOFA_CLASS (BaseComponent, Base)
 
virtual void draw (const core::visual::VisualParams *)
 Render internal data of this object, for debugging purposes. More...
 
void setSrc (const std::string &v, std::vector< std::string > *attributeList=nullptr)
 Sets a source Object and parses it to collect dependent Data. More...
 
void setSrc (const std::string &v, const BaseComponent *loader, std::vector< std::string > *attributeList=nullptr)
 
BasefindLinkDestClass (const BaseClass *destType, const std::string &path, const BaseLink *link) override
 
virtual std::string getPathName () const override
 Return the full path name of this object. More...
 
SReal getTime () const
 Current time. More...
 
const BaseContextgetContext () const
 
BaseContextgetContext ()
 
const BaseComponentgetMaster () const
 
BaseComponentgetMaster ()
 
const VecSlavesgetSlaves () const
 
BaseComponentgetSlave (const std::string &name) const
 
virtual void addSlave (BaseComponent::SPtr s)
 
virtual void removeSlave (BaseComponent::SPtr s)
 
virtual void handleEvent (Event *)
 Handle an event. More...
 
virtual void handleTopologyChange ()
 
virtual void handleTopologyChange (core::topology::Topology *t)
 
void parse (BaseObjectDescription *arg) override
 Parse the given description to assign values to this object's fields and potentially other parameters. More...
 
virtual void bwdInit ()
 Initialization method called at graph creation and modification, during bottom-up traversal. More...
 
virtual void reinit ()
 Update method called when variables used in precomputation are modified. More...
 
void updateInternal ()
 Update method called when variables (used to compute other internal variables) are modified. More...
 
virtual void storeResetState ()
 Save the initial state for later uses in reset() More...
 
virtual void reset ()
 Reset to initial state. More...
 
virtual void cleanup ()
 
- Public Member Functions inherited from sofa::core::objectmodel::Base
virtual const BaseClassgetClass () const
 
void addDeprecatedAttribute (lifecycle::DeprecatedData *attribute)
 
void addUpdateCallback (const std::string &name, std::initializer_list< BaseData * > inputs, std::function< sofa::core::objectmodel::ComponentState(const DataTracker &)> function, std::initializer_list< BaseData * > outputs)
 
void addOutputsToCallback (const std::string &name, std::initializer_list< BaseData * > outputs)
 
const std::string & getName () const
 Accessor to the object name. More...
 
void setName (const std::string &n)
 Set the name of this object. More...
 
void setName (const std::string &n, int counter)
 Set the name of this object, adding an integer counter. More...
 
std::string getTypeName () const
 Get the type name of this object (i.e. class and template types) More...
 
virtual std::string getClassName () const
 Get the class name of this object. More...
 
virtual std::string getTemplateName () const final
 Get the template type names (if any) used to instantiate this object. More...
 
std::string getNameSpaceName () const
 Get the template type names (if any) used to instantiate this object. More...
 
void setDefinitionSourceFileName (const std::string &sourceFileName)
 Set the source filename (where the component is implemented) More...
 
const std::string & getDefinitionSourceFileName () const
 Get the source filename (where the component is implemented) More...
 
void setDefinitionSourceFilePos (const int)
 Set the source location (where the component is implemented) More...
 
int getDefinitionSourceFilePos () const
 Get the source location (where the component is implemented) More...
 
void setInstanciationSourceFileName (const std::string &sourceFileName)
 
const std::string & getInstanciationSourceFileName () const
 
void setInstanciationSourceFilePos (const int)
 
int getInstanciationSourceFilePos () const
 
void addMessage (const sofa::helper::logging::Message &m) const
 
size_t countLoggedMessages (sofa::helper::logging::Message::TypeSet t=sofa::helper::logging::Message::AnyTypes) const
 
const std::deque< sofa::helper::logging::Message > & getLoggedMessages () const
 
const std::string getLoggedMessagesAsString (sofa::helper::logging::Message::TypeSet t=sofa::helper::logging::Message::AnyTypes) const
 
void clearLoggedMessages () const
 
bool notMuted () const
 
const sofa::core::objectmodel::TagSetgetTags () const
 Represents the subsets the object belongs to. More...
 
bool hasTag (Tag t) const
 Return true if the object belong to the given subset. More...
 
void addTag (Tag t)
 Add a subset qualification to the object. More...
 
void removeTag (Tag t)
 Remove a subset qualification to the object. More...
 
ComponentState getComponentState () const
 
bool isComponentStateValid () const
 
bool isComponentStateInvalid () const
 
 SOFA_ATTRIBUTE_DEPRECATED__TOBASECONSTRAINT () virtual const behavior
 
 SOFA_ATTRIBUTE_DEPRECATED__TOBASEOBJECT () virtual const objectmodel
 
virtual bool parseField (const std::string &attribute, const std::string &value)
 Assign one field value (Data or Link) More...
 
virtual bool hasField (const std::string &attribute) const
 Check if a given Data field or Link exists. More...
 
void parseFields (const std::list< std::string > &str)
 Assign the field values stored in the given list of name + value pairs of strings. More...
 
virtual void parseFields (const std::map< std::string, std::string * > &str)
 Assign the field values stored in the given map of name -> value pairs. More...
 
void writeDatas (std::ostream &out, const std::string &separator=" ")
 
BaseDatafindData (const std::string &name) const
 
std::vector< BaseData * > findGlobalField (const std::string &name) const
 Find data fields given a name: several can be found as we look into the alias map. More...
 
BaseLinkfindLink (const std::string &name) const
 
std::vector< BaseLink * > findLinks (const std::string &name) const
 Find link fields given a name: several can be found as we look into the alias map. More...
 
virtual void updateLinks (bool logErrors=true)
 Update pointers in case the pointed-to objects have appeared. More...
 
template<class T >
BaseData::BaseInitData initData (::sofa::core::objectmodel::Data< T > *field, const char *n, const char *help, ::sofa::core::objectmodel::BaseData::DataFlags dataflags)
 Helper method used to initialize a data field containing a value of type T. More...
 
template<class T >
BaseData::BaseInitData initData (Data< T > *field, const char *n, const char *help, bool isDisplayed=true, bool isReadOnly=false)
 Helper method used to initialize a data field containing a value of type T. More...
 
template<class T >
Data< T >::InitData initData (Data< T > *field, const T &value, const char *n, const char *help, bool isDisplayed=true, bool isReadOnly=false)
 Helper method used to initialize a data field containing a value of type T. More...
 
void addData (BaseData *f, const std::string &name)
 
void addData (BaseData *f)
 
void removeData (BaseData *f)
 Remove a data field. More...
 
void addAlias (BaseData *field, const char *alias)
 Add an alias to a Data. More...
 
void addLink (BaseLink *l)
 Add a link. More...
 
void addAlias (BaseLink *link, const char *alias)
 Add an alias to a Link. More...
 
const VecDatagetDataFields () const
 Accessor to the vector containing all the fields of this object. More...
 
const MapDatagetDataAliases () const
 Accessor to the map containing all the aliases of this object. More...
 
const VecLinkgetLinks () const
 Accessor to the vector containing all the fields of this object. More...
 
const MapLinkgetLinkAliases () const
 Accessor to the map containing all the aliases of this object. More...
 
virtual bool findDataLinkDest (BaseData *&ptr, const std::string &path, const BaseLink *link)
 
template<class T >
bool findLinkDest (T *&ptr, const std::string &path, const BaseLink *link)
 
- Public Member Functions inherited from sofa::core::behavior::SingleStateAccessor< TDataTypes >
 SOFA_ABSTRACT_CLASS (SOFA_TEMPLATE(SingleStateAccessor, TDataTypes), StateAccessor)
 
void init () override
 Initialization method called at graph creation and modification, during top-down traversal. More...
 
MechanicalState< TDataTypes > * getMState ()
 
const MechanicalState< TDataTypes > * getMState () const
 
- Public Member Functions inherited from sofa::core::behavior::BaseMass
 SOFA_ABSTRACT_CLASS (BaseMass, StateAccessor)
 
- Public Member Functions inherited from sofa::core::behavior::TopologyAccessor
 SOFA_CLASS (TopologyAccessor, sofa::core::objectmodel::BaseComponent)
 
void init () override
 Initialization method called at graph creation and modification, during top-down traversal. More...
 

Protected Member Functions

 FEMMass ()
 Default constructor. More...
 
void elementFEMMass_init ()
 Performs the internal calculation and assembly of the mass matrix. More...
 
void calculateElementMassMatrix (const auto &elements, sofa::type::vector< ElementMassMatrix > &elementMassMatrices)
 Computes the mass matrix for each finite element. More...
 
void initializeGlobalMassMatrix (const auto &elements, const sofa::type::vector< ElementMassMatrix > &elementMassMatrices)
 Assembles the global mass matrix from individual element mass matrices. More...
 
void validateNodalMassDensity ()
 Ensures that a valid NodalMassDensity component is linked. More...
 
- Protected Member Functions inherited from sofa::core::behavior::Mass< TDataTypes >
 Mass (MechanicalState< TDataTypes > *mm=nullptr)
 
 ~Mass () override
 
- Protected Member Functions inherited from sofa::core::behavior::ForceField< TDataTypes >
 ForceField (MechanicalState< DataTypes > *mm=nullptr)
 
 ~ForceField () override
 
- Protected Member Functions inherited from sofa::core::behavior::BaseForceField
 BaseForceField ()
 
 ~BaseForceField () override=default
 
- Protected Member Functions inherited from sofa::core::behavior::StateAccessor
 StateAccessor ()
 
 ~StateAccessor () override=default
 
- Protected Member Functions inherited from sofa::core::objectmodel::BaseComponent
 BaseComponent ()
 
 ~BaseComponent () override
 
virtual void doUpdateInternal ()
 Implementation of the internal update. More...
 
void changeContextLink (BaseContext *before, BaseContext *&after)
 
void changeSlavesLink (BaseComponent::SPtr ptr, std::size_t, bool add)
 This method insures that slaves objects have master and context links set correctly. More...
 
void trackInternalData (const BaseData &data)
 Method called to add the Data to the DataTracker (listing the Data to track) More...
 
void cleanTracker ()
 
bool hasDataChanged (const BaseData &data)
 Method called to know if a tracked Data has changed. More...
 
- Protected Member Functions inherited from sofa::core::objectmodel::Base
 Base ()
 
virtual ~Base ()
 
void initData0 (BaseData *field, BaseData::BaseInitData &res, const char *name, const char *help, bool isDisplayed=true, bool isReadOnly=false)
 Helper method used by initData() More...
 
void initData0 (BaseData *field, BaseData::BaseInitData &res, const char *name, const char *help, BaseData::DataFlags dataFlags)
 Helper method used by initData() More...
 
template<class T >
void initData0 (Data< T > *field, typename Data< T >::InitData &res, const T &value, const char *n, const char *help, bool isDisplayed=true, bool isReadOnly=false)
 Helper method used by initData() More...
 
- Protected Member Functions inherited from sofa::core::IntrusiveObject
virtual ~IntrusiveObject ()=default
 
- Protected Member Functions inherited from sofa::core::behavior::SingleStateAccessor< TDataTypes >
 SingleStateAccessor (MechanicalState< TDataTypes > *mm=nullptr)
 
 ~SingleStateAccessor () override=default
 
- Protected Member Functions inherited from sofa::core::behavior::BaseMass
 BaseMass ()
 
 ~BaseMass () override=default
 
- Protected Member Functions inherited from sofa::core::behavior::TopologyAccessor
 TopologyAccessor ()
 
void validateTopology ()
 

Additional Inherited Members

- Static Public Member Functions inherited from sofa::core::behavior::ForceField< TDataTypes >
template<class T >
static bool canCreate (T *&obj, objectmodel::BaseContext *context, objectmodel::BaseObjectDescription *arg)
 
template<class T >
static std::string shortName (const T *ptr=nullptr, objectmodel::BaseObjectDescription *arg=nullptr)
 
- Static Public Member Functions inherited from sofa::core::objectmodel::BaseComponent
template<class T >
static bool canCreate (T *, BaseContext *, BaseObjectDescription *)
 Pre-construction check method called by ObjectFactory. More...
 
template<class T >
static T::SPtr create (T *, BaseContext *context, BaseObjectDescription *arg)
 Construction method called by ObjectFactory. More...
 
- Static Public Member Functions inherited from sofa::core::objectmodel::Base
static const BaseClassGetClass ()
 
template<class T >
static std::string shortName (const T *ptr=nullptr, BaseObjectDescription *=nullptr)
 

Attribute details

◆ l_nodalMassDensity

template<class TDataTypes , class TElementType >
sofa::SingleLink<FEMMass, NodalMassDensity, sofa::BaseLink::FLAG_STOREPATH | sofa::BaseLink::FLAG_STRONGLINK> sofa::component::mass::FEMMass< TDataTypes, TElementType >::l_nodalMassDensity

Link to the nodal mass density component.

This component provides the mass density at each node of the mesh. It must be present in the context for the mass to be calculated correctly.

◆ m_globalMassMatrix

template<class TDataTypes , class TElementType >
GlobalMassMatrixType sofa::component::mass::FEMMass< TDataTypes, TElementType >::m_globalMassMatrix
protected

Represents the global mass matrix of the system.

This matrix is stored in a compressed sparse row format. Since the mass contribution for each node is isotropic (affects all spatial dimensions identically), this matrix stores only the scalar scaling factor for each identity block of size spatial_dimensions * spatial_dimensions.

For example, in 3D, a node's mass contribution is a 3x3 diagonal matrix m * I. Only m is stored here.

◆ NumberOfDofsInElement

template<class TDataTypes , class TElementType >
constexpr sofa::Size sofa::component::mass::FEMMass< TDataTypes, TElementType >::NumberOfDofsInElement = NumberOfNodesInElement * spatial_dimensions
staticconstexprprotected

◆ NumberOfNodesInElement

template<class TDataTypes , class TElementType >
constexpr sofa::Size sofa::component::mass::FEMMass< TDataTypes, TElementType >::NumberOfNodesInElement = ElementType::NumberOfNodes
staticconstexprprotected

◆ spatial_dimensions

template<class TDataTypes , class TElementType >
constexpr sofa::Size sofa::component::mass::FEMMass< TDataTypes, TElementType >::spatial_dimensions = DataTypes::spatial_dimensions
staticconstexprprotected

◆ TopologicalDimension

template<class TDataTypes , class TElementType >
constexpr sofa::Size sofa::component::mass::FEMMass< TDataTypes, TElementType >::TopologicalDimension = FiniteElement::TopologicalDimension
staticconstexprprotected

Constructor details

◆ FEMMass()

template<class TDataTypes , class TElementType >
sofa::component::mass::FEMMass< TDataTypes, TElementType >::FEMMass
protected

Default constructor.

Function details

◆ accFromF()

template<class TDataTypes , class TElementType >
void sofa::component::mass::FEMMass< TDataTypes, TElementType >::accFromF ( const core::MechanicalParams mparams,
DataVecDeriv_t< DataTypes > &  a,
const DataVecDeriv_t< DataTypes > &  f 
)
override

Supposed to compute $ a = M^{-1} f $, but triggers an error in this implementation.

Parameters
mparamsMechanical parameters for the computation.
aThe result vector of $M^{-1} f$.
fThe vector to be multiplied by the inverse mass matrix.

◆ addForce()

template<class TDataTypes , class TElementType >
void sofa::component::mass::FEMMass< TDataTypes, TElementType >::addForce ( const core::MechanicalParams mparams,
sofa::DataVecDeriv_t< DataTypes > &  f,
const sofa::DataVecCoord_t< DataTypes > &  x,
const sofa::DataVecDeriv_t< DataTypes > &  v 
)
override

Adds the gravity force (f = M * g) to the force vector.

This method computes the product of the mass matrix and the gravity vector, adding the result to the force vector f.

Parameters
mparamsMechanical parameters for the computation.
fThe force vector to which the gravity force will be added.
xThe current positions (unused in this implementation).
vThe current velocities (unused in this implementation).

◆ addMDx()

template<class TDataTypes , class TElementType >
void sofa::component::mass::FEMMass< TDataTypes, TElementType >::addMDx ( const core::MechanicalParams mparams,
DataVecDeriv_t< DataTypes > &  f,
const DataVecDeriv_t< DataTypes > &  dx,
SReal  factor 
)
override

Adds the product of the mass matrix and a vector to another vector (f += M * dx * factor).

This is used for computing accelerations or in iterative solvers.

Parameters
mparamsMechanical parameters for the computation.
fThe result vector to which the product is added.
dxThe vector to be multiplied by the mass matrix.
factorA scaling factor for the product.

◆ buildMassMatrix()

template<class TDataTypes , class TElementType >
void sofa::component::mass::FEMMass< TDataTypes, TElementType >::buildMassMatrix ( sofa::core::behavior::MassMatrixAccumulator matrices)
overridevirtual

Accumulates the mass matrix into a global matrix accumulator.

This is used during the assembly of the system matrix for implicit solvers. It maps the stored sparse mass matrix into the global system matrix.

Parameters
matricesThe accumulator used to build the global system matrix.

Reimplemented from sofa::core::behavior::BaseMass.

◆ calculateElementMassMatrix()

template<class TDataTypes , class TElementType >
void sofa::component::mass::FEMMass< TDataTypes, TElementType >::calculateElementMassMatrix ( const auto &  elements,
sofa::type::vector< ElementMassMatrix > &  elementMassMatrices 
)
protected

Computes the mass matrix for each finite element.

This method iterates over all elements provided by the topology and performs numerical integration (quadrature) to compute the local mass matrix for each element. The mass density is interpolated from the nodal values using the element's shape functions.

Parameters
elementsThe sequence of elements to process.
[out]elementMassMatricesA vector to be populated with the computed local mass matrices.

◆ elementFEMMass_init()

template<class TDataTypes , class TElementType >
void sofa::component::mass::FEMMass< TDataTypes, TElementType >::elementFEMMass_init
protected

Performs the internal calculation and assembly of the mass matrix.

This method iterates over all elements, performs numerical integration to find element-level mass matrices, and then assembles them into the global sparse matrix m_globalMassMatrix.

◆ getKineticEnergy()

template<class TDataTypes , class TElementType >
SReal sofa::component::mass::FEMMass< TDataTypes, TElementType >::getKineticEnergy ( const core::MechanicalParams mparams,
const DataVecDeriv_t< DataTypes > &  v 
) const
override

Computes the total kinetic energy of the system.

The kinetic energy $T$ is computed as: $ T = \frac{1}{2} \mathbf{v}^T \mathbf{M} \mathbf{v} $ where $ \mathbf{M} $ is the global mass matrix and $ \mathbf{v} $ is the velocity vector.

Parameters
mparamsMechanical parameters for the computation.
vThe current velocity vector.
Returns
The computed kinetic energy.

◆ getPotentialEnergy()

template<class TDataTypes , class TElementType >
SReal sofa::component::mass::FEMMass< TDataTypes, TElementType >::getPotentialEnergy ( const core::MechanicalParams mparams,
const DataVecCoord_t< DataTypes > &  x 
) const
override

Computes the total gravitational potential energy of the system.

The potential energy $V$ is computed as: $ V = - \mathbf{x}^T \mathbf{M} \mathbf{g} $ where $ \mathbf{M} $ is the global mass matrix, $ \mathbf{x} $ is the position vector, and $ \mathbf{g} $ is the gravity vector.

Parameters
mparamsMechanical parameters for the computation.
xThe current position vector.
Returns
The computed gravitational potential energy.

◆ init()

template<class TDataTypes , class TElementType >
void sofa::component::mass::FEMMass< TDataTypes, TElementType >::init ( void  )
finalvirtual

Initializes the component.

This method performs several initialization steps:

  1. Initializes the topology accessor.
  2. Initializes the base Mass class.
  3. Validates that a valid nodal mass density is linked.
  4. Computes and assembles the global mass matrix.

Reimplemented from sofa::core::objectmodel::BaseComponent.

◆ initializeGlobalMassMatrix()

template<class TDataTypes , class TElementType >
void sofa::component::mass::FEMMass< TDataTypes, TElementType >::initializeGlobalMassMatrix ( const auto &  elements,
const sofa::type::vector< ElementMassMatrix > &  elementMassMatrices 
)
protected

Assembles the global mass matrix from individual element mass matrices.

This method takes the precomputed local mass matrices and distributes their contributions into the global sparse mass matrix m_globalMassMatrix. It handles the mapping from local element node indices to global degree-of-freedom indices.

Parameters
elementsThe sequence of elements corresponding to the provided mass matrices.
elementMassMatricesThe precomputed local mass matrices for each element.

◆ isDiagonal()

template<class TDataTypes , class TElementType >
bool sofa::component::mass::FEMMass< TDataTypes, TElementType >::isDiagonal ( ) const
inlineoverridevirtual

Indicates whether the mass matrix is diagonal.

Returns
Always returns false, as FEM mass matrices are generally not diagonal (unless lumped).

Implements sofa::core::behavior::BaseMass.

◆ SOFA_CLASS2()

template<class TDataTypes , class TElementType >
sofa::component::mass::FEMMass< TDataTypes, TElementType >::SOFA_CLASS2 ( SOFA_TEMPLATE2(FEMMass< TDataTypes, TElementType >, DataTypes, ElementType ,
core::behavior::Mass< TDataTypes >  ,
sofa::core::behavior::TopologyAccessor   
)

◆ validateNodalMassDensity()

template<class TDataTypes , class TElementType >
void sofa::component::mass::FEMMass< TDataTypes, TElementType >::validateNodalMassDensity
protected

Ensures that a valid NodalMassDensity component is linked.

If no link is set, it attempts to find a suitable component in the current context. If no component is found, it marks the component state as invalid.