-
Notifications
You must be signed in to change notification settings - Fork 359
Expand file tree
/
Copy pathConstraintAnimationLoop.h
More file actions
170 lines (127 loc) · 7.71 KB
/
Copy pathConstraintAnimationLoop.h
File metadata and controls
170 lines (127 loc) · 7.71 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
/******************************************************************************
* SOFA, Simulation Open-Framework Architecture *
* (c) 2006 INRIA, USTL, UJF, CNRS, MGH *
* *
* This program is free software; you can redistribute it and/or modify it *
* under the terms of the GNU Lesser General Public License as published by *
* the Free Software Foundation; either version 2.1 of the License, or (at *
* your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, but WITHOUT *
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or *
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License *
* for more details. *
* *
* You should have received a copy of the GNU Lesser General Public License *
* along with this program. If not, see <http://www.gnu.org/licenses/>. *
*******************************************************************************
* Authors: The SOFA Team and external contributors (see Authors.txt) *
* *
* Contact information: contact@sofa-framework.org *
******************************************************************************/
#pragma once
#include <sofa/component/animationloop/config.h>
SOFA_HEADER_DEPRECATED_NOT_REPLACED("v26.06", "v26.12")
#include <sofa/helper/map.h>
#include <sofa/linearalgebra/FullMatrix.h>
#include <sofa/core/MultiVecId.h>
#include <sofa/core/VecId.h>
#include <sofa/core/behavior/BaseConstraintCorrection.h>
#include <sofa/core/behavior/OdeSolver.h>
#include <sofa/core/ConstraintParams.h>
#include <sofa/core/fwd.h>
#include <sofa/simulation/CollisionAnimationLoop.h>
#include <sofa/simulation/MechanicalVisitor.h>
#include <sofa/simulation/fwd.h>
#include <vector>
namespace sofa::simulation::mechanicalvisitor
{
class MechanicalAccumulateMatrixDeriv;
class MechanicalBuildConstraintMatrix;
}
namespace sofa::component::constraint::lagrangian::solver
{
class MechanicalGetConstraintResolutionVisitor;
}
namespace sofa::component::animationloop
{
class SOFA_COMPONENT_ANIMATIONLOOP_API ConstraintProblem
{
protected:
sofa::linearalgebra::LPtrFullMatrix<SReal> _W;
sofa::linearalgebra::FullVector<SReal> _dFree, _force, _d, _df;// cf. These Duriez + _df for scheme correction
std::vector<core::behavior::ConstraintResolution*> _constraintsResolutions;
SReal _tol;
int _dim;
sofa::helper::system::thread::CTime *_timer;
public:
ConstraintProblem(bool printLog=false);
virtual ~ConstraintProblem();
virtual void clear(int dim, const SReal &tol);
inline int getSize(void) {return _dim;}
inline sofa::linearalgebra::LPtrFullMatrix<SReal>* getW(void) {return &_W;}
inline sofa::linearalgebra::FullVector<SReal>* getDfree(void) {return &_dFree;}
inline sofa::linearalgebra::FullVector<SReal>* getD(void) {return &_d;}
inline sofa::linearalgebra::FullVector<SReal>* getF(void) {return &_force;}
inline sofa::linearalgebra::FullVector<SReal>* getdF(void) {return &_df;}
inline std::vector<core::behavior::ConstraintResolution*>& getConstraintResolutions(void) {return _constraintsResolutions;}
inline SReal *getTolerance(void) {return &_tol;}
void gaussSeidelConstraintTimed(SReal &timeout, int numItMax);
};
class SOFA_COMPONENT_ANIMATIONLOOP_API ConstraintAnimationLoop : public sofa::simulation::CollisionAnimationLoop
{
public:
typedef sofa::simulation::CollisionAnimationLoop Inherit;
SOFA_CLASS(ConstraintAnimationLoop, sofa::simulation::CollisionAnimationLoop);
protected:
ConstraintAnimationLoop();
~ConstraintAnimationLoop() override;
public:
void init() override;
Data<bool> d_displayTime; ///< Display time for each important step of ConstraintAnimationLoop.
Data<SReal> d_tol; ///< Tolerance of the Gauss-Seidel
Data<int> d_maxIt; ///< Maximum number of iterations of the Gauss-Seidel
Data<bool> d_doCollisionsFirst; ///< Compute the collisions first (to support penality-based contacts)
Data<bool> d_doubleBuffer; ///< Double the buffer dedicated to the constraint problem to make it accessible to another thread
Data<bool> d_scaleTolerance; ///< Scale the error tolerance with the number of constraints
Data<bool> d_allVerified; ///< All constraints must be verified (each constraint's error < tolerance)
Data<SReal> d_sor; ///< Successive Over Relaxation parameter (0-2)
Data<bool> d_schemeCorrection; ///< Apply new scheme where compliance is progressively corrected
Data<bool> d_realTimeCompensation; ///< If the total computational time T < dt, sleep(dt-T)
Data<bool> d_activateSubGraph;
Data<std::map < std::string, sofa::type::vector<SReal> > > d_graphErrors; ///< Sum of the constraints' errors at each iteration
Data<std::map < std::string, sofa::type::vector<SReal> > > d_graphConstraints; ///< Graph of each constraint's error at the end of the resolution
Data<std::map < std::string, sofa::type::vector<SReal> > > d_graphForces; ///< Graph of each constraint's force at each step of the resolution
ConstraintProblem *getConstraintProblem() {return bufCP1 ? &CP1 : &CP2;}
protected:
void doStep(const core::ExecParams* params, SReal dt) override;
void launchCollisionDetection(const core::ExecParams* params);
void freeMotion(const core::ExecParams* params, simulation::Node *context, SReal &dt);
void setConstraintEquations(const core::ExecParams* params, simulation::Node *context);
void correctiveMotion(const core::ExecParams* params, simulation::Node *context);
void debugWithContact(int numConstraints);
/// Specific procedures that are called for setting the constraints:
/// 1.calling resetConstraint & setConstraint & accumulateConstraint visitors
/// and resize the constraint problem that will be solved
void writeAndAccumulateAndCountConstraintDirections(const core::ExecParams* params, simulation::Node *context, unsigned int &numConstraints);
/// 2.calling GetConstraintViolationVisitor: each constraint provides its present violation
/// for a given state (by default: free_position TODO: add VecId to make this method more generic)
void getIndividualConstraintViolations(const core::ExecParams* params, simulation::Node *context);
/// 3.calling getConstraintResolution: each constraint provides a method that is used to solve it during GS iterations
void getIndividualConstraintSolvingProcess(const core::ExecParams* params, simulation::Node *context);
/// 4.calling addComplianceInConstraintSpace projected in the contact space => getDelassusOperator(_W) = H*C*Ht
virtual void computeComplianceInConstraintSpace();
/// method for predictive scheme:
void computePredictiveForce(int dim, SReal* force, std::vector<core::behavior::ConstraintResolution*>& res);
void gaussSeidelConstraint(int dim, SReal* dfree, SReal** w, SReal* force, SReal* d, std::vector<core::behavior::ConstraintResolution*>& res, SReal* df);
std::vector<core::behavior::BaseConstraintCorrection*> constraintCorrections;
virtual ConstraintProblem* getCP();
sofa::helper::system::thread::CTime *timer;
SReal timeScale, time ;
unsigned int numConstraints;
bool bufCP1;
SReal compTime, iterationTime;
private:
ConstraintProblem CP1, CP2;
};
} //namespace sofa::component::animationloop