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 @@ -43,7 +43,7 @@

#include <sofa/core/ObjectFactory.h>

#include <sofa/core/behavior/BaseConstraint.h> ///< ConstraintResolution.
#include <sofa/core/behavior/BaseLagrangianConstraint.h> ///< ConstraintResolution.

#include <sofa/helper/AdvancedTimer.h>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,15 +61,15 @@ class BaseContactLagrangianConstraint : public core::behavior::PairInteractionCo
typedef typename Coord::value_type Real;
typedef typename core::behavior::MechanicalState<DataTypes> MechanicalState;

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

typedef core::behavior::BaseConstraint::VecConstraintBlockInfo VecConstraintBlockInfo;
typedef core::behavior::BaseConstraint::VecPersistentID VecPersistentID;
typedef core::behavior::BaseConstraint::VecConstCoord VecConstCoord;
typedef core::behavior::BaseConstraint::VecConstDeriv VecConstDeriv;
typedef core::behavior::BaseConstraint::VecConstArea VecConstArea;
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
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
#include <sofa/component/constraint/lagrangian/model/config.h>

#include <sofa/type/Mat.h>
#include <sofa/core/behavior/BaseConstraint.h>
#include <sofa/core/behavior/BaseLagrangianConstraint.h>
#include <sofa/core/behavior/ConstraintResolution.h>
#include <Eigen/Core>
#include <Eigen/Cholesky>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ namespace sofa::component::constraint::lagrangian::model

/// These 'using' are in a per-file namespace so they will not leak
/// and polluate the standard namespace.
using sofa::core::behavior::BaseConstraint ;
using sofa::core::behavior::BaseLagrangianConstraint ;
using sofa::core::behavior::ConstraintResolution ;
using sofa::core::behavior::PairInteractionConstraint ;
using sofa::core::ConstraintParams ;
Expand Down Expand Up @@ -81,7 +81,7 @@ class BilateralLagrangianConstraint : public PairInteractionConstraint<DataTypes
typedef typename DataTypes::MatrixDeriv::RowIterator MatrixDerivRowIterator;

typedef core::behavior::MechanicalState<DataTypes> MechanicalState;
typedef BaseConstraint::PersistentID PersistentID;
typedef BaseLagrangianConstraint::PersistentID PersistentID;

typedef Data<VecCoord> DataVecCoord;
typedef Data<VecDeriv> DataVecDeriv;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@

#include <sofa/component/constraint/lagrangian/solver/ConstraintSolverImpl.h>
#include <sofa/core/behavior/BaseConstraintCorrection.h>
#include <sofa/core/behavior/BaseConstraint.h>
#include <sofa/core/behavior/BaseLagrangianConstraint.h>
#include <sofa/helper/map.h>

