- This topic has 5 replies, 2 voices, and was last updated 4 years, 1 month ago by .
Viewing 6 posts - 1 through 6 (of 6 total)
Viewing 6 posts - 1 through 6 (of 6 total)
- You must be logged in to reply to this topic.
Home › Forum › SOFA › Programming with SOFA › Compute forces programatically
Tagged: 64_bits, forces, Linux_other, Plugin_other, SOFA_2006
I want to debug some forces on the initial state of the simulation. What I am doing right now is set the dt to 0 and do a step, that way the correct visitors are launched and the forces are computed, but looks like a hack.
What is the correct way to ask SOFA to compute force? I guess that I will also need to apply mappings before computing forces, and also apply mappings backwards to get the forces back to the DoF nodes.
Hi @jjcasmar,
This is usually done using mechanical operators. In your case, you could create a component that does this:
sofa::core::MechanicalParams mparams (sofa::core::ExecParams::defaultInstance());
sofa::simulation::common::VectorOperations vop( &mparams, this->getContext());
sofa::simulation::common::MechanicalOperations mop( &mparams, this->getContext());
sofa::core::behavior::MultiVecDeriv F( &vop, sofa::core::VecDerivId::force());
// Accumulate the force vectors
// 1. Clear the force vector (F := 0)
// 2. Go down in the current context tree calling addForce on every forcefields
// 3. Go up from the current context tree leaves calling applyJT on every mechanical mappings
mop.computeForce(F);
Jean-Nicolas
the mop.computeForce
takes care of updating the mappings in both directions?
It takes care of propagating the mapped force vector into the system (top level mechanical object) force vector.
So I still need to update the mapping to propagate the positions, right?
Exact, you can use
sofa::simulation::MechanicalPropagateOnlyPositionAndVelocityVisitor(&mparams).execute(this->getContext());
to do so.
WARNING
The forum has been moved to GitHub Discussions.
Old topics and replies are kept here as an archive.