SOFA API  d3aee470
Open source framework for multi-physics simuation
sofa::helper::StateMask Class Reference

#include <StateMask.h>

Utility class to handle the mechanism of masks. More...

Detailed Description

Utility class to handle the mechanism of masks.

One of the most time-consuming process in Sofa is the transmission of forces and velocities through the mappings. If only a little subset of particles are used, we would like to propagate those forces (applyJT), and velocities (applyJ) to this subset only.

This class is used inside the BaseMechanicalState.

USAGE:

  • Forcefields, Constraints which acts only on a little number of dofs should use the mask by only adding active entries in the fonction updateForceMask() (the default implementation adds every dofs in the mask)
  • (Multi)Mappings they must propagate the mask from their child (tomodel) to their parents (frommodels) ApplyJ shoud check is the mask is active and use getEntry to check if a child dof is active ApplyJT shoud use getEntry to check if a child dof is active and CAN insert parent dofs in the parent mask. ApplyDJT, getJ/getJs shoud use getEntry to check if a child dof is active updateForceMask() must insert only active parent dofs in the parent mask (or should add nothing if parents have already been added in ApplyJT)

Protected Attributes

size_t m_size
 

Public Member Functions

 StateMask ()
 
void assign (size_t size, bool)
 filling-up (and resizing when necessary) the mask More...
 
void activate (bool)
 
bool isActivated () const
 
void insertEntry (size_t)
 add the given dof index in the mask More...
 
bool getEntry (size_t) const
 
void resize (size_t size)
 getting mask entries is useful for advanced uses. More...
 
void clear ()
 
size_t size () const
 
template<class Real >
void maskedMatrix (Eigen::SparseMatrix< Real, Eigen::RowMajor > &output, const Eigen::SparseMatrix< Real, Eigen::RowMajor > &input, size_t blockSize=1) const
 
size_t nbActiveDofs () const
 return the number of dofs in the mask More...
 
size_t getHash () const
 

Friends

std::ostream & operator<< (std::ostream &os, const StateMask &)
 

Attribute details

size_t sofa::helper::StateMask::m_size
protected

Constructor details

sofa::helper::StateMask::StateMask ( )
inline

Function details

void sofa::helper::StateMask::activate ( bool  )
inline

the mask can be deactivated when the mappings must be applied to every dofs (e.g. propagatePosition) it must be activated when the mappings can be limited to active dofs

void sofa::helper::StateMask::assign ( size_t  size,
bool   
)
inline

filling-up (and resizing when necessary) the mask

void sofa::helper::StateMask::clear ( )
inline
bool sofa::helper::StateMask::getEntry ( size_t  ) const
inline

is the given dof index in the mask?

Warning
always returns the mask value w/o checking if the mask is activated (ie do no forget to check if mask is activated in Mapping::applyJ)
size_t sofa::helper::StateMask::getHash ( ) const
inline
void sofa::helper::StateMask::insertEntry ( size_t  )
inline

add the given dof index in the mask

bool sofa::helper::StateMask::isActivated ( ) const
inline
template<class Real >
void sofa::helper::StateMask::maskedMatrix ( Eigen::SparseMatrix< Real, Eigen::RowMajor > &  output,
const Eigen::SparseMatrix< Real, Eigen::RowMajor > &  input,
size_t  blockSize = 1 
) const
inline

filtering the given input matrix by using the mask as a diagonal projection matrix output = mask.asDiagonal() * input

size_t sofa::helper::StateMask::nbActiveDofs ( ) const
inline

return the number of dofs in the mask

void sofa::helper::StateMask::resize ( size_t  size)
inline

getting mask entries is useful for advanced uses.

size_t sofa::helper::StateMask::size ( void  ) const
inline

Related details

std::ostream& operator<< ( std::ostream &  os,
const StateMask  
)
friend