SOFA plugin: MultiThreading  03b3d92c
Open source framework for multi-physics simuation
sofa::component::forcefield::ParallelHexahedronFEMForceField< DataTypes > Class Template Reference

#include <ParallelHexahedronFEMForceField.h>

Inheritance diagram for sofa::component::forcefield::ParallelHexahedronFEMForceField< DataTypes >:

Detailed Description

template<class DataTypes>
class sofa::component::forcefield::ParallelHexahedronFEMForceField< DataTypes >

Parallel implementation of HexahedronFEMForceField

This implementation is the most efficient when: 1) the number of hexahedron is large (> 1000) 2) the global system matrix is not assembled. It is usually the case with a CGLinearSolver templated with GraphScattered types. 3) the method is 'large'. If the method is 'polar' or 'small', addForce is executed sequentially, but addDForce in parallel.

The following methods are executed in parallel:

  • addForce for method 'large'.
  • addDForce

The method addKToMatrix is not executed in parallel. This method is called with an assembled system, usually with a direct solver or a CGLinearSolver templated with types different from GraphScattered. In this case, the most time-consumming step is to invert the matrix. This is where efforts should be put to accelerate the simulation.

Protected Attributes

std::vector< AccumulateForceLargeTasks< DataTypes > > m_accumulateForceLargeTasks
 
std::vector< AddDForceTask< DataTypes > > m_addDForceTasks
 
- Protected Attributes inherited from sofa::component::forcefield::HexahedronFEMForceField< DataTypes >
VecMaterialStiffness _materialsStiffnesses
 
Data< VecElementStiffness > _elementStiffnesses
 
CompressedMatrix _stiffnesses
 
SReal m_potentialEnergy
 
sofa::core::topology::BaseMeshTopologym_topology
 
topology::SparseGridTopology_sparseGrid
 
Data< VecCoord > _initialPoints
 
type::Mat< 8, 3, int > _coef
 
HexahedronFEMForceFieldInternalData< DataTypes > * data
 
type::vector< type::fixed_array< Coord, 8 > > _rotatedInitialElements
 
type::vector< Transformation > _rotations
 
type::vector< Transformation > _initialrotations
 
bool _alreadyInit
 
- Protected Attributes inherited from ForceField< DataTypes >
SingleLink< ForceField< DataTypes >, MechanicalState< DataTypes >, BaseLink::FLAG_STRONGLINK > mstate
 
- Protected Attributes inherited from sofa::core::objectmodel::BaseObject
SingleLink< BaseObject, BaseContext, BaseLink::FLAG_DOUBLELINK > l_context
 
LinkSlaves l_slaves
 
SingleLink< BaseObject, BaseObject, BaseLink::FLAG_DOUBLELINK > l_master
 
- Protected Attributes inherited from sofa::core::objectmodel::Base
std::map< std::string, sofa::core::DataTrackerCallbackm_internalEngine
 
VecData m_vecData
 
MapData m_aliasData
 
VecLink m_vecLink
 
MapLink m_aliasLink
 

Public Member Functions

 SOFA_CLASS (SOFA_TEMPLATE(ParallelHexahedronFEMForceField, DataTypes), SOFA_TEMPLATE(HexahedronFEMForceField, DataTypes))
 
void init () override
 
void addForce (const core::MechanicalParams *mparams, DataVecDeriv &f, const DataVecCoord &x, const DataVecDeriv &v) override
 
void addDForce (const core::MechanicalParams *mparams, DataVecDeriv &df, const DataVecDeriv &dx) override
 
- Public Member Functions inherited from sofa::component::forcefield::HexahedronFEMForceField< DataTypes >
 SOFA_CLASS (SOFA_TEMPLATE(HexahedronFEMForceField, DataTypes), SOFA_TEMPLATE(core::behavior::ForceField, DataTypes))
 
void setPoissonRatio (Real val)
 
void setYoungModulus (Real val)
 
void setMethod (int val)
 
void setUpdateStiffnessMatrix (bool val)
 
void setComputeGlobalMatrix (bool val)
 
void reinit () override
 
void addForce (const core::MechanicalParams *mparams, DataVecDeriv &f, const DataVecCoord &x, const DataVecDeriv &v) override
 
void addDForce (const core::MechanicalParams *mparams, DataVecDeriv &df, const DataVecDeriv &dx) override
 
