SOFA API  ca665544
Open source framework for multi-physics simuation
sofa::simulation::common::MechanicalOperations Class Reference

#include <MechanicalOperations.h>

Public Attributes

core::MechanicalParams mparams
 
core::ConstraintParams cparams
 
core::objectmodel::BaseContextctx
 

Protected Attributes

VisitorExecuteFunc executeVisitor
 

Static Protected Attributes

static std::map< core::objectmodel::BaseContext *, boolhasShownMissingLinearSolverMap
 Store if the "missing linear solver" error message has already been shown for a given context. More...
 

Public Member Functions

 MechanicalOperations (const core::MechanicalParams *mparams, core::objectmodel::BaseContext *ctx, bool precomputedTraversalOrder=false)
 
 MechanicalOperations (const core::ExecParams *params, core::objectmodel::BaseContext *ctx, bool precomputedTraversalOrder=false)
 
core::MechanicalParamsoperator-> ()
 
 operator const core::MechanicalParams * ()
 
void addMBKdx (core::MultiVecDerivId df, SReal m, SReal b, SReal k, bool clear=true, bool accumulate=true)
 
void addMBKv (core::MultiVecDerivId df, SReal m, SReal b, SReal k, bool clear=true, bool accumulate=true)
 
void setSystemMBKMatrix (SReal mFact, SReal bFact, SReal kFact, core::behavior::LinearSolver *linearSolver)
 
Mechanical Vector operations
void propagateDx (core::MultiVecDerivId dx, bool ignore_flag=false)
 Propagate the given displacement through all mappings. More...
 
void propagateDxAndResetDf (core::MultiVecDerivId dx, core::MultiVecDerivId df)
 Propagate the given displacement through all mappings and reset the current force delta. More...
 
void propagateX (core::MultiVecCoordId x)
 Propagate the given position through all mappings. More...
 
void propagateV (core::MultiVecDerivId v)
 Propagate the given velocity through all mappings. More...
 
void propagateXAndV (core::MultiVecCoordId x, core::MultiVecDerivId v)
 Propagate the given position and velocity through all mappings. More...
 
void propagateXAndResetF (core::MultiVecCoordId x, core::MultiVecDerivId f)
 Propagate the given position through all mappings and reset the current force delta. More...
 
void projectPosition (core::MultiVecCoordId x, SReal time=0.0)
 Apply projective constraints to the given position vector. More...
 
void projectVelocity (core::MultiVecDerivId v, SReal time=0.0)
 Apply projective constraints to the given velocity vector. More...
 
void projectResponse (core::MultiVecDerivId dx, double **W=nullptr)
 Apply projective constraints to the given vector. More...
 
void projectPositionAndVelocity (core::MultiVecCoordId x, core::MultiVecDerivId v, double time=0.0)
 Apply projective constraints to the given position and velocity vectors. More...
 
void addMdx (core::MultiVecDerivId res, core::MultiVecDerivId dx, SReal factor=1.0)
 res += factor M.dx More...
 
void integrateVelocity (core::MultiVecDerivId res, core::ConstMultiVecCoordId x, core::ConstMultiVecDerivId v, SReal dt)
 res = x + v.dt More...
 
void accFromF (core::MultiVecDerivId a, core::ConstMultiVecDerivId f)
 
void computeEnergy (SReal &kineticEnergy, SReal &potentialEnergy)
 Compute Energy. More...
 
void computeForce (core::MultiVecDerivId result, bool clear=true, bool accumulate=true)
 Compute the current force (given the latest propagated position and velocity) More...
 
void computeDf (core::MultiVecDerivId df, bool clear=true, bool accumulate=true)
 Compute the current force delta (given the latest propagated displacement) More...
 
void computeDfV (core::MultiVecDerivId df, bool clear=true, bool accumulate=true)
 Compute the current force delta (given the latest propagated velocity) More...
 
void addMBKdx (core::MultiVecDerivId df, core::MatricesFactors::M m, core::MatricesFactors::B b, core::MatricesFactors::K k, bool clear=true, bool accumulate=true)
 accumulate $ df += (m M + b B + k K) dx $ (given the latest propagated displacement) More...
 
void addMBKv (core::MultiVecDerivId df, core::MatricesFactors::M m, core::MatricesFactors::B b, core::MatricesFactors::K k, bool clear=true, bool accumulate=true)
 accumulate $ df += (m M + b B + k K) velocity $ More...
 
