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" 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;}
409 static void installSignalHandler();
421 static void sigSegfaultHandler(
int);
423 void checkExitRequest();
426 void setPartialEventDrivenSolver(
bool peds_) {
peds = peds_; }
433 void writez(std::string fileName,
bool formatH5=
true);
446 void readz0(std::string fileName);
448 void initializeUsingXML(xercesc::DOMElement *element)
override;
474 void setAlwaysConsiderContact(
bool alwaysConsiderContact_) { alwaysConsiderContact = alwaysConsiderContact_; }
476 void setInverseKinetics(
bool inverseKinetics_) { inverseKinetics = inverseKinetics_; }
477 bool getInverseKinetics()
const {
return inverseKinetics; }
479 void setInitialProjection(
bool initialProjection_) { initialProjection = initialProjection_; }
480 bool getInitialProjection()
const {
return initialProjection; }
482 void setDetermineEquilibriumState(
bool determineEquilibriumState_) { determineEquilibriumState = determineEquilibriumState_; }
483 bool getDetermineEquilibriumState()
const {
return determineEquilibriumState; }
485 void setUseConstraintSolverForSmoothMotion(
bool useConstraintSolverForSmoothMotion_) { useConstraintSolverForSmoothMotion = useConstraintSolverForSmoothMotion_; }
486 bool getUseConstraintSolverForSmoothMotion()
const {
return useConstraintSolverForSmoothMotion; }
488 void setUseConstraintSolverForPlot(
bool useConstraintSolverForPlot_) { useConstraintSolverForPlot = useConstraintSolverForPlot_; }
489 bool getUseConstraintSolverForPlot()
const {
return useConstraintSolverForPlot; }
496 void setRootID(
int ID) {rootID = ID;}
497 int getRootID()
const {
return rootID;}
499 void resetUpToDate()
override;
501 bool getUpdateT() {
return updT; }
502 bool getUpdateM() {
return updM; }
503 bool getUpdateLLM() {
return updLLM; }
504 bool getUpdateh(
int j) {
return updh[j]; }
505 bool getUpdater(
int j) {
return updr[j]; }
506 bool getUpdaterdt() {
return updrdt; }
507 bool getUpdateW(
int j) {
return updW[j]; }
508 bool getUpdateV(
int j) {
return updV[j]; }
509 bool getUpdatewb() {
return updwb; }
510 bool getUpdateg() {
return updg; }
511 bool getUpdategd() {
return updgd; }
512 bool getUpdatela() {
return updla; }
513 bool getUpdateLa() {
return updLa; }
514 bool getUpdatezd() {
return updzd; }
515 bool getUpdatedq() {
return upddq; }
516 bool getUpdatedu() {
return upddu; }
517 bool getUpdatedx() {
return upddx; }
518 void setUpdatela(
bool updla_) { updla = updla_; }
519 void setUpdateLa(
bool updLa_) { updLa = updLa_; }
520 void setUpdateG(
bool updG_) { updG = updG_; }
521 void setUpdatebi(
bool updbi_) { updbi = updbi_; }
522 void setUpdatebc(
bool updbc_) { updbc = updbc_; }
523 void setUpdatezd(
bool updzd_) { updzd = updzd_; }
524 void setUpdateW(
bool updW_,
int i=0) { updW[i] = updW_; }
563 void updatedq()
override;
564 void updatedu()
override;
565 void updatedx()
override;
567 void updateStopVector()
override;
569 void updateInternalState();
571 void plot()
override;
586 std::vector<StateTable>& getStateTable() {
return tabz; }
722 fmatvec::SparseMat
Gs;
747 int maxIter, highIter, maxDampingSteps, iterc, iteri;
832 bool alwaysConsiderContact;
833 bool inverseKinetics;
834 bool initialProjection;
835 bool determineEquilibriumState;
836 bool useConstraintSolverForSmoothMotion;
837 bool useConstraintSolverForPlot;
843 double gTol, gdTol, gddTol, laTol, LaTol;
845 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;
849 std::vector<StateTable> tabz;
882 bool truncateSimulationFiles;
889 std::vector<DynamicSystem*> dynamicsystemPreReorganize;
893 std::vector<std::unique_ptr<Environment>> environments;
900 auto &reqType=
typeid(Env);
901 for(
auto &e : environments)
902 if(reqType==
typeid(*e))
903 return static_cast<Env*>(e.get());
905 addEnvironment(newEnv);
bool useOldla
flag if contac force parameter of last time step should be used
Definition: dynamic_system_solver.h:772
Definition: dynamic_system_solver.h:33
void plot() override
plots time dependent data
Definition: dynamic_system_solver.cc:1585
int solveImpactsGaussSeidel() override
solve impact equations with Gauss-Seidel scheme on velocity level
Definition: dynamic_system_solver.cc:504
int(DynamicSystemSolver::* solveConstraints_)()
Definition: dynamic_system_solver.h:280
int solveConstraintsLinearEquations()
solution of contact equations with Cholesky decomposition
Definition: dynamic_system_solver.cc:863
fmatvec::Vec gParent
relative distances
Definition: dynamic_system_solver.h:669
int zSize
size of state vector
Definition: dynamic_system_solver.h:602
double t
time
Definition: dynamic_system_solver.h:592
bool checkGSize
boolean if force action matrix should be resized in each step
Definition: dynamic_system_solver.h:792
int solveImpactsLinearEquations()
solution of contact equations with Cholesky decomposition on velocity level
Definition: dynamic_system_solver.cc:868
fmatvec::Vec rParent[2]
nonsmooth right hand side
Definition: dynamic_system_solver.h:696
int solveConstraintsGaussSeidel() override
solve contact equations with Gauss-Seidel scheme
Definition: dynamic_system_solver.cc:484
void initLa()
load contact impulses for use as starting value
Definition: dynamic_system_solver.cc:1122
bool term
boolean to check for termination of contact equations solution
Definition: dynamic_system_solver.h:742
void readz0(std::string fileName)
reads state from a file
Definition: dynamic_system_solver.cc:1276
Env * getEnvironment()
Definition: dynamic_system_solver.h:898
bool dropContactInfo
flag if contact matrices for debugging should be dropped in no-convergence case
Definition: dynamic_system_solver.h:767
int solveConstraintsFixpointSingle() override
solve contact equations with single step fixed point scheme
Definition: dynamic_system_solver.cc:422
double tolProj
Tolerance for projection of generalized position.
Definition: dynamic_system_solver.h:819
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:1112
virtual void updateVRef(fmatvec::Mat &VParent, int j=0)
references to condensed contact force direction matrix of dynamic system parent
Definition: dynamic_system.cc:847
fmatvec::SparseMat Gs
sparse mass action matrix
Definition: dynamic_system_solver.h:722
fmatvec::VecInt checkTermLevels
TODO.
Definition: dynamic_system_solver.h:787
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:757
void updategRef(fmatvec::Vec &ref) override
references to relative distances of dynamic system parent
Definition: dynamic_system_solver.h:530
fmatvec::Vec bc
TODO.
Definition: dynamic_system_solver.h:737
bool stopIfNoConvergence
flag if the contact equations should be stopped if there is no convergence
Definition: dynamic_system_solver.h:762
virtual const fmatvec::Vec & shift()
update for event driven integrator for event
Definition: dynamic_system_solver.cc:1417
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:556
fmatvec::Mat TParent
matrix of linear relation between differentiated positions and velocities
Definition: dynamic_system_solver.h:627
fmatvec::Vec sParent
TODO.
Definition: dynamic_system_solver.h:657
fmatvec::VecInt LinkStatusRegParent
status vector of single valued links
Definition: dynamic_system_solver.h:717
Definition: environment.h:37
fmatvec::Vec zd
derivative of state vector
Definition: dynamic_system_solver.h:612
void getLinkStatusReg(fmatvec::VecInt &LinkStatusRegExt)
Definition: dynamic_system_solver.cc:982
void updateWRef(fmatvec::Mat &ref, int i=0) override
references to contact force direction matrix of dynamic system parent
Definition: dynamic_system_solver.h:549
fmatvec::Vec gdParent
relative velocities
Definition: dynamic_system_solver.h:674
void projectGeneralizedVelocities(int mode)
drift projection for positions
Definition: dynamic_system_solver.cc:1069
fmatvec::VecInt LinkStatusParent
status vector of set valued links with piecewise link equation (which piece is valid)
Definition: dynamic_system_solver.h:711
virtual void updatewbRef(fmatvec::Vec &wbParent)
references to TODO of dynamic system parent
Definition: dynamic_system.cc:819
group ingredients do not depend on each other
Definition: group.h:35
unsigned int flushCount
counts plot-calls until files to be flushed TODO
Definition: dynamic_system_solver.h:814
void checkImpactsForTermination() override
validate force laws concerning given tolerances on velocity level
Definition: dynamic_system_solver.cc:667
std::string getSolverInfo()
Definition: dynamic_system_solver.cc:1166
fmatvec::Vec z
state vector
Definition: dynamic_system_solver.h:607
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:1211
double lmParm
Levenberg-Marquard parameter.
Definition: dynamic_system_solver.h:752
int solveImpactsFixpointSingle() override
solve impact equations with single step fixed point scheme on velocity level
Definition: dynamic_system_solver.cc:453
void addElement(Element *element_)
Definition: dynamic_system_solver.cc:1127
fmatvec::Vec rFactorParent
relaxation parameters for contact equations
Definition: dynamic_system_solver.h:652
void checkConstraintsForTermination() override
validate force laws concerning given tolerances
Definition: dynamic_system_solver.cc:656
virtual void updateWRef(fmatvec::Mat &WParent, int j=0)
references to contact force direction matrix of dynamic system parent
Definition: dynamic_system.cc:826
fmatvec::VecInt decreaseLevels
decreasing relaxation factors is done in levels containing the number of contact iterations as condit...
Definition: dynamic_system_solver.h:782
virtual void updatelaInverseKinetics()
update inverse kinetics constraint forces
Definition: dynamic_system_solver.cc:1510
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:781
void dropContactMatrices()
Definition: dynamic_system_solver.cc:1181
void updatezdRef(fmatvec::Vec &ext)
references to differentiated external state
Definition: dynamic_system_solver.cc:1296
void initialize()
Initialize the system.
Definition: dynamic_system_solver.cc:88
virtual void updateG()
updates mass action matrix
Definition: dynamic_system_solver.cc:873
~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:777
unsigned int flushEvery
flushes all hdf5-files every x-times the plot-routine is called TODO
Definition: dynamic_system_solver.h:808
fmatvec::Mat WParent[2]
contact force directions
Definition: dynamic_system_solver.h:632
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:454
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:1139
bool positionDriftCompensationNeeded(double gmax)
check if drift compensation on position level is needed
Definition: dynamic_system_solver.cc:990
fmatvec::VecInt jsvParent
boolean evaluation of stopvector
Definition: dynamic_system_solver.h:706
void savela()
save contact forces for use as starting value in next time step
Definition: dynamic_system_solver.cc:1107
Definition: contact_kinematics.h:32
void projectGeneralizedPositions(int mode, bool fullUpdate=false)
drift projection for positions
Definition: dynamic_system_solver.cc:1016
fmatvec::SymMat LLMParent
Cholesky decomposition of mass matrix.
Definition: dynamic_system_solver.h:622
std::string name
name of element
Definition: element.h:249
int limitGSize
TODO.
Definition: dynamic_system_solver.h:797
static bool exitRequest
boolean signal evaluation for end integration set by user
Definition: dynamic_system_solver.h:865
fmatvec::SymMat MParent
mass matrix
Definition: dynamic_system_solver.h:617
bool peds
TODO, flag for occuring impact and sticking in event driven solver.
Definition: dynamic_system_solver.h:802
fmatvec::Vec hParent[2]
smooth, smooth with respect to objects, smooth with respect to links right hand side
Definition: dynamic_system_solver.h:691
void writeStateTable(std::string fileName)
writes state table to a file
Definition: dynamic_system_solver.cc:1265
void constructor()
set plot feature default values
Definition: dynamic_system_solver.cc:1310
fmatvec::SqrMat G
mass action matrix
Definition: dynamic_system_solver.h:732
double dt
step size
Definition: dynamic_system_solver.h:597
void saveLa()
save contact impulses for use as starting value in next time step
Definition: dynamic_system_solver.cc:1117
bool integratorExitRequest
boolean signal evaluation for end integration set by program
Definition: dynamic_system_solver.h:860
fmatvec::Vec wbParent
TODO.
Definition: dynamic_system_solver.h:642
void addToGraph(Graph *graph, fmatvec::SqrMat &A, int i, std::vector< Element * > &objList)
adds list of objects to tree
Definition: dynamic_system_solver.cc:1404
virtual void updategRef(fmatvec::Vec &gParent)
references to relative distances of dynamic system parent
Definition: dynamic_system.cc:784
void updatewbRef(fmatvec::Vec &ref) override
references to TODO of dynamic system parent
Definition: dynamic_system_solver.h:542
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:747
void getLinkStatus(fmatvec::VecInt &LinkStatusExt)
Definition: dynamic_system_solver.cc:974
Solver
solver for contact equations
Definition: dynamic_system_solver.h:71
MBSimEnvironment * getMBSimEnvironment()
Definition: dynamic_system_solver.cc:1613
fmatvec::Vec zParent
state
Definition: dynamic_system_solver.h:679
fmatvec::Vec laParent
contact force parameters
Definition: dynamic_system_solver.h:647
fmatvec::Vec resParent
residuum of contact equations
Definition: dynamic_system_solver.h:662
void setFlushEvery(unsigned int every)
set the number of plot-routine-calls after which all hdf5-files will be flushed
Definition: dynamic_system_solver.h:472
bool velocityDriftCompensationNeeded(double gdmax)
check if drift compensation on velocity level is needed
Definition: dynamic_system_solver.cc:1003
fmatvec::Vec svParent
stopvector (rootfunctions for event driven integration
Definition: dynamic_system_solver.h:701
fmatvec::SqrMat Jprox
JACOBIAN of contact equations for Newton scheme.
Definition: dynamic_system_solver.h:727
fmatvec::Mat VParent[2]
condensed contact force directions
Definition: dynamic_system_solver.h:637
void updatezRef(fmatvec::Vec &ext)
references to external state
Definition: dynamic_system_solver.cc:1284
void writez(std::string fileName, bool formatH5=true)
writes state to a file
Definition: dynamic_system_solver.cc:1243
static void sigAbortHandler(int)
handler for abort signals
Definition: dynamic_system_solver.cc:1216
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:524
void decreaserFactors()
decrease relaxation factors if mass action matrix is not diagonal dominant
Definition: dynamic_system_solver.cc:968
void computeInitialCondition()
compute initial condition for links for event driven integrator
Definition: dynamic_system_solver.cc:824
bool READZ0
is a state read from a file
Definition: dynamic_system_solver.h:870
int solveImpactsRootFinding() override
solve impact equations with Newton scheme on velocity level
Definition: dynamic_system_solver.cc:591
void updategdRef(fmatvec::Vec &ref) override
references to relative velocities of dynamic system parent
Definition: dynamic_system_solver.h:536
virtual void updategdRef(fmatvec::Vec &gdParent)
references to relative velocities of dynamic system parent
Definition: dynamic_system.cc:791
fmatvec::Vec zdParent
differentiated state
Definition: dynamic_system_solver.h:684
namespace MBSim
Definition: eigenanalyzer.cc:47