SReal getPotentialEnergy (const core::MechanicalParams *, const DataVecCoord &) const override
 
SReal getPotentialEnergy (const core::MechanicalParams *) const override
 
const Transformation & getElementRotation (const sofa::Index elemidx)
 
void getNodeRotation (Transformation &R, sofa::Index nodeIdx)
 
void getRotations (defaulttype::BaseMatrix *rotations, int offset=0) override
 
void addKToMatrix (const core::MechanicalParams *mparams, const sofa::core::behavior::MultiMatrixAccessor *matrix) override
 
void computeBBox (const core::ExecParams *params, bool onlyVisible) override
 
void draw (const core::visual::VisualParams *vparams) override
 
void handleTopologyChange () override
 
- Public Member Functions inherited from ForceField< DataTypes >
 SOFA_CLASS (SOFA_TEMPLATE(ForceField, DataTypes), BaseForceField)
 
MechanicalState< DataTypes > * getMState ()
 
const MechanicalState< DataTypes > * getMState () const
 
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
 
virtual void addDForce (const MechanicalParams *mparams, DataVecDeriv &df, const DataVecDeriv &dx)=0
 
void addClambda (const MechanicalParams *mparams, MultiVecDerivId resId, MultiVecDerivId lambdaId, SReal cFactor) override
 
virtual void addClambda (const MechanicalParams *mparams, DataVecDeriv &df, const DataVecDeriv &lambda, SReal cFactor)
 
SReal getPotentialEnergy (const MechanicalParams *mparams) const override
 
virtual SReal getPotentialEnergy (const MechanicalParams *, const DataVecCoord &x) const =0
 
void addKToMatrix (const MechanicalParams *mparams, const sofa::core::behavior::MultiMatrixAccessor *matrix) override
 
virtual void addKToMatrix (sofa::defaulttype::BaseMatrix *matrix, SReal kFact, unsigned int &offset)
 
void addBToMatrix (const MechanicalParams *mparams, const sofa::core::behavior::MultiMatrixAccessor *matrix) override
 
virtual void addBToMatrix (sofa::defaulttype::BaseMatrix *matrix, SReal bFact, unsigned int &offset)
 
void addToMatrix (sofa::defaulttype::BaseMatrix *bm, unsigned offset, const IndexArray &nodeIndex, const ElementMat &em, SReal scale)
 
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
 
virtual void addDForce (const MechanicalParams *mparams, DataVecDeriv &df, const DataVecDeriv &dx)=0
 
void addClambda (const MechanicalParams *mparams, MultiVecDerivId resId, MultiVecDerivId lambdaId, SReal cFactor) override
 
virtual void addClambda (const MechanicalParams *mparams, DataVecDeriv &df, const DataVecDeriv &lambda, SReal cFactor)
 
SReal getPotentialEnergy (const MechanicalParams *mparams) const override
 
virtual SReal getPotentialEnergy (const MechanicalParams *, const DataVecCoord &x) const =0
 
void addKToMatrix (const MechanicalParams *mparams, const sofa::core::behavior::MultiMatrixAccessor *matrix) override
 
virtual void addKToMatrix (sofa::defaulttype::BaseMatrix *matrix, SReal kFact, unsigned int &offset)
 
void addBToMatrix (const MechanicalParams *mparams, const sofa::core::behavior::MultiMatrixAccessor *matrix) override
 
virtual void addBToMatrix (sofa::defaulttype::BaseMatrix *matrix, SReal bFact, unsigned int &offset)
 
void addToMatrix (sofa::defaulttype::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, objectmodel::BaseObject)
 
bool insertInNode (objectmodel::BaseNode *node) override
 
bool removeInNode (objectmodel::BaseNode *node) override
 
virtual void addForce (const MechanicalParams *mparams, MultiVecDerivId fId)=0
 
virtual void addDForce (const MechanicalParams *mparams, MultiVecDerivId dfId)=0
 
virtual void addMBKdx (const MechanicalParams *mparams, MultiVecDerivId dfId)
 
virtual void addBToMatrix (const MechanicalParams *mparams, const sofa::core::behavior::MultiMatrixAccessor *matrix)
 
virtual void addMBKToMatrix (const MechanicalParams *mparams, const sofa::core::behavior::MultiMatrixAccessor *matrix)
 