#include <sofa/simulation/CpuTask.h>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -676,7 +676,7 @@ void LCPConstraintSolver::computeInitialGuess()
for (const ConstraintBlockInfo& info : constraintBlockInfo)
{
if (!info.hasId) continue;
std::map<core::behavior::BaseConstraint*, ConstraintBlockBuf>::const_iterator previt = _previousConstraints.find(info.parent);
std::map<core::behavior::BaseLagrangianConstraint*, ConstraintBlockBuf>::const_iterator previt = _previousConstraints.find(info.parent);
if (previt == _previousConstraints.end()) continue;
const ConstraintBlockBuf& buf = previt->second;
const int c0 = info.const0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@

#include <sofa/component/constraint/lagrangian/solver/ConstraintSolverImpl.h>
#include <sofa/core/behavior/BaseConstraintCorrection.h>
#include <sofa/core/behavior/BaseConstraint.h>
#include <sofa/core/behavior/BaseLagrangianConstraint.h>

#include <sofa/simulation/MechanicalVisitor.h>
#include <sofa/simulation/fwd.h>
Expand Down Expand Up @@ -147,17 +147,17 @@ class SOFA_COMPONENT_CONSTRAINT_LAGRANGIAN_SOLVER_API LCPConstraintSolver : publ
std::vector<core::behavior::BaseConstraintCorrection*> _cclist_elem1;
std::vector<core::behavior::BaseConstraintCorrection*> _cclist_elem2;

typedef core::behavior::BaseConstraint::ConstraintBlockInfo ConstraintBlockInfo;
typedef core::behavior::BaseConstraint::PersistentID PersistentID;
typedef core::behavior::BaseConstraint::ConstCoord ConstCoord;
typedef core::behavior::BaseConstraint::ConstDeriv ConstDeriv;
typedef core::behavior::BaseConstraint::ConstArea ConstArea;
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::BaseConstraint::VecConstraintBlockInfo VecConstraintBlockInfo;
typedef core::behavior::BaseConstraint::VecPersistentID VecPersistentID;
typedef core::behavior::BaseConstraint::VecConstCoord VecConstCoord;
typedef core::behavior::BaseConstraint::VecConstDeriv VecConstDeriv;
typedef core::behavior::BaseConstraint::VecConstArea VecConstArea;
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 @@ -166,7 +166,7 @@ class SOFA_COMPONENT_CONSTRAINT_LAGRANGIAN_SOLVER_API LCPConstraintSolver : publ
int nbLines; ///< how many dofs (i.e. lines in the matrix) are used by each constraint
};

std::map<core::behavior::BaseConstraint*, ConstraintBlockBuf> _previousConstraints;
std::map<core::behavior::BaseLagrangianConstraint*, ConstraintBlockBuf> _previousConstraints;
type::vector< SReal > _previousForces;

type::vector< VecConstraintBlockInfo > hierarchy_constraintBlockInfo;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
* *
* Contact information: contact@sofa-framework.org *
******************************************************************************/
#include <sofa/core/behavior/BaseConstraint.h>
#include <sofa/core/behavior/BaseLagrangianConstraint.h>
#include <sofa/component/constraint/lagrangian/solver/visitors/ConstraintStoreLambdaVisitor.h>
#include <sofa/core/ConstraintParams.h>

