Skip to content
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 @@ -63,13 +63,9 @@ class BaseContactLagrangianConstraint : public core::behavior::PairInteractionCo

typedef core::behavior::BaseLagrangianConstraint::ConstraintBlockInfo ConstraintBlockInfo;
typedef core::behavior::BaseLagrangianConstraint::PersistentID PersistentID;
typedef core::behavior::BaseLagrangianConstraint::ConstCoord ConstCoord;

typedef core::behavior::BaseLagrangianConstraint::VecConstraintBlockInfo VecConstraintBlockInfo;
typedef core::behavior::BaseLagrangianConstraint::VecPersistentID VecPersistentID;
typedef core::behavior::BaseLagrangianConstraint::VecConstCoord VecConstCoord;
typedef core::behavior::BaseLagrangianConstraint::VecConstDeriv VecConstDeriv;
typedef core::behavior::BaseLagrangianConstraint::VecConstArea VecConstArea;

typedef core::objectmodel::Data<VecCoord> DataVecCoord;
typedef core::objectmodel::Data<VecDeriv> DataVecDeriv;
Expand Down Expand Up @@ -148,7 +144,7 @@ class BaseContactLagrangianConstraint : public core::behavior::PairInteractionCo
, const DataVecDeriv &v1, const DataVecDeriv &v2) override;


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

virtual void getConstraintResolution(const core::ConstraintParams *,std::vector<core::behavior::ConstraintResolution*>& resTab, unsigned int& offset) =0;
bool isActive() const override;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ void BaseContactLagrangianConstraint<DataTypes, ContactParams>::addContact(const
id, localid);
}


