Skip to content

Commit e20d427

Browse files
authored
Merge branch 'master' into fix-ogden
2 parents d11d313 + 0648009 commit e20d427

File tree

37 files changed

+225
-104
lines changed

37 files changed

+225
-104
lines changed

CMakePresets.json

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,14 @@
143143
"type": "BOOL",
144144
"value": "ON"
145145
},
146+
"SOFA_FETCH_SOFTROBOTS_INVERSE": {
147+
"type": "BOOL",
148+
"value": "ON"
149+
},
150+
"PLUGIN_SOFTROBOTS_INVERSE": {
151+
"type": "BOOL",
152+
"value": "ON"
153+
},
146154
"PLUGIN_SOFTROBOTS_CUDA": {
147155
"type": "BOOL",
148156
"value": "ON"
@@ -159,6 +167,14 @@
159167
"type": "BOOL",
160168
"value": "ON"
161169
},
170+
"SOFA_FETCH_SOFAVISCOELASTIC": {
171+
"type": "BOOL",
172+
"value": "ON"
173+
},
174+
"PLUGIN_SOFAVISCOELASTIC": {
175+
"type": "BOOL",
176+
"value": "ON"
177+
},
162178
"PLUGIN_SOFAMATRIX": {
163179
"type": "BOOL",
164180
"value": "ON"

Sofa/Component/AnimationLoop/src/sofa/component/animationloop/FreeMotionAnimationLoop.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@
4747
#include <sofa/component/constraint/lagrangian/solver/ProjectedGaussSeidelConstraintSolver.h>
4848

4949
#include <sofa/simulation/mechanicalvisitor/MechanicalVInitVisitor.h>
50+
51+
#include <sofa/component/constraint/lagrangian/solver/ProjectedGaussSeidelConstraintSolver.h>
5052
using sofa::simulation::mechanicalvisitor::MechanicalVInitVisitor;
5153

5254

@@ -102,7 +104,7 @@ void FreeMotionAnimationLoop::init()
102104
l_constraintSolver.set(this->getContext()->get<sofa::core::behavior::ConstraintSolver>(core::objectmodel::BaseContext::SearchDown));
103105
if (!l_constraintSolver)
104106
{
105-
if (const auto constraintSolver = sofa::core::objectmodel::New<DefaultConstraintSolver>())
107+
if (const auto constraintSolver = sofa::core::objectmodel::New<constraint::lagrangian::solver::ProjectedGaussSeidelConstraintSolver>())
106108
{
107109
getContext()->addObject(constraintSolver);
108110
constraintSolver->setName( this->getContext()->getNameHelper().resolveName(constraintSolver->getClassName(), {}));

Sofa/Component/Constraint/Lagrangian/Solver/src/sofa/component/constraint/lagrangian/solver/BuiltConstraintSolver.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828

2929
namespace sofa::component::constraint::lagrangian::solver
3030
{
31+
3132
BuiltConstraintSolver::BuiltConstraintSolver()
3233
: d_multithreading(initData(&d_multithreading, false, "multithreading", "Build compliances concurrently"))
3334
{}

Sofa/Component/Constraint/Lagrangian/Solver/src/sofa/component/constraint/lagrangian/solver/BuiltConstraintSolver.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525

2626
namespace sofa::component::constraint::lagrangian::solver
2727
{
28+
2829
/**
2930
* \brief This component implements a generic way of building system for solvers that use a built
3031
* version of the constraint matrix. Any solver that uses a build matrix should inherit from this.
@@ -34,7 +35,6 @@ namespace sofa::component::constraint::lagrangian::solver
3435
class SOFA_COMPONENT_CONSTRAINT_LAGRANGIAN_SOLVER_API BuiltConstraintSolver : public GenericConstraintSolver
3536
{
3637

37-
3838
public:
3939
SOFA_CLASS(BuiltConstraintSolver, GenericConstraintSolver);
4040
Data<bool> d_multithreading; ///< Build compliances concurrently

Sofa/Component/Constraint/Lagrangian/Solver/src/sofa/component/constraint/lagrangian/solver/GenericConstraintProblem.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ void GenericConstraintProblem::solveTimed(SReal tol, int maxIt, SReal timeout)
7474
tolerance = tol;
7575
maxIterations = maxIt;
7676

77+
7778
m_solver->doSolve(this, timeout);
7879

7980
tolerance = tempTol;

Sofa/Component/Constraint/Lagrangian/Solver/src/sofa/component/constraint/lagrangian/solver/GenericConstraintSolver.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,7 @@ bool GenericConstraintSolver::buildSystem(const core::ConstraintParams *cParams,
209209
}
210210

211211

212+
212213
this->doBuildSystem(cParams, current_cp, numConstraints);
213214

214215
return true;

Sofa/Component/Constraint/Lagrangian/Solver/src/sofa/component/constraint/lagrangian/solver/GenericConstraintSolver.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,12 +60,14 @@ class SOFA_COMPONENT_CONSTRAINT_LAGRANGIAN_SOLVER_API GenericConstraintSolver :
6060
ConstraintProblem* getConstraintProblem() override;
6161
void lockConstraintProblem(sofa::core::objectmodel::BaseObject* from, ConstraintProblem* p1, ConstraintProblem* p2 = nullptr) override;
6262

63+
6364
Data<int> d_maxIt; ///< maximal number of iterations of iterative algorithm
6465
Data<SReal> d_tolerance; ///< residual error threshold for termination of the Gauss-Seidel algorithm
6566
Data<SReal> d_sor; ///< Successive Over Relaxation parameter (0-2)
6667
Data< SReal > d_regularizationTerm; ///< add regularization*Id to W when solving for constraints
6768
Data<bool> d_scaleTolerance; ///< Scale the error tolerance with the number of constraints
6869
Data<bool> d_allVerified; ///< All constraints must be verified (each constraint's error < tolerance)
70+
6971
Data<bool> d_computeGraphs; ///< Compute graphs of errors and forces during resolution
7072
Data<std::map < std::string, sofa::type::vector<SReal> > > d_graphErrors; ///< Sum of the constraints' errors at each iteration
7173
Data<std::map < std::string, sofa::type::vector<SReal> > > d_graphConstraints; ///< Graph of each constraint's error at the end of the resolution

Sofa/Component/Constraint/Lagrangian/Solver/src/sofa/component/constraint/lagrangian/solver/NNCGConstraintSolver.cpp

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ void NNCGConstraintSolver::doSolve(GenericConstraintProblem * problem , SReal ti
3333
{
3434
SCOPED_TIMER_VARNAME(unbuiltGaussSeidelTimer, "NonsmoothNonlinearConjugateGradient");
3535

36-
3736
const int dimension = problem->getDimension();
3837

3938
if(!dimension)
@@ -70,18 +69,21 @@ void NNCGConstraintSolver::doSolve(GenericConstraintProblem * problem , SReal ti
7069
tempForces.resize(dimension);
7170
}
7271

72+
7373
if(problem->scaleTolerance && !problem->allVerified)
7474
{
7575
tol *= dimension;
7676
}
7777

7878
for(int i=0; i<dimension; )
7979
{
80+
8081
if(!problem->constraintsResolutions[i])
8182
{
8283
msg_error() << "Bad size of constraintsResolutions in GenericConstraintSolver" ;
8384
break;
8485
}
86+
8587
problem->constraintsResolutions[i]->init(i, w, force);
8688
i += problem->constraintsResolutions[i]->getNbLines();
8789
}
@@ -91,6 +93,7 @@ void NNCGConstraintSolver::doSolve(GenericConstraintProblem * problem , SReal ti
9193
{
9294
// perform one iteration of ProjectedGaussSeidel
9395
bool constraintsAreVerified = true;
96+
9497
std::copy_n(force, dimension, std::begin(problem->m_lam));
9598

9699
gaussSeidel_increment(false, dfree, force, w, tol, d, dimension, constraintsAreVerified, error, problem->constraintsResolutions, tabErrors);
@@ -118,6 +121,7 @@ void NNCGConstraintSolver::doSolve(GenericConstraintProblem * problem , SReal ti
118121

119122

120123
error=0.0;
124+
121125
gaussSeidel_increment(true, dfree, force, w, tol, d, dimension, constraintsAreVerified, error, problem->constraintsResolutions, tabErrors);
122126

123127

@@ -158,6 +162,11 @@ void NNCGConstraintSolver::doSolve(GenericConstraintProblem * problem , SReal ti
158162
problem->m_p[j] = beta*problem->m_p[j] -problem-> m_deltaF[j];
159163
}
160164
}
165+
//Stopping condition based on constraint evolution rate
166+
if (problem->m_deltaF_new.norm() < tol)
167+
{
168+
break;
169+
}
161170
}
162171

163172
problem->result_output(this, force, error, iterCount, convergence);

Sofa/Component/Constraint/Lagrangian/Solver/src/sofa/component/constraint/lagrangian/solver/ProjectedGaussSeidelConstraintSolver.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,13 @@
2929
namespace sofa::component::constraint::lagrangian::solver
3030
{
3131

32+
3233
void ProjectedGaussSeidelConstraintSolver::doSolve( GenericConstraintProblem * problem ,SReal timeout)
3334
{
3435
SCOPED_TIMER_VARNAME(gaussSeidelTimer, "ConstraintsGaussSeidel");
3536

3637

38+
3739
const int dimension = problem->getDimension();
3840

3941
if(!dimension)
@@ -46,6 +48,7 @@ void ProjectedGaussSeidelConstraintSolver::doSolve( GenericConstraintProblem * p
4648
const SReal t0 = (SReal)sofa::helper::system::thread::CTime::getTime() ;
4749
const SReal timeScale = 1.0 / (SReal)sofa::helper::system::thread::CTime::getTicksPerSec();
4850

51+
4952
SReal *dfree = problem->getDfree();
5053
SReal *force = problem->getF();
5154
SReal **w = problem->getW();
@@ -99,17 +102,20 @@ void ProjectedGaussSeidelConstraintSolver::doSolve( GenericConstraintProblem * p
99102

100103
int iterCount = 0;
101104

105+
102106
for(int i=0; i<problem->maxIterations; i++)
103107
{
104108
iterCount ++;
105109
bool constraintsAreVerified = true;
106110

111+
107112
if(problem->sor != 1.0)
108113
{
109114
std::copy_n(force, dimension, tempForces.begin());
110115
}
111116

112117
error=0.0;
118+
113119
gaussSeidel_increment(true, dfree, force, w, tol, d, dimension, constraintsAreVerified, error, problem->constraintsResolutions, tabErrors);
114120

115121
if(showGraphs)
@@ -193,6 +199,7 @@ void ProjectedGaussSeidelConstraintSolver::doSolve( GenericConstraintProblem * p
193199
d_graphForces.endEdit();
194200
}
195201
}
202+
196203
void ProjectedGaussSeidelConstraintSolver::gaussSeidel_increment(bool measureError, SReal *dfree, SReal *force, SReal **w, SReal tol, SReal *d, int dim, bool& constraintsAreVerified, SReal& error, std::vector<core::behavior::ConstraintResolution*>& constraintCorrections, sofa::type::vector<SReal>& tabErrors) const
197204
{
198205
for(int j=0; j<dim; ) // increment of j realized at the end of the loop

Sofa/Component/Constraint/Lagrangian/Solver/src/sofa/component/constraint/lagrangian/solver/ProjectedGaussSeidelConstraintSolver.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ class SOFA_COMPONENT_CONSTRAINT_LAGRANGIAN_SOLVER_API ProjectedGaussSeidelConstr
3030
{
3131
public:
3232
SOFA_CLASS(ProjectedGaussSeidelConstraintSolver, BuiltConstraintSolver);
33+
3334
protected:
3435
virtual void doSolve(GenericConstraintProblem * problem , SReal timeout = 0.0) override;
3536

0 commit comments

Comments
 (0)