Skip to content

Commit

Permalink
Merge branch 'master' into 24_11_add_warning_when_using_disabled_mech…
Browse files Browse the repository at this point in the history
…anism
  • Loading branch information
bakpaul authored Dec 6, 2024
2 parents 4598a35 + fdacdac commit f989e41
Show file tree
Hide file tree
Showing 52 changed files with 2,225 additions and 286 deletions.
21 changes: 21 additions & 0 deletions .github/workflows/nix.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
name: "CI - Nix"

on:
push:

jobs:
nix:
runs-on: "${{ matrix.os }}-latest"
if: ${{ github.repository_owner == 'sofa-framework' }}
strategy:
matrix:
os: [ubuntu, macos]
steps:
- uses: actions/checkout@v4
- uses: cachix/install-nix-action@v27
# TODO: the "sofa" account on cachix does not exist yet
#- uses: cachix/cachix-action@v15
#with:
#name: sofa
#authToken: '${{ secrets.CACHIX_AUTH_TOKEN }}'
- run: nix build -L
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ class SlidingLagrangianConstraint : public core::behavior::PairInteractionConstr
SlidingLagrangianConstraint(MechanicalState* object);
SlidingLagrangianConstraint(MechanicalState* object1, MechanicalState* object2);

virtual ~SlidingLagrangianConstraint(){}
~SlidingLagrangianConstraint() override {}



Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,10 @@ void clearMultiVecId(sofa::core::objectmodel::BaseContext* ctx, const sofa::core

}

static constexpr GenericConstraintSolver::ResolutionMethod defaultResolutionMethod("ProjectedGaussSeidel");