virtual void addForce (const MechanicalParams *mparams, MultiVecDerivId fId)=0
 
virtual void addDForce (const MechanicalParams *mparams, MultiVecDerivId dfId)=0
 
virtual void addMBKdx (const MechanicalParams *mparams, MultiVecDerivId dfId)
 
virtual void addBToMatrix (const MechanicalParams *mparams, const sofa::core::behavior::MultiMatrixAccessor *matrix)
 
virtual void addMBKToMatrix (const MechanicalParams *mparams, const sofa::core::behavior::MultiMatrixAccessor *matrix)
 
virtual const sofa::defaulttype::BaseMatrixgetComplianceMatrix (const MechanicalParams *)
 
virtual void addClambda (const MechanicalParams *, MultiVecDerivId, MultiVecDerivId, SReal)
 
- Public Member Functions inherited from sofa::core::objectmodel::BaseObject
 SOFA_CLASS (BaseObject, Base)
 
void setSrc (const std::string &v, std::vector< std::string > *attributeList=nullptr)
 
void setSrc (const std::string &v, const BaseObject *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
 
SReal getTime () const
 
void parse (BaseObjectDescription *arg) override
 
virtual void bwdInit ()
 
void updateInternal ()
 
virtual void storeResetState ()
 
virtual void reset ()
 
virtual void cleanup ()
 
const BaseContextgetContext () const
 
BaseContextgetContext ()
 
const BaseObjectgetMaster () const
 
BaseObjectgetMaster ()
 
const VecSlavesgetSlaves () const
 
BaseObjectgetSlave (const std::string &name) const
 
virtual void addSlave (BaseObject::SPtr s)
 
virtual void removeSlave (BaseObject::SPtr s)
 
SReal getTime () const
 
virtual void handleEvent (Event *)
 
virtual void handleTopologyChange (core::topology::Topology *t)
 
- Public Member Functions inherited from sofa::core::objectmodel::Base
virtual const BaseClassgetClass () const
 
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
 
void setName (const std::string &n)
 
void setName (const std::string &n, int counter)
 
virtual std::string getTypeName () const
 
virtual std::string getClassName () const
 
virtual std::string getTemplateName () const
 
virtual std::string getNameSpaceName () const
 
void setDefinitionSourceFileName (const std::string &sourceFileName)
 
const std::string & getDefinitionSourceFileName () const
 
void setDefinitionSourceFilePos (const int)
 
int getDefinitionSourceFilePos () const
 
void setInstanciationSourceFileName (const std::string &sourceFileName)
 
const std::string & getInstanciationSourceFileName () const
 
void setInstanciationSourceFilePos (const int)
 
int getInstanciationSourceFilePos () const
 
void processStream (std::ostream &out)
 
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
 
bool IsInheritingFromBase ()
 
const sofa::core::objectmodel::TagSetgetTags () const
 
bool hasTag (Tag t) const
 
void addTag (Tag t)
 
void removeTag (Tag t)
 
ComponentState getComponentState () const
 
bool isComponentStateValid () const
 
virtual bool parseField (const std::string &attribute, const std::string &value)
 
virtual bool hasField (const std::string &attribute) const
 
void parseFields (const std::list< std::string > &str)
 
virtual void parseFields (const std::map< std::string, std::string * > &str)
 
void writeDatas (std::map< std::string, std::string * > &str)
 
void writeDatas (std::ostream &out, const std::string &separator=" ")
 
BaseDatafindData (const std::string &name) const
 
std::vector< BaseData * > findGlobalField (const std::string &name) const
 
BaseLinkfindLink (const std::string &name) const
 
std::vector< BaseLink * > findLinks (const std::string &name) const
 
virtual void updateLinks (bool logErrors=true)
 
BaseData::BaseInitData initData (Data< T > *field, const char *name, const char *help, bool isDisplayed=true, bool isReadOnly=false)
 
Data< T >::InitData initData (Data< T > *field, const T &value, const char *name, const char *help, bool isDisplayed=true, bool isReadOnly=false)
 
void addData (BaseData *f, const std::string &name)
 
void addData (BaseData *f)
 
void removeData (BaseData *f)
 
void addAlias (BaseData *field, const char *alias)
 
void addLink (BaseLink *l)
 
void addAlias (BaseLink *link, const char *alias)
 
const VecDatagetDataFields () const
 
const MapDatagetDataAliases () const
 
const VecLinkgetLinks () const
 
const MapLinkgetLinkAliases () const
 
virtual bool findDataLinkDest (BaseData *&ptr, const std::string &path, const BaseLink *link)
 
bool findLinkDest (T *&ptr, const std::string &path, const BaseLink *link)
 
const sofa::core::objectmodel::TagSetgetTags () const
 
bool hasTag (Tag t) const
 
void addTag (Tag t)
 
void removeTag (Tag t)
 
ComponentState getComponentState () const
 
bool isComponentStateValid () const
 

Protected Member Functions

void computeTaskForceLarge (RDataRefVecCoord &p, sofa::Index elementId, const Element &elem, const VecElementStiffness &elementStiffnesses, SReal &OutPotentialEnery, type::Vec< 8, Deriv > &OutF)
 
void initTaskScheduler ()
 
- Protected Member Functions inherited from sofa::component::forcefield::HexahedronFEMForceField< DataTypes >
 HexahedronFEMForceField ()
 
const VecElement * getIndexedElements ()
 
virtual void computeElementStiffness (ElementStiffness &K, const MaterialStiffness &M, const type::fixed_array< Coord, 8 > &nodes, const sofa::Index elementIndice, double stiffnessFactor=1.0) const
 
void computeMaterialStiffness (sofa::Index i)
 
void initLarge (int i, const Element &elem)
 
virtual void accumulateForceLarge (WDataRefVecDeriv &f, RDataRefVecCoord &p, sofa::Index i, const Element &elem)
 
void initPolar (int i, const Element &elem)
 
void computeRotationPolar (Transformation &r, type::Vec< 8, Coord > &nodes)
 
virtual void accumulateForcePolar (WDataRefVecDeriv &f, RDataRefVecCoord &p, sofa::Index i, const Element &elem)
 
void initSmall (int i, const Element &elem)
 
virtual void accumulateForceSmall (WDataRefVecDeriv &f, RDataRefVecCoord &p, sofa::Index i, const Element &elem)
 
- Protected Member Functions inherited from ForceField< DataTypes >
 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::objectmodel::BaseObject
 BaseObject ()
 
 ~BaseObject () override
 
virtual void doUpdateInternal ()
 
void changeContextLink (BaseContext *before, BaseContext *&after)
 
void changeSlavesLink (BaseObject::SPtr ptr, std::size_t, bool add)
 
void trackInternalData (const BaseData &data)
 
void cleanTracker ()
 
bool hasDataChanged (const BaseData &data)
 
- 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)
 
