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

FIX constraint index modification #108

Merged
Merged
Show file tree
Hide file tree
Changes from all 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
2 changes: 1 addition & 1 deletion src/Cosserat/constraint/CosseratActuatorConstraint.h
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ class CosseratActuatorConstraint : public CableModel<DataTypes>
using CableModel<DataTypes>::d_displacement ;
using CableModel<DataTypes>::d_componentState ;
using CableModel<DataTypes>::m_nbLines ;
using CableModel<DataTypes>::m_constraintId ;
using CableModel<DataTypes>::m_constraintIndex ;
using CableModel<DataTypes>::m_state ;
using CableModel<DataTypes>::d_indices ;
using CableModel<DataTypes>::d_pullPoint;
Expand Down
9 changes: 5 additions & 4 deletions src/Cosserat/constraint/CosseratActuatorConstraint.inl
Original file line number Diff line number Diff line change
Expand Up @@ -104,11 +104,12 @@ void CosseratActuatorConstraint<DataTypes>::buildConstraintMatrix(const Constrai

SOFA_UNUSED(cParams);

m_constraintId = cIndex;
m_constraintIndex.setValue(cIndex);
const auto& constraintIndex = sofa::helper::getReadAccessor(m_constraintIndex);

MatrixDeriv& matrix = *cMatrix.beginEdit();

MatrixDerivRowIterator rowIterator = matrix.writeLine(m_constraintId);
MatrixDerivRowIterator rowIterator = matrix.writeLine(constraintIndex);

VecCoord positions = x.getValue();

Expand Down Expand Up @@ -144,7 +145,7 @@ void CosseratActuatorConstraint<DataTypes>::buildConstraintMatrix(const Constrai
}
cIndex++;
cMatrix.endEdit();
m_nbLines = cIndex - m_constraintId;
m_nbLines = cIndex - constraintIndex;
}


Expand All @@ -168,7 +169,7 @@ void CosseratActuatorConstraint<DataTypes>::getConstraintViolation(const Constra


for (unsigned i=0;i<d_indices.getValue().size();i++) {
resV->set(m_constraintId, dfree);
resV->set(m_constraintIndex.getValue(), dfree);
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/Cosserat/constraint/CosseratNeedleSlidingConstraint.h
Original file line number Diff line number Diff line change
Expand Up @@ -134,8 +134,8 @@ namespace sofa::component::constraintset
using Constraint<DataTypes>::d_componentState;
////////////////////////////////////////////////////////////////////////////
/// \brief internalInit
unsigned int m_nbLines;
unsigned int m_constraintId;
unsigned m_nbLines ;
using Constraint<DataTypes>::m_constraintIndex ;

void internalInit();
};
Expand Down
11 changes: 6 additions & 5 deletions src/Cosserat/constraint/CosseratNeedleSlidingConstraint.inl
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ namespace sofa::component::constraintset
SOFA_UNUSED(cParams);
MatrixDeriv &matrix = *cMatrix.beginEdit();
VecCoord positions = x.getValue();
m_constraintId = cIndex;
m_constraintIndex.setValue(cIndex);

type::Vec<3, bool> use = d_useDirections.getValue();

Expand All @@ -131,7 +131,7 @@ namespace sofa::component::constraintset
}
}
cMatrix.endEdit();
m_nbLines = cIndex - m_constraintId;
m_nbLines = cIndex - m_constraintIndex.getValue();

}

Expand All @@ -151,20 +151,21 @@ namespace sofa::component::constraintset
//ReadAccessor<Data<VecCoord>> positions = this->mstate->readPositions();
const VecCoord positions = x.getValue();
type::Vec<3, bool> use = d_useDirections.getValue();
const auto& constraintIndex = sofa::helper::getReadAccessor(m_constraintIndex);

