Skip to content

Commit 010326e

Browse files
committed
implement addMBKv
1 parent 924952c commit 010326e

3 files changed

Lines changed: 45 additions & 1 deletion

File tree

Sofa/Component/ODESolver/Backward/src/sofa/component/odesolver/backward/EulerImplicitSolver.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ void EulerImplicitSolver::solve(const core::ExecParams* params, SReal dt, sofa::
149149
msg_info() << "f = " << f;
150150

151151
// add the change of force due to stiffness + Rayleigh damping
152-
mop.addMBKv(b, core::MatricesFactors::M(-d_rayleighMass.getValue()),
152+
mop.addMBKv(m_mappingGraph, b, core::MatricesFactors::M(-d_rayleighMass.getValue()),
153153
core::MatricesFactors::B(0),
154154
core::MatricesFactors::K(h * tr + d_rayleighStiffness.getValue())); // b = f + ( rm M + (h+rs) K ) v
155155

Sofa/framework/Simulation/Core/src/sofa/simulation/MechanicalOperations.cpp

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -380,7 +380,49 @@ void MechanicalOperations::addMBKv(core::MultiVecDerivId df,
380380
mparams.setDx(dx);
381381
}
382382

383+
void MechanicalOperations::addMBKv(const MappingGraph& mappingGraph, core::MultiVecDerivId df,
384+
core::MatricesFactors::M m, core::MatricesFactors::B b,
385+
core::MatricesFactors::K k, bool clear, bool accumulate)
386+
{
387+
const core::ConstMultiVecDerivId dx = mparams.dx();
388+
mparams.setDx(mparams.v());
389+
setDf(df);
390+
if (clear)
391+
{
392+
/**
393+
* Reset forces on all mapped mechanical states in the mapping graph. This operation can be performed
394+
* in any order on all mapped states in the graph.
395+
*/
396+
mappingGraph.algorithms.traverse_([&](core::behavior::BaseMechanicalState& state)
397+
{
398+
const VecDerivId& stateForce = df.getId(&state);
399+
state.resetForce(&mparams, stateForce);
400+
}, VisitorApplication::ONLY_MAPPED_NODES);
401+
}
402+
mparams.setBFactor(b.get());
403+
mparams.setKFactor(k.get());
404+
mparams.setMFactor(m.get());
405+
/* useV = true */
383406

407+
mappingGraph.algorithms.traverseComponentGroups_([&](core::behavior::BaseForceField& forceField)
408+
{
409+
forceField.addMBKdx(&mparams, df);
410+
});
411+
412+
if (accumulate)
413+
{
414+
mappingGraph.algorithms.traverseBottomUp_([&](core::BaseMapping& mapping)
415+
{
416+
mapping.applyJT(&mparams, df, df);
417+
if( mparams.kFactor() == 0 )
418+
{
419+
mapping.applyDJT(&mparams, df, df);
420+
}
421+
});
422+
}
423+
424+
mparams.setDx(dx);
425+
}
384426

385427
/// Add dt*Gravity to the velocity
386428
void MechanicalOperations::addSeparateGravity(SReal dt, core::MultiVecDerivId result)

Sofa/framework/Simulation/Core/src/sofa/simulation/MechanicalOperations.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,8 @@ class SOFA_SIMULATION_CORE_API MechanicalOperations
8989
void addMBKdx(core::MultiVecDerivId df, core::MatricesFactors::M m, core::MatricesFactors::B b, core::MatricesFactors::K k, bool clear = true, bool accumulate = true);
9090
/// accumulate $ df += (m M + b B + k K) velocity $
9191
void addMBKv(core::MultiVecDerivId df, core::MatricesFactors::M m, core::MatricesFactors::B b, core::MatricesFactors::K k, bool clear = true, bool accumulate = true);
92+
/// accumulate $ df += (m M + b B + k K) velocity $
93+
void addMBKv(const MappingGraph& mappingGraph, core::MultiVecDerivId df, core::MatricesFactors::M m, core::MatricesFactors::B b, core::MatricesFactors::K k, bool clear = true, bool accumulate = true);
9294
/// Add dt*Gravity to the velocity
9395
void addSeparateGravity(SReal dt, core::MultiVecDerivId result = core::vec_id::write_access::velocity );
9496

0 commit comments

Comments
 (0)