mbsimflexiblebody  4.0.0
flexible_body_ffr.h
00001 /* Copyright (C) 2004-2015 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 _FLEXIBLE_BODY_FFR_H_
00021 #define _FLEXIBLE_BODY_FFR_H_
00022 
00023 #include "mbsim/body.h"
00024 #include "mbsim/functions/auxiliary_functions.h"
00025 #include "mbsimFlexibleBody/utils/taylor.h"
00026 
00027 #ifdef HAVE_OPENMBVCPPINTERFACE
00028 #include "mbsim/utils/boost_parameters.h"
00029 #include "mbsim/utils/openmbv_utils.h"
00030 #endif
00031 
00032 namespace MBSim {
00033   class Frame;
00034   class Contour;
00035   class CompoundContour;
00036 }
00037 
00038 namespace MBSimFlexibleBody {
00039 
00040   class FixedNodalFrame;
00041 
00042   class FlexibleBodyFFR : public MBSim::Body {
00043     public:
00044 
00045       FlexibleBodyFFR(const std::string &name=""); 
00049       virtual ~FlexibleBodyFFR();
00050 
00051       virtual void updatedq(double t, double dt);
00052       virtual void updateqd(double t); 
00053       virtual void updateT(double t);
00054       virtual void updateh(double t, int j=0);
00055       virtual void updatehInverseKinetics(double t, int j=0);
00056       virtual void updateStateDerivativeDependentVariables(double t);
00057       virtual void updateM(double t, int i=0) { (this->*updateM_)(t,i); }
00058       virtual void updateStateDependentVariables(double t) { 
00059         updateKinematicsForSelectedFrame(t); 
00060         updateKinematicsForRemainingFramesAndContours(t); 
00061       }
00062       virtual void updateJacobians(double t, int j=0) { (this->*updateJacobians_[j])(t); }
00063       void updateJacobians0(double t) { 
00064         updateJacobiansForSelectedFrame0(t); 
00065         updateJacobiansForRemainingFramesAndContours(t,0); 
00066       }
00067       void updateJacobians1(double t) { 
00068         updateJacobiansForRemainingFramesAndContours1(t); 
00069       }
00070       virtual void calcqSize();
00071       virtual void calcuSize(int j=0);
00072 
00073       /* INHERITED INTERFACE OF OBJECT */
00074       virtual void updateqRef(const fmatvec::Vec& ref);
00075       virtual void updateuRef(const fmatvec::Vec& ref);
00076       virtual void init(InitStage stage);
00077       virtual void initz();
00078       virtual void facLLM(int i=0) { (this->*facLLM_)(i); }
00079       virtual void setUpInverseKinetics();
00080       /*****************************************************/
00081 
00082       /* INHERITED INTERFACE OF ELEMENT */
00083       virtual std::string getType() const { return "FlexibleBodyFFR"; }
00084       virtual void plot(double t, double dt=1);
00085       /*****************************************************/
00086 
00087       /* INTERFACE FOR DERIVED CLASSES */
00091       virtual void updateKinematicsForSelectedFrame(double t);
00095       virtual void updateJacobiansForSelectedFrame0(double t); 
00096 
00100       virtual void updateKinematicsForRemainingFramesAndContours(double t);
00101 
00105       virtual void updateJacobiansForRemainingFramesAndContours(double t, int j=0);
00106       virtual void updateJacobiansForRemainingFramesAndContours1(double t);
00107 
00108       /* GETTER / SETTER */
00109 
00110       // NOTE: we can not use a overloaded setTranslation here due to restrictions in XML but define them for convinience in c++
00115       void setGeneralTranslation(MBSim::Function<fmatvec::Vec3(fmatvec::VecV, double)> *fPrPK_) {
00116         fPrPK = fPrPK_;
00117         fPrPK->setParent(this);
00118         fPrPK->setName("GeneralTranslation");
00119       }
00124       void setTimeDependentTranslation(MBSim::Function<fmatvec::Vec3(double)> *fPrPK_) {
00125         setGeneralTranslation(new MBSim::TimeDependentFunction<fmatvec::Vec3>(fPrPK_));
00126       }
00131       void setStateDependentTranslation(MBSim::Function<fmatvec::Vec3(fmatvec::VecV)> *fPrPK_) {
00132         setGeneralTranslation(new MBSim::StateDependentFunction<fmatvec::Vec3>(fPrPK_));
00133       }
00134       void setTranslation(MBSim::Function<fmatvec::Vec3(fmatvec::VecV, double)> *fPrPK_) { setGeneralTranslation(fPrPK_); }
00135       void setTranslation(MBSim::Function<fmatvec::Vec3(double)> *fPrPK_) { setTimeDependentTranslation(fPrPK_); }
00136       void setTranslation(MBSim::Function<fmatvec::Vec3(fmatvec::VecV)> *fPrPK_) { setStateDependentTranslation(fPrPK_); }
00137 
00138       // NOTE: we can not use a overloaded setRotation here due to restrictions in XML but define them for convinience in c++
00143       void setGeneralRotation(MBSim::Function<fmatvec::RotMat3(fmatvec::VecV, double)>* fAPK_) {
00144         fAPK = fAPK_;
00145         fAPK->setParent(this);
00146         fAPK->setName("GeneralRotation");
00147       }
00152       void setTimeDependentRotation(MBSim::Function<fmatvec::RotMat3(double)>* fAPK_) { setGeneralRotation(new MBSim::TimeDependentFunction<fmatvec::RotMat3>(fAPK_)); }
00157       void setStateDependentRotation(MBSim::Function<fmatvec::RotMat3(fmatvec::VecV)>* fAPK_) { setGeneralRotation(new MBSim::StateDependentFunction<fmatvec::RotMat3>(fAPK_)); }
00158       void setRotation(MBSim::Function<fmatvec::RotMat3(fmatvec::VecV, double)>* fAPK_) { setGeneralRotation(fAPK_); }
00159       void setRotation(MBSim::Function<fmatvec::RotMat3(double)>* fAPK_) { setTimeDependentRotation(fAPK_); }
00160       void setRotation(MBSim::Function<fmatvec::RotMat3(fmatvec::VecV)>* fAPK_) { setStateDependentRotation(fAPK_); }
00161 
00162       void setTranslationDependentRotation(bool dep) { translationDependentRotation = dep; }
00163       void setCoordinateTransformationForRotation(bool ct) { coordinateTransformation = ct; }
00164 
00169       MBSim::Function<fmatvec::Vec3(fmatvec::VecV, double)>* getTranslation() { return fPrPK; }
00174       MBSim::Function<fmatvec::RotMat3(fmatvec::VecV, double)>* getRotation() { return fAPK; }
00175 
00176       double getMass() const { return m; }
00177       FixedNodalFrame* getFrameK() { return K; };
00178 
00179       // Interface for basic data
00183       void setMass(double m_) { m = m_; }
00184       void setc0(const fmatvec::Vec3 &c0_) { c0 = c0_; }
00189       void setI0(const fmatvec::SymMat3& I0_) { I0 = I0_; }
00190       void setC1(const fmatvec::Mat3xV &C1_) { C1 = C1_; }
00191       void setC3(const std::vector<std::vector<fmatvec::SqrMatV> > &C3_) { C3 = C3_; }
00192       void setC4(const std::vector<fmatvec::SqrMat3> &C4_) { C4 = C4_; }
00193       void setKe(const fmatvec::SymMatV &Ke_) { Ke.setM0(Ke_); }
00194       void setDe(const fmatvec::SymMatV &De_) { De.setM0(De_); }
00195       void setProportionalDamping(const fmatvec::Vec2 &beta_) { beta = beta_; }
00196       // End of interface
00197 
00198       // Interface for nonlinear stiffness matrices
00199       void setC7(const std::vector<fmatvec::SqrMatV> &C7_) { C7 = C7_; }
00200       void setC8(const std::vector<std::vector<fmatvec::SqrMatV> > &C8_) { C8 = C8_; }
00201       // End of interface
00202 
00203       // Interface for geometric stiffness matrices 
00204       void setK0t(const std::vector<fmatvec::SqrMatV> &K0t_) { K0t = K0t_; }
00205       void setK0r(const std::vector<fmatvec::SqrMatV> &K0r_) { K0r = K0r_; }
00206       void setK0om(const std::vector<fmatvec::SqrMatV> &K0om_) { K0om = K0om_; }
00207       // End of interface
00208 
00209       // Interface for reference stresses 
00210       void setke0(const fmatvec::VecV &ke0_) { ke0 = ke0_; }
00211       void setKe0(const fmatvec::SqrMatV &Ke0_) { Ke0 = Ke0_; }
00212       // End of interface
00213 
00214       // Interface for standard input data
00215       void setmCM(const Taylor<fmatvec::Vec3,fmatvec::Mat3xV> &mCM_) { mCM = mCM_; }
00216       void setmmi(const Taylor<fmatvec::SymMat3,std::vector<fmatvec::SymMat3>,std::vector<std::vector<fmatvec::SqrMat3> > > &mmi_) { mmi = mmi_; }
00217       void setCt(const Taylor<fmatvec::MatVx3,std::vector<fmatvec::SqrMatV> > &Ct_) { Ct = Ct_; }
00218       void setCr(const Taylor<fmatvec::MatVx3,std::vector<fmatvec::SqrMatV> > &Cr_) { Cr = Cr_; }
00219       void setMe(const Taylor<fmatvec::SymMatV> &Me_) { Me = Me_; }
00220       void setGr(const Taylor<std::vector<fmatvec::SqrMat3>,std::vector<std::vector<fmatvec::SqrMat3> > > &Gr_) { Gr = Gr_; }
00221       void setGe(const Taylor<std::vector<fmatvec::SqrMatV> > &Ge_) { Ge = Ge_; }
00222       void setOe(const Taylor<fmatvec::Matrix<fmatvec::General,fmatvec::Var,fmatvec::Fixed<6>,double>,std::vector<fmatvec::SqrMatV> > &Oe_) { Oe = Oe_; }
00223       void setKe(const Taylor<fmatvec::SymMatV,std::vector<fmatvec::SqrMatV>, std::vector<std::vector<fmatvec::SqrMatV> > > &Ke_) { Ke = Ke_; }
00224       void setDe(const Taylor<fmatvec::SymMatV,std::vector<fmatvec::SqrMatV>, std::vector<std::vector<fmatvec::SqrMatV> > > &De_) { De = De_; }
00225       void setksigma(const Taylor<fmatvec::VecV,fmatvec::SqrMatV> &ksigma_) { ksigma = ksigma_; }
00226       // End of interface
00227       
00231       void readBIDFromFile(const std::string& file);
00232 
00236       void readSIDFromFile(const std::string& file);
00237 
00238       void addFrame(FixedNodalFrame *frame); 
00239 
00240       using Body::addContour;
00241 
00242 #ifdef HAVE_OPENMBVCPPINTERFACE
00243       void setOpenMBVRigidBody(const boost::shared_ptr<OpenMBV::RigidBody> &body);
00244       void setOpenMBVFrameOfReference(MBSim::Frame * frame) {openMBVFrame=frame; }
00245       const MBSim::Frame* getOpenMBVFrameOfReference() const {return openMBVFrame; }
00246 
00248       BOOST_PARAMETER_MEMBER_FUNCTION( (void), enableOpenMBVWeight, MBSim::tag, (optional (scaleLength,(double),1)(scaleSize,(double),1)(referencePoint,(OpenMBV::Arrow::ReferencePoint),OpenMBV::Arrow::toPoint)(diffuseColor,(const fmatvec::Vec3&),"[-1;1;1]")(transparency,(double),0))) { 
00249         MBSim::OpenMBVArrow ombv(diffuseColor,transparency,OpenMBV::Arrow::toHead,referencePoint,scaleLength,scaleSize);
00250         FWeight=ombv.createOpenMBV();
00251       }
00252 
00254       BOOST_PARAMETER_MEMBER_FUNCTION( (void), enableOpenMBVJointForce, MBSim::tag, (optional (scaleLength,(double),1)(scaleSize,(double),1)(referencePoint,(OpenMBV::Arrow::ReferencePoint),OpenMBV::Arrow::toPoint)(diffuseColor,(const fmatvec::Vec3&),"[-1;1;1]")(transparency,(double),0))) { 
00255         MBSim::OpenMBVArrow ombv(diffuseColor,transparency,OpenMBV::Arrow::toHead,referencePoint,scaleLength,scaleSize);
00256         FArrow=ombv.createOpenMBV();
00257       }
00258 
00260       BOOST_PARAMETER_MEMBER_FUNCTION( (void), enableOpenMBVJointMoment, MBSim::tag, (optional (scaleLength,(double),1)(scaleSize,(double),1)(referencePoint,(OpenMBV::Arrow::ReferencePoint),OpenMBV::Arrow::toPoint)(diffuseColor,(const fmatvec::Vec3&),"[-1;1;1]")(transparency,(double),0))) { 
00261         MBSim::OpenMBVArrow ombv(diffuseColor,transparency,OpenMBV::Arrow::toHead,referencePoint,scaleLength,scaleSize);
00262         MArrow=ombv.createOpenMBV();
00263       }
00264 #endif
00265 
00266       virtual void initializeUsingXML(xercesc::DOMElement *element);
00267       virtual xercesc::DOMElement* writeXMLFile(xercesc::DOMNode *element);
00268 
00269       const fmatvec::Mat3xV& getWJTrel() const {return WJTrel;}
00270       const fmatvec::Mat3xV& getWJRrel() const {return WJRrel;}
00271       fmatvec::Mat3xV& getWJTrel() {return WJTrel;}
00272       fmatvec::Mat3xV& getWJRrel() {return WJRrel;}
00273       fmatvec::Vec& getqRel() {return qRel;}
00274       fmatvec::Vec& getuRel() {return uRel;}
00275       fmatvec::Mat& getTRel() {return TRel;}
00276       fmatvec::Mat3xV& getPJT(int i=0) {return PJT[i];}
00277       fmatvec::Mat3xV& getPJR(int i=0) {return PJR[i];}
00278 
00279       int getqRelSize() const {return nq;}
00280       int getuRelSize(int i=0) const {return nu[i];}
00281 
00282       bool transformCoordinates() const {return fTR!=NULL;}
00283 
00284     protected:
00285       // Basic input data
00286       double m;
00287       fmatvec::Vec3 c0;
00288       fmatvec::SymMat3 I0;
00289       fmatvec::Mat3xV C1, C2;
00290       std::vector<std::vector<fmatvec::SqrMatV> > C3;
00291       std::vector<fmatvec::SqrMat3> C4;
00292       std::vector<fmatvec::Mat3xV> C5;
00293       std::vector<std::vector<fmatvec::SqrMat3> > C6;
00294       std::vector<fmatvec::SqrMatV> C7;
00295       std::vector<std::vector<fmatvec::SqrMatV> > C8;
00296       std::vector<fmatvec::SqrMatV> K0t, K0r, K0om;
00297       fmatvec::Vec2 beta;
00298       fmatvec::VecV ke0;
00299       fmatvec::SqrMatV Ke0;
00300       // End of basic input data
00301 
00302       // Standard input data (SID)
00303       Taylor<fmatvec::Vec3,fmatvec::Mat3xV> mCM;
00304       Taylor<fmatvec::SymMat3,std::vector<fmatvec::SymMat3>,std::vector<std::vector<fmatvec::SqrMat3> > > mmi;
00305       Taylor<fmatvec::MatVx3,std::vector<fmatvec::SqrMatV> > Ct;
00306       Taylor<fmatvec::MatVx3,std::vector<fmatvec::SqrMatV> > Cr;
00307       Taylor<fmatvec::SymMatV> Me;
00308       Taylor<std::vector<fmatvec::SqrMat3>,std::vector<std::vector<fmatvec::SqrMat3> > > Gr;
00309       Taylor<std::vector<fmatvec::SqrMatV> > Ge;
00310       Taylor<fmatvec::Matrix<fmatvec::General,fmatvec::Var,fmatvec::Fixed<6>,double>,std::vector<fmatvec::SqrMatV> > Oe;
00311       Taylor<fmatvec::SymMatV,std::vector<fmatvec::SqrMatV>, std::vector<std::vector<fmatvec::SqrMatV> > > Ke, De;
00312       Taylor<fmatvec::VecV,fmatvec::SqrMatV> ksigma;
00313       // End of standard input data (SID)
00314 
00315       // Number of mode shapes 
00316       int ne;
00317 
00318       FixedNodalFrame *K;
00319 
00323       fmatvec::SymMat Mbuf;
00324 
00328       bool coordinateTransformation;
00329 
00333       fmatvec::Mat3xV PJT[2], PJR[2];
00334 
00335       fmatvec::Vec3 PjhT, PjhR, PjbT, PjbR;
00336 
00340       fmatvec::SqrMat3 APK;
00341 
00345       fmatvec::Vec3 PrPK, WrPK;
00346 
00350       fmatvec::Vec3 WvPKrel, WomPK;
00351 
00352       MBSim::Function<fmatvec::MatV(fmatvec::VecV)> *fTR;
00353 
00357       MBSim::Function<fmatvec::Vec3(fmatvec::VecV, double)> *fPrPK;
00358 
00362       MBSim::Function<fmatvec::RotMat3(fmatvec::VecV, double)> *fAPK;
00363 
00367       void (FlexibleBodyFFR::*updateM_)(double t, int i);
00368 
00372       void updateMConst(double t, int i=0);
00373 
00377       void updateMNotConst(double t, int i=0); 
00378 
00382       void (FlexibleBodyFFR::*facLLM_)(int i);
00383 
00387       void facLLMConst(int i=0) {};
00388 
00392       void facLLMNotConst(int i=0) { Object::facLLM(i); }
00393 
00394       void (FlexibleBodyFFR::*updateJacobians_[2])(double t); 
00395 
00396       fmatvec::Vec aT, aR;
00397 
00398       fmatvec::Vec qRel, uRel;
00399       fmatvec::Mat TRel;
00400 
00401       fmatvec::VecV qTRel, qRRel, uTRel, uRRel;
00402       fmatvec::Mat3xV WJTrel, WJRrel, PJTT, PJRR;
00403 
00404       int nu[2], nq;
00405 
00406       MBSim::Frame *frameForJacobianOfRotation;
00407 
00408       std::vector<FixedNodalFrame*> RBF;
00409       std::vector<MBSim::CompoundContour*> RBC;
00410 
00411       fmatvec::Range<fmatvec::Var,fmatvec::Var> iqT, iqR, iqE, iuT, iuR, iuE;
00412 
00413       bool translationDependentRotation, constJT, constJR, constjT, constjR;
00414 
00415       fmatvec::SymMatV M_;
00416       fmatvec::VecV h_;
00417       fmatvec::MatV KJ[2];
00418       fmatvec::VecV Ki[2];
00419 
00420       void determineSID();
00421       void prefillMassMatrix();
00422 
00423     private:
00424 #ifdef HAVE_OPENMBVCPPINTERFACE
00425 
00428       MBSim::Frame * openMBVFrame;
00429       boost::shared_ptr<OpenMBV::Arrow> FWeight, FArrow, MArrow;
00430 #endif
00431   };
00432 
00433 }
00434 
00435 #endif