for (unsigned int i = 0; i < positions.size(); i++)
{
if (use[0]){
Real dfree0 = positions[i][0];
resV->set(m_constraintId + 2 * i, dfree0);
resV->set(constraintIndex + 2 * i, dfree0);
}
if (use[1]){
Real dfree1 = positions[i][1];
resV->set(m_constraintId + 2 * i, dfree1);
resV->set(constraintIndex + 2 * i, dfree1);
}
if (use[2]){
Real dfree2 = positions[i][2];
resV->set(m_constraintId + 2 * i + 1, dfree2);
resV->set(constraintIndex + 2 * i + 1, dfree2);
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/Cosserat/constraint/QPSlidingConstraint.h
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ class QPSlidingConstraint : public CableModel<DataTypes>
////////////////////////////////////////////////////////////////////////////
/// \brief internalInit
using SoftRobotsConstraint<DataTypes>::m_nbLines ;
using SoftRobotsConstraint<DataTypes>::m_constraintId ;
using SoftRobotsConstraint<DataTypes>::m_constraintIndex ;

void internalInit();
};
Expand Down
26 changes: 14 additions & 12 deletions src/Cosserat/constraint/QPSlidingConstraint.inl
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,8 @@ void QPSlidingConstraint<DataTypes>::buildConstraintMatrix(const ConstraintParam
SOFA_UNUSED(cParams);
MatrixDeriv& matrix = *cMatrix.beginEdit();
VecCoord positions = x.getValue();
m_constraintId= cIndex;
m_constraintIndex.setValue(cIndex);
const auto& constraintIndex = sofa::helper::getReadAccessor(m_constraintIndex);

for (unsigned int i=0; i<positions.size(); i++)
{
Expand All @@ -141,7 +142,7 @@ void QPSlidingConstraint<DataTypes>::buildConstraintMatrix(const ConstraintParam

}
cMatrix.endEdit();
m_nbLines = cIndex - m_constraintId;
m_nbLines = cIndex - constraintIndex;
}


Expand All @@ -155,6 +156,7 @@ void QPSlidingConstraint<DataTypes>::getConstraintViolation(const ConstraintPara

SOFA_UNUSED(cParams);
ReadAccessor<Data<VecCoord>> positions = m_state->readPositions();
const auto& constraintIndex = sofa::helper::getReadAccessor(m_constraintIndex);

if(Jdx->size()==0){
//std::cout << "Size JDX = "<< Jdx->size() << std::endl;
Expand All @@ -163,16 +165,16 @@ void QPSlidingConstraint<DataTypes>::getConstraintViolation(const ConstraintPara
Real dfree1 = positions[i][1];
Real dfree2 = positions[i][2];

resV->set(m_constraintId + 2*i , dfree1);
resV->set(m_constraintId + 2*i +1, dfree2);
resV->set(constraintIndex + 2*i , dfree1);
resV->set(constraintIndex + 2*i +1, dfree2);
}else{
Real dfree0 = positions[i][0];
Real dfree1 = positions[i][1];
Real dfree2 = positions[i][2];

resV->set(m_constraintId + 2*i , dfree0);
resV->set(m_constraintId + 2*i +1, dfree1);
resV->set(m_constraintId + 2*i +2, dfree2);
resV->set(constraintIndex + 2*i , dfree0);
resV->set(constraintIndex + 2*i +1, dfree1);
resV->set(constraintIndex + 2*i +2, dfree2);
}
}

Expand All @@ -183,18 +185,18 @@ void QPSlidingConstraint<DataTypes>::getConstraintViolation(const ConstraintPara
Real dfree1 = Jdx->element(2*i) + positions[i][1];
Real dfree2 = Jdx->element(2*i+1) + positions[i][2];

resV->set(m_constraintId + 2*i , dfree1);
resV->set(m_constraintId + 2*i +1, dfree2);
resV->set(constraintIndex + 2*i , dfree1);
resV->set(constraintIndex + 2*i +1, dfree2);
}else{
//std::cout << " The laste position : "<< positions[i] << "; Jdx->element() "<< Jdx->element(2*i) <<" "<< Jdx->element(2*i+1) <<" "<< Jdx->element(2*i+2) << std::endl;
Real dfree0 = Jdx->element(2*i) + positions[i][0];
Real dfree1 = Jdx->element(2*i+1) + positions[i][1];
Real dfree2 = Jdx->element(2*i+2) + positions[i][2];

//std::cout << " m_constraintId + 2*i : "<< m_constraintId + 2*i << std::endl;
resV->set(m_constraintId + 2*i , dfree0);
resV->set(m_constraintId + 2*i +1, dfree1);
resV->set(m_constraintId + 2*i +2, dfree2);
resV->set(constraintIndex + 2*i , dfree0);
resV->set(constraintIndex + 2*i +1, dfree1);
resV->set(constraintIndex + 2*i +2, dfree2);
}
}
}
Expand Down
Loading