20 #ifndef _DYNAMIC_SYSTEM_SOLVER_H_ 21 #define _DYNAMIC_SYSTEM_SOLVER_H_ 23 #include "mbsim/group.h" 24 #include "fmatvec/sparse_matrix.h" 25 #include "mbsim/functions/function.h" 26 #include "mbsim/environment.h" 31 class MBSimEnvironment;
38 StateTable(
const std::string &name_,
char label_,
int number_) : name(name_), label(label_), number(number_) { }
71 enum Solver { fixedpoint, GaussSeidel, direct, rootfinding, unknownSolver };
131 void setTruncateSimulationFiles(
bool trunc) { truncateSimulationFiles=trunc; }
134 void init(
InitStage stage,
const InitConfigSet &config)
override;
150 void updateT()
override;
151 void updateh(
int i=0)
override;
152 void updateM()
override;
153 void updateLLM()
override;
154 void updatezd()
override;
170 virtual void updaterdt();
171 void updatewb()
override;
172 void updateg()
override;
173 void updategd()
override;
174 void updateW(
int j=0)
override;
175 void updateV(
int j=0)
override;
176 virtual void updatebc();
177 virtual void updatebi();
178 virtual void updatela();
179 virtual void updateLa();
188 void setImpactSolver(
Solver solver_) { impactSolver = solver_; }
190 const Solver& getImpactSolver() {
return impactSolver; }
191 void setTermination(
bool term_) {
term = term_; }
192 void setMaximumNumberOfIterations(
int iter) {
maxIter = iter; }
193 void setHighNumberOfIterations(
int iter) { highIter = iter; }
194 void setNumericalJacobian(
bool numJac_) {
numJac = numJac_; }
195 void setMaximumDampingSteps(
int maxDSteps) { maxDampingSteps = maxDSteps; }
196 void setLevenbergMarquardtParamater(
double lmParm_) {
lmParm = lmParm_; }
198 void setUseOldla(
bool flag) {
useOldla = flag; }
199 void setDecreaseLevels(
const fmatvec::VecInt &decreaseLevels_) {
decreaseLevels = decreaseLevels_; }
200 void setCheckTermLevels(
const fmatvec::VecInt &checkTermLevels_) {
checkTermLevels = checkTermLevels_; }
201 void setCheckGSize(
bool checkGSize_) {
checkGSize = checkGSize_; }
204 double& getTime() {
return t; }
205 const double& getTime()
const {
return t; }
206 void setTime(
double t_) {
t = t_; }
208 double getStepSize()
const {
return dt; }
209 void setStepSize(
double dt_) {
dt = dt_; }
211 int getzSize()
const {
return zSize; }
219 const fmatvec::SqrMat& getG(
bool check=
true)
const { assert((not check) or (not updG));
return G; }
220 const fmatvec::SparseMat& getGs(
bool check=
true)
const { assert((not check) or (not updG));
return Gs; }
221 const fmatvec::Vec& getbc(
bool check=
true)
const { assert((not check) or (not updbc));
return bc; }
222 const fmatvec::Vec& getbi(
bool check=
true)
const { assert((not check) or (not updbi));
return bi; }
224 fmatvec::SqrMat& getG(
bool check=
true) { assert((not check) or (not updG));
return G; }
225 fmatvec::SparseMat& getGs(
bool check=
true) { assert((not check) or (not updG));
return Gs; }
226 fmatvec::Vec& getbc(
bool check=
true) { assert((not check) or (not updbc));
return bc; }
227 fmatvec::Vec& getbi(
bool check=
true) { assert((not check) or (not updbi));
return bi; }
230 const fmatvec::Vec& evaldq() {
if(upddq) updatedq();
return dq; }
231 const fmatvec::Vec& evaldu() {
if(upddu) updatedu();
return du; }
232 const fmatvec::Vec& evaldx() {
if(upddx) updatedx();
return dx; }
235 const fmatvec::SparseMat& evalGs() {
if(updG)
updateG();
return Gs; }
237 const fmatvec::Vec& evalbi() {
if(updbi) updatebi();
return bi; }
241 const fmatvec::Vec& evalLa() {
if(updLa) updateLa();
return La; }
261 void resizezParent(
int nz) {
zParent.resize(nz); }
262 void resizezdParent(
int nz) {
zdParent.resize(nz); }
266 int getMaxIter() {
return maxIter;}
267 int getIterC() {
return iterc;}
268 int getIterI() {
return iteri;}
415 #ifdef HAVE_ANSICSIGNAL 416 using SigHandle = void (*)(int);
418 SigHandle oldSigTerm;
428 void checkExitRequest();
431 void setPartialEventDrivenSolver(
bool peds_) {
peds = peds_; }
438 void writez(std::string fileName,
bool formatH5=
true);
451 void readz0(std::string fileName);
453 void initializeUsingXML(xercesc::DOMElement *element)
override;
473 void setAlwaysConsiderContact(
bool alwaysConsiderContact_) { alwaysConsiderContact = alwaysConsiderContact_; }
475 void setInverseKinetics(
bool inverseKinetics_) { inverseKinetics = inverseKinetics_; }
476 bool getInverseKinetics()
const {
return inverseKinetics; }
478 void setInitialProjection(
bool initialProjection_) { initialProjection = initialProjection_; }
479 bool getInitialProjection()
const {
return initialProjection; }
481 void setDetermineEquilibriumState(
bool determineEquilibriumState_) { determineEquilibriumState = determineEquilibriumState_; }
482 bool getDetermineEquilibriumState()
const {
return determineEquilibriumState; }
484 void setUseConstraintSolverForSmoothMotion(
bool useConstraintSolverForSmoothMotion_) { useConstraintSolverForSmoothMotion = useConstraintSolverForSmoothMotion_; }
485 bool getUseConstraintSolverForSmoothMotion()
const {
return useConstraintSolverForSmoothMotion; }
487 void setUseConstraintSolverForPlot(
bool useConstraintSolverForPlot_) { useConstraintSolverForPlot = useConstraintSolverForPlot_; }
488 bool getUseConstraintSolverForPlot()
const {
return useConstraintSolverForPlot; }
495 void setRootID(
int ID) {rootID = ID;}
496 int getRootID()
const {
return rootID;}
498 void resetUpToDate()
override;
500 bool getUpdateT() {
return updT; }
501 bool getUpdateM() {
return updM; }
502 bool getUpdateLLM() {
return updLLM; }
503 bool getUpdateh(
int j) {
return updh[j]; }
504 bool getUpdater(
int j) {
return updr[j]; }
505 bool getUpdaterdt() {
return updrdt; }
506 bool getUpdateW(
int j) {
return updW[j]; }
507 bool getUpdateV(
int j) {
return updV[j]; }
508 bool getUpdatewb() {
return updwb; }
509 bool getUpdateg() {
return updg; }
510 bool getUpdategd() {
return updgd; }
511 bool getUpdatela() {
return updla; }
512 bool getUpdateLa() {
return updLa; }
513 bool getUpdatezd() {
return updzd; }
514 bool getUpdatedq() {
return upddq; }
515 bool getUpdatedu() {
return upddu; }
516 bool getUpdatedx() {
return upddx; }
517 void setUpdatela(
bool updla_) { updla = updla_; }
518 void setUpdateLa(
bool updLa_) { updLa = updLa_; }
519 void setUpdateG(
bool updG_) { updG = updG_; }
520 void setUpdatebi(
bool updbi_) { updbi = updbi_; }
521 void setUpdatebc(
bool updbc_) { updbc = updbc_; }
522 void setUpdatezd(
bool updzd_) { updzd = updzd_; }
523 void setUpdateW(
bool updW_,
int i=0) { updW[i] = updW_; }
562 void updatedq()
override;
563 void updatedu()
override;
564 void updatedx()
override;
566 void updateStopVector()
override;
568 void updateInternalState();
570 void plot()
override;
585 std::vector<StateTable>& getStateTable() {
return tabz; }
721 fmatvec::SparseMat
Gs;
746 int maxIter, highIter, maxDampingSteps, iterc, iteri;
819 bool alwaysConsiderContact;
820 bool inverseKinetics;
821 bool initialProjection;
822 bool determineEquilibriumState;
823 bool useConstraintSolverForSmoothMotion;
824 bool useConstraintSolverForPlot;
830 double gTol, gdTol, gddTol, laTol, LaTol;
832 bool updT, updh[2], updr[2], updrdt, updM, updLLM, updW[2], updV[2], updwb, updg, updgd, updG, updbc, updbi, updsv, updzd, updla, updLa, upddq, upddu, upddx;
836 std::vector<StateTable> tabz;
870 bool truncateSimulationFiles;
877 std::vector<DynamicSystem*> dynamicsystemPreReorganize;
881 std::vector<std::unique_ptr<Environment>> environments;
884 bool firstPlot {
true };
890 auto &reqType=
typeid(Env);
891 for(
auto &e : environments)
892 if(reqType==
typeid(*e))
893 return static_cast<Env*>(e.get());
895 addEnvironment(newEnv);
bool useOldla
flag if contac force parameter of last time step should be used
Definition: dynamic_system_solver.h:771
Definition: dynamic_system_solver.h:33
void plot() override
plots time dependent data
Definition: dynamic_system_solver.cc:1582
int solveImpactsGaussSeidel() override
solve impact equations with Gauss-Seidel scheme on velocity level
Definition: dynamic_system_solver.cc:516
int(DynamicSystemSolver::* solveConstraints_)()
Definition: dynamic_system_solver.h:280
int solveConstraintsLinearEquations()
solution of contact equations with Cholesky decomposition
Definition: dynamic_system_solver.cc:875
fmatvec::Vec gParent
relative distances
Definition: dynamic_system_solver.h:668
int zSize
size of state vector
Definition: dynamic_system_solver.h:601
double t
time
Definition: dynamic_system_solver.h:591
bool checkGSize
boolean if force action matrix should be resized in each step
Definition: dynamic_system_solver.h:791
int solveImpactsLinearEquations()
solution of contact equations with Cholesky decomposition on velocity level
Definition: dynamic_system_solver.cc:880
fmatvec::Vec rParent[2]
nonsmooth right hand side
Definition: dynamic_system_solver.h:695
int solveConstraintsGaussSeidel() override
solve contact equations with Gauss-Seidel scheme
Definition: dynamic_system_solver.cc:496
void initLa()
load contact impulses for use as starting value
Definition: dynamic_system_solver.cc:1134
bool term
boolean to check for termination of contact equations solution
Definition: dynamic_system_solver.h:741
void readz0(std::string fileName)
reads state from a file
Definition: dynamic_system_solver.cc:1275
Env * getEnvironment()
Definition: dynamic_system_solver.h:888
bool dropContactInfo
flag if contact matrices for debugging should be dropped in no-convergence case
Definition: dynamic_system_solver.h:766
int solveConstraintsFixpointSingle() override
solve contact equations with single step fixed point scheme
Definition: dynamic_system_solver.cc:434
double tolProj
Tolerance for projection of generalized position.
Definition: dynamic_system_solver.h:806
solver interface for modelling and simulation of dynamic systems
Definition: dynamic_system_solver.h:56
void initla()
load contact forces for use as starting value
Definition: dynamic_system_solver.cc:1124
virtual void updateVRef(fmatvec::Mat &VParent, int j=0)
references to condensed contact force direction matrix of dynamic system parent
Definition: dynamic_system.cc:828
fmatvec::SparseMat Gs
sparse mass action matrix
Definition: dynamic_system_solver.h:721
fmatvec::VecInt checkTermLevels
TODO.
Definition: dynamic_system_solver.h:786
DynamicSystemSolver(const std::string &name="")
constructor
Definition: dynamic_system_solver.cc:70
Solver contactSolver
solver for contact equations and impact equations
Definition: dynamic_system_solver.h:756
void updategRef(fmatvec::Vec &ref) override
references to relative distances of dynamic system parent
Definition: dynamic_system_solver.h:529
fmatvec::Vec bc
TODO.
Definition: dynamic_system_solver.h:736
bool stopIfNoConvergence
flag if the contact equations should be stopped if there is no convergence
Definition: dynamic_system_solver.h:761
virtual const fmatvec::Vec & shift()
update for event driven integrator for event
Definition: dynamic_system_solver.cc:1414
void updateVRef(fmatvec::Mat &ref, int i=0) override
references to condensed contact force direction matrix of dynamic system parent
Definition: dynamic_system_solver.h:555
fmatvec::Mat TParent
matrix of linear relation between differentiated positions and velocities
Definition: dynamic_system_solver.h:626
fmatvec::Vec sParent
TODO.
Definition: dynamic_system_solver.h:656
fmatvec::VecInt LinkStatusRegParent
status vector of single valued links
Definition: dynamic_system_solver.h:716
Definition: environment.h:37
fmatvec::Vec zd
derivative of state vector
Definition: dynamic_system_solver.h:611
void getLinkStatusReg(fmatvec::VecInt &LinkStatusRegExt)
Definition: dynamic_system_solver.cc:994
void updateWRef(fmatvec::Mat &ref, int i=0) override
references to contact force direction matrix of dynamic system parent
Definition: dynamic_system_solver.h:548
fmatvec::Vec gdParent
relative velocities
Definition: dynamic_system_solver.h:673
void projectGeneralizedVelocities(int mode)
drift projection for positions
Definition: dynamic_system_solver.cc:1081
fmatvec::VecInt LinkStatusParent
status vector of set valued links with piecewise link equation (which piece is valid)
Definition: dynamic_system_solver.h:710
virtual void updatewbRef(fmatvec::Vec &wbParent)
references to TODO of dynamic system parent
Definition: dynamic_system.cc:800
group ingredients do not depend on each other
Definition: group.h:35
void checkImpactsForTermination() override
validate force laws concerning given tolerances on velocity level
Definition: dynamic_system_solver.cc:679
std::string getSolverInfo()
Definition: dynamic_system_solver.cc:1178
fmatvec::Vec z
state vector
Definition: dynamic_system_solver.h:606
basic class of MBSim mainly for plotting
Definition: element.h:56
static void sigInterruptHandler(int)
handler for user interrupt signal
Definition: dynamic_system_solver.cc:1228
double lmParm
Levenberg-Marquard parameter.
Definition: dynamic_system_solver.h:751
int solveImpactsFixpointSingle() override
solve impact equations with single step fixed point scheme on velocity level
Definition: dynamic_system_solver.cc:465
void addElement(Element *element_)
Definition: dynamic_system_solver.cc:1139
fmatvec::Vec rFactorParent
relaxation parameters for contact equations
Definition: dynamic_system_solver.h:651
void checkConstraintsForTermination() override
validate force laws concerning given tolerances
Definition: dynamic_system_solver.cc:668
virtual void updateWRef(fmatvec::Mat &WParent, int j=0)
references to contact force direction matrix of dynamic system parent
Definition: dynamic_system.cc:807
fmatvec::VecInt decreaseLevels
decreasing relaxation factors is done in levels containing the number of contact iterations as condit...
Definition: dynamic_system_solver.h:781
virtual void updatelaInverseKinetics()
update inverse kinetics constraint forces
Definition: dynamic_system_solver.cc:1507
void setStopIfNoConvergence(bool flag, bool dropInfo=false)
Definition: dynamic_system_solver.h:401
Definition: dynamic_system_solver.h:58
Definition: environment.h:59
virtual void updater(int j=0)
update smooth link force law
Definition: dynamic_system_solver.cc:793
void dropContactMatrices()
Definition: dynamic_system_solver.cc:1193
void updatezdRef(fmatvec::Vec &ext)
references to differentiated external state
Definition: dynamic_system_solver.cc:1295
void initialize()
Initialize the system.
Definition: dynamic_system_solver.cc:88
virtual void updateG()
updates mass action matrix
Definition: dynamic_system_solver.cc:885
~DynamicSystemSolver() override
destructor
Definition: dynamic_system_solver.cc:80
bool numJac
flag if Jacobian for Newton scheme should be calculated numerically
Definition: dynamic_system_solver.h:776
fmatvec::Mat WParent[2]
contact force directions
Definition: dynamic_system_solver.h:631
void plot() override
plots time dependent data
Definition: dynamic_system.cc:332
class for tree-structured mechanical systems with recursive and flat memory mechanism
Definition: graph.h:36
InitStage
The stages of the initialization.
Definition: element.h:62
void setProjectionTolerance(double tol)
set tolerance for projection of generalized position
Definition: dynamic_system_solver.h:459
int(DynamicSystemSolver::* solveImpacts_)()
function pointer for election of prox-solver for impact equations on velocity level
Definition: dynamic_system_solver.h:287
Element * getElement(const std::string &name)
Definition: dynamic_system_solver.cc:1151
bool positionDriftCompensationNeeded(double gmax)
check if drift compensation on position level is needed
Definition: dynamic_system_solver.cc:1002
fmatvec::VecInt jsvParent
boolean evaluation of stopvector
Definition: dynamic_system_solver.h:705
void savela()
save contact forces for use as starting value in next time step
Definition: dynamic_system_solver.cc:1119
Definition: contact_kinematics.h:32
void projectGeneralizedPositions(int mode, bool fullUpdate=false)
drift projection for positions
Definition: dynamic_system_solver.cc:1028
fmatvec::SymMat LLMParent
Cholesky decomposition of mass matrix.
Definition: dynamic_system_solver.h:621
std::string name
name of element
Definition: element.h:249
static std::atomic< bool > exitRequest
boolean signal evaluation for end integration set by user
Definition: dynamic_system_solver.h:852
int limitGSize
TODO.
Definition: dynamic_system_solver.h:796
fmatvec::SymMat MParent
mass matrix
Definition: dynamic_system_solver.h:616
bool peds
TODO, flag for occuring impact and sticking in event driven solver.
Definition: dynamic_system_solver.h:801
fmatvec::Vec hParent[2]
smooth, smooth with respect to objects, smooth with respect to links right hand side
Definition: dynamic_system_solver.h:690
void writeStateTable(std::string fileName)
writes state table to a file
Definition: dynamic_system_solver.cc:1264
void constructor()
set plot feature default values
Definition: dynamic_system_solver.cc:1309
fmatvec::SqrMat G
mass action matrix
Definition: dynamic_system_solver.h:731
double dt
step size
Definition: dynamic_system_solver.h:596
void saveLa()
save contact impulses for use as starting value in next time step
Definition: dynamic_system_solver.cc:1129
bool integratorExitRequest
boolean signal evaluation for end integration set by program
Definition: dynamic_system_solver.h:847
fmatvec::Vec wbParent
TODO.
Definition: dynamic_system_solver.h:641
void addToGraph(Graph *graph, fmatvec::SqrMat &A, int i, std::vector< Element * > &objList)
adds list of objects to tree
Definition: dynamic_system_solver.cc:1401
virtual void updategRef(fmatvec::Vec &gParent)
references to relative distances of dynamic system parent
Definition: dynamic_system.cc:765
void updatewbRef(fmatvec::Vec &ref) override
references to TODO of dynamic system parent
Definition: dynamic_system_solver.h:541
fmatvec::Vec la
contact force parameters
Definition: dynamic_system.h:856
int maxIter
maximum number of contact iterations, high number of contact iterations for warnings,...
Definition: dynamic_system_solver.h:746
void getLinkStatus(fmatvec::VecInt &LinkStatusExt)
Definition: dynamic_system_solver.cc:986
Solver
solver for contact equations
Definition: dynamic_system_solver.h:71
MBSimEnvironment * getMBSimEnvironment()
Definition: dynamic_system_solver.cc:1622
fmatvec::Vec zParent
state
Definition: dynamic_system_solver.h:678
fmatvec::Vec laParent
contact force parameters
Definition: dynamic_system_solver.h:646
fmatvec::Vec resParent
residuum of contact equations
Definition: dynamic_system_solver.h:661
bool velocityDriftCompensationNeeded(double gdmax)
check if drift compensation on velocity level is needed
Definition: dynamic_system_solver.cc:1015
fmatvec::Vec svParent
stopvector (rootfunctions for event driven integration
Definition: dynamic_system_solver.h:700
fmatvec::SqrMat Jprox
JACOBIAN of contact equations for Newton scheme.
Definition: dynamic_system_solver.h:726
fmatvec::Mat VParent[2]
condensed contact force directions
Definition: dynamic_system_solver.h:636
void updatezRef(fmatvec::Vec &ext)
references to external state
Definition: dynamic_system_solver.cc:1283
void writez(std::string fileName, bool formatH5=true)
writes state to a file
Definition: dynamic_system_solver.cc:1242
void init(InitStage stage, const InitConfigSet &config) override
plots time series header
Definition: dynamic_system_solver.cc:104
int solveConstraintsRootFinding() override
solve contact equations with Newton scheme
Definition: dynamic_system_solver.cc:536
void decreaserFactors()
decrease relaxation factors if mass action matrix is not diagonal dominant
Definition: dynamic_system_solver.cc:980
void computeInitialCondition()
compute initial condition for links for event driven integrator
Definition: dynamic_system_solver.cc:836
bool READZ0
is a state read from a file
Definition: dynamic_system_solver.h:853
int solveImpactsRootFinding() override
solve impact equations with Newton scheme on velocity level
Definition: dynamic_system_solver.cc:603
void updategdRef(fmatvec::Vec &ref) override
references to relative velocities of dynamic system parent
Definition: dynamic_system_solver.h:535
virtual void updategdRef(fmatvec::Vec &gdParent)
references to relative velocities of dynamic system parent
Definition: dynamic_system.cc:772
fmatvec::Vec zdParent
differentiated state
Definition: dynamic_system_solver.h:683
Definition: dynamic_system_solver.h:410
namespace MBSim
Definition: bilateral_constraint.cc:29