void initData0 (BaseData *field, BaseData::BaseInitData &res, const char *name, const char *help, BaseData::DataFlags dataFlags)
 
void initData0 (Data< T > *field, typename Data< T >::InitData &res, const T &value, const char *name, const char *help, bool isDisplayed=true, bool isReadOnly=false)
 

Friends

class AccumulateForceLargeTasks< DataTypes >
 
class AddDForceTask< DataTypes >
 

Additional Inherited Members

- Public Attributes inherited from sofa::component::forcefield::HexahedronFEMForceField< DataTypes >
int method
 
Data< std::string > f_method
 
Data< Real > f_poissonRatio
 
Data< Real > f_youngModulus
 
Data< boolf_updateStiffnessMatrix
 
Data< boolf_assembling
 
Data< sofa::helper::OptionsGroup_gatherPt
 
Data< sofa::helper::OptionsGroup_gatherBsize
 
Data< boolf_drawing
 
Data< Real > f_drawPercentageOffset
 
bool needUpdateTopology
 
SingleLink< HexahedronFEMForceField< DataTypes >, sofa::core::topology::BaseMeshTopology, BaseLink::FLAG_STOREPATH|BaseLink::FLAG_STRONGLINK > l_topology
 
- Public Attributes inherited from sofa::core::behavior::BaseForceField
Data< SReal > rayleighStiffness
 
Data< boolisCompliance
 
- Public Attributes inherited from sofa::core::objectmodel::BaseObject
Data< boolf_listening
 
- Public Attributes inherited from sofa::core::objectmodel::Base
helper::system::SofaOStream< helper::logging::Message::Warning > serr
 