GenericConstraintSolver::GenericConstraintSolver()
: d_resolutionMethod( initData(&d_resolutionMethod, "resolutionMethod", "Method used to solve the constraint problem, among: \"ProjectedGaussSeidel\", \"UnbuiltGaussSeidel\" or \"for NonsmoothNonlinearConjugateGradient\""))
: d_resolutionMethod( initData(&d_resolutionMethod, defaultResolutionMethod, "resolutionMethod", ("Method used to solve the constraint problem\n" + ResolutionMethod::dataDescription()).c_str()))
, d_maxIt(initData(&d_maxIt, 1000, "maxIterations", "maximal number of iterations of the Gauss-Seidel algorithm"))
, d_tolerance(initData(&d_tolerance, 0.001_sreal, "tolerance", "residual error threshold for termination of the Gauss-Seidel algorithm"))
, d_sor(initData(&d_sor, 1.0_sreal, "sor", "Successive Over Relaxation parameter (0-2)"))
Expand All @@ -86,10 +88,6 @@ GenericConstraintSolver::GenericConstraintSolver()
, current_cp(&m_cpBuffer[0])
, last_cp(nullptr)
{
sofa::helper::OptionsGroup m_newoptiongroup{"ProjectedGaussSeidel","UnbuiltGaussSeidel", "NonsmoothNonlinearConjugateGradient"};
m_newoptiongroup.setSelectedItem("ProjectedGaussSeidel");
d_resolutionMethod.setValue(m_newoptiongroup);

addAlias(&d_maxIt, "maxIt");

d_graphErrors.setWidget("graph");
Expand Down Expand Up @@ -159,7 +157,8 @@ void GenericConstraintSolver::init()

if(d_newtonIterations.isSet())
{
if (d_resolutionMethod.getValue().getSelectedId() != 2)
static constexpr ResolutionMethod NonsmoothNonlinearConjugateGradient("NonsmoothNonlinearConjugateGradient");
if (d_resolutionMethod.getValue() != NonsmoothNonlinearConjugateGradient)
{
msg_warning() << "data \"newtonIterations\" is not only taken into account when using the NonsmoothNonlinearConjugateGradient solver";
}
Expand Down Expand Up @@ -225,15 +224,15 @@ bool GenericConstraintSolver::buildSystem(const core::ConstraintParams *cParams,
}

// Resolution depending on the method selected
switch ( d_resolutionMethod.getValue().getSelectedId() )
switch ( d_resolutionMethod.getValue() )
{
case 0: // ProjectedGaussSeidel
case 2: // NonsmoothNonlinearConjugateGradient
case ResolutionMethod("ProjectedGaussSeidel"):
case ResolutionMethod("NonsmoothNonlinearConjugateGradient"):
{
buildSystem_matrixAssembly(cParams);
break;
}
case 1: // UnbuiltGaussSeidel
case ResolutionMethod("UnbuiltGaussSeidel"):
{
buildSystem_matrixFree(numConstraints);
break;
Expand Down Expand Up @@ -429,10 +428,9 @@ bool GenericConstraintSolver::solveSystem(const core::ConstraintParams * /*cPara


// Resolution depending on the method selected
switch ( d_resolutionMethod.getValue().getSelectedId() )
switch ( d_resolutionMethod.getValue())
{
// ProjectedGaussSeidel
case 0: {
case ResolutionMethod("ProjectedGaussSeidel"): {
if (notMuted())
{
std::stringstream tmp;
Expand All @@ -445,14 +443,12 @@ bool GenericConstraintSolver::solveSystem(const core::ConstraintParams * /*cPara
current_cp->gaussSeidel(0, this);
break;
}
// UnbuiltGaussSeidel
case 1: {
case ResolutionMethod("UnbuiltGaussSeidel"): {
SCOPED_TIMER_VARNAME(unbuiltGaussSeidelTimer, "ConstraintsUnbuiltGaussSeidel");
current_cp->unbuiltGaussSeidel(0, this);
break;
}
// NonsmoothNonlinearConjugateGradient
case 2: {
case ResolutionMethod("NonsmoothNonlinearConjugateGradient"): {
current_cp->NNCG(this, d_newtonIterations.getValue());
break;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@
#include <sofa/component/constraint/lagrangian/solver/visitors/MechanicalGetConstraintResolutionVisitor.h>

#include <sofa/core/objectmodel/RenamedData.h>
#include <sofa/helper/SelectableItem.h>


namespace sofa::component::constraint::lagrangian::solver
{
Expand Down Expand Up @@ -60,7 +62,13 @@ class SOFA_COMPONENT_CONSTRAINT_LAGRANGIAN_SOLVER_API GenericConstraintSolver :
ConstraintProblem* getConstraintProblem() override;
void lockConstraintProblem(sofa::core::objectmodel::BaseObject* from, ConstraintProblem* p1, ConstraintProblem* p2 = nullptr) override;

Data< sofa::helper::OptionsGroup > d_resolutionMethod; ///< Method used to solve the constraint problem, among: "ProjectedGaussSeidel", "UnbuiltGaussSeidel" or "for NonsmoothNonlinearConjugateGradient"
MAKE_SELECTABLE_ITEMS(ResolutionMethod,
sofa::helper::Item{"ProjectedGaussSeidel", "Projected Gauss-Seidel"},
sofa::helper::Item{"UnbuiltGaussSeidel", "Gauss-Seidel where the matrix is not assembled"},
sofa::helper::Item{"NonsmoothNonlinearConjugateGradient", "Non-smooth non-linear conjugate gradient"}
);

Data< ResolutionMethod > d_resolutionMethod; ///< Method used to solve the constraint problem, among: "ProjectedGaussSeidel", "UnbuiltGaussSeidel" or "for NonsmoothNonlinearConjugateGradient"

SOFA_ATTRIBUTE_DEPRECATED__RENAME_DATA_IN_CONSTRAINT_LAGRANGIAN_SOLVER()
sofa::core::objectmodel::RenamedData<int> maxIt;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,10 @@ void GraphScatteredMatrix::apply(GraphScatteredVector& res, GraphScatteredVector
{
// matrix-vector product through visitors
parent->propagateDxAndResetDf(x,res);
parent->addMBKdx(res,parent->mparams.mFactor(),parent->mparams.bFactor(),parent->mparams.kFactor(), false); // df = (m M + b B + k K) dx
parent->addMBKdx(res,
core::MatricesFactors::M(parent->mparams.mFactor()),
core::MatricesFactors::B(parent->mparams.bFactor()),
core::MatricesFactors::K(parent->mparams.kFactor()), false); // df = (m M + b B + k K) dx

// filter the product to take the constraints into account
//
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,6 @@
namespace sofa::component::mapping::linear
{

/**
* @class SubsetMapping
* @brief Compute a subset of input points
*/
template <class TIn, class TOut>
class SubsetMultiMapping : public LinearMultiMapping<TIn, TOut>
{
Expand All @@ -48,28 +44,6 @@ class SubsetMultiMapping : public LinearMultiMapping<TIn, TOut>
typedef TIn In;
typedef TOut Out;

typedef typename Out::VecCoord OutVecCoord;
typedef typename Out::VecDeriv OutVecDeriv;
typedef typename Out::Coord OutCoord;
typedef typename Out::Deriv OutDeriv;
typedef typename Out::MatrixDeriv OutMatrixDeriv;
typedef typename In::VecCoord InVecCoord;
typedef typename In::VecDeriv InVecDeriv;
typedef typename In::Coord InCoord;
typedef typename In::Deriv InDeriv;
typedef typename In::MatrixDeriv InMatrixDeriv;
typedef typename InCoord::value_type Real;
typedef typename type::vector<const InVecCoord*> vecConstInVecCoord;
typedef typename type::vector<OutVecCoord*> vecOutVecCoord;

typedef Data<InVecCoord> InDataVecCoord;
typedef Data<InVecDeriv> InDataVecDeriv;
typedef Data<InMatrixDeriv> InDataMatrixDeriv;

typedef Data<OutVecCoord> OutDataVecCoord;
typedef Data<OutVecDeriv> OutDataVecDeriv;
typedef Data<OutMatrixDeriv> OutDataMatrixDeriv;

/// Correspondence array
typedef core::topology::BaseMeshTopology::SetIndex IndexArray;

Expand All @@ -81,12 +55,12 @@ class SubsetMultiMapping : public LinearMultiMapping<TIn, TOut>
void addPoint(int fromModel, int index);

// usual Mapping API
void apply(const core::MechanicalParams* mparams, const type::vector<OutDataVecCoord*>& dataVecOutPos, const type::vector<const InDataVecCoord*>& dataVecInPos) override;
void applyJ(const core::MechanicalParams* mparams, const type::vector<OutDataVecDeriv*>& dataVecOutVel, const type::vector<const InDataVecDeriv*>& dataVecInVel) override;
void applyJT(const core::MechanicalParams* mparams, const type::vector<InDataVecDeriv*>& dataVecOutForce, const type::vector<const OutDataVecDeriv*>& dataVecInForce) override;
void apply(const core::MechanicalParams* mparams, const type::vector<DataVecCoord_t<Out>*>& dataVecOutPos, const type::vector<const DataVecCoord_t<In>*>& dataVecInPos) override;
void applyJ(const core::MechanicalParams* mparams, const type::vector<DataVecDeriv_t<Out>*>& dataVecOutVel, const type::vector<const DataVecDeriv_t<In>*>& dataVecInVel) override;
void applyJT(const core::MechanicalParams* mparams, const type::vector<DataVecDeriv_t<In>*>& dataVecOutForce, const type::vector<const DataVecDeriv_t<Out>*>& dataVecInForce) override;
void applyDJT(const core::MechanicalParams* /*mparams*/, core::MultiVecDerivId /*inForce*/, core::ConstMultiVecDerivId /*outForce*/) override {}

void applyJT( const core::ConstraintParams* cparams, const type::vector< InDataMatrixDeriv* >& dataMatOutConst, const type::vector< const OutDataMatrixDeriv* >& dataMatInConst ) override;
void applyJT( const core::ConstraintParams* cparams, const type::vector< DataMatrixDeriv_t<In>* >& dataMatOutConst, const type::vector< const DataMatrixDeriv_t<Out>* >& dataMatInConst ) override;

/// Experimental API used to handle multimappings in matrix assembly. Returns pointers to matrices associated with parent states, consistently with getFrom().
virtual const type::vector<sofa::linearalgebra::BaseMatrix*>* getJs() override;
Expand All @@ -99,7 +73,7 @@ class SubsetMultiMapping : public LinearMultiMapping<TIn, TOut>
protected :

SubsetMultiMapping();
virtual ~SubsetMultiMapping();
virtual ~SubsetMultiMapping() override;

type::vector<linearalgebra::BaseMatrix*> baseMatrices; ///< Jacobian of the mapping, in a vector

Expand All @@ -112,7 +86,6 @@ extern template class SOFA_COMPONENT_MAPPING_LINEAR_API SubsetMultiMapping< defa
extern template class SOFA_COMPONENT_MAPPING_LINEAR_API SubsetMultiMapping< defaulttype::Vec1Types, defaulttype::Vec1Types >;
extern template class SOFA_COMPONENT_MAPPING_LINEAR_API SubsetMultiMapping< defaulttype::Rigid3Types, defaulttype::Rigid3Types >;
extern template class SOFA_COMPONENT_MAPPING_LINEAR_API SubsetMultiMapping< defaulttype::Rigid3Types, defaulttype::Vec3Types >;

#endif

} // namespace sofa::component::mapping::linear
Loading

0 comments on commit f989e41

Please sign in to comment.