template<class DataTypes, class ContactParams>
void BaseContactLagrangianConstraint<DataTypes, ContactParams>::addContact(const ContactParams& parameters, Deriv norm, Coord P, Coord Q, Real contactDistance, int m1, int m2, Coord /*Pfree*/, Coord /*Qfree*/, long id, PersistentID localid)
{
Expand All @@ -96,6 +97,7 @@ void BaseContactLagrangianConstraint<DataTypes, ContactParams>::addContact(const
}



template<class DataTypes, class ContactParams>
void BaseContactLagrangianConstraint<DataTypes, ContactParams>::buildConstraintMatrix(const core::ConstraintParams *, DataMatrixDeriv &c1_d, DataMatrixDeriv &c2_d, unsigned int &contactId
, const DataVecCoord &, const DataVecCoord &)
Expand Down Expand Up @@ -310,7 +312,7 @@ void BaseContactLagrangianConstraint<DataTypes, ContactParams>::getConstraintVio


template<class DataTypes, class ContactParams>
void BaseContactLagrangianConstraint<DataTypes, ContactParams>::getConstraintInfo(const core::ConstraintParams*, VecConstraintBlockInfo& blocks, VecPersistentID& ids, VecConstCoord& /*positions*/, VecConstDeriv& directions, VecConstArea& /*areas*/)
void BaseContactLagrangianConstraint<DataTypes, ContactParams>::getConstraintInfo(const core::ConstraintParams*, VecConstraintBlockInfo& blocks, VecPersistentID& ids)
{
if (contacts.empty()) return;
const bool friction = (contacts[0].parameters.mu > 0.0); /// @todo: can there be both friction-less and friction contacts in the same BaseContactLagrangianConstraint ???
Expand All @@ -320,22 +322,15 @@ void BaseContactLagrangianConstraint<DataTypes, ContactParams>::getConstraintInf
info.nbLines = friction ? 3 : 1;
info.hasId = true;
info.offsetId = ids.size();
info.hasDirection = true;
info.offsetDirection = directions.size();
info.nbGroups = contacts.size();

for (unsigned int i=0; i<contacts.size(); i++)
{
Contact& c = contacts[i];
ids.push_back( yetIntegrated ? c.contactId : -c.contactId);
directions.push_back( c.norm );
if (friction)
{
directions.push_back( c.t );
directions.push_back( c.s );
}
}


yetIntegrated = true;

blocks.push_back(info);
Expand Down Expand Up @@ -367,7 +362,7 @@ void BaseContactLagrangianConstraint<DataTypes, ContactParams>::draw(const core:
{
const Contact& c = contacts[i];

otherVertices.push_back(c.P);
otherVertices.push_back(c.P);
otherVertices.push_back(c.P + c.norm);
otherColors.push_back(sofa::type::RGBAColor::white());

Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ class SOFA_COMPONENT_CONSTRAINT_LAGRANGIAN_SOLVER_API LCPConstraintSolver : publ
bool solveSystem(const core::ConstraintParams * /*cParams*/, MultiVecId res1, MultiVecId res2=MultiVecId::null()) override;
bool applyCorrection(const core::ConstraintParams * /*cParams*/, MultiVecId res1, MultiVecId res2=MultiVecId::null()) override;

void draw(const core::visual::VisualParams* vparams) override;


Data<bool> d_displayDebug; ///< Display debug information.
Data<bool> d_initial_guess; ///< activate LCP results history to improve its resolution performances.
Expand All @@ -81,22 +81,22 @@ class SOFA_COMPONENT_CONSTRAINT_LAGRANGIAN_SOLVER_API LCPConstraintSolver : publ
Data<SReal> d_mu; ///< Friction coefficient
Data<SReal> d_minW; ///< If not zero, constraints whose self-compliance (i.e. the corresponding value on the diagonal of W) is smaller than this threshold will be ignored
Data<SReal> d_maxF; ///< If not zero, constraints whose response force becomes larger than this threshold will be ignored
Data<bool> d_multi_grid; ///< activate multi_grid resolution (NOT STABLE YET)
Data<int> d_multi_grid_levels; ///< if multi_grid is active: how many levels to create (>=2)
Data<int> d_merge_method; ///< if multi_grid is active: which method to use to merge constraints (0 = compliance-based, 1 = spatial coordinates)
Data<int> d_merge_spatial_step; ///< if merge_method is 1: grid size reduction between multigrid levels
Data<int> d_merge_local_levels; ///< if merge_method is 1: up to the specified level of the multigrid, constraints are grouped locally, i.e. separately within each contact pairs, while on upper levels they are grouped globally independently of contact pairs.
DeprecatedAndRemoved d_multi_grid; ///< activate multi_grid resolution (NOT STABLE YET)
DeprecatedAndRemoved d_multi_grid_levels; ///< if multi_grid is active: how many levels to create (>=2)
DeprecatedAndRemoved d_merge_method; ///< if multi_grid is active: which method to use to merge constraints (0 = compliance-based, 1 = spatial coordinates)
DeprecatedAndRemoved d_merge_spatial_step; ///< if merge_method is 1: grid size reduction between multigrid levels
DeprecatedAndRemoved d_merge_local_levels; ///< if merge_method is 1: up to the specified level of the multigrid, constraints are grouped locally, i.e. separately within each contact pairs, while on upper levels they are grouped globally independently of contact pairs.
Data<type::vector< SReal >> d_constraintForces; ///< OUTPUT: constraint forces (stored only if computeConstraintForces=True)
Data<bool> d_computeConstraintForces; ///< The indices of the constraintForces to store in the constraintForce data field

Data < std::set<int> > d_constraintGroups; ///< list of ID of groups of constraints to be handled by this solver.

Data<std::map < std::string, sofa::type::vector<SReal> > > d_graph; ///< Graph of residuals at each iteration

Data<int> d_showLevels; ///< Number of constraint levels to display
DeprecatedAndRemoved d_showLevels; ///< Number of constraint levels to display
Data<SReal> d_showCellWidth; ///< Distance between each constraint cells
Data<type::Vec3> d_showTranslation; ///< Position of the first cell
Data<type::Vec3> d_showLevelTranslation; ///< Translation between levels
DeprecatedAndRemoved d_showLevelTranslation; ///< Translation between levels

ConstraintProblem* getConstraintProblem() override;
void lockConstraintProblem(sofa::core::objectmodel::BaseObject* from, ConstraintProblem* p1, ConstraintProblem* p2=nullptr) override; ///< Do not use the following LCPs until the next call to this function. This is used to prevent concurrent access to the LCP when using a LCPForceFeedback through an haptic thread
Expand All @@ -108,8 +108,6 @@ class SOFA_COMPONENT_CONSTRAINT_LAGRANGIAN_SOLVER_API LCPConstraintSolver : publ

unsigned int _numConstraints;

/// Multigrid hierarchy is resized and cleared
void buildHierarchy();
/// Call the method getConstraintInfo on all the BaseConstraintSet
void getConstraintInfo(core::ConstraintParams cparams);
/// Call the method addComplianceInConstraintSpace on all the BaseConstraintCorrection
Expand All @@ -121,16 +119,13 @@ class SOFA_COMPONENT_CONSTRAINT_LAGRANGIAN_SOLVER_API LCPConstraintSolver : publ
sofa::linearalgebra::LPtrFullMatrix<SReal> *_W;

/// multi-grid approach ///
void MultigridConstraintsMerge();
void MultigridConstraintsMerge_Compliance();
void MultigridConstraintsMerge_Spatial();
void build_Coarse_Compliance(std::vector<int> &/*constraint_merge*/, int /*sizeCoarseSystem*/);
sofa::linearalgebra::LPtrFullMatrix<SReal> _Wcoarse;

std::vector< std::vector< int > > hierarchy_contact_group;
std::vector< std::vector< int > > hierarchy_constraint_group;
std::vector< std::vector< SReal > > hierarchy_constraint_group_fact;
std::vector< unsigned int > hierarchy_num_group;
std::vector< int > m_contact_group;
std::vector< int > m_constraint_group;
std::vector< SReal > m_constraint_group_fact;
unsigned int m_num_group;


/// common built-unbuilt
Expand All @@ -149,15 +144,9 @@ class SOFA_COMPONENT_CONSTRAINT_LAGRANGIAN_SOLVER_API LCPConstraintSolver : publ

typedef core::behavior::BaseLagrangianConstraint::ConstraintBlockInfo ConstraintBlockInfo;
typedef core::behavior::BaseLagrangianConstraint::PersistentID PersistentID;
typedef core::behavior::BaseLagrangianConstraint::ConstCoord ConstCoord;
typedef core::behavior::BaseLagrangianConstraint::ConstDeriv ConstDeriv;
typedef core::behavior::BaseLagrangianConstraint::ConstArea ConstArea;

typedef core::behavior::BaseLagrangianConstraint::VecConstraintBlockInfo VecConstraintBlockInfo;
typedef core::behavior::BaseLagrangianConstraint::VecPersistentID VecPersistentID;
typedef core::behavior::BaseLagrangianConstraint::VecConstCoord VecConstCoord;
typedef core::behavior::BaseLagrangianConstraint::VecConstDeriv VecConstDeriv;
typedef core::behavior::BaseLagrangianConstraint::VecConstArea VecConstArea;

class ConstraintBlockBuf
{
Expand All @@ -169,11 +158,8 @@ class SOFA_COMPONENT_CONSTRAINT_LAGRANGIAN_SOLVER_API LCPConstraintSolver : publ
std::map<core::behavior::BaseLagrangianConstraint*, ConstraintBlockBuf> _previousConstraints;
type::vector< SReal > _previousForces;

type::vector< VecConstraintBlockInfo > hierarchy_constraintBlockInfo;
type::vector< VecPersistentID > hierarchy_constraintIds;
type::vector< VecConstCoord > hierarchy_constraintPositions;
type::vector< VecConstDeriv > hierarchy_constraintDirections;
type::vector< VecConstArea > hierarchy_constraintAreas;
VecConstraintBlockInfo m_constraintBlockInfo;
VecPersistentID m_constraintIds;

// for gaussseidel_unbuilt
type::vector< helper::LocalBlock33 > unbuilt_W33;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,20 @@ void BaseLagrangianConstraint::setGroup(int g)
}

void BaseLagrangianConstraint::getConstraintInfo(const ConstraintParams* cParams, VecConstraintBlockInfo& blocks,
VecPersistentID& ids, VecConstCoord& positions, VecConstDeriv& directions, VecConstArea& areas)
VecPersistentID& ids)
{
SOFA_UNUSED(cParams);
SOFA_UNUSED(blocks);
SOFA_UNUSED(ids);
}

void BaseLagrangianConstraint::getConstraintInfo(const core::ConstraintParams* cParams, VecConstraintBlockInfo& blocks, VecPersistentID& ids, VecConstCoord& positions, VecConstDeriv& directions, VecConstArea& areas)
{
msg_warning()<<"BaseLagrangianConstraint::getConstraintInfo signature has changed. Positions, directions and areas are not used anymore. This method is deprecated since v25.06 and will be deleted in v25.12.";
this->getConstraintInfo(cParams, blocks, ids);
SOFA_UNUSED(positions);
SOFA_UNUSED(directions);
SOFA_UNUSED(areas);

}

void BaseLagrangianConstraint::getConstraintResolution(const ConstraintParams* cParams,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,12 +62,6 @@ class SOFA_CORE_API BaseLagrangianConstraint : public BaseConstraintSet

typedef long long PersistentID;
typedef type::vector<PersistentID> VecPersistentID;
typedef type::Vec<3,int> ConstCoord;
typedef type::vector<ConstCoord> VecConstCoord;
typedef type::Vec<3,double> ConstDeriv;
typedef type::vector<ConstDeriv> VecConstDeriv;
typedef double ConstArea;
typedef type::vector<ConstArea> VecConstArea;

class ConstraintBlockInfo
{
Expand All @@ -77,21 +71,23 @@ class SOFA_CORE_API BaseLagrangianConstraint : public BaseConstraintSet
int nbLines; ///< how many dofs (i.e. lines in the matrix) are used by each constraint
int nbGroups; ///< how many groups of constraints are active
bool hasId; ///< true if this constraint has persistent ID information
bool hasPosition; ///< true if this constraint has coordinates information
bool hasDirection; ///< true if this constraint has direction information
bool hasArea; ///< true if this constraint has area information
int offsetId; ///< index of first constraint group info in vector of persistent ids and coordinates
int offsetPosition; ///< index of first constraint group info in vector of coordinates
int offsetDirection; ///< index of first constraint info in vector of directions
int offsetArea; ///< index of first constraint group info in vector of areas
ConstraintBlockInfo() : parent(nullptr), const0(0), nbLines(1), nbGroups(0), hasId(false), hasPosition(false), hasDirection(false), hasArea(false), offsetId(0), offsetPosition(0), offsetDirection(0), offsetArea(0)
ConstraintBlockInfo() : parent(nullptr), const0(0), nbLines(1), nbGroups(0), hasId(false), offsetId(0)
{}
};
typedef type::vector<ConstraintBlockInfo> VecConstraintBlockInfo;

/// Get information for each constraint: pointer to parent BaseConstraint, unique persistent ID, 3D position
/// \param cParams defines the state vectors to use for positions and velocities. Also defines the order of the constraint (POS, VEL, ACC) and resolution parameters (smoothness, ...)
virtual void getConstraintInfo(const ConstraintParams* cParams, VecConstraintBlockInfo& blocks, VecPersistentID& ids, VecConstCoord& positions, VecConstDeriv& directions, VecConstArea& areas);
virtual void getConstraintInfo(const ConstraintParams* cParams, VecConstraintBlockInfo& blocks, VecPersistentID& ids);


//DEPRECATED(v25.06, v25.12)
typedef sofa::type::vector<type::Vec<3,double>> VecConstCoord;
typedef sofa::type::vector<type::Vec<3,double>> VecConstDeriv;
typedef sofa::type::vector<double> VecConstArea;
SOFA_ATTRIBUTE_DEPRECATED__DELETED_ARGUMENTS()
virtual void getConstraintInfo(const core::ConstraintParams* cParams, VecConstraintBlockInfo& blocks, VecPersistentID& ids, VecConstCoord& positions, VecConstDeriv& directions, VecConstArea& areas) final;

/// Add the corresponding ConstraintResolution using the offset parameter
/// \param cParams defines the state vectors to use for positions and velocities. Also defines the order of the constraint (POS, VEL, ACC) and resolution parameters (smoothness, ...)
Expand Down
6 changes: 6 additions & 0 deletions Sofa/framework/Core/src/sofa/core/config.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,12 @@
#endif


#ifdef SOFA_BUILD_SOFA_CORE
#define SOFA_ATTRIBUTE_DEPRECATED__DELETED_ARGUMENTS()
#else
#define SOFA_ATTRIBUTE_DEPRECATED__DELETED_ARGUMENTS() \
SOFA_ATTRIBUTE_DEPRECATED("v25.06", "v25.12", "Signature has changed, use 'getConstraintResolution(const ConstraintParams* cParams, std::vector<ConstraintResolution*> &resTab, unsigned int &offset)' instead")
#endif


#ifdef SOFA_BUILD_SOFA_CORE
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,10 @@ namespace sofa::simulation::mechanicalvisitor
{

MechanicalGetConstraintInfoVisitor::MechanicalGetConstraintInfoVisitor(const core::ConstraintParams* params,
VecConstraintBlockInfo& blocks, VecPersistentID& ids, VecConstCoord& positions, VecConstDeriv& directions,
VecConstArea& areas)
VecConstraintBlockInfo& blocks, VecPersistentID& ids)
: simulation::BaseMechanicalVisitor(params)
, _blocks(blocks)
, _ids(ids)
, _positions(positions)
, _directions(directions)
, _areas(areas)
, _cparams(params)
{}

Expand All @@ -44,7 +40,7 @@ Visitor::Result MechanicalGetConstraintInfoVisitor::fwdConstraintSet(simulation:
if (core::behavior::BaseLagrangianConstraint *c=cSet->toBaseLagrangianConstraint())
{
const ctime_t t0 = begin(node, c);
c->getConstraintInfo(_cparams, _blocks, _ids, _positions, _directions, _areas);
c->getConstraintInfo(_cparams, _blocks, _ids);
end(node, c, t0);
}
return RESULT_CONTINUE;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,8 @@ class SOFA_SIMULATION_CORE_API MechanicalGetConstraintInfoVisitor : public simul
public:
typedef core::behavior::BaseLagrangianConstraint::VecConstraintBlockInfo VecConstraintBlockInfo;
typedef core::behavior::BaseLagrangianConstraint::VecPersistentID VecPersistentID;
typedef core::behavior::BaseLagrangianConstraint::VecConstCoord VecConstCoord;
typedef core::behavior::BaseLagrangianConstraint::VecConstDeriv VecConstDeriv;
typedef core::behavior::BaseLagrangianConstraint::VecConstArea VecConstArea;

MechanicalGetConstraintInfoVisitor(const core::ConstraintParams* params, VecConstraintBlockInfo& blocks, VecPersistentID& ids, VecConstCoord& positions, VecConstDeriv& directions, VecConstArea& areas);
MechanicalGetConstraintInfoVisitor(const core::ConstraintParams* params, VecConstraintBlockInfo& blocks, VecPersistentID& ids);

Result fwdConstraintSet(simulation::Node* node, core::behavior::BaseConstraintSet* cSet) override;

Expand All @@ -49,9 +46,6 @@ class SOFA_SIMULATION_CORE_API MechanicalGetConstraintInfoVisitor : public simul
private:
VecConstraintBlockInfo& _blocks;
VecPersistentID& _ids;
VecConstCoord& _positions;
VecConstDeriv& _directions;
VecConstArea& _areas;
const core::ConstraintParams* _cparams;
};

Expand Down