MBSim

Project Page
link.h
1 /* Copyright (C) 2004-2009 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/link_interface.h"
25 //#include "mbsim/extradynamic_interface.h"
26 #include "mbsim/mbsim_event.h"
27 
28 namespace H5 {
29  class Group;
30 }
31 
32 namespace MBSim {
33 
34  class Frame;
35  class Object;
36  class ExtraDynamic;
37  class Contour;
38  class DynamicSystem;
39 
53  //class Link : public Element, public LinkInterface, public ExtraDynamicInterface {
54  class Link : public Element {
55  public:
60  Link(const std::string &name);
61 
65  virtual ~Link() {}
66 
67  /* INHERITED INTERFACE OF LINKINTERFACE */
68  virtual void updateg(double t) = 0;
69  virtual void updategd(double t) = 0;
70  virtual void updatewb(double t, int i=0) {};
71  virtual void updateW(double t, int i=0) {};
72  virtual void updateV(double t, int i=0) {};
73  virtual void updateh(double t, int i=0) {};
74  virtual void updateStopVector(double t) {}
75  virtual void updateLinkStatus(double t) {}
76  virtual void updateLinkStatusReg(double t) {}
77  virtual void updateJacobians(double t, int j=0) {}
78  virtual void updateb(double t) {};
79  /***************************************************/
80 
81  /* INHERITED INTERFACE OF EXTRADYNAMICINTERFACE */
82  virtual void updatedx(double t, double dt) {}
83  virtual void updatexd(double t) {}
84  virtual void calcxSize() { xSize = 0; }
85  virtual const fmatvec::Vec& getx() const { return x; }
86  virtual fmatvec::Vec& getx() { return x; }
87  virtual void setxInd(int xInd_) { xInd = xInd_; };
88  virtual int getxSize() const { return xSize; }
89  virtual void updatexRef(const fmatvec::Vec& ref);
90  virtual void updatexdRef(const fmatvec::Vec& ref);
91  virtual void updatebRef(const fmatvec::Mat &hRef);
92  virtual void init(InitStage stage);
93  virtual void initz();
94  /***************************************************/
95 
96  virtual void setbInd(int bInd_) { bInd = bInd_; };
97 
98  /* INHERITED INTERFACE OF ELEMENT */
99  std::string getType() const { return "Link"; }
100  virtual void plot(double t, double dt = 1);
101  virtual void closePlot();
102  /***************************************************/
103 
104  /* INTERFACE TO BE DEFINED IN DERIVED CLASS */
108  virtual void updateWRef(const fmatvec::Mat& ref, int i=0) = 0;
109 
113  virtual void updateVRef(const fmatvec::Mat& ref, int i=0) = 0;
114 
118  virtual void updatehRef(const fmatvec::Vec &hRef, int i=0) = 0;
119 
123  virtual void updaterRef(const fmatvec::Vec &ref, int i=0) = 0;
124 
128  virtual void updatewbRef(const fmatvec::Vec &ref);
129 
133  virtual void updatefRef(const fmatvec::Vec &ref) {};
134 
138  virtual void updatelaRef(const fmatvec::Vec& ref);
139 
143  virtual void deletelaRef();
144 
148  virtual void updategRef(const fmatvec::Vec& ref);
149 
153  virtual void updategdRef(const fmatvec::Vec& ref);
154 
158  virtual void updateresRef(const fmatvec::Vec& ref);
159 
163  virtual void updaterFactorRef(const fmatvec::Vec& ref);
164 
168  virtual void updatesvRef(const fmatvec::Vec &sv);
169 
173  virtual void updatejsvRef(const fmatvec::Vector<int> &jsvParent);
174 
178  virtual void updateLinkStatusRef(const fmatvec::Vector<int> &LinkStatusParent);
179 
183  virtual void updateLinkStatusRegRef(const fmatvec::Vector<int> &LinkStatusRegParent);
184 
188  virtual void calclaSize(int j) { laSize = 0; }
189 
193  virtual void calcgSize(int j) { gSize = 0; }
194 
198  virtual void calcgdSize(int j) { gdSize = 0; }
199 
203  virtual void calcrFactorSize(int j) { rFactorSize = 0; }
204 
208  virtual void calcbSize() { bSize = 0; }
209 
213  virtual void calcsvSize() { svSize = 0; }
214 
218  virtual void calcLinkStatusSize() { LinkStatusSize =0;}
219 
224 
228  virtual bool isSetValued() const { return false; }
229 
233  virtual bool hasSmoothPart() const { return false; }
234 
238  virtual bool isActive() const = 0;
239 
243  virtual bool gActiveChanged() = 0;
244 
248  virtual void solveImpactsFixpointSingle(double dt) { throw MBSimError("ERROR in "+getName()+" (Link::solveImpactsFixpointSingle): Not implemented."); }
249 
253  virtual void solveConstraintsFixpointSingle() { throw MBSimError("ERROR in "+getName()+" (Link::solveConstraintsFixpointSingle): Not implemented."); }
254 
258  virtual void solveImpactsGaussSeidel(double dt) { throw MBSimError("ERROR in "+getName()+" (Link::solveImpactsGaussSeidel): Not implemented."); }
259 
263  virtual void solveConstraintsGaussSeidel() { throw MBSimError("ERROR in "+getName()+" (Link::solveConstraintsGaussSeidel): Not implemented."); }
264 
268  virtual void solveImpactsRootFinding(double dt) { throw MBSimError("ERROR in "+getName()+" (Link::solveImpactsRootFinding): Not implemented."); }
269 
273  virtual void solveConstraintsRootFinding() { throw MBSimError("ERROR in "+getName()+" (Link::solveConstraintsRootFinding): Not implemented."); }
274 
278  virtual void jacobianConstraints() { throw MBSimError("ERROR in "+getName()+" (Link::jacobianConstraints): Not implemented."); }
279 
283  virtual void jacobianImpacts() { throw MBSimError("ERROR in "+getName()+" (Link::jacobianImpacts): Not implemented."); }
284 
288  virtual void updaterFactors() { throw MBSimError("ERROR in "+getName()+" (Link::updaterFactors): Not implemented."); }
289 
293  virtual void checkImpactsForTermination(double dt) { throw MBSimError("ERROR in "+getName()+" (Link::checkImpactsForTermination): Not implemented."); }
294 
298  virtual void checkConstraintsForTermination() { throw MBSimError("ERROR in "+getName()+" (Link::checkConstraintsForTermination): Not implemented."); }
299 
304  virtual void checkActive(int j) {}
305 
309  virtual double computePotentialEnergy() { return 0; }
310 
311  /* GETTER / SETTER */
312  virtual void setlaTol(double tol) { laTol = tol; }
313  virtual void setLaTol(double tol) { LaTol = tol; }
314  virtual void setgTol(double tol) { gTol = tol; }
315  virtual void setgdTol(double tol) { gdTol = tol; }
316  virtual void setgddTol(double tol) { gddTol = tol; }
317  virtual void setrMax(double rMax_) { rMax = rMax_; }
318  /***************************************************/
319 
320  /* GETTER / SETTER */
321  const std::vector<fmatvec::Mat>& getW(int i=0) const { return W[i]; }
322  const std::vector<fmatvec::Mat>& getV(int i=0) const { return V[i]; }
323  const std::vector<fmatvec::Vec>& geth(int i=0) const { return h[i]; }
324 
325  void setx(const fmatvec::Vec &x_) { x = x_; }
326  const fmatvec::Vec& getxd() const { return xd; }
327 
328  void setsvInd(int svInd_) { svInd = svInd_; };
329  int getsvSize() const { return svSize; }
330 
331  void setLinkStatusInd(int LinkStatusInd_) { LinkStatusInd = LinkStatusInd_; };
332  int getLinkStatusSize() const { return LinkStatusSize; }
333 
334  void setLinkStatusRegInd(int LinkStatusRegInd_) { LinkStatusRegInd = LinkStatusRegInd_; };
335  int getLinkStatusRegSize() const { return LinkStatusRegSize; }
336 
337  const fmatvec::Vec& getla() const { return la; }
338  fmatvec::Vec& getla() { return la; }
339  void setlaInd(int laInd_) { laInd = laInd_;Ila=fmatvec::Index(laInd,laInd+laSize-1); }
340  int getlaInd() const { return laInd; }
341  int getlaSize() const { return laSize; }
342  int getbSize() const { return bSize; }
343  const fmatvec::Index& getlaIndex() const { return Ila; }
344 
345  const fmatvec::Vec& getg() const { return g; }
346  fmatvec::Vec& getg() { return g; }
347  void setgInd(int gInd_) { gInd = gInd_; Ig=fmatvec::Index(gInd,gInd+gSize-1); }
348  const fmatvec::Vec& getgd() const { return gd; }
349  fmatvec::Vec& getgd() { return gd; }
350  void setgdInd(int gdInd_) { gdInd = gdInd_; }
351  int getgdInd() const { return gdInd; }
352  int getgSize() const { return gSize; }
353  int getgdSize() const { return gdSize; }
354  const fmatvec::Index& getgIndex() const { return Ig; }
355 
356  void setrFactorInd(int rFactorInd_) { rFactorInd = rFactorInd_; }
357  int getrFactorSize() const { return rFactorSize; }
358 
359  const fmatvec::Vector<int>& getrFactorUnsure() const { return rFactorUnsure; }
360 
364  void savela(double dt=1.0);
365 
369  void initla(double dt=1.0);
370 
374  void decreaserFactors();
375 
379  virtual Element* getByPathSearch(std::string path);
380 
389  virtual void LinearImpactEstimation(fmatvec::Vec &gInActive_,fmatvec::Vec &gdInActive_,int *IndInActive_,fmatvec::Vec &gAct_,int *IndActive_){};
390 
394  virtual void SizeLinearImpactEstimation(int *sizeInActive_, int *sizeActive_) {};
395 
396  virtual void updatecorr(int j) { corr.init(0); }
397  virtual void updatecorrRef(const fmatvec::Vec &ref);
398  virtual void calccorrSize(int j) { corrSize = 0; }
399  void setcorrInd(int corrInd_) { corrInd = corrInd_; }
400  int getcorrSize() const { return corrSize; }
401  virtual void checkRoot() {};
402 
403  protected:
407  fmatvec::Vec x;
408 
412  fmatvec::Vec xd;
413 
417  fmatvec::Vec x0;
418 
422  int xSize, xInd;
423 
427  fmatvec::Vec sv;
428 
432  fmatvec::Vector<int> jsv;
433 
437  int svSize, svInd;
438 
443  fmatvec::Vector<int> LinkStatus;
444 
448  int LinkStatusSize, LinkStatusInd;
449 
454  fmatvec::Vector<int> LinkStatusReg;
455 
459  int LinkStatusRegSize, LinkStatusRegInd;
460 
464  fmatvec::Vec g, gd, la;
465 
469  int gSize, gInd;
470 
474  int gdSize, gdInd;
475 
479  int laSize, laInd;
480 
484  int bSize, bInd;
485 
489  fmatvec::Index Ig, Ila;
490 
494  double gTol, gdTol, gddTol, laTol, LaTol;
495 
499  fmatvec::Vec la0;
500 
504  fmatvec::Vec rFactor;
505 
509  fmatvec::Vector<int> rFactorUnsure;
510 
514  int rFactorSize, rFactorInd;
515 
519  double rMax;
520 
524  fmatvec::Vec res;
525 
529  std::vector<fmatvec::Mat> W[2];
530 
534  std::vector<fmatvec::Mat> V[2];
535 
539  std::vector<fmatvec::Vec> h[2];
540 
544  std::vector<fmatvec::Mat> dhdq;
545  std::vector<fmatvec::Mat> dhdu;
546  std::vector<fmatvec::Vec> dhdt;
547 
551  std::vector<fmatvec::Vec> r[2];
552 
556  fmatvec::Vec wb;
557 
561  fmatvec::Mat b;
562 
563  int corrSize, corrInd;
564  fmatvec::Vec corr;
565  };
566 }
567 
568 #endif /* _LINK_H_ */
569