Expand All @@ -35,7 +35,7 @@ ConstraintStoreLambdaVisitor::ConstraintStoreLambdaVisitor(const sofa::core::Con

simulation::Visitor::Result ConstraintStoreLambdaVisitor::fwdConstraintSet(simulation::Node* node, core::behavior::BaseConstraintSet* cSet)
{
if (core::behavior::BaseConstraint *c = dynamic_cast<core::behavior::BaseConstraint*>(cSet) )
if (core::behavior::BaseLagrangianConstraint *c = dynamic_cast<core::behavior::BaseLagrangianConstraint*>(cSet) )
{
const ctime_t t0 = begin(node, c);
c->storeLambda(m_cParams, m_cParams->lambda(), m_lambda);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
#include <sofa/component/constraint/lagrangian/solver/visitors/MechanicalGetConstraintResolutionVisitor.h>
#include <sofa/core/behavior/BaseConstraintSet.h>
#include <sofa/core/ConstraintParams.h>
#include <sofa/core/behavior/BaseConstraint.h>
#include <sofa/core/behavior/BaseLagrangianConstraint.h>

namespace sofa::component::constraint::lagrangian::solver
{
Expand All @@ -39,7 +39,7 @@ MechanicalGetConstraintResolutionVisitor::MechanicalGetConstraintResolutionVisit

MechanicalGetConstraintResolutionVisitor::Result MechanicalGetConstraintResolutionVisitor::fwdConstraintSet(simulation::Node* node, core::behavior::BaseConstraintSet* cSet)
{
if (core::behavior::BaseConstraint *c=cSet->toBaseConstraint())
if (core::behavior::BaseLagrangianConstraint *c=cSet->toBaseLagrangianConstraint())
{
const ctime_t t0 = begin(node, c);
c->getConstraintResolution(cparams, _res, _offset);
Expand Down
3 changes: 2 additions & 1 deletion Sofa/framework/Core/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ set(HEADER_FILES
${SRC_ROOT}/behavior/BaseInteractionConstraint.h
${SRC_ROOT}/behavior/BaseInteractionForceField.h
${SRC_ROOT}/behavior/BaseInteractionProjectiveConstraintSet.h
${SRC_ROOT}/behavior/BaseLagrangianConstraint.h
${SRC_ROOT}/behavior/BaseLinearSolver.h
${SRC_ROOT}/behavior/BaseLocalForceFieldMatrix.h
${SRC_ROOT}/behavior/BaseLocalMassMatrix.h
Expand Down Expand Up @@ -234,11 +235,11 @@ set(SOURCE_FILES
${SRC_ROOT}/State.cpp
${SRC_ROOT}/VecId.cpp
${SRC_ROOT}/behavior/BaseAnimationLoop.cpp
${SRC_ROOT}/behavior/BaseConstraint.cpp
${SRC_ROOT}/behavior/BaseConstraintCorrection.cpp
${SRC_ROOT}/behavior/BaseConstraintSet.cpp
${SRC_ROOT}/behavior/BaseForceField.cpp
${SRC_ROOT}/behavior/BaseInteractionForceField.cpp
${SRC_ROOT}/behavior/BaseLagrangianConstraint.cpp
${SRC_ROOT}/behavior/BaseLinearSolver.cpp
${SRC_ROOT}/behavior/BaseMass.cpp
${SRC_ROOT}/behavior/BaseMatrixLinearSystem.cpp
Expand Down
102 changes: 5 additions & 97 deletions Sofa/framework/Core/src/sofa/core/behavior/BaseConstraint.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,103 +21,11 @@
******************************************************************************/
#pragma once

#include <sofa/core/behavior/BaseConstraintSet.h>
#include <sofa/core/fwd.h>
#include <sofa/core/behavior/BaseLagrangianConstraint.h>

namespace sofa::core::behavior
{
SOFA_HEADER_DEPRECATED("v25.06", "v26.06", "sofa/core/behavior/BaseLagrangianConstraint.h")

/**
* \brief Component computing constraints within a simulated body.
*
* This class defines the abstract API common to all constraints.
* A BaseConstraint computes constraints applied to one or more simulated body
* given its current position and velocity.
*
* Constraints can be internal to a given body (attached to one MechanicalState,
* see the Constraint class), or link several bodies together (such as contacts,
* see the InteractionConstraint class).
*
*/
class SOFA_CORE_API BaseConstraint : public BaseConstraintSet
namespace sofa::core::behavior
{
public:
SOFA_ABSTRACT_CLASS(BaseConstraint, BaseConstraintSet);
SOFA_BASE_CAST_IMPLEMENTATION(BaseConstraint)

protected:
BaseConstraint() {}
~BaseConstraint() override {}

private:
BaseConstraint(const BaseConstraint& n) = delete ;
BaseConstraint& operator=(const BaseConstraint& n) = delete ;

public:
/// Get the ID of the group containing this constraint. This ID is used to specify which constraints are solved by which solver, by specifying in each solver which groups of constraints it should handle.
int getGroup() const;

/// Set the ID of the group containing this constraint. This ID is used to specify which constraints are solved by which solver, by specifying in each solver which groups of constraints it should handle.
void setGroup(int g);

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
{
public:
BaseConstraint* parent;
int const0; ///< index of first constraint
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)
{}
};
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);

/// 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, ...)
/// \param resTab is the result vector that contains the constraint resolution algorithms
virtual void getConstraintResolution(const ConstraintParams* cParams, std::vector<ConstraintResolution*> &resTab, unsigned int &offset);

virtual void getConstraintResolution(std::vector<ConstraintResolution*> &resTab, unsigned int &offset);

type::vector<std::string> getIdentifiers()
{
type::vector<std::string> ids = getBaseConstraintIdentifiers();
ids.push_back("Base");
return ids;
}

virtual type::vector<std::string> getBaseConstraintIdentifiers() = 0;


/// Store the constraint lambda at the constraint dofs at the given VecDerivId location.
/// res = J^t * lambda.
/// J is the sparse matrix containing the constraint jacobian that was used to build the constraint matrix ( see BaseConstraintSet::buildConstraintMatrix ).
/// \param cParams stores the id of the state vectors used during the constraint solving step. Mostly it helps retrieving the MatrixDerivId where
/// the constraint jacobian J is stored.
/// \param res is the state vector Id where to store the result.
/// \param lambda is the vector of scalar constraint impulses. The direction are stored in the MatrixDerivId stored in the cParams.
virtual void storeLambda(const ConstraintParams* cParams, MultiVecDerivId res, const sofa::linearalgebra::BaseVector* lambda) = 0;
};

} // namespace sofa::core::behavior
using BaseConstraint SOFA_ATTRIBUTE_DEPRECATED("v25.06", "v26.06", "BaseConstraint has been renamed to BaseLagrangianConstraint") = BaseLagrangianConstraint;
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
******************************************************************************/
#pragma once

#include <sofa/core/behavior/BaseConstraint.h>
#include <sofa/core/behavior/BaseLagrangianConstraint.h>
#include <sofa/core/behavior/StateAccessor.h>

namespace sofa::core::behavior
Expand All @@ -34,10 +34,10 @@ namespace sofa::core::behavior
* bodies given their current positions and velocities.
*
*/
class SOFA_CORE_API BaseInteractionConstraint : public BaseConstraint, public virtual StateAccessor
class SOFA_CORE_API BaseInteractionConstraint : public BaseLagrangianConstraint, public virtual StateAccessor
{
public:
SOFA_ABSTRACT_CLASS2(BaseInteractionConstraint, BaseConstraint, StateAccessor);
SOFA_ABSTRACT_CLASS2(BaseInteractionConstraint, BaseLagrangianConstraint, StateAccessor);
SOFA_BASE_CAST_IMPLEMENTATION(BaseInteractionConstraint)

/// Get the first MechanicalState
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,21 +19,21 @@
* *
* Contact information: contact@sofa-framework.org *
******************************************************************************/
#include <sofa/core/behavior/BaseConstraint.h>
#include <sofa/core/behavior/BaseLagrangianConstraint.h>

namespace sofa::core::behavior
{
int BaseConstraint::getGroup() const
int BaseLagrangianConstraint::getGroup() const
{
return group.getValue();
}

void BaseConstraint::setGroup(int g)
void BaseLagrangianConstraint::setGroup(int g)
{
group.setValue(g);
}

void BaseConstraint::getConstraintInfo(const ConstraintParams* cParams, VecConstraintBlockInfo& blocks,
void BaseLagrangianConstraint::getConstraintInfo(const ConstraintParams* cParams, VecConstraintBlockInfo& blocks,
VecPersistentID& ids, VecConstCoord& positions, VecConstDeriv& directions, VecConstArea& areas)
{
SOFA_UNUSED(cParams);
Expand All @@ -45,14 +45,14 @@ void BaseConstraint::getConstraintInfo(const ConstraintParams* cParams, VecConst

}

void BaseConstraint::getConstraintResolution(const ConstraintParams* cParams,
void BaseLagrangianConstraint::getConstraintResolution(const ConstraintParams* cParams,
std::vector<ConstraintResolution*>& resTab, unsigned& offset)
{
getConstraintResolution(resTab, offset);
SOFA_UNUSED(cParams);
}

void BaseConstraint::getConstraintResolution(std::vector<ConstraintResolution*>& resTab, unsigned& offset)
void BaseLagrangianConstraint::getConstraintResolution(std::vector<ConstraintResolution*>& resTab, unsigned& offset)
{
SOFA_UNUSED(resTab);
SOFA_UNUSED(offset);
Expand Down
Loading