void addSeparateGravity (SReal dt, core::MultiVecDerivId result=core::vec_id::write_access::velocity)
 Add dt*Gravity to the velocity. More...
 
void computeContactForce (core::MultiVecDerivId result)
 
void computeContactDf (core::MultiVecDerivId df)
 
void computeAcc (SReal t, core::MultiVecDerivId a, core::MultiVecCoordId x, core::MultiVecDerivId v)
 Compute a(x,v) at time t. Parameters x and v not const due to propagation through mappings. More...
 
void computeForce (SReal t, core::MultiVecDerivId f, core::MultiVecCoordId x, core::MultiVecDerivId v)
 Compute f(x,v) at time t. Parameters x and v not const due to propagation through mappings. More...
 
void computeContactAcc (SReal t, core::MultiVecDerivId a, core::MultiVecCoordId x, core::MultiVecDerivId v)
 
Matrix operations
void getMatrixDimension (sofa::Size *const, sofa::Size *const, sofa::core::behavior::MultiMatrixAccessor *matrix=nullptr)
 
void getMatrixDimension (sofa::core::behavior::MultiMatrixAccessor *matrix)
 
void addMBK_ToMatrix (const sofa::core::behavior::MultiMatrixAccessor *matrix, SReal mFact, SReal bFact, SReal kFact)
 
void multiVector2BaseVector (core::ConstMultiVecId src, linearalgebra::BaseVector *dest, const sofa::core::behavior::MultiMatrixAccessor *matrix)
 
void baseVector2MultiVector (const linearalgebra::BaseVector *src, core::MultiVecId dest, const sofa::core::behavior::MultiMatrixAccessor *matrix)
 
void multiVectorPeqBaseVector (core::MultiVecDerivId dest, const linearalgebra::BaseVector *src, const sofa::core::behavior::MultiMatrixAccessor *matrix)
 
Debug operations
void print (core::ConstMultiVecId v, std::ostream &out)
 Dump the content of the given vector. More...
 
void printWithElapsedTime (core::ConstMultiVecId v, unsigned time, std::ostream &out=std::cerr)
 

Protected Member Functions

void setX (core::MultiVecCoordId &v)
 
void setX (core::ConstMultiVecCoordId &v)
 
void setV (core::MultiVecDerivId &v)
 
void setV (core::ConstMultiVecDerivId &v)
 
void setF (core::MultiVecDerivId &v)
 
void setF (core::ConstMultiVecDerivId &v)
 
void setDx (core::MultiVecDerivId &v)
 
void setDx (core::ConstMultiVecDerivId &v)
 
void setDf (core::MultiVecDerivId &v)
 
void setDf (core::ConstMultiVecDerivId &v)
 
void showMissingLinearSolverError () const
 Warn the user that a linear solver is required but has not been found. More...
 

Matrix operations using LinearSolver components

SReal bFact
 
SReal SReal kFact
 
void resetSystem (core::behavior::LinearSolver *linearSolver)
 
void setSystemMBKMatrix (core::MatricesFactors::M m, core::MatricesFactors::B b, core::MatricesFactors::K k, core::behavior::LinearSolver *linearSolver)
 
void setSystemRHVector (core::MultiVecDerivId v, core::behavior::LinearSolver *linearSolver)
 
void setSystemLHVector (core::MultiVecDerivId v, core::behavior::LinearSolver *linearSolver)
 
void solveSystem (core::behavior::LinearSolver *linearSolver)
 