helper::system::SofaOStream< helper::logging::Message::Info > sout
 
helper::system::SofaEndl< Basesendl
 
Data< std::string > name
 
Data< boolf_printLog
 
Data< sofa::core::objectmodel::TagSetf_tags
 
Data< sofa::type::BoundingBoxf_bbox
 
Data< sofa::core::objectmodel::ComponentStated_componentState
 
DeprecatedAndRemoved m_componentstate
 
DeprecatedAndRemoved d_componentstate
 
std::string m_definitionSourceFileName
 
int m_definitionSourceFilePos
 
std::string m_instanciationSourceFileName
 
int m_instanciationSourceFilePos
 
- Static Public Member Functions inherited from ForceField< DataTypes >
static bool canCreate (T *&obj, objectmodel::BaseContext *context, objectmodel::BaseObjectDescription *arg)
 
static std::string shortName (const T *ptr=nullptr, objectmodel::BaseObjectDescription *arg=nullptr)
 
- Static Public Member Functions inherited from sofa::core::objectmodel::BaseObject
static bool canCreate (T *, BaseContext *, BaseObjectDescription *)
 
static T::SPtr create (T *, BaseContext *context, BaseObjectDescription *arg)
 
- Static Public Member Functions inherited from sofa::core::objectmodel::Base
static const BaseClassGetClass ()
 
static std::string typeName (const T *ptr=nullptr)=delete
 
static std::string className (const T *ptr=nullptr)=delete
 
static std::string namespaceName (const T *ptr=nullptr)=delete
 
static std::string templateName (const T *ptr=nullptr)=delete
 
static std::string shortName (const T *ptr=nullptr, BaseObjectDescription *=nullptr)
 
- Static Protected Member Functions inherited from sofa::component::forcefield::HexahedronFEMForceField< DataTypes >
static Mat33 integrateStiffness (int signx0, int signy0, int signz0, int signx1, int signy1, int signz1, const Real u, const Real v, const Real w, const Mat33 &J_1)
 
static void computeForce (Displacement &F, const Displacement &Depl, const ElementStiffness &K)
 
static void computeRotationLarge (Transformation &r, Coord &edgex, Coord &edgey)
 

Attribute details

template<class DataTypes >
std::vector<AccumulateForceLargeTasks<DataTypes> > sofa::component::forcefield::ParallelHexahedronFEMForceField< DataTypes >::m_accumulateForceLargeTasks
protected
template<class DataTypes >
std::vector<AddDForceTask<DataTypes> > sofa::component::forcefield::ParallelHexahedronFEMForceField< DataTypes >::m_addDForceTasks
protected

Function details

template<class DataTypes >
void sofa::component::forcefield::ParallelHexahedronFEMForceField< DataTypes >::addDForce ( const core::MechanicalParams mparams,
DataVecDeriv df,
const DataVecDeriv dx 
)
override
template<class DataTypes >
void sofa::component::forcefield::ParallelHexahedronFEMForceField< DataTypes >::addForce ( const core::MechanicalParams mparams,
DataVecDeriv f,
const DataVecCoord x,
const DataVecDeriv v 
)
override
template<class DataTypes >
void sofa::component::forcefield::ParallelHexahedronFEMForceField< DataTypes >::computeTaskForceLarge ( RDataRefVecCoord p,
sofa::Index  elementId,
const Element elem,
const VecElementStiffness elementStiffnesses,
SReal &  OutPotentialEnery,
type::Vec< 8, Deriv > &  OutF 
)
protected
template<class DataTypes >
void sofa::component::forcefield::ParallelHexahedronFEMForceField< DataTypes >::init ( void  )
overridevirtual
template<class DataTypes >
void sofa::component::forcefield::ParallelHexahedronFEMForceField< DataTypes >::initTaskScheduler ( )
protected
template<class DataTypes >
sofa::component::forcefield::ParallelHexahedronFEMForceField< DataTypes >::SOFA_CLASS ( SOFA_TEMPLATE(ParallelHexahedronFEMForceField< DataTypes >, DataTypes)  ,
SOFA_TEMPLATE(HexahedronFEMForceField, DataTypes)   
)

Related details

template<class DataTypes >
friend class AccumulateForceLargeTasks< DataTypes >
friend
template<class DataTypes >
friend class AddDForceTask< DataTypes >
friend