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

Cleaning + update accord to latest SOFA changes #136

Merged
merged 1 commit into from
Jul 30, 2024
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
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
#include <sofa/core/collision/Contact.h>
#include <sofa/core/collision/Intersection.h>
#include <sofa/component/mapping/linear/BarycentricMapping.h>
#include <sofa/component/constraint/lagrangian/model/UnilateralInteractionConstraint.h>
#include <sofa/component/constraint/lagrangian/model/UnilateralLagrangianConstraint.h>
#include <ModelOrderReduction/component/contact/MORUnilateralInteractionConstraint.h>
#include <sofa/helper/Factory.h>
#include <sofa/component/collision/response/mapper/BaseContactMapper.h>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ void MORFrictionContact<TCollisionModel1,TCollisionModel2,ResponseDataTypes>::ac
m_constraint = sofa::core::objectmodel::New<sofa::component::constraint::lagrangian::model::MORUnilateralInteractionConstraint<defaulttype::Vec3Types> >(mmodel1, mmodel2, d_lambdaModesPath.getValue(), d_lambdaModesCoeffsPath.getValue());
m_constraint->setName( this->getName() );
this->setInteractionTags(mmodel1, mmodel2);
m_constraint->setCustomTolerance( tol.getValue() );
m_constraint->setCustomTolerance( this->d_tol.getValue() );
}

int size = contacts.size();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
#include <iostream>
#include <map>
#include <deque>
#include <sofa/component/constraint/lagrangian/model/UnilateralInteractionConstraint.h>
#include <sofa/component/constraint/lagrangian/model/UnilateralLagrangianConstraint.h>
#include <Eigen/Sparse>

namespace sofa::component::constraint::lagrangian::model
Expand Down Expand Up @@ -56,10 +56,10 @@ class MORUnilateralConstraintResolution : public UnilateralConstraintResolution