void print (std::ostream &out, core::behavior::LinearSolver *linearSolver)
 
 SOFA_ATTRIBUTE_DEPRECATED_MECHANICALOPERATIONS_RESETSYSTEM () void m_resetSystem()
 
 SOFA_ATTRIBUTE_DEPRECATED_MECHANICALOPERATIONS_SETSYSTEMMBKMATRIX () void m_setSystemMBKMatrix(SReal mFact
 

Attribute details

◆ bFact

SReal sofa::simulation::common::MechanicalOperations::bFact

◆ cparams

core::ConstraintParams sofa::simulation::common::MechanicalOperations::cparams

◆ ctx

core::objectmodel::BaseContext* sofa::simulation::common::MechanicalOperations::ctx

◆ executeVisitor

VisitorExecuteFunc sofa::simulation::common::MechanicalOperations::executeVisitor
protected

◆ hasShownMissingLinearSolverMap

std::map< core::objectmodel::BaseContext *, bool > sofa::simulation::common::MechanicalOperations::hasShownMissingLinearSolverMap
staticprotected

Store if the "missing linear solver" error message has already been shown for a given context.

◆ kFact

SReal SReal sofa::simulation::common::MechanicalOperations::kFact

◆ mparams

core::MechanicalParams sofa::simulation::common::MechanicalOperations::mparams

Constructor details

◆ MechanicalOperations() [1/2]

sofa::simulation::common::MechanicalOperations::MechanicalOperations ( const core::MechanicalParams mparams,
core::objectmodel::BaseContext ctx,
bool  precomputedTraversalOrder = false 
)

◆ MechanicalOperations() [2/2]

sofa::simulation::common::MechanicalOperations::MechanicalOperations ( const core::ExecParams params,
core::objectmodel::BaseContext ctx,
bool  precomputedTraversalOrder = false 
)

Function details

◆ accFromF()

void sofa::simulation::common::MechanicalOperations::accFromF ( core::MultiVecDerivId  a,
core::ConstMultiVecDerivId  f 
)

a = M^-1 . f

Parameters
fa = M^-1 . f

◆ addMBK_ToMatrix()

void sofa::simulation::common::MechanicalOperations::addMBK_ToMatrix ( const sofa::core::behavior::MultiMatrixAccessor matrix,
SReal  mFact,
SReal  bFact,
SReal  kFact 
)

◆ addMBKdx() [1/2]

void sofa::simulation::common::MechanicalOperations::addMBKdx ( core::MultiVecDerivId  df,
core::MatricesFactors::M  m,
core::MatricesFactors::B  b,
core::MatricesFactors::K  k,
bool  clear = true,
bool  accumulate = true 
)

accumulate $ df += (m M + b B + k K) dx $ (given the latest propagated displacement)

◆ addMBKdx() [2/2]

void sofa::simulation::common::MechanicalOperations::addMBKdx ( core::MultiVecDerivId  df,
SReal  m,
SReal  b,
SReal  k,
bool  clear = true,
bool  accumulate = true 
)

◆ addMBKv() [1/2]

void sofa::simulation::common::MechanicalOperations::addMBKv ( core::MultiVecDerivId  df,
core::MatricesFactors::M  m,
core::MatricesFactors::B  b,
core::MatricesFactors::K  k,
bool  clear = true,
bool  accumulate = true 
)

accumulate $ df += (m M + b B + k K) velocity $

◆ addMBKv() [2/2]

void sofa::simulation::common::MechanicalOperations::addMBKv ( core::MultiVecDerivId  df,
SReal  m,
SReal  b,
SReal  k,
bool  clear = true,
bool  accumulate = true 
)

◆ addMdx()

void sofa::simulation::common::MechanicalOperations::addMdx ( core::MultiVecDerivId  res,
core::MultiVecDerivId  dx,
SReal  factor = 1.0 
)

res += factor M.dx

◆ addSeparateGravity()

void sofa::simulation::common::MechanicalOperations::addSeparateGravity ( SReal  dt,
core::MultiVecDerivId  result = core::vec_id::write_access::velocity 
)

Add dt*Gravity to the velocity.

◆ baseVector2MultiVector()

void sofa::simulation::common::MechanicalOperations::baseVector2MultiVector ( const linearalgebra::BaseVector src,
core::MultiVecId  dest,
const sofa::core::behavior::MultiMatrixAccessor matrix 
)

◆ computeAcc()

void sofa::simulation::common::MechanicalOperations::computeAcc ( SReal  t,
core::MultiVecDerivId  a,
core::MultiVecCoordId  x,
core::MultiVecDerivId  v 
)

Compute a(x,v) at time t. Parameters x and v not const due to propagation through mappings.

◆ computeContactAcc()

void sofa::simulation::common::MechanicalOperations::computeContactAcc ( SReal  t,
core::MultiVecDerivId  a,
core::MultiVecCoordId  x,
core::MultiVecDerivId  v 
)

◆ computeContactDf()

void sofa::simulation::common::MechanicalOperations::computeContactDf ( core::MultiVecDerivId  df)

◆ computeContactForce()

void sofa::simulation::common::MechanicalOperations::computeContactForce ( core::MultiVecDerivId  result)

◆ computeDf()

void sofa::simulation::common::MechanicalOperations::computeDf ( core::MultiVecDerivId  df,
bool  clear = true,
bool  accumulate = true 
)

Compute the current force delta (given the latest propagated displacement)

◆ computeDfV()

void sofa::simulation::common::MechanicalOperations::computeDfV ( core::MultiVecDerivId  df,
bool  clear = true,
bool  accumulate = true 
)

Compute the current force delta (given the latest propagated velocity)

◆ computeEnergy()

void sofa::simulation::common::MechanicalOperations::computeEnergy ( SReal kineticEnergy,
SReal potentialEnergy 
)

Compute Energy.

Apply projective constraints to the given velocity vector.

◆ computeForce() [1/2]

void sofa::simulation::common::MechanicalOperations::computeForce ( core::MultiVecDerivId  result,
bool  clear = true,
bool  accumulate = true 
)

Compute the current force (given the latest propagated position and velocity)

◆ computeForce() [2/2]

void sofa::simulation::common::MechanicalOperations::computeForce ( SReal  t,
core::MultiVecDerivId  f,
core::MultiVecCoordId  x,
core::MultiVecDerivId  v 
)

Compute f(x,v) at time t. Parameters x and v not const due to propagation through mappings.

◆ getMatrixDimension() [1/2]

void sofa::simulation::common::MechanicalOperations::getMatrixDimension ( sofa::core::behavior::MultiMatrixAccessor matrix)
inline

◆ getMatrixDimension() [2/2]

void sofa::simulation::common::MechanicalOperations::getMatrixDimension ( sofa::Size * const  nbRow,
sofa::Size * const  nbCol,
sofa::core::behavior::MultiMatrixAccessor matrix = nullptr 
)

◆ integrateVelocity()

void sofa::simulation::common::MechanicalOperations::integrateVelocity ( core::MultiVecDerivId  res,
core::ConstMultiVecCoordId  x,
core::ConstMultiVecDerivId  v,
SReal  dt 
)

res = x + v.dt

◆ multiVector2BaseVector()

void sofa::simulation::common::MechanicalOperations::multiVector2BaseVector ( core::ConstMultiVecId  src,
linearalgebra::BaseVector dest,
const sofa::core::behavior::MultiMatrixAccessor matrix 
)

◆ multiVectorPeqBaseVector()

void sofa::simulation::common::MechanicalOperations::multiVectorPeqBaseVector ( core::MultiVecDerivId  dest,
const linearalgebra::BaseVector src,
const sofa::core::behavior::MultiMatrixAccessor matrix 
)

◆ operator const core::MechanicalParams *()

sofa::simulation::common::MechanicalOperations::operator const core::MechanicalParams * ( )
inline

◆ operator->()

core::MechanicalParams* sofa::simulation::common::MechanicalOperations::operator-> ( )
inline

◆ print() [1/2]

void sofa::simulation::common::MechanicalOperations::print ( core::ConstMultiVecId  v,
std::ostream &  out 
)

Dump the content of the given vector.

◆ print() [2/2]

void sofa::simulation::common::MechanicalOperations::print ( std::ostream &  out,
core::behavior::LinearSolver linearSolver 
)

◆ printWithElapsedTime()

void sofa::simulation::common::MechanicalOperations::printWithElapsedTime ( core::ConstMultiVecId  v,
unsigned  time,
std::ostream &  out = std::cerr 
)

◆ projectPosition()

void sofa::simulation::common::MechanicalOperations::projectPosition ( core::MultiVecCoordId  x,
SReal  time = 0.0 
)

Apply projective constraints to the given position vector.

◆ projectPositionAndVelocity()

void sofa::simulation::common::MechanicalOperations::projectPositionAndVelocity ( core::MultiVecCoordId  x,
core::MultiVecDerivId  v,
double  time = 0.0 
)

Apply projective constraints to the given position and velocity vectors.

◆ projectResponse()

void sofa::simulation::common::MechanicalOperations::projectResponse ( core::MultiVecDerivId  dx,
double **  W = nullptr 
)

Apply projective constraints to the given vector.

◆ projectVelocity()

void sofa::simulation::common::MechanicalOperations::projectVelocity ( core::MultiVecDerivId  v,
SReal  time = 0.0 
)

Apply projective constraints to the given velocity vector.

◆ propagateDx()

void sofa::simulation::common::MechanicalOperations::propagateDx ( core::MultiVecDerivId  dx,
bool  ignore_flag = false 
)

Propagate the given displacement through all mappings.

◆ propagateDxAndResetDf()

void sofa::simulation::common::MechanicalOperations::propagateDxAndResetDf ( core::MultiVecDerivId  dx,
core::MultiVecDerivId  df 
)

Propagate the given displacement through all mappings and reset the current force delta.

◆ propagateV()

void sofa::simulation::common::MechanicalOperations::propagateV ( core::MultiVecDerivId  v)

Propagate the given velocity through all mappings.

◆ propagateX()

void sofa::simulation::common::MechanicalOperations::propagateX ( core::MultiVecCoordId  x)

Propagate the given position through all mappings.

◆ propagateXAndResetF()

void sofa::simulation::common::MechanicalOperations::propagateXAndResetF ( core::MultiVecCoordId  x,
core::MultiVecDerivId  f 
)

Propagate the given position through all mappings and reset the current force delta.

◆ propagateXAndV()

void sofa::simulation::common::MechanicalOperations::propagateXAndV ( core::MultiVecCoordId  x,
core::MultiVecDerivId  v 
)

Propagate the given position and velocity through all mappings.

◆ resetSystem()

void sofa::simulation::common::MechanicalOperations::resetSystem ( core::behavior::LinearSolver linearSolver)

◆ setDf() [1/2]

void sofa::simulation::common::MechanicalOperations::setDf ( core::ConstMultiVecDerivId v)
protected

◆ setDf() [2/2]

void sofa::simulation::common::MechanicalOperations::setDf ( core::MultiVecDerivId v)
protected

◆ setDx() [1/2]

void sofa::simulation::common::MechanicalOperations::setDx ( core::ConstMultiVecDerivId v)
protected

◆ setDx() [2/2]

void sofa::simulation::common::MechanicalOperations::setDx ( core::MultiVecDerivId v)
protected

◆ setF() [1/2]

void sofa::simulation::common::MechanicalOperations::setF ( core::ConstMultiVecDerivId v)
protected

◆ setF() [2/2]

void sofa::simulation::common::MechanicalOperations::setF ( core::MultiVecDerivId v)
protected

◆ setSystemLHVector()

void sofa::simulation::common::MechanicalOperations::setSystemLHVector ( core::MultiVecDerivId  v,
core::behavior::LinearSolver linearSolver 
)

◆ setSystemMBKMatrix() [1/2]

void sofa::simulation::common::MechanicalOperations::setSystemMBKMatrix ( core::MatricesFactors::M  m,
core::MatricesFactors::B  b,
core::MatricesFactors::K  k,
core::behavior::LinearSolver linearSolver 
)

◆ setSystemMBKMatrix() [2/2]

void sofa::simulation::common::MechanicalOperations::setSystemMBKMatrix ( SReal  mFact,
SReal  bFact,
SReal  kFact,
core::behavior::LinearSolver linearSolver 
)

◆ setSystemRHVector()

void sofa::simulation::common::MechanicalOperations::setSystemRHVector ( core::MultiVecDerivId  v,
core::behavior::LinearSolver linearSolver 
)

◆ setV() [1/2]

void sofa::simulation::common::MechanicalOperations::setV ( core::ConstMultiVecDerivId v)
protected

◆ setV() [2/2]

void sofa::simulation::common::MechanicalOperations::setV ( core::MultiVecDerivId v)
protected

◆ setX() [1/2]

void sofa::simulation::common::MechanicalOperations::setX ( core::ConstMultiVecCoordId v)
protected

◆ setX() [2/2]

void sofa::simulation::common::MechanicalOperations::setX ( core::MultiVecCoordId v)
protected

◆ showMissingLinearSolverError()

void sofa::simulation::common::MechanicalOperations::showMissingLinearSolverError ( ) const
protected

Warn the user that a linear solver is required but has not been found.

◆ SOFA_ATTRIBUTE_DEPRECATED_MECHANICALOPERATIONS_RESETSYSTEM()

sofa::simulation::common::MechanicalOperations::SOFA_ATTRIBUTE_DEPRECATED_MECHANICALOPERATIONS_RESETSYSTEM ( )

◆ SOFA_ATTRIBUTE_DEPRECATED_MECHANICALOPERATIONS_SETSYSTEMMBKMATRIX()

sofa::simulation::common::MechanicalOperations::SOFA_ATTRIBUTE_DEPRECATED_MECHANICALOPERATIONS_SETSYSTEMMBKMATRIX ( )

◆ solveSystem()

void sofa::simulation::common::MechanicalOperations::solveSystem ( core::behavior::LinearSolver linearSolver)