Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SofaConstraint] ADD Data to show constraint forces #840

Merged
merged 12 commits into from
Dec 13, 2018
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 13 additions & 4 deletions modules/SofaConstraint/GenericConstraintSolver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ GenericConstraintSolver::GenericConstraintSolver()
, currentError(initData(&currentError, 0.0, "currentError", "OUTPUT: current error"))
, reverseAccumulateOrder(initData(&reverseAccumulateOrder, false, "reverseAccumulateOrder", "True to accumulate constraints from nodes in reversed order (can be necessary when using multi-mappings or interaction constraints not following the node hierarchy)"))
, current_cp(&m_cpBuffer[0])
, d_constraintForces(initData(&d_constraintForces,"constraintForces","Constraint forces"))
, last_cp(NULL)
{
addAlias(&maxIt, "maxIt");
Expand Down Expand Up @@ -332,7 +333,7 @@ void GenericConstraintSolver::rebuildSystem(double massFactor, double forceFacto
}
}

void afficheLCP(std::ostream& file, double *q, double **M, double *f, int dim, bool printMatrix = true)
void printLCP(std::ostream& file, double *q, double **M, double *f, int dim, bool printMatrix = true)
{
file.precision(9);
// affichage de la matrice du LCP
Expand Down Expand Up @@ -383,7 +384,7 @@ bool GenericConstraintSolver::solveSystem(const core::ConstraintParams * /*cPara
{
std::stringstream tmp;
tmp << "---> Before Resolution" << msgendl ;
afficheLCP(tmp, current_cp->getDfree(), current_cp->getW(), current_cp->getF(), current_cp->getDimension(), true);
printLCP(tmp, current_cp->getDfree(), current_cp->getW(), current_cp->getF(), current_cp->getDimension(), true);

msg_info() << tmp.str() ;
}
Expand All @@ -408,8 +409,16 @@ bool GenericConstraintSolver::solveSystem(const core::ConstraintParams * /*cPara
{
std::stringstream tmp;
tmp << "---> After Resolution" << msgendl;
afficheLCP(tmp, current_cp->_d.ptr(), current_cp->getW(), current_cp->getF(), current_cp->getDimension(), false);
msg_info() << tmp.str() ;
printLCP(tmp, current_cp->_d.ptr(), current_cp->getW(), current_cp->getF(), current_cp->getDimension(), false);
msg_info() << tmp.str() ;

std::vector<double>* v = d_constraintForces.beginEdit();
v->resize(current_cp->getDimension());
for(int i=0; i<current_cp->getDimension(); i++)
{
(*v)[i] = current_cp->getF()[i];
}
d_constraintForces.endEdit();
}


Expand Down
2 changes: 2 additions & 0 deletions modules/SofaConstraint/GenericConstraintSolver.h
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,8 @@ class SOFA_CONSTRAINT_API GenericConstraintSolver : public ConstraintSolverImpl
Data<int> currentIterations; ///< OUTPUT: current number of constraint groups
Data<double> currentError; ///< OUTPUT: current error
Data<bool> reverseAccumulateOrder; ///< True to accumulate constraints from nodes in reversed order (can be necessary when using multi-mappings or interaction constraints not following the node hierarchy)
Data<helper::vector< double >> d_constraintForces; //The Data constraintForces is used to provide the intensities of constraint forces in the simulation. The user can easily check the constraint forces from the GenericConstraint component interface.


virtual sofa::core::MultiVecDerivId getLambda() const override
{
Expand Down