Skip to content

Commit

Permalink
Merge pull request #142 from bakpaul/0924_fix_morinteractionconstraint
Browse files Browse the repository at this point in the history
Fix parameters usage and some deleted attributes regarding SOFA PR 5003
  • Loading branch information
hugtalbot authored Dec 13, 2024
2 parents 6902943 + f27d45d commit b482378
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 34 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -101,11 +101,9 @@ class MORUnilateralInteractionConstraint : public UnilateralLagrangianConstraint
protected:

using UnilateralLagrangianConstraint<DataTypes>::contacts;
using UnilateralLagrangianConstraint<DataTypes>::epsilon;
using UnilateralLagrangianConstraint<DataTypes>::yetIntegrated;
using UnilateralLagrangianConstraint<DataTypes>::customTolerance;

using UnilateralLagrangianConstraint<DataTypes>::prevForces;
using UnilateralLagrangianConstraint<DataTypes>::contactsStatus;

// /// Computes constraint violation
Expand All @@ -125,10 +123,6 @@ class MORUnilateralInteractionConstraint : public UnilateralLagrangianConstraint
void buildConstraintMatrix(const core::ConstraintParams* cParams, DataMatrixDeriv &c1, DataMatrixDeriv &c2, unsigned int &cIndex
, const DataVecCoord &x1, const DataVecCoord &x2) override;

void getConstraintViolation(const core::ConstraintParams* cParams, linearalgebra::BaseVector *v, const DataVecCoord &x1, const DataVecCoord &x2
, const DataVecDeriv &v1, const DataVecDeriv &v2) override;


// void getConstraintInfo(const core::ConstraintParams* cParams, VecConstraintBlockInfo& blocks, VecPersistentID& ids, VecConstCoord& positions, VecConstDeriv& directions, VecConstArea& areas) override;

virtual void getConstraintResolution(const core::ConstraintParams *,std::vector<core::behavior::ConstraintResolution*>& resTab, unsigned int& offset) override;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ void MORUnilateralInteractionConstraint<DataTypes>::buildConstraintMatrix(const
c1_it.addCol(c.m1, -c.norm);
c1_it.addCol(c.m2, c.norm);

if (c.mu > 0.0)
if (c.parameters.hasTangentialComponent())
{
c1_it = c1.writeLine(c.id + 1);
c1_it.setCol(c.m1, -c.t);
Expand Down Expand Up @@ -108,16 +108,16 @@ void MORUnilateralInteractionConstraint<DataTypes>::buildConstraintMatrix(const
for (unsigned int i = 0; i < contacts.size(); i++)
{
auto& c = contacts[i];
myMuForAllContacts = c.mu;
myMuForAllContacts = c.parameters.mu;
c.id = i;
if (c.mu == 0.0)
if (!c.parameters.hasTangentialComponent())
if (contactIndices(c.m2) != -1 && lambdaModes(contactIndices(c.m2),numMode)!=0.0){
c1_it.addCol(c.m1, -lambdaModes(contactIndices(c.m2),numMode)*c.norm);
c2_it.addCol(c.m2, lambdaModes(contactIndices(c.m2),numMode)*c.norm);
somethingAdded = true;
}

if (c.mu > 0.0)
if (c.parameters.hasTangentialComponent())
{
if (contactIndices(3*c.m2) != -1 && lambdaModes(contactIndices(3*c.m2),numMode)!=0.0){
c1_it.addCol(c.m1, -lambdaModes(contactIndices(3*c.m2),numMode)*c.norm);
Expand Down Expand Up @@ -176,27 +176,6 @@ void MORUnilateralInteractionConstraint<DataTypes>::buildConstraintMatrix(const
// contactId = contactId - 3;
}

template<class DataTypes>
void MORUnilateralInteractionConstraint<DataTypes>::getConstraintViolation(const core::ConstraintParams *cparams, linearalgebra::BaseVector *v, const DataVecCoord &, const DataVecCoord &
, const DataVecDeriv &, const DataVecDeriv &)
{
switch (cparams->constOrder())
{
case core::ConstraintParams::POS_AND_VEL :
case core::ConstraintParams::POS :
getPositionViolation(v);
break;

case core::ConstraintParams::ACC :
case core::ConstraintParams::VEL :
UnilateralLagrangianConstraint<DataTypes>::getVelocityViolation(v);
break;

default :
msg_error() << this->getClassName() << " doesn't implement " << cparams->getName() << " constraint violation";
break;
}
}

template<class DataTypes>
void MORUnilateralInteractionConstraint<DataTypes>::getPositionViolation(linearalgebra::BaseVector *v)
Expand Down Expand Up @@ -265,7 +244,7 @@ void MORUnilateralInteractionConstraint<DataTypes>::getPositionViolation(lineara
}

// Sets dfree in global violation vector
if (c.mu == 0.0){
if (!c.parameters.hasTangentialComponent()){

for (int k=0;k<reducedContacts.size();k++){
if (contactIndices(c.m2) != -1)
Expand Down Expand Up @@ -312,10 +291,10 @@ void MORUnilateralInteractionConstraint<DataTypes>::getConstraintResolution(cons
for(unsigned int i=0; i<reducedContacts.size(); i++)
{
auto& c = contacts[0];
if(c.mu > 0.0)
if(c.parameters.hasTangentialComponent())
{
i = i+2;
UnilateralConstraintResolutionWithFriction* ucrwf = new UnilateralConstraintResolutionWithFriction(c.mu, nullptr, &contactsStatus[i]);
UnilateralConstraintResolutionWithFriction* ucrwf = new UnilateralConstraintResolutionWithFriction(c.parameters.mu, nullptr, &contactsStatus[i]);
ucrwf->setTolerance(customTolerance);
resTab[offset] = ucrwf;
// TODO : cette méthode de stockage des forces peu mal fonctionner avec 2 threads quand on utilise l'haptique
Expand Down

0 comments on commit b482378

Please sign in to comment.