6 December 2021 at 5 h 19 min #21057
I would like to get the constraint forces from the GenericConstraintSolver and pass them to my class but I have not been able to do so as all I get are zero/null values.
The address of the constraint forces can be retrieved within the GenericConstraintSolver class by
How can I go about doing this outside the GenericConstraintSolver? Any help/ideas would be appreciated. Thanks.6 December 2021 at 16 h 31 min #21064
From what I see you are attempting to do this in C++. Correct?
The GenericConstraintSolver has two dedicated options to compute the constraint forces:
computeConstraintForces: boolean enablin the storage of the constraintForces
constraintForces: vector containing the constraint forces
The type of
type::vector< double >, make sure you are accessing it properly (WriteAccessor) and that you use the proper data type.
Since both are SOFA data, you can access them from outside the GenericConstraintSover.
Do you see my point?
Do you have a code snippet on your end that we could edit?
Hugo7 December 2021 at 6 h 57 min #21070
Thanks for the reply! For example if we’d like to print out the values of the constraint forces from another class.
sofa::component::constraintset::GenericConstraintSolver* solver; Data<type::vector< double >> constraintForces = solver->d_constraintForces.getValue(); if (condition) msg_info("Constraint Forces") << constraintForces;
How could I go about this?7 December 2021 at 21 h 52 min #21079
Ok then you could write something like:
sofa::component::constraintset::GenericConstraintSolver* solver; type::vector< double > constraintForces = solver->d_constraintForces.getValue(); if (condition) msg_info("Constraint Forces") << constraintForces;
Keep us posted if this helps.
How do you get the pointer to the GenericConstraintSolver?
Hugo8 December 2021 at 6 h 26 min #21085
@Hugo, that perhaps is my question. How do I get the pointer to the GenericConstraintSolver?10 December 2021 at 22 h 12 min #21121
This depends on where/what is your code supposed to be implemented?
What is this C++ code you want to write?
Hugo11 December 2021 at 10 h 30 min #21122
I would like to impose different constraints depending on the contact force. So for example, in the SOFA class FrictionContact(FrictionContact -SOFA API), in the
createResponsefunction, I’d like to reference the ConstraintSolver so I can impose a contact depending on the force. I appreciate any help you can offer on this. Thanks14 December 2021 at 16 h 41 min #21138
I was able to solve it like this:
core::objectmodel::BaseContext* context = this->getContext(); context->get(constraintSolver);
and finally the constraint forces can be printed out:
msg_info("constraint forces") << constraintSolver->getConstraintProblem()->f;9 January 2022 at 18 h 40 min #21334
- You must be logged in to reply to this topic.