mbsim  4.0.0
MBSim Kernel
link.h
1 /* Copyright (C) 2004-2014 MBSim Development Team
2  *
3  * This library is free software; you can redistribute it and/or
4  * modify it under the terms of the GNU Lesser General Public
5  * License as published by the Free Software Foundation; either
6  * version 2.1 of the License, or (at your option) any later version.
7  *
8  * This library is distributed in the hope that it will be useful,
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11  * Lesser General Public License for more details.
12  *
13  * You should have received a copy of the GNU Lesser General Public
14  * License along with this library; if not, write to the Free Software
15  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
16  *
17  * Contact: martin.o.foerg@googlemail.com
18  */
19 
20 #ifndef _LINK_H_
21 #define _LINK_H_
22 
23 #include "mbsim/element.h"
24 #include "mbsim/mbsim_event.h"
25 
26 namespace H5 {
27  class Group;
28 }
29 
30 namespace MBSim {
31 
32  extern const PlotFeatureEnum generalizedRelativePosition, generalizedRelativeVelocity, generalizedForce;
33 
47  //class Link : public Element, public LinkInterface, public ExtraDynamicInterface {
48  class Link : public Element {
49  public:
54  Link(const std::string &name);
55 
56  virtual void calcSize() { }
57  int getGeneralizedRelativePositionSize() { if(updSize) calcSize(); return ng; }
58  int getGeneralizedRelativeVelocitySize() { if(updSize) calcSize(); return ngd; }
59  int getGeneralizedForceSize() { if(updSize) calcSize(); return nla; }
60 
61  virtual void updateg() { }
62  virtual void updategd() { }
63  virtual void updatewb() { }
64  virtual void updateW(int i=0) { }
65  virtual void updateV(int i=0) { }
66  virtual void updateh(int i=0) { }
67  virtual void updateStopVector() { }
68  virtual void updateStopVectorParameters() { }
69  virtual void updateLinkStatus() { }
70  virtual void updateLinkStatusReg() { }
71  virtual void updateJacobians(int j=0) { }
72  virtual void updateb() { }
73 
74  virtual void updatedx();
75  virtual void updatexd() { }
76  virtual void calcxSize() { xSize = 0; }
77  virtual const fmatvec::Vec& getx() const { return x; }
78  virtual fmatvec::Vec& getx() { return x; }
79  virtual int getxInd() { return xInd; }
80  virtual void setxInd(int xInd_) { xInd = xInd_; };
81  virtual int getxSize() const { return xSize; }
82  virtual void updatexRef(fmatvec::Vec& ref);
83  virtual void updatexdRef(fmatvec::Vec& ref);
84  virtual void updatedxRef(fmatvec::Vec& ref);
85  virtual void updatebRef(fmatvec::Mat &hRef);
86  void init(InitStage stage, const InitConfigSet &config) override;
87  virtual void initz();
88  virtual void writez(H5::GroupBase *group);
89  virtual void readz0(H5::GroupBase *group);
90 
91  virtual void setbInd(int bInd_) { bInd = bInd_; };
92 
93  /* INHERITED INTERFACE OF ELEMENT */
94  void plot() override;
95  /***************************************************/
96 
97  /* INTERFACE TO BE DEFINED IN DERIVED CLASS */
101  virtual void updateWRef(fmatvec::Mat& ref, int i=0) = 0;
102 
106  virtual void updateVRef(fmatvec::Mat& ref, int i=0) = 0;
107 
111  virtual void updatehRef(fmatvec::Vec &hRef, int i=0) = 0;
112 
116  virtual void updaterRef(fmatvec::Vec &ref, int i=0) = 0;
117 
121  virtual void updatewbRef(fmatvec::Vec &ref);
122 
126  virtual void updatelaRef(fmatvec::Vec& ref);
127 
131  virtual void updateLaRef(fmatvec::Vec& ref);
132 
136  virtual void deletelaRef();
137 
141  virtual void updateInternalStateRef(fmatvec::Vec& cur, fmatvec::Vec& next);
142 
146  virtual void updategRef(fmatvec::Vec& ref);
147 
151  virtual void updategdRef(fmatvec::Vec& ref);
152 
156  virtual void updateresRef(fmatvec::Vec& ref);
157 
161  virtual void updaterFactorRef(fmatvec::Vec& ref);
162 
166  virtual void updatesvRef(fmatvec::Vec &sv);
167 
171  virtual void updatejsvRef(fmatvec::VecInt &jsvParent);
172 
176  virtual void updateLinkStatusRef(fmatvec::VecInt &LinkStatusParent);
177 
181  virtual void updateLinkStatusRegRef(fmatvec::VecInt &LinkStatusRegParent);
182 
186  virtual void calclaSize(int j) { laSize = 0; }
187 
188  int getisInd() { return isInd; }
189  int getisSize() { return isSize; }
190  virtual void calcisSize() { isSize = 0; }
191 
195  virtual void calcgSize(int j) { gSize = 0; }
196 
203  virtual void calcgdSize(int j) { gdSize = 0; }
204 
208  virtual void calcrFactorSize(int j) { rFactorSize = 0; }
209 
213  virtual void calcbSize() { bSize = 0; }
214 
218  virtual void calcsvSize() { svSize = 0; }
219 
223  virtual void calcLinkStatusSize() { LinkStatusSize =0;}
224 
229 
235  virtual bool isSetValued() const { return false; }
236 
242  virtual bool isSingleValued() const { return false; }
243 
247  virtual bool isActive() const = 0;
248 
252  virtual bool gActiveChanged() = 0;
253 
257  virtual bool detectImpact() { return false; }
258 
263  virtual void solveImpactsFixpointSingle() { throwError("(Link::solveImpactsFixpointSingle): Not implemented."); }
264 
268  virtual void solveConstraintsFixpointSingle() { throwError("(Link::solveConstraintsFixpointSingle): Not implemented."); }
269 
274  virtual void solveImpactsGaussSeidel() { throwError("(Link::solveImpactsGaussSeidel): Not implemented."); }
275 
279  virtual void solveConstraintsGaussSeidel() { throwError("(Link::solveConstraintsGaussSeidel): Not implemented."); }
280 
285  virtual void solveImpactsRootFinding() { throwError("(Link::solveImpactsRootFinding): Not implemented."); }
286 
290  virtual void solveConstraintsRootFinding() { throwError("(Link::solveConstraintsRootFinding): Not implemented."); }
291 
295  virtual void jacobianConstraints() { throwError("(Link::jacobianConstraints): Not implemented."); }
296 
300  virtual void jacobianImpacts() { throwError("(Link::jacobianImpacts): Not implemented."); }
301 
305  virtual void updaterFactors() { throwError("(Link::updaterFactors): Not implemented."); }
306 
310  virtual void checkImpactsForTermination() { throwError("(Link::checkImpactsForTermination): Not implemented."); }
311 
315  virtual void checkConstraintsForTermination() { throwError("(Link::checkConstraintsForTermination): Not implemented."); }
316 
323  virtual void checkActive(int j) { }
324 
325  virtual void setGeneralizedForceTolerance(double tol) { laTol = tol; }
326  virtual void setGeneralizedImpulseTolerance(double tol) { LaTol = tol; }
327  virtual void setGeneralizedRelativePositionTolerance(double tol) { gTol = tol; }
328  virtual void setGeneralizedRelativeVelocityTolerance(double tol) { gdTol = tol; }
329  virtual void setGeneralizedRelativeAccelerationTolerance(double tol) { gddTol = tol; }
330  virtual void setGeneralizedRelativePositionCorrectionValue(double corr) { gCorr = corr; }
331  virtual void setGeneralizedRelativeVelocityCorrectionValue(double corr) { gdCorr = corr; }
332  virtual void setrMax(double rMax_) { rMax = rMax_; }
333  virtual void setLinkStatusInd(int LinkStatusInd_) { LinkStatusInd = LinkStatusInd_; };
334  virtual void setLinkStatusRegInd(int LinkStatusRegInd_) { LinkStatusRegInd = LinkStatusRegInd_; };
335  virtual void setlaInd(int laInd_) { laInd = laInd_;Ila=fmatvec::RangeV(laInd,laInd+laSize-1); }
336  virtual void setisInd(int isInd_) { isInd = isInd_; }
337  virtual void setgInd(int gInd_) { gInd = gInd_; Ig=fmatvec::RangeV(gInd,gInd+gSize-1); }
338  virtual void setgdInd(int gdInd_) { gdInd = gdInd_; }
339  virtual void setrFactorInd(int rFactorInd_) { rFactorInd = rFactorInd_; }
348  virtual void LinearImpactEstimation(double t, fmatvec::Vec &gInActive_,fmatvec::Vec &gdInActive_,int *IndInActive_,fmatvec::Vec &gAct_,int *IndActive_) { }
349 
353  virtual void SizeLinearImpactEstimation(int *sizeInActive_, int *sizeActive_) { }
354  virtual void updatecorr(int j) { corr.init(0); }
355  virtual void updatecorrRef(fmatvec::Vec &ref);
356  virtual void calccorrSize(int j) { corrSize = 0; }
357  virtual void setcorrInd(int corrInd_) { corrInd = corrInd_; }
358  virtual void checkRoot() { }
359  /***************************************************/
360 
361  void setx(const fmatvec::Vec &x_) { x = x_; }
362 
363  virtual void setsvInd(int svInd_) { svInd = svInd_; };
364  int getsvSize() const { return svSize; }
365 
366  int getLinkStatusSize() const { return LinkStatusSize; }
367 
368  int getLinkStatusRegSize() const { return LinkStatusRegSize; }
369 
370  const fmatvec::Vec& getla(bool check=true) const;
371  const fmatvec::Vec& getLa(bool check=true) const;
372  fmatvec::Vec& getla(bool check=true);
373  fmatvec::Vec& getLa(bool check=true);
374  fmatvec::Vec& getwb(bool check=true);
375 
376  int getlaInd() const { return laInd; }
377  int getlaSize() const { return laSize; }
378  int getbSize() const { return bSize; }
379 
380  const fmatvec::Vec& evalg();
381  const fmatvec::Vec& evalgd();
382  const fmatvec::Vec& evalla();
383  const fmatvec::Vec& evalLa();
384  const fmatvec::Vec& evalwb();
385  const fmatvec::Vec& evalxd();
386 
387  int getgdInd() const { return gdInd; }
388  int getgSize() const { return gSize; }
389  int getgdSize() const { return gdSize; }
390 
391  int getrFactorSize() const { return rFactorSize; }
392 
393  const fmatvec::VecInt& getrFactorUnsure() const { return rFactorUnsure; }
394 
395  void resetUpToDate() override { updrrel = true; updvrel = true; updla = true; }
396 
397  virtual void updateGeneralizedPositions() { updrrel = false; }
398  virtual void updateGeneralizedVelocities() { updvrel = false; }
399  virtual void updateGeneralizedForces() { updla = false; }
400 
401  const fmatvec::VecV& evalGeneralizedRelativePosition() { if(updrrel) updateGeneralizedPositions(); return rrel; }
402  const fmatvec::VecV& evalGeneralizedRelativeVelocity() { if(updvrel) updateGeneralizedVelocities(); return vrel; }
403  const fmatvec::VecV& evalGeneralizedForce() { if(updla) updateGeneralizedForces(); return lambda; }
404 
405  fmatvec::VecV& getGeneralizedRelativePosition(bool check=true) { assert((not check) or (not updrrel)); return rrel; }
406  fmatvec::VecV& getGeneralizedRelativeVelocity(bool check=true) { assert((not check) or (not updvrel)); return vrel; }
407  fmatvec::VecV& getGeneralizedForce(bool check=true) { assert((not check) or (not updla)); return lambda; }
408 
412  void savela();
413 
417  void saveLa();
418 
422  void initla();
423 
427  void initLa();
428 
432  void decreaserFactors();
433 
434 
435  int getcorrSize() const { return corrSize; }
436 
437  bool getUpdaterrel() const { return updrrel; }
438 
439  void createPlotGroup() override;
440 
441  protected:
442  int ng, ngd, nla;
443 
447  fmatvec::Vec x;
448 
452  fmatvec::Vec xd;
453 
454  fmatvec::Vec dx;
455 
459  fmatvec::Vec x0;
460 
464  int xSize, xInd;
465 
469  fmatvec::Vec sv;
470 
474  fmatvec::VecInt jsv;
475 
479  int svSize, svInd;
480 
485  fmatvec::VecInt LinkStatus;
486 
490  int LinkStatusSize, LinkStatusInd;
491 
496  fmatvec::VecInt LinkStatusReg;
497 
501  int LinkStatusRegSize, LinkStatusRegInd;
502 
503  fmatvec::Vec curis, nextis;
504 
508  fmatvec::Vec g, gd, la, La;
509 
513  fmatvec::Vec laS;
514 
515  int isSize, isInd;
516 
520  int gSize, gInd;
521 
525  int gdSize, gdInd;
526 
530  int laSize, laInd;
531 
535  int bSize, bInd;
536 
540  fmatvec::RangeV Ig, Ila;
541 
545  double gTol, gdTol, gddTol, laTol, LaTol;
546 
550  double gCorr, gdCorr;
551 
555  fmatvec::Vec la0, La0;
556 
560  fmatvec::Vec rFactor;
561 
565  fmatvec::VecInt rFactorUnsure;
566 
570  int rFactorSize, rFactorInd;
571 
575  double rMax;
576 
580  fmatvec::Vec res;
581 
585  std::vector<fmatvec::Mat> W[2];
586 
590  std::vector<fmatvec::Mat> V[2];
591 
595  std::vector<fmatvec::Vec> h[2];
596 
600  std::vector<fmatvec::Mat> dhdq;
601  std::vector<fmatvec::Mat> dhdu;
602  std::vector<fmatvec::Vec> dhdt;
603 
607  std::vector<fmatvec::Vec> r[2];
608 
612  fmatvec::Vec wb;
613 
617  fmatvec::Mat b;
618 
619  int corrSize, corrInd;
620  fmatvec::Vec corr;
621 
622  fmatvec::VecV rrel, vrel, lambda;
623 
624  bool updSize, updrrel, updvrel, updla;
625  };
626 }
627 
628 #endif /* _LINK_H_ */
basic class of MBSim mainly for plotting
Definition: element.h:58
InitStage
The stages of the initialization.
Definition: element.h:64
std::string name
name of element
Definition: element.h:251
namespace MBSim
Definition: bilateral_constraint.cc:29