MBSim

Project Page
link.h
00001 /* Copyright (C) 2004-2014 MBSim Development Team
00002  * 
00003  * This library is free software; you can redistribute it and/or 
00004  * modify it under the terms of the GNU Lesser General Public 
00005  * License as published by the Free Software Foundation; either 
00006  * version 2.1 of the License, or (at your option) any later version. 
00007  * 
00008  * This library is distributed in the hope that it will be useful, 
00009  * but WITHOUT ANY WARRANTY; without even the implied warranty of 
00010  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
00011  * Lesser General Public License for more details. 
00012  *
00013  * You should have received a copy of the GNU Lesser General Public 
00014  * License along with this library; if not, write to the Free Software 
00015  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301 USA
00016  *
00017  * Contact: martin.o.foerg@googlemail.com
00018  */
00019 
00020 #ifndef _LINK_H_
00021 #define _LINK_H_
00022 
00023 #include "mbsim/element.h"
00024 #include "mbsim/mbsim_event.h"
00025 
00026 namespace H5 {
00027   class Group;
00028 }
00029 
00030 namespace MBSim {
00031 
00032   class Frame;
00033   class Object;
00034   class Contour;
00035   class DynamicSystem;
00036 
00050   //class Link : public Element, public LinkInterface, public ExtraDynamicInterface {
00051   class Link : public Element {
00052     public:
00057       Link(const std::string &name);
00058 
00062       virtual ~Link() {}
00063 
00064       /* INHERITED INTERFACE OF LINKINTERFACE */
00065       virtual void updateg(double t) = 0;
00066       virtual void updategd(double t) = 0;
00067       virtual void updatewb(double t, int i=0) {};
00068       virtual void updateW(double t, int i=0) {};
00069       virtual void updateV(double t, int i=0) {};
00070       virtual void updateh(double t, int i=0) {};
00071       virtual void updateStopVector(double t) {}
00072       virtual void updateLinkStatus(double t) {}
00073       virtual void updateLinkStatusReg(double t) {}
00074       virtual void updateJacobians(double t, int j=0) {}
00075       virtual void updateb(double t) {};
00076       /***************************************************/
00077 
00078       /* INHERITED INTERFACE OF EXTRADYNAMICINTERFACE */
00079       virtual void updatedx(double t, double dt) {}
00080       virtual void updatexd(double t) {}
00081       virtual void calcxSize() { xSize = 0; }
00082       virtual const fmatvec::Vec& getx() const { return x; }
00083       virtual fmatvec::Vec& getx() { return x; }
00084       virtual void setxInd(int xInd_) { xInd = xInd_; };
00085       virtual int getxSize() const { return xSize; }
00086       virtual void updatexRef(const fmatvec::Vec& ref);
00087       virtual void updatexdRef(const fmatvec::Vec& ref);
00088       virtual void updatebRef(const fmatvec::Mat &hRef);
00089       virtual void init(InitStage stage);
00090       virtual void initz();
00091       virtual void writez(H5::GroupBase *group);
00092       virtual void readz0(H5::GroupBase *group);
00093       /***************************************************/
00094 
00095       virtual void setbInd(int bInd_) { bInd = bInd_; };
00096 
00097       /* INHERITED INTERFACE OF ELEMENT */
00098       std::string getType() const { return "Link"; }
00099       virtual void plot(double t, double dt = 1);
00100       virtual void closePlot();
00101       /***************************************************/
00102 
00103       /* INTERFACE TO BE DEFINED IN DERIVED CLASS */
00107       virtual void updateWRef(const fmatvec::Mat& ref, int i=0) = 0;
00108 
00112       virtual void updateVRef(const fmatvec::Mat& ref, int i=0) = 0;
00113 
00117       virtual void updatehRef(const fmatvec::Vec &hRef, int i=0) = 0;
00118 
00122       virtual void updaterRef(const fmatvec::Vec &ref, int i=0) = 0;
00123 
00127       virtual void updatewbRef(const fmatvec::Vec &ref);
00128 
00132       virtual void updatelaRef(const fmatvec::Vec& ref);
00133 
00137       virtual void deletelaRef();
00138 
00142       virtual void updategRef(const fmatvec::Vec& ref);
00143 
00147       virtual void updategdRef(const fmatvec::Vec& ref);
00148 
00152       virtual void updateresRef(const fmatvec::Vec& ref);
00153 
00157       virtual void updaterFactorRef(const fmatvec::Vec& ref);
00158 
00162       virtual void updatesvRef(const fmatvec::Vec &sv);
00163 
00167       virtual void updatejsvRef(const fmatvec::VecInt &jsvParent);
00168 
00172        virtual void updateLinkStatusRef(const fmatvec::VecInt &LinkStatusParent);
00173 
00177        virtual void updateLinkStatusRegRef(const fmatvec::VecInt &LinkStatusRegParent);
00178 
00182       virtual void calclaSize(int j) { laSize = 0; }
00183 
00187       virtual void calcgSize(int j) { gSize = 0; }
00188 
00195       virtual void calcgdSize(int j) { gdSize = 0; }
00196 
00200       virtual void calcrFactorSize(int j) { rFactorSize = 0; }
00201 
00205       virtual void calcbSize() { bSize = 0; }
00206 
00210       virtual void calcsvSize() { svSize = 0; }
00211       
00215       virtual void calcLinkStatusSize() { LinkStatusSize =0;}
00216 
00220       virtual void calcLinkStatusRegSize() { LinkStatusRegSize =0;}
00221 
00227       virtual bool isSetValued() const { return false; }
00228 
00234       virtual bool isSingleValued() const { return false; }
00235 
00241       virtual bool hasSmoothPart() const { return false; }
00242 
00246       virtual bool isActive() const = 0;
00247 
00251       virtual bool gActiveChanged() = 0;
00252       
00256       virtual bool detectImpact() { return false; }
00257 
00262       virtual void solveImpactsFixpointSingle(double dt) { THROW_MBSIMERROR("(Link::solveImpactsFixpointSingle): Not implemented."); }
00263 
00267       virtual void solveConstraintsFixpointSingle() { THROW_MBSIMERROR("(Link::solveConstraintsFixpointSingle): Not implemented."); }
00268 
00273       virtual void solveImpactsGaussSeidel(double dt) { THROW_MBSIMERROR("(Link::solveImpactsGaussSeidel): Not implemented."); }
00274 
00278       virtual void solveConstraintsGaussSeidel() { THROW_MBSIMERROR("(Link::solveConstraintsGaussSeidel): Not implemented."); }
00279 
00284       virtual void solveImpactsRootFinding(double dt) { THROW_MBSIMERROR("(Link::solveImpactsRootFinding): Not implemented."); }
00285 
00289       virtual void solveConstraintsRootFinding() { THROW_MBSIMERROR("(Link::solveConstraintsRootFinding): Not implemented."); }
00290 
00294       virtual void jacobianConstraints() { THROW_MBSIMERROR("(Link::jacobianConstraints): Not implemented."); }
00295 
00299       virtual void jacobianImpacts() { THROW_MBSIMERROR("(Link::jacobianImpacts): Not implemented."); }
00300 
00304       virtual void updaterFactors() { THROW_MBSIMERROR("(Link::updaterFactors): Not implemented."); }
00305 
00309       virtual void checkImpactsForTermination(double dt) { THROW_MBSIMERROR("(Link::checkImpactsForTermination): Not implemented."); }
00310       
00314       virtual void checkConstraintsForTermination() { THROW_MBSIMERROR("(Link::checkConstraintsForTermination): Not implemented."); }
00315 
00322       virtual void checkActive(int j) {}
00323 
00327       virtual double computePotentialEnergy() { return 0; }
00328 
00329       virtual void setlaTol(double tol) { laTol = tol; }
00330       virtual void setLaTol(double tol) { LaTol = tol; }
00331       virtual void setgTol(double tol) { gTol = tol; }
00332       virtual void setgdTol(double tol) { gdTol = tol; }
00333       virtual void setgddTol(double tol) { gddTol = tol; }
00334       virtual void setrMax(double rMax_) { rMax = rMax_; }
00335       virtual void setLinkStatusInd(int LinkStatusInd_) { LinkStatusInd = LinkStatusInd_; };
00336       virtual void setLinkStatusRegInd(int LinkStatusRegInd_) { LinkStatusRegInd = LinkStatusRegInd_; };
00337       virtual void setlaInd(int laInd_) { laInd = laInd_;Ila=fmatvec::Index(laInd,laInd+laSize-1); }
00338       virtual void setgInd(int gInd_) { gInd = gInd_; Ig=fmatvec::Index(gInd,gInd+gSize-1); }
00339       virtual void setgdInd(int gdInd_) { gdInd = gdInd_; }
00340       virtual void setrFactorInd(int rFactorInd_) { rFactorInd = rFactorInd_; }
00349       virtual void LinearImpactEstimation(fmatvec::Vec &gInActive_,fmatvec::Vec &gdInActive_,int *IndInActive_,fmatvec::Vec &gAct_,int *IndActive_){};
00350       
00354       virtual void SizeLinearImpactEstimation(int *sizeInActive_, int *sizeActive_) {};
00355       virtual void updatecorr(int j) { corr.init(0); }
00356       virtual void updatecorrRef(const fmatvec::Vec &ref);
00357       virtual void calccorrSize(int j) { corrSize = 0; }
00358       virtual void setcorrInd(int corrInd_) { corrInd = corrInd_; }
00359       virtual void checkRoot() {};
00360       /***************************************************/
00361 
00362       /* GETTER / SETTER */
00363       const std::vector<fmatvec::Mat>& getW(int i=0) const { return W[i]; }
00364       const std::vector<fmatvec::Mat>& getV(int i=0) const { return V[i]; }
00365       const std::vector<fmatvec::Vec>& geth(int i=0) const { return h[i]; }
00366 
00367       void setx(const fmatvec::Vec &x_) { x = x_; }
00368       const fmatvec::Vec& getxd() const { return xd; }
00369       
00370       virtual void setsvInd(int svInd_) { svInd = svInd_; };
00371       int getsvSize() const { return svSize; }
00372 
00373       int getLinkStatusSize() const { return LinkStatusSize; }
00374 
00375       int getLinkStatusRegSize() const { return LinkStatusRegSize; }
00376 
00377       const fmatvec::Vec& getla() const { return la; }
00378       fmatvec::Vec& getla() { return la; }
00379       int getlaInd() const { return laInd; } 
00380       int getlaSize() const { return laSize; } 
00381       int getbSize() const { return bSize; }
00382       const fmatvec::Index& getlaIndex() const { return Ila; }
00383 
00384       const fmatvec::Vec& getg() const { return g; }
00385       fmatvec::Vec& getg() { return g; }
00386       const fmatvec::Vec& getgd() const { return gd; }
00387       fmatvec::Vec& getgd() { return gd; }
00388       const fmatvec::Vec& getwb() const { return wb; }
00389       fmatvec::Vec& getwb() { return wb; }
00390       int getgdInd() const { return gdInd; } 
00391       int getgSize() const { return gSize; } 
00392       int getgdSize() const { return gdSize; } 
00393       const fmatvec::Index& getgIndex() const { return Ig; }
00394       
00395       int getrFactorSize() const { return rFactorSize; } 
00396       
00397       const fmatvec::VecInt& getrFactorUnsure() const { return rFactorUnsure; }
00398 
00402       void savela(double dt=1.0);
00403 
00407       void initla(double dt=1.0);
00408 
00412       void decreaserFactors();
00413 
00414       
00415       int getcorrSize() const { return corrSize; } 
00416 
00417     protected:
00421       fmatvec::Vec x;
00422 
00426       fmatvec::Vec xd;
00427 
00431       fmatvec::Vec x0;
00432 
00436       int xSize, xInd;
00437 
00441       fmatvec::Vec sv;
00442 
00446       fmatvec::VecInt jsv;
00447 
00451       int svSize, svInd;
00452              
00457       fmatvec::VecInt LinkStatus;
00458 
00462        int LinkStatusSize, LinkStatusInd;
00463     
00468       fmatvec::VecInt LinkStatusReg;
00469 
00473        int LinkStatusRegSize, LinkStatusRegInd; 
00474 
00478       fmatvec::Vec g, gd, la;
00479       
00483       fmatvec::Vec laS;
00484 
00488       int gSize, gInd;
00489 
00493       int gdSize, gdInd;
00494 
00498       int laSize, laInd;
00499 
00503       int bSize, bInd;
00504 
00508       fmatvec::Index Ig, Ila;
00509       
00513       double gTol, gdTol, gddTol, laTol, LaTol;
00514       
00518       fmatvec::Vec la0;
00519 
00523       fmatvec::Vec rFactor;
00524 
00528       fmatvec::VecInt rFactorUnsure;
00529 
00533       int rFactorSize, rFactorInd;
00534       
00538       double rMax;
00539 
00543       fmatvec::Vec res;
00544 
00548       std::vector<fmatvec::Mat> W[2];
00549 
00553       std::vector<fmatvec::Mat> V[2];
00554       
00558       std::vector<fmatvec::Vec> h[2];
00559       
00563       std::vector<fmatvec::Mat> dhdq;
00564       std::vector<fmatvec::Mat> dhdu;
00565       std::vector<fmatvec::Vec> dhdt;
00566       
00570       std::vector<fmatvec::Vec> r[2];
00571       
00575       fmatvec::Vec wb;
00576 
00580       fmatvec::Mat b;
00581 
00582       int corrSize, corrInd;
00583       fmatvec::Vec corr;
00584   };
00585 }
00586 
00587 #endif /* _LINK_H_ */
00588