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 updategRef(fmatvec::Vec& ref);
142 
146  virtual void updategdRef(fmatvec::Vec& ref);
147 
151  virtual void updateresRef(fmatvec::Vec& ref);
152 
156  virtual void updaterFactorRef(fmatvec::Vec& ref);
157 
161  virtual void updatesvRef(fmatvec::Vec &sv);
162 
166  virtual void updatejsvRef(fmatvec::VecInt &jsvParent);
167 
171  virtual void updateLinkStatusRef(fmatvec::VecInt &LinkStatusParent);
172 
176  virtual void updateLinkStatusRegRef(fmatvec::VecInt &LinkStatusRegParent);
177 
181  virtual void calclaSize(int j) { laSize = 0; }
182 
186  virtual void calcgSize(int j) { gSize = 0; }
187 
194  virtual void calcgdSize(int j) { gdSize = 0; }
195 
199  virtual void calcrFactorSize(int j) { rFactorSize = 0; }
200 
204  virtual void calcbSize() { bSize = 0; }
205 
209  virtual void calcsvSize() { svSize = 0; }
210 
214  virtual void calcLinkStatusSize() { LinkStatusSize =0;}
215 
220 
226  virtual bool isSetValued() const { return false; }
227 
233  virtual bool isSingleValued() const { return false; }
234 
238  virtual bool isActive() const = 0;
239 
243  virtual bool gActiveChanged() = 0;
244 
248  virtual bool detectImpact() { return false; }
249 
254  virtual void solveImpactsFixpointSingle() { throwError("(Link::solveImpactsFixpointSingle): Not implemented."); }
255 
259  virtual void solveConstraintsFixpointSingle() { throwError("(Link::solveConstraintsFixpointSingle): Not implemented."); }
260 
265  virtual void solveImpactsGaussSeidel() { throwError("(Link::solveImpactsGaussSeidel): Not implemented."); }
266 
270  virtual void solveConstraintsGaussSeidel() { throwError("(Link::solveConstraintsGaussSeidel): Not implemented."); }
271 
276  virtual void solveImpactsRootFinding() { throwError("(Link::solveImpactsRootFinding): Not implemented."); }
277 
281  virtual void solveConstraintsRootFinding() { throwError("(Link::solveConstraintsRootFinding): Not implemented."); }
282 
286  virtual void jacobianConstraints() { throwError("(Link::jacobianConstraints): Not implemented."); }
287 
291  virtual void jacobianImpacts() { throwError("(Link::jacobianImpacts): Not implemented."); }
292 
296  virtual void updaterFactors() { throwError("(Link::updaterFactors): Not implemented."); }
297 
301  virtual void checkImpactsForTermination() { throwError("(Link::checkImpactsForTermination): Not implemented."); }
302 
306  virtual void checkConstraintsForTermination() { throwError("(Link::checkConstraintsForTermination): Not implemented."); }
307 
314  virtual void checkActive(int j) { }
315 
319  virtual double evalPotentialEnergy() { return 0; }
320 
321  virtual void setGeneralizedForceTolerance(double tol) { laTol = tol; }
322  virtual void setGeneralizedImpulseTolerance(double tol) { LaTol = tol; }
323  virtual void setGeneralizedRelativePositionTolerance(double tol) { gTol = tol; }
324  virtual void setGeneralizedRelativeVelocityTolerance(double tol) { gdTol = tol; }
325  virtual void setGeneralizedRelativeAccelerationTolerance(double tol) { gddTol = tol; }
326  virtual void setGeneralizedRelativePositionCorrectionValue(double corr) { gCorr = corr; }
327  virtual void setGeneralizedRelativeVelocityCorrectionValue(double corr) { gdCorr = corr; }
328  virtual void setrMax(double rMax_) { rMax = rMax_; }
329  virtual void setLinkStatusInd(int LinkStatusInd_) { LinkStatusInd = LinkStatusInd_; };
330  virtual void setLinkStatusRegInd(int LinkStatusRegInd_) { LinkStatusRegInd = LinkStatusRegInd_; };
331  virtual void setlaInd(int laInd_) { laInd = laInd_;Ila=fmatvec::RangeV(laInd,laInd+laSize-1); }
332  virtual void setgInd(int gInd_) { gInd = gInd_; Ig=fmatvec::RangeV(gInd,gInd+gSize-1); }
333  virtual void setgdInd(int gdInd_) { gdInd = gdInd_; }
334  virtual void setrFactorInd(int rFactorInd_) { rFactorInd = rFactorInd_; }
343  virtual void LinearImpactEstimation(double t, fmatvec::Vec &gInActive_,fmatvec::Vec &gdInActive_,int *IndInActive_,fmatvec::Vec &gAct_,int *IndActive_) { }
344 
348  virtual void SizeLinearImpactEstimation(int *sizeInActive_, int *sizeActive_) { }
349  virtual void updatecorr(int j) { corr.init(0); }
350  virtual void updatecorrRef(fmatvec::Vec &ref);
351  virtual void calccorrSize(int j) { corrSize = 0; }
352  virtual void setcorrInd(int corrInd_) { corrInd = corrInd_; }
353  virtual void checkRoot() { }
354  /***************************************************/
355 
356  void setx(const fmatvec::Vec &x_) { x = x_; }
357 
358  virtual void setsvInd(int svInd_) { svInd = svInd_; };
359  int getsvSize() const { return svSize; }
360 
361  int getLinkStatusSize() const { return LinkStatusSize; }
362 
363  int getLinkStatusRegSize() const { return LinkStatusRegSize; }
364 
365  const fmatvec::Vec& getla(bool check=true) const;
366  const fmatvec::Vec& getLa(bool check=true) const;
367  fmatvec::Vec& getla(bool check=true);
368  fmatvec::Vec& getLa(bool check=true);
369  fmatvec::Vec& getwb(bool check=true);
370 
371  int getlaInd() const { return laInd; }
372  int getlaSize() const { return laSize; }
373  int getbSize() const { return bSize; }
374 
375  const fmatvec::Vec& evalg();
376  const fmatvec::Vec& evalgd();
377  const fmatvec::Vec& evalla();
378  const fmatvec::Vec& evalLa();
379  const fmatvec::Vec& evalwb();
380  const fmatvec::Vec& evalxd();
381 
382  int getgdInd() const { return gdInd; }
383  int getgSize() const { return gSize; }
384  int getgdSize() const { return gdSize; }
385 
386  int getrFactorSize() const { return rFactorSize; }
387 
388  const fmatvec::VecInt& getrFactorUnsure() const { return rFactorUnsure; }
389 
390  void resetUpToDate() override { updrrel = true; updvrel = true; updla = true; }
391 
392  virtual void updateGeneralizedPositions() { updrrel = false; }
393  virtual void updateGeneralizedVelocities() { updvrel = false; }
394  virtual void updateGeneralizedForces() { updla = false; }
395 
396  const fmatvec::VecV& evalGeneralizedRelativePosition() { if(updrrel) updateGeneralizedPositions(); return rrel; }
397  const fmatvec::VecV& evalGeneralizedRelativeVelocity() { if(updvrel) updateGeneralizedVelocities(); return vrel; }
398  const fmatvec::VecV& evalGeneralizedForce() { if(updla) updateGeneralizedForces(); return lambda; }
399 
400  fmatvec::VecV& getGeneralizedRelativePosition(bool check=true) { assert((not check) or (not updrrel)); return rrel; }
401  fmatvec::VecV& getGeneralizedRelativeVelocity(bool check=true) { assert((not check) or (not updvrel)); return vrel; }
402  fmatvec::VecV& getGeneralizedForce(bool check=true) { assert((not check) or (not updla)); return lambda; }
403 
407  void savela();
408 
412  void saveLa();
413 
417  void initla();
418 
422  void initLa();
423 
427  void decreaserFactors();
428 
429 
430  int getcorrSize() const { return corrSize; }
431 
432  bool getUpdaterrel() const { return updrrel; }
433 
434  protected:
435  int ng, ngd, nla;
436 
441 
446 
447  fmatvec::Vec dx;
448 
453 
457  int xSize, xInd;
458 
463 
467  fmatvec::VecInt jsv;
468 
472  int svSize, svInd;
473 
478  fmatvec::VecInt LinkStatus;
479 
483  int LinkStatusSize, LinkStatusInd;
484 
489  fmatvec::VecInt LinkStatusReg;
490 
494  int LinkStatusRegSize, LinkStatusRegInd;
495 
499  fmatvec::Vec g, gd, la, La;
500 
505 
509  int gSize, gInd;
510 
514  int gdSize, gdInd;
515 
519  int laSize, laInd;
520 
524  int bSize, bInd;
525 
529  fmatvec::RangeV Ig, Ila;
530 
534  double gTol, gdTol, gddTol, laTol, LaTol;
535 
539  double gCorr, gdCorr;
540 
545 
550 
554  fmatvec::VecInt rFactorUnsure;
555 
559  int rFactorSize, rFactorInd;
560 
564  double rMax;
565 
570 
574  std::vector<fmatvec::Mat> W[2];
575 
579  std::vector<fmatvec::Mat> V[2];
580 
584  std::vector<fmatvec::Vec> h[2];
585 
589  std::vector<fmatvec::Mat> dhdq;
590  std::vector<fmatvec::Mat> dhdu;
591  std::vector<fmatvec::Vec> dhdt;
592 
596  std::vector<fmatvec::Vec> r[2];
597 
602 
607 
608  int corrSize, corrInd;
609  fmatvec::Vec corr;
610 
611  fmatvec::VecV rrel, vrel, lambda;
612 
613  bool updSize, updrrel, updvrel, updla;
614  };
615 }
616 
617 #endif /* _LINK_H_ */
basic class of MBSim mainly for plotting
Definition: element.h:56
InitStage
The stages of the initialization.
Definition: element.h:62
std::string name
name of element
Definition: element.h:235
namespace MBSim
Definition: eigenanalyzer.cc:47