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  const fmatvec::Vec& getx() const { return x; }
78  fmatvec::Vec& getx() { return x; }
79  const fmatvec::Vec& getxd(bool check=true) const;
80  fmatvec::Vec& getxd(bool check=true);
81  int getxInd() { return xInd; }
82  virtual void setxInd(int xInd_) { xInd = xInd_; };
83  int getxSize() const { return xSize; }
84  virtual void updatexRef(fmatvec::Vec& ref);
85  virtual void updatexdRef(fmatvec::Vec& ref);
86  virtual void updatedxRef(fmatvec::Vec& ref);
87  virtual void updatebRef(fmatvec::Mat &hRef);
88  void init(InitStage stage, const InitConfigSet &config) override;
89  virtual void initz();
90  virtual void writez(H5::GroupBase *group);
91  virtual void readz0(H5::GroupBase *group);
92 
93  virtual void setbInd(int bInd_) { bInd = bInd_; };
94 
95  /* INHERITED INTERFACE OF ELEMENT */
96  void plot() override;
97  /***************************************************/
98 
99  /* INTERFACE TO BE DEFINED IN DERIVED CLASS */
103  virtual void updateWRef(fmatvec::Mat& ref, int i=0) = 0;
104 
108  virtual void updateVRef(fmatvec::Mat& ref, int i=0) = 0;
109 
113  virtual void updatehRef(fmatvec::Vec &hRef, int i=0) = 0;
114 
118  virtual void updaterRef(fmatvec::Vec &ref, int i=0) = 0;
119 
123  virtual void updatewbRef(fmatvec::Vec &ref);
124 
128  virtual void updatelaRef(fmatvec::Vec& ref);
129 
133  virtual void updateLaRef(fmatvec::Vec& ref);
134 
138  virtual void deletelaRef();
139 
143  virtual void updateInternalStateRef(fmatvec::Vec& cur, fmatvec::Vec& next);
144 
148  virtual void updategRef(fmatvec::Vec& ref);
149 
153  virtual void updategdRef(fmatvec::Vec& ref);
154 
158  virtual void updateresRef(fmatvec::Vec& ref);
159 
163  virtual void updaterFactorRef(fmatvec::Vec& ref);
164 
168  virtual void updatesvRef(fmatvec::Vec &sv);
169 
173  virtual void updatejsvRef(fmatvec::VecInt &jsvParent);
174 
178  virtual void updateLinkStatusRef(fmatvec::VecInt &LinkStatusParent);
179 
183  virtual void updateLinkStatusRegRef(fmatvec::VecInt &LinkStatusRegParent);
184 
188  virtual void calclaSize(int j) { laSize = 0; }
189 
190  int getisInd() { return isInd; }
191  int getisSize() { return isSize; }
192  virtual void calcisSize() { isSize = 0; }
193 
199  virtual void aboutToUpdateInternalState() {}
200 
201  virtual void postprocessing() {}
202 
206  virtual void calcgSize(int j) { gSize = 0; }
207 
214  virtual void calcgdSize(int j) { gdSize = 0; }
215 
219  virtual void calcrFactorSize(int j) { rFactorSize = 0; }
220 
224  virtual void calcbSize() { bSize = 0; }
225 
229  virtual void calcsvSize() { svSize = 0; }
230 
234  virtual void calcLinkStatusSize() { LinkStatusSize =0;}
235 
240 
246  virtual bool isSetValued() const { return false; }
247 
253  virtual bool isSingleValued() const { return false; }
254 
258  virtual bool isActive() const = 0;
259 
263  virtual bool gActiveChanged() = 0;
264 
268  virtual bool detectImpact() { return false; }
269 
274  virtual void solveImpactsFixpointSingle() { throwError("(Link::solveImpactsFixpointSingle): Not implemented."); }
275 
279  virtual void solveConstraintsFixpointSingle() { throwError("(Link::solveConstraintsFixpointSingle): Not implemented."); }
280 
285  virtual void solveImpactsGaussSeidel() { throwError("(Link::solveImpactsGaussSeidel): Not implemented."); }
286 
290  virtual void solveConstraintsGaussSeidel() { throwError("(Link::solveConstraintsGaussSeidel): Not implemented."); }
291 
296  virtual void solveImpactsRootFinding() { throwError("(Link::solveImpactsRootFinding): Not implemented."); }
297 
301  virtual void solveConstraintsRootFinding() { throwError("(Link::solveConstraintsRootFinding): Not implemented."); }
302 
306  virtual void jacobianConstraints() { throwError("(Link::jacobianConstraints): Not implemented."); }
307 
311  virtual void jacobianImpacts() { throwError("(Link::jacobianImpacts): Not implemented."); }
312 
316  virtual void updaterFactors() { throwError("(Link::updaterFactors): Not implemented."); }
317 
321  virtual void checkImpactsForTermination() { throwError("(Link::checkImpactsForTermination): Not implemented."); }
322 
326  virtual void checkConstraintsForTermination() { throwError("(Link::checkConstraintsForTermination): Not implemented."); }
327 
334  virtual void checkActive(int j) { }
335 
336  virtual void setGeneralizedForceTolerance(double tol) { laTol = tol; }
337  virtual void setGeneralizedImpulseTolerance(double tol) { LaTol = tol; }
338  virtual void setGeneralizedRelativePositionTolerance(double tol) { gTol = tol; }
339  virtual void setGeneralizedRelativeVelocityTolerance(double tol) { gdTol = tol; }
340  virtual void setGeneralizedRelativeAccelerationTolerance(double tol) { gddTol = tol; }
341  virtual void setGeneralizedRelativePositionCorrectionValue(double corr) { gCorr = corr; }
342  virtual void setGeneralizedRelativeVelocityCorrectionValue(double corr) { gdCorr = corr; }
343  virtual void setrMax(double rMax_) { rMax = rMax_; }
344  virtual void setLinkStatusInd(int LinkStatusInd_) { LinkStatusInd = LinkStatusInd_; };
345  virtual void setLinkStatusRegInd(int LinkStatusRegInd_) { LinkStatusRegInd = LinkStatusRegInd_; };
346  virtual void setlaInd(int laInd_) { laInd = laInd_;Ila=fmatvec::RangeV(laInd,laInd+laSize-1); }
347  virtual void setisInd(int isInd_) { isInd = isInd_; }
348  virtual void setgInd(int gInd_) { gInd = gInd_; Ig=fmatvec::RangeV(gInd,gInd+gSize-1); }
349  virtual void setgdInd(int gdInd_) { gdInd = gdInd_; }
350  virtual void setrFactorInd(int rFactorInd_) { rFactorInd = rFactorInd_; }
359  virtual void LinearImpactEstimation(double t, fmatvec::Vec &gInActive_,fmatvec::Vec &gdInActive_,int *IndInActive_,fmatvec::Vec &gAct_,int *IndActive_) { }
360 
364  virtual void SizeLinearImpactEstimation(int *sizeInActive_, int *sizeActive_) { }
365  virtual void updatecorr(int j) { corr.init(0); }
366  virtual void updatecorrRef(fmatvec::Vec &ref);
367  virtual void calccorrSize(int j) { corrSize = 0; }
368  virtual void setcorrInd(int corrInd_) { corrInd = corrInd_; }
369  virtual void checkRoot() { }
370  /***************************************************/
371 
372  void setx(const fmatvec::Vec &x_) { x = x_; }
373 
374  virtual void setsvInd(int svInd_) { svInd = svInd_; };
375  int getsvSize() const { return svSize; }
376 
377  int getLinkStatusSize() const { return LinkStatusSize; }
378 
379  int getLinkStatusRegSize() const { return LinkStatusRegSize; }
380 
381  const fmatvec::Vec& getla(bool check=true) const;
382  const fmatvec::Vec& getLa(bool check=true) const;
383  fmatvec::Vec& getla(bool check=true);
384  fmatvec::Vec& getLa(bool check=true);
385  fmatvec::Vec& getwb(bool check=true);
386 
387  int getlaInd() const { return laInd; }
388  int getlaSize() const { return laSize; }
389  int getbSize() const { return bSize; }
390 
391  const fmatvec::Vec& evalg();
392  const fmatvec::Vec& evalgd();
393  const fmatvec::Vec& evalla();
394  const fmatvec::Vec& evalLa();
395  const fmatvec::Vec& evalwb();
396  const fmatvec::Vec& evalxd();
397 
398  int getgdInd() const { return gdInd; }
399  int getgSize() const { return gSize; }
400  int getgdSize() const { return gdSize; }
401 
402  int getrFactorSize() const { return rFactorSize; }
403 
404  const fmatvec::VecInt& getrFactorUnsure() const { return rFactorUnsure; }
405 
406  void resetUpToDate() override { updrrel = true; updvrel = true; updla = true; }
407 
408  virtual void updateGeneralizedPositions() { updrrel = false; }
409  virtual void updateGeneralizedVelocities() { updvrel = false; }
410  virtual void updateGeneralizedForces() { updla = false; }
411 
412  const fmatvec::VecV& evalGeneralizedRelativePosition() { if(updrrel) updateGeneralizedPositions(); return rrel; }
413  const fmatvec::VecV& evalGeneralizedRelativeVelocity() { if(updvrel) updateGeneralizedVelocities(); return vrel; }
414  const fmatvec::VecV& evalGeneralizedForce() { if(updla) updateGeneralizedForces(); return lambda; }
415 
416  fmatvec::VecV& getGeneralizedRelativePosition(bool check=true) { assert((not check) or (not updrrel)); return rrel; }
417  fmatvec::VecV& getGeneralizedRelativeVelocity(bool check=true) { assert((not check) or (not updvrel)); return vrel; }
418  fmatvec::VecV& getGeneralizedForce(bool check=true) { assert((not check) or (not updla)); return lambda; }
419 
423  void savela();
424 
428  void saveLa();
429 
433  void initla();
434 
438  void initLa();
439 
443  void decreaserFactors();
444 
445 
446  int getcorrSize() const { return corrSize; }
447 
448  bool getUpdaterrel() const { return updrrel; }
449 
450  void createPlotGroup() override;
451 
452  protected:
453  int ng, ngd, nla;
454 
458  fmatvec::Vec x;
459 
463  fmatvec::Vec xd;
464 
465  fmatvec::Vec dx;
466 
470  fmatvec::Vec x0;
471 
475  int xSize, xInd;
476 
480  fmatvec::Vec sv;
481 
485  fmatvec::VecInt jsv;
486 
490  int svSize, svInd;
491 
496  fmatvec::VecInt LinkStatus;
497 
501  int LinkStatusSize, LinkStatusInd;
502 
507  fmatvec::VecInt LinkStatusReg;
508 
512  int LinkStatusRegSize, LinkStatusRegInd;
513 
514  fmatvec::Vec curis, nextis;
515 
519  fmatvec::Vec g, gd, la, La;
520 
524  fmatvec::Vec laS;
525 
526  int isSize, isInd;
527 
531  int gSize, gInd;
532 
536  int gdSize, gdInd;
537 
541  int laSize, laInd;
542 
546  int bSize, bInd;
547 
551  fmatvec::RangeV Ig, Ila;
552 
556  double gTol, gdTol, gddTol, laTol, LaTol;
557 
561  double gCorr, gdCorr;
562 
566  fmatvec::Vec la0, La0;
567 
571  fmatvec::Vec rFactor;
572 
576  fmatvec::VecInt rFactorUnsure;
577 
581  int rFactorSize, rFactorInd;
582 
586  double rMax;
587 
591  fmatvec::Vec res;
592 
596  std::vector<fmatvec::Mat> W[2];
597 
601  std::vector<fmatvec::Mat> V[2];
602 
606  std::vector<fmatvec::Vec> h[2];
607 
611  std::vector<fmatvec::Mat> dhdq;
612  std::vector<fmatvec::Mat> dhdu;
613  std::vector<fmatvec::Vec> dhdt;
614 
618  std::vector<fmatvec::Vec> r[2];
619 
623  fmatvec::Vec wb;
624 
628  fmatvec::Mat b;
629 
630  int corrSize, corrInd;
631  fmatvec::Vec corr;
632 
633  fmatvec::VecV rrel, vrel, lambda;
634 
635  bool updSize, updrrel, updvrel, updla;
636  };
637 }
638 
639 #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:262
namespace MBSim
Definition: bilateral_constraint.cc:29