template<class DataTypes>
class MORUnilateralInteractionConstraint : public UnilateralInteractionConstraint<DataTypes>
class MORUnilateralInteractionConstraint : public UnilateralLagrangianConstraint<DataTypes>
{
public:
SOFA_CLASS(SOFA_TEMPLATE(MORUnilateralInteractionConstraint,DataTypes), SOFA_TEMPLATE(UnilateralInteractionConstraint,DataTypes));
SOFA_CLASS(SOFA_TEMPLATE(MORUnilateralInteractionConstraint,DataTypes), SOFA_TEMPLATE(UnilateralLagrangianConstraint,DataTypes));

typedef typename DataTypes::VecCoord VecCoord;
typedef typename DataTypes::VecDeriv VecDeriv;
Expand Down Expand Up @@ -100,13 +100,13 @@ class MORUnilateralInteractionConstraint : public UnilateralInteractionConstrain

protected:

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

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

// /// Computes constraint violation
// in position and stores it into resolution global vector
Expand All @@ -116,7 +116,7 @@ class MORUnilateralInteractionConstraint : public UnilateralInteractionConstrain

public:

using UnilateralInteractionConstraint<DataTypes>::constraintId;
using UnilateralLagrangianConstraint<DataTypes>::constraintId;
protected:
MORUnilateralInteractionConstraint(MechanicalState* object1=nullptr, MechanicalState* object2=nullptr, std::string lambdaModesPath=nullptr,std::string lambdaModesCoeffsPath=nullptr);
~MORUnilateralInteractionConstraint();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
#define MOR_MORUNILATERALINTERACTIONCONSTRAINT_INL

#include "MORUnilateralInteractionConstraint.h"
#include <sofa/component/constraint/lagrangian/model/UnilateralInteractionConstraint.inl>
#include <sofa/component/constraint/lagrangian/model/UnilateralLagrangianConstraint.inl>
#include <sofa/core/visual/VisualParams.h>
#include <sofa/type/Vec.h>
#include <sofa/type/RGBAColor.h>
Expand All @@ -36,7 +36,7 @@ namespace sofa::component::constraint::lagrangian::model
using sofa::component::loader::MatrixLoader;
template<class DataTypes>
MORUnilateralInteractionConstraint<DataTypes>::MORUnilateralInteractionConstraint(MechanicalState* object1, MechanicalState* object2, std::string lambdaModesPath, std::string lambdaModesCoeffsPath)
: UnilateralInteractionConstraint<DataTypes>(object1,object2)
: UnilateralLagrangianConstraint<DataTypes>(object1,object2)
{
m_lambdaModesPath = lambdaModesPath;
m_lambdaModesCoeffsPath = lambdaModesCoeffsPath;
Expand All @@ -61,7 +61,7 @@ void MORUnilateralInteractionConstraint<DataTypes>::buildConstraintMatrix(const
{
assert(this->mstate1);
assert(this->mstate2);
double myMuForAllContacts;
double myMuForAllContacts {};
reducedContacts.resize(0);
if (this->mstate1 == this->mstate2)
{
Expand Down Expand Up @@ -189,7 +189,7 @@ void MORUnilateralInteractionConstraint<DataTypes>::getConstraintViolation(const

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

default :
Expand Down Expand Up @@ -315,7 +315,7 @@ void MORUnilateralInteractionConstraint<DataTypes>::getConstraintResolution(cons
if(c.mu > 0.0)
{
i = i+2;
UnilateralConstraintResolutionWithFriction* ucrwf = new UnilateralConstraintResolutionWithFriction(c.mu, NULL, &contactsStatus[i]);
UnilateralConstraintResolutionWithFriction* ucrwf = new UnilateralConstraintResolutionWithFriction(c.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
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ void MORPointCollisionModel<DataTypes>::draw(const core::visual::VisualParams* v
vparams->drawTool()->drawPoints(pointsP, 3, type::RGBAColor(color[0], color[1], color[2], color[3]));
vparams->drawTool()->drawLines(pointsL, 3, type::RGBAColor(color[0], color[1], color[2], color[3]));

if (m_displayFreePosition.getValue())
if (this->d_displayFreePosition.getValue())
{
std::vector< type::Vec3 > pointsPFree;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ void HyperReducedHexahedronFEMForceField<DataTypes>::addDForce (const core::Mech
}

Displacement F;
this->computeForce( F, X, _elementStiffnesses.getValue()[i] );
this->computeForce( F, X, this->d_elementStiffnesses.getValue()[i] );
for(int w=0; w<8; ++w)
{
Deriv contrib = _rotations[i].multTranspose(Deriv(F[w*3], F[w*3+1], F[w*3+2])) * kFactor;
Expand Down Expand Up @@ -219,12 +219,12 @@ template<class DataTypes>
}


if(f_updateStiffnessMatrix.getValue())
this->computeElementStiffness( (*_elementStiffnesses.beginEdit())[i], _materialsStiffnesses[i], deformed, i, _sparseGrid?_sparseGrid->getStiffnessCoef(i):1.0 );
if(this->d_updateStiffnessMatrix.getValue())
this->computeElementStiffness( (*this->d_elementStiffnesses.beginEdit())[i], _materialsStiffnesses[i], deformed, i, _sparseGrid?_sparseGrid->getStiffnessCoef(i):1.0 );


Displacement F; //forces
this->computeForce( F, D, _elementStiffnesses.getValue()[i] ); // compute force on element
this->computeForce( F, D, this->d_elementStiffnesses.getValue()[i] ); // compute force on element

for(int w=0; w<8; ++w)
f[elem[w]] += Deriv( F[w*3], F[w*3+1], F[w*3+2] ) ;
Expand Down Expand Up @@ -279,12 +279,12 @@ template<class DataTypes>
}


if(f_updateStiffnessMatrix.getValue())
this->computeElementStiffness( (*_elementStiffnesses.beginEdit())[i], _materialsStiffnesses[i], deformed, i, _sparseGrid?_sparseGrid->getStiffnessCoef(i):1.0 );
if(this->d_updateStiffnessMatrix.getValue())
this->computeElementStiffness( (*this->d_elementStiffnesses.beginEdit())[i], _materialsStiffnesses[i], deformed, i, _sparseGrid?_sparseGrid->getStiffnessCoef(i):1.0 );


Displacement F; //forces
this->computeForce( F, D, _elementStiffnesses.getValue()[i] ); // compute force on element
this->computeForce( F, D, this->d_elementStiffnesses.getValue()[i] ); // compute force on element
std::vector<Deriv> contrib;
std::vector<unsigned int> indexList;
contrib.resize(8);
Expand Down Expand Up @@ -359,13 +359,13 @@ template<class DataTypes>
//forces
Displacement F;

if(f_updateStiffnessMatrix.getValue())
if(this->d_updateStiffnessMatrix.getValue())
// this->computeElementStiffness( _elementStiffnesses[i], _materialsStiffnesses[i], deformed );
this->computeElementStiffness( (*_elementStiffnesses.beginEdit())[i], _materialsStiffnesses[i], deformed, i, _sparseGrid?_sparseGrid->getStiffnessCoef(i):1.0);
this->computeElementStiffness( (*this->d_elementStiffnesses.beginEdit())[i], _materialsStiffnesses[i], deformed, i, _sparseGrid?_sparseGrid->getStiffnessCoef(i):1.0);


// compute force on element
this->computeForce( F, D, _elementStiffnesses.getValue()[i] );
this->computeForce( F, D, this->d_elementStiffnesses.getValue()[i] );


for(int j=0; j<8; ++j)
Expand Down Expand Up @@ -397,15 +397,15 @@ void HyperReducedHexahedronFEMForceField<DataTypes>::buildStiffnessMatrix(
constexpr auto S = DataTypes::deriv_total_size; // size of node blocks
constexpr auto N = Element::size();

const auto& stiffnesses = _elementStiffnesses.getValue();
const auto& stiffnesses = this->d_elementStiffnesses.getValue();
const auto* indexedElements = this->getIndexedElements();
sofa::type::Mat<3, 3, Real> localMatrix(type::NOINIT);

auto dfdx = matrix->getForceDerivativeIn(this->mstate)
.withRespectToPositionsIn(this->mstate);


typename VecElement::const_iterator it, it0;
VecElement::const_iterator it, it0;

it0 = indexedElements->begin();
std::size_t nbElementsConsidered;
Expand Down Expand Up @@ -453,7 +453,7 @@ void HyperReducedHexahedronFEMForceField<DataTypes>::draw(const core::visual::Vi
{
if (!vparams->displayFlags().getShowForceFields()) return;
if (!this->mstate) return;
if (!f_drawing.getValue()) return;
if (!this->d_drawing.getValue()) return;


const VecCoord& x = this->mstate->read(core::ConstVecCoordId::position())->getValue();
Expand Down Expand Up @@ -495,7 +495,7 @@ void HyperReducedHexahedronFEMForceField<DataTypes>::draw(const core::visual::Vi
Index g = (*it)[6];

Coord center = (x[a]+x[b]+x[c]+x[d]+x[e]+x[g]+x[f]+x[h])*0.125;
Real percentage = f_drawPercentageOffset.getValue();
Real percentage = this->d_drawPercentageOffset.getValue();
Coord pa = x[a]-(x[a]-center)*percentage;
Coord pb = x[b]-(x[b]-center)*percentage;
Coord pc = x[c]-(x[c]-center)*percentage;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,21 +108,20 @@ class HyperReducedTetrahedralCorotationalFEMForceField : public virtual Tetrahed


using TetrahedralCorotationalFEMForceField<DataTypes>::method;
using TetrahedralCorotationalFEMForceField<DataTypes>::f_method; ///< the computation method of the displacements
using TetrahedralCorotationalFEMForceField<DataTypes>::_poissonRatio; ///< FEM Poisson Ratio
using TetrahedralCorotationalFEMForceField<DataTypes>::_youngModulus; ///< FEM Young Modulus
using TetrahedralCorotationalFEMForceField<DataTypes>::_localStiffnessFactor; ///< Allow specification of different stiffness per element. If there are N element and M values are specified, the youngModulus factor for element i would be localStiffnessFactor[i*M/N]
using TetrahedralCorotationalFEMForceField<DataTypes>::_updateStiffnessMatrix;
using TetrahedralCorotationalFEMForceField<DataTypes>::_assembling;
using TetrahedralCorotationalFEMForceField<DataTypes>::f_drawing; ///< draw the forcefield if true
using TetrahedralCorotationalFEMForceField<DataTypes>::d_method; ///< the computation method of the displacements
using TetrahedralCorotationalFEMForceField<DataTypes>::d_poissonRatio; ///< FEM Poisson Ratio
using TetrahedralCorotationalFEMForceField<DataTypes>::d_youngModulus; ///< FEM Young Modulus
using TetrahedralCorotationalFEMForceField<DataTypes>::d_localStiffnessFactor; ///< Allow specification of different stiffness per element. If there are N element and M values are specified, the youngModulus factor for element i would be localStiffnessFactor[i*M/N]
using TetrahedralCorotationalFEMForceField<DataTypes>::d_updateStiffnessMatrix;
using TetrahedralCorotationalFEMForceField<DataTypes>::d_assembling;
using TetrahedralCorotationalFEMForceField<DataTypes>::d_drawing; ///< draw the forcefield if true
using TetrahedralCorotationalFEMForceField<DataTypes>::_displayWholeVolume;
using TetrahedralCorotationalFEMForceField<DataTypes>::drawColor1; ///< draw color for faces 1
using TetrahedralCorotationalFEMForceField<DataTypes>::drawColor2; ///< draw color for faces 2
using TetrahedralCorotationalFEMForceField<DataTypes>::drawColor3; ///< draw color for faces 3
using TetrahedralCorotationalFEMForceField<DataTypes>::drawColor4; ///< draw color for faces 4
using TetrahedralCorotationalFEMForceField<DataTypes>::d_drawColor1; ///< draw color for faces 1
using TetrahedralCorotationalFEMForceField<DataTypes>::d_drawColor2; ///< draw color for faces 2
using TetrahedralCorotationalFEMForceField<DataTypes>::d_drawColor3; ///< draw color for faces 3
using TetrahedralCorotationalFEMForceField<DataTypes>::d_drawColor4; ///< draw color for faces 4
using TetrahedralCorotationalFEMForceField<DataTypes>::_volumeGraph;
protected:
HyperReducedTetrahedralCorotationalFEMForceField();

public:

virtual void init() override;
Expand Down
Loading
Loading