MBSim

Project Page
link.h
00001 /* Copyright (C) 2004-2009 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/link_interface.h"
00025 //#include "mbsim/extradynamic_interface.h"
00026 #include "mbsim/mbsim_event.h"
00027 
00028 namespace H5 {
00029   class Group;
00030 }
00031 
00032 namespace MBSim {
00033 
00034   class Frame;
00035   class Object;
00036   class Contour;
00037   class DynamicSystem;
00038 
00052   //class Link : public Element, public LinkInterface, public ExtraDynamicInterface {
00053   class Link : public Element {
00054     public:
00059       Link(const std::string &name);
00060 
00064       virtual ~Link() {}
00065 
00066       /* INHERITED INTERFACE OF LINKINTERFACE */
00067       virtual void updateg(double t) = 0;
00068       virtual void updategd(double t) = 0;
00069       virtual void updatewb(double t, int i=0) {};
00070       virtual void updateW(double t, int i=0) {};
00071       virtual void updateV(double t, int i=0) {};
00072       virtual void updateh(double t, int i=0) {};
00073       virtual void updateStopVector(double t) {}
00074       virtual void updateLinkStatus(double t) {}
00075       virtual void updateLinkStatusReg(double t) {}
00076       virtual void updateJacobians(double t, int j=0) {}
00077       virtual void updateb(double t) {};
00078       /***************************************************/
00079 
00080       /* INHERITED INTERFACE OF EXTRADYNAMICINTERFACE */
00081       virtual void updatedx(double t, double dt) {}
00082       virtual void updatexd(double t) {}
00083       virtual void calcxSize() { xSize = 0; }
00084       virtual const fmatvec::Vec& getx() const { return x; }
00085       virtual fmatvec::Vec& getx() { return x; }
00086       virtual void setxInd(int xInd_) { xInd = xInd_; };
00087       virtual int getxSize() const { return xSize; }
00088       virtual void updatexRef(const fmatvec::Vec& ref);
00089       virtual void updatexdRef(const fmatvec::Vec& ref);
00090       virtual void updatebRef(const fmatvec::Mat &hRef);
00091       virtual void init(InitStage stage);
00092       virtual void initz();
00093       virtual void writez(const H5::Group & group);
00094       virtual void readz0(const H5::Group & group);
00095       /***************************************************/
00096 
00097       virtual void setbInd(int bInd_) { bInd = bInd_; };
00098 
00099       /* INHERITED INTERFACE OF ELEMENT */
00100       std::string getType() const { return "Link"; }
00101       virtual void plot(double t, double dt = 1);
00102       virtual void closePlot();
00103       /***************************************************/
00104 
00105       /* INTERFACE TO BE DEFINED IN DERIVED CLASS */
00109       virtual void updateWRef(const fmatvec::Mat& ref, int i=0) = 0;
00110 
00114       virtual void updateVRef(const fmatvec::Mat& ref, int i=0) = 0;
00115 
00119       virtual void updatehRef(const fmatvec::Vec &hRef, int i=0) = 0;
00120 
00124       virtual void updaterRef(const fmatvec::Vec &ref, int i=0) = 0;
00125 
00129       virtual void updatewbRef(const fmatvec::Vec &ref);
00130 
00134       virtual void updatelaRef(const fmatvec::Vec& ref);
00135 
00139       virtual void deletelaRef();
00140 
00144       virtual void updategRef(const fmatvec::Vec& ref);
00145 
00149       virtual void updategdRef(const fmatvec::Vec& ref);
00150 
00154       virtual void updateresRef(const fmatvec::Vec& ref);
00155 
00159       virtual void updaterFactorRef(const fmatvec::Vec& ref);
00160 
00164       virtual void updatesvRef(const fmatvec::Vec &sv);
00165 
00169       virtual void updatejsvRef(const fmatvec::VecInt &jsvParent);
00170 
00174        virtual void updateLinkStatusRef(const fmatvec::VecInt &LinkStatusParent);
00175 
00179        virtual void updateLinkStatusRegRef(const fmatvec::VecInt &LinkStatusRegParent);
00180 
00184       virtual void calclaSize(int j) { laSize = 0; }
00185 
00189       virtual void calcgSize(int j) { gSize = 0; }
00190 
00194       virtual void calcgdSize(int j) { gdSize = 0; }
00195 
00199       virtual void calcrFactorSize(int j) { rFactorSize = 0; }
00200 
00204       virtual void calcbSize() { bSize = 0; }
00205 
00209       virtual void calcsvSize() { svSize = 0; }
00210       
00214       virtual void calcLinkStatusSize() { LinkStatusSize =0;}
00215 
00219       virtual void calcLinkStatusRegSize() { LinkStatusRegSize =0;}
00220 
00226       virtual bool isSetValued() const { return false; }
00227 
00233       virtual bool isSingleValued() const { return false; }
00234 
00240       virtual bool hasSmoothPart() const { return false; }
00241 
00245       virtual bool isActive() const = 0;
00246 
00250       virtual bool gActiveChanged() = 0;
00251 
00255       virtual void solveImpactsFixpointSingle(double dt) { throw MBSimError("ERROR in "+getName()+" (Link::solveImpactsFixpointSingle): Not implemented."); }
00256 
00260       virtual void solveConstraintsFixpointSingle() { throw MBSimError("ERROR in "+getName()+" (Link::solveConstraintsFixpointSingle): Not implemented."); }
00261 
00265       virtual void solveImpactsGaussSeidel(double dt) { throw MBSimError("ERROR in "+getName()+" (Link::solveImpactsGaussSeidel): Not implemented."); }
00266 
00270       virtual void solveConstraintsGaussSeidel() { throw MBSimError("ERROR in "+getName()+" (Link::solveConstraintsGaussSeidel): Not implemented."); }
00271 
00275       virtual void solveImpactsRootFinding(double dt) { throw MBSimError("ERROR in "+getName()+" (Link::solveImpactsRootFinding): Not implemented."); }
00276 
00280       virtual void solveConstraintsRootFinding() { throw MBSimError("ERROR in "+getName()+" (Link::solveConstraintsRootFinding): Not implemented."); }
00281 
00285       virtual void jacobianConstraints() { throw MBSimError("ERROR in "+getName()+" (Link::jacobianConstraints): Not implemented."); }
00286 
00290       virtual void jacobianImpacts() { throw MBSimError("ERROR in "+getName()+" (Link::jacobianImpacts): Not implemented."); }
00291 
00295       virtual void updaterFactors() { throw MBSimError("ERROR in "+getName()+" (Link::updaterFactors): Not implemented."); }
00296 
00300       virtual void checkImpactsForTermination(double dt) { throw MBSimError("ERROR in "+getName()+" (Link::checkImpactsForTermination): Not implemented."); }
00301       
00305       virtual void checkConstraintsForTermination() { throw MBSimError("ERROR in "+getName()+" (Link::checkConstraintsForTermination): Not implemented."); }
00306 
00311       virtual void checkActive(int j) {}
00312 
00316       virtual double computePotentialEnergy() { return 0; }
00317 
00318       /* GETTER / SETTER */
00319       virtual void setlaTol(double tol) { laTol = tol; }
00320       virtual void setLaTol(double tol) { LaTol = tol; }
00321       virtual void setgTol(double tol) { gTol = tol; }
00322       virtual void setgdTol(double tol) { gdTol = tol; }
00323       virtual void setgddTol(double tol) { gddTol = tol; }
00324       virtual void setrMax(double rMax_) { rMax = rMax_; }
00325       /***************************************************/
00326 
00327       /* GETTER / SETTER */
00328       const std::vector<fmatvec::Mat>& getW(int i=0) const { return W[i]; }
00329       const std::vector<fmatvec::Mat>& getV(int i=0) const { return V[i]; }
00330       const std::vector<fmatvec::Vec>& geth(int i=0) const { return h[i]; }
00331 
00332       void setx(const fmatvec::Vec &x_) { x = x_; }
00333       const fmatvec::Vec& getxd() const { return xd; }
00334       
00335       void setsvInd(int svInd_) { svInd = svInd_; };
00336       int getsvSize() const { return svSize; }
00337 
00338       virtual void setLinkStatusInd(int LinkStatusInd_) { LinkStatusInd = LinkStatusInd_; };
00339       int getLinkStatusSize() const { return LinkStatusSize; }
00340 
00341       virtual void setLinkStatusRegInd(int LinkStatusRegInd_) { LinkStatusRegInd = LinkStatusRegInd_; };
00342       int getLinkStatusRegSize() const { return LinkStatusRegSize; }
00343 
00344       const fmatvec::Vec& getla() const { return la; }
00345       fmatvec::Vec& getla() { return la; }
00346       virtual void setlaInd(int laInd_) { laInd = laInd_;Ila=fmatvec::Index(laInd,laInd+laSize-1); }
00347       int getlaInd() const { return laInd; } 
00348       int getlaSize() const { return laSize; } 
00349       int getbSize() const { return bSize; }
00350       const fmatvec::Index& getlaIndex() const { return Ila; }
00351 
00352       const fmatvec::Vec& getg() const { return g; }
00353       fmatvec::Vec& getg() { return g; }
00354       virtual void setgInd(int gInd_) { gInd = gInd_; Ig=fmatvec::Index(gInd,gInd+gSize-1); }
00355       const fmatvec::Vec& getgd() const { return gd; }
00356       fmatvec::Vec& getgd() { return gd; }
00357       const fmatvec::Vec& getwb() const { return wb; }
00358       fmatvec::Vec& getwb() { return wb; }
00359       virtual void setgdInd(int gdInd_) { gdInd = gdInd_; }
00360       int getgdInd() const { return gdInd; } 
00361       int getgSize() const { return gSize; } 
00362       int getgdSize() const { return gdSize; } 
00363       const fmatvec::Index& getgIndex() const { return Ig; }
00364       
00365       virtual void setrFactorInd(int rFactorInd_) { rFactorInd = rFactorInd_; }
00366       int getrFactorSize() const { return rFactorSize; } 
00367       
00368       const fmatvec::VecInt& getrFactorUnsure() const { return rFactorUnsure; }
00369 
00373       void savela(double dt=1.0);
00374 
00378       void initla(double dt=1.0);
00379 
00383       void decreaserFactors();
00384 
00388       virtual Element* getByPathSearch(std::string path);
00389 
00398       virtual void LinearImpactEstimation(fmatvec::Vec &gInActive_,fmatvec::Vec &gdInActive_,int *IndInActive_,fmatvec::Vec &gAct_,int *IndActive_){};
00399       
00403       virtual void SizeLinearImpactEstimation(int *sizeInActive_, int *sizeActive_) {};
00404 
00405       virtual void updatecorr(int j) { corr.init(0); }
00406       virtual void updatecorrRef(const fmatvec::Vec &ref);
00407       virtual void calccorrSize(int j) { corrSize = 0; }
00408       virtual void setcorrInd(int corrInd_) { corrInd = corrInd_; }
00409       int getcorrSize() const { return corrSize; } 
00410       virtual void checkRoot() {};
00411 
00412     protected:
00416       fmatvec::Vec x;
00417 
00421       fmatvec::Vec xd;
00422 
00426       fmatvec::Vec x0;
00427 
00431       int xSize, xInd;
00432 
00436       fmatvec::Vec sv;
00437 
00441       fmatvec::VecInt jsv;
00442 
00446       int svSize, svInd;
00447              
00452       fmatvec::VecInt LinkStatus;
00453 
00457        int LinkStatusSize, LinkStatusInd;
00458     
00463       fmatvec::VecInt LinkStatusReg;
00464 
00468        int LinkStatusRegSize, LinkStatusRegInd; 
00469 
00473       fmatvec::Vec g, gd, la;
00474       
00478       fmatvec::Vec laS;
00479 
00483       int gSize, gInd;
00484 
00488       int gdSize, gdInd;
00489 
00493       int laSize, laInd;
00494 
00498       int bSize, bInd;
00499 
00503       fmatvec::Index Ig, Ila;
00504       
00508       double gTol, gdTol, gddTol, laTol, LaTol;
00509       
00513       fmatvec::Vec la0;
00514 
00518       fmatvec::Vec rFactor;
00519 
00523       fmatvec::VecInt rFactorUnsure;
00524 
00528       int rFactorSize, rFactorInd;
00529       
00533       double rMax;
00534 
00538       fmatvec::Vec res;
00539 
00543       std::vector<fmatvec::Mat> W[2];
00544 
00548       std::vector<fmatvec::Mat> V[2];
00549       
00553       std::vector<fmatvec::Vec> h[2];
00554       
00558       std::vector<fmatvec::Mat> dhdq;
00559       std::vector<fmatvec::Mat> dhdu;
00560       std::vector<fmatvec::Vec> dhdt;
00561       
00565       std::vector<fmatvec::Vec> r[2];
00566       
00570       fmatvec::Vec wb;
00571 
00575       fmatvec::Mat b;
00576 
00577       int corrSize, corrInd;
00578       fmatvec::Vec corr;
00579   };
00580 }
00581 
00582 #endif /* _LINK_H_ */
00583